From d09b1bfb5ac63bf8320d210f6c2ca9ead8ef24b3 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 17 Nov 2023 16:18:10 -0800 Subject: [PATCH] Pick #56449 into release-5.3 (#56451) --- src/compiler/checker.ts | 2 +- src/testRunner/unittests/services/transpile.ts | 11 +++++++++++ .../transpile/Elides re-export of type-only import.js | 2 ++ ...ides re-export of type-only import.oldTranspile.js | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/transpile/Elides re-export of type-only import.js create mode 100644 tests/baselines/reference/transpile/Elides re-export of type-only import.oldTranspile.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 560783a71b58d..9ad699f1adcb0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47515,7 +47515,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const target = getExportSymbolOfValueSymbolIfExported(resolveAlias(symbol)); if (target === unknownSymbol) { - return true; + return !excludeTypeOnlyValues || !getTypeOnlyAliasDeclaration(symbol); } // const enums and modules that contain only const enums are not considered values from the emit perspective // unless 'preserveConstEnums' option is set to true diff --git a/src/testRunner/unittests/services/transpile.ts b/src/testRunner/unittests/services/transpile.ts index ddb040d7af356..a5d4efaf0b395 100644 --- a/src/testRunner/unittests/services/transpile.ts +++ b/src/testRunner/unittests/services/transpile.ts @@ -662,4 +662,15 @@ export * as alias from './file';`, testVerbatimModuleSyntax: true, }, ); + + transpilesCorrectly( + "Elides re-export of type-only import", + ` + import type { Foo } from "./types"; + export { Foo }; + `, + { + options: { compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ESNext } }, + }, + ); }); diff --git a/tests/baselines/reference/transpile/Elides re-export of type-only import.js b/tests/baselines/reference/transpile/Elides re-export of type-only import.js new file mode 100644 index 0000000000000..e113dbc728253 --- /dev/null +++ b/tests/baselines/reference/transpile/Elides re-export of type-only import.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=file.js.map \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Elides re-export of type-only import.oldTranspile.js b/tests/baselines/reference/transpile/Elides re-export of type-only import.oldTranspile.js new file mode 100644 index 0000000000000..e113dbc728253 --- /dev/null +++ b/tests/baselines/reference/transpile/Elides re-export of type-only import.oldTranspile.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=file.js.map \ No newline at end of file