mirror of
https://github.com/swc-project/swc.git
synced 2024-12-27 15:42:51 +03:00
fix(es/transforms/proposal): Fix type detection (#2431)
swc_ecma_transforms_proposal: - Try the type of the LHS of an assignment pattern. (#2428)
This commit is contained in:
parent
647d3ed36a
commit
f8995848b8
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2900,7 +2900,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_proposal"
|
||||
version = "0.46.0"
|
||||
version = "0.46.1"
|
||||
dependencies = [
|
||||
"either",
|
||||
"serde",
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_proposal"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.46.0"
|
||||
version = "0.46.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -600,7 +600,9 @@ fn get_type_ann_of_pat(p: &Pat) -> Option<&TsTypeAnn> {
|
||||
Pat::Array(p) => &p.type_ann,
|
||||
Pat::Rest(p) => &p.type_ann,
|
||||
Pat::Object(p) => &p.type_ann,
|
||||
Pat::Assign(p) => &p.type_ann,
|
||||
Pat::Assign(p) => {
|
||||
return p.type_ann.as_ref().or_else(|| get_type_ann_of_pat(&p.left));
|
||||
}
|
||||
Pat::Invalid(_) => return None,
|
||||
Pat::Expr(_) => return None,
|
||||
}
|
||||
|
@ -5031,7 +5031,7 @@ var _dec9 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "funct
|
||||
Function,
|
||||
Boolean,
|
||||
Boolean,
|
||||
void 0
|
||||
String
|
||||
]), _dec10 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec11 = Decorate();
|
||||
let Sample = _class = _dec11(_class = _dec10(_class = _dec9(((_class = class Sample {
|
||||
constructor(private p0: String, p1: Number, p2: 10, p3: "ABC", p4: boolean, p5: string, p6: number, p7: Object, p8: () => any, p9: "abc" | "def", p10: String | Number, p11: Function, p12: null, p13: undefined, p14: any, p15: (abc: any) => void, p16: false, p17: true, p18: string = "abc"){
|
||||
@ -5069,14 +5069,14 @@ let Sample = _class = _dec11(_class = _dec10(_class = _dec9(((_class = class Sam
|
||||
_dec1,
|
||||
_dec2
|
||||
], Object.getOwnPropertyDescriptor(_class.prototype, "method"), _class.prototype), _dec3 = Decorate(), _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", [
|
||||
void 0,
|
||||
typeof Decorate === "undefined" || typeof Decorate.Name === "undefined" ? Object : Decorate.Name,
|
||||
typeof Decorate === "undefined" || typeof Decorate.Name === "undefined" ? Object : Decorate.Name
|
||||
]), _applyDecoratedDescriptor(_class.prototype, "method2", [
|
||||
_dec3,
|
||||
_dec4,
|
||||
_dec5
|
||||
], Object.getOwnPropertyDescriptor(_class.prototype, "method2"), _class.prototype), _dec6 = Decorate(), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec8 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [
|
||||
void 0
|
||||
String
|
||||
]), _applyDecoratedDescriptor(_class.prototype, "assignments", [
|
||||
_dec6,
|
||||
_dec7,
|
||||
|
22
tests/fixture/issue-2428/1/input/.swcrc
Normal file
22
tests/fixture/issue-2428/1/input/.swcrc
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": false,
|
||||
"decorators": true,
|
||||
"dynamicImport": false
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
},
|
||||
"target": "es2016"
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs",
|
||||
"strict": false,
|
||||
"strictMode": true,
|
||||
"lazy": false,
|
||||
"noInterop": false
|
||||
}
|
||||
}
|
10
tests/fixture/issue-2428/1/input/index.ts
Normal file
10
tests/fixture/issue-2428/1/input/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
class Foo {
|
||||
async fnName1(
|
||||
@Arg('GraphQLArgName', { nullable: true }) argName: boolean,
|
||||
): Promise<number> { }
|
||||
|
||||
async fnName2(
|
||||
@Arg('GraphQLArgName', { nullable: true }) argName: boolean = false,
|
||||
): Promise<number> { }
|
||||
}
|
85
tests/fixture/issue-2428/1/output/index.ts
Normal file
85
tests/fixture/issue-2428/1/output/index.ts
Normal file
@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
||||
var desc = {
|
||||
};
|
||||
Object.keys(descriptor).forEach(function(key) {
|
||||
desc[key] = descriptor[key];
|
||||
});
|
||||
desc.enumerable = !!desc.enumerable;
|
||||
desc.configurable = !!desc.configurable;
|
||||
if ("value" in desc || desc.initializer) {
|
||||
desc.writable = true;
|
||||
}
|
||||
desc = decorators.slice().reverse().reduce(function(desc, decorator) {
|
||||
return decorator ? decorator(target, property, desc) || desc : desc;
|
||||
}, desc);
|
||||
if (context && desc.initializer !== void 0) {
|
||||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
||||
desc.initializer = undefined;
|
||||
}
|
||||
if (desc.initializer === void 0) {
|
||||
Object.defineProperty(target, property, desc);
|
||||
desc = null;
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
||||
try {
|
||||
var info = gen[key](arg);
|
||||
var value = info.value;
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (info.done) {
|
||||
resolve(value);
|
||||
} else {
|
||||
Promise.resolve(value).then(_next, _throw);
|
||||
}
|
||||
}
|
||||
function _asyncToGenerator(fn) {
|
||||
return function() {
|
||||
var self = this, args = arguments;
|
||||
return new Promise(function(resolve, reject) {
|
||||
var gen = fn.apply(self, args);
|
||||
function _next(value) {
|
||||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
||||
}
|
||||
function _throw(err) {
|
||||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
||||
}
|
||||
_next(undefined);
|
||||
});
|
||||
};
|
||||
}
|
||||
var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5;
|
||||
let Foo1 = ((_class = class Foo {
|
||||
fnName1(argName) {
|
||||
return _asyncToGenerator(function*() {
|
||||
})();
|
||||
}
|
||||
fnName2(argName = false) {
|
||||
return _asyncToGenerator(function*() {
|
||||
})();
|
||||
}
|
||||
}) || _class, _dec = function(target, key) {
|
||||
return 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
|
||||
]), _applyDecoratedDescriptor(_class.prototype, "fnName1", [
|
||||
_dec,
|
||||
_dec1,
|
||||
_dec2
|
||||
], Object.getOwnPropertyDescriptor(_class.prototype, "fnName1"), _class.prototype), _dec3 = function(target, key) {
|
||||
return 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
|
||||
]), _applyDecoratedDescriptor(_class.prototype, "fnName2", [
|
||||
_dec3,
|
||||
_dec4,
|
||||
_dec5
|
||||
], Object.getOwnPropertyDescriptor(_class.prototype, "fnName2"), _class.prototype), _class);
|
Loading…
Reference in New Issue
Block a user