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 extracts inlined script code into separate assets. */ | 5 /** Transfomer that extracts inlined script code into separate assets. */ |
6 library polymer.src.build.code_extractor; | 6 library polymer.src.build.code_extractor; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 /** Only run this transformer on .html files. */ | 28 /** Only run this transformer on .html files. */ |
29 final String allowedExtensions = ".html"; | 29 final String allowedExtensions = ".html"; |
30 | 30 |
31 Future apply(Transform transform) { | 31 Future apply(Transform transform) { |
32 var input = transform.primaryInput; | 32 var input = transform.primaryInput; |
33 var id = transform.primaryInput.id; | 33 var id = transform.primaryInput.id; |
34 return readPrimaryAsHtml(transform).then((document) { | 34 return readPrimaryAsHtml(transform).then((document) { |
35 int count = 0; | 35 int count = 0; |
36 bool htmlChanged = false; | 36 bool htmlChanged = false; |
37 for (var tag in document.queryAll('script')) { | 37 for (var tag in document.querySelectorAll('script')) { |
38 // Only process tags that have inline Dart code | 38 // Only process tags that have inline Dart code |
39 if (tag.attributes['type'] != 'application/dart' || | 39 if (tag.attributes['type'] != 'application/dart' || |
40 tag.attributes.containsKey('src')) { | 40 tag.attributes.containsKey('src')) { |
41 continue; | 41 continue; |
42 } | 42 } |
43 htmlChanged = true; | 43 htmlChanged = true; |
44 | 44 |
45 // Remove empty tags | 45 // Remove empty tags |
46 if (tag.nodes.length == 0) { | 46 if (tag.nodes.length == 0) { |
47 tag.remove(); | 47 tag.remove(); |
(...skipping 28 matching lines...) Expand all Loading... |
76 var scanner = new Scanner(null, reader, errorListener); | 76 var scanner = new Scanner(null, reader, errorListener); |
77 var token = scanner.tokenize(); | 77 var token = scanner.tokenize(); |
78 var unit = new Parser(null, errorListener).parseCompilationUnit(token); | 78 var unit = new Parser(null, errorListener).parseCompilationUnit(token); |
79 return unit.directives.any((d) => d is LibraryDirective); | 79 return unit.directives.any((d) => d is LibraryDirective); |
80 } | 80 } |
81 | 81 |
82 class _ErrorCollector extends AnalysisErrorListener { | 82 class _ErrorCollector extends AnalysisErrorListener { |
83 final errors = <AnalysisError>[]; | 83 final errors = <AnalysisError>[]; |
84 onError(error) => errors.add(error); | 84 onError(error) => errors.add(error); |
85 } | 85 } |
OLD | NEW |