| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of js_ast; | 5 part of js_ast; |
| 6 | 6 |
| 7 class TemplateManager { | 7 class TemplateManager { |
| 8 Map<String, Template> expressionTemplates = new Map<String, Template>(); | 8 Map<String, Template> expressionTemplates = new Map<String, Template>(); |
| 9 Map<String, Template> statementTemplates = new Map<String, Template>(); | 9 Map<String, Template> statementTemplates = new Map<String, Template>(); |
| 10 | 10 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 Method toMethod(item) { | 267 Method toMethod(item) { |
| 268 if (item is Method) return item; | 268 if (item is Method) return item; |
| 269 return error('Interpolated value #$nameOrPosition is not a Method ' | 269 return error('Interpolated value #$nameOrPosition is not a Method ' |
| 270 'or List of Methods: $value'); | 270 'or List of Methods: $value'); |
| 271 } | 271 } |
| 272 if (value is Iterable) return value.map(toMethod); | 272 if (value is Iterable) return value.map(toMethod); |
| 273 return toMethod(value); | 273 return toMethod(value); |
| 274 }; | 274 }; |
| 275 } | 275 } |
| 276 | 276 |
| 277 Instantiator visitInterpolatedPropertyName(InterpolatedPropertyName node) { | |
| 278 var nameOrPosition = node.nameOrPosition; | |
| 279 return (arguments) { | |
| 280 var item = arguments[nameOrPosition]; | |
| 281 if (item is PropertyName) return item; | |
| 282 if (item is String) return new PropertyName(item); | |
| 283 return error('Interpolated value #$nameOrPosition is not a ' | |
| 284 'PropertyName or String: $item'); | |
| 285 }; | |
| 286 } | |
| 287 | |
| 288 Instantiator visitInterpolatedVariableDeclaration( | 277 Instantiator visitInterpolatedVariableDeclaration( |
| 289 InterpolatedVariableDeclaration node) { | 278 InterpolatedVariableDeclaration node) { |
| 290 var nameOrPosition = node.nameOrPosition; | 279 var nameOrPosition = node.nameOrPosition; |
| 291 return (arguments) { | 280 return (arguments) { |
| 292 var item = arguments[nameOrPosition]; | 281 var item = arguments[nameOrPosition]; |
| 293 if (item is VariableDeclaration) return item; | 282 if (item is VariableDeclaration) return item; |
| 294 if (item is String) return new VariableDeclaration(item); | 283 if (item is String) return new VariableDeclaration(item); |
| 295 return error('Interpolated value #$nameOrPosition is not a ' | 284 return error('Interpolated value #$nameOrPosition is not a ' |
| 296 'VariableDeclaration or String: $item'); | 285 'VariableDeclaration or String: $item'); |
| 297 }; | 286 }; |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 734 } |
| 746 | 735 |
| 747 Instantiator visitProperty(Property node) { | 736 Instantiator visitProperty(Property node) { |
| 748 Instantiator makeName = visit(node.name); | 737 Instantiator makeName = visit(node.name); |
| 749 Instantiator makeValue = visit(node.value); | 738 Instantiator makeValue = visit(node.value); |
| 750 return (arguments) { | 739 return (arguments) { |
| 751 return new Property(makeName(arguments), makeValue(arguments)); | 740 return new Property(makeName(arguments), makeValue(arguments)); |
| 752 }; | 741 }; |
| 753 } | 742 } |
| 754 | 743 |
| 755 Instantiator visitPropertyName(PropertyName node) => | |
| 756 (arguments) => new PropertyName(node.name); | |
| 757 | |
| 758 Instantiator visitRegExpLiteral(RegExpLiteral node) => | 744 Instantiator visitRegExpLiteral(RegExpLiteral node) => |
| 759 (arguments) => new RegExpLiteral(node.pattern); | 745 (arguments) => new RegExpLiteral(node.pattern); |
| 760 | 746 |
| 761 Instantiator visitTemplateString(TemplateString node) { | 747 Instantiator visitTemplateString(TemplateString node) { |
| 762 Iterable makeElements = | 748 Iterable makeElements = |
| 763 node.elements.map((e) => e is String ? e : visit(e)); | 749 node.elements.map((e) => e is String ? e : visit(e)); |
| 764 return (arguments) { | 750 return (arguments) { |
| 765 return new TemplateString(makeElements | 751 return new TemplateString(makeElements |
| 766 .map((m) => m is String ? m : m(arguments)) | 752 .map((m) => m is String ? m : m(arguments)) |
| 767 .toList(growable: false)); | 753 .toList(growable: false)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 if (count != before) containsInterpolatedNode.add(node); | 845 if (count != before) containsInterpolatedNode.add(node); |
| 860 return null; | 846 return null; |
| 861 } | 847 } |
| 862 | 848 |
| 863 visitInterpolatedNode(InterpolatedNode node) { | 849 visitInterpolatedNode(InterpolatedNode node) { |
| 864 containsInterpolatedNode.add(node); | 850 containsInterpolatedNode.add(node); |
| 865 if (node.isNamed) holeNames.add(node.nameOrPosition); | 851 if (node.isNamed) holeNames.add(node.nameOrPosition); |
| 866 ++count; | 852 ++count; |
| 867 } | 853 } |
| 868 } | 854 } |
| OLD | NEW |