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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 String op = node.op; | 632 String op = node.op; |
633 return (arguments) => new Postfix(op, makeOperand(arguments)); | 633 return (arguments) => new Postfix(op, makeOperand(arguments)); |
634 } | 634 } |
635 | 635 |
636 Instantiator visitThis(This node) => (arguments) => new This(); | 636 Instantiator visitThis(This node) => (arguments) => new This(); |
637 Instantiator visitSuper(Super node) => (arguments) => new Super(); | 637 Instantiator visitSuper(Super node) => (arguments) => new Super(); |
638 | 638 |
639 Instantiator visitIdentifier(Identifier node) => | 639 Instantiator visitIdentifier(Identifier node) => |
640 (arguments) => new Identifier(node.name); | 640 (arguments) => new Identifier(node.name); |
641 | 641 |
| 642 Instantiator visitSpread(Spread node) => |
| 643 (args) => new Spread(visit(node.argument)(args)); |
| 644 |
| 645 Instantiator visitRestParameter(RestParameter node) => |
| 646 (args) => new RestParameter(visit(node.parameter)(args)); |
| 647 |
642 Instantiator visitAccess(PropertyAccess node) { | 648 Instantiator visitAccess(PropertyAccess node) { |
643 Instantiator makeReceiver = visit(node.receiver); | 649 Instantiator makeReceiver = visit(node.receiver); |
644 Instantiator makeSelector = visit(node.selector); | 650 Instantiator makeSelector = visit(node.selector); |
645 return (arguments) => | 651 return (arguments) => |
646 new PropertyAccess(makeReceiver(arguments), makeSelector(arguments)); | 652 new PropertyAccess(makeReceiver(arguments), makeSelector(arguments)); |
647 } | 653 } |
648 | 654 |
649 Instantiator visitNamedFunction(NamedFunction node) { | 655 Instantiator visitNamedFunction(NamedFunction node) { |
650 Instantiator makeDeclaration = visit(node.name); | 656 Instantiator makeDeclaration = visit(node.name); |
651 Instantiator makeFunction = visit(node.function); | 657 Instantiator makeFunction = visit(node.function); |
652 return (arguments) => | 658 return (arguments) => |
653 new NamedFunction(makeDeclaration(arguments), makeFunction(arguments)); | 659 new NamedFunction(makeDeclaration(arguments), makeFunction(arguments)); |
654 } | 660 } |
655 | 661 |
656 Instantiator visitFunctionExpression(FunctionExpression node) { | 662 Instantiator visitFunctionExpression(FunctionExpression node) { |
657 List<Instantiator> paramMakers = node.params.map(visitSplayable).toList(); | 663 List<Instantiator> paramMakers = node.params.map(visitSplayable).toList(); |
658 Instantiator makeBody = visit(node.body); | 664 Instantiator makeBody = visit(node.body); |
659 // TODO(sra): Avoid copying params if no interpolation or forced copying. | 665 // TODO(sra): Avoid copying params if no interpolation or forced copying. |
660 return (arguments) { | 666 return (arguments) { |
661 List<Identifier> params = <Identifier>[]; | 667 List<Parameter> params = <Parameter>[]; |
662 for (Instantiator instantiator in paramMakers) { | 668 for (Instantiator instantiator in paramMakers) { |
663 var result = instantiator(arguments); | 669 var result = instantiator(arguments); |
664 if (result is Iterable) { | 670 if (result is Iterable) { |
665 params.addAll(result); | 671 params.addAll(result); |
666 } else { | 672 } else { |
667 params.add(result); | 673 params.add(result); |
668 } | 674 } |
669 } | 675 } |
670 var body = makeBody(arguments); | 676 var body = makeBody(arguments); |
671 if (node is ArrowFun) { | 677 if (node is ArrowFun) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 if (count != before) containsInterpolatedNode.add(node); | 846 if (count != before) containsInterpolatedNode.add(node); |
841 return null; | 847 return null; |
842 } | 848 } |
843 | 849 |
844 visitInterpolatedNode(InterpolatedNode node) { | 850 visitInterpolatedNode(InterpolatedNode node) { |
845 containsInterpolatedNode.add(node); | 851 containsInterpolatedNode.add(node); |
846 if (node.isNamed) holeNames.add(node.nameOrPosition); | 852 if (node.isNamed) holeNames.add(node.nameOrPosition); |
847 ++count; | 853 ++count; |
848 } | 854 } |
849 } | 855 } |
OLD | NEW |