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 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 _bindCustomElement(node, info); | 130 _bindCustomElement(node, info); |
131 | 131 |
132 var lastInfo = _currentInfo; | 132 var lastInfo = _currentInfo; |
133 if (node.tagName == 'element') { | 133 if (node.tagName == 'element') { |
134 // If element is invalid _ElementLoader already reported an error, but | 134 // If element is invalid _ElementLoader already reported an error, but |
135 // we skip the body of the element here. | 135 // we skip the body of the element here. |
136 var name = node.attributes['name']; | 136 var name = node.attributes['name']; |
137 if (name == null) return; | 137 if (name == null) return; |
| 138 |
138 var component = _fileInfo.components[name]; | 139 var component = _fileInfo.components[name]; |
139 if (component == null) return; | 140 if (component == null) return; |
140 | 141 |
141 // Associate ElementInfo of the <element> tag with its component. | 142 // Associate ElementInfo of the <element> tag with its component. |
142 component.elemInfo = info; | 143 component.elemInfo = info; |
143 | 144 |
144 _bindExtends(component); | 145 _bindExtends(component); |
145 | 146 |
146 _currentInfo = component; | 147 _currentInfo = component; |
147 } | 148 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 195 |
195 return info.hasDataBinding || info.hasIfCondition || info.hasIterate | 196 return info.hasDataBinding || info.hasIfCondition || info.hasIterate |
196 || info.hasQuery || info.component != null || info.values.length > 0 || | 197 || info.hasQuery || info.component != null || info.values.length > 0 || |
197 info.events.length > 0; | 198 info.events.length > 0; |
198 } | 199 } |
199 | 200 |
200 void _bindExtends(ComponentInfo component) { | 201 void _bindExtends(ComponentInfo component) { |
201 component.extendsComponent = _fileInfo.components[component.extendsTag]; | 202 component.extendsComponent = _fileInfo.components[component.extendsTag]; |
202 if (component.extendsComponent == null && | 203 if (component.extendsComponent == null && |
203 component.extendsTag.startsWith('x-')) { | 204 component.extendsTag.startsWith('x-')) { |
204 | |
205 _messages.warning( | 205 _messages.warning( |
206 'custom element with tag name ${component.extendsTag} not found.', | 206 'custom element with tag name ${component.extendsTag} not found.', |
207 component.element.sourceSpan, file: _fileInfo.path); | 207 component.element.sourceSpan, file: _fileInfo.path); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 void _bindCustomElement(Element node, ElementInfo info) { | 211 void _bindCustomElement(Element node, ElementInfo info) { |
212 // <x-fancy-button> | 212 // <x-fancy-button> |
213 var component = _fileInfo.components[node.tagName]; | 213 var component = _fileInfo.components[node.tagName]; |
214 if (component == null) { | 214 if (component == null) { |
215 // TODO(jmesserly): warn for unknown element tags? | 215 // TODO(jmesserly): warn for unknown element tags? |
216 | 216 |
217 // <button is="x-fancy-button"> | 217 // <button is="x-fancy-button"> |
218 var isAttr = node.attributes['is']; | 218 var componentName = node.attributes['is']; |
219 if (isAttr != null) { | 219 if (componentName != null) { |
220 component = _fileInfo.components[isAttr]; | 220 component = _fileInfo.components[componentName]; |
221 if (component == null) { | 221 } else if (node.tagName.startsWith('x-')) { |
222 _messages.warning('custom element with tag name $isAttr not found.', | 222 componentName = node.tagName; |
223 node.sourceSpan, file: _fileInfo.path); | 223 } |
224 } | 224 if (component == null && componentName != null) { |
| 225 _messages.warning( |
| 226 'custom element with tag name $componentName not found.', |
| 227 node.sourceSpan, file: _fileInfo.path); |
225 } | 228 } |
226 } | 229 } |
227 | 230 |
228 if (component != null && !component.hasConflict) { | 231 if (component != null && !component.hasConflict) { |
229 info.component = component; | 232 info.component = component; |
230 _currentInfo.usedComponents[component] = true; | 233 _currentInfo.usedComponents[component] = true; |
231 } | 234 } |
232 } | 235 } |
233 | 236 |
234 TemplateInfo _createTemplateInfo(Element node) { | 237 TemplateInfo _createTemplateInfo(Element node) { |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 end = text.indexOf('}}', start); | 957 end = text.indexOf('}}', start); |
955 if (end < 0) { | 958 if (end < 0) { |
956 start = length; | 959 start = length; |
957 return false; | 960 return false; |
958 } | 961 } |
959 // For consistency, start and end both include the curly braces. | 962 // For consistency, start and end both include the curly braces. |
960 end += 2; | 963 end += 2; |
961 return true; | 964 return true; |
962 } | 965 } |
963 } | 966 } |
OLD | NEW |