microsoft / microsoft/TypeScript

.js error when module type is CommonJS and a variable name is exports

Open
#54,738 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JS Emit Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 CommonJS exports
🕗 5.1.3
⏯ Playground Link

Playground link with relevant code

💻 Code
export let a = 1;

function b(exports: any) {
    if (a == 1)
        return exports.a;
    else
        return exports.b;
}
🙁 Actual behavior
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
exports.a = 1;
function b(exports) {
    if (exports.a == 1)
        return exports.a;
    else
        return exports.b;
}
🙂 Expected behavior
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
exports.a = 1;
function b(exports_1) {
    if (exports.a == 1)
        return exports_1.a;
    else
        return exports_1.b;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the linked Playground example with CommonJS output, then trace the compiler's CommonJS transformation for a function parameter named exports. Done means the emitted JavaScript keeps the module export object references correct while renaming the conflicting parameter, with a regression test for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.