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

Unified Diff: pkg/code_transformers/lib/src/entry_point.dart

Issue 235483002: Updating code_transformer's ResolverTransform to filter on Dart entry points in apply. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: CR change & nudge the version Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/code_transformers/lib/src/resolvers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/code_transformers/lib/src/entry_point.dart
diff --git a/pkg/code_transformers/lib/src/entry_point.dart b/pkg/code_transformers/lib/src/entry_point.dart
index ee7868e3ea9fef58a419664d79e6c3ef251ac6e6..ed9eb28f09ac32cd83ab7d13d143fecea883b5c7 100644
--- a/pkg/code_transformers/lib/src/entry_point.dart
+++ b/pkg/code_transformers/lib/src/entry_point.dart
@@ -7,21 +7,29 @@ import 'package:analyzer/analyzer.dart' as analyzer;
import 'package:analyzer/src/generated/ast.dart';
import 'package:barback/barback.dart';
-/// Checks to see if the provided Asset is a Dart entry point.
+/// Checks to see if the provided AssetId is a Dart file in a directory which
+/// may contain entry points.
///
-/// Assets are considered entry points if they are Dart files located in
-/// web/, test/, benchmark/ or example/ and have a main() function.
+/// Directories are considered entry points if they are Dart files located in
+/// web/, test/, benchmark/ or example/.
+bool isPossibleDartEntryId(AssetId id) {
+ if (id.extension != '.dart') return false;
+
+ return ['benchmark', 'example', 'test', 'web']
+ .any((dir) => id.path.startsWith("$dir/"));
+}
+
+/// Checks to see if the provided Asset is possibly a Dart entry point.
+///
+/// Assets are considered entry points if they pass [isPossibleDartEntryId] and
+/// have a main() method.
///
/// Because this only analyzes the primary asset this may return true for files
/// which are not dart entries if the file does not have a main() but does have
/// parts or exports.
Future<bool> isPossibleDartEntry(Asset asset) {
- if (asset.id.extension != '.dart') return new Future.value(false);
+ if (!isPossibleDartEntryId(asset.id)) return new Future.value(false);
- if (!['benchmark', 'example', 'test', 'web']
- .any((dir) => asset.id.path.startsWith("$dir/"))) {
- return new Future.value(false);
- }
return asset.readAsString().then((contents) {
return _couldBeEntrypoint(
analyzer.parseCompilationUnit(contents, suppressErrors: true));
« no previous file with comments | « no previous file | pkg/code_transformers/lib/src/resolvers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698