diff --git a/crates/oxc_transformer/src/react/jsx/mod.rs b/crates/oxc_transformer/src/react/jsx/mod.rs index beae98cba..c8eaaf6c5 100644 --- a/crates/oxc_transformer/src/react/jsx/mod.rs +++ b/crates/oxc_transformer/src/react/jsx/mod.rs @@ -646,20 +646,18 @@ impl<'a> ReactJsx<'a> { let mut acc: Option = None; let mut first_non_whitespace: Option = Some(0); let mut last_non_whitespace: Option = None; - let mut i: usize = 0; - for c in text.chars() { + for (index, c) in text.char_indices() { if is_line_terminator(c) { if let (Some(first), Some(last)) = (first_non_whitespace, last_non_whitespace) { - acc = Some(Self::add_line_of_jsx_text(acc, &text[first..=last])); + acc = Some(Self::add_line_of_jsx_text(acc, &text[first..last])); } first_non_whitespace = None; } else if c != ' ' && !is_irregular_whitespace(c) { - last_non_whitespace = Some(i); + last_non_whitespace = Some(index + c.len_utf8()); if first_non_whitespace.is_none() { - first_non_whitespace.replace(i); + first_non_whitespace.replace(index); } } - i += c.len_utf8(); } if let Some(first) = first_non_whitespace { Some(Self::add_line_of_jsx_text(acc, &text[first..])) @@ -682,14 +680,14 @@ impl<'a> ReactJsx<'a> { /// Code adapted from fn decode_entities(s: &str) -> String { let mut buffer = vec![]; - let mut chars = s.bytes().enumerate(); + let mut chars = s.char_indices(); let mut prev = 0; while let Some((i, c)) = chars.next() { - if c == b'&' { + if c == '&' { let start = i; let mut end = None; for (j, c) in chars.by_ref() { - if c == b';' { + if c == ';' { end.replace(j); break; } diff --git a/tasks/transform_conformance/oxc.snap.md b/tasks/transform_conformance/oxc.snap.md index 99fcdd3ba..c31db523d 100644 --- a/tasks/transform_conformance/oxc.snap.md +++ b/tasks/transform_conformance/oxc.snap.md @@ -1,6 +1,6 @@ -Passed: 0/0 +Passed: 1/1 # All Passed: - +* babel-plugin-transform-react-jsx diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/options.json b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/options.json new file mode 100644 index 000000000..21e6dbde3 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["transform-react-jsx"]] +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/unicode/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/unicode/input.jsx new file mode 100644 index 000000000..1e33319d9 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/unicode/input.jsx @@ -0,0 +1,3 @@ +

+🏝️ +

diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/unicode/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/unicode/output.js new file mode 100644 index 000000000..92d5b28cb --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/unicode/output.js @@ -0,0 +1,4 @@ +import {jsx as _jsx} from 'react/jsx-runtime'; +_jsx('h2', { + children: '🏝️' +});