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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 if (value is Literal) return value; | 223 if (value is Literal) return value; |
224 error('Interpolated value #$nameOrPosition is not a Literal: $value'); | 224 error('Interpolated value #$nameOrPosition is not a Literal: $value'); |
225 }; | 225 }; |
226 } | 226 } |
227 | 227 |
228 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { | 228 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { |
229 var nameOrPosition = node.nameOrPosition; | 229 var nameOrPosition = node.nameOrPosition; |
230 return (arguments) { | 230 return (arguments) { |
231 var value = arguments[nameOrPosition]; | 231 var value = arguments[nameOrPosition]; |
232 | 232 |
233 Identifier toIdentifier(item) { | 233 Parameter toIdentifier(item) { |
234 if (item is Identifier) return item; | 234 if (item is Parameter) return item; |
235 if (item is String) return new Identifier(item); | 235 if (item is String) return new Identifier(item); |
236 return error('Interpolated value #$nameOrPosition is not an Identifier' | 236 return error('Interpolated value #$nameOrPosition is not an Identifier' |
237 ' or List of Identifiers: $value'); | 237 ' or List of Identifiers: $value'); |
238 } | 238 } |
239 if (value is Iterable) return value.map(toIdentifier); | 239 if (value is Iterable) return value.map(toIdentifier); |
240 return toIdentifier(value); | 240 return toIdentifier(value); |
241 }; | 241 }; |
242 } | 242 } |
243 | 243 |
244 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { | 244 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 throw new UnimplementedError(); | 819 throw new UnimplementedError(); |
820 | 820 |
821 Instantiator visitImportDeclaration(ImportDeclaration node) => | 821 Instantiator visitImportDeclaration(ImportDeclaration node) => |
822 throw new UnimplementedError(); | 822 throw new UnimplementedError(); |
823 | 823 |
824 Instantiator visitExportDeclaration(ExportDeclaration node) => | 824 Instantiator visitExportDeclaration(ExportDeclaration node) => |
825 throw new UnimplementedError(); | 825 throw new UnimplementedError(); |
826 | 826 |
827 Instantiator visitExportClause(ExportClause node) => | 827 Instantiator visitExportClause(ExportClause node) => |
828 throw new UnimplementedError(); | 828 throw new UnimplementedError(); |
829 | |
830 @override | |
831 Instantiator visitDestructuredVariable(DestructuredVariable node) { | |
832 Instantiator makeName = visit(node.name); | |
833 Instantiator makeStructure = visit(node.structure); | |
834 Instantiator makeDefaultValue = visit(node.defaultValue); | |
835 return (arguments) { | |
836 return new DestructuredVariable( | |
837 name: makeName(arguments), | |
838 structure: makeStructure(arguments), | |
839 defaultValue: makeDefaultValue(arguments)); | |
840 }; | |
841 } | |
842 | |
843 @override | |
844 Instantiator visitArrayBindingPattern(ArrayBindingPattern node) { | |
845 List<Instantiator> makeVars = node.variables.map(this.visit).toList(); | |
846 return (arguments) { | |
847 return new ArrayBindingPattern(makeVars.map((m) => m(arguments)).toList()) ; | |
Jennifer Messerly
2015/12/02 20:41:09
long line
ochafik
2015/12/02 21:56:08
Done.
| |
848 }; | |
849 } | |
850 | |
851 @override | |
852 Instantiator visitObjectBindingPattern(ObjectBindingPattern node) { | |
853 List<Instantiator> makeVars = node.variables.map(this.visit).toList(); | |
854 return (arguments) { | |
855 return new ObjectBindingPattern( | |
856 makeVars.map((m) => m(arguments)).toList()); | |
857 }; | |
858 } | |
829 } | 859 } |
830 | 860 |
831 /** | 861 /** |
832 * InterpolatedNodeAnalysis determines which AST trees contain | 862 * InterpolatedNodeAnalysis determines which AST trees contain |
833 * [InterpolatedNode]s, and the names of the named interpolated nodes. | 863 * [InterpolatedNode]s, and the names of the named interpolated nodes. |
834 */ | 864 */ |
835 class InterpolatedNodeAnalysis extends BaseVisitor { | 865 class InterpolatedNodeAnalysis extends BaseVisitor { |
836 final Set<Node> containsInterpolatedNode = new Set<Node>(); | 866 final Set<Node> containsInterpolatedNode = new Set<Node>(); |
837 final Set<String> holeNames = new Set<String>(); | 867 final Set<String> holeNames = new Set<String>(); |
838 int count = 0; | 868 int count = 0; |
(...skipping 13 matching lines...) Expand all Loading... | |
852 if (count != before) containsInterpolatedNode.add(node); | 882 if (count != before) containsInterpolatedNode.add(node); |
853 return null; | 883 return null; |
854 } | 884 } |
855 | 885 |
856 visitInterpolatedNode(InterpolatedNode node) { | 886 visitInterpolatedNode(InterpolatedNode node) { |
857 containsInterpolatedNode.add(node); | 887 containsInterpolatedNode.add(node); |
858 if (node.isNamed) holeNames.add(node.nameOrPosition); | 888 if (node.isNamed) holeNames.add(node.nameOrPosition); |
859 ++count; | 889 ++count; |
860 } | 890 } |
861 } | 891 } |
OLD | NEW |