finish removal of ecmaVersion option

This commit is contained in:
Sebastian McKenzie 2015-07-15 16:41:32 +01:00
parent bd2fb6126b
commit b21db8a37e
7 changed files with 12 additions and 228 deletions

View File

@ -42,21 +42,6 @@ pp.checkPropClash = function (prop, propHash) {
if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property"); if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property");
propHash.proto = true; 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 // ### Expression parsing
@ -375,7 +360,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
node = this.startNode(); node = this.startNode();
this.next(); this.next();
// check whether this is array comprehension or regular array // 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); return this.parseComprehension(node, false);
} }
node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos); node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
@ -676,17 +661,15 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
}; };
pp.parsePropertyName = function (prop) { pp.parsePropertyName = function (prop) {
if (this.options.ecmaVersion >= 6) { if (this.eat(tt.bracketL)) {
if (this.eat(tt.bracketL)) { prop.computed = true;
prop.computed = true; prop.key = this.parseMaybeAssign();
prop.key = this.parseMaybeAssign(); this.expect(tt.bracketR);
this.expect(tt.bracketR); return prop.key;
return prop.key; } else {
} else { prop.computed = false;
prop.computed = false; return prop.key = (this.type === tt.num || this.type === tt.string) ? this.parseExprAtom() : this.parseIdent(true);
}
} }
return prop.key = (this.type === tt.num || this.type === tt.string) ? this.parseExprAtom() : this.parseIdent(true);
}; };
// Initialize empty function node. // Initialize empty function node.

View File

@ -94,7 +94,6 @@ pp.parseRest = function () {
// Parses lvalue (assignable) atom. // Parses lvalue (assignable) atom.
pp.parseBindingAtom = function () { pp.parseBindingAtom = function () {
if (this.options.ecmaVersion < 6) return this.parseIdent();
switch (this.type) { switch (this.type) {
case tt.name: case tt.name:
return this.parseIdent(); return this.parseIdent();

View File

@ -5,11 +5,6 @@ import { SourceLocation } from "./location";
// the parser process. These options are recognized: // the parser process. These options are recognized:
export const defaultOptions = { 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 // Source type ("script" or "module") for different semantics
sourceType: "script", sourceType: "script",
// `onInsertedSemicolon` can be a callback that will be called // `onInsertedSemicolon` can be a callback that will be called

View File

@ -9,8 +9,7 @@ const pp = Parser.prototype;
// Test whether a statement node is the string literal `"use strict"`. // Test whether a statement node is the string literal `"use strict"`.
pp.isUseStrict = function (stmt) { pp.isUseStrict = function (stmt) {
return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
}; };
// Predicate that tests whether the next token is of the given // Predicate that tests whether the next token is of the given

View File

@ -6,7 +6,7 @@ export function Parser(options, input, startPos) {
this.options = options; this.options = options;
this.sourceFile = this.options.sourceFile || null; this.sourceFile = this.options.sourceFile || null;
this.isKeyword = keywords[6]; this.isKeyword = keywords[6];
this.isReservedWord = reservedWords[this.options.ecmaVersion]; this.isReservedWord = reservedWords[6];
this.input = input; this.input = input;
this.loadPlugins(this.options.plugins); this.loadPlugins(this.options.plugins);

View File

@ -89,7 +89,7 @@ pp.nextToken = function () {
pp.readToken = function (code) { pp.readToken = function (code) {
// Identifier or keyword. '\uXXXX' sequences are allowed in // Identifier or keyword. '\uXXXX' sequences are allowed in
// identifiers, so '\' also dispatches to that. // 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.readWord();
return this.getTokenFromCode(code); return this.getTokenFromCode(code);
@ -351,7 +351,6 @@ pp.getTokenFromCode = function (code) {
case 64: ++this.pos; return this.finishToken(tt.at); case 64: ++this.pos; return this.finishToken(tt.at);
case 96: // '`' case 96: // '`'
if (this.options.ecmaVersion < 6) break;
++this.pos; ++this.pos;
return this.finishToken(tt.backQuote); return this.finishToken(tt.backQuote);
@ -542,7 +541,6 @@ pp.readCodePoint = function () {
let ch = this.input.charCodeAt(this.pos), code; let ch = this.input.charCodeAt(this.pos), code;
if (ch === 123) { if (ch === 123) {
if (this.options.ecmaVersion < 6) this.unexpected();
let codePos = ++this.pos; let codePos = ++this.pos;
code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos); code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
++this.pos; ++this.pos;

View File

@ -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()", { test("if (morning) goodMorning(); else goodDay()", {
type: "Program", type: "Program",
body: [ body: [
@ -26855,27 +26769,6 @@ testFail("({ set: s(a, b) { } })",
testFail("({ get: g(d) { } })", testFail("({ get: g(d) { } })",
"Unexpected token (1:13)"); "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(...) { }", testFail("function t(...) { }",
"Unexpected token (1:14)", "Unexpected token (1:14)",
{ ecmaVersion: 6 }); { ecmaVersion: 6 });
@ -27100,12 +26993,6 @@ testFail("(function () { 'use strict'; delete i; }())",
testFail("(function () { 'use strict'; with (i); }())", testFail("(function () { 'use strict'; with (i); }())",
"'with' in strict mode (1:29)"); "'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; }", testFail("function hello() {'use strict'; var eval = 10; }",
"Binding eval in strict mode (1:36)"); "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)"); 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 // ECMA 6 support
test("let x", { test("let x", {
@ -28604,10 +28418,6 @@ test("for(const x = 0;;);", {
range: [0, 19] range: [0, 19]
}, {ecmaVersion: 6, ranges: true}); }, {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 // Assertion Tests
test(function TestComments() { test(function TestComments() {
// Bear class // Bear class