Skip to content

Commit

Permalink
fix: optional-chaining should work correctly with ts non-null operator
Browse files Browse the repository at this point in the history
  • Loading branch information
macabeus authored and nicolo-ribaudo committed Apr 7, 2020
1 parent ce6cc4e commit 7cff730
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/babel-plugin-proposal-optional-chaining/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default declare((api, options) => {
optionalPath.node.type = "CallExpression";
optionalPath = optionalPath.get("callee");
}

// unwrap a TSNonNullExpression if need
if (optionalPath.isTSNonNullExpression()) {
optionalPath.replaceWith(optionalPath.node.expression);
}
}

let replacementPath = path;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a?.b!.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["proposal-optional-chaining"],
"presets": ["../../../../../babel-preset-typescript"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var _a;

(_a = a) === null || _a === void 0 ? void 0 : _a.b.c;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a?.b!.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": [
"proposal-optional-chaining",
"../../../../../babel-plugin-syntax-typescript"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var _a;

(_a = a) === null || _a === void 0 ? void 0 : _a.b.c;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a?.b!.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": [
"../../../../../babel-plugin-syntax-optional-chaining",
"../../../../../babel-plugin-transform-typescript"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a?.b.c;

0 comments on commit 7cff730

Please sign in to comment.