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 'package:dev_compiler/src/js/js_ast.dart'; | 7 import 'package:dev_compiler/src/js/js_ast.dart'; |
8 | 8 |
9 /// Marker subclass for temporary variables. | 9 /// Marker subclass for temporary variables. |
10 /// We treat these as being in a different scope from other identifiers, and | 10 /// We treat these as being in a different scope from other identifiers, and |
(...skipping 22 matching lines...) Expand all Loading... |
33 final renames = new Map<String, String>(); | 33 final renames = new Map<String, String>(); |
34 | 34 |
35 JSNamer(Node node) { | 35 JSNamer(Node node) { |
36 node.accept(new _NameCollector(usedNames)); | 36 node.accept(new _NameCollector(usedNames)); |
37 } | 37 } |
38 | 38 |
39 String getName(Identifier node) { | 39 String getName(Identifier node) { |
40 var name = node.name; | 40 var name = node.name; |
41 if (node is JSTemporary) { | 41 if (node is JSTemporary) { |
42 return _rename(name, valid: true); | 42 return _rename(name, valid: true); |
43 } else if (invalidJSVariableName(name)) { | 43 } else if (node.allowRename && invalidJSVariableName(name)) { |
44 return _rename(name, valid: false); | 44 return _rename(name, valid: false); |
45 } | 45 } |
46 return name; | 46 return name; |
47 } | 47 } |
48 | 48 |
49 String _rename(String name, {bool valid}) { | 49 String _rename(String name, {bool valid}) { |
50 var candidate = renames[name]; | 50 var candidate = renames[name]; |
51 if (candidate != null) return candidate; | 51 if (candidate != null) return candidate; |
52 | 52 |
53 // Try to use the temp's name, otherwise rename. | 53 // Try to use the temp's name, otherwise rename. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 /// In particular, "caller" "callee" and "arguments" cannot be used. | 130 /// In particular, "caller" "callee" and "arguments" cannot be used. |
131 bool invalidJSStaticMethodName(String name) { | 131 bool invalidJSStaticMethodName(String name) { |
132 switch (name) { | 132 switch (name) { |
133 case "arguments": | 133 case "arguments": |
134 case "caller": | 134 case "caller": |
135 case "callee": | 135 case "callee": |
136 return true; | 136 return true; |
137 } | 137 } |
138 return false; | 138 return false; |
139 } | 139 } |
OLD | NEW |