Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: lib/src/analyzer.dart

Issue 11359215: Ensure parent id added only when we need an identifier for the child (Closed) Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 visitElementInfo(info); 81 visitElementInfo(info);
82 82
83 if (_parent == null) { 83 if (_parent == null) {
84 _fileInfo.bodyInfo = info; 84 _fileInfo.bodyInfo = info;
85 } 85 }
86 } 86 }
87 87
88 void visitElementInfo(ElementInfo info) { 88 void visitElementInfo(ElementInfo info) {
89 var node = info.node; 89 var node = info.node;
90 90
91 _ensureParentHasQuery(info);
92
93 if (node.id != '') info.identifier = '_${toCamelCase(node.id)}'; 91 if (node.id != '') info.identifier = '_${toCamelCase(node.id)}';
94 if (node.tagName == 'body' || (_currentInfo is ComponentInfo 92 if (node.tagName == 'body' || (_currentInfo is ComponentInfo
95 && (_currentInfo as ComponentInfo).template == node)) { 93 && (_currentInfo as ComponentInfo).template == node)) {
96 info.isRoot = true; 94 info.isRoot = true;
97 info.identifier = '_root'; 95 info.identifier = '_root';
98 } 96 }
99 97
100 node.attributes.forEach((name, value) { 98 node.attributes.forEach((name, value) {
101 visitAttribute(node, info, name, value); 99 visitAttribute(node, info, name, value);
102 }); 100 });
(...skipping 19 matching lines...) Expand all
122 120
123 var savedParent = _parent; 121 var savedParent = _parent;
124 _parent = info; 122 _parent = info;
125 123
126 // Invoke super to visit children. 124 // Invoke super to visit children.
127 super.visitElement(node); 125 super.visitElement(node);
128 _currentInfo = lastInfo; 126 _currentInfo = lastInfo;
129 127
130 _parent = savedParent; 128 _parent = savedParent;
131 129
132 if (info.identifier == null && _needsIdentifier(info)) { 130 if (_needsIdentifier(info)) {
133 var id = '__e-$_uniqueId'; 131 _ensureParentHasQuery(info);
134 info.identifier = toCamelCase(id); 132 if (info.identifier == null) {
135 // If it's not created in code, we'll query the element by it's id. 133 var id = '__e-$_uniqueId';
136 if (!info.createdInCode) node.attributes['id'] = id; 134 info.identifier = toCamelCase(id);
137 _uniqueId++; 135 // If it's not created in code, we'll query the element by it's id.
136 if (!info.createdInCode) node.attributes['id'] = id;
137 _uniqueId++;
138 }
138 } 139 }
139 } 140 }
140 141
141 /** 142 /**
142 * If this [info] is not created in code, ensure that whichever parent element 143 * If this [info] is not created in code, ensure that whichever parent element
143 * is created in code has been marked appropriately, so we get an identifier. 144 * is created in code has been marked appropriately, so we get an identifier.
144 */ 145 */
145 static void _ensureParentHasQuery(ElementInfo info) { 146 static void _ensureParentHasQuery(ElementInfo info) {
146 if (info.isRoot || info.createdInCode) return; 147 if (info.isRoot || info.createdInCode) return;
147 148
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 end = text.indexOf('}}', start); 750 end = text.indexOf('}}', start);
750 if (end < 0) { 751 if (end < 0) {
751 start = length; 752 start = length;
752 return false; 753 return false;
753 } 754 }
754 // For consistency, start and end both include the curly braces. 755 // For consistency, start and end both include the curly braces.
755 end += 2; 756 end += 2;
756 return true; 757 return true;
757 } 758 }
758 } 759 }
OLDNEW
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698