Skip to content

Invalid emit for class+namespace using module=commonJs in TS 3.9 #37118

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
mjbvz opened this issue Feb 28, 2020 · 3 comments · Fixed by #37122
Closed

Invalid emit for class+namespace using module=commonJs in TS 3.9 #37118

mjbvz opened this issue Feb 28, 2020 · 3 comments · Fixed by #37122

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Feb 28, 2020

TypeScript Version: 3.9.0-dev.20200228

Search Terms:

  • export
  • namespace

Code
With target = ES2017, module = commonJS

export class Color {
    static readonly x = new Color();
}

export namespace Color {
    export const a = 1
}

Expected behavior:
In TS 3.8, this emits:

Object.defineProperty(exports, "__esModule", { value: true });
class Color {
}
exports.Color = Color;
Color.x = new Color();
(function (Color) {
    Color.a = 1;
})(Color = exports.Color || (exports.Color = {}));

Actual behavior:
In TS 3.9, this emits:

Object.defineProperty(exports, "__esModule", { value: true });
const Color = /** @class */ (() => {
    class Color {
    }
    Color.x = new Color();
    return Color;
})();
exports.Color = Color;
(function (Color) {
    Color.a = 1;
})(Color = exports.Color || (exports.Color = {}));
exports.Color = Color;

Which is not valid since it tries to reassign a constant value: Color = exports.Color

@mjbvz mjbvz changed the title Invalid emit for module: commonJs in TS 3.9 Invalid emit for class+namespace using module=commonJs in TS 3.9 Feb 28, 2020
@mjbvz
Copy link
Contributor Author

mjbvz commented Feb 28, 2020

/cc @RyanCavanaugh This blocks using TS 3.9 for building VS Code

@mjbvz
Copy link
Contributor Author

mjbvz commented Feb 28, 2020

@rbuckton Possibly introduced by #36795

@weswigham
Copy link
Member

Ack, this is probably my fault - as a follow up to the community PR, I updated it to use const, thinking it was more desirable - I didn't realize we relied on the ability to reassign the class declaration later on (even if we're reassigning it to itself in most cases). Regressed by #36907.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants