Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (options.pre) {
options.pre(state, file);
}
// no attributes are allowed with <> syntax
args.push(t.nullLiteral(), ...path.node.children);
if (options.post) {
options.post(state, file);
}
file.set("@babel/plugin-react-jsx/usedFragment", true);
const call =
state.call || t.callExpression(state.createElementCallee, args);
if (state.pure) annotateAsPure(call);
return call;
}
let templateObject = this.templates.get(name);
if (templateObject) {
templateObject = t.clone(templateObject);
} else {
const programPath = path.find(p => p.isProgram());
templateObject = programPath.scope.generateUidIdentifier(
"templateObject",
);
this.templates.set(name, templateObject);
const helperId = this.addHelper(helperName);
const init = t.callExpression(helperId, [
t.arrayExpression(strings),
t.arrayExpression(raws),
]);
annotateAsPure(init);
init._compact = true;
programPath.scope.push({
id: templateObject,
init,
// This ensures that we don't fail if not using function expression helpers
_blockHoist: 1.9,
});
}
path.replaceWith(
t.callExpression(node.tag, [templateObject, ...quasi.expressions]),
);
},
const isIIFE = checkIsIIFE(path);
path.node.async = false;
path.node.generator = true;
wrapFunction(path, t.cloneNode(helpers.wrapAsync));
const isProperty =
path.isObjectMethod() ||
path.isClassMethod() ||
path.parentPath.isObjectProperty() ||
path.parentPath.isClassProperty();
if (!isProperty && !isIIFE && path.isExpression()) {
annotateAsPure(path);
}
function checkIsIIFE(path: NodePath) {
if (path.parentPath.isCallExpression({ callee: path.node })) {
return true;
}
// try to catch calls to Function#bind, as emitted by arrowFunctionToExpression in spec mode
// this may also catch .bind(this) written by users, but does it matter? 🤔
const { parentPath } = path;
if (
parentPath.isMemberExpression() &&
t.isIdentifier(parentPath.node.property, { name: "bind" })
) {
const { parentPath: bindCall } = parentPath;
namePath = namePath.get("property");
}
const elementName = namePath.node.name;
state.mutablePropsAllowed =
allowMutablePropsOnTags.indexOf(elementName) > -1;
}
// Traverse all props passed to this element for immutability.
path.traverse(immutabilityVisitor, state);
if (state.isImmutable) {
const hoisted = path.hoist();
if (hoisted) {
annotateAsPure(hoisted);
}
}
},
},
references[referenceKey].reverse().forEach(reference => {
const path = reference.parentPath
reference.replaceWith(t.cloneDeep(runtimeNode))
// add pure function annotation
// so that consumers can remove console statements from prod bundles
if (process.env.NODE_ENV === 'production') {
path.traverse({
Function: annotateAsPure
})
annotateAsPure(reference)
annotateAsPure(path)
}
})
})
references[referenceKey].reverse().forEach(reference => {
const path = reference.parentPath
reference.replaceWith(t.cloneDeep(runtimeNode))
// add pure function annotation
// so that consumers can remove console statements from prod bundles
if (process.env.NODE_ENV === 'production') {
path.traverse({
Function: annotateAsPure
})
annotateAsPure(reference)
annotateAsPure(path)
}
})
})
path.scope.buildUndefinedNode(),
t.booleanLiteral(path.node.children.length > 1),
);
}
if (options.post) {
options.post(state, file);
}
const call =
state.call ||
t.callExpression(
path.node.children.length > 1 ? state.jsxStaticCallee : state.jsxCallee,
args,
);
if (state.pure) annotateAsPure(call);
return call;
}
extracted.__source ?? path.scope.buildUndefinedNode(),
extracted.__self ?? t.thisExpression(),
);
}
if (options.post) {
options.post(state, file);
}
const call =
state.call ||
t.callExpression(
path.node.children.length > 1 ? state.jsxStaticCallee : state.jsxCallee,
args,
);
if (state.pure) annotateAsPure(call);
return call;
}
}
const attribs = buildCreateElementOpeningElementAttributes(
path,
openingPath.node.attributes,
);
args.push(attribs, ...path.node.children);
if (options.post) {
options.post(state, file);
}
const call =
state.call || t.callExpression(state.createElementCallee, args);
if (state.pure) annotateAsPure(call);
return call;
}
if (node[VISITED]) return;
const inferred = nameFunction(path);
if (inferred && inferred !== node) {
path.replaceWith(inferred);
return;
}
node[VISITED] = true;
path.replaceWith(
transformClass(path, state.file, builtinClasses, loose),
);
if (path.isCallExpression()) {
annotateAsPure(path);
if (path.get("callee").isArrowFunctionExpression()) {
path.get("callee").arrowFunctionToExpression();
}
}
},
},