| 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_names; | 5 library dev_compiler.src.codegen.js_names; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'package:dev_compiler/src/js/js_ast.dart'; | 8 import 'package:dev_compiler/src/js/js_ast.dart'; |
| 9 | 9 |
| 10 /// Unique instance for temporary variables. Will be renamed consistently | 10 /// Unique instance for temporary variables. Will be renamed consistently |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 _RenameVisitor.build(Node root) { | 79 _RenameVisitor.build(Node root) { |
| 80 scope = rootScope; | 80 scope = rootScope; |
| 81 root.accept(this); | 81 root.accept(this); |
| 82 _finishFunctions(); | 82 _finishFunctions(); |
| 83 _finishNames(); | 83 _finishNames(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 declare(Identifier node) { | 86 declare(Identifier node) { |
| 87 var id = identifierKey(node); | 87 var id = identifierKey(node); |
| 88 scope.declared.add(id); | 88 var notAlreadyDeclared = scope.declared.add(id); |
| 89 // Normal identifiers can be declared multiple times, because we don't |
| 90 // implement block scope yet. However temps should only be declared once. |
| 91 assert(notAlreadyDeclared || node is! TemporaryId); |
| 89 _markUsed(node, id, scope); | 92 _markUsed(node, id, scope); |
| 90 } | 93 } |
| 91 | 94 |
| 92 visitIdentifier(Identifier node) { | 95 visitIdentifier(Identifier node) { |
| 93 var id = identifierKey(node); | 96 var id = identifierKey(node); |
| 94 | 97 |
| 95 // Find where the node was declared. | 98 // Find where the node was declared. |
| 96 var declScope = scope; | 99 var declScope = scope; |
| 97 while (declScope != null && !declScope.declared.contains(id)) { | 100 while (declScope != null && !declScope.declared.contains(id)) { |
| 98 declScope = declScope.parent; | 101 declScope = declScope.parent; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 /// In particular, "caller" "callee" and "arguments" cannot be used. | 238 /// In particular, "caller" "callee" and "arguments" cannot be used. |
| 236 bool invalidStaticFieldName(String name) { | 239 bool invalidStaticFieldName(String name) { |
| 237 switch (name) { | 240 switch (name) { |
| 238 case "arguments": | 241 case "arguments": |
| 239 case "caller": | 242 case "caller": |
| 240 case "callee": | 243 case "callee": |
| 241 return true; | 244 return true; |
| 242 } | 245 } |
| 243 return false; | 246 return false; |
| 244 } | 247 } |
| OLD | NEW |