finish removal of ecmaVersion option
This commit is contained in:
parent
bd2fb6126b
commit
b21db8a37e
@ -42,21 +42,6 @@ pp.checkPropClash = function (prop, propHash) {
|
||||
if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property");
|
||||
propHash.proto = true;
|
||||
}
|
||||
|
||||
let other;
|
||||
if (propHash[name]) {
|
||||
other = propHash[name];
|
||||
let isGetSet = kind !== "init";
|
||||
if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init))
|
||||
this.raise(key.start, "Redefinition of property");
|
||||
} else {
|
||||
other = propHash[name] = {
|
||||
init: false,
|
||||
get: false,
|
||||
set: false
|
||||
};
|
||||
}
|
||||
other[kind] = true;
|
||||
};
|
||||
|
||||
// ### Expression parsing
|
||||
@ -375,7 +360,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
node = this.startNode();
|
||||
this.next();
|
||||
// check whether this is array comprehension or regular array
|
||||
if ((this.options.ecmaVersion >= 7 || this.options.features["es7.comprehensions"]) && this.type === tt._for) {
|
||||
if (this.options.features["es7.comprehensions"] && this.type === tt._for) {
|
||||
return this.parseComprehension(node, false);
|
||||
}
|
||||
node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
|
||||
@ -676,7 +661,6 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
|
||||
};
|
||||
|
||||
pp.parsePropertyName = function (prop) {
|
||||
if (this.options.ecmaVersion >= 6) {
|
||||
if (this.eat(tt.bracketL)) {
|
||||
prop.computed = true;
|
||||
prop.key = this.parseMaybeAssign();
|
||||
@ -684,9 +668,8 @@ pp.parsePropertyName = function (prop) {
|
||||
return prop.key;
|
||||
} else {
|
||||
prop.computed = false;
|
||||
}
|
||||
}
|
||||
return prop.key = (this.type === tt.num || this.type === tt.string) ? this.parseExprAtom() : this.parseIdent(true);
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize empty function node.
|
||||
|
||||
@ -94,7 +94,6 @@ pp.parseRest = function () {
|
||||
// Parses lvalue (assignable) atom.
|
||||
|
||||
pp.parseBindingAtom = function () {
|
||||
if (this.options.ecmaVersion < 6) return this.parseIdent();
|
||||
switch (this.type) {
|
||||
case tt.name:
|
||||
return this.parseIdent();
|
||||
|
||||
@ -5,11 +5,6 @@ import { SourceLocation } from "./location";
|
||||
// the parser process. These options are recognized:
|
||||
|
||||
export const defaultOptions = {
|
||||
// `ecmaVersion` indicates the ECMAScript version to parse. Must
|
||||
// be either 3, or 5, or 6. This influences support for strict
|
||||
// mode, the set of reserved words, support for getters and
|
||||
// setters and other features.
|
||||
ecmaVersion: 5,
|
||||
// Source type ("script" or "module") for different semantics
|
||||
sourceType: "script",
|
||||
// `onInsertedSemicolon` can be a callback that will be called
|
||||
|
||||
@ -9,8 +9,7 @@ const pp = Parser.prototype;
|
||||
// Test whether a statement node is the string literal `"use strict"`.
|
||||
|
||||
pp.isUseStrict = function (stmt) {
|
||||
return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" &&
|
||||
stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
|
||||
return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
|
||||
};
|
||||
|
||||
// Predicate that tests whether the next token is of the given
|
||||
|
||||
@ -6,7 +6,7 @@ export function Parser(options, input, startPos) {
|
||||
this.options = options;
|
||||
this.sourceFile = this.options.sourceFile || null;
|
||||
this.isKeyword = keywords[6];
|
||||
this.isReservedWord = reservedWords[this.options.ecmaVersion];
|
||||
this.isReservedWord = reservedWords[6];
|
||||
this.input = input;
|
||||
this.loadPlugins(this.options.plugins);
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ pp.nextToken = function () {
|
||||
pp.readToken = function (code) {
|
||||
// Identifier or keyword. '\uXXXX' sequences are allowed in
|
||||
// identifiers, so '\' also dispatches to that.
|
||||
if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
|
||||
if (isIdentifierStart(code, true) || code === 92 /* '\' */)
|
||||
return this.readWord();
|
||||
|
||||
return this.getTokenFromCode(code);
|
||||
@ -351,7 +351,6 @@ pp.getTokenFromCode = function (code) {
|
||||
case 64: ++this.pos; return this.finishToken(tt.at);
|
||||
|
||||
case 96: // '`'
|
||||
if (this.options.ecmaVersion < 6) break;
|
||||
++this.pos;
|
||||
return this.finishToken(tt.backQuote);
|
||||
|
||||
@ -542,7 +541,6 @@ pp.readCodePoint = function () {
|
||||
let ch = this.input.charCodeAt(this.pos), code;
|
||||
|
||||
if (ch === 123) {
|
||||
if (this.options.ecmaVersion < 6) this.unexpected();
|
||||
let codePos = ++this.pos;
|
||||
code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
|
||||
++this.pos;
|
||||
|
||||
190
test/tests.js
190
test/tests.js
@ -17415,92 +17415,6 @@ test("if (morning) var x = 0;", {
|
||||
}
|
||||
});
|
||||
|
||||
test("if (morning) function a(){}", {
|
||||
type: "Program",
|
||||
body: [
|
||||
{
|
||||
type: "IfStatement",
|
||||
test: {
|
||||
type: "Identifier",
|
||||
name: "morning",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 4
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 11
|
||||
}
|
||||
}
|
||||
},
|
||||
consequent: {
|
||||
type: "FunctionDeclaration",
|
||||
id: {
|
||||
type: "Identifier",
|
||||
name: "a",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 22
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 23
|
||||
}
|
||||
}
|
||||
},
|
||||
params: [],
|
||||
body: {
|
||||
type: "BlockStatement",
|
||||
body: [],
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 25
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 27
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 13
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 27
|
||||
}
|
||||
}
|
||||
},
|
||||
alternate: null,
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 27
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 27
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("if (morning) goodMorning(); else goodDay()", {
|
||||
type: "Program",
|
||||
body: [
|
||||
@ -26855,27 +26769,6 @@ testFail("({ set: s(a, b) { } })",
|
||||
testFail("({ get: g(d) { } })",
|
||||
"Unexpected token (1:13)");
|
||||
|
||||
testFail("({ get i() { }, i: 42 })",
|
||||
"Redefinition of property (1:16)");
|
||||
|
||||
testFail("({ i: 42, get i() { } })",
|
||||
"Redefinition of property (1:14)");
|
||||
|
||||
testFail("({ set i(x) { }, i: 42 })",
|
||||
"Redefinition of property (1:17)");
|
||||
|
||||
testFail("({ i: 42, set i(x) { } })",
|
||||
"Redefinition of property (1:14)");
|
||||
|
||||
testFail("({ get i() { }, get i() { } })",
|
||||
"Redefinition of property (1:20)");
|
||||
|
||||
testFail("({ set i(x) { }, set i(x) { } })",
|
||||
"Redefinition of property (1:21)");
|
||||
|
||||
testFail("function t(...) { }",
|
||||
"Unexpected token (1:11)");
|
||||
|
||||
testFail("function t(...) { }",
|
||||
"Unexpected token (1:14)",
|
||||
{ ecmaVersion: 6 });
|
||||
@ -27100,12 +26993,6 @@ testFail("(function () { 'use strict'; delete i; }())",
|
||||
testFail("(function () { 'use strict'; with (i); }())",
|
||||
"'with' in strict mode (1:29)");
|
||||
|
||||
testFail("function hello() {'use strict'; ({ i: 42, i: 42 }) }",
|
||||
"Redefinition of property (1:42)");
|
||||
|
||||
testFail("function hello() {'use strict'; ({ hasOwnProperty: 42, hasOwnProperty: 42 }) }",
|
||||
"Redefinition of property (1:55)");
|
||||
|
||||
testFail("function hello() {'use strict'; var eval = 10; }",
|
||||
"Binding eval in strict mode (1:36)");
|
||||
|
||||
@ -27275,79 +27162,6 @@ testFail("var this = 10;", "Unexpected token (1:4)");
|
||||
|
||||
testFail("throw\n10;", "Illegal newline after throw (1:5)");
|
||||
|
||||
|
||||
// ECMA < 6 mode should work as before
|
||||
|
||||
testFail("const a;", "Unexpected token (1:6)");
|
||||
|
||||
testFail("let x;", "Unexpected token (1:4)");
|
||||
|
||||
testFail("const a = 1;", "Unexpected token (1:6)");
|
||||
|
||||
testFail("let a = 1;", "Unexpected token (1:4)");
|
||||
|
||||
testFail("for(const x = 0;;);", "Unexpected token (1:10)");
|
||||
|
||||
testFail("for(let x = 0;;);", "Unexpected token (1:8)");
|
||||
|
||||
test("let++", {
|
||||
type: "Program",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 5
|
||||
}
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 5
|
||||
}
|
||||
},
|
||||
expression: {
|
||||
type: "UpdateExpression",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 5
|
||||
}
|
||||
},
|
||||
operator: "++",
|
||||
prefix: false,
|
||||
argument: {
|
||||
type: "Identifier",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 3
|
||||
}
|
||||
},
|
||||
name: "let"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// ECMA 6 support
|
||||
|
||||
test("let x", {
|
||||
@ -28604,10 +28418,6 @@ test("for(const x = 0;;);", {
|
||||
range: [0, 19]
|
||||
}, {ecmaVersion: 6, ranges: true});
|
||||
|
||||
testFail("for(x of a);", "Unexpected token (1:6)");
|
||||
|
||||
testFail("for(var x of a);", "Unexpected token (1:10)");
|
||||
|
||||
// Assertion Tests
|
||||
test(function TestComments() {
|
||||
// Bear class
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user