-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Duplicate exports.* = assignments in CommonJS output in some casesΒ #58772
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
π 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 |
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue