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 * 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 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 | 70 |
71 | 71 |
72 /** A visitor that walks the HTML to extract all the relevant information. */ | 72 /** A visitor that walks the HTML to extract all the relevant information. */ |
73 class _Analyzer extends TreeVisitor { | 73 class _Analyzer extends TreeVisitor { |
74 final FileInfo _fileInfo; | 74 final FileInfo _fileInfo; |
75 LibraryInfo _currentInfo; | 75 LibraryInfo _currentInfo; |
76 ElementInfo _parent; | 76 ElementInfo _parent; |
77 Iterator<int> _uniqueIds; | 77 Iterator<int> _uniqueIds; |
78 Map<String, String> _pseudoElements; | 78 Map<String, String> _pseudoElements; |
79 Messages _messages; | 79 Messages _messages; |
80 bool _inHead = false; | |
80 | 81 |
81 /** | 82 /** |
82 * Whether to keep indentation spaces. Break lines and indentation spaces | 83 * Whether to keep indentation spaces. Break lines and indentation spaces |
83 * within templates are preserved in HTML. When users specify the attribute | 84 * within templates are preserved in HTML. When users specify the attribute |
84 * 'indentation="remove"' on a template tag, we'll trim those indentation | 85 * 'indentation="remove"' on a template tag, we'll trim those indentation |
85 * spaces that occur within that tag and its decendants. If any decendant | 86 * spaces that occur within that tag and its decendants. If any decendant |
86 * specifies 'indentation="preserve"', then we'll switch back to the normal | 87 * specifies 'indentation="preserve"', then we'll switch back to the normal |
87 * behavior. | 88 * behavior. |
88 */ | 89 */ |
89 bool _keepIndentationSpaces = true; | 90 bool _keepIndentationSpaces = true; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 var value = node.attributes['indentation']; | 175 var value = node.attributes['indentation']; |
175 if (value != 'remove' && value != 'preserve') { | 176 if (value != 'remove' && value != 'preserve') { |
176 _messages.warning( | 177 _messages.warning( |
177 "Invalid value for 'indentation' ($value). By default we preserve " | 178 "Invalid value for 'indentation' ($value). By default we preserve " |
178 "the indentation. Valid values are either 'remove' or 'preserve'.", | 179 "the indentation. Valid values are either 'remove' or 'preserve'.", |
179 node.sourceSpan); | 180 node.sourceSpan); |
180 } | 181 } |
181 _keepIndentationSpaces = value != 'remove'; | 182 _keepIndentationSpaces = value != 'remove'; |
182 } | 183 } |
183 | 184 |
185 var savedInHead = _inHead; | |
186 if (node.tagName == 'head') { | |
Jennifer Messerly
2013/07/23 20:39:04
alternatively, we could just skip visiting "head"?
Siggi Cherem (dart-lang)
2013/07/23 21:03:04
We could skip head, but in that case we would not
Jennifer Messerly
2013/07/23 21:04:03
yeah, okay to me either way. just worried what els
Siggi Cherem (dart-lang)
2013/07/23 21:07:04
funny - I worry about the opposite =)... I mean, w
| |
187 _inHead = true; | |
188 } | |
189 | |
184 // Invoke super to visit children. | 190 // Invoke super to visit children. |
185 super.visitElement(node); | 191 super.visitElement(node); |
186 | 192 |
187 _keepIndentationSpaces = keepSpaces; | 193 _keepIndentationSpaces = keepSpaces; |
188 _currentInfo = lastInfo; | 194 _currentInfo = lastInfo; |
189 _parent = savedParent; | 195 _parent = savedParent; |
196 _inHead = savedInHead; | |
190 | 197 |
191 if (_needsIdentifier(info)) { | 198 if (_needsIdentifier(info)) { |
192 _ensureParentHasVariable(info); | 199 _ensureParentHasVariable(info); |
193 if (info.identifier == null) { | 200 if (info.identifier == null) { |
194 _uniqueIds.moveNext(); | 201 _uniqueIds.moveNext(); |
195 info.identifier = toCamelCase('__e-${_uniqueIds.current}'); | 202 info.identifier = toCamelCase('__e-${_uniqueIds.current}'); |
196 } | 203 } |
197 } | 204 } |
198 } | 205 } |
199 | 206 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 if (name == 'style') { | 434 if (name == 'style') { |
428 attrInfo = _readStyleAttribute(info, value); | 435 attrInfo = _readStyleAttribute(info, value); |
429 } else if (name == 'class') { | 436 } else if (name == 'class') { |
430 attrInfo = _readClassAttribute(info, value); | 437 attrInfo = _readClassAttribute(info, value); |
431 } else { | 438 } else { |
432 attrInfo = _readAttribute(info, name, value); | 439 attrInfo = _readAttribute(info, name, value); |
433 } | 440 } |
434 | 441 |
435 if (attrInfo != null) { | 442 if (attrInfo != null) { |
436 info.attributes[name] = attrInfo; | 443 info.attributes[name] = attrInfo; |
444 if (_inHead) { | |
445 _messages.error('Attribute bindings are not supported under the <head>' | |
Jennifer Messerly
2013/07/23 20:39:04
I forgot, does an error cause us to skip running e
Siggi Cherem (dart-lang)
2013/07/23 21:03:04
correct
| |
446 'element', info.node.attributeSpans[name]); | |
447 } | |
437 } | 448 } |
438 | 449 |
439 // Any component's custom pseudo-element(s) defined? | 450 // Any component's custom pseudo-element(s) defined? |
440 if (name == 'pseudo' && _currentInfo is ComponentInfo) { | 451 if (name == 'pseudo' && _currentInfo is ComponentInfo) { |
441 _processPseudoAttribute(info.node, value.split(' ')); | 452 _processPseudoAttribute(info.node, value.split(' ')); |
442 } | 453 } |
443 } | 454 } |
444 | 455 |
445 void _processPseudoAttribute(Node node, List<String> values) { | 456 void _processPseudoAttribute(Node node, List<String> values) { |
446 List mangledValues = []; | 457 List mangledValues = []; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 var parser = new BindingParser(text.value); | 697 var parser = new BindingParser(text.value); |
687 if (!parser.moveNext()) { | 698 if (!parser.moveNext()) { |
688 if (!_keepIndentationSpaces) { | 699 if (!_keepIndentationSpaces) { |
689 text.value = trimOrCompact(text.value); | 700 text.value = trimOrCompact(text.value); |
690 } | 701 } |
691 if (text.value != '') new TextInfo(text, _parent); | 702 if (text.value != '') new TextInfo(text, _parent); |
692 return; | 703 return; |
693 } | 704 } |
694 | 705 |
695 _parent.childrenCreatedInCode = true; | 706 _parent.childrenCreatedInCode = true; |
707 if (_inHead) { | |
708 _messages.error('Bindings are not supported under the <head> element', | |
709 text.sourceSpan); | |
710 } | |
696 | 711 |
697 // We split [text] so that each binding has its own text node. | 712 // We split [text] so that each binding has its own text node. |
698 var node = text.parent; | 713 var node = text.parent; |
699 do { | 714 do { |
700 _addRawTextContent(parser.textContent); | 715 _addRawTextContent(parser.textContent); |
701 var placeholder = new Text(''); | 716 var placeholder = new Text(''); |
702 _uniqueIds.moveNext(); | 717 _uniqueIds.moveNext(); |
703 var id = '__binding${_uniqueIds.current}'; | 718 var id = '__binding${_uniqueIds.current}'; |
704 new TextInfo(placeholder, _parent, parser.binding, id); | 719 new TextInfo(placeholder, _parent, parser.binding, id); |
705 } while (parser.moveNext()); | 720 } while (parser.moveNext()); |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1219 } | 1234 } |
1220 } | 1235 } |
1221 } | 1236 } |
1222 } | 1237 } |
1223 } | 1238 } |
1224 } | 1239 } |
1225 | 1240 |
1226 return seen; | 1241 return seen; |
1227 } | 1242 } |
1228 } | 1243 } |
OLD | NEW |