mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 23:27:56 +03:00
fix(es/helpers): Fix decorator helper script (#4072)
This commit is contained in:
parent
1483a71c7e
commit
55cfad152d
@ -3,6 +3,7 @@ authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "rust port of babel and closure compiler."
|
||||
documentation = "https://rustdoc.swc.rs/swc_ecma_transforms/"
|
||||
edition = "2021"
|
||||
include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0"
|
||||
name = "swc_ecma_transforms"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
|
@ -0,0 +1,12 @@
|
||||
function field(host: any, field: any, descr?: any): any {
|
||||
return { ...descr, get: () => { }, set: () => { } }
|
||||
}
|
||||
|
||||
class TestMems {
|
||||
@field
|
||||
static some = 1
|
||||
}
|
||||
|
||||
|
||||
expect(Object.keys(TestMems)).toEqual(['some'])
|
||||
expect(TestMems.some).toBeUndefined()
|
@ -12,10 +12,17 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con
|
||||
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
|
||||
return decorator ? (decorator(target, property, desc) || desc) : desc;
|
||||
}, desc);
|
||||
if (context && desc.initializer !== void 0) {
|
||||
var hasAccessor = Object.prototype.hasOwnProperty.call(desc, 'get') || Object.prototype.hasOwnProperty.call(desc, 'set');
|
||||
if (context && desc.initializer !== void 0 && !hasAccessor) {
|
||||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
||||
desc.initializer = undefined;
|
||||
}
|
||||
|
||||
if (hasAccessor) {
|
||||
delete desc.writable;
|
||||
delete desc.initializer;
|
||||
delete desc.value;
|
||||
}
|
||||
if (desc.initializer === void 0) {
|
||||
Object.defineProperty(target, property, desc);
|
||||
desc = null;
|
||||
|
@ -14,11 +14,17 @@ export default function _applyDecoratedDescriptor(target, property, decorators,
|
||||
return decorator ? (decorator(target, property, desc) || desc) : desc;
|
||||
}, desc);
|
||||
|
||||
if (context && desc.initializer !== void 0) {
|
||||
var hasAccessor = Object.prototype.hasOwnProperty.call(desc, 'get') || Object.prototype.hasOwnProperty.call(desc, 'set');
|
||||
if (context && desc.initializer !== void 0 && !hasAccessor) {
|
||||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
||||
desc.initializer = undefined;
|
||||
}
|
||||
|
||||
if (hasAccessor) {
|
||||
delete desc.writable;
|
||||
delete desc.initializer;
|
||||
delete desc.value;
|
||||
}
|
||||
if (desc.initializer === void 0) {
|
||||
Object['define' + 'Property'](target, property, desc);
|
||||
desc = null;
|
||||
|
Loading…
Reference in New Issue
Block a user