-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/decorator): Add support for private access expressions in lega…
- Loading branch information
1 parent
c43dbad
commit 62ed065
Showing
7 changed files
with
191 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
swc_ecma_transforms_proposal: patch | ||
swc_core: patch | ||
--- | ||
|
||
fix(es/decorator): Add support for private access expressions in legacy decorators |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true, | ||
"decorators": true | ||
}, | ||
"target": "es2022", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Foo { | ||
static #loggedMethod<Args extends unknown[], Ret>( | ||
_prototype: typeof Foo.prototype, | ||
_propertyKey: string, | ||
descriptor: TypedPropertyDescriptor<(this: Foo, ...args: Args) => Promise<Ret>>, | ||
) { | ||
const method = descriptor.value!; | ||
descriptor.value = function (...args) { | ||
try { | ||
console.log("before"); | ||
return method.apply(this, args); | ||
} finally { | ||
console.log("after"); | ||
} | ||
}; | ||
} | ||
|
||
@(Foo.#loggedMethod) | ||
public greet(): any { | ||
console.log("hi"); | ||
} | ||
} | ||
|
||
const foo = new Foo(); | ||
foo.greet(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Foo { | ||
static { | ||
class Bar { | ||
static #x() {} | ||
|
||
@Bar.#x | ||
foo() {} | ||
} | ||
} | ||
|
||
static #y() {} | ||
|
||
@Foo.#y | ||
public foo() {} | ||
|
||
static { | ||
class Bar { | ||
static #x() {} | ||
|
||
@Bar.#x | ||
foo() {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); | ||
class Foo { | ||
static #loggedMethod(_prototype, _propertyKey, descriptor) { | ||
const method = descriptor.value; | ||
descriptor.value = function(...args) { | ||
try { | ||
console.log("before"); | ||
return method.apply(this, args); | ||
} finally{ | ||
console.log("after"); | ||
} | ||
}; | ||
} | ||
greet() { | ||
console.log("hi"); | ||
} | ||
static{ | ||
_ts_decorate._([ | ||
Foo.#loggedMethod | ||
], Foo.prototype, "greet", null); | ||
} | ||
} | ||
const foo = new Foo(); | ||
foo.greet(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var _ts_decorate = require("@swc/helpers/_/_ts_decorate"); | ||
class Foo { | ||
static{ | ||
class Bar { | ||
static #x() {} | ||
foo() {} | ||
static{ | ||
_ts_decorate._([ | ||
Bar.#x | ||
], Bar.prototype, "foo", null); | ||
} | ||
} | ||
} | ||
static #y() {} | ||
foo() {} | ||
static{ | ||
class Bar { | ||
static #x() {} | ||
foo() {} | ||
static{ | ||
_ts_decorate._([ | ||
Bar.#x | ||
], Bar.prototype, "foo", null); | ||
} | ||
} | ||
} | ||
static{ | ||
_ts_decorate._([ | ||
Foo.#y | ||
], Foo.prototype, "foo", null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters