Skip to content

fix(parser): validate TS named tuple rest elements - #26419

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-named-tuple-rest-validation
Sep 7, 2026
Merged

graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-named-tuple-rest-validation

Conversation

@camc314

@camc314 camc314 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Named tuple rest elements bypass the parser's existing checks for optional elements after an array rest and for multiple array rests. For example, both of these declarations currently parse successfully even though TypeScript rejects them:

type OptionalAfterRest = [...a: string[], b?: number];
type RestAfterRest = [...a: string[], ...b: number[]];

The equivalent unnamed forms already produce TS1266 and TS1265, respectively. Mixed named and unnamed array rests have the same gap when either rest is named.

Cause and change

parse_tuple_type inspects TSRestType.type_annotation to decide whether an element is an array rest. For a named element, that annotation is a TSNamedTupleMember, and the actual type is stored in its element_type. Matching directly on the outer annotation therefore skips the array check and fails to track the rest element.

Unwrap the named member with as_ts_type() before applying the existing classification. Named and unnamed elements then share the same validation and existing diagnostics:

  • An optional element after an array rest reports TS1266.
  • A second array rest reports TS1265, including mixed named and unnamed forms.

The diagnostic spans continue to use the complete tuple elements, including their labels. The change borrows the underlying type without changing the AST representation or introducing allocations.

Preserved behavior

A rest marker alone does not make a spread an unbounded array. Fixed-tuple and generic variadic spreads continue to be accepted, including:

type FixedBeforeOptional = [...a: [string], b?: number];
type RestBeforeFixed = [...a: string[], ...b: [number]];
type VariadicBeforeOptional<T extends unknown[]> = [...a: T, b?: number];
type RestBeforeVariadic<T extends unknown[]> = [...a: string[], ...b: T];
type MultipleVariadic<T extends unknown[], U extends unknown[]> = [...a: T, ...b: U];

This change preserves the existing type-reference classification; it does not add type resolution or change how shadowed Array references are handled.

Copilot AI lite review requested due to automatic review settings September 7, 2026 17:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-07T17:28:55.346098Z 277732b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

The parser change is narrowly scoped, matches the stated root cause (named-member wrapping), and is backed by new pass/fail coverage plus updated snapshots demonstrating the intended TS1265/TS1266 diagnostics.

Pull request overview

This PR fixes a TypeScript tuple-type validation gap in oxc_parser where named tuple rest elements (...a: string[]) were not being recognized as “array rest” elements, causing the parser to miss existing TS1265/TS1266 validations that already applied to unnamed rests.

Changes:

  • Update parse_tuple_type to unwrap TSNamedTupleMember and classify the underlying element_type when determining whether a rest element is an array rest.
  • Add new misc/pass and misc/fail coverage cases for named tuple rest interactions (optional-after-rest, rest-after-rest, and mixed named/unnamed).
  • Update coverage snapshots to reflect the new test files and expected diagnostics.
File summaries
File Description
crates/oxc_parser/src/ts/types.rs Fixes rest-element classification by unwrapping TSNamedTupleMember.element_type before applying the existing “array rest” checks.
tasks/coverage/misc/pass/tuple-named-rest.ts Adds passing cases ensuring fixed-tuple and variadic spreads remain accepted with named elements.
tasks/coverage/misc/fail/tuple-named-rest.ts Adds failing cases that must now report TS1265/TS1266 for named/mixed rest scenarios.
tasks/coverage/snapshots/parser_misc.snap Records the new expected TS1265/TS1266 diagnostics for the added failing cases.
tasks/coverage/snapshots/lexer_misc.snap Updates misc snapshot counts due to new test files.
tasks/coverage/snapshots/semantic_misc.snap Updates misc snapshot counts due to new test files.
tasks/coverage/snapshots/transformer_misc.snap Updates misc snapshot counts due to new test files.
tasks/coverage/snapshots/formatter_misc.snap Updates misc snapshot counts due to new test files.
tasks/coverage/snapshots/codegen_misc.snap Updates misc snapshot counts due to new test files.
Review details
  • Files reviewed: 1/9 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@camc314
camc314 force-pushed the codex/fix-named-tuple-rest-validation branch from 6eed02c to 277732b Compare September 7, 2026 17:24
@github-actions github-actions Bot added the A-parser Area - JS/TS parsing and syntax errors, oxc_parser label Sep 7, 2026
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Sep 7, 2026
@camc314 camc314 changed the title fix(parser): validate named tuple rest elements fix(parser): validate TS named tuple rest elements Sep 7, 2026
@camc314 camc314 self-assigned this Sep 7, 2026
@codspeed

codspeed Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 72 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing codex/fix-named-tuple-rest-validation (277732b) with main (ae6c386)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

camc314 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge activity

## Problem

Named tuple rest elements bypass the parser's existing checks for optional elements after an array rest and for multiple array rests. For example, both of these declarations currently parse successfully even though TypeScript rejects them:

```ts
type OptionalAfterRest = [...a: string[], b?: number];
type RestAfterRest = [...a: string[], ...b: number[]];
```

The equivalent unnamed forms already produce TS1266 and TS1265, respectively. Mixed named and unnamed array rests have the same gap when either rest is named.

## Cause and change

`parse_tuple_type` inspects `TSRestType.type_annotation` to decide whether an element is an array rest. For a named element, that annotation is a `TSNamedTupleMember`, and the actual type is stored in its `element_type`. Matching directly on the outer annotation therefore skips the array check and fails to track the rest element.

Unwrap the named member with `as_ts_type()` before applying the existing classification. Named and unnamed elements then share the same validation and existing diagnostics:

- An optional element after an array rest reports TS1266.
- A second array rest reports TS1265, including mixed named and unnamed forms.

The diagnostic spans continue to use the complete tuple elements, including their labels. The change borrows the underlying type without changing the AST representation or introducing allocations.

## Preserved behavior

A rest marker alone does not make a spread an unbounded array. Fixed-tuple and generic variadic spreads continue to be accepted, including:

```ts
type FixedBeforeOptional = [...a: [string], b?: number];
type RestBeforeFixed = [...a: string[], ...b: [number]];
type VariadicBeforeOptional<T extends unknown[]> = [...a: T, b?: number];
type RestBeforeVariadic<T extends unknown[]> = [...a: string[], ...b: T];
type MultipleVariadic<T extends unknown[], U extends unknown[]> = [...a: T, ...b: U];
```

This change preserves the existing type-reference classification; it does not add type resolution or change how shadowed `Array` references are handled.
@graphite-app
graphite-app Bot force-pushed the codex/fix-named-tuple-rest-validation branch from 277732b to d61e3bf Compare September 7, 2026 17:43
@graphite-app
graphite-app Bot merged commit d61e3bf into main Sep 7, 2026
34 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Sep 7, 2026
@graphite-app
graphite-app Bot deleted the codex/fix-named-tuple-rest-validation branch September 7, 2026 17:47
graphite-app Bot pushed a commit that referenced this pull request Sep 14, 2026
### 🚀 Features

- ca649e0 ecma: Define math constants as known globals and resolve their types (#26585) (Armano)
- 9ef028c codegen: Add `ascii_only` option (#25994) (Samuel Attard)
- 80a76a0 minifier: Negate binary comparison for `typeof x < 'u'` (#26367) (Armano)

### 🐛 Bug Fixes

- 8ca76da parser: Reject `accessor` modifiers on methods (#26617) (camc314)
- 1916f31 parser: Reject `readonly` modifier on constructors (#26612) (camc314)
- 1c42008 parser: Handle escaped let in for loops (#26583) (camc314)
- d21d5cf parser: Recognize annotated empty arrows in conditionals (#26537) (camc314)
- d7713ad parser: Classify Unicode line breaks in block comments (#26536) (camc314)
- 75cd919 transformer: Preserve receivers in private optional chains (#26535) (camc314)
- b32d25d parser: Reject escaped import-phase keywords (#26534) (camc314)
- 47b8311 parser: Recognize contextual binding names in type lookaheads (#26532) (camc314)
- d6b6705 parser: Require arrow separator in TypeScript function types (#26529) (camc314)
- e98beef parser: Disambiguate await using in for initializers (#26527) (camc314)
- 92afee6 parser: Allow parenthesized JSX comma expressions with preserve_parens=false (#26524) (camc314)
- 31508b1 parser: Reject return types on constructor overloads (#26523) (camc314)
- a091fc4 parser: Validate await context for await using declarations (#26495) (camc314)
- 5501e86 parser: Disallow in expressions in using for-loop initializers (#26490) (camc314)
- c8e5fa7 parser: Allow escaped type names in import and export specifiers (#26487) (camc314)
- 2dcee2f parser: Reject async modifiers on class fields (#26486) (camc314)
- 973d58e parser: Require comma after TypeScript this parameter (#26480) (camc314)
- 32d00c5 codegen: Preserve instantiation expression precedence (#26424) (camc314)
- cfa47ab parser: Allow `in` expressions in class static blocks (#26423) (camc314)
- 5986187 packages/codegen: Preserve private-in right operand precedence (#26420) (camc314)
- f8e6c6c packages/codegen: Preserve in restriction through yield arguments (#26421) (camc314)
- d61e3bf parser: Validate TS named tuple rest elements (#26419) (camc314)
- ae6c386 codegen: Preserve in restriction through yield arguments (#26413) (camc314)
- 42ac916 codegen: Preserve private-in right operand precedence (#26411) (camc314)
- 10521b2 parser: Allow escaped type default import bindings (#26409) (camc314)
- 72cb5e3 parser: Reject rest parameters in getters (#26400) (camc314)
- 6e15ad5 packages/codegen: Print matching quoted import names as identifiers (#26404) (camc314)
- bbbb4bc packages/codegen: Preserve private-in left operand precedence (#26403) (camc314)
- a111b5b packages/codegen: Print accessibility modifiers before abstract (#26402) (camc314)
- 4e76602 parser: Allow `in` in arrow block bodies within `for` initializers (#26395) (camc314)
- b20fc19 parser: Reject partially parenthesized mixed coalesce expressions (#26394) (camc314)

### ⚡ Performance

- 1f902a6 isolated_declarations: Key scope maps by `Ident` (#26380) (Dunqing)
- a242469 minfiier: Reduce allocs when creating indirect access (#26601) (Armano)
- 5b4787f minifier: Update chain expressions in place (#26544) (Armano)
- 0bc1661 minifier: Try merging before creating new expression statements (#26556) (Armano)
- c78d707 minifier: Process newly created stmt in handle_if_statement (#26541) (Armano)
- 029c84b minfier: Update expressions in place when substituting alternate syntax (#26460) (Armano)
- d198982 codegen: Outline postfix source mapping work (#26450) (camc314)
- 53f006e ecmascript: Format small integer literals with itoa (#26446) (camc314)
- 8bfb8c0 codegen: Avoid duplicate sourcemap name lookups (#26441) (camc314)

### 📚 Documentation

- 38533ac ast: Move type annotation span comment to span field (#26522) (camc314)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - JS/TS parsing and syntax errors, oxc_parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants