From 5bd50cce6f29f76c0c6bc09a46b8782a0dca8fd9 Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke
ecmaVersion: 5,Turn on strictSemicolons to prevent the parser from doing
automatic semicolon insertion.
strictSemicolons: false,When allowTrailingCommas is false, the parser will not allow
trailing commas in array and object literals.
allowTrailingCommas: true,By default, reserved words are not enforced. Enable
-forbidReserved to enforce them.
forbidReserved: false,When enabled, a return at the top level is not considered an
+forbidReserved to enforce them. When this option has the
+value "everywhere", reserved words and keywords can also not be
+used as property names.
forbidReserved: false,When enabled, a return at the top level is not considered an error.
allowReturnOutsideFunction: false,When locations is on, loc properties holding objects with
start and end properties in {line, column} form (with
line being 1-based and column 0-based) will be attached to the
@@ -676,13 +678,8 @@ containeds an escape, as a micro-optimization.
function readWord() {
var word = readWord1();
var type = _name;
- if (!containsEsc) {
- if (isKeyword(word)) type = keywordTypes[word];
- else if (options.forbidReserved &&
- (options.ecmaVersion === 3 ? isReservedWord3 : isReservedWord5)(word) ||
- strict && isStrictReservedWord(word))
- raise(tokStart, "The keyword '" + word + "' is reserved");
- }
+ if (!containsEsc && isKeyword(word))
+ type = keywordTypes[word];
return finishToken(type, word);
}A recursive descent parser operates by defining functions for all syntactic elements, and recursively calling those, each function @@ -1323,7 +1320,20 @@ for array literals).
function parseIdent(liberal) {
var node = startNode();
- node.name = tokType === _name ? tokVal : (liberal && !options.forbidReserved && tokType.keyword) || unexpected();
+ if (liberal && options.forbidReserved == "everywhere") liberal = false;
+ if (tokType === _name) {
+ if (!liberal &&
+ (options.forbidReserved &&
+ (options.ecmaVersion === 3 ? isReservedWord3 : isReservedWord5)(tokVal) ||
+ strict && isStrictReservedWord(tokVal)) &&
+ input.slice(tokStart, tokEnd).indexOf("\\") == -1)
+ raise(tokStart, "The keyword '" + tokVal + "' is reserved");
+ node.name = tokVal;
+ } else if (liberal && tokType.keyword) {
+ node.name = tokType.keyword;
+ } else {
+ unexpected();
+ }
tokRegexpAllowed = false;
next();
return finishNode(node, "Identifier");
diff --git a/test/tests.js b/test/tests.js
index efce0b4122..9cb04321fb 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -26348,6 +26348,39 @@ test("x = y-->10;\n --> nothing", {
]
});
+test("'use strict';\nobject.static();", {
+ type: "Program",
+ body: [
+ {
+ type: "ExpressionStatement",
+ expression: {
+ type: "Literal",
+ value: "use strict",
+ raw: "'use strict'"
+ }
+ },
+ {
+ type: "ExpressionStatement",
+ expression: {
+ type: "CallExpression",
+ callee: {
+ type: "MemberExpression",
+ object: {
+ type: "Identifier",
+ name: "object"
+ },
+ property: {
+ type: "Identifier",
+ name: "static"
+ },
+ computed: false
+ },
+ arguments: []
+ }
+ }
+ ]
+});
+
// Failure tests
testFail("{",