| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class JsNames { | 5 class JsNames { |
| 6 static final javaScriptKeywords = const <String>[ | 6 static final javaScriptKeywords = const <String>[ |
| 7 // These are current keywords | 7 // These are current keywords |
| 8 "break", "delete", "function", "return", "typeof", "case", "do", "if", | 8 "break", "delete", "function", "return", "typeof", "case", "do", "if", |
| 9 "switch", "var", "catch", "else", "in", "this", "void", "continue", | 9 "switch", "var", "catch", "else", "in", "this", "void", "continue", |
| 10 "false", "instanceof", "throw", "while", "debugger", "finally", "new", | 10 "false", "instanceof", "throw", "while", "debugger", "finally", "new", |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 static Set<String> get reserved() { | 158 static Set<String> get reserved() { |
| 159 if (_reserved === null) { | 159 if (_reserved === null) { |
| 160 _reserved = new Set<String>(); | 160 _reserved = new Set<String>(); |
| 161 _reserved.addAll(reservedPropertySymbols); | 161 _reserved.addAll(reservedPropertySymbols); |
| 162 _reserved.addAll(reservedGlobalSymbols); | 162 _reserved.addAll(reservedGlobalSymbols); |
| 163 _reserved.addAll(javaScriptKeywords); | 163 _reserved.addAll(javaScriptKeywords); |
| 164 } | 164 } |
| 165 return _reserved; | 165 return _reserved; |
| 166 } | 166 } |
| 167 | 167 |
| 168 // TODO(ngeoffray): only the namer should call this method. |
| 169 // Eventually move it there. |
| 170 /* |
| 171 * Returns a name that does not clash with reserved JS keywords, |
| 172 * and also ensures it won't clash with other identifiers. |
| 173 */ |
| 168 static String getValid(String name) { | 174 static String getValid(String name) { |
| 169 if (reserved.contains(name)) { | 175 if (reserved.contains(name)) { |
| 170 name = '\$$name'; | 176 name = '\$$name'; |
| 171 assert(!reserved.contains(name)); | 177 assert(!reserved.contains(name)); |
| 172 } else if (name.contains(@'$')) { | 178 } else if (name.contains(@'$')) { |
| 173 // TODO(ngeoffray): replace with '$$' when frog supports it. | 179 // TODO(ngeoffray): replace with '$$' when frog supports it. |
| 174 name = name.replaceAll(@'$', @'_$'); | 180 name = name.replaceAll(@'$', @'_$'); |
| 175 } | 181 } |
| 176 return name; | 182 return name; |
| 177 } | 183 } |
| 178 } | 184 } |
| OLD | NEW |