Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
reactElement: ObjectValue,
id: BabelNodeExpression,
reactElementAst: BabelNodeExpression,
hoistedCreateElementIdentifier: BabelNodeIdentifier,
originalCreateElementIdentifier: BabelNodeIdentifier
) {
// if the currentHoistedReactElements is not defined, we create it an emit the function call
// this should only occur once per additional function
if (this._lazilyHoistedNodes === undefined) {
let funcId = t.identifier(this.residualHeapSerializer.functionNameGenerator.generate());
this._lazilyHoistedNodes = {
id: funcId,
createElementIdentifier: hoistedCreateElementIdentifier,
nodes: [],
};
let statement = t.expressionStatement(
t.logicalExpression(
"&&",
t.binaryExpression("===", id, t.unaryExpression("void", t.numericLiteral(0), true)),
// pass the createElementIdentifier if it's not null
t.callExpression(funcId, originalCreateElementIdentifier ? [originalCreateElementIdentifier] : [])
)
);
let optimizedFunction = this.residualHeapSerializer.isReferencedOnlyByOptimizedFunction(reactElement);
this.residualHeapSerializer.getPrelude(optimizedFunction).push(statement);
}
// we then push the reactElement and its id into our list of elements to process after
// the current additional function has serialzied
invariant(this._lazilyHoistedNodes !== undefined);
invariant(Array.isArray(this._lazilyHoistedNodes.nodes));
this._lazilyHoistedNodes.nodes.push({ id, astNode: reactElementAst });
}
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
// can't be accessed
return;
}
// ignore block hoisted nodes as these can be left in
if (state.formatter._canHoist(node)) return;
let nodes = [];
for (let i = 0; i < node.declarations.length; i++) {
let declar = node.declarations[i];
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
if (declar.init) {
// no initializer so we can just hoist it as-is
let assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
nodes.push(assign);
}
}
// for (let i in test)
if (t.isFor(parent) && parent.left === node) {
return node.declarations[0].id;
}
return nodes;
}
};
specHandleAssignmentExpression(ref, path, node) {
if (node.operator === "=") {
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
return this.setSuperProperty(node.left.property, node.right, node.left.computed);
} else {
// super.age += 2; -> let _ref = super.age; super.age = _ref + 2;
ref = ref || path.scope.generateUidIdentifier("ref");
return [
t.variableDeclaration("var", [
t.variableDeclarator(ref, node.left)
]),
t.expressionStatement(
t.assignmentExpression("=", node.left, t.binaryExpression(node.operator[0], ref, node.right))
)
];
}
}
exit: function(path) {
let expr = varDeclToExpr(path.node, false);
if (expr === null) {
path.remove();
} else {
// We don't need to traverse this expression any further because
// there can't be any new declarations inside an expression.
path.replaceWith(t.expressionStatement(expr));
}
// Since the original node has been either removed or replaced,
// avoid traversing it any further.
path.skip();
}
},
FunctionDeclaration: function(path) {
let node = path.node;
vars[node.id.name] = node.id;
let assignment = t.expressionStatement(
t.assignmentExpression(
"=",
node.id,
t.functionExpression(
node.id,
node.params,
node.body,
node.generator,
node.expression
)
)
);
if (path.parentPath.isBlockStatement()) {
// Insert the assignment form before the first statement in the
// enclosing block.
exit(path) {
const { body } = path.node;
const bodyPath = path.get('body.0');
const newBody = t.expressionStatement(foldSequence(bodyPath, body));
newBody.cps = true;
path.node.body = [newBody];
},
},
const isSelfClosing = el.selfClosing || !el.children.length;
let openElementCall = elementOpen(
state,
isSelfClosing ? 'elementVoid' : 'elementOpen',
el.name,
key,
staticId,
attributes
);
if (isSelfClosing && ref) {
openElementCall = t.callExpression(
t.identifier(state.addImportFrom('melody-idom', 'ref')),
[ref, openElementCall]
);
}
replacements.push(t.expressionStatement(openElementCall));
}
_build(mappings) {
const outputContent = t.expressionStatement(
t.assignmentExpression(
"=",
t.memberExpression(t.identifier("module"), t.identifier("exports")),
t.objectExpression(
Object.keys(mappings).map((key) => {
const valueNode = mappings[key];
const keyNode = t.stringLiteral(key);
return t.objectProperty(keyNode, valueNode);
})
)
)
);
const comment =
"\n" +
function setGlobal(global: t.Expression, name: t.Identifier, expr: t.Expression): t.Statement {
return t.expressionStatement(
t.assignmentExpression('=',
t.memberExpression(global, name, false),
expr));
}
function fakeModule(path: NodePath) {
const isStop = t.identifier("$isStop");
const onStop = t.identifier("$onStop");
const onDone = t.identifier("$onDone");
const opts = t.identifier("$opts");
path.node.body.push(t.returnStatement(t.callExpression(onDone, [])));
path.node.body = [t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(t.identifier('module'), t.identifier('exports')),
t.functionExpression(
void 0,
[isStop, onStop, onDone, opts],
t.blockStatement(path.node.body))))];
}
const visitor: Visitor = {