Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let ast;
const comments = [];
for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
if(!ast) {
try {
comments.length = 0;
POSSIBLE_AST_OPTIONS[i].onComment = comments;
ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
} catch(e) {
// ignore the error
}
}
}
if(!ast) {
// for the error
ast = acorn.parse(source, {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
},
onComment: comments
});
}
if(!ast || typeof ast !== "object")
throw new Error("Source couldn't be parsed");
const oldScope = this.scope;
const oldState = this.state;
const oldComments = this.comments;
this.scope = {
let ast;
const comments = [];
for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
if(!ast) {
try {
comments.length = 0;
POSSIBLE_AST_OPTIONS[i].onComment = comments;
ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
} catch(e) {
// ignore the error
}
}
}
if(!ast) {
// for the error
ast = acorn.parse(source, {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
},
onComment: comments
});
}
if(!ast || typeof ast !== "object")
throw new Error("Source couldn't be parsed");
const oldScope = this.scope;
const oldState = this.state;
const oldComments = this.comments;
this.scope = {
let ast;
const comments = [];
for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
if(!ast) {
try {
comments.length = 0;
POSSIBLE_AST_OPTIONS[i].onComment = comments;
ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
} catch(e) {
// ignore the error
}
}
}
if(!ast) {
// for the error
ast = acorn.parse(source, {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
},
onComment: comments
});
}
if(!ast || typeof ast !== "object")
throw new Error("Source couldn't be parsed");
const oldScope = this.scope;
const oldState = this.state;
const oldComments = this.comments;
this.scope = {
parse(source, initialState) {
let ast;
const comments = [];
for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
if(!ast) {
try {
comments.length = 0;
POSSIBLE_AST_OPTIONS[i].onComment = comments;
ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
} catch(e) {
// ignore the error
}
}
}
if(!ast) {
// for the error
ast = acorn.parse(source, {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
},
onComment: comments
evaluate(source) {
const ast = acorn.parse("(" + source + ")", {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
}
});
if(!ast || typeof ast !== "object" || ast.type !== "Program")
throw new Error("evaluate: Source couldn't be parsed");
if(ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
throw new Error("evaluate: Source is not a expression");
return this.evaluateExpression(ast.body[0].expression);
}
let error;
let threw = false;
try {
ast = acorn.parse(code, parserOptions);
} catch (e) {
error = e;
threw = true;
}
if (threw && type === "auto") {
parserOptions.sourceType = "script";
if (Array.isArray(parserOptions.onComment)) {
parserOptions.onComment.length = 0;
}
try {
ast = acorn.parse(code, parserOptions);
threw = false;
} catch (e) {
threw = true;
}
}
if (threw) {
throw error;
}
return ast;
}
}
Parser.prototype.evaluate = function evaluate(source) {
var ast = acorn.parse("(" + source + ")", {
ranges: true,
locations: true,
ecmaVersion: 2017,
sourceType: "module",
plugins: {
dynamicImport: true
}
});
if(!ast || typeof ast !== "object" || ast.type !== "Program")
throw new Error("evaluate: Source couldn't be parsed");
if(ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
throw new Error("evaluate: Source is not a expression");
return this.evaluateExpression(ast.body[0].expression);
};
evaluate(source) {
const ast = acorn.parse("(" + source + ")", {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
}
});
if(!ast || typeof ast !== "object" || ast.type !== "Program")
throw new Error("evaluate: Source couldn't be parsed");
if(ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
throw new Error("evaluate: Source is not a expression");
return this.evaluateExpression(ast.body[0].expression);
}
evaluate(source) {
const ast = acorn.parse("(" + source + ")", {
ranges: true,
locations: true,
ecmaVersion: ECMA_VERSION,
sourceType: "module",
plugins: {
dynamicImport: true
}
});
if(!ast || typeof ast !== "object" || ast.type !== "Program")
throw new Error("evaluate: Source couldn't be parsed");
if(ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
throw new Error("evaluate: Source is not a expression");
return this.evaluateExpression(ast.body[0].expression);
}
Parser.prototype.evaluate = function evaluate(source) {
var ast = acorn.parse("(" + source + ")", {
ranges: true,
locations: true,
ecmaVersion: 2017,
sourceType: "module",
plugins: {
dynamicImport: true
}
});
if(!ast || typeof ast !== "object" || ast.type !== "Program")
throw new Error("evaluate: Source couldn't be parsed");
if(ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
throw new Error("evaluate: Source is not a expression");
return this.evaluateExpression(ast.body[0].expression);
};