Skip to content

Duplicate exports.* = assignments in CommonJS output in some casesΒ #58772

Closed
@lauraharker

Description

@lauraharker

πŸ”Ž Search Terms

commonjs, exports, function

πŸ•— Version & Regression Information

⏯ Playground Link

Thanks for merging I'm still seeing an odd behavior I think is related: here's the minimal repro I could find - bug workbench link

πŸ’» Code

// @showEmittedFile: main.ts
// @module: commonjs

// @filename: main.ts
import { Foo } from "./file-with-export"
export function createFoo(): Foo {
    return {};
}
export {createFoo as createFooV2};

// @filename: file-with-export.ts
export interface Foo {}

πŸ™ Actual behavior

main.js has two exports for createFoo and createFooV2:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFoo = createFoo;
exports.createFooV2 = createFoo;
exports.createFoo = createFoo;
exports.createFooV2 = createFoo;
function createFoo() {
    return {};
}

πŸ™‚ Expected behavior

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFoo = createFoo;
exports.createFooV2 = createFoo;
function createFoo() {
    return {};
}

Additional information about the issue

I believe this is a result of the fix for #58473. (I still appreciate having these duplicate exports rather than the compiler dropping the exports entirely πŸ˜ƒ )

In the debugger, I see that this exportedFunctions (

exportedFunctions: Set<FunctionDeclaration>; // all of the top-level exported function declarations
) set contains two separate createFoo nodes.

If I remove the export {createFoo as createFooV2} from the repro, or remove the declared return type : Foo, I get the expected behavior.

This was uncovered by testing the latest TS version in Google (#58685)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions