| 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 library js_backend.namer; | 5 library js_backend.namer; |
| 6 | 6 |
| 7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; | 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; |
| 10 | 10 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * 3. The `is` and operator uses the following names: | 128 * 3. The `is` and operator uses the following names: |
| 129 * | 129 * |
| 130 * $is<NAME> | 130 * $is<NAME> |
| 131 * $as<NAME> | 131 * $as<NAME> |
| 132 * | 132 * |
| 133 * For local variables, the [Namer] only provides *proposed names*. These names | 133 * For local variables, the [Namer] only provides *proposed names*. These names |
| 134 * must be disambiguated elsewhere. | 134 * must be disambiguated elsewhere. |
| 135 */ | 135 */ |
| 136 class Namer { | 136 class Namer { |
| 137 static const List<String> javaScriptKeywords = const <String>[ | 137 static const List<String> javaScriptKeywords = const <String>[ |
| 138 // These are current keywords. | 138 // ES5 7.6.1.1 Keywords. |
| 139 "break", "delete", "function", "return", "typeof", "case", "do", "if", | 139 'break', |
| 140 "switch", "var", "catch", "else", "in", "this", "void", "continue", | 140 'do', |
| 141 "false", "instanceof", "throw", "while", "debugger", "finally", "new", | 141 'instanceof', |
| 142 "true", "with", "default", "for", "null", "try", | 142 'typeof', |
| 143 'case', |
| 144 'else', |
| 145 'new', |
| 146 'var', |
| 147 'catch', |
| 148 'finally', |
| 149 'return', |
| 150 'void', |
| 151 'continue', |
| 152 'for', |
| 153 'switch', |
| 154 'while', |
| 155 'debugger', |
| 156 'function', |
| 157 'this', |
| 158 'with', |
| 159 'default', |
| 160 'if', |
| 161 'throw', |
| 162 'delete', |
| 163 'in', |
| 164 'try', |
| 143 | 165 |
| 144 // These are future keywords. | 166 // ES5 7.6.1.2 Future Reserved Words. |
| 145 "abstract", "double", "goto", "native", "static", "boolean", "enum", | 167 'class', |
| 146 "implements", "package", "super", "byte", "export", "import", "private", | 168 'enum', |
| 147 "synchronized", "char", "extends", "int", "protected", "throws", | 169 'extends', |
| 148 "class", "final", "interface", "public", "transient", "const", "float", | 170 'super', |
| 149 "long", "short", "volatile" | 171 'const', |
| 172 'export', |
| 173 'import', |
| 174 |
| 175 // ES5 7.6.1.2 Words with semantic restrictions. |
| 176 'implements', |
| 177 'let', |
| 178 'private', |
| 179 'public', |
| 180 'yield', |
| 181 'interface', |
| 182 'package', |
| 183 'protected', |
| 184 'static', |
| 185 |
| 186 // ES6 11.6.2.1 Keywords (including repeats of ES5 to ease comparison with |
| 187 // documents). |
| 188 'break', |
| 189 'do', |
| 190 'in', |
| 191 'typeof', |
| 192 'case', |
| 193 'else', |
| 194 'instanceof', |
| 195 'var', |
| 196 'catch', |
| 197 'export', |
| 198 'new', |
| 199 'void', |
| 200 'class', |
| 201 'extends', |
| 202 'return', |
| 203 'while', |
| 204 'const', |
| 205 'finally', |
| 206 'super', |
| 207 'with', |
| 208 'continue', |
| 209 'for', |
| 210 'switch', |
| 211 'yield', |
| 212 'debugger', |
| 213 'function', |
| 214 'this', |
| 215 'default', |
| 216 'if', |
| 217 'throw', |
| 218 'delete', |
| 219 'import', |
| 220 'try', |
| 221 |
| 222 // ES6 11.6.2.1 Words with semantic restrictions. |
| 223 'yield', 'let', 'static', |
| 224 |
| 225 // ES6 11.6.2.2 Future Reserved Words. |
| 226 'enum', |
| 227 'await', |
| 228 |
| 229 // ES6 11.6.2.2 / ES6 12.1.1 Words with semantic restrictions. |
| 230 'implements', |
| 231 'package', |
| 232 'protected', |
| 233 'interface', |
| 234 'private', |
| 235 'public', |
| 236 |
| 237 // Other words to avoid due to non-standard keyword-like behavior. |
| 150 ]; | 238 ]; |
| 151 | 239 |
| 152 static const List<String> reservedPropertySymbols = const <String>[ | 240 static const List<String> reservedPropertySymbols = const <String>[ |
| 153 "__proto__", "prototype", "constructor", "call", | 241 "__proto__", "prototype", "constructor", "call", |
| 154 // "use strict" disallows the use of "arguments" and "eval" as | 242 // "use strict" disallows the use of "arguments" and "eval" as |
| 155 // variable names or property names. See ECMA-262, Edition 5.1, | 243 // variable names or property names. See ECMA-262, Edition 5.1, |
| 156 // section 11.1.5 (for the property names). | 244 // section 11.1.5 (for the property names). |
| 157 "eval", "arguments" | 245 "eval", "arguments" |
| 158 ]; | 246 ]; |
| 159 | 247 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart", | 318 "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart", |
| 231 "ongesturestart", "ongesturechange", "ongestureend", | 319 "ongesturestart", "ongesturechange", "ongestureend", |
| 232 | 320 |
| 233 // extra window methods | 321 // extra window methods |
| 234 "uneval", | 322 "uneval", |
| 235 | 323 |
| 236 // keywords https://developer.mozilla.org/en/New_in_JavaScript_1.7, | 324 // keywords https://developer.mozilla.org/en/New_in_JavaScript_1.7, |
| 237 // https://developer.mozilla.org/en/New_in_JavaScript_1.8.1 | 325 // https://developer.mozilla.org/en/New_in_JavaScript_1.8.1 |
| 238 "getPrototypeOf", "let", "yield", | 326 "getPrototypeOf", "let", "yield", |
| 239 | 327 |
| 240 // "future reserved words" | |
| 241 "abstract", "int", "short", "boolean", "interface", "static", "byte", | |
| 242 "long", "char", "final", "native", "synchronized", "float", "package", | |
| 243 "throws", "goto", "private", "transient", "implements", "protected", | |
| 244 "volatile", "double", "public", | |
| 245 | |
| 246 // IE methods | 328 // IE methods |
| 247 // (http://msdn.microsoft.com/en-us/library/ms535873(VS.85).aspx#) | 329 // (http://msdn.microsoft.com/en-us/library/ms535873(VS.85).aspx#) |
| 248 "attachEvent", "clientInformation", "clipboardData", "createPopup", | 330 "attachEvent", "clientInformation", "clipboardData", "createPopup", |
| 249 "dialogHeight", "dialogLeft", "dialogTop", "dialogWidth", | 331 "dialogHeight", "dialogLeft", "dialogTop", "dialogWidth", |
| 250 "onafterprint", "onbeforedeactivate", "onbeforeprint", | 332 "onafterprint", "onbeforedeactivate", "onbeforeprint", |
| 251 "oncontrolselect", "ondeactivate", "onhelp", "onresizeend", | 333 "oncontrolselect", "ondeactivate", "onhelp", "onresizeend", |
| 252 | 334 |
| 253 // Common browser-defined identifiers not defined in ECMAScript | 335 // Common browser-defined identifiers not defined in ECMAScript |
| 254 "event", "external", "Debug", "Enumerator", "Global", "Image", | 336 "event", "external", "Debug", "Enumerator", "Global", "Image", |
| 255 "ActiveXObject", "VBArray", "Components", | 337 "ActiveXObject", "VBArray", "Components", |
| (...skipping 15 matching lines...) Expand all Loading... |
| 271 "Table", "TableCell", "TableRow", "TableSelection", "Text", "TextArea", | 353 "Table", "TableCell", "TableRow", "TableSelection", "Text", "TextArea", |
| 272 "UIEvent", "Window", "XMLHttpRequest", "XMLSerializer", | 354 "UIEvent", "Window", "XMLHttpRequest", "XMLSerializer", |
| 273 "XPathException", "XPathResult", "XSLTProcessor", | 355 "XPathException", "XPathResult", "XSLTProcessor", |
| 274 | 356 |
| 275 // These keywords trigger the loading of the java-plugin. For the | 357 // These keywords trigger the loading of the java-plugin. For the |
| 276 // next-generation plugin, this results in starting a new Java process. | 358 // next-generation plugin, this results in starting a new Java process. |
| 277 "java", "Packages", "netscape", "sun", "JavaObject", "JavaClass", | 359 "java", "Packages", "netscape", "sun", "JavaObject", "JavaClass", |
| 278 "JavaArray", "JavaMember", | 360 "JavaArray", "JavaMember", |
| 279 | 361 |
| 280 // ES6 collections. | 362 // ES6 collections. |
| 281 "Map", | 363 "Map", "Set", |
| 282 ]; | 364 ]; |
| 283 | 365 |
| 284 static const List<String> reservedGlobalObjectNames = const <String>[ | 366 static const List<String> reservedGlobalObjectNames = const <String>[ |
| 285 "A", | 367 "A", |
| 286 "B", | 368 "B", |
| 287 "C", // Global object for *C*onstants. | 369 "C", // Global object for *C*onstants. |
| 288 "D", | 370 "D", |
| 289 "E", | 371 "E", |
| 290 "F", | 372 "F", |
| 291 "G", | 373 "G", |
| (...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2106 void addSuggestion(String original, String suggestion) { | 2188 void addSuggestion(String original, String suggestion) { |
| 2107 assert(!_suggestedNames.containsKey(original)); | 2189 assert(!_suggestedNames.containsKey(original)); |
| 2108 _suggestedNames[original] = suggestion; | 2190 _suggestedNames[original] = suggestion; |
| 2109 } | 2191 } |
| 2110 | 2192 |
| 2111 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2193 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2112 bool isSuggestion(String candidate) { | 2194 bool isSuggestion(String candidate) { |
| 2113 return _suggestedNames.containsValue(candidate); | 2195 return _suggestedNames.containsValue(candidate); |
| 2114 } | 2196 } |
| 2115 } | 2197 } |
| OLD | NEW |