Skip to content

Commit

Permalink
chore: call getImport*Declarations from has*
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Feb 29, 2024
1 parent e1056d3 commit f436346
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
10 changes: 2 additions & 8 deletions src/transforms/v2-to-v3/modules/hasImport.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Collection, JSCodeshift } from "jscodeshift";
import { PACKAGE_NAME } from "../config";
import { getImportDeclarations } from "./importModule";

export const hasImport = (j: JSCodeshift, source: Collection<unknown>) =>
source
.find(j.ImportDeclaration)
.filter((importDeclaration) => {
const { value: sourceValue } = importDeclaration.value.source;
return typeof sourceValue === "string" && sourceValue.startsWith(PACKAGE_NAME);
})
.size() > 0;
getImportDeclarations(j, source).size() > 0;
17 changes: 2 additions & 15 deletions src/transforms/v2-to-v3/modules/hasImportEquals.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { Collection, JSCodeshift } from "jscodeshift";

import { PACKAGE_NAME } from "../config";
import { getImportEqualsDeclarations } from "./importEqualsModule";

export const hasImportEquals = (j: JSCodeshift, source: Collection<unknown>) =>
source
.find(j.TSImportEqualsDeclaration)
.filter((importEqualsDeclaration) => {
const { moduleReference } = importEqualsDeclaration.value;
if (moduleReference.type !== "TSExternalModuleReference") return false;
const { expression } = moduleReference;
return (
expression.type === "StringLiteral" &&
typeof expression.value === "string" &&
expression.value.startsWith(PACKAGE_NAME)
);
})
.size() > 0;
getImportEqualsDeclarations(j, source).size() > 0;

0 comments on commit f436346

Please sign in to comment.