fix(parser): disallow optional chaining on import.defer - #63690
fix(parser): disallow optional chaining on import.defer#63690BhariGowda wants to merge 2 commits into
Conversation
) - Add diagnostic TS18062: 'import.defer' does not support optional invocation - Report error when '?.' follows 'import.defer' in parser - Add conformance test importDeferOptionalCall.ts with baselines Fixes microsoft#63679
There was a problem hiding this comment.
Pull request overview
This PR tightens the parser’s handling of the import.defer meta-property by rejecting optional chaining invocation syntax (import.defer?.(...)) and adds a conformance test/baselines to lock in the new diagnostic behavior.
Changes:
- Add a new diagnostic (TS18062) for optional invocation on
import.defer. - Update the parser to detect
?.immediately after parsingimport.deferand report TS18062. - Add a conformance test and reference baselines for the new error.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/parser.ts | Adds a parser check to error on QuestionDotToken following import.defer. |
| src/compiler/diagnosticMessages.json | Introduces TS18062 message text and code assignment. |
| tests/cases/conformance/importDefer/importDeferOptionalCall.ts | New conformance test for import.defer?.('x'). |
| tests/baselines/reference/importDeferOptionalCall.errors.txt | Baseline showing TS18062 (and current additional TS2307). |
| tests/baselines/reference/importDeferOptionalCall.types | Type baseline for the test input. |
| tests/baselines/reference/importDeferOptionalCall.symbols | Symbols baseline for the test input. |
| tests/baselines/reference/importDeferOptionalCall.js | JS emit baseline for the test input. |
| // @target: es2015 | ||
| // @module: esnext | ||
| // @filename: b.ts | ||
| import.defer?.('x'); |
There was a problem hiding this comment.
Fixed in the second commit added x.ts as a separate filename
section and used a relative specifier './x' to avoid TS2307 noise.
There was a problem hiding this comment.
Fixed in the second commit narrowed the check to only fire when
'?.' is followed by '(' or '<' (invocation only), so import.defer?.prop
and import.defer?.[0] are not affected.
|
@microsoft-github-policy-service agree |
|
@BhariGowda You implemented the change in the wrong repository. See: https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md |
|
Thanks for the heads up! I've filed microsoft/typescript-go#4789 |
|
Reopening microsoft/typescript-go#4789 was closed by a maintainer |
|
Issues are tracked here. Pull requests are done in the TypeScript-Go repository, because it contains the new codebase. TypeScript 7.0 is no longer written in TypeScript / JavaScript. |
|
Understood, closing this and will submit the fix to microsoft/typescript-go. Thanks for the clarification! |
Fixes #63679
Problem
import.defer?.('x')was not producing an error in TypeScript,even though all major parsers (Oxc, SWC, Babel, Acorn) reject it.
Fix
'import.defer' does not support optional invocationparser.tsforQuestionDotTokenimmediatelyafter
import.deferis parsedTest
Before fix:
import.defer?.('x'); // no error ❌
After fix:
import.defer?.('x');
// error TS18062: 'import.defer' does not support optional invocation ✅