feat(typescript-estree): handle 3.9's non-null assertion changes #2036
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TS 3.9 introduced a breaking change for how non-null assertions are handled in optional chains.
Pre-3.9,
x?.y!.z
means(x?.y).z
- i.e. it essentially scrubbed the optionality from the chainPost-3.9,
x?.y!.z
meansx?.y!.z
- i.e. it just asserts that the propertyy
is non-null, not the result ofx?.y
This PR:
updates the AST so it matches this
Previously
x?.y!.z
producedMemberExpression > TSNonNullAssertion > OptionalMemberExpression
.Now it produces
OptionalMemberExpression > TSNonNullAssertion > OptionalMemberExpression
.Note that both
(x?.y)!.z
and(x?.y!).z
still produceMemberExpression > TSNonNullAssertion > OptionalMemberExpression
.Same results apply for call expressions.
updates
no-non-null-asserted-optional-chain
to handle thisWith the above AST change, the only change needed was a simple "is parent optional chain" check.
Both of these changes are gated behind a version check, so they are completely backwards compatible.
Fixes #1976