babel-plugin-jsx-dom-expressions 0.36.4 → 0.36.6

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 +129 -19
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -600,15 +600,70 @@ function canNativeSpread(key, { checkNameSpaces } = {}) {
600
600
  return true;
601
601
  }
602
602
 
603
- const alwaysClose = ["a", "table", "button", "textarea", "select", "b", "strong", "small", "i", "em"];
603
+ const InlineElements = [
604
+ "a",
605
+ "abbr",
606
+ "acronym",
607
+ "b",
608
+ "bdi",
609
+ "bdo",
610
+ "big",
611
+ "br",
612
+ "button",
613
+ "canvas",
614
+ "cite",
615
+ "code",
616
+ "data",
617
+ "datalist",
618
+ "del",
619
+ "dfn",
620
+ "em",
621
+ "embed",
622
+ "i",
623
+ "iframe",
624
+ "img",
625
+ "input",
626
+ "ins",
627
+ "kbd",
628
+ "label",
629
+ "map",
630
+ "mark",
631
+ "meter",
632
+ "noscript",
633
+ "object",
634
+ "output",
635
+ "picture",
636
+ "progress",
637
+ "q",
638
+ "ruby",
639
+ "s",
640
+ "samp",
641
+ "script",
642
+ "select",
643
+ "slot",
644
+ "small",
645
+ "span",
646
+ "strong",
647
+ "sub",
648
+ "sup",
649
+ "svg",
650
+ "template",
651
+ "textarea",
652
+ "time",
653
+ "u",
654
+ "tt",
655
+ "var",
656
+ "video"
657
+ ];
604
658
 
605
659
  const BlockElements = [
606
660
  "address",
607
661
  "article",
608
662
  "aside",
609
663
  "blockquote",
610
- "canvas",
611
664
  "dd",
665
+ "details",
666
+ "dialog",
612
667
  "div",
613
668
  "dl",
614
669
  "dt",
@@ -628,17 +683,36 @@ const BlockElements = [
628
683
  "hr",
629
684
  "li",
630
685
  "main",
686
+ "menu",
631
687
  "nav",
632
- "noscript",
633
688
  "ol",
634
- "output",
635
689
  "p",
636
690
  "pre",
637
691
  "section",
638
692
  "table",
639
- "tfoot",
640
693
  "ul",
641
- "video"
694
+ ];
695
+
696
+ const alwaysClose = [
697
+ "title",
698
+ "style",
699
+ "a",
700
+ "strong",
701
+ "small",
702
+ "b",
703
+ "u",
704
+ "i",
705
+ "em",
706
+ "s",
707
+ "code",
708
+ "object",
709
+ "table",
710
+ "button",
711
+ "textarea",
712
+ "select",
713
+ "iframe",
714
+ "script",
715
+ "template"
642
716
  ];
643
717
 
644
718
  function transformElement$3(path, info) {
@@ -687,12 +761,12 @@ function transformElement$3(path, info) {
687
761
  }
688
762
  results.template += ">";
689
763
  if (!voidTag) {
690
- // always close tags can still be skipped if they have no parents and are the last element
691
- const toBeClosed = !info.lastElement || (info.toBeClosed && info.toBeClosed.includes(tagName));
764
+ // always close tags can still be skipped if they have no closing parents and are the last element
765
+ const toBeClosed = !info.lastElement || (info.toBeClosed && info.toBeClosed.has(tagName));
692
766
  if (toBeClosed) {
693
- results.toBeClosed = info.toBeClosed || [...alwaysClose];
694
- results.toBeClosed.push(tagName);
695
- if (tagName === "a") results.toBeClosed.push(...BlockElements);
767
+ results.toBeClosed = new Set(info.toBeClosed || alwaysClose);
768
+ results.toBeClosed.add(tagName);
769
+ if (InlineElements.includes(tagName)) results.toBeClosed.add(...BlockElements);
696
770
  }
697
771
  transformChildren$2(path, results, config);
698
772
  if (toBeClosed) results.template += `</${tagName}>`;
@@ -718,13 +792,42 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE, tagN
718
792
  namespace = parts[0];
719
793
  }
720
794
 
795
+ // TODO: consider moving to a helper
721
796
  if (namespace === "style") {
722
- return t__namespace.callExpression(
723
- t__namespace.memberExpression(
724
- t__namespace.memberExpression(elem, t__namespace.identifier("style")),
725
- t__namespace.identifier("setProperty")
797
+ if (t__namespace.isStringLiteral(value)) {
798
+ return t__namespace.callExpression(
799
+ t__namespace.memberExpression(
800
+ t__namespace.memberExpression(elem, t__namespace.identifier("style")),
801
+ t__namespace.identifier("setProperty")
802
+ ),
803
+ [t__namespace.stringLiteral(name), value]
804
+ );
805
+ }
806
+ if (t__namespace.isNullLiteral(value) || t__namespace.isIdentifier(value, { name: "undefined" })) {
807
+ return t__namespace.callExpression(
808
+ t__namespace.memberExpression(
809
+ t__namespace.memberExpression(elem, t__namespace.identifier("style")),
810
+ t__namespace.identifier("removeProperty")
811
+ ),
812
+ [t__namespace.stringLiteral(name)]
813
+ );
814
+ }
815
+ return t__namespace.conditionalExpression(
816
+ t__namespace.binaryExpression("!=", value, t__namespace.nullLiteral()),
817
+ t__namespace.callExpression(
818
+ t__namespace.memberExpression(
819
+ t__namespace.memberExpression(elem, t__namespace.identifier("style")),
820
+ t__namespace.identifier("setProperty")
821
+ ),
822
+ [t__namespace.stringLiteral(name), prevId ? prevId : value]
726
823
  ),
727
- [t__namespace.stringLiteral(name), value]
824
+ t__namespace.callExpression(
825
+ t__namespace.memberExpression(
826
+ t__namespace.memberExpression(elem, t__namespace.identifier("style")),
827
+ t__namespace.identifier("removeProperty")
828
+ ),
829
+ [t__namespace.stringLiteral(name)]
830
+ )
728
831
  );
729
832
  }
730
833
 
@@ -1283,10 +1386,16 @@ function transformAttributes$2(path, results) {
1283
1386
  }
1284
1387
 
1285
1388
  function findLastElement(children, hydratable) {
1286
- let lastElement = -1, tagName;
1389
+ let lastElement = -1,
1390
+ tagName;
1287
1391
  for (let i = children.length - 1; i >= 0; i--) {
1288
1392
  const node = children[i].node;
1289
- if (hydratable || t__namespace.isJSXText(node) || getStaticExpression(children[i]) || (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName))) {
1393
+ if (
1394
+ hydratable ||
1395
+ t__namespace.isJSXText(node) ||
1396
+ getStaticExpression(children[i]) ||
1397
+ (t__namespace.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName))
1398
+ ) {
1290
1399
  lastElement = i;
1291
1400
  break;
1292
1401
  }
@@ -1761,6 +1870,7 @@ function wrapDynamics$1(path, dynamics) {
1761
1870
  )
1762
1871
  );
1763
1872
  } else {
1873
+ const prev = key.startsWith("style:") ? identifier : undefined;
1764
1874
  statements.push(
1765
1875
  t__namespace.expressionStatement(
1766
1876
  t__namespace.logicalExpression(
@@ -1771,7 +1881,7 @@ function wrapDynamics$1(path, dynamics) {
1771
1881
  elem,
1772
1882
  key,
1773
1883
  t__namespace.assignmentExpression("=", t__namespace.memberExpression(prevId, identifier), identifier),
1774
- { isSVG, isCE, tagName, dynamic: true }
1884
+ { isSVG, isCE, tagName, dynamic: true, prevId: prev }
1775
1885
  )
1776
1886
  )
1777
1887
  )
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.4",
4
+ "version": "0.36.6",
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": "44549c307893921bbcb393f9edb24363421f536c"
34
+ "gitHead": "35c4a68d712cb008adf5e37bc0fd79d7e941491b"
35
35
  }