Chromium Code Reviews| 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 /** | 5 /** |
| 6 * Logic to validate that developers are correctly using Polymer constructs. | 6 * Logic to validate that developers are correctly using Polymer constructs. |
| 7 * This is mainly used to produce warnings for feedback in the editor. | 7 * This is mainly used to produce warnings for feedback in the editor. |
| 8 */ | 8 */ |
| 9 library polymer.src.build.linter; | 9 library polymer.src.build.linter; |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 /** | 56 /** |
| 57 * Collect into [elements] any data about each polymer-element defined in | 57 * Collect into [elements] any data about each polymer-element defined in |
| 58 * [document] or any of it's imports, unless they have already been [seen]. | 58 * [document] or any of it's imports, unless they have already been [seen]. |
| 59 * Elements are added in the order they appear, transitive imports are added | 59 * Elements are added in the order they appear, transitive imports are added |
| 60 * first. | 60 * first. |
| 61 */ | 61 */ |
| 62 Future<Map<String, _ElementSummary>> _collectElements( | 62 Future<Map<String, _ElementSummary>> _collectElements( |
| 63 Document document, AssetId sourceId, Transform transform, | 63 Document document, AssetId sourceId, Transform transform, |
| 64 Set<AssetId> seen, [Map<String, _ElementSummary> elements]) { | 64 Set<AssetId> seen, [Map<String, _ElementSummary> elements]) { |
| 65 if (elements == null) elements = <String, _ElementSummary>{}; | 65 if (elements == null) elements = <String, _ElementSummary>{}; |
| 66 var logger = transform.logger; | 66 return _getImportedIds(document, sourceId, transform) |
| 67 // Note: the import order is relevant, so we visit in that order. | 67 // Note: the import order is relevant, so we visit in that order. |
| 68 return Future.forEach(_getImportedIds(document, sourceId, logger), (id) { | 68 .then((ids) => Future.forEach(ids, |
| 69 if (seen.contains(id)) return new Future.value(null); | 69 (id) => _readAndCollectElements(id, transform, seen, elements))) |
| 70 seen.add(id); | 70 .then((_) => _addElements(document, transform.logger, elements)) |
| 71 return readAsHtml(id, transform) | 71 .then((_) => elements); |
| 72 .then((doc) => _collectElements(doc, id, transform, seen, elements)); | |
| 73 }).then((_) { | |
| 74 _addElements(document, logger, elements); | |
| 75 return elements; | |
| 76 }); | |
| 77 } | 72 } |
| 78 | 73 |
| 79 List<AssetId> _getImportedIds( | 74 Future _readAndCollectElements(AssetId id, Transform transform, |
| 80 Document document, AssetId sourceId, TranformLogger logger) { | 75 Set<AssetId> seen, Map<String, _ElementSummary> elements) { |
| 76 if (id == null || seen.contains(id)) return new Future.value(null); | |
| 77 seen.add(id); | |
| 78 return readAsHtml(id, transform).then( | |
| 79 (doc) => _collectElements(doc, id, transform, seen, elements)); | |
| 80 } | |
| 81 | |
| 82 Future<List<AssetId>> _getImportedIds( | |
| 83 Document document, AssetId sourceId, Tranform transform) { | |
| 81 var importIds = []; | 84 var importIds = []; |
| 85 var logger = transform.logger; | |
| 82 for (var tag in document.queryAll('link')) { | 86 for (var tag in document.queryAll('link')) { |
| 83 if (tag.attributes['rel'] != 'import') continue; | 87 if (tag.attributes['rel'] != 'import') continue; |
| 84 var href = tag.attributes['href']; | 88 var href = tag.attributes['href']; |
| 85 var id = resolve(sourceId, href, logger, tag.sourceSpan); | 89 var span = tag.sourceSpan; |
| 90 var id = resolve(sourceId, href, logger, span); | |
| 86 if (id == null) continue; | 91 if (id == null) continue; |
| 87 importIds.add(id); | 92 importIds.add(assetExists(id, transform).then((exists) { |
| 93 if (exists) return id; | |
| 94 if (sourceId == transform.primaryInput.id) { | |
| 95 logger.error('couldn\'t find imported asset "${id.path}" in package ' | |
| 96 '"${id.package}".', span); | |
|
Jennifer Messerly
2013/09/13 18:12:40
+2 indent
Siggi Cherem (dart-lang)
2013/09/13 18:20:16
Done.
| |
| 97 } | |
| 98 })); | |
| 88 } | 99 } |
| 89 return importIds; | 100 return Future.wait(importIds); |
| 90 } | 101 } |
| 91 | 102 |
| 92 void _addElements(Document document, TransformLogger logger, | 103 void _addElements(Document document, TransformLogger logger, |
| 93 Map<String, _ElementSummary> elements) { | 104 Map<String, _ElementSummary> elements) { |
| 94 for (var tag in document.queryAll('polymer-element')) { | 105 for (var tag in document.queryAll('polymer-element')) { |
| 95 var name = tag.attributes['name']; | 106 var name = tag.attributes['name']; |
| 96 if (name == null) continue; | 107 if (name == null) continue; |
| 97 var extendsTag = tag.attributes['extends']; | 108 var extendsTag = tag.attributes['extends']; |
| 98 var span = tag.sourceSpan; | 109 var span = tag.sourceSpan; |
| 99 var existing = elements[name]; | 110 var existing = elements[name]; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn -custom-element-name> | 446 * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn -custom-element-name> |
| 436 */ | 447 */ |
| 437 bool _isCustomTag(String name) { | 448 bool _isCustomTag(String name) { |
| 438 if (name == null || !name.contains('-')) return false; | 449 if (name == null || !name.contains('-')) return false; |
| 439 return !_invalidTagNames.containsKey(name); | 450 return !_invalidTagNames.containsKey(name); |
| 440 } | 451 } |
| 441 | 452 |
| 442 final String _RED_COLOR = '\u001b[31m'; | 453 final String _RED_COLOR = '\u001b[31m'; |
| 443 final String _MAGENTA_COLOR = '\u001b[35m'; | 454 final String _MAGENTA_COLOR = '\u001b[35m'; |
| 444 final String _NO_COLOR = '\u001b[0m'; | 455 final String _NO_COLOR = '\u001b[0m'; |
| OLD | NEW |