OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dev_compiler.src.codegen.js_metalet; | 5 library dev_compiler.src.codegen.js_metalet; |
6 | 6 |
7 // TODO(jmesserly): import from its own package | 7 // TODO(jmesserly): import from its own package |
8 import 'package:dev_compiler/src/js/js_ast.dart'; | 8 import 'package:dev_compiler/src/js/js_ast.dart'; |
9 import 'package:dev_compiler/src/js/precedence.dart'; | 9 import 'package:dev_compiler/src/js/precedence.dart'; |
10 | 10 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 var params = []; | 125 var params = []; |
126 var values = []; | 126 var values = []; |
127 var block = _build(params, values, new Block(statements)); | 127 var block = _build(params, values, new Block(statements)); |
128 if (params.isEmpty) return block; | 128 if (params.isEmpty) return block; |
129 | 129 |
130 var vars = []; | 130 var vars = []; |
131 for (int i = 0; i < params.length; i++) { | 131 for (int i = 0; i < params.length; i++) { |
132 vars.add(new VariableInitialization(params[i], values[i])); | 132 vars.add(new VariableInitialization(params[i], values[i])); |
133 } | 133 } |
134 | 134 |
135 return new Block( | 135 return new Block(<Statement>[ |
136 [new VariableDeclarationList('let', vars).toStatement(), block]); | 136 new VariableDeclarationList('let', vars).toStatement(), |
| 137 block |
| 138 ]); |
137 } | 139 } |
138 | 140 |
139 Node _build(List<TemporaryId> params, List<Expression> values, Node node) { | 141 Node _build(List<TemporaryId> params, List<Expression> values, Node node) { |
140 // Visit the tree and count how many times each temp was used. | 142 // Visit the tree and count how many times each temp was used. |
141 var counter = new _VariableUseCounter(); | 143 var counter = new _VariableUseCounter(); |
142 node.accept(counter); | 144 node.accept(counter); |
143 // Also count the init expressions. | 145 // Also count the init expressions. |
144 for (var init in variables.values) init.accept(counter); | 146 for (var init in variables.values) init.accept(counter); |
145 | 147 |
146 var substitutions = {}; | 148 var substitutions = {}; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 bool found = false; | 233 bool found = false; |
232 _IdentFinder(this.name); | 234 _IdentFinder(this.name); |
233 | 235 |
234 visitIdentifier(Identifier node) { | 236 visitIdentifier(Identifier node) { |
235 if (node.name == name) found = true; | 237 if (node.name == name) found = true; |
236 } | 238 } |
237 visitNode(Node node) { | 239 visitNode(Node node) { |
238 if (!found) super.visitNode(node); | 240 if (!found) super.visitNode(node); |
239 } | 241 } |
240 } | 242 } |
OLD | NEW |