Skip to content

Conversation

@rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Oct 17, 2024

This changes the __importStar helper to include non-enumerable own keys to ensure the following two cases are consistent:

// ts
import A, { b } from "mod";
A;
b;

// js
const mod_1 = __importStar(require("mod"));
mod_1.default;
mod_1.b;

vs

// ts
import A from "mod";
import { b } from "mod";
A;
b;

// js
const mod_1 = __importDefault(require("mod"));
const mod_2 = require("mod");
mod_1.default;
mod_2.b;

The discrepancy occurs when the module "mod" produces exports that are non-enumerable, such as:

class C {
  static b() {}
}

module.exports = C;

In the above case, C.b is an own static method of C which makes it non-enumerable by default.

The other way to address this would be to also wrap mod_2's require in __importStar so that we apply the rule consistently in both cases, but that would be a major breaking change as it has the potential to break existing users w/o warning.

The companion PR for tslib can be found at microsoft/tslib#272.

Fixes #45133

@rbuckton rbuckton merged commit 2e4f2c7 into main Oct 18, 2024
@rbuckton rbuckton deleted the fix45133 branch October 18, 2024 14:26
@jakebailey
Copy link
Member

Was there a typo? #41533 seems unrelated.

Should this have waited for 5.8 since it's an emit change?

@rbuckton
Copy link
Contributor Author

It's a bugfix to an emit helper and I would say the risk of it being an issue is fairly small given that it is more permissive. Going the other direction I mentioned in the OP would have needed to wait for 5.8 as it would be a breaking change.

@rbuckton
Copy link
Contributor Author

Was there a typo? #41533 seems unrelated.

Yeah, that should have been #45133.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

esModuleInterop: true with class static method

5 participants