Fix: disallow optional call chaining on import.defer expressions (#63679) - #64199
Fix: disallow optional call chaining on import.defer expressions (#63679)#64199Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
Conversation
| return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node16_node18_node20_or_nodenext); | ||
| } | ||
|
|
||
| if (node.typeArguments) { |
There was a problem hiding this comment.
Your agent is very confused, these are test fixtures, not files to update
61992cf to
cd3cb06
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The implementation and regression coverage are consistent, with no unresolved issues.
Pull request overview
Disallows optional call chaining on import.defer expressions and adds regression coverage.
Changes:
- Detects and rejects
import.defer?.(...)with TS1326. - Updates parser and checker fixtures.
- Adds conformance tests and expected baselines.
File summaries
| File | Description |
|---|---|
tsc/testdata/tests/cases/conformance/importDefer/importDeferOptionalChain.ts |
Adds the regression test. |
tsc/testdata/fixtures/compiler/parser.ts |
Updates parser fixture behavior. |
tsc/testdata/fixtures/compiler/checker.ts |
Updates checker fixture behavior. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.types |
Captures expected types. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.symbols |
Captures expected symbols. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.js |
Captures expected emit. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.errors.txt |
Captures expected diagnostics. |
tsc/internal/parser/parser.go |
Flags optional deferred imports for grammar checking. |
tsc/internal/checker/grammarchecks.go |
Reports TS1326 for optional import calls. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
@microsoft-github-policy-service agree |
|
Thanks Jake Bailey (@jakebailey)! Apologies for the confusion regarding the test fixtures — I have reverted all changes under |
| if nodeAsCall.TypeArguments != nil || nodeAsCall.QuestionDotToken != nil { | ||
| return c.grammarErrorOnNode(node, diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments) |
There was a problem hiding this comment.
We should issue a different error message here.
Fixes #63679.
Problem
import.defer(part of TC39 Stage 3 Deferred Import Evaluation proposal) is a syntactic call construct, not a function reference. Previously, optional call chaining syntax likeimport.defer?.('x')was accepted without grammar errors during parsing and type checking.Solution
checkGrammarImportCallExpressionto check for non-nilQuestionDotToken(?.) and emit errorTS1326(This use of 'import' is invalid...).import.deferwhen followed by?.to ensure dynamic import statements with optional chaining are visited and grammar-checked.importDeferOptionalChain.tsand reference baselines.AI Disclosure: This patch was developed with AI assistance using Google Antigravity. I have reviewed, tested, and verified the implementation and baselines, and will shepherd this PR through review.