Fix typescript strip in class properties pass (#954)

Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
LongYinan 2020-08-10 19:33:25 +08:00 committed by GitHub
parent e1f5d681e3
commit dde9defbe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "swc_ecma_transforms"
version = "0.19.2"
version = "0.19.3"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"

View File

@ -586,7 +586,10 @@ impl ClassProperties {
c.params = c.params.move_map(|mut param| match &mut param {
ParamOrTsParamProp::TsParamProp(p) => match &p.param {
TsParamPropParam::Ident(i) => {
typescript_constructor_properties.push(store(i));
typescript_constructor_properties.push(store(&Ident {
type_ann: None,
..i.clone()
}));
ParamOrTsParamProp::Param(Param {
span: p.span,
decorators: take(&mut p.decorators),
@ -595,11 +598,19 @@ impl ClassProperties {
}
TsParamPropParam::Assign(pat) => match &*pat.left {
Pat::Ident(i) => {
typescript_constructor_properties.push(store(i));
typescript_constructor_properties.push(store(&Ident {
type_ann: None,
..i.clone()
}));
ParamOrTsParamProp::Param(Param {
span: p.span,
decorators: take(&mut p.decorators),
pat: Pat::Ident(i.clone()),
pat: Pat::Assign(AssignPat {
span: DUMMY_SP,
left: pat.left.clone(),
right: pat.right.clone(),
type_ann: None,
}),
})
}
_ => param,

View File

@ -763,15 +763,17 @@ test!(
foo = 'foo'
b = this.a;
constructor(readonly a) {
constructor(private readonly a: string, readonly c, private d: number = 1) {
super()
this.foo.subscribe()
}
}",
"class A extends B {
constructor(a) {
constructor(a, c, d = 1) {
super();
this.a = a;
this.c = c;
this.d = d;
this.foo = 'foo';
this.b = this.a;
this.foo.subscribe();

View File

@ -1,6 +1,6 @@
{
"name": "@swc/core",
"version": "1.2.16",
"version": "1.2.17",
"description": "Super-fast alternative for babel",
"main": "./index.js",
"author": "강동윤 <kdy1997.dev@gmail.com>",