Skip to content

Commit

Permalink
[deno-gen-cache-entry] Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Sep 3, 2024
1 parent 8b88297 commit a1e8193
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkgs/deno-gen-cache-entry/shared.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import ts from "typescript";
import {
createSourceFile,
forEachChild,
isExportDeclaration,
isImportDeclaration,
isStringLiteral,
type Node,
ScriptTarget,
} from "typescript";

export function extractImportExportSpecifiers(
filePath: string,
sourceCode: string,
): Set<string> {
const specifierSet = new Set<string>();
const sourceFile = ts.createSourceFile(
const sourceFile = createSourceFile(
filePath,
sourceCode,
ts.ScriptTarget.Latest,
ScriptTarget.Latest,
true,
);

function visit(node: ts.Node): void {
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
function visit(node: Node): void {
if (isImportDeclaration(node) || isExportDeclaration(node)) {
if (node.moduleSpecifier && isStringLiteral(node.moduleSpecifier)) {
const specifier = node.moduleSpecifier.text;
specifierSet.add(specifier);
}
} else {
ts.forEachChild(node, visit);
forEachChild(node, visit);
}
}

Expand Down

0 comments on commit a1e8193

Please sign in to comment.