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

Unified Diff: pkg/polymer/lib/src/transform/code_extractor.dart

Issue 23011045: Declare the sequence of phases for the full polymer transform and add tests for (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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/transform.dart ('k') | pkg/polymer/lib/src/transform/script_compactor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/transform/code_extractor.dart
diff --git a/pkg/polymer/lib/src/transform/code_extractor.dart b/pkg/polymer/lib/src/transform/code_extractor.dart
index 5f7058f01974f4dc335fbe5a05e797e577f45925..0e6d4d535ee9eb6103c5a052e78fa399576fa97a 100644
--- a/pkg/polymer/lib/src/transform/code_extractor.dart
+++ b/pkg/polymer/lib/src/transform/code_extractor.dart
@@ -25,22 +25,34 @@ class InlineCodeExtractor extends Transformer {
return getPrimaryContent(transform).then((content) {
var document = parseHtml(content, inputId.path, transform.logger);
int count = 0;
+ bool htmlChanged = false;
for (var tag in document.queryAll('script')) {
- if (tag.attributes['type'] == 'application/dart' &&
- !tag.attributes.containsKey('src')) {
- // TODO(sigmund): should we automatically include a library directive
- // if it doesn't have one?
- var filename = path.url.basename(inputId.path);
- tag.attributes['src'] = '$filename.$count.dart';
- var textContent = tag.nodes.first;
- var id = inputId.addExtension('.$count.dart');
- transform.addOutput(new Asset.fromString(id, textContent.value));
- textContent.remove();
- count++;
+ // Only process tags that have inline Dart code
+ if (tag.attributes['type'] != 'application/dart' ||
+ tag.attributes.containsKey('src')) {
+ continue;
}
+ htmlChanged = true;
+
+ // Remove empty tags
+ if (tag.nodes.length == 0) {
+ tag.remove();
+ continue;
+ }
+
+ // TODO(sigmund): should we automatically include a library directive
+ // if it doesn't have one?
+ var filename = path.url.basename(inputId.path);
+ // TODO(sigmund): ensure this filename is unique (dartbug.com/12618).
+ tag.attributes['src'] = '$filename.$count.dart';
+ var textContent = tag.nodes.first;
+ var id = inputId.addExtension('.$count.dart');
+ transform.addOutput(new Asset.fromString(id, textContent.value));
+ textContent.remove();
+ count++;
}
transform.addOutput(new Asset.fromString(inputId,
- count == 0 ? content : document.outerHtml));
+ htmlChanged ? document.outerHtml : content));
});
}
}
« no previous file with comments | « pkg/polymer/lib/src/transform.dart ('k') | pkg/polymer/lib/src/transform/script_compactor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698