| 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 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 | 883 |
| 884 Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier); | 884 Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier); |
| 885 | 885 |
| 886 int get precedenceLevel => CALL; | 886 int get precedenceLevel => CALL; |
| 887 } | 887 } |
| 888 | 888 |
| 889 class ArrowFun extends FunctionExpression { | 889 class ArrowFun extends FunctionExpression { |
| 890 final List<Identifier> params; | 890 final List<Identifier> params; |
| 891 final body; // Expression or Block | 891 final body; // Expression or Block |
| 892 | 892 |
| 893 bool _bindThisWorkaround; // lazy initialized |
| 894 |
| 893 ArrowFun(this.params, this.body); | 895 ArrowFun(this.params, this.body); |
| 894 | 896 |
| 895 accept(NodeVisitor visitor) => visitor.visitArrowFun(this); | 897 accept(NodeVisitor visitor) => visitor.visitArrowFun(this); |
| 896 | 898 |
| 897 void visitChildren(NodeVisitor visitor) { | 899 void visitChildren(NodeVisitor visitor) { |
| 898 for (Identifier param in params) param.accept(visitor); | 900 for (Identifier param in params) param.accept(visitor); |
| 899 body.accept(visitor); | 901 body.accept(visitor); |
| 900 } | 902 } |
| 901 | 903 |
| 902 ArrowFun _clone() => new ArrowFun(params, body); | 904 ArrowFun _clone() => new ArrowFun(params, body); |
| 903 | 905 |
| 906 /// This is a workaround for V8 arrow function bindings being not yet |
| 907 /// implemented. See <https://code.google.com/p/v8/issues/detail?id=2700> |
| 908 bool get bindThisWorkaround { |
| 909 if (_bindThisWorkaround != null) return _bindThisWorkaround; |
| 910 var visitor = new _ThisFinder(); |
| 911 body.accept(visitor); |
| 912 return _bindThisWorkaround = visitor.found; |
| 913 } |
| 914 |
| 904 /// Ensure parens always get generated if necessary. | 915 /// Ensure parens always get generated if necessary. |
| 905 // TODO(jmesserly): I'm not sure the printer is handling this correctly for | 916 // TODO(jmesserly): I'm not sure the printer is handling this correctly for |
| 906 // function() { ... } either. | 917 // function() { ... } either. |
| 907 int get precedenceLevel => ASSIGNMENT; | 918 int get precedenceLevel => bindThisWorkaround ? CALL : ASSIGNMENT; |
| 919 } |
| 920 |
| 921 class _ThisFinder extends BaseVisitor { |
| 922 bool found = false; |
| 923 visitThis(This node) { |
| 924 found = true; |
| 925 } |
| 926 visitNode(Node node) { |
| 927 if (!found) super.visitNode(node); |
| 928 } |
| 908 } | 929 } |
| 909 | 930 |
| 910 class AsyncModifier { | 931 class AsyncModifier { |
| 911 final bool isAsync; | 932 final bool isAsync; |
| 912 final bool isYielding; | 933 final bool isYielding; |
| 913 final String description; | 934 final String description; |
| 914 | 935 |
| 915 const AsyncModifier.sync() | 936 const AsyncModifier.sync() |
| 916 : isAsync = false, | 937 : isAsync = false, |
| 917 isYielding = false, | 938 isYielding = false, |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 final Expression expression; | 1363 final Expression expression; |
| 1343 | 1364 |
| 1344 CommentExpression(this.comment, this.expression); | 1365 CommentExpression(this.comment, this.expression); |
| 1345 | 1366 |
| 1346 int get precedenceLevel => PRIMARY; | 1367 int get precedenceLevel => PRIMARY; |
| 1347 accept(NodeVisitor visitor) => visitor.visitCommentExpression(this); | 1368 accept(NodeVisitor visitor) => visitor.visitCommentExpression(this); |
| 1348 CommentExpression _clone() => new CommentExpression(comment, expression); | 1369 CommentExpression _clone() => new CommentExpression(comment, expression); |
| 1349 | 1370 |
| 1350 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); | 1371 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); |
| 1351 } | 1372 } |
| OLD | NEW |