Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function transformFnBody(node) {
var addressParam = node.params[2];
var bindAddress = build.variableDeclaration('var', [
build.variableDeclarator(
build.identifier(localVarName),
addressParam)]);
// Use member expression so that this isn't cps'd. Writing as an
// assignment statement doesn't work as it is wrapped in a thunk and
// returned early from the function.
var saveAddress = build.expressionStatement(
build.callExpression(
build.memberExpression(
build.identifier(saveAddressFn[0]),
build.identifier(saveAddressFn[1])
), [
build.identifier(globalVarName),
addressParam]));
var expr = build.functionExpression(
node.id,
node.params,
build.blockStatement([bindAddress, saveAddress].concat(node.body.body))
);
expr.loc = node.loc;
return expr;
}
function insertSuperCall(path) {
const classMethods = get(path, 'value.body.body') || [];
const constructorIndex = findIndex(classMethods, {kind: 'constructor'});
if (constructorIndex > -1) {
const superCalls = jsc(classMethods[constructorIndex])
.find(jsc.CallExpression, {callee: {name: 'super'}})
.nodes();
if (superCalls.length < 1) {
classMethods[constructorIndex]
.value.body.body
.unshift(
b.expressionStatement(b.callExpression(b.identifier('super'), [])));
}
}
}
function buildExportedFunc(opts, ast, name) {
var func = (opts.es6 ? b.functionDeclaration : b.functionExpression)(
b.identifier(name),
[b.identifier('type')],
b.blockStatement(ast)
);
if (opts.es6) {
return [b.exportDeclaration(false, func)];
}
return [
b.expressionStatement(b.assignmentExpression(
'=',
b.memberExpression(
b.identifier('exports'),
b.identifier(name),
false
),
func
))
];
}
module.exports = function buildType(type, opts) {
var imports = buildTypeImports(type, opts);
var typeAst = type.ast;
var typeExport = [buildExports(b.identifier(type.varName), opts)];
var register = [b.expressionStatement(
b.callExpression(
b.identifier('registerType'),
[b.identifier(type.varName)]
)
)];
return b.program([]
.concat(imports)
.concat(typeAst)
.concat(register)
.concat(typeExport)
);
};
.map(specifier =>
b.expressionStatement(
b.assignmentExpression(
'=',
moduleExportsExpression(specifier.exported.name),
b.memberExpression(
b.memberExpression(
tempIdentifier,
b.identifier('exports'),
false
),
b.literal(specifier.local.name),
true
)
)
)
);
function wrapExternalModule(modulePath: string, context: PaeckchenContext): Promise {
const external = context.config.externals[modulePath] === false
? b.objectExpression([])
: b.identifier(context.config.externals[modulePath] as string);
return Promise.resolve(b.program([
b.expressionStatement(
b.assignmentExpression(
'=',
b.memberExpression(
b.identifier('module'),
b.identifier('exports'),
false
),
external
)
)
]));
}
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;
}
function buildFunction(params, body, id) {
return build.functionExpression(id || null, params,
build.blockStatement([build.expressionStatement(body)]));
}
return function(node) {
if (types.Program.check(node) &&
node.body.length === 1 &&
types.ExpressionStatement.check(node.body[0])) {
return build.program([
build.expressionStatement(f(node.body[0].expression))
]);
}
else {
return failSafe('inProgram', fail);
}
};
}
return mapThrowStatement(node, meta);
} else if (type === 'Comment') {
return b.emptyStatement();
} else if (type === 'For') {
return mapForStatement(node, meta);
} else if (type === 'Class') {
return mapClassDeclaration(node, meta);
} else if (type === 'Switch') {
return addBreakStatementsToSwitch(mapSwitchStatement(node, meta));
} else if (type === 'If') {
return mapConditionalStatement(node, meta);
} else if (type === 'Try') {
return mapTryCatchBlock(node, meta);
}
return b.expressionStatement(mapExpression(node, meta));
}