Disallow optional calls on import.defer - #64074
Disallow optional calls on import.defer#64074KIM HYEONSANG (HyeonsangKim) wants to merge 1 commit into
Conversation
|
KIM HYEONSANG (@HyeonsangKim) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Disallows optional-call syntax on import.defer while preserving standard deferred imports.
Changes:
- Adds parser diagnostics for ordinary and generic optional calls.
- Adds conformance coverage and generated baselines.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tsc/internal/parser/parser.go |
Rejects optional import.defer calls. |
tsc/testdata/tests/cases/conformance/importDefer/importDeferOptionalCall.ts |
Adds conformance cases. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalCall.errors.txt |
Captures diagnostics. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalCall.js |
Captures emitted JavaScript. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalCall.types |
Captures inferred types. |
tsc/testdata/baselines/reference/conformance/importDeferOptionalCall.symbols |
Captures symbol resolution. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| if p.token == ast.KindQuestionDotToken && p.lookAhead((*Parser).nextTokenIsOpenParenOrLessThan) { | ||
| p.parseErrorAtCurrentToken(diagnostics.X_0_expected, scanner.TokenToString(ast.KindOpenParenToken)) | ||
| } |
Fixes #63679
Summary
import.defer?.(...).import.defer?.<T>(...)as well.import.defer(...)calls and add conformance baselines for all three cases.The parser reuses the existing
TS1005: '(' expecteddiagnostic. This matches the current diagnostics for other invalid standalone uses ofimport.deferand avoids adding a new public diagnostic for the same grammar requirement.Tests
go -C ./tsc test -count=1 -run='TestLocal/importDeferOptionalCall' ./internal/testrunnernpx hereby generatenpx hereby buildnpx hereby testnpx hereby test:allnpx hereby lintnpx hereby check:formatnpm run -w @typescript/typescript buildnpm run -w @typescript/typescript testnpm run -w native-preview buildgo -C ./tsc mod tidy -diffgo -C ./tools mod tidy -diffgo work syncThe full suite was also rerun with Node.js 24 LTS.
Prior work
This incorporates the syntax coverage identified in #63690 and microsoft/typescript-go#4794. Those PRs were closed during the TypeScript/Go repository transition rather than because the parser direction was rejected.
AI assistance disclosure
I used Codex to help implement and validate this patch. I selected this specific issue, reviewed and understand the parser change and generated baselines, and will personally respond to review feedback and revise the change as needed.