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 committed Jan 7, 2020
1 parent a7dac49 commit f56f54b
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
Expand Up @@ -34,6 +34,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
@@ -0,0 +1 @@
a?.b!.c
@@ -0,0 +1,4 @@
{
"plugins": ["proposal-optional-chaining"],
"presets": ["../../../../../babel-preset-typescript"]
}
@@ -0,0 +1,3 @@
var _a;

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

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

0 comments on commit f56f54b

Please sign in to comment.