remove ecmaVersion <= 6

This commit is contained in:
Sebastian McKenzie 2015-07-15 15:34:47 +01:00
parent 21a11e5d2b
commit 472b079862
5 changed files with 36 additions and 60 deletions

View File

@ -28,7 +28,7 @@ const pp = Parser.prototype;
// strict mode, init properties are also not allowed to be repeated.
pp.checkPropClash = function (prop, propHash) {
if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) return;
if (prop.computed || prop.method || prop.shorthand) return;
let key = prop.key, name;
switch (key.type) {
@ -38,12 +38,9 @@ pp.checkPropClash = function (prop, propHash) {
}
let kind = prop.kind;
if (this.options.ecmaVersion >= 6) {
if (name === "__proto__" && kind === "init") {
if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property");
propHash.proto = true;
}
return;
if (name === "__proto__" && kind === "init") {
if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property");
propHash.proto = true;
}
let other;
@ -524,7 +521,7 @@ pp.parseNew = function () {
let node = this.startNode();
let meta = this.parseIdent(true);
if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
if (this.eat(tt.dot)) {
node.meta = meta;
node.property = this.parseIdent(true);
@ -605,16 +602,14 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
node.properties.push(prop);
continue;
}
if (this.options.ecmaVersion >= 6) {
prop.method = false;
prop.shorthand = false;
if (isPattern || refShorthandDefaultPos) {
startPos = this.start;
startLoc = this.startLoc;
}
if (!isPattern)
isGenerator = this.eat(tt.star);
prop.method = false;
prop.shorthand = false;
if (isPattern || refShorthandDefaultPos) {
startPos = this.start;
startLoc = this.startLoc;
}
if (!isPattern)
isGenerator = this.eat(tt.star);
if (this.options.features["es7.asyncFunctions"] && this.isContextual("async")) {
if (isGenerator || isPattern) this.unexpected();
var asyncId = this.parseIdent();
@ -641,14 +636,12 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
if (this.eat(tt.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
prop.kind = "init";
} else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
} else if (this.type === tt.parenL) {
if (isPattern) this.unexpected();
prop.kind = "init";
prop.method = true;
prop.value = this.parseMethod(isGenerator, isAsync);
} else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.type !== tt.comma && this.type !== tt.braceR)) {
} else if (!prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.type !== tt.comma && this.type !== tt.braceR)) {
if (isGenerator || isAsync || isPattern) this.unexpected();
prop.kind = prop.key.name;
this.parsePropertyName(prop);
@ -661,7 +654,7 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
else
this.raise(start, "setter should have exactly one param");
}
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
} else if (!prop.computed && prop.key.type === "Identifier") {
prop.kind = "init";
if (isPattern) {
if (this.isKeyword(prop.key.name) ||
@ -700,10 +693,8 @@ pp.parsePropertyName = function (prop) {
pp.initFunction = function (node, isAsync) {
node.id = null;
if (this.options.ecmaVersion >= 6) {
node.generator = false;
node.expression = false;
}
node.generator = false;
node.expression = false;
if (this.options.features["es7.asyncFunctions"]) {
node.async = !!isAsync;
}
@ -716,9 +707,7 @@ pp.parseMethod = function (isGenerator, isAsync) {
this.initFunction(node, isAsync);
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"]);
if (this.options.ecmaVersion >= 6) {
node.generator = isGenerator;
}
node.generator = isGenerator;
this.parseFunctionBody(node);
return this.finishNode(node, "FunctionExpression");
};
@ -807,8 +796,7 @@ pp.parseIdent = function (liberal) {
if (!liberal &&
((!this.options.allowReserved && this.isReservedWord(this.value)) ||
(this.strict && reservedWords.strict(this.value)) &&
(this.options.ecmaVersion >= 6 ||
this.input.slice(this.start, this.end).indexOf("\\") === -1)))
this.input.slice(this.start, this.end).indexOf("\\") === -1))
this.raise(this.start, "The keyword '" + this.value + "' is reserved");
node.name = this.value;
} else if (liberal && this.type.keyword) {

View File

@ -8,7 +8,7 @@ const pp = Parser.prototype;
// if possible.
pp.toAssignable = function (node, isBinding) {
if (this.options.ecmaVersion >= 6 && node) {
if (node) {
switch (node.type) {
case "Identifier":
case "ObjectPattern":

View File

@ -5,7 +5,7 @@ import { lineBreak } from "./whitespace";
export function Parser(options, input, startPos) {
this.options = options;
this.sourceFile = this.options.sourceFile || null;
this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5];
this.isKeyword = keywords[6];
this.isReservedWord = reservedWords[this.options.ecmaVersion];
this.input = input;
this.loadPlugins(this.options.plugins);

View File

@ -23,9 +23,7 @@ pp.parseTopLevel = function (node) {
}
}
this.next();
if (this.options.ecmaVersion >= 6) {
node.sourceType = this.options.sourceType;
}
node.sourceType = this.options.sourceType;
return this.finishNode(node, "Program");
};
@ -55,7 +53,7 @@ pp.parseStatement = function (declaration, topLevel) {
case tt._do: return this.parseDoStatement(node);
case tt._for: return this.parseForStatement(node);
case tt._function:
if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
if (!declaration) this.unexpected();
return this.parseFunctionStatement(node);
case tt._class:
@ -181,11 +179,7 @@ pp.parseDoStatement = function (node) {
this.labels.pop();
this.expect(tt._while);
node.test = this.parseParenExpression();
if (this.options.ecmaVersion >= 6) {
this.eat(tt.semi);
} else {
this.semicolon();
}
this.eat(tt.semi);
return this.finishNode(node, "DoWhileStatement");
};
@ -211,7 +205,7 @@ pp.parseForStatement = function (node) {
this.next();
this.parseVar(init, true, varKind);
this.finishNode(init, "VariableDeclaration");
if ((this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init.declarations.length === 1 &&
if ((this.type === tt._in || this.isContextual("of")) && init.declarations.length === 1 &&
!(varKind !== tt._var && init.declarations[0].init))
return this.parseForIn(node, init);
return this.parseFor(node, init);
@ -219,7 +213,7 @@ pp.parseForStatement = function (node) {
let refShorthandDefaultPos = {start: 0};
let init = this.parseExpression(true, refShorthandDefaultPos);
if (this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
if (this.type === tt._in || this.isContextual("of")) {
this.toAssignable(init);
this.checkLVal(init);
return this.parseForIn(node, init);
@ -459,7 +453,7 @@ pp.parseVar = function (node, isFor, kind) {
this.parseVarHead(decl);
if (this.eat(tt.eq)) {
decl.init = this.parseMaybeAssign(isFor);
} else if (kind === tt._const && !(this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
} else if (kind === tt._const && !(this.type === tt._in || this.isContextual("of"))) {
this.unexpected();
} else if (decl.id.type !== "Identifier" && !(isFor && (this.type === tt._in || this.isContextual("of")))) {
this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
@ -482,9 +476,7 @@ pp.parseVarHead = function (decl) {
pp.parseFunction = function (node, isStatement, allowExpressionBody, isAsync) {
this.initFunction(node, isAsync);
if (this.options.ecmaVersion >= 6) {
node.generator = this.eat(tt.star);
}
node.generator = this.eat(tt.star);
if (isStatement || this.type === tt.name) {
node.id = this.parseIdent();

View File

@ -213,7 +213,7 @@ pp.readToken_dot = function () {
if (next >= 48 && next <= 57) return this.readNumber(true);
let next2 = this.input.charCodeAt(this.pos + 2);
if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
if (next === 46 && next2 === 46) { // 46 = dot '.'
this.pos += 3;
return this.finishToken(tt.ellipsis);
} else {
@ -315,7 +315,7 @@ pp.readToken_lt_gt = function (code) { // '<>'
pp.readToken_eq_excl = function (code) { // '=!'
let next = this.input.charCodeAt(this.pos + 1);
if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2);
if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
if (code === 61 && next === 62) { // '=>'
this.pos += 2;
return this.finishToken(tt.arrow);
}
@ -358,10 +358,8 @@ pp.getTokenFromCode = function (code) {
case 48: // '0'
let next = this.input.charCodeAt(this.pos + 1);
if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
if (this.options.ecmaVersion >= 6) {
if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
}
if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
// Anything else beginning with a digit is an integer, octal
// number, or float.
case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
@ -449,8 +447,7 @@ pp.readRegexp = function() {
let mods = this.readWord1();
let tmp = content;
if (mods) {
let validFlags = /^[gmsiy]*$/;
if (this.options.ecmaVersion >= 6) validFlags = /^[gmsiyu]*$/;
let validFlags = /^[gmsiyu]*$/;
if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
if (mods.indexOf("u") >= 0 && !regexpUnicodeSupport) {
// Replace each astral symbol and every Unicode escape sequence that
@ -693,10 +690,9 @@ var containsEsc;
pp.readWord1 = function () {
containsEsc = false;
let word = "", first = true, chunkStart = this.pos;
let astral = this.options.ecmaVersion >= 6;
while (this.pos < this.input.length) {
let ch = this.fullCharCodeAtPos();
if (isIdentifierChar(ch, astral)) {
if (isIdentifierChar(ch, true)) {
this.pos += ch <= 0xffff ? 1 : 2;
} else if (ch === 92) { // "\"
containsEsc = true;
@ -710,7 +706,7 @@ pp.readWord1 = function () {
++this.pos;
let esc = this.readCodePoint();
if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral)) {
if (!(first ? isIdentifierStart : isIdentifierChar)(esc, true)) {
this.raise(escStart, "Invalid Unicode escape");
}
@ -730,7 +726,7 @@ pp.readWord1 = function () {
pp.readWord = function () {
let word = this.readWord1();
let type = tt.name;
if ((this.options.ecmaVersion >= 6 || !containsEsc) && this.isKeyword(word))
if (!containsEsc && this.isKeyword(word))
type = keywordTypes[word];
return this.finishToken(type, word);
};