Open
Description
openedon Apr 1, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment