babel-plugin-jsx-dom-expressions 0.36.0-beta.2 → 0.36.0-beta.4

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 +82 -58
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -600,6 +600,45 @@ function canNativeSpread(key, { checkNameSpaces } = {}) {
600
600
  return true;
601
601
  }
602
602
 
603
+ const BlockElements = [
604
+ "address",
605
+ "article",
606
+ "aside",
607
+ "blockquote",
608
+ "canvas",
609
+ "dd",
610
+ "div",
611
+ "dl",
612
+ "dt",
613
+ "fieldset",
614
+ "figcaption",
615
+ "figure",
616
+ "footer",
617
+ "form",
618
+ "h1",
619
+ "h2",
620
+ "h3",
621
+ "h4",
622
+ "h5",
623
+ "h6",
624
+ "header",
625
+ "hgroup",
626
+ "hr",
627
+ "li",
628
+ "main",
629
+ "nav",
630
+ "noscript",
631
+ "ol",
632
+ "output",
633
+ "p",
634
+ "pre",
635
+ "section",
636
+ "table",
637
+ "tfoot",
638
+ "ul",
639
+ "video"
640
+ ];
641
+
603
642
  function transformElement$3(path, info) {
604
643
  let tagName = getTagName(path.node),
605
644
  config = getConfig(path),
@@ -646,8 +685,14 @@ function transformElement$3(path, info) {
646
685
  }
647
686
  results.template += ">";
648
687
  if (!voidTag) {
688
+ const toBeClosed = !info.lastElement || (info.toBeClosed && info.toBeClosed.includes(tagName));
689
+ if (toBeClosed) {
690
+ results.toBeClosed = info.toBeClosed || [];
691
+ results.toBeClosed.push(tagName);
692
+ if (tagName === "a") results.toBeClosed.push(...BlockElements);
693
+ }
649
694
  transformChildren$2(path, results, config);
650
- results.template += `</${tagName}>`;
695
+ if (toBeClosed) results.template += `</${tagName}>`;
651
696
  }
652
697
  if (info.topLevel && config.hydratable && results.hasHydratableEvent) {
653
698
  let runHydrationEvents = registerImportMethod(
@@ -1185,10 +1230,19 @@ function transformAttributes$2(path, results) {
1185
1230
  t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild")))
1186
1231
  );
1187
1232
  }
1188
- results.dynamics.push({ elem: nextElem, key, value: value.expression, isSVG, isCE, tagName });
1233
+ results.dynamics.push({
1234
+ elem: nextElem,
1235
+ key,
1236
+ value: value.expression,
1237
+ isSVG,
1238
+ isCE,
1239
+ tagName
1240
+ });
1189
1241
  } else {
1190
1242
  results.exprs.push(
1191
- t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value.expression, { isSVG, isCE, tagName }))
1243
+ t__namespace.expressionStatement(
1244
+ setAttr$2(attribute, elem, key, value.expression, { isSVG, isCE, tagName })
1245
+ )
1192
1246
  );
1193
1247
  }
1194
1248
  } else {
@@ -1230,6 +1284,8 @@ function transformChildren$2(path, results, config) {
1230
1284
  );
1231
1285
  }
1232
1286
  const transformed = transformNode(child, {
1287
+ toBeClosed: results.toBeClosed,
1288
+ lastElement: index === filteredChildren.length - 1,
1233
1289
  skipId: !results.id || !detectExpressions(filteredChildren, index, config)
1234
1290
  });
1235
1291
  if (!transformed) return memo;
@@ -1496,7 +1552,9 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
1496
1552
  runningObject.push(
1497
1553
  t__namespace.objectProperty(
1498
1554
  t__namespace.stringLiteral(key),
1499
- isContainer ? node.value.expression : node.value || (Properties.has(key) ? t__namespace.booleanLiteral(true) : t__namespace.stringLiteral(""))
1555
+ isContainer
1556
+ ? node.value.expression
1557
+ : node.value || (Properties.has(key) ? t__namespace.booleanLiteral(true) : t__namespace.stringLiteral(""))
1500
1558
  )
1501
1559
  );
1502
1560
  }
@@ -1566,10 +1624,11 @@ function appendTemplates$1(path, templates) {
1566
1624
  t__namespace.addComment(
1567
1625
  t__namespace.callExpression(
1568
1626
  registerImportMethod(path, "template", getRendererConfig(path, "dom").moduleName),
1569
- [
1570
- t__namespace.templateLiteral([t__namespace.templateElement(tmpl, true)], []),
1571
- t__namespace.numericLiteral(template.elementCount)
1572
- ].concat(template.isSVG ? t__namespace.booleanLiteral(template.isSVG) : [])
1627
+ [t__namespace.templateLiteral([t__namespace.templateElement(tmpl, true)], [])].concat(
1628
+ template.isSVG || template.isCE
1629
+ ? [t__namespace.booleanLiteral(template.isSVG), t__namespace.booleanLiteral(template.isCE)]
1630
+ : []
1631
+ )
1573
1632
  ),
1574
1633
  "leading",
1575
1634
  "#__PURE__"
@@ -1595,8 +1654,8 @@ function registerTemplate(path, results) {
1595
1654
  templates.push({
1596
1655
  id: templateId,
1597
1656
  template: results.template,
1598
- elementCount: results.template.split("<").length - 1,
1599
1657
  isSVG: results.isSVG,
1658
+ isCE: results.hasCustomElement,
1600
1659
  renderer: "dom"
1601
1660
  });
1602
1661
  }
@@ -1608,22 +1667,7 @@ function registerTemplate(path, results) {
1608
1667
  registerImportMethod(path, "getNextElement", getRendererConfig(path, "dom").moduleName),
1609
1668
  templateId ? [templateId] : []
1610
1669
  )
1611
- : results.hasCustomElement
1612
- ? t__namespace.callExpression(
1613
- registerImportMethod(path, "untrack", getRendererConfig(path, "dom").moduleName),
1614
- [
1615
- t__namespace.arrowFunctionExpression(
1616
- [],
1617
- t__namespace.callExpression(
1618
- t__namespace.memberExpression(t__namespace.identifier("document"), t__namespace.identifier("importNode")),
1619
- [templateId, t__namespace.booleanLiteral(true)]
1620
- )
1621
- )
1622
- ]
1623
- )
1624
- : t__namespace.callExpression(t__namespace.memberExpression(templateId, t__namespace.identifier("cloneNode")), [
1625
- t__namespace.booleanLiteral(true)
1626
- ])
1670
+ : t__namespace.callExpression(templateId, [])
1627
1671
  );
1628
1672
  }
1629
1673
  results.declarations.unshift(decl);
@@ -1682,7 +1726,13 @@ function wrapDynamics$1(path, dynamics) {
1682
1726
  t__namespace.assignmentExpression(
1683
1727
  "=",
1684
1728
  prev,
1685
- setAttr$2(path, elem, key, identifier, { isSVG, isCE, tagName, dynamic: true, prevId: prev })
1729
+ setAttr$2(path, elem, key, identifier, {
1730
+ isSVG,
1731
+ isCE,
1732
+ tagName,
1733
+ dynamic: true,
1734
+ prevId: prev
1735
+ })
1686
1736
  )
1687
1737
  )
1688
1738
  );
@@ -3019,7 +3069,8 @@ function transformComponentChildren(children, config) {
3019
3069
  } else {
3020
3070
  const child = transformNode(path, {
3021
3071
  topLevel: true,
3022
- componentChild: true
3072
+ componentChild: true,
3073
+ lastElement: true
3023
3074
  });
3024
3075
  dynamic = dynamic || child.dynamic;
3025
3076
  if (
@@ -3058,43 +3109,15 @@ function transformComponentChildren(children, config) {
3058
3109
  return [transformedChildren, dynamic];
3059
3110
  }
3060
3111
 
3061
- function insertMarker(path, config, result) {
3062
- if (config.generate === "ssr") {
3063
- const open = { template: "<!---->", exprs: [] };
3064
- result.push(getCreateTemplate(config, path, open)(path, open, true));
3065
- } else {
3066
- result.push(t__namespace.stringLiteral("<!>"));
3067
- }
3068
- }
3069
-
3070
3112
  function transformFragmentChildren(children, results, config) {
3071
- let prevResult;
3072
3113
  const filteredChildren = filterChildren(children),
3073
3114
  childNodes = filteredChildren.reduce((memo, path) => {
3074
3115
  if (t__namespace.isJSXText(path.node)) {
3075
3116
  const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
3076
- if (v.length) {
3077
- if (config.hydratable &&
3078
- prevResult &&
3079
- !prevResult.tagName &&
3080
- !prevResult.component &&
3081
- prevResult.exprs.length &&
3082
- !prevResult.spreadElement) insertMarker(path, config, memo);
3083
- memo.push(t__namespace.stringLiteral(v));
3084
- prevResult = v;
3085
- }
3117
+ if (v.length) memo.push(t__namespace.stringLiteral(v));
3086
3118
  } else {
3087
- const child = transformNode(path, { topLevel: true, fragmentChild: true });
3088
- const insertMarkers =
3089
- config.hydratable &&
3090
- !child.component &&
3091
- child.exprs.length &&
3092
- !child.spreadElement &&
3093
- prevResult &&
3094
- (typeof prevResult !== "object" || !(prevResult.tagName || prevResult.component));
3095
- if (insertMarkers) insertMarker(path, config, memo);
3119
+ const child = transformNode(path, { topLevel: true, fragmentChild: true, lastElement: true });
3096
3120
  memo.push(getCreateTemplate(config, path, child)(path, child, true));
3097
- prevResult = child;
3098
3121
  }
3099
3122
  return memo;
3100
3123
  }, []);
@@ -3109,7 +3132,8 @@ function transformJSX(path) {
3109
3132
  t__namespace.isJSXFragment(path.node)
3110
3133
  ? {}
3111
3134
  : {
3112
- topLevel: true
3135
+ topLevel: true,
3136
+ lastElement: true
3113
3137
  }
3114
3138
  );
3115
3139
 
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.0-beta.2",
4
+ "version": "0.36.0-beta.4",
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": "3afd7a16f14cae485c63e6227492bb6ed151d1b3"
34
+ "gitHead": "d2c4d6692be78ba505be59d77ac14aa215c7b232"
35
35
  }