Repository navigation
Reject unary exponentiation operands hidden by assertions - #65323
Ryan Cavanaugh (RyanCavanaugh) merged 4 commits into
Conversation
…rands Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
as and satisfies|
Copilot |
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Addressed in b64beb2. Bare and assertion-wrapped operands now share the TS17006 reporter, including the operator name and original operand span; type assertions use TS17007. Added matching bare-form controls and recovery coverage. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change extending exponentiation operand checks through TypeScript assertions.
No open issues 🎉
What changed in this PR
Addresses #65170 by extending the native TypeScript parser’s exponentiation checks to reject unary and await operands hidden by as or satisfies, regardless of erasableSyntaxOnly.
Changes:
- Detects invalid left operands across assertion chains and reuses a shared diagnostic helper.
- Preserves valid parenthesized operands, update expressions, and unary right operands.
- Adds regression coverage and diagnostic baselines for both
erasableSyntaxOnlysettings.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts |
Covers invalid assertion-wrapped operands and valid boundaries. |
tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt |
Records expected diagnostics with erasure-only syntax enabled. |
tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt |
Records expected diagnostics with erasure-only syntax disabled. |
tsc/internal/parser/parser.go |
Extends operand validation and extracts shared diagnostic reporting. |
Review effort: Balanced
…1490) ## Motivation Erasing `as` or `satisfies` can expose an invalid unary or `await` operand on the left of `**` without a parser diagnostic. ## Changes Check `**` left operands after unwrapping `as` and `satisfies` chains. Use the same diagnostic path for bare unary, await, and type assertion operands. Preserve the existing recovery AST and accept parenthesized and update expressions. ## Related Links - Close #1016 - microsoft/TypeScript#65323
Fixes #65170
Analysis
Erasing
asorsatisfiescan expose an unparenthesized unary orawaitexpression as the left operand of**, producing invalid JavaScript.Fix
erasableSyntaxOnly. Preserve explicitly parenthesized operands and update expressions.await, mixed assertion chains, and legal boundaries witherasableSyntaxOnlyenabled and disabled.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error:
asorsatisfiescan expose an invalid left operand of**#65170