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

Side by Side Diff: pkg/polymer/lib/src/build/import_inliner.dart

Issue 662013004: fix duplicate script issue (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add warnings and fix dynamic version Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Transfomer that inlines polymer-element definitions from html imports. 5 /// Transfomer that inlines polymer-element definitions from html imports.
6 library polymer.src.build.import_inliner; 6 library polymer.src.build.import_inliner;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 10
(...skipping 12 matching lines...) Expand all
23 import 'common.dart'; 23 import 'common.dart';
24 import 'messages.dart'; 24 import 'messages.dart';
25 25
26 // TODO(sigmund): move to web_components package (dartbug.com/18037). 26 // TODO(sigmund): move to web_components package (dartbug.com/18037).
27 class _HtmlInliner extends PolymerTransformer { 27 class _HtmlInliner extends PolymerTransformer {
28 final TransformOptions options; 28 final TransformOptions options;
29 final Transform transform; 29 final Transform transform;
30 final BuildLogger logger; 30 final BuildLogger logger;
31 final AssetId docId; 31 final AssetId docId;
32 final seen = new Set<AssetId>(); 32 final seen = new Set<AssetId>();
33 final scriptIds = <AssetId>[]; 33 final scriptIds = new List<AssetId>();
Siggi Cherem (dart-lang) 2014/10/21 17:06:03 undo?
jakemac 2014/10/21 18:14:01 Done.
34 final inlinedStylesheetIds = new Set<AssetId>(); 34 final inlinedStylesheetIds = new Set<AssetId>();
35 final extractedFiles = new Set<AssetId>(); 35 final extractedFiles = new Set<AssetId>();
36 bool experimentalBootstrap = false; 36 bool experimentalBootstrap = false;
37 final Element importsWrapper = new Element.html('<div hidden></div>'); 37 final Element importsWrapper = new Element.html('<div hidden></div>');
38 38
39 /// The number of extracted inline Dart scripts. Used as a counter to give 39 /// The number of extracted inline Dart scripts. Used as a counter to give
40 /// unique-ish filenames. 40 /// unique-ish filenames.
41 int inlineScriptCounter = 0; 41 int inlineScriptCounter = 0;
42 42
43 _HtmlInliner(TransformOptions options, Transform transform) 43 _HtmlInliner(TransformOptions options, Transform transform)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 /// the script tags. Instead we remove them entirely. 234 /// the script tags. Instead we remove them entirely.
235 Future<bool> _removeScripts(Document doc) { 235 Future<bool> _removeScripts(Document doc) {
236 bool changed = false; 236 bool changed = false;
237 return Future.forEach(doc.querySelectorAll('script'), (script) { 237 return Future.forEach(doc.querySelectorAll('script'), (script) {
238 if (script.attributes['type'] == TYPE_DART) { 238 if (script.attributes['type'] == TYPE_DART) {
239 changed = true; 239 changed = true;
240 script.remove(); 240 script.remove();
241 var src = script.attributes['src']; 241 var src = script.attributes['src'];
242 var srcId = uriToAssetId(docId, src, logger, script.sourceSpan); 242 var srcId = uriToAssetId(docId, src, logger, script.sourceSpan);
243 243
244 // No duplicates allowed!
245 if (scriptIds.contains(srcId)) {
Siggi Cherem (dart-lang) 2014/10/21 17:06:03 might be worth to keep a set on the side here - to
jakemac 2014/10/21 18:14:01 Done.
246 logger.warning(SCRIPT_INCLUDED_MORE_THAN_ONCE.create({'url': src}),
247 span: script.sourceSpan);
248 return true;
249 }
250
244 // We check for extractedFiles because 'hasInput' below is only true for 251 // We check for extractedFiles because 'hasInput' below is only true for
245 // assets that existed before this transformer runs (hasInput is false 252 // assets that existed before this transformer runs (hasInput is false
246 // for files created by [_extractScripts]). 253 // for files created by [_extractScripts]).
247 if (extractedFiles.contains(srcId)) { 254 if (extractedFiles.contains(srcId)) {
248 scriptIds.add(srcId); 255 scriptIds.add(srcId);
249 return true; 256 return true;
250 } 257 }
251 258
252 return transform.hasInput(srcId).then((exists) { 259 return transform.hasInput(srcId).then((exists) {
253 if (!exists) { 260 if (!exists) {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 /// style tag except these ones. 559 /// style tag except these ones.
553 const IGNORED_LINKED_STYLE_ATTRS = 560 const IGNORED_LINKED_STYLE_ATTRS =
554 const ['charset', 'href', 'href-lang', 'rel', 'rev']; 561 const ['charset', 'href', 'href-lang', 'rel', 'rev'];
555 562
556 /// Global RegExp objects. 563 /// Global RegExp objects.
557 final _INVALID_LIB_CHARS_REGEX = new RegExp('[^a-z0-9_]'); 564 final _INVALID_LIB_CHARS_REGEX = new RegExp('[^a-z0-9_]');
558 final _NUM_REGEX = new RegExp('[0-9]'); 565 final _NUM_REGEX = new RegExp('[0-9]');
559 final _BINDING_REGEX = new RegExp(r'(({{.*}})|(\[\[.*\]\]))'); 566 final _BINDING_REGEX = new RegExp(r'(({{.*}})|(\[\[.*\]\]))');
560 567
561 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end); 568 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698