Skip to content

Commit f2813d0

Browse files
authored
fix: disable the type-only transform (#341)
1 parent cef4b81 commit f2813d0

File tree

5 files changed

+58
-25
lines changed

5 files changed

+58
-25
lines changed

src/transform/Transformer.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type * as ESTree from "estree";
22
import ts from "typescript";
3-
import { convertExpression, convertTypeOnlyHintStatement, createIdentifier, createProgram, withStartEnd } from "./astHelpers.js";
3+
import { convertExpression, createIdentifier, createProgram, withStartEnd } from "./astHelpers.js";
44
import { DeclarationScope } from "./DeclarationScope.js";
55
import { UnsupportedSyntaxError } from "./errors.js";
6-
import { parseTypeOnlyName } from "./TypeOnlyFixer.js";
76

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

@@ -166,10 +165,17 @@ class Transformer {
166165
}
167166

168167
convertTypeAliasDeclaration(node: ts.TypeAliasDeclaration) {
169-
if(parseTypeOnlyName(node.name.text).isTypeOnly) {
170-
this.pushStatement(convertTypeOnlyHintStatement(node))
171-
return
172-
}
168+
/**
169+
* TODO: type-only import/export fixer.
170+
* Temporarily disable the type-only import/export transformation,
171+
* because the current implementation is unsafe.
172+
*
173+
* Issue: https://github.com/Swatinem/rollup-plugin-dts/issues/340
174+
*/
175+
// if(parseTypeOnlyName(node.name.text).isTypeOnly) {
176+
// this.pushStatement(convertTypeOnlyHintStatement(node))
177+
// return
178+
// }
173179

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

src/transform/TypeOnlyFixer.ts

+23-16
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,29 @@ export class TypeOnlyFixer {
195195
this.DEBUG && console.log(`${node.name.getFullText()} is a type`);
196196
this.types.add(alias);
197197

198-
if (ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName)) {
199-
const reference = node.type.typeName.text;
200-
const aliasHint = parseTypeOnlyName(alias);
201-
202-
if(aliasHint.isTypeOnly) {
203-
this.DEBUG && console.log(`${reference} is a type (from type-only hint)`);
204-
this.types.add(reference);
205-
this.typeHints.set(reference, (this.typeHints.get(reference) || 0) + 1);
206-
if(aliasHint.isReExport) {
207-
const reExportName = alias.split(TYPE_ONLY_RE_EXPORT)[0]!
208-
this.DEBUG && console.log(`${reExportName} is a type (from type-only re-export hint)`);
209-
this.reExportTypeHints.set(reExportName, (this.reExportTypeHints.get(reExportName) || 0) + 1);
210-
}
211-
this.code.remove(node.getStart(), node.getEnd());
212-
}
213-
}
198+
/**
199+
* TODO: type-only import/export fixer.
200+
* Temporarily disable the type-only import/export transformation,
201+
* because the current implementation is unsafe.
202+
*
203+
* Issue: https://github.com/Swatinem/rollup-plugin-dts/issues/340
204+
*/
205+
// if (ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName)) {
206+
// const reference = node.type.typeName.text;
207+
// const aliasHint = parseTypeOnlyName(alias);
208+
209+
// if(aliasHint.isTypeOnly) {
210+
// this.DEBUG && console.log(`${reference} is a type (from type-only hint)`);
211+
// this.types.add(reference);
212+
// this.typeHints.set(reference, (this.typeHints.get(reference) || 0) + 1);
213+
// if(aliasHint.isReExport) {
214+
// const reExportName = alias.split(TYPE_ONLY_RE_EXPORT)[0]!
215+
// this.DEBUG && console.log(`${reExportName} is a type (from type-only re-export hint)`);
216+
// this.reExportTypeHints.set(reExportName, (this.reExportTypeHints.get(reExportName) || 0) + 1);
217+
// }
218+
// this.code.remove(node.getStart(), node.getEnd());
219+
// }
220+
// }
214221
continue;
215222
}
216223

src/transform/preprocess.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,15 @@ export function preProcess({ sourceFile, isEntry, isJSON }: PreProcessInput): Pr
194194
// recursively check inline imports
195195
checkInlineImport(node);
196196

197-
transformTypeOnlyImport(node);
198-
transformTypeOnlyExport(node);
197+
/**
198+
* TODO: type-only import/export fixer.
199+
* Temporarily disable the type-only import/export transformation,
200+
* because the current implementation is unsafe.
201+
*
202+
* Issue: https://github.com/Swatinem/rollup-plugin-dts/issues/340
203+
*/
204+
// transformTypeOnlyImport(node);
205+
// transformTypeOnlyExport(node);
199206

200207
if (!matchesModifier(node, ts.ModifierFlags.ExportDefault)) {
201208
continue;
@@ -305,6 +312,7 @@ export function preProcess({ sourceFile, isEntry, isJSON }: PreProcessInput): Pr
305312
fileReferences,
306313
};
307314

315+
// @ts-expect-error temporary disabled
308316
function transformTypeOnlyImport(node: ts.Node) {
309317
if (!ts.isImportDeclaration(node) || !node.importClause) {
310318
return;
@@ -351,6 +359,7 @@ export function preProcess({ sourceFile, isEntry, isJSON }: PreProcessInput): Pr
351359
}
352360
}
353361

362+
// @ts-expect-error temporary disabled
354363
function transformTypeOnlyExport(node: ts.Node) {
355364
if(!ts.isExportDeclaration(node)) {
356365
return;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
interface Foo {}
2-
//@ts-expect-error
32
export type { Foo };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @ts-check
2+
3+
/** @type {import('../../testcases').Meta} */
4+
export default {
5+
options: {},
6+
rollupOptions: {},
7+
/**
8+
* TODO: Until we found a safe way to handle the type-only import/export,
9+
* we skip this test.
10+
*/
11+
skip: true,
12+
};

0 commit comments

Comments
 (0)