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

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

Issue 239433012: Detect and warn about missing scripts (rather than fail during the build) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
Index: pkg/polymer/lib/src/build/import_inliner.dart
diff --git a/pkg/polymer/lib/src/build/import_inliner.dart b/pkg/polymer/lib/src/build/import_inliner.dart
index ee2aee0b87c1de94d118e888bce63f8d3bdb9b23..e785315bd126d9805b88e4919f5752a6f4931d1c 100644
--- a/pkg/polymer/lib/src/build/import_inliner.dart
+++ b/pkg/polymer/lib/src/build/import_inliner.dart
@@ -28,6 +28,7 @@ class _HtmlInliner extends PolymerTransformer {
final AssetId docId;
final seen = new Set<AssetId>();
final scriptIds = <AssetId>[];
+ final extractedFiles = new Set<AssetId>();
/// The number of extracted inline Dart scripts. Used as a counter to give
/// unique-ish filenames.
@@ -51,8 +52,10 @@ class _HtmlInliner extends PolymerTransformer {
changed = _extractScripts(document, docId);
return _visitImports(document);
}).then((importsFound) {
- bool scriptsRemoved = _removeScripts(document);
- changed = changed || importsFound || scriptsRemoved;
+ changed = changed || importsFound;
+ return _removeScripts(document);
+ }).then((scriptsRemoved) {
+ changed = changed || scriptsRemoved;
var output = transform.primaryInput;
if (changed) output = new Asset.fromString(docId, document.outerHtml);
@@ -160,17 +163,32 @@ class _HtmlInliner extends PolymerTransformer {
///
/// Dartium only allows a single script tag per page, so we can't inline
/// the script tags. Instead we remove them entirely.
- bool _removeScripts(Document doc) {
+ Future<bool> _removeScripts(Document doc) {
bool changed = false;
- for (var script in doc.querySelectorAll('script')) {
+ return Future.forEach(doc.querySelectorAll('script'), (script) {
if (script.attributes['type'] == TYPE_DART_COMPONENT) {
changed = true;
script.remove();
var src = script.attributes['src'];
- scriptIds.add(uriToAssetId(docId, src, logger, script.sourceSpan));
+ var srcId = uriToAssetId(docId, src, logger, script.sourceSpan);
+
+ // We check for extractedFiles because 'hasInput' below is only true for
+ // assets that existed before this transformer runs (hasInput is false
+ // for files created by [_extractScripts]).
+ if (extractedFiles.contains(srcId)) {
+ scriptIds.add(srcId);
+ return true;
+ }
+ return transform.hasInput(srcId).then((exists) {
+ if (!exists) {
+ logger.warning('Script file at "$src" not found.',
+ span: script.sourceSpan);
+ } else {
+ scriptIds.add(srcId);
+ }
+ });
}
- }
- return changed;
+ }).then((_) => changed);
}
/// Split inline scripts into their own files. We need to do this for dart2js
@@ -219,6 +237,7 @@ class _HtmlInliner extends PolymerTransformer {
code = "library $libName;\n$code";
}
+ extractedFiles.add(newId);
transform.addOutput(new Asset.fromString(newId, code));
}
return changed;
« no previous file with comments | « no previous file | pkg/polymer/lib/src/build/script_compactor.dart » ('j') | pkg/polymer/lib/src/build/script_compactor.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698