microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Home Page:https://www.typescriptlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

5.5.0 regression - Named exports of functions are not emitted for CommonJS

Knagis opened this issue · comments

🔎 Search Terms

commonjs export

🕗 Version & Regression Information

  • This changed between versions 5.4.5 and 5.5.0

⏯ Playground Link

https://www.typescriptlang.org/play/?target=7&module=1&isolatedModules=true&verbatimModuleSyntax=false&ts=5.5.0-beta#code/GYVwdgxgLglg9mABMOcAUBKAXIgbnGAE0QG8AoAXzLIFMAPABzgCcpSzFPlUAaSgbjJA

💻 Code

function foo(): void {
}

export {
    foo,
};

🙁 Actual behavior

ts 5.5.0-beta and 5.5.0-dev-20240508 both emit:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
function foo() {
}

note missing last line

🙂 Expected behavior

ts 5.4.5 emit

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
function foo() {
}
exports.foo = foo;

Additional information about the issue

No response

the problem shows up only with functions. exporting classes or variables via export { foo } work fine. also export function foo() {} works fine.

Most likely this was #57669 (you could try using https://www.npmjs.com/package/every-ts to bisect and verify).

Bisect confirms that it is the cause

881f449a8a10839db5d535c3a407621d53c78666 is the first bad commit
commit 881f449a8a10839db5d535c3a407621d53c78666
Author: Ron Buckton
Date:   Wed Mar 6 18:43:59 2024 -0500

    Hoist function exports to top of module body in CJS/AMD/UMD (#57669)

Yeah, the issue appears to be that collectExternalModuleInfo doesn't do the same thing it does for function declarations when processing export declarations.