fix(parser): disallow optional chaining on import.defer - #4794
Open
BhariGowda wants to merge 2 commits into
Open
fix(parser): disallow optional chaining on import.defer#4794BhariGowda wants to merge 2 commits into
BhariGowda wants to merge 2 commits into
Conversation
- Add diagnostic TS18062: 'import.defer' does not support optional invocation
- Report error when '?.' followed by '(' or '<' appears after 'import.defer'
Fixes microsoft#4789
Contributor
There was a problem hiding this comment.
Pull request overview
Adds parser enforcement matching upstream TypeScript behavior by rejecting optional invocation of import.defer.
Changes:
- Detects optional and generic optional invocation forms.
- Adds diagnostic TS18062 and lookup mapping.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/parser/parser.go |
Reports invalid optional import.defer invocation. |
internal/diagnostics/diagnostics_generated.go |
Defines and maps TS18062. |
Files not reviewed (1)
- internal/diagnostics/diagnostics_generated.go: Generated file
Comment on lines
+5192
to
+5195
| if p.token == ast.KindQuestionDotToken && p.lookAhead(func(p *Parser) bool { | ||
| p.nextToken() | ||
| return p.token == ast.KindOpenParenToken || p.token == ast.KindLessThanToken | ||
| }) { |
Author
There was a problem hiding this comment.
Added conformance test covering both ?.() and ?.() forms,
with a valid import.defer('./x') control case. Baselines committed.
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 microsoft/TypeScript#63679
Problem
import.defer?.('x')produces no error in TypeScript, but allmajor parsers (Oxc, SWC, Babel, Acorn) reject it.
Fix
'import.defer' does not support optional invocationimmediately after import.defer is parsed
Test
Before:
import.defer?.('x'); // no error ❌
After:
import.defer?.('x');
// error TS18062: 'import.defer' does not support optional invocation ✅
Note
Fix was originally implemented in microsoft/TypeScript#63690
and ported here per maintainer guidance.