Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: pkg/code_transformers/lib/src/entry_point.dart

Issue 204033003: Updating code_transformers to not fail on syntax errors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/analyzer.dart ('k') | pkg/code_transformers/lib/src/resolver_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 import 'dart:async'; 4 import 'dart:async';
5 5
6 import 'package:analyzer/analyzer.dart' as analyzer; 6 import 'package:analyzer/analyzer.dart' as analyzer;
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:barback/barback.dart'; 8 import 'package:barback/barback.dart';
9 9
10 /// Checks to see if the provided Asset is a Dart entry point. 10 /// Checks to see if the provided Asset is a Dart entry point.
11 /// 11 ///
12 /// Assets are considered entry points if they are Dart files located in 12 /// Assets are considered entry points if they are Dart files located in
13 /// web/, test/, benchmark/ or example/ and have a main() function. 13 /// web/, test/, benchmark/ or example/ and have a main() function.
14 /// 14 ///
15 /// Because this only analyzes the primary asset this may return true for files 15 /// Because this only analyzes the primary asset this may return true for files
16 /// which are not dart entries if the file does not have a main() but does have 16 /// which are not dart entries if the file does not have a main() but does have
17 /// parts or exports. 17 /// parts or exports.
18 Future<bool> isPossibleDartEntry(Asset asset) { 18 Future<bool> isPossibleDartEntry(Asset asset) {
19 if (asset.id.extension != '.dart') return new Future.value(false); 19 if (asset.id.extension != '.dart') return new Future.value(false);
20 20
21 if (!['benchmark', 'example', 'test', 'web'] 21 if (!['benchmark', 'example', 'test', 'web']
22 .any((dir) => asset.id.path.startsWith("$dir/"))) { 22 .any((dir) => asset.id.path.startsWith("$dir/"))) {
23 return new Future.value(false); 23 return new Future.value(false);
24 } 24 }
25 return asset.readAsString().then((contents) { 25 return asset.readAsString().then((contents) {
26 return _couldBeEntrypoint(analyzer.parseCompilationUnit(contents)); 26 return _couldBeEntrypoint(
27 analyzer.parseCompilationUnit(contents, suppressErrors: true));
27 }); 28 });
28 } 29 }
29 30
30 bool _couldBeEntrypoint(CompilationUnit compilationUnit) { 31 bool _couldBeEntrypoint(CompilationUnit compilationUnit) {
31 // Allow two or fewer arguments so that entrypoints intended for use with 32 // Allow two or fewer arguments so that entrypoints intended for use with
32 // [spawnUri] get counted. 33 // [spawnUri] get counted.
33 var hasMain = compilationUnit.declarations.any((node) => 34 var hasMain = compilationUnit.declarations.any((node) =>
34 node is FunctionDeclaration && 35 node is FunctionDeclaration &&
35 node.name.name == "main" && 36 node.name.name == "main" &&
36 node.functionExpression.parameters.parameters.length <= 2); 37 node.functionExpression.parameters.parameters.length <= 2);
37 38
38 if (hasMain) return true; 39 if (hasMain) return true;
39 40
40 // If it has an export or a part, assume the worst- that the main could be 41 // If it has an export or a part, assume the worst- that the main could be
41 // in there. 42 // in there.
42 // We avoid loading those since this can be run from isPrimaryAsset calls 43 // We avoid loading those since this can be run from isPrimaryAsset calls
43 // where we do not have access to other sources. 44 // where we do not have access to other sources.
44 return compilationUnit.directives.any((node) => 45 return compilationUnit.directives.any((node) =>
45 node is ExportDirective || node is PartDirective); 46 node is ExportDirective || node is PartDirective);
46 } 47 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/analyzer.dart ('k') | pkg/code_transformers/lib/src/resolver_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698