Add loose mode for nullish coalescing operator (#6531)

* Add loose mode for nullish-coalescing

* Remove unneeded SequenceExpression
This commit is contained in:
Lucas Azzola
2017-10-22 22:25:29 +11:00
committed by Mateusz Burzyński
parent 9e0f5235b1
commit cd4f0ae393
8 changed files with 93 additions and 21 deletions

View File

@@ -113,6 +113,36 @@ require("@babel/core").transform("code", {
});
```
## Options
### `loose`
`boolean`, defaults to `false`.
When `true`, this transform will pretend `document.all` does not exist,
and perform loose equality checks with `null` instead of string equality checks
against both `null` and `undefined`.
#### Example
In
```javascript
foo?.bar;
```
Out (`loose === true`)
```javascript
foo == null ? void 0 : foo.bar;
```
Out (`loose === false`)
```javascript
foo === null || foo === void 0 ? void 0 : foo.bar;
```
## References
* [Proposal: Optional Chaining](https://github.com/tc39/proposal-optional-chaining)