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 /** Collects several code emitters for the template tool. */ | 5 /** Collects several code emitters for the template tool. */ |
| 6 // TODO(sigmund): add visitor that applies all emitters on a component | 6 // TODO(sigmund): add visitor that applies all emitters on a component |
| 7 // TODO(sigmund): add support for conditionals, so context is changed at that | 7 // TODO(sigmund): add support for conditionals, so context is changed at that |
| 8 // point. | 8 // point. |
| 9 library emitters; | 9 library emitters; |
| 10 | 10 |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 _removeChildNodes(printer); | 508 _removeChildNodes(printer); |
| 509 | 509 |
| 510 printer.add('} else if (!_isVisible$id && showNow) {') | 510 printer.add('} else if (!_isVisible$id && showNow) {') |
| 511 .add('_isVisible$id = true;') | 511 .add('_isVisible$id = true;') |
| 512 .add(_childrenCreated); | 512 .add(_childrenCreated); |
| 513 | 513 |
| 514 if (info.isTemplateElement) { | 514 if (info.isTemplateElement) { |
| 515 if (info.children.length > 0) { | 515 if (info.children.length > 0) { |
| 516 var nodes = info.children.map(_createChildExpression); | 516 var nodes = info.children.map(_createChildExpression); |
| 517 nodes[nodes.length - 1] = '_endPosition$id = ${nodes.last}'; | 517 nodes[nodes.length - 1] = '_endPosition$id = ${nodes.last}'; |
| 518 printer.add('autogenerated.insertAllBefore($id.parent, $id.nextNode,'); | 518 printer.add( |
| 519 'autogenerated.insertAllBefore($id.parentNode, $id.nextNode,'); | |
|
Jennifer Messerly
2012/12/12 19:47:18
+2 spaces?
Siggi Cherem (dart-lang)
2012/12/12 19:57:42
Done.
| |
| 519 printer.add('[${Strings.join(nodes, ", ")}]);'); | 520 printer.add('[${Strings.join(nodes, ", ")}]);'); |
| 520 } | 521 } |
| 521 } else { | 522 } else { |
| 522 // conditional as attributes mean that the whole conditional is a single | 523 // conditional as attributes mean that the whole conditional is a single |
| 523 // node. | 524 // node. |
| 524 assert(info.children.length == 1); | 525 assert(info.children.length == 1); |
| 525 var exp = _createChildExpression(info.children[0]); | 526 var exp = _createChildExpression(info.children[0]); |
| 526 printer.add('$id.parent.insertBefore($exp, $id.nextNode);'); | 527 printer.add('$id.parentNode.insertBefore($exp, $id.nextNode);'); |
|
Jennifer Messerly
2012/12/12 19:47:18
Can we keep using using:
http://api.dartlang.org/
Siggi Cherem (dart-lang)
2012/12/12 19:57:42
I tried, but I was hitting bugs with ShadowRoot be
| |
| 527 } | 528 } |
| 528 | 529 |
| 529 printer.add(_childrenInserted).add('''\n}\n}));\n'''); | 530 printer.add(_childrenInserted).add('''\n}\n}));\n'''); |
| 530 } | 531 } |
| 531 | 532 |
| 532 void emitRemoved(Context context) { | 533 void emitRemoved(Context context) { |
| 533 super.emitRemoved(context); | 534 super.emitRemoved(context); |
| 534 var id = info.identifier; | 535 var id = info.identifier; |
| 535 var printer = context.removedMethod; | 536 var printer = context.removedMethod; |
| 536 printer.add('if (_isVisible$id) {'); | 537 printer.add('if (_isVisible$id) {'); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 } | 608 } |
| 608 | 609 |
| 609 printer.add('for (var $iterExpr) {') | 610 printer.add('for (var $iterExpr) {') |
| 610 .add(_childrenDeclarations) | 611 .add(_childrenDeclarations) |
| 611 .add(_childrenCreated); | 612 .add(_childrenCreated); |
| 612 | 613 |
| 613 if (info.children.length > 0) { | 614 if (info.children.length > 0) { |
| 614 var nodes = info.children.map(_createChildExpression); | 615 var nodes = info.children.map(_createChildExpression); |
| 615 if (info.isTemplateElement) { | 616 if (info.isTemplateElement) { |
| 616 nodes[nodes.length - 1] = '_endPosition$id = ${nodes.last}'; | 617 nodes[nodes.length - 1] = '_endPosition$id = ${nodes.last}'; |
| 617 printer.add('autogenerated.insertAllBefore($id.parent, __insert_$id,'); | 618 printer.add( |
| 619 'autogenerated.insertAllBefore($id.parentNode, __insert_$id,'); | |
| 618 printer.add('[${Strings.join(nodes, ", ")}]);'); | 620 printer.add('[${Strings.join(nodes, ", ")}]);'); |
| 619 } else { | 621 } else { |
| 620 printer.add('$id.nodes.addAll([${Strings.join(nodes, ", ")}]);'); | 622 printer.add('$id.nodes.addAll([${Strings.join(nodes, ", ")}]);'); |
| 621 } | 623 } |
| 622 } | 624 } |
| 623 | 625 |
| 624 printer.add(_childrenInserted) | 626 printer.add(_childrenInserted) |
| 625 .add('_removeChild$id.add(() {') | 627 .add('_removeChild$id.add(() {') |
| 626 .add(_childrenRemoved) | 628 .add(_childrenRemoved) |
| 627 .add('});\n}\n}));'); | 629 .add('});\n}\n}));'); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 } | 941 } |
| 940 typeName = htmlElementExtends[typeName]; | 942 typeName = htmlElementExtends[typeName]; |
| 941 } | 943 } |
| 942 // If we didn't find a DOM setter, and this is a component, set a property on | 944 // If we didn't find a DOM setter, and this is a component, set a property on |
| 943 // the component. | 945 // the component. |
| 944 if (info.component != null && !name.startsWith('data-')) { | 946 if (info.component != null && !name.startsWith('data-')) { |
| 945 return 'xtag.${toCamelCase(name)}'; | 947 return 'xtag.${toCamelCase(name)}'; |
| 946 } | 948 } |
| 947 return "attributes['$name']"; | 949 return "attributes['$name']"; |
| 948 } | 950 } |
| OLD | NEW |