Skip to content

Commit

Permalink
better use String(text) and needSpace/isLast seems not needed here
Browse files Browse the repository at this point in the history
  • Loading branch information
titoBouzout committed Jan 24, 2025
1 parent 7cae003 commit 108dcf2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions packages/babel-plugin-jsx-dom-expressions/src/ssr/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,7 @@ function transformAttributes(path, results, info) {
attributes = normalizeAttributes(path);
let children;

attributes.forEach((attribute, i) => {
const isLast = attributes.length - 1 === i;

attributes.forEach(attribute => {
const node = attribute.node;

let value = node.value,
Expand Down Expand Up @@ -401,12 +399,8 @@ function transformAttributes(path, results, info) {

appendToTemplate(
results.template,
// `typeof text === "string"``is needed, `attr=10>` becomes `attr>` without it
typeof text === "string" && !text.length
? isLast
? ``
: ` `
: `="${escapeHTML(text, true)}"`
// `String(text)` is needed, as text.length will mess up `attr=10>` becomes `attr>` without it
String(text) === "" ? `` : `="${escapeHTML(text, true)}"`
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _tmpl$ = ['<a href="/" class="', '">Welcome</a>'],
_tmpl$21 = ["<button", "></button>"],
_tmpl$22 = '<input value="10">',
_tmpl$23 = ["<select", "><option", ">Red</option><option", ">Blue</option></select>"],
_tmpl$24 = ['<div a a a checked a="true" a="false" a="0" a a ', " a></div>"];
_tmpl$24 = ['<div a a a checked a="true" a="false" a="0" a a', " a></div>"];
import * as styles from "./styles.module.css";
const selected = true;
let id = "my-h1";
Expand Down

0 comments on commit 108dcf2

Please sign in to comment.