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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « code_transformers/lib/src/delete_file.dart ('k') | code_transformers/lib/src/messages.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: code_transformers/lib/src/entry_point.dart
diff --git a/code_transformers/lib/src/entry_point.dart b/code_transformers/lib/src/entry_point.dart
deleted file mode 100644
index 21f7acf41163f1de214d33ea27185423ce69475c..0000000000000000000000000000000000000000
--- a/code_transformers/lib/src/entry_point.dart
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-import 'dart:async';
-
-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 AssetId is a Dart file in a directory which
-/// may contain entry points.
-///
-/// 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 (!isPossibleDartEntryId(asset.id)) return new Future.value(false);
-
- return asset.readAsString().then((contents) {
- return _couldBeEntrypoint(
- analyzer.parseCompilationUnit(contents, suppressErrors: true));
- });
-}
-
-bool _couldBeEntrypoint(CompilationUnit compilationUnit) {
- // Allow two or fewer arguments so that entrypoints intended for use with
- // [spawnUri] get counted.
- var hasMain = compilationUnit.declarations.any(
- (node) => node is FunctionDeclaration &&
- node.name.name == "main" &&
- node.functionExpression.parameters.parameters.length <= 2);
-
- if (hasMain) return true;
-
- // If it has an export or a part, assume the worst- that the main could be
- // in there.
- // We avoid loading those since this can be run from isPrimaryAsset calls
- // where we do not have access to other sources.
- return compilationUnit.directives
- .any((node) => node is ExportDirective || node is PartDirective);
-}
« no previous file with comments | « code_transformers/lib/src/delete_file.dart ('k') | code_transformers/lib/src/messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698