Skip to content

Reject unary exponentiation operands hidden by assertions - #65323

Merged
Ryan Cavanaugh (RyanCavanaugh) merged 4 commits into
mainfrom
copilot/fix-invalid-left-operand-exponentiation
Nov 5, 2026
Merged

Ryan Cavanaugh (RyanCavanaugh) merged 4 commits into
mainfrom
copilot/fix-invalid-left-operand-exponentiation

Conversation

Copilot AI commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #65170

Analysis

Erasing as or satisfies can expose an unparenthesized unary or await expression as the left operand of **, producing invalid JavaScript.

Fix

  • Parser: Extend the existing erasure-precedence guard to reject these forms regardless of erasableSyntaxOnly. Preserve explicitly parenthesized operands and update expressions.
  • Coverage: Exercise every unary operator, await, mixed assertion chains, and legal boundaries with erasableSyntaxOnly enabled and disabled.
-x as number ** 2;   // Error
(-x) as number ** 2; // OK

Copilot Checklist

I successfully ran the applicable command at the end of my session, and it completed without error:

  • npx hereby validate
  • npx hereby validate --api (for TypeScript API changes)

@typescript-automation typescript-automation Bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Nov 4, 2026
Copilot AI linked an issue Nov 4, 2026 that may be closed by this pull request
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Nov 4, 2026
Copilot AI and others added 2 commits November 4, 2026 20:02
…rands

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid left operand exposure with as and satisfies Reject unary exponentiation operands hidden by assertions Nov 4, 2026
@RyanCavanaugh

Copy link
Copy Markdown
Member

Copilot ; expected is an unsatisfactory error message here, we should be issuing the same error for -n as any ** 2 as if you had written -n ** 2

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>

Copilot AI commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Copilot ; expected is an unsatisfactory error message here, we should be issuing the same error for -n as any ** 2 as if you had written -n ** 2

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. npx hereby validate passed.

@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as ready for review November 4, 2026 21:44
Copilot AI balanced review requested due to automatic review settings November 4, 2026 21:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 erasableSyntaxOnly settings.
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

@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit c46bcd6 Nov 5, 2026
35 checks passed
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) deleted the copilot/fix-invalid-left-operand-exponentiation branch November 5, 2026 01:15
CPunisher pushed a commit to swc-project/swc-next that referenced this pull request Nov 5, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Erasing as or satisfies can expose an invalid left operand of **

4 participants