You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hoisted function declarations should be assigned to exports before any require calls #39853
The exports.* assignment should be done immediately after __esModule, just like how Babel does it.
// a.js"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.a=a;constb_1=require("./b.js");functiona(){returnb_1.b();}// b.js"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.b=b;consta_js_1=require("./a.js");// Crashes when transpiled by TypeScript:a_js_1.a();functionb(){return123;}
Actual behavior:
The exports assignment is performed after the function declaration, which causes behaviour differences between native ES modules (where hoisted function declarations are initialised before any code begins executing) and transpiled CommonJS modules (where hoisted function declarations are added to the exports object after require(…) calls)
// a.js"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.a=void0;constb_1=require("./b.js");functiona(){returnb_1.b();}exports.a=a;// b.js"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.b=void0;consta_js_1=require("./a.js");// Crashes when transpiled by TypeScript:a_js_1.a();functionb(){return123;}exports.b=b;
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.
"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.b=void0;consta_js_1=require("./a.js");// Crashes when transpiled by TypeScript:(0,a_js_1.a)();functionb(){return123;}exports.b=b;
Historical Information
Version
Reproduction Outputs
4.4.2, 4.5.2, 4.6.2
👍 Compiled Emit:
"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.b=void0;consta_js_1=require("./a.js");// Crashes when transpiled by TypeScript:(0,a_js_1.a)();functionb(){return123;}exports.b=b;
4.2.2, 4.3.2
👍 Compiled Emit:
"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.b=void0;consta_js_1=require("./a.js");// Crashes when transpiled by TypeScript:a_js_1.a();functionb(){return123;}exports.b=b;
Activity
typescript-bot commentedon Apr 13, 2022
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.
Issue body code block by ExE Boss (@ExE-Boss)
👍 Compiled
Emit:
Historical Information
👍 Compiled
Emit:
👍 Compiled
Emit: