Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_compileExpressions(ast) {
const _state = {
stack: [],
output: []
};
walk.full(
ast,
(node, state) => {
/* eslint-disable no-case-declarations */
switch (node.type) {
case "Identifier":
state.stack.push([]);
break;
case "Literal":
const items =
isString(node.value) || isNumber(node.value) ? [node.value] : [];
state.stack.push(items);
break;
case "MemberExpression":
_popN(state.stack, 1);
state.stack.push([]);
break;
export function walkFull(node: Ast.Node, callback: AstVisitorCallback, baseVisitor = base, state?: T, override?: string): void {
acornWalk.full(node, callback, baseVisitor, state, override);
}
function full (node, callback, baseVisitor, state, override) {
return walk.full(node, callback, baseVisitor || base, state, override)
}
function full (node, callback, baseVisitor, state, override) {
return walk.full(node, callback, baseVisitor || base, state, override)
}
function full (node, callback, baseVisitor, state, override) {
return walk.full(node, callback, baseVisitor || base, state, override)
}
_compileExpressions(ast) {
const _state = {
stack: [],
output: [],
};
walk.full(ast, (node, state) => {
switch (node.type) {
case 'Identifier':
state.stack.push([]);
break;
case 'Literal':
const items = isString(node.value) || isNumber(node.value) ? [node.value] : [];
state.stack.push(items);
break;
case 'MemberExpression':
_popN(state.stack, 1);
state.stack.push([]);
break;
case 'ConditionalExpression':
let [, consequent, alternate] = _popN(state.stack, node.alternate ? 3 : 2);
state.stack.push([...consequent, ...alternate]);
break;
function extractExpressions(code) {
const expressions = []
let expressionStart = 0
let expressionEnd = 0
let trackingExpression = false
walk.full(acorn.parse(code), (node, state, type) => {
if (
(type === 'MemberExpression' && node.property.type === 'Identifier') ||
(type === 'ExpressionStatement' && node.expression.type === 'Identifier')
) {
trackingExpression = true
expressionStart = node.start
expressionEnd = node.end
}
if ((trackingExpression && expressionStart !== node.start) || type === 'Program') {
expressions.push(code.slice(expressionStart, expressionEnd))
trackingExpression = false
}
})
return expressions
}