Skip to content

useDefineForClassFields emit uses undeclared temp name for computed properties #33857

@jcormont

Description

@jcormont

TypeScript Version: 3.7.0-beta

Code

I'm not sure what is causing this exactly, I'll try to find a minimal reproduction; but adding this issue anyway since there is a chance that the emitted code is enough to find the root cause.

There seems to be a strange interplay between the useDefineForClassFields option and code emission for ES5 and ES6, causing the emitted JS code to contain undefined variables.

The issue occurs in https://github.com/typescene/typescene repo; checkout branch tsc-useDefineForClassFields, and run npm install && npm run build -- code compiles fine (no errors) but tests fail. That's because the emitted code has syntax errors. This occurs for both ES5 (functions) and ES6 (proper classes) targets. However esnext works fine but in that case of course Node.js complains.

Expected behavior:

No syntax errors in emitted code, OR an error when compiling since useDefineForClassFields doesn't necessarily make sense with ES5/ES6.

Actual behavior:

The following code is emitted for dist/core/ManagedObject.js (comment mine):

// ...
export class ManagedObject {
    constructor() {
        Object.defineProperty(this, "managedId", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: _nextUID++
        });
        Object.defineProperty(this, _a, { //////////////// !!!!!!!!!!!!!!!!!!!! <<<
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, _b, {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, _c, {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, _d, {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, _e, {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "_emitting", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
    // ... etc

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions