| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 bool needsRename(Identifier node) => | 221 bool needsRename(Identifier node) => |
| 222 node is TemporaryId || node.allowRename && invalidVariableName(node.name); | 222 node is TemporaryId || node.allowRename && invalidVariableName(node.name); |
| 223 | 223 |
| 224 Object /*String|TemporaryId*/ identifierKey(Identifier node) => | 224 Object /*String|TemporaryId*/ identifierKey(Identifier node) => |
| 225 node is TemporaryId ? node : node.name; | 225 node is TemporaryId ? node : node.name; |
| 226 | 226 |
| 227 /// Returns true for invalid JS variable names, such as keywords. | 227 /// Returns true for invalid JS variable names, such as keywords. |
| 228 /// Also handles invalid variable names in strict mode, like "arguments". | 228 /// Also handles invalid variable names in strict mode, like "arguments". |
| 229 bool invalidVariableName(String keyword, {bool strictMode: true}) { | 229 bool invalidVariableName(String keyword, {bool strictMode: true}) { |
| 230 switch (keyword) { | 230 switch (keyword) { |
| 231 // http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words |
| 232 case "await": |
| 233 |
| 231 case "break": | 234 case "break": |
| 232 case "case": | 235 case "case": |
| 233 case "catch": | 236 case "catch": |
| 234 case "class": | 237 case "class": |
| 235 case "const": | 238 case "const": |
| 236 case "continue": | 239 case "continue": |
| 237 case "debugger": | 240 case "debugger": |
| 238 case "default": | 241 case "default": |
| 239 case "delete": | 242 case "delete": |
| 240 case "do": | 243 case "do": |
| 241 case "else": | 244 case "else": |
| 245 case "enum": |
| 242 case "export": | 246 case "export": |
| 243 case "extends": | 247 case "extends": |
| 244 case "finally": | 248 case "finally": |
| 245 case "for": | 249 case "for": |
| 246 case "function": | 250 case "function": |
| 247 case "if": | 251 case "if": |
| 248 case "import": | 252 case "import": |
| 249 case "in": | 253 case "in": |
| 250 case "instanceof": | 254 case "instanceof": |
| 251 case "interface": | |
| 252 case "let": | 255 case "let": |
| 253 case "new": | 256 case "new": |
| 254 case "return": | 257 case "return": |
| 255 case "static": | |
| 256 case "super": | 258 case "super": |
| 257 case "switch": | 259 case "switch": |
| 258 case "this": | 260 case "this": |
| 259 case "throw": | 261 case "throw": |
| 260 case "try": | 262 case "try": |
| 261 case "typeof": | 263 case "typeof": |
| 262 case "var": | 264 case "var": |
| 263 case "void": | 265 case "void": |
| 264 case "while": | 266 case "while": |
| 265 case "with": | 267 case "with": |
| 266 case "yield": | |
| 267 return true; | 268 return true; |
| 268 case "arguments": | 269 case "arguments": |
| 269 case "eval": | 270 case "eval": |
| 271 // http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words |
| 272 // http://www.ecma-international.org/ecma-262/6.0/#sec-identifiers-static-se
mantics-early-errors |
| 273 case "implements": |
| 274 case "interface": |
| 275 case "let": |
| 276 case "package": |
| 277 case "private": |
| 278 case "protected": |
| 279 case "public": |
| 280 case "static": |
| 281 case "yield": |
| 270 return strictMode; | 282 return strictMode; |
| 271 } | 283 } |
| 272 return false; | 284 return false; |
| 273 } | 285 } |
| 274 | 286 |
| 275 /// Returns true for invalid static field names in strict mode. | 287 /// Returns true for invalid static field names in strict mode. |
| 276 /// In particular, "caller" "callee" and "arguments" cannot be used. | 288 /// In particular, "caller" "callee" and "arguments" cannot be used. |
| 277 bool invalidStaticFieldName(String name) { | 289 bool invalidStaticFieldName(String name) { |
| 278 switch (name) { | 290 switch (name) { |
| 279 case "arguments": | 291 case "arguments": |
| 280 case "caller": | 292 case "caller": |
| 281 case "callee": | 293 case "callee": |
| 282 return true; | 294 return true; |
| 283 } | 295 } |
| 284 return false; | 296 return false; |
| 285 } | 297 } |
| OLD | NEW |