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] [package]
name = "swc_ecma_transforms" name = "swc_ecma_transforms"
version = "0.19.2" version = "0.19.3"
authors = ["강동윤 <kdy1997.dev@gmail.com>"] authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT" license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git" 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 { c.params = c.params.move_map(|mut param| match &mut param {
ParamOrTsParamProp::TsParamProp(p) => match &p.param { ParamOrTsParamProp::TsParamProp(p) => match &p.param {
TsParamPropParam::Ident(i) => { TsParamPropParam::Ident(i) => {
typescript_constructor_properties.push(store(i)); typescript_constructor_properties.push(store(&Ident {
type_ann: None,
..i.clone()
}));
ParamOrTsParamProp::Param(Param { ParamOrTsParamProp::Param(Param {
span: p.span, span: p.span,
decorators: take(&mut p.decorators), decorators: take(&mut p.decorators),
@ -595,11 +598,19 @@ impl ClassProperties {
} }
TsParamPropParam::Assign(pat) => match &*pat.left { TsParamPropParam::Assign(pat) => match &*pat.left {
Pat::Ident(i) => { Pat::Ident(i) => {
typescript_constructor_properties.push(store(i)); typescript_constructor_properties.push(store(&Ident {
type_ann: None,
..i.clone()
}));
ParamOrTsParamProp::Param(Param { ParamOrTsParamProp::Param(Param {
span: p.span, span: p.span,
decorators: take(&mut p.decorators), 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, _ => param,

View File

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

View File

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