From a099275b2aa5318a67d4bb2a1ae15fe32b2997ec Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 3 Jan 2024 15:46:54 -0600 Subject: [PATCH] Fix declaration emit for JS default re-exports that resolve to modules through synthesized default exports (#56340) --- src/compiler/checker.ts | 3 +++ .../declarationEmitJsReExportDefault.js | 15 +++++++++++++++ .../declarationEmitJsReExportDefault.ts | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitJsReExportDefault.js create mode 100644 tests/cases/compiler/declarationEmitJsReExportDefault.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 30c41c94d3a..7fcd96913ae 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9744,6 +9744,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // does not use localName because the symbol name in this case refers to the name in the exports table, // which we must exactly preserve const specifier = (node.parent.parent as ExportDeclaration).moduleSpecifier; + if (specifier && (node as ExportSpecifier).propertyName?.escapedText === InternalSymbolName.Default) { + verbatimTargetName = InternalSymbolName.Default; + } // targetName is only used when the target is local, as otherwise the target is an alias that points at // another file serializeExportSpecifier( diff --git a/tests/baselines/reference/declarationEmitJsReExportDefault.js b/tests/baselines/reference/declarationEmitJsReExportDefault.js new file mode 100644 index 00000000000..f575575ff96 --- /dev/null +++ b/tests/baselines/reference/declarationEmitJsReExportDefault.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/declarationEmitJsReExportDefault.ts] //// + +//// [package.json] +{"name": "a", "version": "0.0.0"} +//// [index.d.ts] +export const a = 123; + +//// [index.mjs] +export {default as mod} from 'a'; + + + + +//// [index.d.mts] +export { default as mod } from "a"; diff --git a/tests/cases/compiler/declarationEmitJsReExportDefault.ts b/tests/cases/compiler/declarationEmitJsReExportDefault.ts new file mode 100644 index 00000000000..0d05fc45d60 --- /dev/null +++ b/tests/cases/compiler/declarationEmitJsReExportDefault.ts @@ -0,0 +1,18 @@ +// @noTypesAndSymbols: true + +// @filename: /node_modules/a/package.json +{"name": "a", "version": "0.0.0"} +// @filename: /node_modules/a/index.d.ts +export const a = 123; + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "module": "node16", + "declaration": true, + "emitDeclarationOnly": true, + "checkJs": true, + } +} +// @filename: /index.mjs +export {default as mod} from 'a';