Skip to content

Commit

Permalink
Fix optional chaining in argument position (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Sep 24, 2020
1 parent a9c3072 commit ab8df21
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.8.1"
version = "0.8.2"

[features]
codegen = ["swc_ecma_codegen"]
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms"
repository = "https://github.com/swc-project/swc.git"
version = "0.24.1"
version = "0.24.2"

[features]
const-modules = ["dashmap"]
Expand Down
5 changes: 4 additions & 1 deletion ecmascript/transforms/src/compat/es2020/opt_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ impl OptChaining {
})),
..expr
}),
Err(e) => e,
Err(callee) => Expr::Call(CallExpr {
callee: callee.as_callee(),
..e
}),
};
}
_ => {}
Expand Down
27 changes: 27 additions & 0 deletions ecmascript/transforms/tests/es2020_optional_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,30 @@ test_exec!(
expect(obj?.a?.b?.c()).toBe(2)
"
);

test!(
syntax(),
|_| tr(()),
swc_node_95_2,
"
obj?.a?.b?.c()
",
"
var ref, ref1;
obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : \
(ref1 = ref.b) === null || ref1 === void 0 ? void 0 : ref1.c();"
);

test!(
syntax(),
|_| tr(()),
swc_node_95_3,
"
expect(obj?.a?.b?.c()).toBe(2)
",
"
var ref, ref1;
expect(obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 \
: (ref1 = ref.b) === null || ref1 === void 0 ? void 0 : ref1.c()).toBe(2);
"
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/core",
"version": "1.2.32",
"version": "1.2.33",
"description": "Super-fast alternative for babel",
"homepage": "https://swc.rs",
"main": "./index.js",
Expand Down

0 comments on commit ab8df21

Please sign in to comment.