mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 21:29:01 +00:00
chore(parser): make sure all span.end >= span.start (#2681)
closes #2679
This commit is contained in:
parent
75ae563dbc
commit
8a73d18fcf
5 changed files with 17 additions and 12 deletions
|
|
@ -27,6 +27,7 @@ impl<'a> ParserImpl<'a> {
|
|||
#[inline]
|
||||
pub(crate) fn end_span(&self, mut span: Span) -> Span {
|
||||
span.end = self.prev_token_end;
|
||||
debug_assert!(span.end >= span.start);
|
||||
span
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ impl<'a> SeparatedList<'a> for ObjectExpressionProperties<'a> {
|
|||
}?;
|
||||
|
||||
if p.at(Kind::Comma) && p.peek_at(self.close()) {
|
||||
self.trailing_comma = Some(p.end_span(p.start_span()));
|
||||
let span = p.start_span();
|
||||
p.bump_any();
|
||||
self.trailing_comma = Some(p.end_span(span));
|
||||
}
|
||||
|
||||
self.elements.push(element);
|
||||
|
|
@ -121,7 +123,9 @@ impl<'a> SeparatedList<'a> for ArrayExpressionList<'a> {
|
|||
};
|
||||
|
||||
if p.at(Kind::Comma) && p.peek_at(self.close()) {
|
||||
self.trailing_comma = Some(p.end_span(p.start_span()));
|
||||
let span = p.start_span();
|
||||
p.bump_any();
|
||||
self.trailing_comma = Some(p.end_span(span));
|
||||
}
|
||||
|
||||
self.elements.push(element?);
|
||||
|
|
|
|||
|
|
@ -2214,19 +2214,19 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
|
|||
× Unexpected trailing comma after rest element
|
||||
╭─[es2015/array-rest-spread/comma-after-rest/input.js:1:6]
|
||||
1 │ [...a,] = [];
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected trailing comma after rest element
|
||||
╭─[es2015/array-rest-spread/comma-after-spread-for-in/input.js:1:11]
|
||||
1 │ for ([...a,] in []);
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected trailing comma after rest element
|
||||
╭─[es2015/array-rest-spread/comma-after-spread-nested/input.js:1:7]
|
||||
1 │ [[...a,]] = [];
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Spread must be last element
|
||||
|
|
|
|||
|
|
@ -2423,7 +2423,7 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
|||
╭─[language/expressions/assignment/dstr/array-rest-before-elision.js:23:9]
|
||||
22 │
|
||||
23 │ 0, [...x,] = [];
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Spread must be last element
|
||||
|
|
@ -2437,7 +2437,7 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
|||
╭─[language/expressions/assignment/dstr/array-rest-elision-invalid.js:23:9]
|
||||
22 │
|
||||
23 │ 0, [...x,] = [];
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Cannot assign to this expression
|
||||
|
|
@ -30252,7 +30252,7 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
|||
╭─[language/statements/for-in/dstr/array-rest-before-elision.js:32:11]
|
||||
31 │
|
||||
32 │ for ([...x,] in [[]]) ;
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected token
|
||||
|
|
@ -30266,7 +30266,7 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
|||
╭─[language/statements/for-in/dstr/array-rest-elision-invalid.js:32:11]
|
||||
31 │
|
||||
32 │ for ([...x,] in [[]]) ;
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected token
|
||||
|
|
@ -30758,7 +30758,7 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
|||
╭─[language/statements/for-of/dstr/array-rest-before-elision.js:32:11]
|
||||
31 │
|
||||
32 │ for ([...x,] of [[]]) ;
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected token
|
||||
|
|
@ -30772,7 +30772,7 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
|||
╭─[language/statements/for-of/dstr/array-rest-elision-invalid.js:32:11]
|
||||
31 │
|
||||
32 │ for ([...x,] of [[]]) ;
|
||||
· ▲
|
||||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected token
|
||||
|
|
|
|||
|
|
@ -15205,7 +15205,7 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
|
|||
╭─[conformance/es7/trailingCommasInBindingPatterns.ts:4:7]
|
||||
3 │ let c, d;
|
||||
4 │ ([...c,] = []);
|
||||
· ▲
|
||||
· ─
|
||||
5 │ ({...d,} = {});
|
||||
╰────
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue