fix(es/decorators): Make legacy decorator identical to tsc (#4496)

This commit is contained in:
Donny/강동윤 2022-05-03 16:48:09 +09:00 committed by GitHub
parent 3e3527f50e
commit f30ffdf200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
218 changed files with 1760 additions and 2086 deletions

3
crates/swc/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# I use this to try stuffs
/lab.js
/cur.js

View File

@ -528,6 +528,7 @@ impl Options {
decorators(decorators::Config { decorators(decorators::Config {
legacy: transform.legacy_decorator, legacy: transform.legacy_decorator,
emit_metadata: transform.decorator_metadata, emit_metadata: transform.decorator_metadata,
use_define_for_class_fields: !assumptions.set_public_class_fields
}), }),
syntax.decorators() syntax.decorators()
), ),

View File

@ -1,5 +1,5 @@
use std::{ use std::{
fs::{self, create_dir_all, rename}, fs::{create_dir_all, rename},
path::{Component, Path, PathBuf}, path::{Component, Path, PathBuf},
process::Command, process::Command,
sync::Arc, sync::Arc,
@ -63,9 +63,10 @@ fn create_matrix(entry: &Path) -> Vec<Options> {
if let Some(ext) = entry.extension() { if let Some(ext) = entry.extension() {
if ext == "ts" { if ext == "ts" {
let ts = Syntax::Typescript(TsConfig { let ts = Syntax::Typescript(TsConfig {
decorators: true,
..Default::default() ..Default::default()
}); });
return vec![ts, default_es]; return vec![ts];
} }
} }
@ -128,16 +129,7 @@ fn run_fixture_test(entry: PathBuf) {
let _guard = testing::init(); let _guard = testing::init();
let matrix = create_matrix(&entry); let matrix = create_matrix(&entry);
let input_code = fs::read_to_string(&entry).expect("failed to read entry file"); let expected_stdout = get_expected_stdout(&entry).expect("failed to get stdout");
let expected_stdout = stdout_of(
&input_code,
if entry.extension().unwrap() == "mjs" {
NodeModuleType::Module
} else {
NodeModuleType::CommonJs
},
)
.expect("failed to get stdout");
eprintln!( eprintln!(
"----- {} -----\n{}\n-----", "----- {} -----\n{}\n-----",
@ -156,6 +148,60 @@ fn run_fixture_test(entry: PathBuf) {
unignore(&entry); unignore(&entry);
} }
fn get_expected_stdout(input: &Path) -> Result<String, Error> {
let cm = Arc::new(SourceMap::default());
let c = Compiler::new(cm.clone());
try_with_handler(
cm.clone(),
HandlerOpts {
color: ColorConfig::Always,
skip_filename: true,
},
|handler| {
let fm = cm.load_file(input).context("failed to load file")?;
let res = c
.process_js_file(
fm,
handler,
&Options {
config: Config {
jsc: JscConfig {
target: Some(EsVersion::Es2021),
syntax: Some(Syntax::Typescript(TsConfig {
decorators: true,
..Default::default()
})),
..Default::default()
},
module: match input.extension() {
Some(ext) if ext == "ts" => {
Some(ModuleConfig::CommonJs(Default::default()))
}
Some(ext) if ext == "mjs" => None,
_ => None,
},
..Default::default()
},
..Default::default()
},
)
.context("failed to process file")?;
let res = stdout_of(
&res.code,
match input.extension() {
Some(ext) if ext == "mjs" => NodeModuleType::Module,
_ => NodeModuleType::CommonJs,
},
)?;
Ok(res)
},
)
}
/// Rename `foo/.bar/exec.js` => `foo/bar/exec.js` /// Rename `foo/.bar/exec.js` => `foo/bar/exec.js`
fn unignore(path: &Path) { fn unignore(path: &Path) {
if path.components().all(|c| { if path.components().all(|c| {

View File

@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2016",
"transform": {
"useDefineForClassFields": false
}
}
}

View File

@ -0,0 +1,49 @@
let calledSetterProperty = false;
const testDecorator = <T extends {},>(target: T, key: keyof T) => {
const privateField = Symbol();
// We define getters and setters for the property on the prototype of the class
// A real application might use this to intercept changes to the decorated property.
// This is a simplified version of a pattern used by the @microsoft/fast-elements library.
Reflect.defineProperty(target, key, {
get: function () {
console.log(`called getter for property ${key}.`)
return (target as any)[privateField]
},
set: function (newValue) {
calledSetterProperty = true;
console.log(`called setter for property ${key} with newValue ${newValue}.`)
return (target as any)[privateField] = newValue
}
})
console.log("called testDecorator!");
};
class TestClass {
@testDecorator
testProp = "hello"
}
const instance = new TestClass();
// SWC console output:
// "called testDecorator!"
// TSC console output:
// "called testDecorator!"
// "called setter for property testProp with newValue hello"
if (!calledSetterProperty) {
throw new Error("Expected setter to be called!");
}
instance.testProp = "goodbye";
// SWC console output:
// <nothing>
// TSC console output:
// "called setter for property testProp with newValue goodbye."
console.log("testProp is now", instance.testProp);
// SWC console output:
// "testProps is now goodbye"
// TSC console output:
// "called getter for property testProp."
// "testProps is now goodbye"

View File

@ -0,0 +1,11 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"loose": true
},
"target": "es2022"
}
}

View File

@ -0,0 +1,33 @@
/*
Proxy any reads and writes to this member. We'll store the value at some private symbol
and read or write to it when the member is accessed.
*/
const d = (proto: any, name) => {
let self = proto.constructor;
const key = typeof name === "symbol" ? Symbol() : `__${name}`;
Object.defineProperty(self.prototype, name, {
get(): any {
return (this as { [key: string]: unknown })[key as string];
},
set(value: unknown) {
const oldValue = (this as {} as { [key: string]: unknown })[
name as string
];
(this as {} as { [key: string]: unknown })[key as string] = value;
},
configurable: true,
enumerable: true,
});
};
class Test {
@d
member = 4;
}
console.log(new Test().member);
if (new Test().member === undefined) {
throw new Error(`wrong`)
}

View File

@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true
},
"target": "es2022",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false
}

View File

@ -0,0 +1,14 @@
const Test = (name: string): any => {
return (target: any, key: string) => {
// stuff
};
}
@Test(FormulaRuleEntity.NAME)
class FormulaRuleEntity {
static readonly NAME = 'cat';
}
console.log('PASS')

View File

@ -0,0 +1,11 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"useDefineForClassFields": false
}
}
}

View File

@ -0,0 +1,17 @@
let id = 1;
function dec() {
console.log(id)
return () => id++
}
@dec
class Foo {
@dec
prop: number
@dec
@dec
propWithInit = 2
}

View File

@ -0,0 +1,11 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"useDefineForClassFields": false
}
}
}

View File

@ -0,0 +1,31 @@
let id = 1;
function dec() {
console.log(id)
return () => id++
}
function key() {
console.log(id)
return id++
}
@dec
class Foo {
@dec
prop1: number
@dec
[key()]: number
@dec
@dec
[key()]: number
@dec
prop2: number
}

View File

@ -1,24 +1,16 @@
"use strict"; "use strict";
var swcHelpers = require("@swc/helpers"); var swcHelpers = require("@swc/helpers");
var _class, _descriptor, _dec, _dec1;
var MyEnum; var MyEnum;
(function(MyEnum) { (function(MyEnum) {
MyEnum["x"] = "xxx"; MyEnum["x"] = "xxx";
MyEnum["y"] = "yyy"; MyEnum["y"] = "yyy";
})(MyEnum || (MyEnum = {})); })(MyEnum || (MyEnum = {}));
let Xpto = ((_class = class Xpto { class Xpto {
constructor(){ }
swcHelpers.initializerDefineProperty(this, "value", _descriptor, this); swcHelpers.__decorate([
} Decorator(),
}) || _class, _dec = Decorator(), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "value", [ swcHelpers.__metadata("design:type", String)
_dec, ], Xpto.prototype, "value", void 0);
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);
function Decorator() { function Decorator() {
return function(...args) {}; return function(...args) {};
} }

View File

@ -1,23 +1,15 @@
"use strict"; "use strict";
var swcHelpers = require("@swc/helpers"); var swcHelpers = require("@swc/helpers");
var _class, _descriptor, _dec, _dec1;
function MyDecorator(klass) { function MyDecorator(klass) {
return ()=>{ return ()=>{
// do something // do something
console.log(klass); console.log(klass);
}; };
} }
let MyClass = ((_class = class MyClass { class MyClass {
constructor(){ }
swcHelpers.initializerDefineProperty(this, "prop", _descriptor, this); swcHelpers.__decorate([
} MyDecorator(MyClass),
}) || _class, _dec = MyDecorator(_class), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "prop", [ swcHelpers.__metadata("design:type", String)
_dec, ], MyClass.prototype, "prop", void 0);
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);
console.log(new MyClass()); console.log(new MyClass());

View File

@ -1,94 +1,55 @@
import * as swcHelpers from "@swc/helpers"; import * as swcHelpers from "@swc/helpers";
var _class, _descriptor, _dec, _dec1, _descriptor1, _dec2, _dec3, _descriptor2, _dec4, _dec5, _descriptor3, _dec6, _dec7, _descriptor4, _dec8, _dec9, _descriptor5, _dec10, _dec11, _descriptor6, _dec12, _dec13, _descriptor7, _dec14, _dec15; export var AccountMemberView = function AccountMemberView() {
var _dec16 = ViewEntity({
name: "AccountMemberView",
expression: '\n SELECT\n m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="F") as accountCnt,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="T") as accountQuickCnt\n FROM TBLMEMBER m\n '
});
export var AccountMemberView = _class = _dec16((_class = function AccountMemberView() {
"use strict"; "use strict";
swcHelpers.classCallCheck(this, AccountMemberView); swcHelpers.classCallCheck(this, AccountMemberView);
swcHelpers.initializerDefineProperty(this, "memberId", _descriptor, this); };
swcHelpers.initializerDefineProperty(this, "mallId", _descriptor1, this); swcHelpers.__decorate([
swcHelpers.initializerDefineProperty(this, "allowAccountCnt", _descriptor2, this); ViewColumn({
swcHelpers.initializerDefineProperty(this, "allowQuickAccountCnt", _descriptor3, this); name: "tmcode"
swcHelpers.initializerDefineProperty(this, "accountEnddedAt", _descriptor4, this); }),
swcHelpers.initializerDefineProperty(this, "accountQuickEnddedAt", _descriptor5, this); swcHelpers.__metadata("design:type", Number)
swcHelpers.initializerDefineProperty(this, "accountCnt", _descriptor6, this); ], AccountMemberView.prototype, "memberId", void 0);
swcHelpers.initializerDefineProperty(this, "accountQuickCnt", _descriptor7, this); swcHelpers.__decorate([
}, _dec = ViewColumn({ ViewColumn({
name: "tmcode" name: "mid"
}), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec2 = ViewColumn({ }),
name: "mid" swcHelpers.__metadata("design:type", String)
}), _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _dec4 = ViewColumn({ ], AccountMemberView.prototype, "mallId", void 0);
name: "accea" swcHelpers.__decorate([
}), _dec5 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec6 = ViewColumn({ ViewColumn({
name: "qaccea" name: "accea"
}), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec8 = ViewColumn({ }),
name: "endday" swcHelpers.__metadata("design:type", Number)
}), _dec9 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec10 = ViewColumn({ ], AccountMemberView.prototype, "allowAccountCnt", void 0);
name: "quick_endday" swcHelpers.__decorate([
}), _dec11 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec12 = ViewColumn(), _dec13 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec14 = ViewColumn(), _dec15 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "memberId", [ ViewColumn({
_dec, name: "qaccea"
_dec1 }),
], { swcHelpers.__metadata("design:type", Number)
configurable: true, ], AccountMemberView.prototype, "allowQuickAccountCnt", void 0);
enumerable: true, swcHelpers.__decorate([
writable: true, ViewColumn({
initializer: null name: "endday"
}), _descriptor1 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "mallId", [ }),
_dec2, swcHelpers.__metadata("design:type", typeof Date === "undefined" ? Object : Date)
_dec3 ], AccountMemberView.prototype, "accountEnddedAt", void 0);
], { swcHelpers.__decorate([
configurable: true, ViewColumn({
enumerable: true, name: "quick_endday"
writable: true, }),
initializer: null swcHelpers.__metadata("design:type", typeof Date === "undefined" ? Object : Date)
}), _descriptor2 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "allowAccountCnt", [ ], AccountMemberView.prototype, "accountQuickEnddedAt", void 0);
_dec4, swcHelpers.__decorate([
_dec5 ViewColumn(),
], { swcHelpers.__metadata("design:type", Number)
configurable: true, ], AccountMemberView.prototype, "accountCnt", void 0);
enumerable: true, swcHelpers.__decorate([
writable: true, ViewColumn(),
initializer: null swcHelpers.__metadata("design:type", Number)
}), _descriptor3 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "allowQuickAccountCnt", [ ], AccountMemberView.prototype, "accountQuickCnt", void 0);
_dec6, AccountMemberView = swcHelpers.__decorate([
_dec7 ViewEntity({
], { name: "AccountMemberView",
configurable: true, expression: '\n SELECT\n m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="F") as accountCnt,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="T") as accountQuickCnt\n FROM TBLMEMBER m\n '
enumerable: true, })
writable: true, ], AccountMemberView);
initializer: null
}), _descriptor4 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "accountEnddedAt", [
_dec8,
_dec9
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor5 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "accountQuickEnddedAt", [
_dec10,
_dec11
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor6 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "accountCnt", [
_dec12,
_dec13
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor7 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "accountQuickCnt", [
_dec14,
_dec15
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class)) || _class;

View File

@ -7,11 +7,7 @@ var swcHelpers = require("@swc/helpers");
var _common = require("@nestjs/common"); var _common = require("@nestjs/common");
var _appService = require("./app.service"); var _appService = require("./app.service");
var _createUserDto = require("./dtos/CreateUserDto"); var _createUserDto = require("./dtos/CreateUserDto");
var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6; let AppController = class AppController {
var _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [
typeof _appService.AppService === "undefined" ? Object : _appService.AppService
]), _dec8 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec9 = (0, _common).Controller();
let AppController = _class = _dec9(_class = _dec8(_class = _dec7(((_class = class AppController {
async getHello() { async getHello() {
const result = await this.appService.getHello(); const result = await this.appService.getHello();
return result; return result;
@ -23,18 +19,25 @@ let AppController = _class = _dec9(_class = _dec8(_class = _dec7(((_class = clas
constructor(appService){ constructor(appService){
this.appService = appService; this.appService = appService;
} }
}) || _class, _dec = (0, _common).Get(), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec2 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), swcHelpers.applyDecoratedDescriptor(_class.prototype, "getHello", [ };
_dec,
_dec1,
_dec2
], Object.getOwnPropertyDescriptor(_class.prototype, "getHello"), _class.prototype), _dec3 = (0, _common).Post(), _dec4 = function(target, key) {
return (0, _common).Body()(target, key, 0);
}, _dec5 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec6 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [
typeof _createUserDto.CreateUserDto === "undefined" ? Object : _createUserDto.CreateUserDto
]), swcHelpers.applyDecoratedDescriptor(_class.prototype, "create", [
_dec3,
_dec4,
_dec5,
_dec6
], Object.getOwnPropertyDescriptor(_class.prototype, "create"), _class.prototype), _class)) || _class) || _class) || _class;
exports.AppController = AppController; exports.AppController = AppController;
swcHelpers.__decorate([
(0, _common).Get(),
swcHelpers.__metadata("design:type", Function),
swcHelpers.__metadata("design:paramtypes", [])
], AppController.prototype, "getHello", null);
swcHelpers.__decorate([
(0, _common).Post(),
swcHelpers.__param(0, (0, _common).Body()),
swcHelpers.__metadata("design:type", Function),
swcHelpers.__metadata("design:paramtypes", [
typeof _createUserDto.CreateUserDto === "undefined" ? Object : _createUserDto.CreateUserDto
])
], AppController.prototype, "create", null);
exports.AppController = AppController = swcHelpers.__decorate([
(0, _common).Controller(),
swcHelpers.__metadata("design:type", Function),
swcHelpers.__metadata("design:paramtypes", [
typeof _appService.AppService === "undefined" ? Object : _appService.AppService
])
], AppController);

View File

@ -1,23 +1,17 @@
"use strict"; "use strict";
var swcHelpers = require("@swc/helpers"); var swcHelpers = require("@swc/helpers");
require("reflect-metadata"); require("reflect-metadata");
var _class, _descriptor, _dec, _dec1;
var COL_KEY = Symbol("col"); var COL_KEY = Symbol("col");
var column = function() { var column = function() {
return function(object, key) { return function(object, key) {
Reflect.defineMetadata(COL_KEY, "value", object, key); Reflect.defineMetadata(COL_KEY, "value", object, key);
}; };
}; };
var User = ((_class = function User() { var User = function User() {
"use strict"; "use strict";
swcHelpers.classCallCheck(this, User); swcHelpers.classCallCheck(this, User);
swcHelpers.initializerDefineProperty(this, "currency", _descriptor, this); };
}) || _class, _dec = column(), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "currency", [ swcHelpers.__decorate([
_dec, column(),
_dec1 swcHelpers.__metadata("design:type", String)
], { ], User.prototype, "currency", void 0);
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);

View File

@ -1,67 +1,78 @@
"use strict"; "use strict";
var _class, _class1, _class2, _class3, _class4, _class5; var swcHelpers = require("@swc/helpers");
var _dec = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ // not work
typeof Injected === "undefined" ? Object : Injected
]), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec2 = function(target, key) {
return Inject()(target, undefined, 0);
};
let MyClass1 = _class = _dec2(_class = _dec1(_class = _dec((_class = // not work
class MyClass1 { class MyClass1 {
constructor(param1){ constructor(param1){
this.param1 = param1; this.param1 = param1;
} }
}) || _class) || _class) || _class) || _class; }
var _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass1 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected swcHelpers.__param(0, Inject()),
]), _dec4 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec5 = function(target, key) { swcHelpers.__metadata("design:type", Function),
return Inject()(target, undefined, 0); swcHelpers.__metadata("design:paramtypes", [
}; typeof Injected === "undefined" ? Object : Injected
let MyClass2 = _class1 = _dec5(_class1 = _dec4(_class1 = _dec3((_class1 = class MyClass2 { ])
], MyClass1);
class MyClass2 {
constructor(param1){ constructor(param1){
this.param1 = param1; this.param1 = param1;
} }
}) || _class1) || _class1) || _class1) || _class1; }
var _dec6 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass2 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected swcHelpers.__param(0, Inject()),
]), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec8 = function(target, key) { swcHelpers.__metadata("design:type", Function),
return Inject()(target, undefined, 0); swcHelpers.__metadata("design:paramtypes", [
}; typeof Injected === "undefined" ? Object : Injected
let MyClass3 = _class2 = _dec8(_class2 = _dec7(_class2 = _dec6((_class2 = class MyClass3 { ])
], MyClass2);
class MyClass3 {
constructor(param1){ constructor(param1){
this.param1 = param1; this.param1 = param1;
} }
}) || _class2) || _class2) || _class2) || _class2; }
var _dec9 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass3 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected swcHelpers.__param(0, Inject()),
]), _dec10 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec11 = function(target, key) { swcHelpers.__metadata("design:type", Function),
return Inject()(target, undefined, 0); swcHelpers.__metadata("design:paramtypes", [
}; typeof Injected === "undefined" ? Object : Injected
let MyClass4 = _class3 = _dec11(_class3 = _dec10(_class3 = _dec9((_class3 = class MyClass4 { ])
], MyClass3);
class MyClass4 {
constructor(param1){ constructor(param1){
this.param1 = param1; this.param1 = param1;
} }
}) || _class3) || _class3) || _class3) || _class3; }
var _dec12 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass4 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected swcHelpers.__param(0, Inject()),
]), _dec13 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec14 = function(target, key) { swcHelpers.__metadata("design:type", Function),
return Inject()(target, undefined, 0); swcHelpers.__metadata("design:paramtypes", [
}; typeof Injected === "undefined" ? Object : Injected
let MyClass5 = _class4 = _dec14(_class4 = _dec13(_class4 = _dec12((_class4 = class MyClass5 { ])
], MyClass4);
class MyClass5 {
constructor(param1){ constructor(param1){
this.param1 = param1; this.param1 = param1;
} }
}) || _class4) || _class4) || _class4) || _class4; }
var _dec15 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass5 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected, swcHelpers.__param(0, Inject()),
typeof Injected === "undefined" ? Object : Injected swcHelpers.__metadata("design:type", Function),
]), _dec16 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec17 = function(target, key) { swcHelpers.__metadata("design:paramtypes", [
return Inject()(target, undefined, 1); typeof Injected === "undefined" ? Object : Injected
}, _dec18 = function(target, key) { ])
return Inject()(target, undefined, 0); ], MyClass5);
}; class MyClass6 {
let MyClass6 = _class5 = _dec18(_class5 = _dec17(_class5 = _dec16(_class5 = _dec15((_class5 = class MyClass6 {
constructor(param1, param2){ constructor(param1, param2){
this.param1 = param1; this.param1 = param1;
this.param2 = param2; this.param2 = param2;
} }
}) || _class5) || _class5) || _class5) || _class5) || _class5; }
MyClass6 = swcHelpers.__decorate([
swcHelpers.__param(0, Inject()),
swcHelpers.__param(1, Inject()),
swcHelpers.__metadata("design:type", Function),
swcHelpers.__metadata("design:paramtypes", [
typeof Injected === "undefined" ? Object : Injected,
typeof Injected === "undefined" ? Object : Injected
])
], MyClass6);

View File

@ -1,37 +1,41 @@
"use strict"; "use strict";
var _class, _class1, _class2; var swcHelpers = require("@swc/helpers");
var _dec = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ // work
typeof Injected === "undefined" ? Object : Injected
]), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec2 = function(target, key) {
return Inject()(target, undefined, 0);
};
let MyClass1 = _class = _dec2(_class = _dec1(_class = _dec((_class = // work
class MyClass1 { class MyClass1 {
constructor(param1){} constructor(param1){}
}) || _class) || _class) || _class) || _class; }
var _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass1 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected, swcHelpers.__param(0, Inject()),
typeof Injected === "undefined" ? Object : Injected swcHelpers.__metadata("design:type", Function),
]), _dec4 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec5 = function(target, key) { swcHelpers.__metadata("design:paramtypes", [
return Inject()(target, undefined, 1); typeof Injected === "undefined" ? Object : Injected
}, _dec6 = function(target, key) { ])
return Inject()(target, undefined, 0); ], MyClass1);
}; class MyClass2 {
let MyClass2 = _class1 = _dec6(_class1 = _dec5(_class1 = _dec4(_class1 = _dec3((_class1 = class MyClass2 {
constructor(param1, param2){ constructor(param1, param2){
this.param1 = param1; this.param1 = param1;
} }
}) || _class1) || _class1) || _class1) || _class1) || _class1; }
var _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ MyClass2 = swcHelpers.__decorate([
typeof Injected === "undefined" ? Object : Injected, swcHelpers.__param(0, Inject()),
typeof Injected === "undefined" ? Object : Injected swcHelpers.__param(1, Inject()),
]), _dec8 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec9 = function(target, key) { swcHelpers.__metadata("design:type", Function),
return Inject()(target, undefined, 1); swcHelpers.__metadata("design:paramtypes", [
}, _dec10 = function(target, key) { typeof Injected === "undefined" ? Object : Injected,
return Inject()(target, undefined, 0); typeof Injected === "undefined" ? Object : Injected
}; ])
let MyClass3 = _class2 = _dec10(_class2 = _dec9(_class2 = _dec8(_class2 = _dec7((_class2 = class MyClass3 { ], MyClass2);
class MyClass3 {
constructor(param1, param2){ constructor(param1, param2){
this.param2 = param2; this.param2 = param2;
} }
}) || _class2) || _class2) || _class2) || _class2) || _class2; }
MyClass3 = swcHelpers.__decorate([
swcHelpers.__param(0, Inject()),
swcHelpers.__param(1, Inject()),
swcHelpers.__metadata("design:type", Function),
swcHelpers.__metadata("design:paramtypes", [
typeof Injected === "undefined" ? Object : Injected,
typeof Injected === "undefined" ? Object : Injected
])
], MyClass3);

View File

@ -1,5 +1,7 @@
var _class; import * as swcHelpers from "@swc/helpers";
import { Entity, BaseEntity } from 'typeorm'; import { Entity, BaseEntity } from 'typeorm';
var _dec = Entity(); export let Location = class Location extends BaseEntity {
export let Location = _class = _dec((_class = class Location extends BaseEntity { };
}) || _class) || _class; Location = swcHelpers.__decorate([
Entity()
], Location);

View File

@ -1,12 +1,14 @@
import * as swcHelpers from "@swc/helpers"; import * as swcHelpers from "@swc/helpers";
var _TestClass; var _TestClass;
var _class; var TestClass = (_TestClass = function TestClass() {
var TestClass = _class = someClassDecorator((_class = (_TestClass = function TestClass() {
"use strict"; "use strict";
swcHelpers.classCallCheck(this, TestClass); swcHelpers.classCallCheck(this, TestClass);
}, _TestClass.Something = "hello", _TestClass.SomeProperties = { }, _TestClass.Something = "hello", _TestClass.SomeProperties = {
firstProp: _TestClass.Something firstProp: _TestClass.Something
}, _TestClass)) || _class) || _class; }, _TestClass);
TestClass = swcHelpers.__decorate([
someClassDecorator
], TestClass);
function someClassDecorator(c) { function someClassDecorator(c) {
return c; return c;
} }

View File

@ -1,31 +1,28 @@
"use strict"; "use strict";
var swcHelpers = require("@swc/helpers"); var swcHelpers = require("@swc/helpers");
var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5; class Foo {
let Foo = ((_class = class Foo {
fnName1(argName) { fnName1(argName) {
return swcHelpers.asyncToGenerator(function*() {})(); return swcHelpers.asyncToGenerator(function*() {})();
} }
fnName2(argName = false) { fnName2(argName = false) {
return swcHelpers.asyncToGenerator(function*() {})(); return swcHelpers.asyncToGenerator(function*() {})();
} }
}) || _class, _dec = function(target, key) { }
return Arg('GraphQLArgName', { swcHelpers.__decorate([
swcHelpers.__param(0, Arg('GraphQLArgName', {
nullable: true nullable: true
})(target, key, 0); })),
}, _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec2 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ swcHelpers.__metadata("design:type", Function),
Boolean swcHelpers.__metadata("design:paramtypes", [
]), swcHelpers.applyDecoratedDescriptor(_class.prototype, "fnName1", [ Boolean
_dec, ])
_dec1, ], Foo.prototype, "fnName1", null);
_dec2 swcHelpers.__decorate([
], Object.getOwnPropertyDescriptor(_class.prototype, "fnName1"), _class.prototype), _dec3 = function(target, key) { swcHelpers.__param(0, Arg('GraphQLArgName', {
return Arg('GraphQLArgName', {
nullable: true nullable: true
})(target, key, 0); })),
}, _dec4 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec5 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [ swcHelpers.__metadata("design:type", Function),
Boolean swcHelpers.__metadata("design:paramtypes", [
]), swcHelpers.applyDecoratedDescriptor(_class.prototype, "fnName2", [ Boolean
_dec3, ])
_dec4, ], Foo.prototype, "fnName2", null);
_dec5
], Object.getOwnPropertyDescriptor(_class.prototype, "fnName2"), _class.prototype), _class);

View File

@ -1,17 +1,11 @@
"use strict"; "use strict";
var swcHelpers = require("@swc/helpers"); var swcHelpers = require("@swc/helpers");
var joiful = swcHelpers.interopRequireWildcard(require("joiful")); var joiful = swcHelpers.interopRequireWildcard(require("joiful"));
var _class, _descriptor, _dec, _dec1; var Schema = function Schema() {
var Schema = ((_class = function Schema() {
"use strict"; "use strict";
swcHelpers.classCallCheck(this, Schema); swcHelpers.classCallCheck(this, Schema);
swcHelpers.initializerDefineProperty(this, "id", _descriptor, this); };
}) || _class, _dec = joiful.string().guid().required(), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "id", [ swcHelpers.__decorate([
_dec, joiful.string().guid().required(),
_dec1 swcHelpers.__metadata("design:type", String)
], { ], Schema.prototype, "id", void 0);
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);

View File

@ -4,26 +4,22 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.ServiceError = void 0; exports.ServiceError = void 0;
var swcHelpers = require("@swc/helpers"); var swcHelpers = require("@swc/helpers");
var _class, _descriptor;
const CD = ()=>{}; const CD = ()=>{};
const PD = ()=>{}; const PD = ()=>{};
let ServiceError = _class = CD(((_class = class ServiceError extends Error { let ServiceError = class ServiceError extends Error {
name = "ServiceError.BadResponse";
constructor(...args){ constructor(...args){
super(...args); super(...args);
swcHelpers.initializerDefineProperty(this, "code", _descriptor, this); this.code = ServiceError.Code.badResponse;
} }
}) || _class, _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "code", [ name = "ServiceError.BadResponse";
PD };
], {
configurable: true,
enumerable: true,
writable: true,
initializer: function() {
return ServiceError.Code.badResponse;
}
}), _class)) || _class;
exports.ServiceError = ServiceError; exports.ServiceError = ServiceError;
swcHelpers.__decorate([
PD
], ServiceError.prototype, "code", void 0);
exports.ServiceError = ServiceError = swcHelpers.__decorate([
CD
], ServiceError);
(function(ServiceError1) { (function(ServiceError1) {
let Code; let Code;
(function(Code) { (function(Code) {

View File

@ -1,8 +1,14 @@
var _class, _class1; import * as swcHelpers from "@swc/helpers";
var N; var N;
(function(N) { (function(N) {
let C1 = _class = foo((_class = class C1 { let C1 = class C1 {
}) || _class) || _class; };
C1 = swcHelpers.__decorate([
foo
], C1);
})(N || (N = {})); })(N || (N = {}));
let C2 = _class1 = foo((_class1 = class C2 { let C2 = class C2 {
}) || _class1) || _class1; };
C2 = swcHelpers.__decorate([
foo
], C2);

View File

@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.default = void 0; exports.default = void 0;
var _class; var swcHelpers = require("@swc/helpers");
function test(constructor) { function test(constructor) {
console.log(constructor); console.log(constructor);
} }
let _class1 = _class = test((_class = class { let _class = class _class {
}) || _class) || _class; };
exports.default = _class1; exports.default = _class = swcHelpers.__decorate([
test
], _class);
exports.default = _class;

View File

@ -1,7 +1,10 @@
var _class; import * as swcHelpers from "@swc/helpers";
function test(constructor) { function test(constructor) {
console.log(constructor); console.log(constructor);
} }
let _class1 = _class = test((_class = class { let _class = class _class {
}) || _class) || _class; };
export { _class1 as default }; _class = swcHelpers.__decorate([
test
], _class);
export { _class as default };

Some files were not shown because too many files have changed in this diff Show More