Repository navigation
Conversation
TypeScript ends an optional chain at an instantiation expression, so `a?.b<T>.c` is emitted as `(a?.b).c`. Erasing only `<T>` gave `a?.b .c`, which keeps the chain going: it returns undefined instead of throwing when `a` is nullish, and `a?.b<T>.c = 1` became invalid JS. Like the `as`/`satisfies` grouping cases, call onError and leave the code unchanged when a non-optional `.x`, `[x]`, `(x)` or template follows such an instantiation expression. Signed-off-by: Mradul Singh <msingh@dealmeridian.com>
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #82
TypeScript ends an optional chain at an instantiation expression, so
a?.b<T>.cis emitted as(a?.b).c. Only blanking<T>gavea?.b .c, which keeps the chain going (returnsundefinedinstead of throwing whenais nullish), anda?.b<T>.c = 1/a?.b<T>.c`` became invalid JS.The
(can't be inserted without moving offsets, so this follows theas/satisfiesgrouping cases:onErroris called and the code is left unchanged when a non-optional.x,[x],(x)or tagged template follows an instantiation expression whose expression is an optional chain (also through!, as ina?.b!<T>.c).The check is done in the parent (property/element access, call, tagged template) because the visitor runs without parent pointers.
Still erased, as the meaning stays the same:
a?.b<T>,a?.b<T>?.c,(a?.b<T>).c,a.b<T>.c,class C extends a?.b<T> {}.Testing:
tests/errors.test.ts: the error cases fail onmain(noonErrorcall) and pass now; the "still erased" cases pass on both.npm test(45 pass),npm run fixtures(no output changes),npm run check,npm run format:check..tsfiles: identical output and error counts.docs/unsupported_syntax.md.