Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly restore type-only import/export names #337

Merged
merged 10 commits into from
Feb 28, 2025
6 changes: 6 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ts from "typescript";

export const TS_EXTENSIONS = /\.([cm]ts|[tj]sx?)$/;

export const DTS_EXTENSIONS = /\.d\.(c|m)?tsx?$/;
Expand All @@ -12,4 +14,8 @@ export function trimExtension(path: string) {

export function getDeclarationId(path: string) {
return path.replace(SUPPORTED_EXTENSIONS, ".d.ts")
}

export function parse(fileName: string, code: string): ts.SourceFile {
return ts.createSourceFile(fileName, code, ts.ScriptTarget.Latest, true);
}
166 changes: 0 additions & 166 deletions src/transform/ExportsFixer.ts

This file was deleted.

8 changes: 7 additions & 1 deletion src/transform/Transformer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type * as ESTree from "estree";
import ts from "typescript";
import { convertExpression, createIdentifier, createProgram, withStartEnd } from "./astHelpers.js";
import { convertExpression, convertTypeOnlyHintStatement, createIdentifier, createProgram, withStartEnd } from "./astHelpers.js";
import { DeclarationScope } from "./DeclarationScope.js";
import { UnsupportedSyntaxError } from "./errors.js";
import { parseTypeOnlyName } from "./TypeOnlyFixer.js";

type ESTreeImports = ESTree.ImportDeclaration["specifiers"];

Expand Down Expand Up @@ -165,6 +166,11 @@ class Transformer {
}

convertTypeAliasDeclaration(node: ts.TypeAliasDeclaration) {
if(parseTypeOnlyName(node.name.text).isTypeOnly) {
this.pushStatement(convertTypeOnlyHintStatement(node))
return
}

const scope = this.createDeclaration(node, node.name);

const typeVariables = scope.convertTypeParameters(node.typeParameters);
Expand Down
Loading