diff --git a/CHANGELOG.md b/CHANGELOG.md index 376a0bc22e8..fb50e62dfe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## Unreleased + +* Fix preserving collapsed JSX whitespace ([#3818](https://github.com/evanw/esbuild/issues/3818)) + + When transformed, certain whitespace inside JSX elements is ignored completely if it collapses to an empty string. However, the whitespace should only be ignored if the JSX is being transformed, not if it's being preserved. This release fixes a bug where esbuild was previously incorrectly ignoring collapsed whitespace with `--jsx=preserve`. Here is an example: + + ```jsx + // Original code + + + + + // Old output (with --jsx=preserve) + ; + + // New output (with --jsx=preserve) + + + ; + ``` + ## 0.22.0 **This release deliberately contains backwards-incompatible changes.** To avoid automatically picking up releases like this, you should either be pinning the exact version of `esbuild` in your `package.json` file (recommended) or be using a version range syntax that only accepts patch upgrades such as `^0.21.0` or `~0.21.0`. See npm's documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information. diff --git a/internal/js_lexer/js_lexer.go b/internal/js_lexer/js_lexer.go index 8bac729c71e..3776f9727dd 100644 --- a/internal/js_lexer/js_lexer.go +++ b/internal/js_lexer/js_lexer.go @@ -794,12 +794,6 @@ func (lexer *Lexer) NextJSXElementChild() { if needsFixing { // Slow path lexer.decodedStringLiteralOrNil = fixWhitespaceAndDecodeJSXEntities(text) - - // Skip this token if it turned out to be empty after trimming - if len(lexer.decodedStringLiteralOrNil) == 0 { - lexer.HasNewlineBefore = true - continue - } } else { // Fast path n := len(text) diff --git a/internal/js_parser/js_parser.go b/internal/js_parser/js_parser.go index d1319c40966..4b82e84dcd1 100644 --- a/internal/js_parser/js_parser.go +++ b/internal/js_parser/js_parser.go @@ -5234,8 +5234,10 @@ func (p *parser) parseJSXElement(loc logger.Loc) js_ast.Expr { case js_lexer.TStringLiteral: if p.options.jsx.Preserve { nullableChildren = append(nullableChildren, js_ast.Expr{Loc: p.lexer.Loc(), Data: &js_ast.EJSXText{Raw: p.lexer.Raw()}}) + } else if str := p.lexer.StringLiteral(); len(str) > 0 { + nullableChildren = append(nullableChildren, js_ast.Expr{Loc: p.lexer.Loc(), Data: &js_ast.EString{Value: str}}) } else { - nullableChildren = append(nullableChildren, js_ast.Expr{Loc: p.lexer.Loc(), Data: &js_ast.EString{Value: p.lexer.StringLiteral()}}) + // Skip this token if it turned out to be empty after trimming } p.lexer.NextJSXElementChild() diff --git a/internal/js_parser/js_parser_test.go b/internal/js_parser/js_parser_test.go index 9c83c23f27d..5efa385ab6d 100644 --- a/internal/js_parser/js_parser_test.go +++ b/internal/js_parser/js_parser_test.go @@ -160,9 +160,15 @@ func expectParseErrorJSX(t *testing.T, contents string, expected string) { }) } -func expectPrintedJSX(t *testing.T, contents string, expected string) { +func expectPrintedJSX(t *testing.T, contents string, expectedPreserve string, expectedTransform string) { t.Helper() - expectPrintedCommon(t, contents, expected, config.Options{ + expectPrintedCommon(t, contents, expectedPreserve, config.Options{ + JSX: config.JSXOptions{ + Parse: true, + Preserve: true, + }, + }) + expectPrintedCommon(t, contents, expectedTransform, config.Options{ JSX: config.JSXOptions{ Parse: true, }, @@ -4515,10 +4521,10 @@ func TestMangleObject(t *testing.T) { } func TestMangleObjectJSX(t *testing.T) { - expectPrintedJSX(t, "x = ", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...{} });\n") - expectPrintedJSX(t, "x = ", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...null });\n") - expectPrintedJSX(t, "x = ", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...{ bar } });\n") - expectPrintedJSX(t, "x = ", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...bar });\n") + expectPrintedJSX(t, "x = ", "x = ;\n", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...{} });\n") + expectPrintedJSX(t, "x = ", "x = ;\n", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...null });\n") + expectPrintedJSX(t, "x = ", "x = ;\n", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...{ bar } });\n") + expectPrintedJSX(t, "x = ", "x = ;\n", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true, ...bar });\n") expectPrintedMangleJSX(t, "x = ", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true });\n") expectPrintedMangleJSX(t, "x = ", "x = /* @__PURE__ */ React.createElement(\"foo\", { bar: true });\n") @@ -5430,19 +5436,19 @@ func TestUnicodeWhitespace(t *testing.T) { // Test "js_lexer.NextInsideJSXElement()" expectParseErrorJSX(t, "", ": ERROR: Expected \">\" but found \"\\b\"\n") for _, s := range whitespace { - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { y: true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { y: true });\n") } // Test "js_lexer.NextJSXElementChild()" - expectPrintedJSX(t, "\n\u0008\n", "/* @__PURE__ */ React.createElement(\"x\", null, \"\\b\");\n") + expectPrintedJSX(t, "\n\u0008\n", "\n\u0008\n;\n", "/* @__PURE__ */ React.createElement(\"x\", null, \"\\b\");\n") for _, s := range whitespace { - expectPrintedJSX(t, "\n"+s+"\n", "/* @__PURE__ */ React.createElement(\"x\", null);\n") + expectPrintedJSX(t, "\n"+s+"\n", "\n"+s+"\n;\n", "/* @__PURE__ */ React.createElement(\"x\", null);\n") } // Test "fixWhitespaceAndDecodeJSXEntities()" - expectPrintedJSX(t, "\n\u0008"\n", "/* @__PURE__ */ React.createElement(\"x\", null, '\\b\"');\n") + expectPrintedJSX(t, "\n\u0008"\n", "\n\u0008"\n;\n", "/* @__PURE__ */ React.createElement(\"x\", null, '\\b\"');\n") for _, s := range whitespace { - expectPrintedJSX(t, "\n"+s+""\n", "/* @__PURE__ */ React.createElement(\"x\", null, '\"');\n") + expectPrintedJSX(t, "\n"+s+""\n", "\n"+s+""\n;\n", "/* @__PURE__ */ React.createElement(\"x\", null, '\"');\n") } invalidWhitespaceInJS := []string{ @@ -5463,12 +5469,12 @@ func TestUnicodeWhitespace(t *testing.T) { // Test "js_lexer.NextJSXElementChild()" for _, s := range invalidWhitespaceInJS { - expectPrintedJSX(t, "\n"+s+"\n", "/* @__PURE__ */ React.createElement(\"x\", null, \""+s+"\");\n") + expectPrintedJSX(t, "\n"+s+"\n", "\n"+s+"\n;\n", "/* @__PURE__ */ React.createElement(\"x\", null, \""+s+"\");\n") } // Test "fixWhitespaceAndDecodeJSXEntities()" for _, s := range invalidWhitespaceInJS { - expectPrintedJSX(t, "\n"+s+""\n", "/* @__PURE__ */ React.createElement(\"x\", null, '"+s+"\"');\n") + expectPrintedJSX(t, "\n"+s+""\n", "\n"+s+""\n;\n", "/* @__PURE__ */ React.createElement(\"x\", null, '"+s+"\"');\n") } } @@ -5482,7 +5488,7 @@ func TestReplacementCharacter(t *testing.T) { expectPrinted(t, "`\uFFFD`", "`\uFFFD`;\n") expectPrinted(t, "/\uFFFD/", "/\uFFFD/;\n") - expectPrintedJSX(t, "\uFFFD", "/* @__PURE__ */ React.createElement(\"a\", null, \"\uFFFD\");\n") + expectPrintedJSX(t, "\uFFFD", "\uFFFD;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"\uFFFD\");\n") } func TestNewTarget(t *testing.T) { @@ -5504,136 +5510,136 @@ func TestJSX(t *testing.T) { expectParseErrorJSX(t, "
{1}}
", ": WARNING: The character \"}\" is not valid inside a JSX element\n"+ "NOTE: Did you mean to escape it as \"{'}'}\" instead?\n") - expectPrintedJSX(t, "
>
", "/* @__PURE__ */ React.createElement(\"div\", null, \">\");\n") - expectPrintedJSX(t, "
{1}}
", "/* @__PURE__ */ React.createElement(\"div\", null, 1, \"}\");\n") + expectPrintedJSX(t, "
>
", "
>
;\n", "/* @__PURE__ */ React.createElement(\"div\", null, \">\");\n") + expectPrintedJSX(t, "
{1}}
", "
{1}}
;\n", "/* @__PURE__ */ React.createElement(\"div\", null, 1, \"}\");\n") expectParseError(t, "", ": ERROR: The JSX syntax extension is not currently enabled\n"+ "NOTE: The esbuild loader for this file is currently set to \"js\" but it must be set to \"jsx\" to be able to parse JSX syntax. "+ "You can use 'Loader: map[string]api.Loader{\".js\": api.LoaderJSX}' to do that.\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(A, null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(a.b, null);\n") - expectPrintedJSX(t, "<_a/>", "/* @__PURE__ */ React.createElement(_a, null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a-b\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a0\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(A, null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(a.b, null);\n") + expectPrintedJSX(t, "<_a/>", "<_a />;\n", "/* @__PURE__ */ React.createElement(_a, null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a-b\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a0\", null);\n") expectParseErrorJSX(t, "<0a/>", ": ERROR: Expected identifier but found \"0\"\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: true });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\\\\" });\n") - expectPrintedJSX(t, "\"/>", "/* @__PURE__ */ React.createElement(\"a\", { b: \"<>\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"<>\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"&wrong;\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: (1, 2) });\n") - expectPrintedJSX(t, "}/>", "/* @__PURE__ */ React.createElement(\"a\", { b: /* @__PURE__ */ React.createElement(\"c\", null) });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { ...props });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚\" });\n") - - expectPrintedJSX(t, "\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "123", "/* @__PURE__ */ React.createElement(\"a\", null, \"123\");\n") - expectPrintedJSX(t, "}", "/* @__PURE__ */ React.createElement(\"a\", null, \"}\");\n") - expectPrintedJSX(t, "=", "/* @__PURE__ */ React.createElement(\"a\", null, \"=\");\n") - expectPrintedJSX(t, ">", "/* @__PURE__ */ React.createElement(\"a\", null, \">\");\n") - expectPrintedJSX(t, ">=", "/* @__PURE__ */ React.createElement(\"a\", null, \">=\");\n") - expectPrintedJSX(t, ">>", "/* @__PURE__ */ React.createElement(\"a\", null, \">>\");\n") - expectPrintedJSX(t, "{}", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "{/* comment */}", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "b{}", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b{/* comment */}", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "{}c", "/* @__PURE__ */ React.createElement(\"a\", null, \"c\");\n") - expectPrintedJSX(t, "{/* comment */}c", "/* @__PURE__ */ React.createElement(\"a\", null, \"c\");\n") - expectPrintedJSX(t, "b{}c", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\", \"c\");\n") - expectPrintedJSX(t, "b{/* comment */}c", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\", \"c\");\n") - expectPrintedJSX(t, "{1, 2}", "/* @__PURE__ */ React.createElement(\"a\", null, (1, 2));\n") - expectPrintedJSX(t, "<>", "/* @__PURE__ */ React.createElement(\"a\", null, \"<>\");\n") - expectPrintedJSX(t, "&wrong;", "/* @__PURE__ */ React.createElement(\"a\", null, \"&wrong;\");\n") - expectPrintedJSX(t, "šŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") - expectPrintedJSX(t, "{...children}", "/* @__PURE__ */ React.createElement(\"a\", null, ...children);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\\\\" });\n") + expectPrintedJSX(t, "\"/>", "\" />;\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"<>\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"<>\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"&wrong;\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: (1, 2) });\n") + expectPrintedJSX(t, "}/>", "} />;\n", "/* @__PURE__ */ React.createElement(\"a\", { b: /* @__PURE__ */ React.createElement(\"c\", null) });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { ...props });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚\" });\n") + + expectPrintedJSX(t, "\n", "\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "123", "123;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"123\");\n") + expectPrintedJSX(t, "}", "};\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"}\");\n") + expectPrintedJSX(t, "=", "=;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"=\");\n") + expectPrintedJSX(t, ">", ">;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \">\");\n") + expectPrintedJSX(t, ">=", ">=;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \">=\");\n") + expectPrintedJSX(t, ">>", ">>;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \">>\");\n") + expectPrintedJSX(t, "{}", "{};\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "{/* comment */}", "{\n /* comment */\n};\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "b{}", "b{};\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b{/* comment */}", "b{\n /* comment */\n};\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "{}c", "{}c;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"c\");\n") + expectPrintedJSX(t, "{/* comment */}c", "{\n /* comment */\n}c;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"c\");\n") + expectPrintedJSX(t, "b{}c", "b{}c;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\", \"c\");\n") + expectPrintedJSX(t, "b{/* comment */}c", "b{\n /* comment */\n}c;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\", \"c\");\n") + expectPrintedJSX(t, "{1, 2}", "{(1, 2)};\n", "/* @__PURE__ */ React.createElement(\"a\", null, (1, 2));\n") + expectPrintedJSX(t, "<>", "<>;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"<>\");\n") + expectPrintedJSX(t, "&wrong;", "&wrong;;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"&wrong;\");\n") + expectPrintedJSX(t, "šŸ™‚", "šŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, "{...children}", "{...children};\n", "/* @__PURE__ */ React.createElement(\"a\", null, ...children);\n") // Note: The TypeScript compiler and Babel disagree. This matches TypeScript. - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" c\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nc\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n c\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c \" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c \\n\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c\\n \" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c d\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c \\nd\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c\\n d\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" c\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nc\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n c\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" c\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nc\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n c\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c \" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c \\n\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c\\n \" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c d\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c \\nd\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"c\\n d\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" c\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nc\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n c\" });\n") // Same test as above except with multi-byte Unicode characters - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" šŸ™‚\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nšŸ™‚\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n šŸ™‚\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ \" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ \\n\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚\\n \" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ šŸ•\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ \\nšŸ•\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚\\n šŸ•\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" šŸ™‚\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nšŸ™‚\" });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n šŸ™‚\" });\n") - - expectPrintedJSX(t, " b", "/* @__PURE__ */ React.createElement(\"a\", null, \" b\");\n") - expectPrintedJSX(t, " \nb", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "\n b", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b ", "/* @__PURE__ */ React.createElement(\"a\", null, \"b \");\n") - expectPrintedJSX(t, "b \n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b\n ", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b c", "/* @__PURE__ */ React.createElement(\"a\", null, \"b c\");\n") - expectPrintedJSX(t, "b \nc", "/* @__PURE__ */ React.createElement(\"a\", null, \"b c\");\n") - expectPrintedJSX(t, "b\n c", "/* @__PURE__ */ React.createElement(\"a\", null, \"b c\");\n") - expectPrintedJSX(t, " b", "/* @__PURE__ */ React.createElement(\"a\", null, \" b\");\n") - expectPrintedJSX(t, " \nb", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "\n b", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" šŸ™‚\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nšŸ™‚\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n šŸ™‚\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ \" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ \\n\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚\\n \" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ šŸ•\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚ \\nšŸ•\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"šŸ™‚\\n šŸ•\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" šŸ™‚\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \" \\nšŸ™‚\" });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { b: \"\\n šŸ™‚\" });\n") + + expectPrintedJSX(t, " b", " b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" b\");\n") + expectPrintedJSX(t, " \nb", " \nb;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "\n b", "\n b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b ", "b ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b \");\n") + expectPrintedJSX(t, "b \n", "b \n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b\n ", "b\n ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b c", "b c;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b c\");\n") + expectPrintedJSX(t, "b \nc", "b \nc;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b c\");\n") + expectPrintedJSX(t, "b\n c", "b\n c;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b c\");\n") + expectPrintedJSX(t, " b", " b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" b\");\n") + expectPrintedJSX(t, " \nb", " \nb;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "\n b", "\n b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") // Same test as above except with multi-byte Unicode characters - expectPrintedJSX(t, " šŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \" šŸ™‚\");\n") - expectPrintedJSX(t, " \nšŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") - expectPrintedJSX(t, "\n šŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") - expectPrintedJSX(t, "šŸ™‚ ", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ \");\n") - expectPrintedJSX(t, "šŸ™‚ \n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") - expectPrintedJSX(t, "šŸ™‚\n ", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") - expectPrintedJSX(t, "šŸ™‚ šŸ•", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ šŸ•\");\n") - expectPrintedJSX(t, "šŸ™‚ \nšŸ•", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ šŸ•\");\n") - expectPrintedJSX(t, "šŸ™‚\n šŸ•", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ šŸ•\");\n") - expectPrintedJSX(t, " šŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \" šŸ™‚\");\n") - expectPrintedJSX(t, " \nšŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") - expectPrintedJSX(t, "\n šŸ™‚", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, " šŸ™‚", " šŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" šŸ™‚\");\n") + expectPrintedJSX(t, " \nšŸ™‚", " \nšŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, "\n šŸ™‚", "\n šŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, "šŸ™‚ ", "šŸ™‚ ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ \");\n") + expectPrintedJSX(t, "šŸ™‚ \n", "šŸ™‚ \n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, "šŸ™‚\n ", "šŸ™‚\n ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, "šŸ™‚ šŸ•", "šŸ™‚ šŸ•;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ šŸ•\");\n") + expectPrintedJSX(t, "šŸ™‚ \nšŸ•", "šŸ™‚ \nšŸ•;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ šŸ•\");\n") + expectPrintedJSX(t, "šŸ™‚\n šŸ•", "šŸ™‚\n šŸ•;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚ šŸ•\");\n") + expectPrintedJSX(t, " šŸ™‚", " šŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" šŸ™‚\");\n") + expectPrintedJSX(t, " \nšŸ™‚", " \nšŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") + expectPrintedJSX(t, "\n šŸ™‚", "\n šŸ™‚;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"šŸ™‚\");\n") // "{x}" with all combinations of "", " ", and "\n" inserted in between - expectPrintedJSX(t, "{x};", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "\n{x};", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "{x}\n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "\n{x}\n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "{x}\n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "\n{x}\n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "{x}\n\n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "\n{x}\n\n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, " {x};", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, " {x}\n;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, " {x}\n;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, " {x}\n\n;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "{x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "\n{x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "{x} \n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "\n{x} \n;", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, " {x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, " {x} \n;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") - expectPrintedJSX(t, "{x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, "\n{x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, "{x}\n ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, "\n{x}\n ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, " {x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, " {x}\n ;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, "{x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, "\n{x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") - expectPrintedJSX(t, " {x} ;", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, \" \", /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, "{x};", "{x};\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "\n{x};", "\n{x};\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "{x}\n;", "{x}\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "\n{x}\n;", "\n{x}\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "{x}\n;", "{x}\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "\n{x}\n;", "\n{x}\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "{x}\n\n;", "{x}\n\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "\n{x}\n\n;", "\n{x}\n\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, " {x};", " {x};\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, " {x}\n;", " {x}\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, " {x}\n;", " {x}\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, " {x}\n\n;", " {x}\n\n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "{x} ;", "{x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "\n{x} ;", "\n{x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "{x} \n;", "{x} \n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "\n{x} \n;", "\n{x} \n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, " {x} ;", " {x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, " {x} \n;", " {x} \n;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, \" \", /* @__PURE__ */ React.createElement(\"b\", null));\n") + expectPrintedJSX(t, "{x} ;", "{x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, "\n{x} ;", "\n{x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, "{x}\n ;", "{x}\n ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, "\n{x}\n ;", "\n{x}\n ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, " {x} ;", " {x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, " {x}\n ;", " {x}\n ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, "{x} ;", "{x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, "\n{x} ;", "\n{x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, x, \" \", /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") + expectPrintedJSX(t, " {x} ;", " {x} ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" \", x, \" \", /* @__PURE__ */ React.createElement(\"b\", null), \" \");\n") expectParseErrorJSX(t, "", ": ERROR: Expected \"{\" but found \"true\"\n") expectParseErrorJSX(t, "", ": ERROR: Expected identifier but found \"/\"\n") @@ -5648,27 +5654,27 @@ func TestJSX(t *testing.T) { expectParseErrorJSX(t, "", ": ERROR: Expected \">\" but found \".\"\n") expectParseErrorJSX(t, "", ": ERROR: Unexpected \"-\"\n") - expectPrintedJSX(t, "< /**/ a/>", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "< //\n a/>", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\n \"a\",\n null\n);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "< /**/ a/>", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "< //\n a/>", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\n \"a\",\n null\n);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "b< /**/ /a>", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b< //\n /a>", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, "b", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b< /**/ /a>", "b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b< //\n /a>", "b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b", "b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b", "b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b", "b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") + expectPrintedJSX(t, "b", "b;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"b\");\n") - expectPrintedJSX(t, " /**/ ", "/* @__PURE__ */ React.createElement(\"a\", null, \" /**/ \");\n") - expectPrintedJSX(t, " //\n ", "/* @__PURE__ */ React.createElement(\"a\", null, \" //\");\n") + expectPrintedJSX(t, " /**/ ", " /**/ ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" /**/ \");\n") + expectPrintedJSX(t, " //\n ", " //\n ;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \" //\");\n") // Unicode tests - expectPrintedJSX(t, "<\U00020000/>", "/* @__PURE__ */ React.createElement(\U00020000, null);\n") - expectPrintedJSX(t, "\U00020000", "/* @__PURE__ */ React.createElement(\"a\", null, \"\U00020000\");\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", { \"\U00020000\": 0 });\n") + expectPrintedJSX(t, "<\U00020000/>", "<\U00020000 />;\n", "/* @__PURE__ */ React.createElement(\U00020000, null);\n") + expectPrintedJSX(t, "\U00020000", "\U00020000;\n", "/* @__PURE__ */ React.createElement(\"a\", null, \"\U00020000\");\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", { \"\U00020000\": 0 });\n") // Comment tests expectParseErrorJSX(t, "", ": ERROR: Expected \"*/\" to terminate multi-line comment\n: NOTE: The multi-line comment starts here:\n") @@ -5686,27 +5692,27 @@ func TestJSX(t *testing.T) { // JSX namespaced names for _, colon := range []string{":", " :", ": ", " : "} { - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a:b\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a-b:c-d\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a-:b-\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"Te:st\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"a:b\": true });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"a-b:c-d\": true });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"a-:b-\": true });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"Te:st\": true });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"a:b\": 0 });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"a-b:c-d\": 0 });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"a-:b-\": 0 });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { \"Te:st\": 0 });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a-b\", { \"a-b\": a - b });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a:b\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a-b:c-d\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a-:b-\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"Te:st\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"a:b\": true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"a-b:c-d\": true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"a-:b-\": true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"Te:st\": true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"a:b\": 0 });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"a-b:c-d\": 0 });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"a-:b-\": 0 });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { \"Te:st\": 0 });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a-b\", { \"a-b\": a - b });\n") expectParseErrorJSX(t, "", ": ERROR: Expected identifier after \"x:\" in namespaced JSX name\n") expectParseErrorJSX(t, "", ": ERROR: Expected \">\" but found \":\"\n") expectParseErrorJSX(t, "", ": ERROR: Expected identifier after \"x:\" in namespaced JSX name\n") } // JSX elements as JSX attribute values - expectPrintedJSX(t, "/>", "/* @__PURE__ */ React.createElement(\"a\", { b: /* @__PURE__ */ React.createElement(\"c\", null) });\n") - expectPrintedJSX(t, "/>", "/* @__PURE__ */ React.createElement(\"a\", { b: /* @__PURE__ */ React.createElement(React.Fragment, null) });\n") + expectPrintedJSX(t, "/>", " />;\n", "/* @__PURE__ */ React.createElement(\"a\", { b: /* @__PURE__ */ React.createElement(\"c\", null) });\n") + expectPrintedJSX(t, "/>", " />;\n", "/* @__PURE__ */ React.createElement(\"a\", { b: /* @__PURE__ */ React.createElement(React.Fragment, null) });\n") expectParseErrorJSX(t, "/>", ": ERROR: Expected identifier but found \"/\"\n") expectParseErrorJSX(t, "/>", ": WARNING: The character \">\" is not valid inside a JSX element\nNOTE: Did you mean to escape it as \"{'>'}\" instead?\n"+ @@ -5721,34 +5727,34 @@ func TestJSX(t *testing.T) { } func TestJSXSingleLine(t *testing.T) { - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", null);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"x\", { y: true });\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\n \"x\",\n null\n);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\n \"x\",\n {\n y: true\n }\n);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\n \"x\",\n {\n y: true\n }\n);\n") - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\n \"x\",\n {\n ...y\n }\n);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"x\", { y: true });\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\n \"x\",\n null\n);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\n \"x\",\n {\n y: true\n }\n);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\n \"x\",\n {\n y: true\n }\n);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\n \"x\",\n {\n ...y\n }\n);\n") } func TestJSXPragmas(t *testing.T) { - expectPrintedJSX(t, "// @jsx h\n", "/* @__PURE__ */ h(\"a\", null);\n") - expectPrintedJSX(t, "/*@jsx h*/\n", "/* @__PURE__ */ h(\"a\", null);\n") - expectPrintedJSX(t, "/* @jsx h */\n", "/* @__PURE__ */ h(\"a\", null);\n") - expectPrintedJSX(t, "\n// @jsx h", "/* @__PURE__ */ h(\"a\", null);\n") - expectPrintedJSX(t, "\n/*@jsx h*/", "/* @__PURE__ */ h(\"a\", null);\n") - expectPrintedJSX(t, "\n/* @jsx h */", "/* @__PURE__ */ h(\"a\", null);\n") - expectPrintedJSX(t, "// @jsx a.b.c\n", "/* @__PURE__ */ a.b.c(\"a\", null);\n") - expectPrintedJSX(t, "/*@jsx a.b.c*/\n", "/* @__PURE__ */ a.b.c(\"a\", null);\n") - expectPrintedJSX(t, "/* @jsx a.b.c */\n", "/* @__PURE__ */ a.b.c(\"a\", null);\n") - - expectPrintedJSX(t, "// @jsxFrag f\n<>", "/* @__PURE__ */ React.createElement(f, null);\n") - expectPrintedJSX(t, "/*@jsxFrag f*/\n<>", "/* @__PURE__ */ React.createElement(f, null);\n") - expectPrintedJSX(t, "/* @jsxFrag f */\n<>", "/* @__PURE__ */ React.createElement(f, null);\n") - expectPrintedJSX(t, "<>\n// @jsxFrag f", "/* @__PURE__ */ React.createElement(f, null);\n") - expectPrintedJSX(t, "<>\n/*@jsxFrag f*/", "/* @__PURE__ */ React.createElement(f, null);\n") - expectPrintedJSX(t, "<>\n/* @jsxFrag f */", "/* @__PURE__ */ React.createElement(f, null);\n") - expectPrintedJSX(t, "// @jsxFrag a.b.c\n<>", "/* @__PURE__ */ React.createElement(a.b.c, null);\n") - expectPrintedJSX(t, "/*@jsxFrag a.b.c*/\n<>", "/* @__PURE__ */ React.createElement(a.b.c, null);\n") - expectPrintedJSX(t, "/* @jsxFrag a.b.c */\n<>", "/* @__PURE__ */ React.createElement(a.b.c, null);\n") + expectPrintedJSX(t, "// @jsx h\n", ";\n", "/* @__PURE__ */ h(\"a\", null);\n") + expectPrintedJSX(t, "/*@jsx h*/\n", ";\n", "/* @__PURE__ */ h(\"a\", null);\n") + expectPrintedJSX(t, "/* @jsx h */\n", ";\n", "/* @__PURE__ */ h(\"a\", null);\n") + expectPrintedJSX(t, "\n// @jsx h", ";\n", "/* @__PURE__ */ h(\"a\", null);\n") + expectPrintedJSX(t, "\n/*@jsx h*/", ";\n", "/* @__PURE__ */ h(\"a\", null);\n") + expectPrintedJSX(t, "\n/* @jsx h */", ";\n", "/* @__PURE__ */ h(\"a\", null);\n") + expectPrintedJSX(t, "// @jsx a.b.c\n", ";\n", "/* @__PURE__ */ a.b.c(\"a\", null);\n") + expectPrintedJSX(t, "/*@jsx a.b.c*/\n", ";\n", "/* @__PURE__ */ a.b.c(\"a\", null);\n") + expectPrintedJSX(t, "/* @jsx a.b.c */\n", ";\n", "/* @__PURE__ */ a.b.c(\"a\", null);\n") + + expectPrintedJSX(t, "// @jsxFrag f\n<>", "<>;\n", "/* @__PURE__ */ React.createElement(f, null);\n") + expectPrintedJSX(t, "/*@jsxFrag f*/\n<>", "<>;\n", "/* @__PURE__ */ React.createElement(f, null);\n") + expectPrintedJSX(t, "/* @jsxFrag f */\n<>", "<>;\n", "/* @__PURE__ */ React.createElement(f, null);\n") + expectPrintedJSX(t, "<>\n// @jsxFrag f", "<>;\n", "/* @__PURE__ */ React.createElement(f, null);\n") + expectPrintedJSX(t, "<>\n/*@jsxFrag f*/", "<>;\n", "/* @__PURE__ */ React.createElement(f, null);\n") + expectPrintedJSX(t, "<>\n/* @jsxFrag f */", "<>;\n", "/* @__PURE__ */ React.createElement(f, null);\n") + expectPrintedJSX(t, "// @jsxFrag a.b.c\n<>", "<>;\n", "/* @__PURE__ */ React.createElement(a.b.c, null);\n") + expectPrintedJSX(t, "/*@jsxFrag a.b.c*/\n<>", "<>;\n", "/* @__PURE__ */ React.createElement(a.b.c, null);\n") + expectPrintedJSX(t, "/* @jsxFrag a.b.c */\n<>", "<>;\n", "/* @__PURE__ */ React.createElement(a.b.c, null);\n") } func TestJSXAutomatic(t *testing.T) { @@ -5861,39 +5867,39 @@ NOTE: Both "__source" and "__self" are set automatically by esbuild when using R ": NOTE: This file is implicitly in strict mode due to the JSX element here:\n" + "NOTE: When React's \"automatic\" JSX transform is enabled, using a JSX element automatically inserts an \"import\" statement at the top of the file " + "for the corresponding the JSX helper function. This means the file is considered an ECMAScript module, and all ECMAScript modules use strict mode.\n" - expectPrintedJSX(t, "with (x) y()", "with (x) y(/* @__PURE__ */ React.createElement(\"z\", null));\n") + expectPrintedJSX(t, "with (x) y()", "with (x) y();\n", "with (x) y(/* @__PURE__ */ React.createElement(\"z\", null));\n") expectPrintedJSXAutomatic(t, p, "with (x) y", "with (x) y;\n") expectParseErrorJSX(t, "with (x) y() // @jsxRuntime automatic", strictModeError) expectParseErrorJSXAutomatic(t, p, "with (x) y()", strictModeError) } func TestJSXAutomaticPragmas(t *testing.T) { - expectPrintedJSX(t, "// @jsxRuntime automatic\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "/*@jsxRuntime automatic*/\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "/* @jsxRuntime automatic */\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "\n/*@jsxRuntime automatic*/", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "\n/* @jsxRuntime automatic */", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - - expectPrintedJSX(t, "// @jsxRuntime classic\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "/*@jsxRuntime classic*/\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "/* @jsxRuntime classic */\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "\n/*@jsxRuntime classic*/\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "\n/* @jsxRuntime classic */\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "// @jsxRuntime automatic\n", ";\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "/*@jsxRuntime automatic*/\n", ";\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "/* @jsxRuntime automatic */\n", ";\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "\n/*@jsxRuntime automatic*/", ";\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "\n/* @jsxRuntime automatic */", ";\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + + expectPrintedJSX(t, "// @jsxRuntime classic\n", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "/*@jsxRuntime classic*/\n", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "/* @jsxRuntime classic */\n", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "\n/*@jsxRuntime classic*/\n", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "\n/* @jsxRuntime classic */\n", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") expectParseErrorJSX(t, "// @jsxRuntime foo\n", `: WARNING: Invalid JSX runtime: "foo" NOTE: The JSX runtime can only be set to either "classic" or "automatic". `) - expectPrintedJSX(t, "// @jsxRuntime automatic @jsxImportSource src\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "/*@jsxRuntime automatic @jsxImportSource src*/\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "/*@jsxRuntime automatic*//*@jsxImportSource src*/\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "/* @jsxRuntime automatic */\n/* @jsxImportSource src */\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "\n/*@jsxRuntime automatic @jsxImportSource src*/", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "\n/*@jsxRuntime automatic*/\n/*@jsxImportSource src*/", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "\n/* @jsxRuntime automatic */\n/* @jsxImportSource src */", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "// @jsxRuntime automatic @jsxImportSource src\n", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "/*@jsxRuntime automatic @jsxImportSource src*/\n", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "/*@jsxRuntime automatic*//*@jsxImportSource src*/\n", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "/* @jsxRuntime automatic */\n/* @jsxImportSource src */\n", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "\n/*@jsxRuntime automatic @jsxImportSource src*/", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "\n/*@jsxRuntime automatic*/\n/*@jsxImportSource src*/", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "\n/* @jsxRuntime automatic */\n/* @jsxImportSource src */", ";\n", "import { jsx } from \"src/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") - expectPrintedJSX(t, "// @jsxRuntime classic @jsxImportSource src\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "// @jsxRuntime classic @jsxImportSource src\n", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") expectParseErrorJSX(t, "// @jsxRuntime classic @jsxImportSource src\n", `: WARNING: The JSX import source cannot be set without also enabling React's "automatic" JSX transform NOTE: You can enable React's "automatic" JSX transform for this file by using a "@jsxRuntime automatic" comment. @@ -5903,16 +5909,16 @@ NOTE: You can enable React's "automatic" JSX transform for this file by using a NOTE: You can enable React's "automatic" JSX transform for this file by using a "@jsxRuntime automatic" comment. `) - expectPrintedJSX(t, "// @jsxRuntime automatic @jsx h\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") + expectPrintedJSX(t, "// @jsxRuntime automatic @jsx h\n", ";\n", "import { jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(\"a\", {});\n") expectParseErrorJSX(t, "// @jsxRuntime automatic @jsx h\n", ": WARNING: The JSX factory cannot be set when using React's \"automatic\" JSX transform\n") - expectPrintedJSX(t, "// @jsxRuntime automatic @jsxFrag f\n<>", "import { Fragment, jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(Fragment, {});\n") + expectPrintedJSX(t, "// @jsxRuntime automatic @jsxFrag f\n<>", "<>;\n", "import { Fragment, jsx } from \"react/jsx-runtime\";\n/* @__PURE__ */ jsx(Fragment, {});\n") expectParseErrorJSX(t, "// @jsxRuntime automatic @jsxFrag f\n<>", ": WARNING: The JSX fragment cannot be set when using React's \"automatic\" JSX transform\n") } func TestJSXSideEffects(t *testing.T) { - expectPrintedJSX(t, "", "/* @__PURE__ */ React.createElement(\"a\", null);\n") - expectPrintedJSX(t, "<>", "/* @__PURE__ */ React.createElement(React.Fragment, null);\n") + expectPrintedJSX(t, "", ";\n", "/* @__PURE__ */ React.createElement(\"a\", null);\n") + expectPrintedJSX(t, "<>", "<>;\n", "/* @__PURE__ */ React.createElement(React.Fragment, null);\n") expectPrintedJSXSideEffects(t, "", "React.createElement(\"a\", null);\n") expectPrintedJSXSideEffects(t, "<>", "React.createElement(React.Fragment, null);\n")