-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: DecoratorsThe issue relates to the decorator syntaxThe issue relates to the decorator syntaxFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
decorator private field syntax error
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
function decorator(cb: () => any): any {
return () => console.log(cb())
}
class Foo {
static #bar = 123
@decorator(() => Foo.#bar) foo() {}
}
new Fooπ Actual behavior
I expect this code to either be a compile error or to compile successfully and print 123 when run.
π Expected behavior
The code compiles without any errors but the generated code contains a syntax error:
"use strict";
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 _a, _Foo_bar;
function decorator(cb) {
return () => console.log(cb());
}
class Foo {
foo() { }
}
_a = Foo;
_Foo_bar = { value: 123 };
__decorate([
decorator(() => Foo.)
], Foo.prototype, "foo", null);
new Foo;Context: I discovered this issue while investigating how TypeScript handles various decorator edge cases, which I'm doing because I'm trying to replicate TypeScript's behavior into esbuild's TypeScript transpiler for this issue: evanw/esbuild#2147.
RyanCavanaugh and Jakob5358
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: DecoratorsThe issue relates to the decorator syntaxThe issue relates to the decorator syntaxFix AvailableA PR has been opened for this issueA PR has been opened for this issue