-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quick-lint-js reports a diagnostic for x?.y.z. The diagnostic is incorrect. Even the JavaScript example in the documentation (written by me) does not do what the documentation claims it does. x?.y.z does not throw an error if x is null or undefined. Fix quick-lint-js's false positives by reverting commit bdfccbd. Leave a tombstone so that the diagnostic's code is not reused.
- Loading branch information
Showing
12 changed files
with
7 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
# E0718: using a '.' after a '?.' might fail, since '?.' might return 'undefined' | ||
|
||
```config-for-examples | ||
{ | ||
"globals": { | ||
} | ||
} | ||
``` | ||
This diagnostic has been removed in quick-lint-js version 3.2.0. | ||
|
||
In JavaScript, `x?.y` ignores `y` and returns `undefined` if `x` is `null` or `undefined`. If `?.` returns `undefined`, then using `.` after will throw an error: | ||
|
||
```js | ||
let bug = { milestone: null }; | ||
console.log(bug.milestone); // null | ||
console.log(bug.milestone?.name); // undefined | ||
console.log(bug.milestone?.name.trim()); // throws an error | ||
``` | ||
Replacing the `.` with `?.` will prevent the errors from being thrown at runtime: | ||
```js | ||
let bug = { milestone: null }; | ||
console.log(bug.milestone?.name?.trim()); // undefined | ||
``` | ||
<!-- QLJS_NO_CHECK_CODE --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters