Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ pub fn rest_element_cannot_follow_another_rest_element(
.with_labels([span.label("Second rest element here"), seen_span.label("First seen here")])
}

/// An optional element cannot follow a rest element. ts(1266)
#[cold]
pub fn optional_element_cannot_follow_rest_element(span: Span, rest_span: Span) -> OxcDiagnostic {
ts_error("1266", "An optional element cannot follow a rest element.").with_labels([
span.label("Optional element here"),
rest_span.label("Rest element seen here"),
])
}

// A type-only import can specify a default import or named bindings, but not both. ts(1363)
#[cold]
pub fn type_only_import_default_and_named(specifier_span: Span) -> OxcDiagnostic {
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,15 @@ impl<'a> ParserImpl<'a> {
}
seen_type_span = Some(tuple.span());
}

if let Some(seen_rest_span) = seen_type_span
&& matches!(tuple, TSTupleElement::TSOptionalType(_))
{
me.error(diagnostics::optional_element_cannot_follow_rest_element(
tuple.span(),
seen_rest_span,
));
}
tuple
});
self.expect(Kind::RBrack);
Expand Down
10 changes: 10 additions & 0 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26514,6 +26514,16 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/statements/Va
8 │ type V11 = [number, ...string[], boolean?]; // Error
╰────

× TS(1266): An optional element cannot follow a rest element.
╭─[typescript/tests/cases/conformance/types/tuple/variadicTuples2.ts:8:21]
7 │ type V10 = [number, ...string[], ...boolean[]]; // Error
8 │ type V11 = [number, ...string[], boolean?]; // Error
· ─────┬───── ────┬───
· │ ╰── Optional element here
· ╰── Rest element seen here
9 │ type V12 = [number, string?, boolean]; // Error
╰────

× TS(1265): A rest element cannot follow another rest element.
╭─[typescript/tests/cases/conformance/types/tuple/variadicTuples2.ts:11:13]
10 │
Expand Down
Loading