don't use in, use hasOwnProperty to avoid weird collisions

This commit is contained in:
Matthew Griffith 2021-09-29 18:41:28 -04:00
parent 9922ab2a94
commit ee9a956c9f

View File

@ -10,13 +10,13 @@ export const replace = (
const visitor = (node: ts.Node): ts.VisitResult<ts.Node> => { const visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {
if (ts.isVariableStatement(node)) { if (ts.isVariableStatement(node)) {
const name = node.declarationList.declarations[0]?.name; const name = node.declarationList.declarations[0]?.name;
if (isIdentifier(name) && name.text in replacements) { if (isIdentifier(name) && replacements.hasOwnProperty(name.text)) {
const key = name.text as keyof typeof replacements; const key = name.text as keyof typeof replacements;
return ast(replacements[key]); return ast(replacements[key]);
} }
} else if (ts.isFunctionDeclaration(node)) { } else if (ts.isFunctionDeclaration(node)) {
const name = node.name; const name = node.name;
if (name && isIdentifier(name) && name.text in replacements) { if (name && isIdentifier(name) && replacements.hasOwnProperty(name.text)) {
const key = name.text as keyof typeof replacements; const key = name.text as keyof typeof replacements;
return astNodes(replacements[key]); return astNodes(replacements[key]);
} }