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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 199 } |
200 | 200 |
201 Instantiator visitSplayableExpression(Node node) { | 201 Instantiator visitSplayableExpression(Node node) { |
202 if (node is InterpolatedExpression) { | 202 if (node is InterpolatedExpression) { |
203 var nameOrPosition = node.nameOrPosition; | 203 var nameOrPosition = node.nameOrPosition; |
204 return (arguments) { | 204 return (arguments) { |
205 var value = arguments[nameOrPosition]; | 205 var value = arguments[nameOrPosition]; |
206 Expression toExpression(item) { | 206 Expression toExpression(item) { |
207 if (item is Expression) return item; | 207 if (item is Expression) return item; |
208 if (item is String) return new Identifier(item); | 208 if (item is String) return new Identifier(item); |
| 209 if (item is Parameter) return item.binding; |
209 return error('Interpolated value #$nameOrPosition is not ' | 210 return error('Interpolated value #$nameOrPosition is not ' |
210 'an Expression or List of Expressions: $value'); | 211 'an Expression or List of Expressions: $value: ${value is Iterable
? value.map((v) => v.runtimeType) : value.runtimeType}'); |
211 } | 212 } |
212 if (value is Iterable) return value.map(toExpression); | 213 if (value is Iterable) return value.map(toExpression); |
213 return toExpression(value); | 214 return toExpression(value); |
214 }; | 215 }; |
215 } | 216 } |
216 return visit(node); | 217 return visit(node); |
217 } | 218 } |
218 | 219 |
219 Instantiator visitInterpolatedLiteral(InterpolatedLiteral node) { | 220 Instantiator visitInterpolatedLiteral(InterpolatedLiteral node) { |
220 var nameOrPosition = node.nameOrPosition; | 221 var nameOrPosition = node.nameOrPosition; |
221 return (arguments) { | 222 return (arguments) { |
222 var value = arguments[nameOrPosition]; | 223 var value = arguments[nameOrPosition]; |
223 if (value is Literal) return value; | 224 if (value is Literal) return value; |
224 error('Interpolated value #$nameOrPosition is not a Literal: $value'); | 225 error('Interpolated value #$nameOrPosition is not a Literal: $value'); |
225 }; | 226 }; |
226 } | 227 } |
227 | 228 |
228 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { | 229 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { |
229 var nameOrPosition = node.nameOrPosition; | 230 var nameOrPosition = node.nameOrPosition; |
| 231 var isRest = node.isRest; |
230 return (arguments) { | 232 return (arguments) { |
231 var value = arguments[nameOrPosition]; | 233 var value = arguments[nameOrPosition]; |
232 | 234 |
233 Parameter toIdentifier(item) { | 235 Parameter toParameter(item, {bool isRest: false}) { |
234 if (item is Parameter) return item; | 236 if (item is Identifier) return new Parameter(item, isRest: isRest); |
235 if (item is String) return new Identifier(item); | 237 if (item is String) return new Parameter(new Identifier(item), isRest: i
sRest); |
236 return error('Interpolated value #$nameOrPosition is not an Identifier' | 238 return error('Interpolated value #$nameOrPosition is not an Parameter' |
237 ' or List of Identifiers: $value'); | 239 ' or List of Parameters: $value: ${value.runtimeType}'); |
238 } | 240 } |
239 if (value is Iterable) return value.map(toIdentifier); | 241 if (value is Iterable) return value.map(toParameter); |
240 return toIdentifier(value); | 242 return toParameter(value, isRest: isRest); |
241 }; | 243 }; |
242 } | 244 } |
243 | 245 |
244 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { | 246 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { |
245 // A selector is an expression, as in `a[selector]`. | 247 // A selector is an expression, as in `a[selector]`. |
246 // A String argument converted into a LiteralString, so `a.#` with argument | 248 // A String argument converted into a LiteralString, so `a.#` with argument |
247 // 'foo' generates `a["foo"]` which prints as `a.foo`. | 249 // 'foo' generates `a["foo"]` which prints as `a.foo`. |
248 var nameOrPosition = node.nameOrPosition; | 250 var nameOrPosition = node.nameOrPosition; |
249 return (arguments) { | 251 return (arguments) { |
250 var value = arguments[nameOrPosition]; | 252 var value = arguments[nameOrPosition]; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 | 622 |
621 Instantiator visitPostfix(Postfix node) { | 623 Instantiator visitPostfix(Postfix node) { |
622 Instantiator makeOperand = visit(node.argument); | 624 Instantiator makeOperand = visit(node.argument); |
623 String op = node.op; | 625 String op = node.op; |
624 return (arguments) => new Postfix(op, makeOperand(arguments)); | 626 return (arguments) => new Postfix(op, makeOperand(arguments)); |
625 } | 627 } |
626 | 628 |
627 Instantiator visitThis(This node) => (arguments) => new This(); | 629 Instantiator visitThis(This node) => (arguments) => new This(); |
628 Instantiator visitSuper(Super node) => (arguments) => new Super(); | 630 Instantiator visitSuper(Super node) => (arguments) => new Super(); |
629 | 631 |
| 632 Instantiator visitParameter(Parameter node) { |
| 633 Instantiator makeBinding = visit(node.binding); |
| 634 Instantiator makeType = visit(node.type); |
| 635 var isRest = node.isRest; |
| 636 return (arguments) => new Parameter( |
| 637 makeBinding(arguments), type: makeType(arguments), isRest: isRest); |
| 638 } |
| 639 |
| 640 Instantiator visitTypeParameter(TypeParameter node) { |
| 641 Instantiator makeName = visit(node.name); |
| 642 Instantiator makeBound = visit(node.bound); |
| 643 return (arguments) => |
| 644 new TypeParameter(makeName(arguments), bound: makeBound(arguments)); |
| 645 } |
| 646 |
630 Instantiator visitIdentifier(Identifier node) => | 647 Instantiator visitIdentifier(Identifier node) => |
631 (arguments) => new Identifier(node.name); | 648 (arguments) => new Identifier(node.name); |
632 | 649 |
633 Instantiator visitSpread(Spread node) => | 650 Instantiator visitSpread(Spread node) => |
634 (args) => new Spread(visit(node.argument)(args)); | 651 (args) => new Spread(visit(node.argument)(args)); |
635 | 652 |
636 Instantiator visitYield(Yield node) => | 653 Instantiator visitYield(Yield node) => |
637 (args) => new Yield(node.value != null ? visit(node.value)(args) : null, | 654 (args) => new Yield(node.value != null ? visit(node.value)(args) : null, |
638 star: node.star); | 655 star: node.star); |
639 | 656 |
640 Instantiator visitRestParameter(RestParameter node) => | |
641 (args) => new RestParameter(visit(node.parameter)(args)); | |
642 | |
643 Instantiator visitAccess(PropertyAccess node) { | 657 Instantiator visitAccess(PropertyAccess node) { |
644 Instantiator makeReceiver = visit(node.receiver); | 658 Instantiator makeReceiver = visit(node.receiver); |
645 Instantiator makeSelector = visit(node.selector); | 659 Instantiator makeSelector = visit(node.selector); |
646 return (arguments) => | 660 return (arguments) => |
647 new PropertyAccess(makeReceiver(arguments), makeSelector(arguments)); | 661 new PropertyAccess(makeReceiver(arguments), makeSelector(arguments)); |
648 } | 662 } |
649 | 663 |
650 Instantiator visitNamedFunction(NamedFunction node) { | 664 Instantiator visitNamedFunction(NamedFunction node) { |
651 Instantiator makeDeclaration = visit(node.name); | 665 Instantiator makeDeclaration = visit(node.name); |
652 Instantiator makeFunction = visit(node.function); | 666 Instantiator makeFunction = visit(node.function); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 if (count != before) containsInterpolatedNode.add(node); | 928 if (count != before) containsInterpolatedNode.add(node); |
915 return null; | 929 return null; |
916 } | 930 } |
917 | 931 |
918 visitInterpolatedNode(InterpolatedNode node) { | 932 visitInterpolatedNode(InterpolatedNode node) { |
919 containsInterpolatedNode.add(node); | 933 containsInterpolatedNode.add(node); |
920 if (node.isNamed) holeNames.add(node.nameOrPosition); | 934 if (node.isNamed) holeNames.add(node.nameOrPosition); |
921 ++count; | 935 ++count; |
922 } | 936 } |
923 } | 937 } |
OLD | NEW |