Repository navigation
Fix missing syntax errors for optional property access in plain JS - #64744
Open
MaheshDesu (mahesh-desu) wants to merge 1 commit into
Open
MaheshDesu (mahesh-desu) wants to merge 1 commit into
MaheshDesu (mahesh-desu) wants to merge 1 commit into
Conversation
Plain JS files filter checker diagnostics through an allowlist, so the grammar errors for optional property access in assignment positions (TS2777-TS2781) were silently dropped even though they are runtime SyntaxErrors. Add the five codes to the allowlist and extend the plainJSGrammarErrors conformance test to cover them. Fixes microsoft#57640. Signed-off-by: MaheshDesu <mahesh.desu3@gmail.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
TS2777 remains suppressed for optional-chain increments on nonnumeric properties.
1 open finding
What changed in this PR
Allows optional-chain assignment grammar diagnostics through plain-JavaScript filtering and adds regression baselines.
Changes:
- Adds five diagnostics to
plainJSErrors. - Tests invalid optional-chain assignment positions and valid controls.
- Updates generated diagnostic, emit, type, and symbol baselines.
| File | Description |
|---|---|
tsc/internal/compiler/program.go |
Allows optional-chain assignment diagnostics in plain JS. |
tsc/testdata/tests/cases/conformance/salsa/plainJSGrammarErrors.ts |
Adds regression cases and controls. |
tsc/testdata/baselines/reference/conformance/plainJSGrammarErrors.errors.txt |
Records expected diagnostics. |
tsc/testdata/baselines/reference/conformance/plainJSGrammarErrors.js |
Updates emit baseline. |
tsc/testdata/baselines/reference/conformance/plainJSGrammarErrors.types |
Updates type baseline. |
tsc/testdata/baselines/reference/conformance/plainJSGrammarErrors.symbols |
Updates symbol baseline. |
🧠 Review effort: Balanced
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 #57640.
In plain JS files (no
checkJs), TypeScript drops most checker diagnostics through theplainJSErrorsallowlist. Five grammar diagnostics that are runtimeSyntaxErrors for optional property access in assignment positions were not in that allowlist, sotscreported nothing for code that immediately fails in an engine:obj?.a++({ ...obj?.a } = {})obj?.a = 1for (obj?.a in {})for (obj?.a of [])Change: adds those five codes to
plainJSErrorsintsc/internal/compiler/program.go(5 lines), following the approach analyzed by Emanuel Hoogeveen (@ehoogeveen-medweb) in the issue.Tests: extends
conformance/salsa/plainJSGrammarErrorsto cover all five codes plus negative controls.Known limitations, inherited from how the checker produces these diagnostics (same behavior as
.tsfiles and classic TypeScript):stringorany; other types produce TS2405, a type error that remains filtered in plain JS. The test covers both thestringandanycases.obj?.a++on a nonnumeric property produces TS2356 instead, which likewise remains filtered. The test uses a numeric property.Fully closing these gaps requires grammar checking in JS files, which is a larger work item. The same class of gap exists for other invalid update targets in plain JS (e.g.
1++is silent because TS2357 is not allowlisted).Verified locally:
hereby build, fullhereby test/test:all(no new failures; only pre-existing symlink-privilege failures ininternal/fswatchon this Windows box),hereby lint,hereby format,hereby check:format,hereby generate(no diff), andgo mod tidy -difffor both modules.