Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function safeRename(path, asset, from, to) {
if (from === to) {
return;
}
// If the binding that we're renaming is constant, it's safe to rename it.
// Otherwise, create a new binding that references the original.
let binding = path.scope.getBinding(from);
if (binding && binding.constant) {
rename(path.scope, from, to);
} else {
let [decl] = path.insertAfter(
t.variableDeclaration('var', [
t.variableDeclarator(t.identifier(to), t.identifier(from)),
]),
);
path.scope.getBinding(from).reference(decl.get('declarations.0.init'));
path.scope.registerDeclaration(decl);
}
}
additionalFunctionEffects.transforms.push((body: Array) => {
// as we've converted a functional component to a complex one, we are going to have issues with
// "props" and "context" references, as they're now going to be "this.props" and "this.context".
// we simply need a to add to vars to beginning of the body to get around this
// if they're not used, any DCE tool post-Prepack (GCC or Uglify) will remove them
body.unshift(
t.variableDeclaration("var", [
t.variableDeclarator(t.identifier("props"), t.memberExpression(t.thisExpression(), t.identifier("props"))),
t.variableDeclarator(t.identifier("context"), t.memberExpression(t.thisExpression(), t.identifier("context"))),
])
);
});
}
convert(context, typeParameter.get('default'))
);
}
else if (typeParameter.has('bound')) {
args.push(
convert(context, typeParameter.get('bound'))
);
}
else if (typeParameter.has('default')) {
args.push(
t.identifier('undefined'), // make sure we don't confuse bound with default
convert(context, typeParameter.get('default'))
);
}
definitions.push(t.variableDeclaration('const', [
t.variableDeclarator(
t.identifier(name),
context.call('typeParameter', ...args)
)
]));
}
for (let param of params) {
const argumentIndex = +param.key;
let assignmentRight;
if (param.isAssignmentPattern()) {
assignmentRight = param.get('right');
param = param.get('left');
}
if (!param.has('typeAnnotation')) {
export const makePureComponent = (params: { name: string; jsxTagTree: t.JSXElement }) => {
const { name, jsxTagTree } = params
const returnStatement = t.returnStatement(jsxTagTree)
const arrowFunction = t.arrowFunctionExpression(
[t.identifier('props')],
t.blockStatement([returnStatement] || [])
)
const declarator = t.variableDeclarator(t.identifier(name), arrowFunction)
const component = t.variableDeclaration('const', [declarator])
return component
}
convert(context, typeParameter)
);
}))
)
));
}
}
if (hasTypeParameters) {
const staticMethods = body.get('body').filter(
item => item.isClassMethod() && item.node.static
);
for (const method of staticMethods) {
method.get('body').unshiftContainer('body', t.variableDeclaration('const', [
t.variableDeclarator(
typeParametersUid,
t.objectExpression(typeParameters.map(typeParameter => {
return t.objectProperty(
t.identifier(typeParameter.node.name),
convert(context, typeParameter)
);
}))
)
]));
}
}
}},
Class: { exit (path: NodePath) {
if (context.shouldSuppressPath(path)) {
path.skip();
return;
}
else if (!shouldCheck) {
return;
}
const body = path.get('body');
const typeParametersSymbolUid = context.getClassData(path, 'typeParametersSymbolUid');
if (typeParametersSymbolUid) {
path.getStatementParent().insertBefore(
t.variableDeclaration('const', [
t.VariableDeclarator(
t.identifier(typeParametersSymbolUid),
t.callExpression(
t.identifier('Symbol'),
[t.stringLiteral(
`${context.getClassData(path, 'currentClassName')}TypeParameters`
)]
)
)
])
);
const staticProp = t.classProperty(
context.symbol('TypeParameters'),
t.identifier(typeParametersSymbolUid),
null,
handleExistingMerge(existingDefinition, newDefinition, allHistoryDefinitions) {
const historyDefinitions = allHistoryDefinitions.map(definitions => (
definitions.find(
d => d.get('id').node.type === 'Identifier' &&
existingDefinition.get('id').node.type === 'Identifier' &&
existingDefinition.get('id').node.name === d.get('id').node.name
)
)).filter(d => !!d);
const lastHistoryDefinition = historyDefinitions.length && historyDefinitions[historyDefinitions.length - 1];
const newVariableDeclaration = t.variableDeclaration('const', [newDefinition.node]);
if (
!this.compareDefinitions(existingDefinition, lastHistoryDefinition) &&
!this.compareDefinitions(existingDefinition, newDefinition)
) {
t.addComment(newVariableDeclaration, 'leading', `\n${this.generateCode(existingDefinition, false)}`);
}
if (existingDefinition.node.type === 'VariableDeclarator') {
existingDefinition = existingDefinition.parentPath;
}
existingDefinition.replaceWith(newVariableDeclaration);
}
function requireGenerator(varName, moduleName) {
return types.variableDeclaration('var', [
types.variableDeclarator(
types.identifier(varName),
types.callExpression(types.identifier('require'), [
types.stringLiteral(moduleName),
]),
),
]);
}
const defaultBabelConfig = {
const insertPragma = (body: t.BaseNode[], pragma: string, start: number) => {
body.splice(
start,
0,
t.variableDeclaration("const", [
t.variableDeclarator(
t.identifier(pragma),
t.memberExpression(t.identifier("fidan"), t.identifier("createElement"))
)
])
);
};
getIdentifier(asset, 'init'),
[],
t.blockStatement([
t.ifStatement(t.identifier(executed), t.returnStatement()),
t.expressionStatement(
t.assignmentExpression(
'=',
t.identifier(executed),
t.booleanLiteral(true)
)
),
...body
])
);
return [t.variableDeclaration('var', decls), ...fns, init];
}