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

Unified Diff: pkg/polymer/lib/src/build/common.dart

Issue 180933002: combine script extractor and import inliner (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix multiple linked scripts Created 6 years, 10 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 | « pkg/polymer/lib/src/build/code_extractor.dart ('k') | pkg/polymer/lib/src/build/import_inliner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/build/common.dart
diff --git a/pkg/polymer/lib/src/build/common.dart b/pkg/polymer/lib/src/build/common.dart
index bcde554030e4896273a70c5e164dc13049c62395..b1a7851b7141f07764ae3a52a7df1e167e51da8e 100644
--- a/pkg/polymer/lib/src/build/common.dart
+++ b/pkg/polymer/lib/src/build/common.dart
@@ -8,6 +8,10 @@ library polymer.src.build.common;
import 'dart:async';
import 'dart:math' show min, max;
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/error.dart';
+import 'package:analyzer/src/generated/parser.dart';
+import 'package:analyzer/src/generated/scanner.dart';
import 'package:barback/barback.dart';
import 'package:html5lib/dom.dart' show Document;
import 'package:html5lib/parser.dart' show HtmlParser;
@@ -101,28 +105,28 @@ abstract class PolymerTransformer {
});
}
- /// Gets the appropriate URL to use in a [Span] to produce messages
- /// (e.g. warnings) for users. This will attempt to format the URL in the most
- /// useful way:
- ///
- /// - If the asset is within the primary package, then use the [id.path],
- /// the user will know it is a file from their own code.
- /// - If the asset is from another package, then use [assetUrlFor], this will
- /// likely be a "package:" url to the file in the other package, which is
- /// enough for users to identify where the error is.
- String spanUrlFor(AssetId id, Transform transform) {
- var primaryId = transform.primaryInput.id;
- bool samePackage = id.package == primaryId.package;
- return samePackage ? id.path
- : assetUrlFor(id, primaryId, transform.logger, allowAssetUrl: true);
- }
-
Future<bool> assetExists(AssetId id, Transform transform) =>
transform.getInput(id).then((_) => true).catchError((_) => false);
String toString() => 'polymer ($runtimeType)';
}
+/// Gets the appropriate URL to use in a [Span] to produce messages
+/// (e.g. warnings) for users. This will attempt to format the URL in the most
+/// useful way:
+///
+/// - If the asset is within the primary package, then use the [id.path],
+/// the user will know it is a file from their own code.
+/// - If the asset is from another package, then use [assetUrlFor], this will
+/// likely be a "package:" url to the file in the other package, which is
+/// enough for users to identify where the error is.
+String spanUrlFor(AssetId id, Transform transform) {
+ var primaryId = transform.primaryInput.id;
+ bool samePackage = id.package == primaryId.package;
+ return samePackage ? id.path
+ : assetUrlFor(id, primaryId, transform.logger, allowAssetUrl: true);
+}
+
/// Transformer phases which should be applied to the Polymer package.
List<List<Transformer>> get phasesForPolymer =>
[[new ObservableTransformer(['lib/src/instance.dart'])]];
@@ -250,3 +254,19 @@ String _systemToAssetPath(String assetPath) {
if (path.Style.platform != path.Style.windows) return assetPath;
return path.posix.joinAll(path.split(assetPath));
}
+
+
+/// Parse [code] using analyzer.
+CompilationUnit parseCompilationUnit(String code) {
+ var errorListener = new _ErrorCollector();
+ var reader = new CharSequenceReader(code);
+ var scanner = new Scanner(null, reader, errorListener);
+ var token = scanner.tokenize();
+ var parser = new Parser(null, errorListener);
+ return parser.parseCompilationUnit(token);
+}
+
+class _ErrorCollector extends AnalysisErrorListener {
+ final errors = <AnalysisError>[];
+ onError(error) => errors.add(error);
+}
« no previous file with comments | « pkg/polymer/lib/src/build/code_extractor.dart ('k') | pkg/polymer/lib/src/build/import_inliner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698