Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * Part of the template compilation that concerns with extracting information | 6 * Part of the template compilation that concerns with extracting information | 
| 7 * from the HTML parse tree. | 7 * from the HTML parse tree. | 
| 8 */ | 8 */ | 
| 9 library analyzer; | 9 library analyzer; | 
| 10 | 10 | 
| 11 import 'dart:uri'; | |
| 11 import 'package:html5lib/dom.dart'; | 12 import 'package:html5lib/dom.dart'; | 
| 12 import 'package:html5lib/dom_parsing.dart'; | 13 import 'package:html5lib/dom_parsing.dart'; | 
| 13 import 'package:source_maps/span.dart'; | 14 import 'package:source_maps/span.dart'; | 
| 14 | 15 | 
| 15 import 'dart_parser.dart'; | 16 import 'dart_parser.dart'; | 
| 16 import 'file_system/path.dart'; | 17 import 'file_system/path.dart'; | 
| 17 import 'files.dart'; | 18 import 'files.dart'; | 
| 18 import 'html5_utils.dart'; | 19 import 'html5_utils.dart'; | 
| 19 import 'info.dart'; | 20 import 'info.dart'; | 
| 20 import 'messages.dart'; | 21 import 'messages.dart'; | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 // child nodes and get their infos, and if any of them need data binding, | 113 // child nodes and get their infos, and if any of them need data binding, | 
| 113 // we create an ElementInfo for ourselves and return it, otherwise we just | 114 // we create an ElementInfo for ourselves and return it, otherwise we just | 
| 114 // return null. | 115 // return null. | 
| 115 if (info == null) { | 116 if (info == null) { | 
| 116 // <element> tags are tracked in the file's declared components, so they | 117 // <element> tags are tracked in the file's declared components, so they | 
| 117 // don't need a parent. | 118 // don't need a parent. | 
| 118 var parent = node.tagName == 'element' ? null : _parent; | 119 var parent = node.tagName == 'element' ? null : _parent; | 
| 119 info = new ElementInfo(node, parent); | 120 info = new ElementInfo(node, parent); | 
| 120 } | 121 } | 
| 121 | 122 | 
| 122 // TODO(terry): How to handle <link rel="stylesheet" href="..."> | |
| 123 // - What if multiple stylesheet links for a component? | |
| 124 // - What if a stylesheet link for all component and particular | |
| 125 // stylesheet links for each component? | |
| 126 // - What if multiple <style> tags for the same component? | |
| 127 if (node.tagName == 'style' && node.attributes.containsKey("scoped")) { | |
| 128 // TODO(terry): Faster to parse the CSS tags separately instead of | |
| 129 // concatenating all styles. | |
| 130 // Get contents of style tag. | |
| 131 _currentInfo.cssSource.write(node.nodes.single.value); | |
| 132 } | |
| 133 | |
| 134 visitElementInfo(info); | 123 visitElementInfo(info); | 
| 135 | 124 | 
| 136 if (_parent == null) { | 125 if (_parent == null) { | 
| 137 _fileInfo.bodyInfo = info; | 126 _fileInfo.bodyInfo = info; | 
| 138 } | 127 } | 
| 139 } | 128 } | 
| 140 | 129 | 
| 141 void visitElementInfo(ElementInfo info) { | 130 void visitElementInfo(ElementInfo info) { | 
| 142 var node = info.node; | 131 var node = info.node; | 
| 143 | 132 | 
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 } | 720 } | 
| 732 } | 721 } | 
| 733 | 722 | 
| 734 /** | 723 /** | 
| 735 * Process `link rel="component"` as specified in: | 724 * Process `link rel="component"` as specified in: | 
| 736 * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/components/index.ht ml#link-type-component> | 725 * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/components/index.ht ml#link-type-component> | 
| 737 */ | 726 */ | 
| 738 void visitLinkElement(Element node) { | 727 void visitLinkElement(Element node) { | 
| 739 // TODO(jmesserly): deprecate the plural form, it is singular in the spec. | 728 // TODO(jmesserly): deprecate the plural form, it is singular in the spec. | 
| 740 var rel = node.attributes['rel']; | 729 var rel = node.attributes['rel']; | 
| 741 if (rel != 'component' && rel != 'components') return; | 730 if (rel != 'components' && rel != 'stylesheet') return; | 
| 
 
Siggi Cherem (dart-lang)
2013/03/07 22:14:20
there seems to be a bad merge here. this should al
 
terry
2013/03/08 20:11:24
Nice catch yeah it was a bad merge.
On 2013/03/07
 
 | |
| 742 | 731 | 
| 743 if (!_inHead) { | 732 if (!_inHead) { | 
| 744 _messages.warning('link rel="$rel" only valid in ' | 733 _messages.warning('link rel="$rel" only valid in ' | 
| 745 'head.', node.sourceSpan, file: _fileInfo.path); | 734 'head.', node.sourceSpan, file: _fileInfo.path); | 
| 746 return; | 735 return; | 
| 747 } | 736 } | 
| 748 | 737 | 
| 749 var href = node.attributes['href']; | 738 var href = node.attributes['href']; | 
| 750 if (href == null || href == '') { | 739 if (href == null || href == '') { | 
| 751 _messages.warning('link rel="$rel" missing href.', | 740 _messages.warning('link rel="$rel" missing href.', | 
| 752 node.sourceSpan, file: _fileInfo.path); | 741 node.sourceSpan, file: _fileInfo.path); | 
| 753 return; | 742 return; | 
| 754 } | 743 } | 
| 755 | 744 | 
| 756 var path; | 745 var path; | 
| 757 if (href.startsWith('package:')) { | 746 if (href.startsWith('package:')) { | 
| 758 path = _packageRoot.join(new Path(href.substring(8))); | 747 path = _packageRoot.join(new Path(href.substring(8))); | 
| 759 } else { | 748 } else { | 
| 760 path = _fileInfo.path.directoryPath.join(new Path(href)); | 749 path = _fileInfo.path.directoryPath.join(new Path(href)); | 
| 761 } | 750 } | 
| 762 | 751 | 
| 763 _fileInfo.componentLinks.add(path); | 752 switch (rel) { | 
| 753 case 'components': | |
| 
 
Siggi Cherem (dart-lang)
2013/03/07 22:14:20
given that there are only two options (since you r
 
terry
2013/03/08 20:11:24
Done.
 
 | |
| 754 _fileInfo.componentLinks.add(path); | |
| 755 break; | |
| 756 case 'stylesheet': | |
| 757 // Local stylesheets only are handled. | |
| 758 var scheme = Uri.parse(href).scheme; | |
| 759 if (scheme != 'http' && scheme != 'https') { | |
| 760 _fileInfo.styleSheetHref.add(path); | |
| 761 } | |
| 762 break; | |
| 763 } | |
| 764 } | 764 } | 
| 765 | 765 | 
| 766 void visitElementElement(Element node) { | 766 void visitElementElement(Element node) { | 
| 767 // TODO(jmesserly): what do we do in this case? It seems like an <element> | 767 // TODO(jmesserly): what do we do in this case? It seems like an <element> | 
| 768 // inside a Shadow DOM should be scoped to that <template> tag, and not | 768 // inside a Shadow DOM should be scoped to that <template> tag, and not | 
| 769 // visible from the outside. | 769 // visible from the outside. | 
| 770 if (_currentInfo is ComponentInfo) { | 770 if (_currentInfo is ComponentInfo) { | 
| 771 _messages.error('Nested component definitions are not yet supported.', | 771 _messages.error('Nested component definitions are not yet supported.', | 
| 772 node.sourceSpan, file: _fileInfo.path); | 772 node.sourceSpan, file: _fileInfo.path); | 
| 773 return; | 773 return; | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 if (start == null) moveNext(); | 981 if (start == null) moveNext(); | 
| 982 if (start < length) { | 982 if (start < length) { | 
| 983 do { | 983 do { | 
| 984 bindings.add(binding); | 984 bindings.add(binding); | 
| 985 content.add(textContent); | 985 content.add(textContent); | 
| 986 } while (moveNext()); | 986 } while (moveNext()); | 
| 987 } | 987 } | 
| 988 content.add(textContent); | 988 content.add(textContent); | 
| 989 } | 989 } | 
| 990 } | 990 } | 
| OLD | NEW |