babel-plugin-jsx-dom-expressions 0.32.17 → 0.33.8

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 +48 -33
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -55,11 +55,11 @@ const booleans = [
55
55
  "selected"
56
56
  ];
57
57
 
58
- const BooleanAttributes = new Set(booleans);
58
+ const BooleanAttributes = /*#__PURE__*/ new Set(booleans);
59
59
 
60
- const Properties = new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]);
60
+ const Properties = /*#__PURE__*/ new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]);
61
61
 
62
- const ChildProperties = new Set(["innerHTML", "textContent", "innerText", "children"]);
62
+ const ChildProperties = /*#__PURE__*/ new Set(["innerHTML", "textContent", "innerText", "children"]);
63
63
 
64
64
  // React Compat
65
65
  const Aliases = {
@@ -77,7 +77,7 @@ const PropAliases = {
77
77
  };
78
78
 
79
79
  // list of Element events that will be delegated
80
- const DelegatedEvents = new Set([
80
+ const DelegatedEvents = /*#__PURE__*/ new Set([
81
81
  "beforeinput",
82
82
  "click",
83
83
  "dblclick",
@@ -102,7 +102,7 @@ const DelegatedEvents = new Set([
102
102
  "touchstart"
103
103
  ]);
104
104
 
105
- const SVGElements = new Set([
105
+ const SVGElements = /*#__PURE__*/ new Set([
106
106
  // "a",
107
107
  "altGlyph",
108
108
  "altGlyphDef",
@@ -526,6 +526,7 @@ function transformElement$3(path, info) {
526
526
  config = getConfig(path),
527
527
  wrapSVG = info.topLevel && tagName != "svg" && SVGElements.has(tagName),
528
528
  voidTag = VoidElements.indexOf(tagName) > -1,
529
+ isCustomElement = tagName.indexOf("-") > -1,
529
530
  results = {
530
531
  template: `<${tagName}`,
531
532
  decl: [],
@@ -533,6 +534,7 @@ function transformElement$3(path, info) {
533
534
  dynamics: [],
534
535
  postExprs: [],
535
536
  isSVG: wrapSVG,
537
+ hasCustomElement: isCustomElement,
536
538
  tagName,
537
539
  renderer: "dom"
538
540
  };
@@ -540,7 +542,7 @@ function transformElement$3(path, info) {
540
542
  if (wrapSVG) results.template = "<svg>" + results.template;
541
543
  if (!info.skipId) results.id = path.scope.generateUidIdentifier("el$");
542
544
  transformAttributes$2(path, results);
543
- if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1)) {
545
+ if (config.contextToCustomElements && (tagName === "slot" || isCustomElement)) {
544
546
  contextToCustomElement(path, results);
545
547
  }
546
548
  results.template += ">";
@@ -594,7 +596,7 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
594
596
  }
595
597
 
596
598
  if (!isSVG && name === "class") {
597
- return t__namespace.assignmentExpression("=", t__namespace.memberExpression(elem, t__namespace.identifier("className")), value);
599
+ return t__namespace.callExpression(registerImportMethod(path, "className", getRendererConfig(path, "dom").moduleName), [elem, value]);
598
600
  }
599
601
 
600
602
  if (name === "classList") {
@@ -1148,6 +1150,7 @@ function transformChildren$2(path, results, config) {
1148
1150
  results.exprs.push(...child.exprs);
1149
1151
  results.dynamics.push(...child.dynamics);
1150
1152
  results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
1153
+ results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
1151
1154
  tempPath = child.id.name;
1152
1155
  nextPlaceholder = null;
1153
1156
  i++;
@@ -1376,6 +1379,10 @@ function registerTemplate(path, results) {
1376
1379
  registerImportMethod(path, "getNextElement", getRendererConfig(path, "dom").moduleName),
1377
1380
  templateId ? [templateId] : []
1378
1381
  )
1382
+ : results.hasCustomElement
1383
+ ? t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier("document"), t__namespace.identifier("importNode")), [
1384
+ templateId, t__namespace.booleanLiteral(true)
1385
+ ])
1379
1386
  : t__namespace.callExpression(t__namespace.memberExpression(templateId, t__namespace.identifier("cloneNode")), [
1380
1387
  t__namespace.booleanLiteral(true)
1381
1388
  ])
@@ -1396,7 +1403,9 @@ function wrapDynamics$1(path, dynamics) {
1396
1403
  dynamics[0].key === "classList" || dynamics[0].key === "style"
1397
1404
  ? t__namespace.identifier("_$p")
1398
1405
  : undefined;
1399
-
1406
+ if (dynamics[0].key.startsWith("class:") && !t__namespace.isBooleanLiteral(dynamics[0].value) && !t__namespace.isUnaryExpression(dynamics[0].value)) {
1407
+ dynamics[0].value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", dynamics[0].value));
1408
+ }
1400
1409
  return t__namespace.expressionStatement(
1401
1410
  t__namespace.callExpression(effectWrapperId, [
1402
1411
  t__namespace.arrowFunctionExpression(
@@ -1417,7 +1426,9 @@ function wrapDynamics$1(path, dynamics) {
1417
1426
  prevId = t__namespace.identifier("_p$");
1418
1427
  dynamics.forEach(({ elem, key, value, isSVG, isCE }) => {
1419
1428
  const identifier = path.scope.generateUidIdentifier("v$");
1420
- identifiers.push(identifier);
1429
+ if (key.startsWith("class:") && !t__namespace.isBooleanLiteral(value) && !t__namespace.isUnaryExpression(value)) {
1430
+ value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
1431
+ } identifiers.push(identifier);
1421
1432
  decls.push(t__namespace.variableDeclarator(identifier, value));
1422
1433
  if (key === "classList" || key === "style") {
1423
1434
  const prev = t__namespace.memberExpression(prevId, identifier);
@@ -1557,7 +1568,7 @@ function toAttribute(key, isSVG) {
1557
1568
  return key;
1558
1569
  }
1559
1570
 
1560
- function setAttr$1(results, name, value, isSVG) {
1571
+ function setAttr$1(attribute, results, name, value, isSVG) {
1561
1572
  // strip out namespaces for now, everything at this point is an attribute
1562
1573
  let parts;
1563
1574
  if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
@@ -1565,9 +1576,18 @@ function setAttr$1(results, name, value, isSVG) {
1565
1576
  }
1566
1577
 
1567
1578
  name = toAttribute(name, isSVG);
1568
- appendToTemplate(results.template, ` ${name}="`);
1569
- results.template.push(`"`);
1570
- results.templateValues.push(value);
1579
+ const attr = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
1580
+ t__namespace.stringLiteral(name),
1581
+ value,
1582
+ t__namespace.booleanLiteral(false)
1583
+ ]);
1584
+ if (results.template[results.template.length - 1].length) {
1585
+ results.template.push("");
1586
+ results.templateValues.push(attr);
1587
+ } else {
1588
+ const last = results.templateValues.length - 1;
1589
+ results.templateValues[last] = t__namespace.binaryExpression("+", results.templateValues[last], attr);
1590
+ }
1571
1591
  }
1572
1592
 
1573
1593
  function escapeExpression(path, expression, attr) {
@@ -1698,6 +1718,7 @@ function transformAttributes$1(path, results) {
1698
1718
  }
1699
1719
  i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
1700
1720
  }
1721
+ first.name = t__namespace.JSXIdentifier("class");
1701
1722
  first.value = t__namespace.JSXExpressionContainer(t__namespace.TemplateLiteral(quasis, values));
1702
1723
  }
1703
1724
  if (styleAttributes.length) transformToObject("style", attributes, styleAttributes);
@@ -1754,23 +1775,15 @@ function transformAttributes$1(path, results) {
1754
1775
  children = value;
1755
1776
  if (key === "innerHTML") path.doNotEscape = true;
1756
1777
  } else {
1757
- let dynamic = false,
1758
- doEscape = true;
1759
- if (
1760
- isDynamic(attribute.get("value").get("expression"), {
1761
- checkMember: true,
1762
- native: true
1763
- })
1764
- )
1765
- dynamic = true;
1766
-
1778
+ let doEscape = true;
1767
1779
  if (BooleanAttributes.has(key)) {
1768
1780
  results.template.push("");
1769
- const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrBoolean"), [
1781
+ const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
1770
1782
  t__namespace.stringLiteral(key),
1771
- value.expression
1783
+ value.expression,
1784
+ t__namespace.booleanLiteral(true)
1772
1785
  ]);
1773
- results.templateValues.push(dynamic ? t__namespace.arrowFunctionExpression([], fn) : fn);
1786
+ results.templateValues.push(fn);
1774
1787
  return;
1775
1788
  }
1776
1789
  if (key === "style") {
@@ -1829,13 +1842,15 @@ function transformAttributes$1(path, results) {
1829
1842
  key = "class";
1830
1843
  doEscape = false;
1831
1844
  }
1832
- if (dynamic)
1833
- value.expression = t__namespace.arrowFunctionExpression(
1834
- [],
1835
- doEscape ? escapeExpression(path, value.expression, true) : value.expression
1836
- );
1837
- else if (doEscape) value.expression = escapeExpression(path, value.expression, true);
1838
- setAttr$1(results, key, value.expression, isSVG);
1845
+ if (doEscape)
1846
+ value.expression = escapeExpression(path, value.expression, true);
1847
+
1848
+ if (!doEscape || t__namespace.isLiteral(value.expression) || t__namespace.isBinaryExpression(value.expression)) {
1849
+ key = toAttribute(key, isSVG);
1850
+ appendToTemplate(results.template, ` ${key}="`);
1851
+ results.template.push(`"`);
1852
+ results.templateValues.push(value.expression);
1853
+ } else setAttr$1(attribute, results, key, value.expression, isSVG);
1839
1854
  }
1840
1855
  } else {
1841
1856
  if (key === "$ServerOnly") return;
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.32.17",
4
+ "version": "0.33.8",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -23,5 +23,5 @@
23
23
  "@babel/types": "^7.16.0",
24
24
  "html-entities": "2.3.2"
25
25
  },
26
- "gitHead": "44833242fc589628431ee04aa8d319f424ba4845"
26
+ "gitHead": "22e8d3ae8c8eb50596fce778c5b9116880cc55c2"
27
27
  }