diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c5701087ebfd4..0897c61ac8e49 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9552,11 +9552,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { symbol.flags & SymbolFlags.ExportDoesNotSupportDefaultModifier || (symbol.flags & SymbolFlags.Function && length(getPropertiesOfType(getTypeOfSymbol(symbol)))) ) && !(symbol.flags & SymbolFlags.Alias); // An alias symbol should preclude needing to make an alias ourselves - let needsExportDeclaration = !needsPostExportDefault && !isPrivate && isStringANonContextualKeyword(symbolName) && !isDefault; - // `serializeVariableOrProperty` will handle adding the export declaration if it is run (since `getInternalSymbolName` will create the name mapping), so we need to ensuer we unset `needsExportDeclaration` if it is - if (needsPostExportDefault || needsExportDeclaration) { - isPrivate = true; - } + isPrivate ||= needsPostExportDefault; const modifierFlags = (!isPrivate ? ModifierFlags.Export : 0) | (isDefault && !needsPostExportDefault ? ModifierFlags.Default : 0); const isConstMergedWithNS = symbol.flags & SymbolFlags.Module && symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property) && @@ -9581,7 +9577,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (propertyAsAlias) { const createdExport = serializeMaybeAliasAssignment(symbol); if (createdExport) { - needsExportDeclaration = false; needsPostExportDefault = false; } } @@ -9679,7 +9674,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ), ModifierFlags.None, ); - needsExportDeclaration = false; needsPostExportDefault = false; } } @@ -9737,18 +9731,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { context.approximateLength += 16 + internalSymbolName.length; // `export default internalName;` addResult(factory.createExportAssignment(/*modifiers*/ undefined, /*isExportEquals*/ false, factory.createIdentifier(internalSymbolName)), ModifierFlags.None); } - else if (needsExportDeclaration) { - const internalSymbolName = getInternalSymbolName(symbol, symbolName); - context.approximateLength += 22 + symbolName.length + internalSymbolName.length; // `export { internalName as symbolName };` - addResult( - factory.createExportDeclaration( - /*modifiers*/ undefined, - /*isTypeOnly*/ false, - factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, internalSymbolName, symbolName)]), - ), - ModifierFlags.None, - ); - } } function includePrivateSymbol(symbol: Symbol) { diff --git a/tests/baselines/reference/jsDeclarationsKeywordExport1.js b/tests/baselines/reference/jsDeclarationsKeywordExport1.js new file mode 100644 index 0000000000000..f7ee2d1412250 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsKeywordExport1.js @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsKeywordExport1.ts] //// + +//// [source.js] +// https://github.com/microsoft/TypeScript/issues/62081 + +const _null = {} +const $void = {} + +export { _null as null, $void as void } + + +//// [source.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/62081 +Object.defineProperty(exports, "__esModule", { value: true }); +exports.void = exports.null = void 0; +var _null = {}; +exports.null = _null; +var $void = {}; +exports.void = $void; + + +//// [source.d.ts] +declare const _null: {}; +declare const $void: {}; +export { _null as null, $void as void }; diff --git a/tests/baselines/reference/jsDeclarationsKeywordExport1.symbols b/tests/baselines/reference/jsDeclarationsKeywordExport1.symbols new file mode 100644 index 0000000000000..9ad25d957a359 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsKeywordExport1.symbols @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsKeywordExport1.ts] //// + +=== source.js === +// https://github.com/microsoft/TypeScript/issues/62081 + +const _null = {} +>_null : Symbol(_null, Decl(source.js, 2, 5)) + +const $void = {} +>$void : Symbol($void, Decl(source.js, 3, 5)) + +export { _null as null, $void as void } +>_null : Symbol(_null, Decl(source.js, 2, 5)) +>null : Symbol(null, Decl(source.js, 5, 8)) +>$void : Symbol($void, Decl(source.js, 3, 5)) +>void : Symbol(void, Decl(source.js, 5, 23)) + diff --git a/tests/baselines/reference/jsDeclarationsKeywordExport1.types b/tests/baselines/reference/jsDeclarationsKeywordExport1.types new file mode 100644 index 0000000000000..c1860743112ad --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsKeywordExport1.types @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsKeywordExport1.ts] //// + +=== source.js === +// https://github.com/microsoft/TypeScript/issues/62081 + +const _null = {} +>_null : {} +> : ^^ +>{} : {} +> : ^^ + +const $void = {} +>$void : {} +> : ^^ +>{} : {} +> : ^^ + +export { _null as null, $void as void } +>_null : {} +> : ^^ +>null : {} +> : ^^ +>$void : {} +> : ^^ +>void : {} +> : ^^ + diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsKeywordExport1.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsKeywordExport1.ts new file mode 100644 index 0000000000000..0a3099980e215 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsKeywordExport1.ts @@ -0,0 +1,13 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: source.js + +// https://github.com/microsoft/TypeScript/issues/62081 + +const _null = {} +const $void = {} + +export { _null as null, $void as void }