Skip to content

Commit

Permalink
fix: check for deep imports in import equals
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Oct 20, 2023
1 parent 35db270 commit 5381967
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ export const addDefaultModule = (
j.tsExternalModuleReference(j.stringLiteral(packageName))
);

const v2ImportEquals = source.find(
j.TSImportEqualsDeclaration,
getImportEqualsDeclarationType(PACKAGE_NAME)
);
const v2ImportEquals = source
.find(j.TSImportEqualsDeclaration, getImportEqualsDeclarationType())
.filter((importEqualsDeclaration) => {
const { moduleReference } = importEqualsDeclaration.value;
if (moduleReference.type !== "TSExternalModuleReference") return false;
const { expression } = moduleReference;
if (expression.type !== "StringLiteral") return false;
const { value } = expression;
return value.startsWith(PACKAGE_NAME);
});

if (v2ImportEquals.size()) {
// Insert it after the first import equals declaration.
Expand Down

0 comments on commit 5381967

Please sign in to comment.