From 2a0ebec0f5e51d5cba1c1981215a893834c63255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 29 Jun 2024 18:24:51 +0900 Subject: [PATCH] fix(es/lexer): Fix lexing of `\r\n` in JSX (#9112) **Description:** I made a mistake while working on the performance of the lexer. **Related issue:** - Closes #9106 --- .../tests/fixture/next-36251/output.tsx | 2 - crates/swc_ecma_parser/src/lexer/jsx.rs | 33 ++++--- crates/swc_ecma_parser/src/lexer/tests.rs | 96 ++++++++++++++++--- crates/swc_ecma_parser/src/parser/jsx.rs | 7 +- crates/swc_ecma_parser/src/token.rs | 19 ++-- .../tests/jsx/basic/7/input.js.json | 4 +- .../basic/custom/unary-paren/input.js.json | 12 +-- .../jsx/basic/custom/unary/input.js.json | 12 +-- .../tests/jsx/basic/entity/input.js.json | 2 +- .../tests/jsx/basic/fragment-3/input.js.json | 16 ++-- .../tests/jsx/basic/fragment-4/input.js.json | 20 ++-- .../tests/jsx/basic/fragment-5/input.js.json | 12 +-- .../tests/jsx/basic/issue-2264/input.js.json | 4 +- .../tests/jsx/basic/issue-6522/input.js.json | 12 +-- .../custom/tsx-unary-paren/input.tsx.json | 8 +- .../custom/tsx-unary/input.tsx.json | 12 +-- .../issue-1446/case1/input.tsx.json | 2 +- .../issue-1446/case2/input.tsx.json | 8 +- .../issue-2237/case1/input.tsx.json | 8 +- .../issue-2237/case2/input.tsx.json | 8 +- .../issue-2264/case2/input.tsx.json | 4 +- .../typescript/issue-4296/1/input.tsx.json | 8 +- .../typescript/issue-7224/1/input.tsx.json | 8 +- .../vercel/next/server/render/1/output.js | 20 ---- .../tests.rs/dont_consider_require_as_hoc.js | 6 -- .../tests/fixture/issue-6923/output.js | 3 - .../tests/fixture/next-45561/1/output.js | 3 - .../tests/fixture/next-45561/2/output.js | 5 - .../fixture/next/server/render/1/output.js | 20 ---- 29 files changed, 195 insertions(+), 179 deletions(-) diff --git a/crates/swc_ecma_codegen/tests/fixture/next-36251/output.tsx b/crates/swc_ecma_codegen/tests/fixture/next-36251/output.tsx index f4d2caa7570d..f741b7c2b216 100644 --- a/crates/swc_ecma_codegen/tests/fixture/next-36251/output.tsx +++ b/crates/swc_ecma_codegen/tests/fixture/next-36251/output.tsx @@ -4,8 +4,6 @@ type ü = { }; export const SomeComponent = ({ name, value }: ü)=>{ return (
- {name} {value} -
); }; diff --git a/crates/swc_ecma_parser/src/lexer/jsx.rs b/crates/swc_ecma_parser/src/lexer/jsx.rs index 3d3e5473c12d..5a35ff9f0344 100644 --- a/crates/swc_ecma_parser/src/lexer/jsx.rs +++ b/crates/swc_ecma_parser/src/lexer/jsx.rs @@ -7,8 +7,9 @@ impl<'a> Lexer<'a> { pub(super) fn read_jsx_token(&mut self) -> LexResult> { debug_assert!(self.syntax.jsx()); + let start = self.input.cur_pos(); let mut chunk_start = self.input.cur_pos(); - let mut out = String::new(); + let mut value = String::new(); loop { let cur = match self.input.cur() { @@ -42,22 +43,30 @@ impl<'a> Lexer<'a> { return self.read_token(); } - let raw = if out.is_empty() { - // Fast path: We don't need to allocate + let value = if value.is_empty() { + // Fast path: We don't need to allocate extra buffer for value let s = unsafe { // Safety: We already checked for the range self.input.slice(chunk_start, cur_pos) }; self.atoms.atom(s) } else { - out.push_str(unsafe { + value.push_str(unsafe { // Safety: We already checked for the range self.input.slice(chunk_start, cur_pos) }); - self.atoms.atom(out) + self.atoms.atom(value) + }; + + let raw = { + let s = unsafe { + // Safety: We already checked for the range + self.input.slice(start, cur_pos) + }; + self.atoms.atom(s) }; - return Ok(Some(Token::JSXText { raw })); + return Ok(Some(Token::JSXText { raw, value })); } '>' => { self.emit_error( @@ -84,28 +93,28 @@ impl<'a> Lexer<'a> { } } '&' => { - out.push_str(unsafe { + value.push_str(unsafe { // Safety: We already checked for the range self.input.slice(chunk_start, cur_pos) }); let jsx_entity = self.read_jsx_entity()?; - out.push(jsx_entity.0); + value.push(jsx_entity.0); chunk_start = self.input.cur_pos(); } _ => { if cur.is_line_terminator() { - out.push_str(unsafe { + value.push_str(unsafe { // Safety: We already checked for the range self.input.slice(chunk_start, cur_pos) }); match self.read_jsx_new_line(true)? { - Either::Left(s) => out.push_str(s), - Either::Right(c) => out.push(c), + Either::Left(s) => value.push_str(s), + Either::Right(c) => value.push(c), } - chunk_start = cur_pos; + chunk_start = self.input.cur_pos(); } else { unsafe { // Safety: cur() was Some(c) diff --git a/crates/swc_ecma_parser/src/lexer/tests.rs b/crates/swc_ecma_parser/src/lexer/tests.rs index f37dc8502517..90732386fb39 100644 --- a/crates/swc_ecma_parser/src/lexer/tests.rs +++ b/crates/swc_ecma_parser/src/lexer/tests.rs @@ -1021,7 +1021,10 @@ fn jsx_02() { Token::JSXTagStart, Token::JSXName { name: "a".into() }, Token::JSXTagEnd, - Token::JSXText { raw: "foo".into() }, + Token::JSXText { + raw: "foo".into(), + value: "foo".into() + }, Token::JSXTagStart, tok!('/'), Token::JSXName { name: "a".into() }, @@ -1205,7 +1208,10 @@ fn issue_299_01() { raw: "'\\ '".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1239,7 +1245,10 @@ fn issue_299_02() { raw: "'\\\\'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1273,7 +1282,10 @@ fn jsx_string_1() { raw: "'abc'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1307,7 +1319,10 @@ fn jsx_string_2() { raw: "\"abc\"".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1341,7 +1356,10 @@ fn jsx_string_3() { raw: "'\n'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1375,7 +1393,10 @@ fn jsx_string_4() { raw: "'³'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1409,7 +1430,10 @@ fn jsx_string_5() { raw: "'*'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1443,7 +1467,10 @@ fn jsx_string_6() { raw: "'#'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1477,7 +1504,10 @@ fn jsx_string_7() { raw: "'&'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1511,7 +1541,10 @@ fn jsx_string_8() { raw: "'&;'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1545,7 +1578,10 @@ fn jsx_string_9() { raw: "'&&'".into(), }, Token::JSXTagEnd, - JSXText { raw: "ABC".into() }, + JSXText { + raw: "ABC".into(), + value: "ABC".into() + }, JSXTagStart, tok!('/'), JSXName { @@ -1599,7 +1635,10 @@ fn issue_481() { name: "span".into() }, Token::JSXTagEnd, - JSXText { raw: " ".into() }, + JSXText { + raw: " ".into(), + value: " ".into() + }, LBrace, Word(Word::Ident("foo".into())), RBrace, @@ -2159,3 +2198,34 @@ class C { assert_eq!(errors.len(), 4); assert!(errors.iter().all(|e| e.kind() == &SyntaxError::TS1185)); } + +#[test] +fn issue_9106() { + assert_eq!( + lex_tokens( + crate::Syntax::Es(crate::EsSyntax { + jsx: true, + ..Default::default() + }), + "\n\r\nABC;" + ), + vec![ + Token::JSXTagStart, + Token::JSXName { + name: "Page".into() + }, + JSXTagEnd, + JSXText { + raw: "\n\r\nABC".into(), + value: "\n\nABC".into(), + }, + JSXTagStart, + tok!('/'), + JSXName { + name: "Page".into() + }, + JSXTagEnd, + Semi, + ] + ); +} diff --git a/crates/swc_ecma_parser/src/parser/jsx.rs b/crates/swc_ecma_parser/src/parser/jsx.rs index 65862c5f1578..80561eb08bff 100644 --- a/crates/swc_ecma_parser/src/parser/jsx.rs +++ b/crates/swc_ecma_parser/src/parser/jsx.rs @@ -428,12 +428,7 @@ impl Parser { let token = bump!(self); let span = self.input.prev_span(); match token { - Token::JSXText { raw } => Ok(JSXText { - span, - // TODO - value: raw.clone(), - raw, - }), + Token::JSXText { raw, value } => Ok(JSXText { span, value, raw }), _ => unreachable!(), } } diff --git a/crates/swc_ecma_parser/src/token.rs b/crates/swc_ecma_parser/src/token.rs index 22f359d749c6..87426de9e4c9 100644 --- a/crates/swc_ecma_parser/src/token.rs +++ b/crates/swc_ecma_parser/src/token.rs @@ -7,7 +7,7 @@ use std::{ }; use num_bigint::BigInt as BigIntValue; -use swc_atoms::{atom, Atom, AtomStore, JsWord}; +use swc_atoms::{atom, Atom, AtomStore}; use swc_common::{Span, Spanned}; use swc_ecma_ast::{AssignOp, BinaryOp}; @@ -278,7 +278,7 @@ pub enum Token { /// String literal. Span of this token contains quote. Str { - value: JsWord, + value: Atom, raw: Atom, }, @@ -297,9 +297,10 @@ pub enum Token { }, JSXName { - name: JsWord, + name: Atom, }, JSXText { + value: Atom, raw: Atom, }, JSXTagStart, @@ -499,7 +500,7 @@ pub enum Word { #[derive(Clone, PartialEq, Eq, Hash)] pub enum IdentLike { Known(KnownIdent), - Other(JsWord), + Other(Atom), } impl From<&'_ str> for IdentLike { @@ -606,7 +607,7 @@ impl From for Word { } } -impl From for JsWord { +impl From for Atom { fn from(w: Word) -> Self { match w { Word::Keyword(k) => match k { @@ -687,7 +688,7 @@ impl Debug for Word { match *self { Word::Ident(ref s) => Display::fmt(s, f), _ => { - let s: JsWord = self.clone().into(); + let s: Atom = self.clone().into(); Display::fmt(&s, f) } } @@ -716,7 +717,7 @@ macro_rules! declare_keyword { $name:ident => $value:tt, )*) => { impl Keyword { - pub(crate) fn into_js_word(self) -> JsWord { + pub(crate) fn into_js_word(self) -> Atom { match self { $(Keyword::$name => atom!($value),)* } @@ -932,7 +933,7 @@ impl TokenKind { } impl Word { - pub(crate) fn cow(&self) -> Cow { + pub(crate) fn cow(&self) -> Cow { match self { Word::Keyword(k) => Cow::Owned(k.into_js_word()), Word::Ident(IdentLike::Known(w)) => Cow::Owned((*w).into()), @@ -980,7 +981,7 @@ impl Debug for Token { Num { value, raw, .. } => write!(f, "numeric literal ({}, {})", value, raw)?, BigInt { value, raw } => write!(f, "bigint literal ({}, {})", value, raw)?, JSXName { name } => write!(f, "jsx name ({})", name)?, - JSXText { raw } => write!(f, "jsx text ({})", raw)?, + JSXText { raw, .. } => write!(f, "jsx text ({})", raw)?, JSXTagStart => write!(f, "< (jsx tag start)")?, JSXTagEnd => write!(f, "> (jsx tag end)")?, Shebang(_) => write!(f, "#!")?, diff --git a/crates/swc_ecma_parser/tests/jsx/basic/7/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/7/input.js.json index f199a598caa8..376b6f06b9a3 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/7/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/7/input.js.json @@ -78,8 +78,8 @@ "end": 42, "ctxt": 0 }, - "value": "\n\nbar\n\nbaz\n\n", - "raw": "\n\nbar\n\nbaz\n\n" + "value": "\nbar\nbaz\n", + "raw": "\nbar\nbaz\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/custom/unary-paren/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/custom/unary-paren/input.js.json index 03e495246e2a..06f6f1d7e95c 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/custom/unary-paren/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/custom/unary-paren/input.js.json @@ -166,8 +166,8 @@ "end": 99, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -235,8 +235,8 @@ "end": 121, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -405,8 +405,8 @@ "end": 267, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/custom/unary/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/custom/unary/input.js.json index 062da7cc87b8..233f4dbea3c4 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/custom/unary/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/custom/unary/input.js.json @@ -166,8 +166,8 @@ "end": 99, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -235,8 +235,8 @@ "end": 121, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -389,8 +389,8 @@ "end": 219, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/entity/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/entity/input.js.json index 87b9037c63c7..e39f63c27d43 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/entity/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/entity/input.js.json @@ -50,7 +50,7 @@ "ctxt": 0 }, "value": "💩", - "raw": "💩" + "raw": "💩" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/fragment-3/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/fragment-3/input.js.json index 53536136831d..3c97dd4ee9f0 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/fragment-3/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/fragment-3/input.js.json @@ -36,8 +36,8 @@ "end": 7, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -75,8 +75,8 @@ "end": 23, "ctxt": 0 }, - "value": "\n\n hi\n\n ", - "raw": "\n\n hi\n\n " + "value": "\n hi\n ", + "raw": "\n hi\n " } ], "closing": { @@ -105,8 +105,8 @@ "end": 33, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -174,8 +174,8 @@ "end": 48, "ctxt": 0 }, - "value": "\n\n", - "raw": "\n\n" + "value": "\n", + "raw": "\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/fragment-4/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/fragment-4/input.js.json index bfea7ec9e62c..0c02c0485ec7 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/fragment-4/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/fragment-4/input.js.json @@ -36,8 +36,8 @@ "end": 6, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXFragment", @@ -62,8 +62,8 @@ "end": 13, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXFragment", @@ -88,8 +88,8 @@ "end": 37, "ctxt": 0 }, - "value": "\n\n super deep\n\n ", - "raw": "\n\n super deep\n\n " + "value": "\n super deep\n ", + "raw": "\n super deep\n " } ], "closing": { @@ -108,8 +108,8 @@ "end": 43, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { @@ -128,8 +128,8 @@ "end": 47, "ctxt": 0 }, - "value": "\n\n", - "raw": "\n\n" + "value": "\n", + "raw": "\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/fragment-5/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/fragment-5/input.js.json index 4dfa94f88e51..c770b24baf38 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/fragment-5/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/fragment-5/input.js.json @@ -36,8 +36,8 @@ "end": 34, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -94,8 +94,8 @@ "end": 48, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -152,8 +152,8 @@ "end": 60, "ctxt": 0 }, - "value": "\n\n", - "raw": "\n\n" + "value": "\n", + "raw": "\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/issue-2264/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/issue-2264/input.js.json index 1902d811703e..19222c837992 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/issue-2264/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/issue-2264/input.js.json @@ -70,8 +70,8 @@ "end": 37, "ctxt": 0 }, - "value": "\n\n // 1\n\n /* 2 */\n\n", - "raw": "\n\n // 1\n\n /* 2 */\n\n" + "value": "\n // 1\n /* 2 */\n", + "raw": "\n // 1\n /* 2 */\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/jsx/basic/issue-6522/input.js.json b/crates/swc_ecma_parser/tests/jsx/basic/issue-6522/input.js.json index 7123568906c6..82e81673eca5 100644 --- a/crates/swc_ecma_parser/tests/jsx/basic/issue-6522/input.js.json +++ b/crates/swc_ecma_parser/tests/jsx/basic/issue-6522/input.js.json @@ -806,8 +806,8 @@ "end": 231, "ctxt": 0 }, - "value": "\n\n", - "raw": "\n\n" + "value": "\n", + "raw": "\n" }, { "type": "JSXElement", @@ -864,8 +864,8 @@ "end": 245, "ctxt": 0 }, - "value": "\n\n", - "raw": "\n\n" + "value": "\n", + "raw": "\n" }, { "type": "JSXElement", @@ -922,8 +922,8 @@ "end": 259, "ctxt": 0 }, - "value": "\n\n", - "raw": "\n\n" + "value": "\n", + "raw": "\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary-paren/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary-paren/input.tsx.json index 21e3befe1c5e..602b367d4c86 100644 --- a/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary-paren/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary-paren/input.tsx.json @@ -56,8 +56,8 @@ "end": 22, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -226,8 +226,8 @@ "end": 175, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary/input.tsx.json index 062da7cc87b8..233f4dbea3c4 100644 --- a/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/custom/tsx-unary/input.tsx.json @@ -166,8 +166,8 @@ "end": 99, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -235,8 +235,8 @@ "end": 121, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -389,8 +389,8 @@ "end": 219, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-1446/case1/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-1446/case1/input.tsx.json index b20acad1f6e2..86334bdd94d5 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-1446/case1/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-1446/case1/input.tsx.json @@ -71,7 +71,7 @@ "ctxt": 0 }, "value": "with ", - "raw": "with " + "raw": "with " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-1446/case2/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-1446/case2/input.tsx.json index f897ea137ed0..8bd05223ee0f 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-1446/case2/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-1446/case2/input.tsx.json @@ -36,8 +36,8 @@ "end": 6, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXElement", @@ -105,8 +105,8 @@ "end": 75, "ctxt": 0 }, - "value": "\n\n  \n\n", - "raw": "\n\n  \n\n" + "value": "\n  \n", + "raw": "\n  \n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2237/case1/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-2237/case1/input.tsx.json index 9fe529d7962c..2caca8a59c79 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-2237/case1/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-2237/case1/input.tsx.json @@ -91,8 +91,8 @@ "end": 68, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -239,8 +239,8 @@ "end": 182, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2237/case2/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-2237/case2/input.tsx.json index b9649a804540..cff76d71ccb4 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-2237/case2/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-2237/case2/input.tsx.json @@ -91,8 +91,8 @@ "end": 68, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -189,8 +189,8 @@ "end": 137, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2264/case2/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-2264/case2/input.tsx.json index 779c8b391d48..810cb4c466a0 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-2264/case2/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-2264/case2/input.tsx.json @@ -70,8 +70,8 @@ "end": 37, "ctxt": 0 }, - "value": "\n\n // 1\n\n /* 2 */\n\n", - "raw": "\n\n // 1\n\n /* 2 */\n\n" + "value": "\n // 1\n /* 2 */\n", + "raw": "\n // 1\n /* 2 */\n" } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-4296/1/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-4296/1/input.tsx.json index 60a645b4a8ba..f9b08717a40c 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-4296/1/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-4296/1/input.tsx.json @@ -464,8 +464,8 @@ "end": 268, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -740,8 +740,8 @@ "end": 528, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json index 269bd2177ced..01ebe144dd6b 100644 --- a/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json +++ b/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json @@ -100,8 +100,8 @@ "end": 59, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " }, { "type": "JSXExpressionContainer", @@ -380,8 +380,8 @@ "end": 178, "ctxt": 0 }, - "value": "\n\n ", - "raw": "\n\n " + "value": "\n ", + "raw": "\n " } ], "closing": { diff --git a/crates/swc_ecma_transforms_base/tests/resolver/vercel/next/server/render/1/output.js b/crates/swc_ecma_transforms_base/tests/resolver/vercel/next/server/render/1/output.js index cf908f540d67..a081566a01a8 100644 --- a/crates/swc_ecma_transforms_base/tests/resolver/vercel/next/server/render/1/output.js +++ b/crates/swc_ecma_transforms_base/tests/resolver/vercel/next/server/render/1/output.js @@ -222,9 +222,7 @@ export async function renderToHTML__2(req__21, res__21, pathname__21, query__21, defaultLocale: renderOpts__21.defaultLocale, AppTree: (props__48)=>{ return - - ; }, defaultGetInitialProps: async (docCtx__49)=>{ @@ -254,9 +252,7 @@ export async function renderToHTML__2(req__21, res__21, pathname__21, query__21, let scriptLoader__21 = {}; const nextExport__21 = !isSSG__21 && (renderOpts__21.nextExport || dev__21 && (isAutoExport__21 || isFallback__21)); const AppContainer__21 = ({ children__52 })=> - - { head__21 = state__53; @@ -267,21 +263,13 @@ export async function renderToHTML__2(req__21, res__21, pathname__21, query__21, scripts: {}, mountedInstances: new Set() }}> - reactLoadableModules__21.push(moduleName__55)}> - - {children__52} - - - - - ; props__21 = await loadGetInitialProps__2(App__21, { AppTree: ctx__21.AppTree, @@ -504,9 +492,7 @@ export async function renderToHTML__2(req__21, res__21, pathname__21, query__21, } const { App: EnhancedApp__112, Component: EnhancedComponent__112 } = enhanceComponents__2(options__112, App__21, Component__21); const html__112 = ReactDOMServer__2.renderToString( - - ); return { html__112, @@ -534,9 +520,7 @@ export async function renderToHTML__2(req__21, res__21, pathname__21, query__21, }; } else { const content__117 = ctx__21.err && ErrorDebug__21 ? : - - ; const bodyResult__117 = concurrentFeatures__21 ? await renderToStream__2(content__117, generateStaticHTML__21) : piperFromArray__2([ ReactDOMServer__2.renderToString(content__117) @@ -614,13 +598,9 @@ export async function renderToHTML__2(req__21, res__21, pathname__21, query__21, useMaybeDeferContent__2 }; const documentHTML__21 = ReactDOMServer__2.renderToStaticMarkup( - - {documentResult__21.documentElement(htmlProps__21)} - - ); if (process.env.NODE_ENV !== "production") { const nonRenderedComponents__123 = []; diff --git a/crates/swc_ecma_transforms_react/tests/__swc_snapshots__/src/refresh/tests.rs/dont_consider_require_as_hoc.js b/crates/swc_ecma_transforms_react/tests/__swc_snapshots__/src/refresh/tests.rs/dont_consider_require_as_hoc.js index 6884459e455a..6d5c1c64aadc 100644 --- a/crates/swc_ecma_transforms_react/tests/__swc_snapshots__/src/refresh/tests.rs/dont_consider_require_as_hoc.js +++ b/crates/swc_ecma_transforms_react/tests/__swc_snapshots__/src/refresh/tests.rs/dont_consider_require_as_hoc.js @@ -5,17 +5,11 @@ const D = import('D'); import E = require('E'); export default function App() { return ; } _c = App; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6923/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6923/output.js index c5420baeb71b..31cd8e727a7e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6923/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6923/output.js @@ -1,10 +1,7 @@ import ReactDOM from "react-dom"; import { _Component } from "./Component"; const App =
- <_Component> -

Hello World

-
; ReactDOM.render(App, window.document.getElementById("react_root")); diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/1/output.js index 03cd1bd466ae..2ee2a9881d48 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/1/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/1/output.js @@ -1,11 +1,8 @@ import { dirname } from "node:path"; export default function IndexPage(props) { return
- abc: {props.abc} - -
; } export function getServerSideProps() { diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/2/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/2/output.js index 89bbf6278029..b25bc2779264 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/2/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/next-45561/2/output.js @@ -1,15 +1,10 @@ import { dirname } from "node:path"; export default function IndexPage(props) { return
- abc: {props.abc} - - - -
; } export function getServerSideProps() { diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js index ad5d83f450a7..f7417cae2fcc 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js @@ -233,9 +233,7 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) { defaultLocale: renderOpts.defaultLocale, AppTree: (props)=>{ return - - ; }, defaultGetInitialProps: async (docCtx)=>{ @@ -265,9 +263,7 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) { let scriptLoader = {}; const nextExport = !isSSG && (renderOpts.nextExport || dev && (isAutoExport || isFallback)); const AppContainer = ({ children })=> - - { head = state; @@ -278,21 +274,13 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) { scripts: {}, mountedInstances: new Set() }}> - reactLoadableModules.push(moduleName)}> - - {children} - - - - - ; props = await loadGetInitialProps(App, { AppTree: ctx.AppTree, @@ -553,9 +541,7 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) { } const { App: EnhancedApp, Component: EnhancedComponent } = enhanceComponents(options, App, Component); const html = ReactDOMServer.renderToString( - - ); return { html, @@ -584,9 +570,7 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) { }; } else { const content = ctx.err && ErrorDebug ? : - - ; const bodyResult = concurrentFeatures ? await renderToStream(content, generateStaticHTML) : piperFromArray([ ReactDOMServer.renderToString(content) @@ -665,13 +649,9 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) { useMaybeDeferContent }; const documentHTML = ReactDOMServer.renderToStaticMarkup( - - {documentResult.documentElement(htmlProps)} - - ); if (process.env.NODE_ENV !== "production") { const nonRenderedComponents = [];