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);
}
}
Class (path: NodePath) {
let className = 'AnonymousClass';
if (path.isClassDeclaration() && path.has('id')) {
const {name} = path.node.id;
// have we seen a reference to this class already?
// if so we should replace it with a `var className = class className {}`
// to avoid temporal dead zone issues
if (!path.parentPath.isExportDefaultDeclaration() && path.scope.getData(`seenReference:${name}`)) {
path.replaceWith(t.variableDeclaration('var', [
t.variableDeclarator(
t.identifier(name),
t.classExpression(
path.node.id,
path.node.superClass,
path.node.body,
path.node.decorators || []
)
)
]));
return;
}
className = name;
context.defineValue(name, path.parentPath);
}
context.setClassData(
path,
}
}
else {
// this is just a normal param
replacement = t.identifier(name);
}
if (param.typeAnnotation) {
test.push(
inlineTest(context, param.typeAnnotation, replacement),
);
}
if (param.isPattern) {
blockPrelude.push(t.variableDeclaration('let', [
t.variableDeclarator(
param.path.node,
replacement
)
]));
}
else if (useBinding) {
const binding = block.scope.getBinding(param.name);
for (const refPath of binding.referencePaths) {
if (refPath.isIdentifier()) {
refPath.replaceWith(replacement);
}
else {
// we've already replaced this, go looking for the reference.
refPath.traverse({
Identifier (id: NodePath) {
if (id.node.name === param.name) {
function moduleNameToLookup(name: string): t.VariableDeclaration {
const localIdentifier = identifierFromComponentName(name);
return t.variableDeclaration('const', [
t.variableDeclarator(
localIdentifier,
t.memberExpression(
t.identifier(TEMPLATE_MODULES_PARAMETER),
t.stringLiteral(name),
true
)
),
]);
}
const args = [t.stringLiteral(typeParameter.node.name)];
if (typeParameter.node.bound) {
args.push(convert(context, typeParameter.get('bound')));
if (typeParameter.node.default) {
args.push(
convert(context, typeParameter.get('default'))
);
}
}
else if (typeParameter.node.default) {
args.push(
t.identifier('undefined'),
convert(context, typeParameter.get('default'))
);
}
return t.variableDeclarator(
t.identifier(typeParameter.node.name),
t.callExpression(
t.memberExpression(
t.identifier(name),
t.identifier('typeParameter')
),
args
)
);
}
declarator.replaceWithMultiple(closureVars.map((cv) => {
return t.variableDeclarator(cv.id, cv.init);
}));
}
t.memberExpression(
varId,
t.identifier('splice')
),
[
node,
t.numericLiteral(1),
value
]
)
)
];
}
return [
t.variableDeclaration('let', [
t.variableDeclarator(
varId,
t.objectExpression([
resolveExp && t.spreadElement(resolveExp),
t.objectProperty(
node,
value
)
].filter(Boolean))
)
])
];
};
);
this.scope.inClassMethod = true;
this.scope.inClass = klass.name;
}
}
this.enterScope();
this.scope.inFnDec = true;
const params = node.params.map(expr => {
this.scope.addLocal(expr.name);
return t.identifier(expr.name);
});
const body = t.blockStatement(node.body.map(stmt => this.visitStmt(stmt)));
if (node.isLocal) {
return loc(
t.variableDeclaration("let", [
t.variableDeclarator(id, t.functionExpression(null, params, body))
]),
node
);
}
this.leaveScope();
if (id.type === NodeType.Identifier) id = JsCodegen.refJlua(id);
return loc(
t.expressionStatement(
t.assignmentExpression(
"=",
id,
t.functionExpression(null, params, body)
)
),
node
);
ExportDefaultDeclaration: (path: NodePath) => {
if (t.isExpression(path.node.declaration)) {
const pageId = path.scope.generateUidIdentifier('page');
const declaration = path.node.declaration;
path.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(pageId, declaration),
])
);
pageConfigExpression(path, pageId);
path.stop();
} else if (
t.isFunctionDeclaration(path.node.declaration) ||
t.isClassDeclaration(path.node.declaration)
) {
const declaration = path.node.declaration;
const pageId = path.scope.generateUidIdentifierBasedOnNode(path.node);
declaration.id = pageId;
path.replaceWith(declaration);
pageConfigExpression(path, pageId);
path.stop();
}
},