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 part of js_ast; | 5 part of js_ast; |
6 | 6 |
7 abstract class NodeVisitor<T> { | 7 abstract class NodeVisitor<T> { |
8 T visitProgram(Program node); | 8 T visitProgram(Program node); |
9 | 9 |
10 T visitBlock(Block node); | 10 T visitBlock(Block node); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 T visitInterpolatedLiteral(InterpolatedLiteral node); | 85 T visitInterpolatedLiteral(InterpolatedLiteral node); |
86 T visitInterpolatedParameter(InterpolatedParameter node); | 86 T visitInterpolatedParameter(InterpolatedParameter node); |
87 T visitInterpolatedSelector(InterpolatedSelector node); | 87 T visitInterpolatedSelector(InterpolatedSelector node); |
88 T visitInterpolatedStatement(InterpolatedStatement node); | 88 T visitInterpolatedStatement(InterpolatedStatement node); |
89 T visitInterpolatedMethod(InterpolatedMethod node); | 89 T visitInterpolatedMethod(InterpolatedMethod node); |
90 T visitInterpolatedIdentifier(InterpolatedIdentifier node); | 90 T visitInterpolatedIdentifier(InterpolatedIdentifier node); |
91 | 91 |
92 T visitArrayBindingPattern(ArrayBindingPattern node); | 92 T visitArrayBindingPattern(ArrayBindingPattern node); |
93 T visitObjectBindingPattern(ObjectBindingPattern node); | 93 T visitObjectBindingPattern(ObjectBindingPattern node); |
94 T visitDestructuredVariable(DestructuredVariable node); | 94 T visitDestructuredVariable(DestructuredVariable node); |
| 95 T visitSimpleBindingPattern(SimpleBindingPattern node); |
95 } | 96 } |
96 | 97 |
97 class BaseVisitor<T> implements NodeVisitor<T> { | 98 class BaseVisitor<T> implements NodeVisitor<T> { |
98 T visitNode(Node node) { | 99 T visitNode(Node node) { |
99 node.visitChildren(this); | 100 node.visitChildren(this); |
100 return null; | 101 return null; |
101 } | 102 } |
102 | 103 |
103 T visitProgram(Program node) => visitNode(node); | 104 T visitProgram(Program node) => visitNode(node); |
104 | 105 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 215 |
215 T visitAwait(Await node) => visitExpression(node); | 216 T visitAwait(Await node) => visitExpression(node); |
216 T visitDartYield(DartYield node) => visitStatement(node); | 217 T visitDartYield(DartYield node) => visitStatement(node); |
217 | 218 |
218 T visitBindingPattern(BindingPattern node) => visitNode(node); | 219 T visitBindingPattern(BindingPattern node) => visitNode(node); |
219 T visitArrayBindingPattern(ArrayBindingPattern node) | 220 T visitArrayBindingPattern(ArrayBindingPattern node) |
220 => visitBindingPattern(node); | 221 => visitBindingPattern(node); |
221 T visitObjectBindingPattern(ObjectBindingPattern node) | 222 T visitObjectBindingPattern(ObjectBindingPattern node) |
222 => visitBindingPattern(node); | 223 => visitBindingPattern(node); |
223 T visitDestructuredVariable(DestructuredVariable node) => visitNode(node); | 224 T visitDestructuredVariable(DestructuredVariable node) => visitNode(node); |
| 225 T visitSimpleBindingPattern(SimpleBindingPattern node) => visitNode(node); |
224 } | 226 } |
225 | 227 |
226 abstract class Node { | 228 abstract class Node { |
227 /// Sets the source location of this node. For performance reasons, we allow | 229 /// Sets the source location of this node. For performance reasons, we allow |
228 /// setting this after construction. | 230 /// setting this after construction. |
229 Object sourceInformation; | 231 Object sourceInformation; |
230 | 232 |
231 ClosureAnnotation _closureAnnotation; | 233 ClosureAnnotation _closureAnnotation; |
232 /// Closure annotation of this node. | 234 /// Closure annotation of this node. |
233 ClosureAnnotation get closureAnnotation => _closureAnnotation; | 235 ClosureAnnotation get closureAnnotation => _closureAnnotation; |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); | 772 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); |
771 | 773 |
772 VariableInitialization _clone() => | 774 VariableInitialization _clone() => |
773 new VariableInitialization(declaration, value); | 775 new VariableInitialization(declaration, value); |
774 } | 776 } |
775 | 777 |
776 abstract class VariableBinding extends Expression { | 778 abstract class VariableBinding extends Expression { |
777 } | 779 } |
778 | 780 |
779 class DestructuredVariable extends Expression implements Parameter { | 781 class DestructuredVariable extends Expression implements Parameter { |
780 final Identifier name; | 782 /// [LiteralString] or [Identifier]. |
| 783 final Expression name; |
781 final BindingPattern structure; | 784 final BindingPattern structure; |
782 final Expression defaultValue; | 785 final Expression defaultValue; |
783 DestructuredVariable({this.name, this.structure, this.defaultValue}) { | 786 DestructuredVariable({this.name, this.structure, this.defaultValue}) { |
784 assert(name != null || structure != null); | 787 assert(name != null || structure != null); |
785 } | 788 } |
786 | 789 |
787 accept(NodeVisitor visitor) => visitor.visitDestructuredVariable(this); | 790 accept(NodeVisitor visitor) => visitor.visitDestructuredVariable(this); |
788 void visitChildren(NodeVisitor visitor) { | 791 void visitChildren(NodeVisitor visitor) { |
789 name?.accept(visitor); | 792 name?.accept(visitor); |
790 structure?.accept(visitor); | 793 structure?.accept(visitor); |
791 defaultValue?.accept(visitor); | 794 defaultValue?.accept(visitor); |
792 } | 795 } |
793 | 796 |
794 /// Avoid parenthesis when pretty-printing. | 797 /// Avoid parenthesis when pretty-printing. |
795 @override int get precedenceLevel => PRIMARY; | 798 @override int get precedenceLevel => PRIMARY; |
796 @override Node _clone() => | 799 @override Node _clone() => |
797 new DestructuredVariable( | 800 new DestructuredVariable( |
798 name: name, structure: structure, defaultValue: defaultValue); | 801 name: name, structure: structure, defaultValue: defaultValue); |
799 } | 802 } |
800 | 803 |
801 abstract class BindingPattern extends Expression implements VariableBinding { | 804 abstract class BindingPattern extends Expression implements VariableBinding { |
802 final List<DestructuredVariable> variables; | 805 final List<DestructuredVariable> variables; |
803 BindingPattern(this.variables); | 806 BindingPattern(this.variables); |
804 | 807 |
805 void visitChildren(NodeVisitor visitor) { | 808 void visitChildren(NodeVisitor visitor) { |
806 for (DestructuredVariable v in variables) v.accept(visitor); | 809 for (DestructuredVariable v in variables) v.accept(visitor); |
807 } | 810 } |
808 } | 811 } |
809 | 812 |
| 813 class SimpleBindingPattern extends BindingPattern { |
| 814 final Identifier name; |
| 815 SimpleBindingPattern(Identifier name) |
| 816 : super([new DestructuredVariable(name: name)]), this.name = name; |
| 817 accept(NodeVisitor visitor) => visitor.visitSimpleBindingPattern(this); |
| 818 |
| 819 /// Avoid parenthesis when pretty-printing. |
| 820 @override int get precedenceLevel => PRIMARY; |
| 821 @override Node _clone() => new SimpleBindingPattern(name); |
| 822 } |
| 823 |
810 class ObjectBindingPattern extends BindingPattern { | 824 class ObjectBindingPattern extends BindingPattern { |
811 ObjectBindingPattern(List<DestructuredVariable> variables) | 825 ObjectBindingPattern(List<DestructuredVariable> variables) |
812 : super(variables); | 826 : super(variables); |
813 accept(NodeVisitor visitor) => visitor.visitObjectBindingPattern(this); | 827 accept(NodeVisitor visitor) => visitor.visitObjectBindingPattern(this); |
814 | 828 |
815 /// Avoid parenthesis when pretty-printing. | 829 /// Avoid parenthesis when pretty-printing. |
816 @override int get precedenceLevel => PRIMARY; | 830 @override int get precedenceLevel => PRIMARY; |
817 @override Node _clone() => new ObjectBindingPattern(variables); | 831 @override Node _clone() => new ObjectBindingPattern(variables); |
818 } | 832 } |
819 | 833 |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 | 1769 |
1756 final List<ModuleItem> body; | 1770 final List<ModuleItem> body; |
1757 Module(this.body, {this.name}); | 1771 Module(this.body, {this.name}); |
1758 | 1772 |
1759 accept(NodeVisitor visitor) => visitor.visitModule(this); | 1773 accept(NodeVisitor visitor) => visitor.visitModule(this); |
1760 void visitChildren(NodeVisitor visitor) { | 1774 void visitChildren(NodeVisitor visitor) { |
1761 for (ModuleItem item in body) item.accept(visitor); | 1775 for (ModuleItem item in body) item.accept(visitor); |
1762 } | 1776 } |
1763 Module _clone() => new Module(body); | 1777 Module _clone() => new Module(body); |
1764 } | 1778 } |
OLD | NEW |