From b21db8a37e70b9e425ace512a89ece3e768aa9ac Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 15 Jul 2015 16:41:32 +0100 Subject: [PATCH] finish removal of ecmaVersion option --- src/expression.js | 35 +++------ src/lval.js | 1 - src/options.js | 5 -- src/parseutil.js | 3 +- src/state.js | 2 +- src/tokenize.js | 4 +- test/tests.js | 190 ---------------------------------------------- 7 files changed, 12 insertions(+), 228 deletions(-) diff --git a/src/expression.js b/src/expression.js index 5ab60bcec0..b2fa912e4a 100755 --- a/src/expression.js +++ b/src/expression.js @@ -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,17 +661,15 @@ 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(); - this.expect(tt.bracketR); - return prop.key; - } else { - prop.computed = false; - } + if (this.eat(tt.bracketL)) { + prop.computed = true; + prop.key = this.parseMaybeAssign(); + this.expect(tt.bracketR); + return prop.key; + } else { + 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. diff --git a/src/lval.js b/src/lval.js index 4c8fd64554..58027e08a8 100755 --- a/src/lval.js +++ b/src/lval.js @@ -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(); diff --git a/src/options.js b/src/options.js index 49619aec8d..828d5bed04 100755 --- a/src/options.js +++ b/src/options.js @@ -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 diff --git a/src/parseutil.js b/src/parseutil.js index 47af1b9b06..41c6d8e79b 100755 --- a/src/parseutil.js +++ b/src/parseutil.js @@ -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 diff --git a/src/state.js b/src/state.js index 37171ecd27..2f398468d6 100755 --- a/src/state.js +++ b/src/state.js @@ -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); diff --git a/src/tokenize.js b/src/tokenize.js index ced6aae03a..3a427e0241 100755 --- a/src/tokenize.js +++ b/src/tokenize.js @@ -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; diff --git a/test/tests.js b/test/tests.js index a775311876..8483d634ba 100755 --- a/test/tests.js +++ b/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