babel-plugin-jsx-dom-expressions 0.36.18 → 0.37.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +42 -5
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1068,6 +1068,8 @@ function transformAttributes$2(path, results) {
1068
1068
  attributes.map(a => a.node)
1069
1069
  );
1070
1070
 
1071
+ let needsSpacing = true;
1072
+
1071
1073
  path
1072
1074
  .get("openingElement")
1073
1075
  .get("attributes")
@@ -1365,16 +1367,51 @@ function transformAttributes$2(path, results) {
1365
1367
  );
1366
1368
  } else {
1367
1369
  !isSVG && (key = key.toLowerCase());
1368
- results.template += ` ${key}`;
1370
+ results.template += `${needsSpacing ? ' ' : ''}${key}`;
1369
1371
  if (!value) return;
1372
+
1370
1373
  let text = value.value;
1374
+ let needsQuoting = false;
1375
+
1371
1376
  if (key === "style" || key === "class") {
1372
1377
  text = trimWhitespace(text);
1373
1378
  if (key === "style") {
1374
1379
  text = text.replace(/; /g, ";").replace(/: /g, ":");
1375
1380
  }
1376
1381
  }
1377
- results.template += `="${escapeBackticks(escapeHTML(text, true))}"`;
1382
+
1383
+ if (!text.length) {
1384
+ results.template += `=""`;
1385
+ return;
1386
+ }
1387
+
1388
+ for (let i = 0, len = text.length; i < len; i++) {
1389
+ let char = text[i];
1390
+
1391
+ if (
1392
+ char === "'" ||
1393
+ char === '"' ||
1394
+ char === " " ||
1395
+ char === "\t" ||
1396
+ char === "\n" ||
1397
+ char === "\r" ||
1398
+ char === "`" ||
1399
+ char === "=" ||
1400
+ char === "<" ||
1401
+ char === ">"
1402
+ ) {
1403
+ needsQuoting = true;
1404
+ }
1405
+ }
1406
+
1407
+ if (needsQuoting) {
1408
+
1409
+ needsSpacing = false;
1410
+ results.template += `="${escapeBackticks(escapeHTML(text, true))}"`;
1411
+ } else {
1412
+ needsSpacing = true;
1413
+ results.template += `=${escapeBackticks(escapeHTML(text, true))}`;
1414
+ }
1378
1415
  }
1379
1416
  }
1380
1417
  });
@@ -1496,7 +1533,7 @@ function transformChildren$2(path, results, config) {
1496
1533
  // boxed by textNodes
1497
1534
  if (markers || wrappedByText(childNodes, index)) {
1498
1535
  let exprId, contentId;
1499
- if (markers) tempPath = createPlaceholder(path, results, tempPath, i++, "#")[0].name;
1536
+ if (markers) tempPath = createPlaceholder(path, results, tempPath, i++, "$")[0].name;
1500
1537
  if (nextPlaceholder) {
1501
1538
  exprId = nextPlaceholder;
1502
1539
  } else {
@@ -2421,7 +2458,7 @@ function transformChildren$1(path, results, { hydratable }) {
2421
2458
 
2422
2459
  // boxed by textNodes
2423
2460
  if (markers && !child.spreadElement) {
2424
- appendToTemplate(results.template, `<!--#-->`);
2461
+ appendToTemplate(results.template, `<!--$-->`);
2425
2462
  results.template.push("");
2426
2463
  results.templateValues.push(child.exprs[0]);
2427
2464
  appendToTemplate(results.template, `<!--/-->`);
@@ -2448,7 +2485,7 @@ function createElement(path, { topLevel, hydratable }) {
2448
2485
  } else {
2449
2486
  const child = transformNode(path);
2450
2487
  if (markers && child.exprs.length && !child.spreadElement)
2451
- memo.push(t__namespace.stringLiteral("<!--#-->"));
2488
+ memo.push(t__namespace.stringLiteral("<!--$-->"));
2452
2489
  if (child.exprs.length && !child.spreadElement)
2453
2490
  child.exprs[0] = escapeExpression(path, child.exprs[0]);
2454
2491
  memo.push(getCreateTemplate(config, path, child)(path, child, true));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "babel-plugin-jsx-dom-expressions",
3
3
  "description": "A JSX to DOM plugin that wraps expressions for fine grained change detection",
4
- "version": "0.36.18",
4
+ "version": "0.37.0-beta.2",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -31,5 +31,5 @@
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.20.12"
33
33
  },
34
- "gitHead": "70ab5bf1b167c0a3cefd0a3582c0b97f502bb92b"
34
+ "gitHead": "bc79e4f6f883b6a1f6f1a68482f5720945c6dcc0"
35
35
  }