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 /// Common methods used by transfomers. | 5 /// Common methods used by transfomers. |
6 library polymer.src.build.common; | 6 library polymer.src.build.common; |
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'; |
11 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
12 import 'package:analyzer/src/generated/parser.dart'; | 12 import 'package:analyzer/src/generated/parser.dart'; |
13 import 'package:analyzer/src/generated/scanner.dart'; | 13 import 'package:analyzer/src/generated/scanner.dart'; |
14 import 'package:barback/barback.dart'; | 14 import 'package:barback/barback.dart'; |
15 import 'package:html5lib/dom.dart' show Document; | 15 import 'package:html5lib/dom.dart' show Document; |
16 import 'package:html5lib/parser.dart' show HtmlParser; | 16 import 'package:html5lib/parser.dart' show HtmlParser; |
17 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
18 import 'package:observe/transformer.dart' show ObservableTransformer; | 18 import 'package:observe/transformer.dart' show ObservableTransformer; |
19 import 'package:source_maps/span.dart' show Span; | |
20 | 19 |
21 const _ignoredErrors = const [ | 20 const _ignoredErrors = const [ |
22 'unexpected-dash-after-double-dash-in-comment', | 21 'unexpected-dash-after-double-dash-in-comment', |
23 'unexpected-char-in-comment', | 22 'unexpected-char-in-comment', |
24 ]; | 23 ]; |
25 | 24 |
26 /// Parses an HTML file [contents] and returns a DOM-like tree. Adds emitted | 25 /// Parses an HTML file [contents] and returns a DOM-like tree. Adds emitted |
27 /// error/warning to [logger]. | 26 /// error/warning to [logger]. |
28 Document _parseHtml(String contents, String sourcePath, TransformLogger logger, | 27 Document _parseHtml(String contents, String sourcePath, TransformLogger logger, |
29 {bool checkDocType: true, bool showWarnings: true}) { | 28 {bool checkDocType: true, bool showWarnings: true}) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 showWarnings: showWarnings); | 117 showWarnings: showWarnings); |
119 }); | 118 }); |
120 } | 119 } |
121 | 120 |
122 Future<bool> assetExists(AssetId id, Transform transform) => | 121 Future<bool> assetExists(AssetId id, Transform transform) => |
123 transform.getInput(id).then((_) => true).catchError((_) => false); | 122 transform.getInput(id).then((_) => true).catchError((_) => false); |
124 | 123 |
125 String toString() => 'polymer ($runtimeType)'; | 124 String toString() => 'polymer ($runtimeType)'; |
126 } | 125 } |
127 | 126 |
128 /// Gets the appropriate URL to use in a [Span] to produce messages | 127 /// Gets the appropriate URL to use in a span to produce messages (e.g. |
129 /// (e.g. warnings) for users. This will attempt to format the URL in the most | 128 /// warnings) for users. This will attempt to format the URL in the most useful |
130 /// useful way: | 129 /// way: |
131 /// | 130 /// |
132 /// - If the asset is within the primary package, then use the [id.path], | 131 /// - If the asset is within the primary package, then use the [id.path], |
133 /// the user will know it is a file from their own code. | 132 /// the user will know it is a file from their own code. |
134 /// - If the asset is from another package, then use [assetUrlFor], this will | 133 /// - If the asset is from another package, then use [assetUrlFor], this will |
135 /// likely be a "package:" url to the file in the other package, which is | 134 /// likely be a "package:" url to the file in the other package, which is |
136 /// enough for users to identify where the error is. | 135 /// enough for users to identify where the error is. |
137 String spanUrlFor(AssetId id, Transform transform) { | 136 String spanUrlFor(AssetId id, Transform transform) { |
138 var primaryId = transform.primaryInput.id; | 137 var primaryId = transform.primaryInput.id; |
139 bool samePackage = id.package == primaryId.package; | 138 bool samePackage = id.package == primaryId.package; |
140 return samePackage ? id.path | 139 return samePackage ? id.path |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 bool isCustomTagName(String name) { | 199 bool isCustomTagName(String name) { |
201 if (name == null || !name.contains('-')) return false; | 200 if (name == null || !name.contains('-')) return false; |
202 return !invalidTagNames.containsKey(name); | 201 return !invalidTagNames.containsKey(name); |
203 } | 202 } |
204 | 203 |
205 /// Regex to split names in the 'attributes' attribute, which supports 'a b c', | 204 /// Regex to split names in the 'attributes' attribute, which supports 'a b c', |
206 /// 'a,b,c', or even 'a b,c'. This is the same as in `lib/src/declaration.dart`. | 205 /// 'a,b,c', or even 'a b,c'. This is the same as in `lib/src/declaration.dart`. |
207 final ATTRIBUTES_REGEX = new RegExp(r'\s|,'); | 206 final ATTRIBUTES_REGEX = new RegExp(r'\s|,'); |
208 | 207 |
209 const POLYMER_EXPERIMENTAL_HTML = 'packages/polymer/polymer_experimental.html'; | 208 const POLYMER_EXPERIMENTAL_HTML = 'packages/polymer/polymer_experimental.html'; |
OLD | NEW |