From 76ac9cd4c51fced2af362b05a4668661a9611636 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 22 Oct 2023 15:44:19 +0100 Subject: [PATCH] fix(lexer) Fix spans for jsx children (#1030) Closes #1026 --- crates/oxc_linter/src/snapshots/jsx_key.snap | 2 +- .../src/snapshots/jsx_no_useless_fragment.snap | 16 ++++++++-------- crates/oxc_parser/src/lexer/mod.rs | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/oxc_linter/src/snapshots/jsx_key.snap b/crates/oxc_linter/src/snapshots/jsx_key.snap index 0994066f9..3d814a8b8 100644 --- a/crates/oxc_linter/src/snapshots/jsx_key.snap +++ b/crates/oxc_linter/src/snapshots/jsx_key.snap @@ -95,7 +95,7 @@ expression: jsx_key ⚠ eslint-plugin-react(jsx-key): Missing "key" prop for element in iterator. ╭─[jsx_key.tsx:1:1] 1 │ [1, 2, 3]?.map(x => <>) - · ────────────────────────────────────────── + · ──────────────────── ╰──── ⚠ eslint-plugin-react(jsx-key): Missing "key" prop for element in iterator. diff --git a/crates/oxc_linter/src/snapshots/jsx_no_useless_fragment.snap b/crates/oxc_linter/src/snapshots/jsx_no_useless_fragment.snap index 201df1e67..1186ac67b 100644 --- a/crates/oxc_linter/src/snapshots/jsx_no_useless_fragment.snap +++ b/crates/oxc_linter/src/snapshots/jsx_no_useless_fragment.snap @@ -35,13 +35,13 @@ expression: jsx_no_useless_fragment ⚠ eslint-plugin-react(jsx-no-useless-fragment): Fragments should contain more than one child. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │

<>{meow}

- · ────────────── + · ─────────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │

<>{meow}

- · ────────────── + · ─────────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Fragments should contain more than one child. @@ -77,31 +77,31 @@ expression: jsx_no_useless_fragment ⚠ eslint-plugin-react(jsx-no-useless-fragment): Fragments should contain more than one child. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │ <>foo - · ────────────── + · ──────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Fragments should contain more than one child. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │
<>foo
- · ───────────── + · ──────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │
<>foo
- · ───────────── + · ──────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │
<>{"a"}{"b"}
- · ──────────────────── + · ─────────────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │
<>{"a"}{"b"}
- · ──────────────────── + · ─────────────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. @@ -115,7 +115,7 @@ expression: jsx_no_useless_fragment ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. ╭─[jsx_no_useless_fragment.tsx:1:1] 1 │
{"a"}{"b"}
- · ──────────────────────────────────── + · ─────────────────────────────── ╰──── ⚠ eslint-plugin-react(jsx-no-useless-fragment): Passing a fragment to a HTML element is useless. diff --git a/crates/oxc_parser/src/lexer/mod.rs b/crates/oxc_parser/src/lexer/mod.rs index 1631753cb..1d6f64f01 100644 --- a/crates/oxc_parser/src/lexer/mod.rs +++ b/crates/oxc_parser/src/lexer/mod.rs @@ -164,6 +164,7 @@ impl<'a> Lexer<'a> { } pub fn next_jsx_child(&mut self) -> Token<'a> { + self.current.token.start = self.offset(); let kind = self.read_jsx_child(); self.finish_next(kind) }