Skip to content

Commit

Permalink
Allow optional constructor property parameters (#959)
Browse files Browse the repository at this point in the history
swc_ecma_transforms:
 - Handle optional constructor property parameters properly (#958)
  • Loading branch information
kdy1 committed Aug 13, 2020
1 parent fe2bcb0 commit a62af5f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ecmascript/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "swc_ecmascript"
version = "0.3.1"
version = "0.3.2"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"
Expand All @@ -20,7 +20,7 @@ swc_ecma_ast = { version = "0.28.0", path ="./ast" }
swc_ecma_codegen = { version = "0.31.0", path ="./codegen", optional = true }
swc_ecma_parser = { version = "0.33.3", path ="./parser", optional = true }
swc_ecma_utils = { version = "0.17.0", path ="./utils", optional = true }
swc_ecma_transforms = { version = "0.19.3", path ="./transforms", optional = true }
swc_ecma_transforms = { version = "0.19.5", path ="./transforms", optional = true }
swc_ecma_visit = { version = "0.13.0", path ="./visit", optional = true }

[dev-dependencies]
2 changes: 1 addition & 1 deletion ecmascript/transforms/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "swc_ecma_transforms"
version = "0.19.4"
version = "0.19.5"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"
Expand Down
19 changes: 19 additions & 0 deletions ecmascript/transforms/src/compat/es2020/class_properties.rs
Expand Up @@ -51,6 +51,25 @@ struct ClassProperties {
}

impl Fold for ClassProperties {
fn fold_ident(&mut self, i: Ident) -> Ident {
Ident {
optional: false,
..i
}
}
fn fold_array_pat(&mut self, p: ArrayPat) -> ArrayPat {
ArrayPat {
optional: false,
..p.fold_children_with(self)
}
}
fn fold_object_pat(&mut self, p: ObjectPat) -> ObjectPat {
ObjectPat {
optional: false,
..p.fold_children_with(self)
}
}

fn fold_module_items(&mut self, n: Vec<ModuleItem>) -> Vec<ModuleItem> {
self.fold_stmt_like(n)
}
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/transforms/src/resolver/tests.rs
Expand Up @@ -1160,7 +1160,7 @@ export class HygieneTest {
getDuration() {
return this.duration;
}
constructor(duration?: number){
constructor(duration: number){
_defineProperty(this, 'duration', DURATION);
this.duration = duration ?? DURATION;
}
Expand Down
14 changes: 14 additions & 0 deletions ecmascript/transforms/tests/typescript_strip.rs
Expand Up @@ -783,3 +783,17 @@ test!(
}
}"
);

test!(
::swc_ecma_parser::Syntax::Typescript(Default::default()),
|_| chain!(typescript_class_properties(), tr()),
issue_958,
"export class Test {
constructor(readonly test?: string) {}
}",
"export class Test {
constructor(test){
this.test = test;
}
}"
);

0 comments on commit a62af5f

Please sign in to comment.