Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function evalExpression(expr: k.ExpressionKind, scope: object, context: vm.Context) {
return vm.compileFunction(
recast.print(b.withStatement(b.identifier('scope'), b.blockStatement([b.returnStatement(expr)]))).code,
['scope'],
{
parsingContext: context,
},
)(scope);
}
clause(Syntax.IfStatement, function(test, consequent, alternate) {
if (alternate === null) {
alternate = build.emptyStatement();
}
if (hasReturn(consequent) || hasReturn(alternate)) {
return [build.ifStatement(
test,
build.blockStatement(linearizeSequence([consequent], 0, ks)),
build.blockStatement(linearizeSequence([alternate], 0, ks)))];
}
else {
return [build.ifStatement(test, consequent, alternate)].concat(ks);
}
}),
clause(Syntax.ReturnStatement, function(argument) {
function mapSwitchExpression(node: CNode, meta: Object) {
return b.callExpression(
b.arrowFunctionExpression(
[],
b.blockStatement([addReturnStatementsToSwitch(
mapSwitchStatement(node, meta)
)])
),
[]
);
}
function mapElseBlock(node: CNode, meta: Object) {
const type = node.constructor.name;
if (type === 'If') {
const conditional = mapIfStatement(node, meta);
if (n.IfStatement.check(conditional)) {
return conditional;
}
return b.blockStatement([conditional]);
} else if (type === 'Block') {
return mapBlockStatement(node, meta);
}
return mapBlockStatement({expressions: [node]}, meta);
}
function conditionalStatementAsExpression(node: CNode, meta: Object) {
const conditionalStatement = mapConditionalStatement(node, meta);
if (conditionalStatement.type === 'IfStatement') {
return b.callExpression(
b.arrowFunctionExpression(
[],
b.blockStatement(
[addReturnStatementToIfBlocks(conditionalStatement)]
)
),
[]
);
}
return conditionalStatement.expression;
}
return node;
});
//
var argumentsId = util.aliasArguments(generateUid, node);
if (argumentsId) {
nodes.push(b.variableDeclaration("var", [
b.variableDeclarator(argumentsId, b.identifier("arguments"))
]));
}
//
var block = b.blockStatement([]);
block.body = node;
var func = b.functionExpression(null, [], block, false);
//
var templateName = "function-call";
if (traverse.hasType(node, "ThisExpression")) templateName += "-this";
if (traverse.hasType(node, "ReturnStatement", traverse.FUNCTION_TYPES)) templateName += "-return";
nodes.push(util.template(templateName, {
FUNCTION: func
}, true));
return {
node: nodes,
identifier,
b.identifier('exports'),
false
)
]
),
b.identifier('forEach'),
false
),
[
b.functionExpression(
null,
[
b.identifier('key')
],
b.blockStatement([
b.expressionStatement(
b.assignmentExpression(
'=',
b.memberExpression(
b.memberExpression(
b.identifier('module'),
b.identifier('exports'),
false
),
b.identifier('key'),
true
),
b.memberExpression(
b.memberExpression(
identifier,
b.identifier('exports'),
clause(Syntax.BlockStatement, function(body) {
return build.blockStatement(returnify(body));
}),
clause(Syntax.EmptyStatement, function() {
clause(Syntax.IfStatement, function(test, consequent, alternate) {
return build.ifStatement(
test,
build.blockStatement(returnify(consequent.body)),
alternate === null ? null : build.blockStatement(returnify(alternate.body)));
}),
clause(Syntax.ReturnStatement, function(argument) {
function transformContinuation(node) {
var saveAddress = build.expressionStatement(
build.callExpression(
build.memberExpression(
build.identifier(saveAddressFn[0]),
build.identifier(saveAddressFn[1])
), [
build.identifier(globalVarName),
build.identifier(localVarName)]));
var expr = build.functionExpression(
node.id,
node.params,
build.blockStatement([saveAddress].concat(node.body.body))
);
expr.loc = node.loc;
return expr;
}