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 {
legacy: transform.legacy_decorator,
emit_metadata: transform.decorator_metadata,
use_define_for_class_fields: !assumptions.set_public_class_fields
}),
syntax.decorators()
),

View File

@ -1,5 +1,5 @@
use std::{
fs::{self, create_dir_all, rename},
fs::{create_dir_all, rename},
path::{Component, Path, PathBuf},
process::Command,
sync::Arc,
@ -63,9 +63,10 @@ fn create_matrix(entry: &Path) -> Vec<Options> {
if let Some(ext) = entry.extension() {
if ext == "ts" {
let ts = Syntax::Typescript(TsConfig {
decorators: true,
..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 matrix = create_matrix(&entry);
let input_code = fs::read_to_string(&entry).expect("failed to read entry file");
let expected_stdout = stdout_of(
&input_code,
if entry.extension().unwrap() == "mjs" {
NodeModuleType::Module
} else {
NodeModuleType::CommonJs
},
)
.expect("failed to get stdout");
let expected_stdout = get_expected_stdout(&entry).expect("failed to get stdout");
eprintln!(
"----- {} -----\n{}\n-----",
@ -156,6 +148,60 @@ fn run_fixture_test(entry: PathBuf) {
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`
fn unignore(path: &Path) {
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";
var swcHelpers = require("@swc/helpers");
var _class, _descriptor, _dec, _dec1;
var MyEnum;
(function(MyEnum) {
MyEnum["x"] = "xxx";
MyEnum["y"] = "yyy";
})(MyEnum || (MyEnum = {}));
let Xpto = ((_class = class Xpto {
constructor(){
swcHelpers.initializerDefineProperty(this, "value", _descriptor, this);
}
}) || _class, _dec = Decorator(), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "value", [
_dec,
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);
class Xpto {
}
swcHelpers.__decorate([
Decorator(),
swcHelpers.__metadata("design:type", String)
], Xpto.prototype, "value", void 0);
function Decorator() {
return function(...args) {};
}

View File

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

View File

@ -1,94 +1,55 @@
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;
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() {
export var AccountMemberView = function AccountMemberView() {
"use strict";
swcHelpers.classCallCheck(this, AccountMemberView);
swcHelpers.initializerDefineProperty(this, "memberId", _descriptor, this);
swcHelpers.initializerDefineProperty(this, "mallId", _descriptor1, this);
swcHelpers.initializerDefineProperty(this, "allowAccountCnt", _descriptor2, this);
swcHelpers.initializerDefineProperty(this, "allowQuickAccountCnt", _descriptor3, this);
swcHelpers.initializerDefineProperty(this, "accountEnddedAt", _descriptor4, this);
swcHelpers.initializerDefineProperty(this, "accountQuickEnddedAt", _descriptor5, this);
swcHelpers.initializerDefineProperty(this, "accountCnt", _descriptor6, this);
swcHelpers.initializerDefineProperty(this, "accountQuickCnt", _descriptor7, this);
}, _dec = ViewColumn({
name: "tmcode"
}), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec2 = ViewColumn({
name: "mid"
}), _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String), _dec4 = ViewColumn({
name: "accea"
}), _dec5 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec6 = ViewColumn({
name: "qaccea"
}), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number), _dec8 = ViewColumn({
name: "endday"
}), _dec9 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec10 = ViewColumn({
name: "quick_endday"
}), _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", [
_dec,
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor1 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "mallId", [
_dec2,
_dec3
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor2 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "allowAccountCnt", [
_dec4,
_dec5
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor3 = swcHelpers.applyDecoratedDescriptor(_class.prototype, "allowQuickAccountCnt", [
_dec6,
_dec7
], {
configurable: true,
enumerable: true,
writable: true,
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;
};
swcHelpers.__decorate([
ViewColumn({
name: "tmcode"
}),
swcHelpers.__metadata("design:type", Number)
], AccountMemberView.prototype, "memberId", void 0);
swcHelpers.__decorate([
ViewColumn({
name: "mid"
}),
swcHelpers.__metadata("design:type", String)
], AccountMemberView.prototype, "mallId", void 0);
swcHelpers.__decorate([
ViewColumn({
name: "accea"
}),
swcHelpers.__metadata("design:type", Number)
], AccountMemberView.prototype, "allowAccountCnt", void 0);
swcHelpers.__decorate([
ViewColumn({
name: "qaccea"
}),
swcHelpers.__metadata("design:type", Number)
], AccountMemberView.prototype, "allowQuickAccountCnt", void 0);
swcHelpers.__decorate([
ViewColumn({
name: "endday"
}),
swcHelpers.__metadata("design:type", typeof Date === "undefined" ? Object : Date)
], AccountMemberView.prototype, "accountEnddedAt", void 0);
swcHelpers.__decorate([
ViewColumn({
name: "quick_endday"
}),
swcHelpers.__metadata("design:type", typeof Date === "undefined" ? Object : Date)
], AccountMemberView.prototype, "accountQuickEnddedAt", void 0);
swcHelpers.__decorate([
ViewColumn(),
swcHelpers.__metadata("design:type", Number)
], AccountMemberView.prototype, "accountCnt", void 0);
swcHelpers.__decorate([
ViewColumn(),
swcHelpers.__metadata("design:type", Number)
], AccountMemberView.prototype, "accountQuickCnt", void 0);
AccountMemberView = swcHelpers.__decorate([
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 '
})
], AccountMemberView);

View File

@ -7,11 +7,7 @@ var swcHelpers = require("@swc/helpers");
var _common = require("@nestjs/common");
var _appService = require("./app.service");
var _createUserDto = require("./dtos/CreateUserDto");
var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6;
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 {
let AppController = class AppController {
async getHello() {
const result = await this.appService.getHello();
return result;
@ -23,18 +19,25 @@ let AppController = _class = _dec9(_class = _dec8(_class = _dec7(((_class = clas
constructor(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;
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";
var swcHelpers = require("@swc/helpers");
require("reflect-metadata");
var _class, _descriptor, _dec, _dec1;
var COL_KEY = Symbol("col");
var column = function() {
return function(object, key) {
Reflect.defineMetadata(COL_KEY, "value", object, key);
};
};
var User = ((_class = function User() {
var User = function User() {
"use strict";
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", [
_dec,
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);
};
swcHelpers.__decorate([
column(),
swcHelpers.__metadata("design:type", String)
], User.prototype, "currency", void 0);

View File

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

View File

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

View File

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

View File

@ -1,17 +1,11 @@
"use strict";
var swcHelpers = require("@swc/helpers");
var joiful = swcHelpers.interopRequireWildcard(require("joiful"));
var _class, _descriptor, _dec, _dec1;
var Schema = ((_class = function Schema() {
var Schema = function Schema() {
"use strict";
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", [
_dec,
_dec1
], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _class);
};
swcHelpers.__decorate([
joiful.string().guid().required(),
swcHelpers.__metadata("design:type", String)
], Schema.prototype, "id", void 0);

View File

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

View File

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

View File

@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _class;
var swcHelpers = require("@swc/helpers");
function test(constructor) {
console.log(constructor);
}
let _class1 = _class = test((_class = class {
}) || _class) || _class;
exports.default = _class1;
let _class = class _class {
};
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) {
console.log(constructor);
}
let _class1 = _class = test((_class = class {
}) || _class) || _class;
export { _class1 as default };
let _class = class _class {
};
_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