| OLD | NEW |
| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 }).then((_) => changed); | 219 }).then((_) => changed); |
| 220 } | 220 } |
| 221 | 221 |
| 222 /// Split inline scripts into their own files. We need to do this for dart2js | 222 /// Split inline scripts into their own files. We need to do this for dart2js |
| 223 /// to be able to compile them. | 223 /// to be able to compile them. |
| 224 /// | 224 /// |
| 225 /// This also validates that there weren't any duplicate scripts. | 225 /// This also validates that there weren't any duplicate scripts. |
| 226 bool _extractScripts(Document doc, {bool injectLibraryName: true}) { | 226 bool _extractScripts(Document doc, {bool injectLibraryName: true}) { |
| 227 bool changed = false; | 227 bool changed = false; |
| 228 for (var script in doc.querySelectorAll('script')) { | 228 for (var script in doc.querySelectorAll('script')) { |
| 229 if (script.attributes['type'] != TYPE_DART) continue; | |
| 230 | |
| 231 var src = script.attributes['src']; | 229 var src = script.attributes['src']; |
| 232 if (src != null) continue; | 230 if (src != null) continue; |
| 233 | 231 |
| 232 var type = script.attributes['type']; |
| 233 var isDart = type == TYPE_DART; |
| 234 |
| 235 var shouldExtract = isDart || |
| 236 (options.contentSecurityPolicy && (type == null || type == TYPE_JS)); |
| 237 if (!shouldExtract) continue; |
| 238 |
| 239 var extension = isDart ? 'dart' : 'js'; |
| 234 final filename = path.url.basename(docId.path); | 240 final filename = path.url.basename(docId.path); |
| 235 final count = inlineScriptCounter++; | 241 final count = inlineScriptCounter++; |
| 236 var code = script.text; | 242 var code = script.text; |
| 237 // TODO(sigmund): ensure this path is unique (dartbug.com/12618). | 243 // TODO(sigmund): ensure this path is unique (dartbug.com/12618). |
| 238 script.attributes['src'] = src = '$filename.$count.dart'; | 244 script.attributes['src'] = src = '$filename.$count.$extension'; |
| 239 script.text = ''; | 245 script.text = ''; |
| 240 changed = true; | 246 changed = true; |
| 241 | 247 |
| 242 var newId = docId.addExtension('.$count.dart'); | 248 var newId = docId.addExtension('.$count.$extension'); |
| 243 if (injectLibraryName && !_hasLibraryDirective(code)) { | 249 if (isDart && injectLibraryName && !_hasLibraryDirective(code)) { |
| 244 var libName = _libraryNameFor(docId, count); | 250 var libName = _libraryNameFor(docId, count); |
| 245 code = "library $libName;\n$code"; | 251 code = "library $libName;\n$code"; |
| 246 } | 252 } |
| 247 extractedFiles.add(newId); | 253 extractedFiles.add(newId); |
| 248 transform.addOutput(new Asset.fromString(newId, code)); | 254 transform.addOutput(new Asset.fromString(newId, code)); |
| 249 } | 255 } |
| 250 return changed; | 256 return changed; |
| 251 } | 257 } |
| 252 } | 258 } |
| 253 | 259 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 /// When inlining <link rel="stylesheet"> tags copy over all attributes to the | 480 /// When inlining <link rel="stylesheet"> tags copy over all attributes to the |
| 475 /// style tag except these ones. | 481 /// style tag except these ones. |
| 476 const IGNORED_LINKED_STYLE_ATTRS = | 482 const IGNORED_LINKED_STYLE_ATTRS = |
| 477 const ['charset', 'href', 'href-lang', 'rel', 'rev']; | 483 const ['charset', 'href', 'href-lang', 'rel', 'rev']; |
| 478 | 484 |
| 479 /// Global RegExp objects for validating generated library names. | 485 /// Global RegExp objects for validating generated library names. |
| 480 final INVALID_LIB_CHARS_REGEX = new RegExp('[^a-z0-9_]'); | 486 final INVALID_LIB_CHARS_REGEX = new RegExp('[^a-z0-9_]'); |
| 481 final NUM_REGEX = new RegExp('[0-9]'); | 487 final NUM_REGEX = new RegExp('[0-9]'); |
| 482 | 488 |
| 483 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end); | 489 _getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end); |
| OLD | NEW |