babel-plugin-jsx-dom-expressions 0.36.0 → 0.36.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 +7 -4
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -600,6 +600,8 @@ function canNativeSpread(key, { checkNameSpaces } = {}) {
600
600
  return true;
601
601
  }
602
602
 
603
+ const alwaysClose = ["a", "table", "b", "strong", "small", "i", "em"];
604
+
603
605
  const BlockElements = [
604
606
  "address",
605
607
  "article",
@@ -685,9 +687,10 @@ function transformElement$3(path, info) {
685
687
  }
686
688
  results.template += ">";
687
689
  if (!voidTag) {
690
+ // always close tags can still be skipped if they have no parents and are the last element
688
691
  const toBeClosed = !info.lastElement || (info.toBeClosed && info.toBeClosed.includes(tagName));
689
692
  if (toBeClosed) {
690
- results.toBeClosed = info.toBeClosed || [];
693
+ results.toBeClosed = info.toBeClosed || [...alwaysClose];
691
694
  results.toBeClosed.push(tagName);
692
695
  if (tagName === "a") results.toBeClosed.push(...BlockElements);
693
696
  }
@@ -1279,11 +1282,11 @@ function transformAttributes$2(path, results) {
1279
1282
  results.hasHydratableEvent = results.hasHydratableEvent || hasHydratableEvent;
1280
1283
  }
1281
1284
 
1282
- function findLastElement(children) {
1285
+ function findLastElement(children, hydratable) {
1283
1286
  let lastElement = -1, tagName;
1284
1287
  for (let i = children.length - 1; i >= 0; i--) {
1285
1288
  const node = children[i].node;
1286
- if (t__namespace.isJSXText(node) || getStaticExpression(children[i]) || (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName))) {
1289
+ if (hydratable || t__namespace.isJSXText(node) || getStaticExpression(children[i]) || (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName))) {
1287
1290
  lastElement = i;
1288
1291
  break;
1289
1292
  }
@@ -1297,7 +1300,7 @@ function transformChildren$2(path, results, config) {
1297
1300
  nextPlaceholder,
1298
1301
  i = 0;
1299
1302
  const filteredChildren = filterChildren(path.get("children")),
1300
- lastElement = findLastElement(filteredChildren),
1303
+ lastElement = findLastElement(filteredChildren, config.hydratable),
1301
1304
  childNodes = filteredChildren.reduce((memo, child, index) => {
1302
1305
  if (child.isJSXFragment()) {
1303
1306
  throw new Error(
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",
4
+ "version": "0.36.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": "05dd73bfadd2bb1b7369764d0d1196f5dc276493"
34
+ "gitHead": "af84575bb87dbb1e403cb79b2b0a55348d295237"
35
35
  }