Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Unified Diff: lib/src/codegen/js_names.dart

Issue 1034273003: fix for static methods and names banned in strict mode (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/js/keywords.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_names.dart
diff --git a/lib/src/codegen/js_names.dart b/lib/src/codegen/js_names.dart
index 58d750718a41adea5b51278ee19f8956901f9f56..561f954f87350c35d9ee10d978d500008f7024d2 100644
--- a/lib/src/codegen/js_names.dart
+++ b/lib/src/codegen/js_names.dart
@@ -5,7 +5,6 @@
library dev_compiler.src.codegen.js_names;
import 'package:dev_compiler/src/js/js_ast.dart';
-import 'package:dev_compiler/src/js/keywords.dart';
/// Marker subclass for temporary variables.
/// We treat these as being in a different scope from other identifiers, and
@@ -41,7 +40,7 @@ class JSNamer extends LocalNamer {
var name = node.name;
if (node is JSTemporary) {
return _rename(name, valid: true);
- } else if (isJsKeyword(name)) {
+ } else if (invalidJSVariableName(name)) {
return _rename(name, valid: false);
}
return name;
@@ -79,3 +78,62 @@ class _NameCollector extends BaseVisitor {
if (node is! JSTemporary) names.add(node.name);
}
}
+
+/// Returns true for invalid JS variable names, such as keywords.
+/// Also handles invalid variable names in strict mode, like "arguments".
+bool invalidJSVariableName(String keyword, {bool strictMode: true}) {
+ switch (keyword) {
+ case "break":
+ case "case":
+ case "catch":
+ case "class":
+ case "const":
+ case "continue":
+ case "debugger":
+ case "default":
+ case "delete":
+ case "do":
+ case "else":
+ case "export":
+ case "extends":
+ case "finally":
+ case "for":
+ case "function":
+ case "if":
+ case "import":
+ case "in":
+ case "instanceof":
+ case "let":
+ case "new":
+ case "return":
+ case "static":
+ case "super":
+ case "switch":
+ case "this":
+ case "throw":
+ case "try":
+ case "typeof":
+ case "var":
+ case "void":
+ case "while":
+ case "with":
+ case "yield":
+ return true;
+ case "arguments":
+ case "eval":
+ return strictMode;
+ }
+ return false;
+}
+
+/// Returns true for invalid static method names in strict mode.
+/// In particular, "caller" "callee" and "arguments" cannot be used.
+bool invalidJSStaticMethodName(String name) {
+ switch (name) {
+ case "arguments":
+ case "caller":
+ case "callee":
+ return true;
+ }
+ return false;
+}
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/js/keywords.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698