Update eslint-config-babel to the latest version 🚀 (#273)
* chore(package): update eslint-config-babel to version 4.0.0 https://greenkeeper.io/ * Fix prefer-const * Update package.json
This commit is contained in:
committed by
Daniel Tschinder
parent
cd9aaf2a58
commit
6773279039
@@ -41,7 +41,7 @@ pp.addComment = function (comment) {
|
||||
pp.processComment = function (node) {
|
||||
if (node.type === "Program" && node.body.length > 0) return;
|
||||
|
||||
let stack = this.state.commentStack;
|
||||
const stack = this.state.commentStack;
|
||||
|
||||
let lastChild, trailingComments, i, j;
|
||||
|
||||
@@ -63,7 +63,7 @@ pp.processComment = function (node) {
|
||||
this.state.trailingComments.length = 0;
|
||||
}
|
||||
} else {
|
||||
let lastInStack = last(stack);
|
||||
const lastInStack = last(stack);
|
||||
if (stack.length > 0 && lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) {
|
||||
trailingComments = lastInStack.trailingComments;
|
||||
lastInStack.trailingComments = null;
|
||||
|
||||
@@ -33,7 +33,7 @@ const pp = Parser.prototype;
|
||||
pp.checkPropClash = function (prop, propHash) {
|
||||
if (prop.computed) return;
|
||||
|
||||
let key = prop.key;
|
||||
const key = prop.key;
|
||||
let name;
|
||||
switch (key.type) {
|
||||
case "Identifier":
|
||||
@@ -72,10 +72,11 @@ pp.checkPropClash = function (prop, propHash) {
|
||||
// delayed syntax error at correct position).
|
||||
|
||||
pp.parseExpression = function (noIn, refShorthandDefaultPos) {
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
let expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
const expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
|
||||
if (this.match(tt.comma)) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.expressions = [expr];
|
||||
while (this.eat(tt.comma)) {
|
||||
node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
|
||||
@@ -90,8 +91,8 @@ pp.parseExpression = function (noIn, refShorthandDefaultPos) {
|
||||
// operators like `+=`.
|
||||
|
||||
pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos) {
|
||||
let startPos = this.state.start;
|
||||
let startLoc = this.state.startLoc;
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
|
||||
if (this.match(tt._yield) && this.state.inGenerator) {
|
||||
let left = this.parseYield();
|
||||
@@ -114,7 +115,7 @@ pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse, re
|
||||
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos);
|
||||
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
|
||||
if (this.state.type.isAssign) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.operator = this.state.value;
|
||||
node.left = this.match(tt.eq) ? this.toAssignable(left, undefined, "assignment expression") : left;
|
||||
refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
|
||||
@@ -146,8 +147,9 @@ pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse, re
|
||||
// Parse a ternary conditional (`?:`) operator.
|
||||
|
||||
pp.parseMaybeConditional = function (noIn, refShorthandDefaultPos, refNeedsArrowPos) {
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
let expr = this.parseExprOps(noIn, refShorthandDefaultPos);
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
const expr = this.parseExprOps(noIn, refShorthandDefaultPos);
|
||||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
|
||||
|
||||
return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos);
|
||||
@@ -155,7 +157,7 @@ pp.parseMaybeConditional = function (noIn, refShorthandDefaultPos, refNeedsArrow
|
||||
|
||||
pp.parseConditional = function (expr, noIn, startPos, startLoc) {
|
||||
if (this.eat(tt.question)) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.test = expr;
|
||||
node.consequent = this.parseMaybeAssign();
|
||||
this.expect(tt.colon);
|
||||
@@ -168,8 +170,9 @@ pp.parseConditional = function (expr, noIn, startPos, startLoc) {
|
||||
// Start the precedence parser.
|
||||
|
||||
pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
let expr = this.parseMaybeUnary(refShorthandDefaultPos);
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
const expr = this.parseMaybeUnary(refShorthandDefaultPos);
|
||||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
|
||||
return expr;
|
||||
} else {
|
||||
@@ -184,10 +187,10 @@ pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
|
||||
// operator that has a lower precedence than the set it is parsing.
|
||||
|
||||
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
||||
let prec = this.state.type.binop;
|
||||
const prec = this.state.type.binop;
|
||||
if (prec != null && (!noIn || !this.match(tt._in))) {
|
||||
if (prec > minPrec) {
|
||||
let node = this.startNodeAt(leftStartPos, leftStartLoc);
|
||||
const node = this.startNodeAt(leftStartPos, leftStartLoc);
|
||||
node.left = left;
|
||||
node.operator = this.state.value;
|
||||
|
||||
@@ -201,11 +204,11 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
||||
this.raise(left.argument.start, "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.");
|
||||
}
|
||||
|
||||
let op = this.state.type;
|
||||
const op = this.state.type;
|
||||
this.next();
|
||||
|
||||
let startPos = this.state.start;
|
||||
let startLoc = this.state.startLoc;
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, op.rightAssociative ? prec - 1 : prec, noIn);
|
||||
|
||||
this.finishNode(node, (op === tt.logicalOR || op === tt.logicalAND) ? "LogicalExpression" : "BinaryExpression");
|
||||
@@ -219,13 +222,13 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
||||
|
||||
pp.parseMaybeUnary = function (refShorthandDefaultPos) {
|
||||
if (this.state.type.prefix) {
|
||||
let node = this.startNode();
|
||||
let update = this.match(tt.incDec);
|
||||
const node = this.startNode();
|
||||
const update = this.match(tt.incDec);
|
||||
node.operator = this.state.value;
|
||||
node.prefix = true;
|
||||
this.next();
|
||||
|
||||
let argType = this.state.type;
|
||||
const argType = this.state.type;
|
||||
node.argument = this.parseMaybeUnary();
|
||||
|
||||
this.addExtra(node, "parenthesizedArgument", argType === tt.parenL && (!node.argument.extra || !node.argument.extra.parenthesized));
|
||||
@@ -243,11 +246,12 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) {
|
||||
return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
|
||||
}
|
||||
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
let expr = this.parseExprSubscripts(refShorthandDefaultPos);
|
||||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
|
||||
while (this.state.type.postfix && !this.canInsertSemicolon()) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.operator = this.state.value;
|
||||
node.prefix = false;
|
||||
node.argument = expr;
|
||||
@@ -261,9 +265,10 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) {
|
||||
// Parse call, dot, and `[]`-subscript expressions.
|
||||
|
||||
pp.parseExprSubscripts = function (refShorthandDefaultPos) {
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
let potentialArrowAt = this.state.potentialArrowAt;
|
||||
let expr = this.parseExprAtom(refShorthandDefaultPos);
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
const potentialArrowAt = this.state.potentialArrowAt;
|
||||
const expr = this.parseExprAtom(refShorthandDefaultPos);
|
||||
|
||||
if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {
|
||||
return expr;
|
||||
@@ -279,28 +284,28 @@ pp.parseExprSubscripts = function (refShorthandDefaultPos) {
|
||||
pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
|
||||
for (;;) {
|
||||
if (!noCalls && this.eat(tt.doubleColon)) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.object = base;
|
||||
node.callee = this.parseNoCallExpr();
|
||||
return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls);
|
||||
} else if (this.eat(tt.dot)) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.object = base;
|
||||
node.property = this.parseIdentifier(true);
|
||||
node.computed = false;
|
||||
base = this.finishNode(node, "MemberExpression");
|
||||
} else if (this.eat(tt.bracketL)) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.object = base;
|
||||
node.property = this.parseExpression();
|
||||
node.computed = true;
|
||||
this.expect(tt.bracketR);
|
||||
base = this.finishNode(node, "MemberExpression");
|
||||
} else if (!noCalls && this.match(tt.parenL)) {
|
||||
let possibleAsync = this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon();
|
||||
const possibleAsync = this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon();
|
||||
this.next();
|
||||
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.callee = base;
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
|
||||
if (node.callee.type === "Import" && node.arguments.length !== 1) {
|
||||
@@ -314,7 +319,7 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
|
||||
this.toReferencedList(node.arguments);
|
||||
}
|
||||
} else if (this.match(tt.backQuote)) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.tag = base;
|
||||
node.quasi = this.parseTemplate();
|
||||
base = this.finishNode(node, "TaggedTemplateExpression");
|
||||
@@ -325,9 +330,10 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
|
||||
};
|
||||
|
||||
pp.parseCallExpressionArguments = function (close, possibleAsyncArrow) {
|
||||
const elts = [];
|
||||
let innerParenStart;
|
||||
let first = true;
|
||||
|
||||
let elts = [], first = true;
|
||||
while (!this.eat(close)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
@@ -364,7 +370,8 @@ pp.parseAsyncArrowFromCallExpression = function (node, call) {
|
||||
// Parse a no-call expression (like argument of `new` or `::` operators).
|
||||
|
||||
pp.parseNoCallExpr = function () {
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
|
||||
};
|
||||
|
||||
@@ -374,7 +381,9 @@ pp.parseNoCallExpr = function () {
|
||||
// or `{}`.
|
||||
|
||||
pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
let node, canBeArrow = this.state.potentialArrowAt === this.state.start;
|
||||
const canBeArrow = this.state.potentialArrowAt === this.state.start;
|
||||
let node;
|
||||
|
||||
switch (this.state.type) {
|
||||
case tt._super:
|
||||
if (!this.state.inMethod && !this.options.allowSuperOutsideMethod) {
|
||||
@@ -411,9 +420,9 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
|
||||
case tt.name:
|
||||
node = this.startNode();
|
||||
let allowAwait = this.state.value === "await" && this.state.inAsync;
|
||||
let allowYield = this.shouldAllowYieldIdentifier();
|
||||
let id = this.parseIdentifier(allowAwait || allowYield);
|
||||
const allowAwait = this.state.value === "await" && this.state.inAsync;
|
||||
const allowYield = this.shouldAllowYieldIdentifier();
|
||||
const id = this.parseIdentifier(allowAwait || allowYield);
|
||||
|
||||
if (id.name === "await") {
|
||||
if (this.state.inAsync || this.inModule) {
|
||||
@@ -423,7 +432,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
this.next();
|
||||
return this.parseFunction(node, false, false, true);
|
||||
} else if (canBeArrow && id.name === "async" && this.match(tt.name)) {
|
||||
let params = [this.parseIdentifier()];
|
||||
const params = [this.parseIdentifier()];
|
||||
this.expect(tt.arrow);
|
||||
// let foo = bar => {};
|
||||
return this.parseArrowExpression(node, params, true);
|
||||
@@ -437,10 +446,10 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
|
||||
case tt._do:
|
||||
if (this.hasPlugin("doExpressions")) {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
let oldInFunction = this.state.inFunction;
|
||||
let oldLabels = this.state.labels;
|
||||
const oldInFunction = this.state.inFunction;
|
||||
const oldLabels = this.state.labels;
|
||||
this.state.labels = [];
|
||||
this.state.inFunction = false;
|
||||
node.body = this.parseBlock(false, true);
|
||||
@@ -450,7 +459,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
}
|
||||
|
||||
case tt.regexp:
|
||||
let value = this.state.value;
|
||||
const value = this.state.value;
|
||||
node = this.parseLiteral(value.value, "RegExpLiteral");
|
||||
node.pattern = value.pattern;
|
||||
node.flags = value.flags;
|
||||
@@ -507,7 +516,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
node = this.startNode();
|
||||
this.next();
|
||||
node.object = null;
|
||||
let callee = node.callee = this.parseNoCallExpr();
|
||||
const callee = node.callee = this.parseNoCallExpr();
|
||||
if (callee.type === "MemberExpression") {
|
||||
return this.finishNode(node, "BindExpression");
|
||||
} else {
|
||||
@@ -520,8 +529,8 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
};
|
||||
|
||||
pp.parseFunctionExpression = function () {
|
||||
let node = this.startNode();
|
||||
let meta = this.parseIdentifier(true);
|
||||
const node = this.startNode();
|
||||
const meta = this.parseIdentifier(true);
|
||||
if (this.state.inGenerator && this.eat(tt.dot) && this.hasPlugin("functionSent")) {
|
||||
return this.parseMetaProperty(node, meta, "sent");
|
||||
} else {
|
||||
@@ -541,7 +550,7 @@ pp.parseMetaProperty = function (node, meta, propertyName) {
|
||||
};
|
||||
|
||||
pp.parseLiteral = function (value, type) {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.addExtra(node, "rawValue", value);
|
||||
this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end));
|
||||
node.value = value;
|
||||
@@ -551,7 +560,7 @@ pp.parseLiteral = function (value, type) {
|
||||
|
||||
pp.parseParenExpression = function () {
|
||||
this.expect(tt.parenL);
|
||||
let val = this.parseExpression();
|
||||
const val = this.parseExpression();
|
||||
this.expect(tt.parenR);
|
||||
return val;
|
||||
};
|
||||
@@ -563,10 +572,15 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
|
||||
let val;
|
||||
this.expect(tt.parenL);
|
||||
|
||||
let innerStartPos = this.state.start, innerStartLoc = this.state.startLoc;
|
||||
let exprList = [], first = true;
|
||||
let refShorthandDefaultPos = { start: 0 }, spreadStart, optionalCommaStart;
|
||||
let refNeedsArrowPos = { start: 0 };
|
||||
const innerStartPos = this.state.start;
|
||||
const innerStartLoc = this.state.startLoc;
|
||||
const exprList = [];
|
||||
const refShorthandDefaultPos = { start: 0 };
|
||||
const refNeedsArrowPos = { start: 0 };
|
||||
let first = true;
|
||||
let spreadStart;
|
||||
let optionalCommaStart;
|
||||
|
||||
while (!this.match(tt.parenR)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
@@ -579,7 +593,8 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
|
||||
}
|
||||
|
||||
if (this.match(tt.ellipsis)) {
|
||||
let spreadNodeStartPos = this.state.start, spreadNodeStartLoc = this.state.startLoc;
|
||||
const spreadNodeStartPos = this.state.start;
|
||||
const spreadNodeStartLoc = this.state.startLoc;
|
||||
spreadStart = this.state.start;
|
||||
exprList.push(this.parseParenItem(this.parseRest(), spreadNodeStartLoc, spreadNodeStartPos));
|
||||
break;
|
||||
@@ -588,13 +603,13 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
|
||||
}
|
||||
}
|
||||
|
||||
let innerEndPos = this.state.start;
|
||||
let innerEndLoc = this.state.startLoc;
|
||||
const innerEndPos = this.state.start;
|
||||
const innerEndLoc = this.state.startLoc;
|
||||
this.expect(tt.parenR);
|
||||
|
||||
let arrowNode = this.startNodeAt(startPos, startLoc);
|
||||
if (canBeArrow && this.shouldParseArrow() && (arrowNode = this.parseArrow(arrowNode))) {
|
||||
for (let param of exprList) {
|
||||
for (const param of exprList) {
|
||||
if (param.extra && param.extra.parenthesized) this.unexpected(param.extra.parenStart);
|
||||
}
|
||||
|
||||
@@ -644,8 +659,8 @@ pp.parseParenItem = function (node) {
|
||||
// least, not without wrapping it in parentheses. Thus, it uses the
|
||||
|
||||
pp.parseNew = function () {
|
||||
let node = this.startNode();
|
||||
let meta = this.parseIdentifier(true);
|
||||
const node = this.startNode();
|
||||
const meta = this.parseIdentifier(true);
|
||||
|
||||
if (this.eat(tt.dot)) {
|
||||
return this.parseMetaProperty(node, meta, "target");
|
||||
@@ -666,7 +681,7 @@ pp.parseNew = function () {
|
||||
// Parse template expression.
|
||||
|
||||
pp.parseTemplateElement = function () {
|
||||
let elem = this.startNode();
|
||||
const elem = this.startNode();
|
||||
elem.value = {
|
||||
raw: this.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"),
|
||||
cooked: this.state.value
|
||||
@@ -677,7 +692,7 @@ pp.parseTemplateElement = function () {
|
||||
};
|
||||
|
||||
pp.parseTemplate = function () {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
node.expressions = [];
|
||||
let curElt = this.parseTemplateElement();
|
||||
@@ -696,9 +711,9 @@ pp.parseTemplate = function () {
|
||||
|
||||
pp.parseObj = function (isPattern, refShorthandDefaultPos) {
|
||||
let decorators = [];
|
||||
let propHash = Object.create(null);
|
||||
const propHash = Object.create(null);
|
||||
let first = true;
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
|
||||
node.properties = [];
|
||||
this.next();
|
||||
@@ -761,7 +776,7 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
|
||||
if (!isPattern && this.isContextual("async")) {
|
||||
if (isGenerator) this.unexpected();
|
||||
|
||||
let asyncId = this.parseIdentifier();
|
||||
const asyncId = this.parseIdentifier();
|
||||
if (this.match(tt.colon) || this.match(tt.parenL) || this.match(tt.braceR) || this.match(tt.eq) || this.match(tt.comma)) {
|
||||
prop.key = asyncId;
|
||||
} else {
|
||||
@@ -813,9 +828,9 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
|
||||
prop.kind = prop.key.name;
|
||||
this.parsePropertyName(prop);
|
||||
this.parseMethod(prop, false);
|
||||
let paramCount = prop.kind === "get" ? 0 : 1;
|
||||
const paramCount = prop.kind === "get" ? 0 : 1;
|
||||
if (prop.params.length !== paramCount) {
|
||||
let start = prop.start;
|
||||
const start = prop.start;
|
||||
if (prop.kind === "get") {
|
||||
this.raise(start, "getter should have no params");
|
||||
} else {
|
||||
@@ -872,7 +887,7 @@ pp.initFunction = function (node, isAsync) {
|
||||
// Parse object or class method.
|
||||
|
||||
pp.parseMethod = function (node, isGenerator, isAsync) {
|
||||
let oldInMethod = this.state.inMethod;
|
||||
const oldInMethod = this.state.inMethod;
|
||||
this.state.inMethod = node.kind || true;
|
||||
this.initFunction(node, isAsync);
|
||||
this.expect(tt.parenL);
|
||||
@@ -895,9 +910,9 @@ pp.parseArrowExpression = function (node, params, isAsync) {
|
||||
// Parse function body and check parameters.
|
||||
|
||||
pp.parseFunctionBody = function (node, allowExpression) {
|
||||
let isExpression = allowExpression && !this.match(tt.braceL);
|
||||
const isExpression = allowExpression && !this.match(tt.braceL);
|
||||
|
||||
let oldInAsync = this.state.inAsync;
|
||||
const oldInAsync = this.state.inAsync;
|
||||
this.state.inAsync = node.async;
|
||||
if (isExpression) {
|
||||
node.body = this.parseMaybeAssign();
|
||||
@@ -905,7 +920,9 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
} else {
|
||||
// Start a new scope with regard to labels and the `inFunction`
|
||||
// flag (restore them to their old value afterwards).
|
||||
let oldInFunc = this.state.inFunction, oldInGen = this.state.inGenerator, oldLabels = this.state.labels;
|
||||
const oldInFunc = this.state.inFunction;
|
||||
const oldInGen = this.state.inGenerator;
|
||||
const oldLabels = this.state.labels;
|
||||
this.state.inFunction = true; this.state.inGenerator = node.generator; this.state.labels = [];
|
||||
node.body = this.parseBlock(true);
|
||||
node.expression = false;
|
||||
@@ -924,7 +941,7 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
|
||||
// normal function
|
||||
if (!isExpression && node.body.directives.length) {
|
||||
for (let directive of (node.body.directives: Array<Object>)) {
|
||||
for (const directive of (node.body.directives: Array<Object>)) {
|
||||
if (directive.value.value === "use strict") {
|
||||
isStrict = true;
|
||||
checkLVal = true;
|
||||
@@ -939,13 +956,13 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
}
|
||||
|
||||
if (checkLVal) {
|
||||
let nameHash = Object.create(null);
|
||||
let oldStrict = this.state.strict;
|
||||
const nameHash = Object.create(null);
|
||||
const oldStrict = this.state.strict;
|
||||
if (isStrict) this.state.strict = true;
|
||||
if (node.id) {
|
||||
this.checkLVal(node.id, true, undefined, "function name");
|
||||
}
|
||||
for (let param of (node.params: Array<Object>)) {
|
||||
for (const param of (node.params: Array<Object>)) {
|
||||
if (isStrict && param.type !== "Identifier") {
|
||||
this.raise(param.start, "Non-simple parameter in strict mode");
|
||||
}
|
||||
@@ -962,7 +979,9 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
// for array literals).
|
||||
|
||||
pp.parseExprList = function (close, allowEmpty, refShorthandDefaultPos) {
|
||||
let elts = [], first = true;
|
||||
const elts = [];
|
||||
let first = true;
|
||||
|
||||
while (!this.eat(close)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
@@ -993,7 +1012,7 @@ pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos) {
|
||||
// identifiers.
|
||||
|
||||
pp.parseIdentifier = function (liberal) {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
|
||||
if (this.match(tt.name)) {
|
||||
if (!liberal) {
|
||||
@@ -1044,7 +1063,7 @@ pp.parseAwait = function (node) {
|
||||
// Parses yield expression inside generator.
|
||||
|
||||
pp.parseYield = function () {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
if (this.match(tt.semi) || this.canInsertSemicolon() || (!this.match(tt.star) && !this.state.type.startsExpr)) {
|
||||
node.delegate = false;
|
||||
|
||||
@@ -60,7 +60,7 @@ export default class Parser extends Tokenizer {
|
||||
pluginNames.push("flow");
|
||||
|
||||
pluginNames.forEach((name) => {
|
||||
let plugin = plugins[name];
|
||||
const plugin = plugins[name];
|
||||
if (plugin) plugin(this);
|
||||
});
|
||||
}
|
||||
@@ -73,7 +73,7 @@ export default class Parser extends Tokenizer {
|
||||
return { "*": true };
|
||||
}
|
||||
|
||||
let pluginMap = {};
|
||||
const pluginMap = {};
|
||||
|
||||
if (pluginList.indexOf("flow") >= 0) {
|
||||
// ensure flow plugin loads last
|
||||
@@ -81,11 +81,11 @@ export default class Parser extends Tokenizer {
|
||||
pluginList.push("flow");
|
||||
}
|
||||
|
||||
for (let name of pluginList) {
|
||||
for (const name of pluginList) {
|
||||
if (!pluginMap[name]) {
|
||||
pluginMap[name] = true;
|
||||
|
||||
let plugin = plugins[name];
|
||||
const plugin = plugins[name];
|
||||
if (plugin) plugin(this);
|
||||
}
|
||||
}
|
||||
@@ -100,8 +100,8 @@ export default class Parser extends Tokenizer {
|
||||
body: Array<Object>
|
||||
}
|
||||
} {
|
||||
let file = this.startNode();
|
||||
let program = this.startNode();
|
||||
const file = this.startNode();
|
||||
const program = this.startNode();
|
||||
this.nextToken();
|
||||
return this.parseTopLevel(file, program);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ const pp = Parser.prototype;
|
||||
// message.
|
||||
|
||||
pp.raise = function (pos, message) {
|
||||
let loc = getLineInfo(this.input, pos);
|
||||
const loc = getLineInfo(this.input, pos);
|
||||
message += ` (${loc.line}:${loc.column})`;
|
||||
let err = new SyntaxError(message);
|
||||
const err = new SyntaxError(message);
|
||||
err.pos = pos;
|
||||
err.loc = loc;
|
||||
throw err;
|
||||
|
||||
@@ -19,7 +19,7 @@ pp.toAssignable = function (node, isBinding, contextDescription) {
|
||||
|
||||
case "ObjectExpression":
|
||||
node.type = "ObjectPattern";
|
||||
for (let prop of (node.properties: Array<Object>)) {
|
||||
for (const prop of (node.properties: Array<Object>)) {
|
||||
if (prop.type === "ObjectMethod") {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
this.raise(prop.key.start, "Object pattern can't contain getter or setter");
|
||||
@@ -72,12 +72,12 @@ pp.toAssignable = function (node, isBinding, contextDescription) {
|
||||
pp.toAssignableList = function (exprList, isBinding, contextDescription) {
|
||||
let end = exprList.length;
|
||||
if (end) {
|
||||
let last = exprList[end - 1];
|
||||
const last = exprList[end - 1];
|
||||
if (last && last.type === "RestElement") {
|
||||
--end;
|
||||
} else if (last && last.type === "SpreadElement") {
|
||||
last.type = "RestElement";
|
||||
let arg = last.argument;
|
||||
const arg = last.argument;
|
||||
this.toAssignable(arg, isBinding, contextDescription);
|
||||
if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") {
|
||||
this.unexpected(arg.start);
|
||||
@@ -86,7 +86,7 @@ pp.toAssignableList = function (exprList, isBinding, contextDescription) {
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < end; i++) {
|
||||
let elt = exprList[i];
|
||||
const elt = exprList[i];
|
||||
if (elt) this.toAssignable(elt, isBinding, contextDescription);
|
||||
}
|
||||
return exprList;
|
||||
@@ -101,14 +101,14 @@ pp.toReferencedList = function (exprList) {
|
||||
// Parses spread element.
|
||||
|
||||
pp.parseSpread = function (refShorthandDefaultPos) {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
node.argument = this.parseMaybeAssign(false, refShorthandDefaultPos);
|
||||
return this.finishNode(node, "SpreadElement");
|
||||
};
|
||||
|
||||
pp.parseRest = function () {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
node.argument = this.parseBindingIdentifier();
|
||||
return this.finishNode(node, "RestElement");
|
||||
@@ -133,7 +133,7 @@ pp.parseBindingAtom = function () {
|
||||
return this.parseIdentifier(true);
|
||||
|
||||
case tt.bracketL:
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
node.elements = this.parseBindingList(tt.bracketR, true);
|
||||
return this.finishNode(node, "ArrayPattern");
|
||||
@@ -147,7 +147,7 @@ pp.parseBindingAtom = function () {
|
||||
};
|
||||
|
||||
pp.parseBindingList = function (close, allowEmpty) {
|
||||
let elts = [];
|
||||
const elts = [];
|
||||
let first = true;
|
||||
while (!this.eat(close)) {
|
||||
if (first) {
|
||||
@@ -164,11 +164,11 @@ pp.parseBindingList = function (close, allowEmpty) {
|
||||
this.expect(close);
|
||||
break;
|
||||
} else {
|
||||
let decorators = [];
|
||||
const decorators = [];
|
||||
while (this.match(tt.at)) {
|
||||
decorators.push(this.parseDecorator());
|
||||
}
|
||||
let left = this.parseMaybeDefault();
|
||||
const left = this.parseMaybeDefault();
|
||||
if (decorators.length) {
|
||||
left.decorators = decorators;
|
||||
}
|
||||
@@ -191,7 +191,7 @@ pp.parseMaybeDefault = function (startPos, startLoc, left) {
|
||||
left = left || this.parseBindingAtom();
|
||||
if (!this.eat(tt.eq)) return left;
|
||||
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.left = left;
|
||||
node.right = this.parseMaybeAssign();
|
||||
return this.finishNode(node, "AssignmentPattern");
|
||||
@@ -217,7 +217,7 @@ pp.checkLVal = function (expr, isBinding, checkClashes, contextDescription) {
|
||||
// true
|
||||
// > obj.__proto__
|
||||
// null
|
||||
let key = `_${expr.name}`;
|
||||
const key = `_${expr.name}`;
|
||||
|
||||
if (checkClashes[key]) {
|
||||
this.raise(expr.start, "Argument name clash in strict mode");
|
||||
@@ -239,7 +239,7 @@ pp.checkLVal = function (expr, isBinding, checkClashes, contextDescription) {
|
||||
break;
|
||||
|
||||
case "ArrayPattern":
|
||||
for (let elem of (expr.elements: Array<Object>)) {
|
||||
for (const elem of (expr.elements: Array<Object>)) {
|
||||
if (elem) this.checkLVal(elem, isBinding, checkClashes, "array destructuring pattern");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -22,7 +22,7 @@ class Node {
|
||||
|
||||
__clone(): Node {
|
||||
const node2 = new Node;
|
||||
for (let key in this) {
|
||||
for (const key in this) {
|
||||
// Do not clone comments that are already attached to the node
|
||||
if (commentKeys.indexOf(key) < 0) {
|
||||
node2[key] = this[key];
|
||||
|
||||
@@ -31,13 +31,13 @@ const loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
|
||||
// TODO
|
||||
|
||||
pp.stmtToDirective = function (stmt) {
|
||||
let expr = stmt.expression;
|
||||
const expr = stmt.expression;
|
||||
|
||||
let directiveLiteral = this.startNodeAt(expr.start, expr.loc.start);
|
||||
let directive = this.startNodeAt(stmt.start, stmt.loc.start);
|
||||
const directiveLiteral = this.startNodeAt(expr.start, expr.loc.start);
|
||||
const directive = this.startNodeAt(stmt.start, stmt.loc.start);
|
||||
|
||||
let raw = this.input.slice(expr.start, expr.end);
|
||||
let val = directiveLiteral.value = raw.slice(1, -1); // remove quotes
|
||||
const raw = this.input.slice(expr.start, expr.end);
|
||||
const val = directiveLiteral.value = raw.slice(1, -1); // remove quotes
|
||||
|
||||
this.addExtra(directiveLiteral, "raw", raw);
|
||||
this.addExtra(directiveLiteral, "rawValue", val);
|
||||
@@ -59,7 +59,8 @@ pp.parseStatement = function (declaration, topLevel) {
|
||||
this.parseDecorators(true);
|
||||
}
|
||||
|
||||
let starttype = this.state.type, node = this.startNode();
|
||||
const starttype = this.state.type;
|
||||
const node = this.startNode();
|
||||
|
||||
// Most types of statements are recognized by the keyword they
|
||||
// start with. Many are trivial to parse, some require a bit of
|
||||
@@ -114,7 +115,7 @@ pp.parseStatement = function (declaration, topLevel) {
|
||||
case tt.name:
|
||||
if (this.state.value === "async") {
|
||||
// peek ahead and see if next token is a function
|
||||
let state = this.state.clone();
|
||||
const state = this.state.clone();
|
||||
this.next();
|
||||
if (this.match(tt._function) && !this.canInsertSemicolon()) {
|
||||
this.expect(tt._function);
|
||||
@@ -130,8 +131,8 @@ pp.parseStatement = function (declaration, topLevel) {
|
||||
// simply start parsing an expression, and afterwards, if the
|
||||
// next token is a colon and the expression was a simple
|
||||
// Identifier node, we switch to interpreting it as a label.
|
||||
let maybeName = this.state.value;
|
||||
let expr = this.parseExpression();
|
||||
const maybeName = this.state.value;
|
||||
const expr = this.parseExpression();
|
||||
|
||||
if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) {
|
||||
return this.parseLabeledStatement(node, maybeName, expr);
|
||||
@@ -149,7 +150,7 @@ pp.takeDecorators = function (node) {
|
||||
|
||||
pp.parseDecorators = function (allowExport) {
|
||||
while (this.match(tt.at)) {
|
||||
let decorator = this.parseDecorator();
|
||||
const decorator = this.parseDecorator();
|
||||
this.state.decorators.push(decorator);
|
||||
}
|
||||
|
||||
@@ -166,14 +167,14 @@ pp.parseDecorator = function () {
|
||||
if (!this.hasPlugin("decorators")) {
|
||||
this.unexpected();
|
||||
}
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
node.expression = this.parseMaybeAssign();
|
||||
return this.finishNode(node, "Decorator");
|
||||
};
|
||||
|
||||
pp.parseBreakContinueStatement = function (node, keyword) {
|
||||
let isBreak = keyword === "break";
|
||||
const isBreak = keyword === "break";
|
||||
this.next();
|
||||
|
||||
if (this.isLineTerminator()) {
|
||||
@@ -189,7 +190,7 @@ pp.parseBreakContinueStatement = function (node, keyword) {
|
||||
// continue to.
|
||||
let i;
|
||||
for (i = 0; i < this.state.labels.length; ++i) {
|
||||
let lab = this.state.labels[i];
|
||||
const lab = this.state.labels[i];
|
||||
if (node.label == null || lab.name === node.label.name) {
|
||||
if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
|
||||
if (node.label && isBreak) break;
|
||||
@@ -243,7 +244,8 @@ pp.parseForStatement = function (node) {
|
||||
}
|
||||
|
||||
if (this.match(tt._var) || this.match(tt._let) || this.match(tt._const)) {
|
||||
let init = this.startNode(), varKind = this.state.type;
|
||||
const init = this.startNode();
|
||||
const varKind = this.state.type;
|
||||
this.next();
|
||||
this.parseVar(init, true, varKind);
|
||||
this.finishNode(init, "VariableDeclaration");
|
||||
@@ -259,8 +261,8 @@ pp.parseForStatement = function (node) {
|
||||
return this.parseFor(node, init);
|
||||
}
|
||||
|
||||
let refShorthandDefaultPos = {start: 0};
|
||||
let init = this.parseExpression(true, refShorthandDefaultPos);
|
||||
const refShorthandDefaultPos = {start: 0};
|
||||
const init = this.parseExpression(true, refShorthandDefaultPos);
|
||||
if (this.match(tt._in) || this.isContextual("of")) {
|
||||
const description = this.isContextual("of") ? "for-of statement" : "for-in statement";
|
||||
this.toAssignable(init, undefined, description);
|
||||
@@ -323,7 +325,7 @@ pp.parseSwitchStatement = function (node) {
|
||||
let cur;
|
||||
for (let sawDefault; !this.match(tt.braceR); ) {
|
||||
if (this.match(tt._case) || this.match(tt._default)) {
|
||||
let isCase = this.match(tt._case);
|
||||
const isCase = this.match(tt._case);
|
||||
if (cur) this.finishNode(cur, "SwitchCase");
|
||||
node.cases.push(cur = this.startNode());
|
||||
cur.consequent = [];
|
||||
@@ -361,7 +363,7 @@ pp.parseThrowStatement = function (node) {
|
||||
|
||||
// Reused empty array added for node fields that are always empty.
|
||||
|
||||
let empty = [];
|
||||
const empty = [];
|
||||
|
||||
pp.parseTryStatement = function (node) {
|
||||
this.next();
|
||||
@@ -370,7 +372,7 @@ pp.parseTryStatement = function (node) {
|
||||
node.handler = null;
|
||||
|
||||
if (this.match(tt._catch)) {
|
||||
let clause = this.startNode();
|
||||
const clause = this.startNode();
|
||||
this.next();
|
||||
|
||||
this.expect(tt.parenL);
|
||||
@@ -422,15 +424,15 @@ pp.parseEmptyStatement = function (node) {
|
||||
};
|
||||
|
||||
pp.parseLabeledStatement = function (node, maybeName, expr) {
|
||||
for (let label of (this.state.labels: Array<Object>)) {
|
||||
for (const label of (this.state.labels: Array<Object>)) {
|
||||
if (label.name === maybeName) {
|
||||
this.raise(expr.start, `Label '${maybeName}' is already declared`);
|
||||
}
|
||||
}
|
||||
|
||||
let kind = this.state.type.isLoop ? "loop" : this.match(tt._switch) ? "switch" : null;
|
||||
const kind = this.state.type.isLoop ? "loop" : this.match(tt._switch) ? "switch" : null;
|
||||
for (let i = this.state.labels.length - 1; i >= 0; i--) {
|
||||
let label = this.state.labels[i];
|
||||
const label = this.state.labels[i];
|
||||
if (label.statementStart === node.start) {
|
||||
label.statementStart = this.state.start;
|
||||
label.kind = kind;
|
||||
@@ -457,7 +459,7 @@ pp.parseExpressionStatement = function (node, expr) {
|
||||
// function bodies).
|
||||
|
||||
pp.parseBlock = function (allowDirectives?) {
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
this.expect(tt.braceL);
|
||||
this.parseBlockBody(node, allowDirectives, false, tt.braceR);
|
||||
return this.finishNode(node, "BlockStatement");
|
||||
@@ -478,12 +480,12 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
|
||||
octalPosition = this.state.octalPosition;
|
||||
}
|
||||
|
||||
let stmt = this.parseStatement(true, topLevel);
|
||||
const stmt = this.parseStatement(true, topLevel);
|
||||
|
||||
if (allowDirectives && !parsedNonDirective &&
|
||||
stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" &&
|
||||
!stmt.expression.extra.parenthesized) {
|
||||
let directive = this.stmtToDirective(stmt);
|
||||
const directive = this.stmtToDirective(stmt);
|
||||
node.directives.push(directive);
|
||||
|
||||
if (oldStrict === undefined && directive.value.value === "use strict") {
|
||||
@@ -549,7 +551,7 @@ pp.parseVar = function (node, isFor, kind) {
|
||||
node.declarations = [];
|
||||
node.kind = kind.keyword;
|
||||
for (;;) {
|
||||
let decl = this.startNode();
|
||||
const decl = this.startNode();
|
||||
this.parseVarHead(decl);
|
||||
if (this.eat(tt.eq)) {
|
||||
decl.init = this.parseMaybeAssign(isFor);
|
||||
@@ -575,7 +577,7 @@ pp.parseVarHead = function (decl) {
|
||||
// `isStatement` parameter).
|
||||
|
||||
pp.parseFunction = function (node, isStatement, allowExpressionBody, isAsync, optionalId) {
|
||||
let oldInMethod = this.state.inMethod;
|
||||
const oldInMethod = this.state.inMethod;
|
||||
this.state.inMethod = false;
|
||||
|
||||
this.initFunction(node, isAsync);
|
||||
@@ -631,13 +633,13 @@ pp.isClassMutatorStarter = function () {
|
||||
|
||||
pp.parseClassBody = function (node) {
|
||||
// class bodies are implicitly strict
|
||||
let oldStrict = this.state.strict;
|
||||
const oldStrict = this.state.strict;
|
||||
this.state.strict = true;
|
||||
|
||||
let hadConstructorCall = false;
|
||||
let hadConstructor = false;
|
||||
let decorators = [];
|
||||
let classBody = this.startNode();
|
||||
const classBody = this.startNode();
|
||||
|
||||
classBody.body = [];
|
||||
|
||||
@@ -653,7 +655,7 @@ pp.parseClassBody = function (node) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let method = this.startNode();
|
||||
const method = this.startNode();
|
||||
|
||||
// steal the decorators if there are any
|
||||
if (decorators.length) {
|
||||
@@ -662,7 +664,7 @@ pp.parseClassBody = function (node) {
|
||||
}
|
||||
|
||||
let isConstructorCall = false;
|
||||
let isMaybeStatic = this.match(tt.name) && this.state.value === "static";
|
||||
const isMaybeStatic = this.match(tt.name) && this.state.value === "static";
|
||||
let isGenerator = this.eat(tt.star);
|
||||
let isGetSet = false;
|
||||
let isAsync = false;
|
||||
@@ -687,7 +689,7 @@ pp.parseClassBody = function (node) {
|
||||
}
|
||||
}
|
||||
|
||||
let isAsyncMethod = !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async";
|
||||
const isAsyncMethod = !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async";
|
||||
if (isAsyncMethod) {
|
||||
if (this.hasPlugin("asyncGenerators") && this.eat(tt.star)) isGenerator = true;
|
||||
isAsync = true;
|
||||
@@ -708,7 +710,7 @@ pp.parseClassBody = function (node) {
|
||||
}
|
||||
|
||||
// disallow invalid constructors
|
||||
let isConstructor = !isConstructorCall && !method.static && (
|
||||
const isConstructor = !isConstructorCall && !method.static && (
|
||||
(key.type === "Identifier" && key.name === "constructor") ||
|
||||
(key.type === "StringLiteral" && key.value === "constructor")
|
||||
);
|
||||
@@ -722,7 +724,7 @@ pp.parseClassBody = function (node) {
|
||||
}
|
||||
|
||||
// disallow static prototype method
|
||||
let isStaticPrototype = method.static && (
|
||||
const isStaticPrototype = method.static && (
|
||||
(key.type === "Identifier" && key.name === "prototype") ||
|
||||
(key.type === "StringLiteral" && key.value === "prototype")
|
||||
);
|
||||
@@ -748,9 +750,9 @@ pp.parseClassBody = function (node) {
|
||||
// get methods aren't allowed to have any parameters
|
||||
// set methods must have exactly 1 parameter
|
||||
if (isGetSet) {
|
||||
let paramCount = method.kind === "get" ? 0 : 1;
|
||||
const paramCount = method.kind === "get" ? 0 : 1;
|
||||
if (method.params.length !== paramCount) {
|
||||
let start = method.start;
|
||||
const start = method.start;
|
||||
if (method.kind === "get") {
|
||||
this.raise(start, "getter should have no params");
|
||||
} else {
|
||||
@@ -808,7 +810,7 @@ pp.parseExport = function (node) {
|
||||
this.next();
|
||||
// export * from '...'
|
||||
if (this.match(tt.star)) {
|
||||
let specifier = this.startNode();
|
||||
const specifier = this.startNode();
|
||||
this.next();
|
||||
if (this.hasPlugin("exportExtensions") && this.eatContextual("as")) {
|
||||
specifier.exported = this.parseIdentifier();
|
||||
@@ -820,12 +822,12 @@ pp.parseExport = function (node) {
|
||||
return this.finishNode(node, "ExportAllDeclaration");
|
||||
}
|
||||
} else if (this.hasPlugin("exportExtensions") && this.isExportDefaultSpecifier()) {
|
||||
let specifier = this.startNode();
|
||||
const specifier = this.startNode();
|
||||
specifier.exported = this.parseIdentifier(true);
|
||||
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
|
||||
if (this.match(tt.comma) && this.lookahead().type === tt.star) {
|
||||
this.expect(tt.comma);
|
||||
let specifier = this.startNode();
|
||||
const specifier = this.startNode();
|
||||
this.expect(tt.star);
|
||||
this.expectContextual("as");
|
||||
specifier.exported = this.parseIdentifier();
|
||||
@@ -877,7 +879,7 @@ pp.isExportDefaultSpecifier = function () {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lookahead = this.lookahead();
|
||||
const lookahead = this.lookahead();
|
||||
return lookahead.type === tt.comma || (lookahead.type === tt.name && lookahead.value === "from");
|
||||
};
|
||||
|
||||
@@ -919,7 +921,7 @@ pp.checkExport = function (node, checkNames, isDefault) {
|
||||
this.checkDuplicateExports(node, "default");
|
||||
} else if (node.specifiers && node.specifiers.length) {
|
||||
// Named exports
|
||||
for (let specifier of node.specifiers) {
|
||||
for (const specifier of node.specifiers) {
|
||||
this.checkDuplicateExports(specifier, specifier.exported.name);
|
||||
}
|
||||
} else if (node.declaration) {
|
||||
@@ -927,7 +929,7 @@ pp.checkExport = function (node, checkNames, isDefault) {
|
||||
if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
|
||||
this.checkDuplicateExports(node, node.declaration.id.name);
|
||||
} else if (node.declaration.type === "VariableDeclaration") {
|
||||
for (let declaration of node.declaration.declarations) {
|
||||
for (const declaration of node.declaration.declarations) {
|
||||
this.checkDeclaration(declaration.id);
|
||||
}
|
||||
}
|
||||
@@ -935,7 +937,7 @@ pp.checkExport = function (node, checkNames, isDefault) {
|
||||
}
|
||||
|
||||
if (this.state.decorators.length) {
|
||||
let isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression");
|
||||
const isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression");
|
||||
if (!node.declaration || !isClass) {
|
||||
this.raise(node.start, "You can only use decorators on an export when exporting a class");
|
||||
}
|
||||
@@ -945,11 +947,11 @@ pp.checkExport = function (node, checkNames, isDefault) {
|
||||
|
||||
pp.checkDeclaration = function(node) {
|
||||
if (node.type === "ObjectPattern") {
|
||||
for (let prop of node.properties) {
|
||||
for (const prop of node.properties) {
|
||||
this.checkDeclaration(prop);
|
||||
}
|
||||
} else if (node.type === "ArrayPattern") {
|
||||
for (let elem of node.elements) {
|
||||
for (const elem of node.elements) {
|
||||
if (elem) {
|
||||
this.checkDeclaration(elem);
|
||||
}
|
||||
@@ -980,7 +982,7 @@ pp.raiseDuplicateExportError = function(node, name) {
|
||||
// Parses a comma-separated list of module exports.
|
||||
|
||||
pp.parseExportSpecifiers = function () {
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
let first = true;
|
||||
let needsFrom;
|
||||
|
||||
@@ -995,10 +997,10 @@ pp.parseExportSpecifiers = function () {
|
||||
if (this.eat(tt.braceR)) break;
|
||||
}
|
||||
|
||||
let isDefault = this.match(tt._default);
|
||||
const isDefault = this.match(tt._default);
|
||||
if (isDefault && !needsFrom) needsFrom = true;
|
||||
|
||||
let node = this.startNode();
|
||||
const node = this.startNode();
|
||||
node.local = this.parseIdentifier(isDefault);
|
||||
node.exported = this.eatContextual("as") ? this.parseIdentifier(true) : node.local.__clone();
|
||||
nodes.push(this.finishNode(node, "ExportSpecifier"));
|
||||
@@ -1037,13 +1039,14 @@ pp.parseImportSpecifiers = function (node) {
|
||||
let first = true;
|
||||
if (this.match(tt.name)) {
|
||||
// import defaultObj, { x, y as z } from '...'
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
node.specifiers.push(this.parseImportSpecifierDefault(this.parseIdentifier(), startPos, startLoc));
|
||||
if (!this.eat(tt.comma)) return;
|
||||
}
|
||||
|
||||
if (this.match(tt.star)) {
|
||||
let specifier = this.startNode();
|
||||
const specifier = this.startNode();
|
||||
this.next();
|
||||
this.expectContextual("as");
|
||||
specifier.local = this.parseIdentifier();
|
||||
@@ -1066,7 +1069,7 @@ pp.parseImportSpecifiers = function (node) {
|
||||
};
|
||||
|
||||
pp.parseImportSpecifier = function (node) {
|
||||
let specifier = this.startNode();
|
||||
const specifier = this.startNode();
|
||||
specifier.imported = this.parseIdentifier(true);
|
||||
specifier.local = this.eatContextual("as") ? this.parseIdentifier() : specifier.imported.__clone();
|
||||
this.checkLVal(specifier.local, true, undefined, "import specifier");
|
||||
@@ -1074,7 +1077,7 @@ pp.parseImportSpecifier = function (node) {
|
||||
};
|
||||
|
||||
pp.parseImportSpecifierDefault = function (id, startPos, startLoc) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.local = id;
|
||||
this.checkLVal(node.local, true, undefined, "default import specifier");
|
||||
return this.finishNode(node, "ImportDefaultSpecifier");
|
||||
|
||||
@@ -11,7 +11,7 @@ const pp = Parser.prototype;
|
||||
pp.addExtra = function (node, key, val) {
|
||||
if (!node) return;
|
||||
|
||||
let extra = node.extra = node.extra || {};
|
||||
const extra = node.extra = node.extra || {};
|
||||
extra[key] = val;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user