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'; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 from: builder.join('/', builder.dirname(sourceId.path))); | 165 from: builder.join('/', builder.dirname(sourceId.path))); |
166 } | 166 } |
167 | 167 |
168 | 168 |
169 /// Convert system paths to asset paths (asset paths are posix style). | 169 /// Convert system paths to asset paths (asset paths are posix style). |
170 String _systemToAssetPath(String assetPath) { | 170 String _systemToAssetPath(String assetPath) { |
171 if (path.Style.platform != path.Style.windows) return assetPath; | 171 if (path.Style.platform != path.Style.windows) return assetPath; |
172 return path.posix.joinAll(path.split(assetPath)); | 172 return path.posix.joinAll(path.split(assetPath)); |
173 } | 173 } |
174 | 174 |
175 | |
176 /// Parse [code] using analyzer. | |
177 CompilationUnit parseCompilationUnit(String code) { | |
178 var errorListener = new _ErrorCollector(); | |
179 var reader = new CharSequenceReader(code); | |
180 var scanner = new Scanner(null, reader, errorListener); | |
181 var token = scanner.tokenize(); | |
182 var parser = new Parser(null, errorListener); | |
183 return parser.parseCompilationUnit(token); | |
184 } | |
185 | |
186 class _ErrorCollector extends AnalysisErrorListener { | |
187 final errors = <AnalysisError>[]; | |
188 onError(error) => errors.add(error); | |
189 } | |
190 | |
191 /// These names have meaning in SVG or MathML, so they aren't allowed as custom | 175 /// These names have meaning in SVG or MathML, so they aren't allowed as custom |
192 /// tags. See [isCustomTagName]. | 176 /// tags. See [isCustomTagName]. |
193 const invalidTagNames = const { | 177 const invalidTagNames = const { |
194 'annotation-xml': '', | 178 'annotation-xml': '', |
195 'color-profile': '', | 179 'color-profile': '', |
196 'font-face': '', | 180 'font-face': '', |
197 'font-face-src': '', | 181 'font-face-src': '', |
198 'font-face-uri': '', | 182 'font-face-uri': '', |
199 'font-face-format': '', | 183 'font-face-format': '', |
200 'font-face-name': '', | 184 'font-face-name': '', |
201 'missing-glyph': '', | 185 'missing-glyph': '', |
202 }; | 186 }; |
203 | 187 |
204 /// Returns true if this is a valid custom element name. See: | 188 /// Returns true if this is a valid custom element name. See: |
205 /// <http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type> | 189 /// <http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type> |
206 bool isCustomTagName(String name) { | 190 bool isCustomTagName(String name) { |
207 if (name == null || !name.contains('-')) return false; | 191 if (name == null || !name.contains('-')) return false; |
208 return !invalidTagNames.containsKey(name); | 192 return !invalidTagNames.containsKey(name); |
209 } | 193 } |
210 | 194 |
211 /// Regex to split names in the 'attributes' attribute, which supports 'a b c', | 195 /// Regex to split names in the 'attributes' attribute, which supports 'a b c', |
212 /// 'a,b,c', or even 'a b,c'. This is the same as in `lib/src/declaration.dart`. | 196 /// 'a,b,c', or even 'a b,c'. This is the same as in `lib/src/declaration.dart`. |
213 final ATTRIBUTES_REGEX = new RegExp(r'\s|,'); | 197 final ATTRIBUTES_REGEX = new RegExp(r'\s|,'); |
214 | 198 |
215 const POLYMER_EXPERIMENTAL_HTML = 'packages/polymer/polymer_experimental.html'; | 199 const POLYMER_EXPERIMENTAL_HTML = 'packages/polymer/polymer_experimental.html'; |
OLD | NEW |