Skip to content

TypeError when overriding export entries in star export #38820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
legendecas opened this issue May 28, 2020 · 2 comments
Closed

TypeError when overriding export entries in star export #38820

legendecas opened this issue May 28, 2020 · 2 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@legendecas
Copy link

legendecas commented May 28, 2020

TypeScript Version: 3.9.3

Search Terms: export star, export binding, duplicated exports

Code

// a.ts
export const name = 'a'
// b.ts
export const name = 'b'
// c.ts
export * from './a'
export { name } from './b'
// d.ts
import { name } from './c'
console.log(name) 

Expected behavior:

In d.ts, it should print b.

Tested with pure .mjs with Node.js, it works as expected.

Actual behavior:

Throws TypeError: Cannot redefine property: name

Generates:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
exports.__esModule = true;
__exportStar(require("./a"), exports);
var b_1 = require("./b");
__createBinding(exports, b_1, "name");

Also tested on TypeScript 3.8.3, 3.8.3 generates:

function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
__export(require("./a"));
var b_1 = require("./b");
exports.name = b_1.name;

According to https://tc39.es/ecma262/#sec-resolveexport, the star exports should be resolved after explicit export names.

@legendecas legendecas changed the title TypeError when overriding export entries in start export TypeError when overriding export entries in export star May 28, 2020
@legendecas legendecas changed the title TypeError when overriding export entries in export star TypeError when overriding export entries in star export May 28, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 11, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 11, 2020
@patrickm
Copy link

Having the same issue

Can reproduce on:
Version 3.9.5
Version 4.0.0-dev.20200626

On 3.8.2 works as expected

Looks like it's broken since 3.9.X by Exports Now Use Getters for Live Bindings

@rbuckton
Copy link
Contributor

I've tested this against the latest in master and it works as expected. I believe this was fixed by #39213. I'm not sure why it would repo in 4.0.0-dev.20200626, as the fix should have been included in that release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants