Socket
Socket
Sign inDemoInstall

@babel/parser

Package Overview
Dependencies
Maintainers
6
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/parser - npm Package Compare versions

Comparing version 7.8.3 to 7.8.4

11

bin/babel-parser.js

@@ -10,8 +10,7 @@ #!/usr/bin/env node

console.error("no filename specified");
process.exit(0);
} else {
var file = fs.readFileSync(filename, "utf8");
var ast = parser.parse(file);
console.log(JSON.stringify(ast, null, " "));
}
var file = fs.readFileSync(filename, "utf8");
var ast = parser.parse(file);
console.log(JSON.stringify(ast, null, " "));

@@ -20,2 +20,4 @@ "use strict";

var _util = require("./util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -28,3 +30,3 @@

class ExpressionParser extends _lval.default {
checkDuplicatedProto(prop, protoRef) {
checkDuplicatedProto(prop, protoRef, refExpressionErrors) {
if (prop.type === "SpreadElement" || prop.computed || prop.kind || prop.shorthand) {

@@ -38,4 +40,10 @@ return;

if (name === "__proto__") {
if (protoRef.used && !protoRef.start) {
protoRef.start = key.start;
if (protoRef.used) {
if (refExpressionErrors) {
if (refExpressionErrors.doubleProto === -1) {
refExpressionErrors.doubleProto = key.start;
}
} else {
this.raise(key.start, "Redefinition of __proto__ property");
}
}

@@ -67,6 +75,6 @@

parseExpression(noIn, refShorthandDefaultPos) {
parseExpression(noIn, refExpressionErrors) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
const expr = this.parseMaybeAssign(noIn, refExpressionErrors);

@@ -78,3 +86,3 @@ if (this.match(_types.types.comma)) {

while (this.eat(_types.types.comma)) {
node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
node.expressions.push(this.parseMaybeAssign(noIn, refExpressionErrors));
}

@@ -89,3 +97,3 @@

parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos) {
parseMaybeAssign(noIn, refExpressionErrors, afterLeftParse, refNeedsArrowPos) {
const startPos = this.state.start;

@@ -108,11 +116,9 @@ const startLoc = this.state.startLoc;

let failOnShorthandAssign;
let ownExpressionErrors;
if (refShorthandDefaultPos) {
failOnShorthandAssign = false;
if (refExpressionErrors) {
ownExpressionErrors = false;
} else {
refShorthandDefaultPos = {
start: 0
};
failOnShorthandAssign = true;
refExpressionErrors = new _util.ExpressionErrors();
ownExpressionErrors = true;
}

@@ -124,3 +130,3 @@

let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos);
let left = this.parseMaybeConditional(noIn, refExpressionErrors, refNeedsArrowPos);

@@ -144,6 +150,11 @@ if (afterLeftParse) {

node.left = this.match(_types.types.eq) ? this.toAssignable(left, undefined, "assignment expression") : left;
if (this.match(_types.types.eq)) {
node.left = this.toAssignable(left);
refExpressionErrors.doubleProto = -1;
} else {
node.left = left;
}
if (refShorthandDefaultPos.start >= node.left.start) {
refShorthandDefaultPos.start = 0;
if (refExpressionErrors.shorthandAssign >= node.left.start) {
refExpressionErrors.shorthandAssign = -1;
}

@@ -155,4 +166,4 @@

return this.finishNode(node, "AssignmentExpression");
} else if (failOnShorthandAssign && refShorthandDefaultPos.start) {
this.unexpected(refShorthandDefaultPos.start);
} else if (ownExpressionErrors) {
this.checkExpressionErrors(refExpressionErrors, true);
}

@@ -163,7 +174,7 @@

parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos) {
parseMaybeConditional(noIn, refExpressionErrors, refNeedsArrowPos) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const potentialArrowAt = this.state.potentialArrowAt;
const expr = this.parseExprOps(noIn, refShorthandDefaultPos);
const expr = this.parseExprOps(noIn, refExpressionErrors);

@@ -174,3 +185,3 @@ if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {

if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos);

@@ -192,7 +203,7 @@ }

parseExprOps(noIn, refShorthandDefaultPos) {
parseExprOps(noIn, refExpressionErrors) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const potentialArrowAt = this.state.potentialArrowAt;
const expr = this.parseMaybeUnary(refShorthandDefaultPos);
const expr = this.parseMaybeUnary(refExpressionErrors);

@@ -203,3 +214,3 @@ if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {

if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
if (this.checkExpressionErrors(refExpressionErrors, false)) {
return expr;

@@ -212,3 +223,3 @@ }

parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) {
const prec = this.state.type.binop;
let prec = this.state.type.binop;

@@ -232,2 +243,4 @@ if (prec != null && (!noIn || !this.match(_types.types._in))) {

const op = this.state.type;
const logical = op === _types.types.logicalOR || op === _types.types.logicalAND;
const coalesce = op === _types.types.nullishCoalescing;

@@ -238,2 +251,4 @@ if (op === _types.types.pipeline) {

this.checkPipelineAtInfixOperator(left, leftStartPos);
} else if (coalesce) {
prec = _types.types.logicalAND.binop;
}

@@ -250,12 +265,9 @@

node.right = this.parseExprOpRightExpr(op, prec, noIn);
this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
const nextOp = this.state.type;
if (op === _types.types.nullishCoalescing) {
if (left.type === "LogicalExpression" && left.operator !== "??" && !(left.extra && left.extra.parenthesized)) {
throw this.raise(left.start, `Nullish coalescing operator(??) requires parens when mixing with logical operators`);
} else if (node.right.type === "LogicalExpression" && node.right.operator !== "??" && !(node.right.extra && node.right.extra.parenthesized)) {
throw this.raise(node.right.start, `Nullish coalescing operator(??) requires parens when mixing with logical operators`);
}
if (coalesce && (nextOp === _types.types.logicalOR || nextOp === _types.types.logicalAND) || logical && nextOp === _types.types.nullishCoalescing) {
throw this.raise(this.state.start, `Nullish coalescing operator(??) requires parens when mixing with logical operators`);
}
this.finishNode(node, op === _types.types.logicalOR || op === _types.types.logicalAND || op === _types.types.nullishCoalescing ? "LogicalExpression" : "BinaryExpression");
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);

@@ -297,3 +309,3 @@ }

parseMaybeUnary(refShorthandDefaultPos) {
parseMaybeUnary(refExpressionErrors) {
if (this.isContextual("await") && this.isAwaitAllowed()) {

@@ -313,7 +325,4 @@ return this.parseAwait();

node.argument = this.parseMaybeUnary();
this.checkExpressionErrors(refExpressionErrors, true);
if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
this.unexpected(refShorthandDefaultPos.start);
}
if (update) {

@@ -336,4 +345,4 @@ this.checkLVal(node.argument, undefined, undefined, "prefix operation");

const startLoc = this.state.startLoc;
let expr = this.parseExprSubscripts(refShorthandDefaultPos);
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
let expr = this.parseExprSubscripts(refExpressionErrors);
if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;

@@ -353,7 +362,7 @@ while (this.state.type.postfix && !this.canInsertSemicolon()) {

parseExprSubscripts(refShorthandDefaultPos) {
parseExprSubscripts(refExpressionErrors) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const potentialArrowAt = this.state.potentialArrowAt;
const expr = this.parseExprAtom(refShorthandDefaultPos);
const expr = this.parseExprAtom(refExpressionErrors);

@@ -364,6 +373,2 @@ if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {

if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
return expr;
}
return this.parseSubscripts(expr, startPos, startLoc);

@@ -544,6 +549,4 @@ }

elts.push(this.parseExprListItem(false, possibleAsyncArrow ? {
elts.push(this.parseExprListItem(false, possibleAsyncArrow ? new _util.ExpressionErrors() : undefined, possibleAsyncArrow ? {
start: 0
} : undefined, possibleAsyncArrow ? {
start: 0
} : undefined, allowPlaceholder));

@@ -578,3 +581,3 @@ }

parseExprAtom(refShorthandDefaultPos) {
parseExprAtom(refExpressionErrors) {
if (this.state.type === _types.types.slash) this.readRegexp();

@@ -710,3 +713,3 @@ const canBeArrow = this.state.potentialArrowAt === this.state.start;

this.next();
node.elements = this.parseExprList(_types.types.bracketR, true, refShorthandDefaultPos, node);
node.elements = this.parseExprList(_types.types.bracketR, true, refExpressionErrors, node);

@@ -725,3 +728,3 @@ if (!this.state.maybeInArrowParameters) {

this.state.inFSharpPipelineDirectBody = false;
const ret = this.parseObj(false, refShorthandDefaultPos);
const ret = this.parseObj(false, refExpressionErrors);
this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;

@@ -896,5 +899,3 @@ return ret;

const exprList = [];
const refShorthandDefaultPos = {
start: 0
};
const refExpressionErrors = new _util.ExpressionErrors();
const refNeedsArrowPos = {

@@ -927,3 +928,3 @@ start: 0

} else {
exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos));
exprList.push(this.parseMaybeAssign(false, refExpressionErrors, this.parseParenItem, refNeedsArrowPos));
}

@@ -965,7 +966,3 @@ }

if (spreadStart) this.unexpected(spreadStart);
if (refShorthandDefaultPos.start) {
this.unexpected(refShorthandDefaultPos.start);
}
this.checkExpressionErrors(refExpressionErrors, true);
if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start);

@@ -1090,3 +1087,3 @@ this.toReferencedListDeep(exprList, true);

parseObj(isPattern, refShorthandDefaultPos) {
parseObj(isPattern, refExpressionErrors) {
const propHash = Object.create(null);

@@ -1111,5 +1108,8 @@ let first = true;

const prop = this.parseObjectMember(isPattern, refShorthandDefaultPos);
if (!isPattern) this.checkDuplicatedProto(prop, propHash);
const prop = this.parseObjectMember(isPattern, refExpressionErrors);
if (!isPattern) {
this.checkDuplicatedProto(prop, propHash, refExpressionErrors);
}
if (prop.shorthand) {

@@ -1122,6 +1122,2 @@ this.addExtra(prop, "shorthand", true);

if (!this.match(_types.types.eq) && propHash.start !== undefined) {
this.raise(propHash.start, "Redefinition of __proto__ property");
}
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");

@@ -1134,3 +1130,3 @@ }

parseObjectMember(isPattern, refShorthandDefaultPos) {
parseObjectMember(isPattern, refExpressionErrors) {
let decorators = [];

@@ -1174,3 +1170,3 @@

if (isPattern || refShorthandDefaultPos) {
if (isPattern || refExpressionErrors) {
startPos = this.state.start;

@@ -1195,3 +1191,3 @@ startLoc = this.state.startLoc;

this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc);
this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refExpressionErrors, containsEsc);
return prop;

@@ -1243,7 +1239,7 @@ }

parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) {
parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors) {
prop.shorthand = false;
if (this.eat(_types.types.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refExpressionErrors);
return this.finishNode(prop, "ObjectProperty");

@@ -1257,5 +1253,5 @@ }

prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone());
} else if (this.match(_types.types.eq) && refShorthandDefaultPos) {
if (!refShorthandDefaultPos.start) {
refShorthandDefaultPos.start = this.state.start;
} else if (this.match(_types.types.eq) && refExpressionErrors) {
if (refExpressionErrors.shorthandAssign === -1) {
refExpressionErrors.shorthandAssign = this.state.start;
}

@@ -1273,4 +1269,4 @@

parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc) {
const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos);
parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refExpressionErrors, containsEsc) {
const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors);
if (!node) this.unexpected();

@@ -1329,6 +1325,11 @@ return node;

const oldAwaitPos = this.state.awaitPos;
if (params) {
this.state.maybeInArrowParameters = true;
this.setArrowFunctionParameters(node, params, trailingCommaPos);
}
this.state.maybeInArrowParameters = false;
this.state.yieldPos = -1;
this.state.awaitPos = -1;
if (params) this.setArrowFunctionParameters(node, params, trailingCommaPos);
this.parseFunctionBody(node, true);

@@ -1343,3 +1344,3 @@ this.scope.exit();

setArrowFunctionParameters(node, params, trailingCommaPos) {
node.params = this.toAssignableList(params, true, "arrow function parameters", trailingCommaPos);
node.params = this.toAssignableList(params, trailingCommaPos);
}

@@ -1407,3 +1408,3 @@

parseExprList(close, allowEmpty, refShorthandDefaultPos, nodeForExtra) {
parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
const elts = [];

@@ -1428,3 +1429,3 @@ let first = true;

elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos));
elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
}

@@ -1435,3 +1436,3 @@

parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos, allowPlaceholder) {
parseExprListItem(allowEmpty, refExpressionErrors, refNeedsArrowPos, allowPlaceholder) {
let elt;

@@ -1444,3 +1445,3 @@

const spreadNodeStartLoc = this.state.startLoc;
elt = this.parseParenItem(this.parseSpread(refShorthandDefaultPos, refNeedsArrowPos), spreadNodeStartPos, spreadNodeStartLoc);
elt = this.parseParenItem(this.parseSpread(refExpressionErrors, refNeedsArrowPos), spreadNodeStartPos, spreadNodeStartLoc);
} else if (this.match(_types.types.question)) {

@@ -1457,3 +1458,3 @@ this.expectPlugin("partialApplication");

} else {
elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos);
elt = this.parseMaybeAssign(false, refExpressionErrors, this.parseParenItem, refNeedsArrowPos);
}

@@ -1460,0 +1461,0 @@

@@ -16,2 +16,4 @@ "use strict";

var _util = require("./util");
const unwrapParenthesizedExpression = node => {

@@ -22,77 +24,72 @@ return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;

class LValParser extends _node.NodeUtils {
toAssignable(node, isBinding, contextDescription) {
var _node$extra3;
toAssignable(node) {
var _node$extra, _node$extra3;
if (node) {
var _node$extra;
let parenthesized = undefined;
if (this.options.createParenthesizedExpressions && node.type === "ParenthesizedExpression" || ((_node$extra = node.extra) == null ? void 0 : _node$extra.parenthesized)) {
const parenthesized = unwrapParenthesizedExpression(node);
if (node.type === "ParenthesizedExpression" || ((_node$extra = node.extra) == null ? void 0 : _node$extra.parenthesized)) {
parenthesized = unwrapParenthesizedExpression(node);
if (parenthesized.type !== "Identifier" && parenthesized.type !== "MemberExpression") {
this.raise(node.start, "Invalid parenthesized assignment pattern");
}
if (parenthesized.type !== "Identifier" && parenthesized.type !== "MemberExpression") {
this.raise(node.start, "Invalid parenthesized assignment pattern");
}
}
switch (node.type) {
case "Identifier":
case "ObjectPattern":
case "ArrayPattern":
case "AssignmentPattern":
break;
switch (node.type) {
case "Identifier":
case "ObjectPattern":
case "ArrayPattern":
case "AssignmentPattern":
break;
case "ObjectExpression":
node.type = "ObjectPattern";
case "ObjectExpression":
node.type = "ObjectPattern";
for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
var _node$extra2;
for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
var _node$extra2;
const prop = node.properties[i];
const isLast = i === last;
this.toAssignableObjectExpressionProp(prop, isBinding, isLast);
const prop = node.properties[i];
const isLast = i === last;
this.toAssignableObjectExpressionProp(prop, isLast);
if (isLast && prop.type === "RestElement" && ((_node$extra2 = node.extra) == null ? void 0 : _node$extra2.trailingComma)) {
this.raiseRestNotLast(node.extra.trailingComma);
}
if (isLast && prop.type === "RestElement" && ((_node$extra2 = node.extra) == null ? void 0 : _node$extra2.trailingComma)) {
this.raiseRestNotLast(node.extra.trailingComma);
}
}
break;
break;
case "ObjectProperty":
this.toAssignable(node.value, isBinding, contextDescription);
break;
case "ObjectProperty":
this.toAssignable(node.value);
break;
case "SpreadElement":
{
this.checkToRestConversion(node);
node.type = "RestElement";
const arg = node.argument;
this.toAssignable(arg, isBinding, contextDescription);
break;
}
case "ArrayExpression":
node.type = "ArrayPattern";
this.toAssignableList(node.elements, isBinding, contextDescription, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingComma);
case "SpreadElement":
{
this.checkToRestConversion(node);
node.type = "RestElement";
const arg = node.argument;
this.toAssignable(arg);
break;
}
case "AssignmentExpression":
if (node.operator !== "=") {
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
}
case "ArrayExpression":
node.type = "ArrayPattern";
this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingComma);
break;
node.type = "AssignmentPattern";
delete node.operator;
this.toAssignable(node.left, isBinding, contextDescription);
break;
case "AssignmentExpression":
if (node.operator !== "=") {
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
}
case "ParenthesizedExpression":
node.expression = this.toAssignable(node.expression, isBinding, contextDescription);
break;
node.type = "AssignmentPattern";
delete node.operator;
this.toAssignable(node.left);
break;
case "MemberExpression":
if (!isBinding) break;
case "ParenthesizedExpression":
this.toAssignable(parenthesized);
break;
default:
}
default:
}

@@ -103,3 +100,3 @@

toAssignableObjectExpressionProp(prop, isBinding, isLast) {
toAssignableObjectExpressionProp(prop, isLast) {
if (prop.type === "ObjectMethod") {

@@ -111,7 +108,7 @@ const error = prop.kind === "get" || prop.kind === "set" ? "Object pattern can't contain getter or setter" : "Object pattern can't contain methods";

} else {
this.toAssignable(prop, isBinding, "object destructuring pattern");
this.toAssignable(prop);
}
}
toAssignableList(exprList, isBinding, contextDescription, trailingCommaPos) {
toAssignableList(exprList, trailingCommaPos) {
let end = exprList.length;

@@ -127,3 +124,3 @@

const arg = last.argument;
this.toAssignable(arg, isBinding, contextDescription);
this.toAssignable(arg);

@@ -146,3 +143,3 @@ if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern" && arg.type !== "ObjectPattern") {

if (elt) {
this.toAssignable(elt, isBinding, contextDescription);
this.toAssignable(elt);

@@ -174,6 +171,6 @@ if (elt.type === "RestElement") {

parseSpread(refShorthandDefaultPos, refNeedsArrowPos) {
parseSpread(refExpressionErrors, refNeedsArrowPos) {
const node = this.startNode();
this.next();
node.argument = this.parseMaybeAssign(false, refShorthandDefaultPos, undefined, refNeedsArrowPos);
node.argument = this.parseMaybeAssign(false, refExpressionErrors, undefined, refNeedsArrowPos);
return this.finishNode(node, "SpreadElement");

@@ -180,0 +177,0 @@ }

@@ -20,2 +20,4 @@ "use strict";

var _util = require("./util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -54,3 +56,3 @@

file.comments = this.state.comments;
if (this.options.tokens) file.tokens = this.state.tokens;
if (this.options.tokens) file.tokens = this.tokens;
return this.finishNode(file, "File");

@@ -437,14 +439,12 @@ }

const refShorthandDefaultPos = {
start: 0
};
const init = this.parseExpression(true, refShorthandDefaultPos);
const refExpressionErrors = new _util.ExpressionErrors();
const init = this.parseExpression(true, refExpressionErrors);
if (this.match(_types2.types._in) || this.isContextual("of")) {
this.toAssignable(init);
const description = this.isContextual("of") ? "for-of statement" : "for-in statement";
this.toAssignable(init, undefined, description);
this.checkLVal(init, undefined, undefined, description);
return this.parseForIn(node, init, awaitAt);
} else if (refShorthandDefaultPos.start) {
this.unexpected(refShorthandDefaultPos.start);
} else {
this.checkExpressionErrors(refExpressionErrors, true);
}

@@ -451,0 +451,0 @@

@@ -6,3 +6,3 @@ "use strict";

});
exports.default = void 0;
exports.ExpressionErrors = exports.default = void 0;

@@ -218,4 +218,31 @@ var _types = require("../tokenizer/types");

checkExpressionErrors(refExpressionErrors, andThrow) {
if (!refExpressionErrors) return false;
const {
shorthandAssign,
doubleProto
} = refExpressionErrors;
if (!andThrow) return shorthandAssign >= 0 || doubleProto >= 0;
if (shorthandAssign >= 0) {
this.unexpected(shorthandAssign);
}
if (doubleProto >= 0) {
this.raise(doubleProto, "Redefinition of __proto__ property");
}
}
}
exports.default = UtilParser;
exports.default = UtilParser;
class ExpressionErrors {
constructor() {
this.shorthandAssign = -1;
this.doubleProto = -1;
}
}
exports.ExpressionErrors = ExpressionErrors;

@@ -105,3 +105,3 @@ "use strict";

checkDuplicatedProto(prop, protoRef) {
checkDuplicatedProto(prop, protoRef, refExpressionErrors) {
if (prop.type === "SpreadElement" || prop.computed || prop.method || prop.shorthand) {

@@ -115,4 +115,8 @@ return;

if (name === "__proto__" && prop.kind === "init") {
if (protoRef.used && !protoRef.start) {
protoRef.start = key.start;
if (protoRef.used) {
if (refExpressionErrors && refExpressionErrors.doubleProto === -1) {
refExpressionErrors.doubleProto = key.start;
} else {
this.raise(key.start, "Redefinition of __proto__ property");
}
}

@@ -153,3 +157,3 @@

parseExprAtom(refShorthandDefaultPos) {
parseExprAtom(refExpressionErrors) {
switch (this.state.type) {

@@ -176,3 +180,3 @@ case _types.types.num:

default:
return super.parseExprAtom(refShorthandDefaultPos);
return super.parseExprAtom(refExpressionErrors);
}

@@ -216,4 +220,4 @@ }

parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) {
const node = super.parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos);
parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors) {
const node = super.parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors);

@@ -228,12 +232,12 @@ if (node) {

toAssignable(node, isBinding, contextDescription) {
toAssignable(node) {
if (isSimpleProperty(node)) {
this.toAssignable(node.value, isBinding, contextDescription);
this.toAssignable(node.value);
return node;
}
return super.toAssignable(node, isBinding, contextDescription);
return super.toAssignable(node);
}
toAssignableObjectExpressionProp(prop, isBinding, isLast) {
toAssignableObjectExpressionProp(prop, isLast) {
if (prop.kind === "get" || prop.kind === "set") {

@@ -244,3 +248,3 @@ throw this.raise(prop.key.start, "Object pattern can't contain getter or setter");

} else {
super.toAssignableObjectExpressionProp(prop, isBinding, isLast);
super.toAssignableObjectExpressionProp(prop, isLast);
}

@@ -247,0 +251,0 @@ }

@@ -448,3 +448,3 @@ "use strict";

parseExprAtom(refShortHandDefaultPos) {
parseExprAtom(refExpressionErrors) {
if (this.match(_types.types.jsxText)) {

@@ -458,3 +458,3 @@ return this.parseLiteral(this.state.value, "JSXText");

} else {
return super.parseExprAtom(refShortHandDefaultPos);
return super.parseExprAtom(refExpressionErrors);
}

@@ -461,0 +461,0 @@ }

@@ -1870,7 +1870,7 @@ "use strict";

parseMaybeUnary(refShorthandDefaultPos) {
parseMaybeUnary(refExpressionErrors) {
if (!this.hasPlugin("jsx") && this.isRelational("<")) {
return this.tsParseTypeAssertion();
} else {
return super.parseMaybeUnary(refShorthandDefaultPos);
return super.parseMaybeUnary(refExpressionErrors);
}

@@ -1912,9 +1912,9 @@ }

toAssignable(node, isBinding, contextDescription) {
toAssignable(node) {
switch (node.type) {
case "TSTypeCastExpression":
return super.toAssignable(this.typeCastToParameter(node), isBinding, contextDescription);
return super.toAssignable(this.typeCastToParameter(node));
case "TSParameterProperty":
return super.toAssignable(node, isBinding, contextDescription);
return super.toAssignable(node);

@@ -1924,7 +1924,7 @@ case "TSAsExpression":

case "TSTypeAssertion":
node.expression = this.toAssignable(node.expression, isBinding, contextDescription);
node.expression = this.toAssignable(node.expression);
return node;
default:
return super.toAssignable(node, isBinding, contextDescription);
return super.toAssignable(node);
}

@@ -2006,3 +2006,3 @@ }

toAssignableList(exprList, isBinding) {
toAssignableList(exprList) {
for (let i = 0; i < exprList.length; i++) {

@@ -2019,3 +2019,3 @@ const expr = exprList[i];

case "TSTypeAssertion":
if (!isBinding) {
if (!this.state.maybeInArrowParameters) {
exprList[i] = this.typeCastToParameter(expr);

@@ -2022,0 +2022,0 @@ } else {

@@ -8,5 +8,7 @@ "use strict";

var N = _interopRequireWildcard(require("../types"));
var _identifier = require("../util/identifier");
var _types = require("./types");
var _types2 = require("./types");

@@ -29,2 +31,6 @@ var _context = require("./context");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const VALID_REGEX_FLAGS = new Set(["g", "m", "s", "i", "y", "u"]);

@@ -57,2 +63,3 @@ const forbiddenNumericSeparatorSiblings = {

super();
this.tokens = [];
this.state = new _state.default();

@@ -65,2 +72,8 @@ this.state.init(options);

pushToken(token) {
this.tokens.length = this.state.tokensLength;
this.tokens.push(token);
++this.state.tokensLength;
}
next() {

@@ -71,3 +84,3 @@ if (!this.isLookahead) {

if (this.options.tokens) {
this.state.tokens.push(new Token(this.state));
this.pushToken(new Token(this.state));
}

@@ -122,3 +135,3 @@ }

this.state.strict = strict;
if (!this.match(_types.types.num) && !this.match(_types.types.string)) return;
if (!this.match(_types2.types.num) && !this.match(_types2.types.string)) return;
this.state.pos = this.state.start;

@@ -147,3 +160,3 @@

if (this.state.pos >= this.length) {
this.finishToken(_types.types.eof);
this.finishToken(_types2.types.eof);
return;

@@ -167,3 +180,3 @@ }

};
if (this.options.tokens) this.state.tokens.push(comment);
if (this.options.tokens) this.pushToken(comment);
this.state.comments.push(comment);

@@ -279,3 +292,3 @@ this.addComment(comment);

if (this.hasPlugin("classPrivateProperties") || this.hasPlugin("classPrivateMethods") || this.getPluginOption("pipelineOperator", "proposal") === "smart") {
this.finishOp(_types.types.hash, 1);
this.finishOp(_types2.types.hash, 1);
} else {

@@ -296,6 +309,6 @@ throw this.raise(this.state.pos, "Unexpected character '#'");

this.state.pos += 3;
this.finishToken(_types.types.ellipsis);
this.finishToken(_types2.types.ellipsis);
} else {
++this.state.pos;
this.finishToken(_types.types.dot);
this.finishToken(_types2.types.dot);
}

@@ -314,5 +327,5 @@ }

if (next === 61) {
this.finishOp(_types.types.assign, 2);
this.finishOp(_types2.types.assign, 2);
} else {
this.finishOp(_types.types.slash, 1);
this.finishOp(_types2.types.slash, 1);
}

@@ -333,3 +346,3 @@ }

const value = this.input.slice(start + 2, this.state.pos);
this.finishToken(_types.types.interpreterDirective, value);
this.finishToken(_types2.types.interpreterDirective, value);
return true;

@@ -339,3 +352,3 @@ }

readToken_mult_modulo(code) {
let type = code === 42 ? _types.types.star : _types.types.modulo;
let type = code === 42 ? _types2.types.star : _types2.types.modulo;
let width = 1;

@@ -348,3 +361,3 @@ let next = this.input.charCodeAt(this.state.pos + 1);

next = this.input.charCodeAt(this.state.pos + 2);
type = _types.types.exponent;
type = _types2.types.exponent;
}

@@ -354,3 +367,3 @@

width++;
type = _types.types.assign;
type = _types2.types.assign;
}

@@ -366,5 +379,5 @@

if (this.input.charCodeAt(this.state.pos + 2) === 61) {
this.finishOp(_types.types.assign, 3);
this.finishOp(_types2.types.assign, 3);
} else {
this.finishOp(code === 124 ? _types.types.logicalOR : _types.types.logicalAND, 2);
this.finishOp(code === 124 ? _types2.types.logicalOR : _types2.types.logicalAND, 2);
}

@@ -377,3 +390,3 @@

if (next === 62) {
this.finishOp(_types.types.pipeline, 2);
this.finishOp(_types2.types.pipeline, 2);
return;

@@ -384,7 +397,7 @@ }

if (next === 61) {
this.finishOp(_types.types.assign, 2);
this.finishOp(_types2.types.assign, 2);
return;
}
this.finishOp(code === 124 ? _types.types.bitwiseOR : _types.types.bitwiseAND, 1);
this.finishOp(code === 124 ? _types2.types.bitwiseOR : _types2.types.bitwiseAND, 1);
}

@@ -396,5 +409,5 @@

if (next === 61) {
this.finishOp(_types.types.assign, 2);
this.finishOp(_types2.types.assign, 2);
} else {
this.finishOp(_types.types.bitwiseXOR, 1);
this.finishOp(_types2.types.bitwiseXOR, 1);
}

@@ -414,3 +427,3 @@ }

this.finishOp(_types.types.incDec, 2);
this.finishOp(_types2.types.incDec, 2);
return;

@@ -420,5 +433,5 @@ }

if (next === 61) {
this.finishOp(_types.types.assign, 2);
this.finishOp(_types2.types.assign, 2);
} else {
this.finishOp(_types.types.plusMin, 1);
this.finishOp(_types2.types.plusMin, 1);
}

@@ -435,7 +448,7 @@ }

if (this.input.charCodeAt(this.state.pos + size) === 61) {
this.finishOp(_types.types.assign, size + 1);
this.finishOp(_types2.types.assign, size + 1);
return;
}
this.finishOp(_types.types.bitShift, size);
this.finishOp(_types2.types.bitShift, size);
return;

@@ -455,3 +468,3 @@ }

this.finishOp(_types.types.relational, size);
this.finishOp(_types2.types.relational, size);
}

@@ -463,3 +476,3 @@

if (next === 61) {
this.finishOp(_types.types.equality, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
this.finishOp(_types2.types.equality, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
return;

@@ -470,7 +483,7 @@ }

this.state.pos += 2;
this.finishToken(_types.types.arrow);
this.finishToken(_types2.types.arrow);
return;
}
this.finishOp(code === 61 ? _types.types.eq : _types.types.bang, 1);
this.finishOp(code === 61 ? _types2.types.eq : _types2.types.bang, 1);
}

@@ -484,12 +497,12 @@

if (next2 === 61) {
this.finishOp(_types.types.assign, 3);
this.finishOp(_types2.types.assign, 3);
} else {
this.finishOp(_types.types.nullishCoalescing, 2);
this.finishOp(_types2.types.nullishCoalescing, 2);
}
} else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
this.state.pos += 2;
this.finishToken(_types.types.questionDot);
this.finishToken(_types2.types.questionDot);
} else {
++this.state.pos;
this.finishToken(_types.types.question);
this.finishToken(_types2.types.question);
}

@@ -506,3 +519,3 @@ }

++this.state.pos;
this.finishToken(_types.types.parenL);
this.finishToken(_types2.types.parenL);
return;

@@ -512,3 +525,3 @@

++this.state.pos;
this.finishToken(_types.types.parenR);
this.finishToken(_types2.types.parenR);
return;

@@ -518,3 +531,3 @@

++this.state.pos;
this.finishToken(_types.types.semi);
this.finishToken(_types2.types.semi);
return;

@@ -524,3 +537,3 @@

++this.state.pos;
this.finishToken(_types.types.comma);
this.finishToken(_types2.types.comma);
return;

@@ -530,3 +543,3 @@

++this.state.pos;
this.finishToken(_types.types.bracketL);
this.finishToken(_types2.types.bracketL);
return;

@@ -536,3 +549,3 @@

++this.state.pos;
this.finishToken(_types.types.bracketR);
this.finishToken(_types2.types.bracketR);
return;

@@ -542,3 +555,3 @@

++this.state.pos;
this.finishToken(_types.types.braceL);
this.finishToken(_types2.types.braceL);
return;

@@ -548,3 +561,3 @@

++this.state.pos;
this.finishToken(_types.types.braceR);
this.finishToken(_types2.types.braceR);
return;

@@ -554,6 +567,6 @@

if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
this.finishOp(_types.types.doubleColon, 2);
this.finishOp(_types2.types.doubleColon, 2);
} else {
++this.state.pos;
this.finishToken(_types.types.colon);
this.finishToken(_types2.types.colon);
}

@@ -569,3 +582,3 @@

++this.state.pos;
this.finishToken(_types.types.backQuote);
this.finishToken(_types2.types.backQuote);
return;

@@ -644,3 +657,3 @@

case 126:
this.finishOp(_types.types.tilde, 1);
this.finishOp(_types2.types.tilde, 1);
return;

@@ -650,3 +663,3 @@

++this.state.pos;
this.finishToken(_types.types.at);
this.finishToken(_types2.types.at);
return;

@@ -733,3 +746,3 @@

this.finishToken(_types.types.regexp, {
this.finishToken(_types2.types.regexp, {
pattern: content,

@@ -827,7 +840,7 @@ flags: mods

const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
this.finishToken(_types.types.bigint, str);
this.finishToken(_types2.types.bigint, str);
return;
}
this.finishToken(_types.types.num, val);
this.finishToken(_types2.types.num, val);
}

@@ -905,3 +918,3 @@

if (isBigInt) {
this.finishToken(_types.types.bigint, str);
this.finishToken(_types2.types.bigint, str);
return;

@@ -911,3 +924,3 @@ }

const val = octal ? parseInt(str, 8) : parseFloat(str);
this.finishToken(_types.types.num, val);
this.finishToken(_types2.types.num, val);
}

@@ -966,3 +979,3 @@

out += this.input.slice(chunkStart, this.state.pos++);
this.finishToken(_types.types.string, out);
this.finishToken(_types2.types.string, out);
}

@@ -983,10 +996,10 @@

if (ch === 96 || ch === 36 && this.input.charCodeAt(this.state.pos + 1) === 123) {
if (this.state.pos === this.state.start && this.match(_types.types.template)) {
if (this.state.pos === this.state.start && this.match(_types2.types.template)) {
if (ch === 36) {
this.state.pos += 2;
this.finishToken(_types.types.dollarBraceL);
this.finishToken(_types2.types.dollarBraceL);
return;
} else {
++this.state.pos;
this.finishToken(_types.types.backQuote);
this.finishToken(_types2.types.backQuote);
return;

@@ -997,3 +1010,3 @@ }

out += this.input.slice(chunkStart, this.state.pos);
this.finishToken(_types.types.template, containsInvalid ? null : out);
this.finishToken(_types2.types.template, containsInvalid ? null : out);
return;

@@ -1194,3 +1207,3 @@ }

const type = _types.keywords.get(word) || _types.types.name;
const type = _types2.keywords.get(word) || _types2.types.name;

@@ -1219,23 +1232,23 @@ if (this.state.isIterator && (!this.isIterator(word) || !this.state.inType)) {

if (prevType === _types.types.colon && (parent === _context.types.braceStatement || parent === _context.types.braceExpression)) {
if (prevType === _types2.types.colon && (parent === _context.types.braceStatement || parent === _context.types.braceExpression)) {
return !parent.isExpr;
}
if (prevType === _types.types._return || prevType === _types.types.name && this.state.exprAllowed) {
if (prevType === _types2.types._return || prevType === _types2.types.name && this.state.exprAllowed) {
return _whitespace.lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
}
if (prevType === _types.types._else || prevType === _types.types.semi || prevType === _types.types.eof || prevType === _types.types.parenR || prevType === _types.types.arrow) {
if (prevType === _types2.types._else || prevType === _types2.types.semi || prevType === _types2.types.eof || prevType === _types2.types.parenR || prevType === _types2.types.arrow) {
return true;
}
if (prevType === _types.types.braceL) {
if (prevType === _types2.types.braceL) {
return parent === _context.types.braceStatement;
}
if (prevType === _types.types._var || prevType === _types.types._const || prevType === _types.types.name) {
if (prevType === _types2.types._var || prevType === _types2.types._const || prevType === _types2.types.name) {
return false;
}
if (prevType === _types.types.relational) {
if (prevType === _types2.types.relational) {
return true;

@@ -1251,3 +1264,3 @@ }

if (type.keyword && (prevType === _types.types.dot || prevType === _types.types.questionDot)) {
if (type.keyword && (prevType === _types2.types.dot || prevType === _types2.types.questionDot)) {
this.state.exprAllowed = false;

@@ -1254,0 +1267,0 @@ } else if (update = type.updateContext) {

@@ -44,3 +44,2 @@ "use strict";

this.awaitPos = -1;
this.tokens = [];
this.comments = [];

@@ -67,2 +66,3 @@ this.trailingComments = [];

this.exportedIdentifiers = [];
this.tokensLength = 0;
}

@@ -69,0 +69,0 @@

@@ -147,13 +147,13 @@ "use strict";

nullishCoalescing: createBinop("??", 1),
logicalOR: createBinop("||", 2),
logicalAND: createBinop("&&", 3),
bitwiseOR: createBinop("|", 4),
bitwiseXOR: createBinop("^", 5),
bitwiseAND: createBinop("&", 6),
equality: createBinop("==/!=/===/!==", 7),
relational: createBinop("</>/<=/>=", 8),
bitShift: createBinop("<</>>/>>>", 9),
logicalOR: createBinop("||", 1),
logicalAND: createBinop("&&", 2),
bitwiseOR: createBinop("|", 3),
bitwiseXOR: createBinop("^", 4),
bitwiseAND: createBinop("&", 5),
equality: createBinop("==/!=/===/!==", 6),
relational: createBinop("</>/<=/>=", 7),
bitShift: createBinop("<</>>/>>>", 8),
plusMin: new TokenType("+/-", {
beforeExpr,
binop: 10,
binop: 9,
prefix,

@@ -164,10 +164,10 @@ startsExpr

beforeExpr,
binop: 11,
binop: 10,
startsExpr
}),
star: createBinop("*", 11),
slash: createBinop("/", 11),
star: createBinop("*", 10),
slash: createBinop("/", 10),
exponent: new TokenType("**", {
beforeExpr,
binop: 12,
binop: 11,
rightAssociative: true

@@ -247,7 +247,7 @@ }),

beforeExpr,
binop: 8
binop: 7
}),
_instanceof: createKeyword("instanceof", {
beforeExpr,
binop: 8
binop: 7
}),

@@ -254,0 +254,0 @@ _typeof: createKeyword("typeof", {

{
"name": "@babel/parser",
"version": "7.8.3",
"version": "7.8.4",
"description": "A JavaScript parser",

@@ -39,3 +39,3 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>",

},
"gitHead": "a7620bd266ae1345975767bbc7abf09034437017"
"gitHead": "5c2e6bc07fed3d28801d93168622c99ae622653a"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc