Skip to content

Invalid emit for class using decorators plus static properties that reference other static properties of the same class #44931

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 Jul 7, 2021 · 3 comments Β· Fixed by #44933
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue High Priority

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jul 7, 2021

Bug Report

πŸ”Ž Search Terms

  • tsc
  • emit
  • compiled

πŸ•— Version & Regression Information

Regression from at least 4.4.0-dev.20210701

Also tested in 4.4.0-dev.20210707

⏯ Playground Link

https://www.typescriptlang.org/play?target=5&ts=4.4.0-dev.20210707#code/JYOwLgpgTgZghgYwgAgJIDED2nkG9kC+AUEQCYQIA2cUKCmIAzmGlpgFzJwgCeA3CSpxGjZACEArpQDWAUVLAwABVoA3YBADuKzOvJQ8JZMeTM4YYAmS04pBpR7IAyggAWEALZxkAXmQByVUZ6cgBaACMpaQgFMAAHNQ1NfwEiE1Mwc0tkTziwHhUIdS1fPFM3TwhOSRl5RULi7ShdYH0AOhd3L0JU9PomMCgJBDBMKAAKNPSTAAEMbGQE4FVzFBs7EAdkAH0PTHInaHUkTnnMABop4wBKMuICIA

πŸ’» Code

interface IFoo { }
declare const IFoo: any;

class BulkEditPreviewProvider {

    static readonly Schema = 'vscode-bulkeditpreview';

    static emptyPreview = { scheme: BulkEditPreviewProvider.Schema };

    constructor(
        @IFoo private readonly _modeService: IFoo,
    ) { }
}

πŸ› Bug

The compiled code for this is:

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var _a;
let BulkEditPreviewProvider = (_a = class BulkEditPreviewProvider {
        constructor(_modeService) {
            this._modeService = _modeService;
        }
    },
    _a.Schema = 'vscode-bulkeditpreview',
    _a.emptyPreview = { scheme: BulkEditPreviewProvider.Schema },
    _a);
BulkEditPreviewProvider = __decorate([
    __param(0, IFoo)
], BulkEditPreviewProvider);

The bug is that _a.emptyPreview = { scheme: BulkEditPreviewProvider.Schema }, uses BulkEditPreviewProvider before that variable is defined

@mjbvz mjbvz changed the title Invalid emit for class using decorators plus static properties Invalid emit for class using decorators plus static properties that reference other static properties of the same class Jul 7, 2021
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript High Priority labels Jul 7, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.4.1 (RC) milestone Jul 7, 2021
@rbuckton
Copy link
Contributor

rbuckton commented Jul 7, 2021

Looking into it now

@MartinJohns
Copy link
Contributor

MartinJohns commented Jul 7, 2021

Sounds like a duplicate of #44908. Or probably just related.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jul 7, 2021
@rbuckton
Copy link
Contributor

rbuckton commented Jul 7, 2021

#44908 has a different root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants