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> implements TypeRefVisitor<T> { | 7 abstract class NodeVisitor<T> implements TypeRefVisitor<T> { |
8 T visitProgram(Program node); | 8 T visitProgram(Program node); |
9 | 9 |
10 T visitBlock(Block node); | 10 T visitBlock(Block node); |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 BindingPattern(this.variables); | 838 BindingPattern(this.variables); |
839 | 839 |
840 void visitChildren(NodeVisitor visitor) { | 840 void visitChildren(NodeVisitor visitor) { |
841 for (DestructuredVariable v in variables) v.accept(visitor); | 841 for (DestructuredVariable v in variables) v.accept(visitor); |
842 } | 842 } |
843 } | 843 } |
844 | 844 |
845 class SimpleBindingPattern extends BindingPattern { | 845 class SimpleBindingPattern extends BindingPattern { |
846 final Identifier name; | 846 final Identifier name; |
847 SimpleBindingPattern(Identifier name) | 847 SimpleBindingPattern(Identifier name) |
848 : super([new DestructuredVariable(name: name)]), this.name = name; | 848 : name = name, |
| 849 super([new DestructuredVariable(name: name)]); |
| 850 |
849 accept(NodeVisitor visitor) => visitor.visitSimpleBindingPattern(this); | 851 accept(NodeVisitor visitor) => visitor.visitSimpleBindingPattern(this); |
850 | 852 |
851 /// Avoid parenthesis when pretty-printing. | 853 /// Avoid parenthesis when pretty-printing. |
852 @override int get precedenceLevel => PRIMARY; | 854 @override int get precedenceLevel => PRIMARY; |
853 @override Node _clone() => new SimpleBindingPattern(name); | 855 @override Node _clone() => new SimpleBindingPattern(name); |
854 } | 856 } |
855 | 857 |
856 class ObjectBindingPattern extends BindingPattern { | 858 class ObjectBindingPattern extends BindingPattern { |
857 ObjectBindingPattern(List<DestructuredVariable> variables) | 859 ObjectBindingPattern(List<DestructuredVariable> variables) |
858 : super(variables); | 860 : super(variables); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 return new Block([left.toStatement(), right.toReturn()]); | 959 return new Block([left.toStatement(), right.toReturn()]); |
958 } | 960 } |
959 | 961 |
960 Statement toYieldStatement({bool star: false}) { | 962 Statement toYieldStatement({bool star: false}) { |
961 if (!isCommaOperator) return super.toYieldStatement(star: star); | 963 if (!isCommaOperator) return super.toYieldStatement(star: star); |
962 return new Block([left.toStatement(), right.toYieldStatement(star: star)]); | 964 return new Block([left.toStatement(), right.toYieldStatement(star: star)]); |
963 } | 965 } |
964 | 966 |
965 List<Expression> commaToExpressionList() { | 967 List<Expression> commaToExpressionList() { |
966 if (!isCommaOperator) throw new StateError('not a comma expression'); | 968 if (!isCommaOperator) throw new StateError('not a comma expression'); |
967 var exprs = []; | 969 var exprs = <Expression>[]; |
968 _flattenComma(exprs, left); | 970 _flattenComma(exprs, left); |
969 _flattenComma(exprs, right); | 971 _flattenComma(exprs, right); |
970 return exprs; | 972 return exprs; |
971 } | 973 } |
972 | 974 |
973 static void _flattenComma(List<Expression> exprs, Expression node) { | 975 static void _flattenComma(List<Expression> exprs, Expression node) { |
974 if (node is Binary && node.isCommaOperator) { | 976 if (node is Binary && node.isCommaOperator) { |
975 _flattenComma(exprs, node.left); | 977 _flattenComma(exprs, node.left); |
976 _flattenComma(exprs, node.right); | 978 _flattenComma(exprs, node.right); |
977 } else { | 979 } else { |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 | 1864 |
1863 final List<ModuleItem> body; | 1865 final List<ModuleItem> body; |
1864 Module(this.body, {this.name}); | 1866 Module(this.body, {this.name}); |
1865 | 1867 |
1866 accept(NodeVisitor visitor) => visitor.visitModule(this); | 1868 accept(NodeVisitor visitor) => visitor.visitModule(this); |
1867 void visitChildren(NodeVisitor visitor) { | 1869 void visitChildren(NodeVisitor visitor) { |
1868 for (ModuleItem item in body) item.accept(visitor); | 1870 for (ModuleItem item in body) item.accept(visitor); |
1869 } | 1871 } |
1870 Module _clone() => new Module(body); | 1872 Module _clone() => new Module(body); |
1871 } | 1873 } |
OLD | NEW |