Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: lib/src/codegen/js_metalet.dart

Issue 1767803002: a few small refactorings to closure workarounds (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/codegen/js_printer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(jmesserly): import from its own package 5 // TODO(jmesserly): import from its own package
6 import '../js/js_ast.dart'; 6 import '../js/js_ast.dart';
7 import '../js/precedence.dart'; 7 import '../js/precedence.dart';
8 8
9 import 'js_names.dart' show TemporaryId; 9 import 'js_names.dart' show TemporaryId;
10 10
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 var newBody = new Expression.binary([assign]..addAll(body), ','); 268 var newBody = new Expression.binary([assign]..addAll(body), ',');
269 Binary comma = new Template(null, newBody).safeCreate({name: left}); 269 Binary comma = new Template(null, newBody).safeCreate({name: left});
270 return new MetaLet(vars, comma.commaToExpressionList(), 270 return new MetaLet(vars, comma.commaToExpressionList(),
271 statelessResult: statelessResult); 271 statelessResult: statelessResult);
272 } 272 }
273 } 273 }
274 274
275 class _VariableUseCounter extends BaseVisitor { 275 class _VariableUseCounter extends BaseVisitor {
276 final counts = <String, int>{}; 276 final counts = <String, int>{};
277 @override visitInterpolatedExpression(InterpolatedExpression node) { 277 @override
278 visitInterpolatedExpression(InterpolatedExpression node) {
278 int n = counts[node.nameOrPosition]; 279 int n = counts[node.nameOrPosition];
279 counts[node.nameOrPosition] = n == null ? 1 : n + 1; 280 counts[node.nameOrPosition] = n == null ? 1 : n + 1;
280 } 281 }
281 } 282 }
282 283
283 class _IdentFinder extends BaseVisitor { 284 class _IdentFinder extends BaseVisitor {
284 final String name; 285 final String name;
285 bool found = false; 286 bool found = false;
286 _IdentFinder(this.name); 287 _IdentFinder(this.name);
287 288
288 @override visitIdentifier(Identifier node) { 289 @override
290 visitIdentifier(Identifier node) {
289 if (node.name == name) found = true; 291 if (node.name == name) found = true;
290 } 292 }
291 293
292 @override visitNode(Node node) { 294 @override
295 visitNode(Node node) {
293 if (!found) super.visitNode(node); 296 if (!found) super.visitNode(node);
294 } 297 }
295 } 298 }
296 299
297 class _YieldFinder extends BaseVisitor { 300 class _YieldFinder extends BaseVisitor {
298 bool hasYield = false; 301 bool hasYield = false;
299 bool hasThis = false; 302 bool hasThis = false;
300 bool _nestedFunction = false; 303 bool _nestedFunction = false;
301 @override visitThis(This node) { 304 @override
305 visitThis(This node) {
302 hasThis = true; 306 hasThis = true;
303 } 307 }
304 308
305 @override visitFunctionExpression(FunctionExpression node) { 309 @override
310 visitFunctionExpression(FunctionExpression node) {
306 var savedNested = _nestedFunction; 311 var savedNested = _nestedFunction;
307 _nestedFunction = true; 312 _nestedFunction = true;
308 super.visitFunctionExpression(node); 313 super.visitFunctionExpression(node);
309 _nestedFunction = savedNested; 314 _nestedFunction = savedNested;
310 } 315 }
311 316
312 @override visitYield(Yield node) { 317 @override
318 visitYield(Yield node) {
313 if (!_nestedFunction) hasYield = true; 319 if (!_nestedFunction) hasYield = true;
314 } 320 }
315 321
316 @override visitNode(Node node) { 322 @override
323 visitNode(Node node) {
317 if (!hasYield) super.visitNode(node); 324 if (!hasYield) super.visitNode(node);
318 } 325 }
319 } 326 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/codegen/js_printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698