Thanks to visit codestin.com
Credit goes to github.com

Skip to content

HTML Entities-encoded whitespace gets trimmed in JSX #17683

@webstrand

Description

@webstrand

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

REPL

<example>
  foo
  <hr />&#32;
  bar
</example>;

Configuration file name

No response

Configuration

{
  "filename": "repl.jsx",
  "presets": [
    ["react", { "runtime": "automatic" }]
  ]
}

Current and expected behavior

Any number of leading or trailing whitespace characters encoded with HTML entities are stripped from JSX. This includes not only (space) but (tab), (newline), and (carriage return). These characters should normally be stripped when unencoded, but when encoded using HTML Entities they should not be stripped, the programmer added them intentionally.

Current Output:

/*#__PURE__*/_jsxs("example", {
  children: ["foo", /*#__PURE__*/_jsx("hr", {}), "bar"]
});

Expected Output:

/*#__PURE__*/_jsxs("example", {
  children: ["foo", /*#__PURE__*/_jsx("hr", {}), " bar"]
});

Whitespace created by HTML Entities is preserved.

Environment

REPL

Possible solution

Decoding HTML Entities should be performed after trimming the string, not before.

Additional context

esbuild and tsc preserve these characters when encoded as html entities. swc does not swc-project/swc#11392.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions