babel-plugin-jsx-dom-expressions 0.32.16 → 0.33.7

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 +43 -28
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -328,6 +328,7 @@ function getStaticExpression(path) {
328
328
  t__namespace.isJSXExpressionContainer(node) &&
329
329
  t__namespace.isJSXElement(path.parent) &&
330
330
  !isComponent(getTagName(path.parent)) &&
331
+ !t__namespace.isSequenceExpression(node.expression) &&
331
332
  (value = path.get("expression").evaluate().value) !== undefined &&
332
333
  ((type = typeof value) === "string" || type === "number") &&
333
334
  value
@@ -525,6 +526,7 @@ function transformElement$3(path, info) {
525
526
  config = getConfig(path),
526
527
  wrapSVG = info.topLevel && tagName != "svg" && SVGElements.has(tagName),
527
528
  voidTag = VoidElements.indexOf(tagName) > -1,
529
+ isCustomElement = tagName.indexOf("-") > -1,
528
530
  results = {
529
531
  template: `<${tagName}`,
530
532
  decl: [],
@@ -532,6 +534,7 @@ function transformElement$3(path, info) {
532
534
  dynamics: [],
533
535
  postExprs: [],
534
536
  isSVG: wrapSVG,
537
+ hasCustomElement: isCustomElement,
535
538
  tagName,
536
539
  renderer: "dom"
537
540
  };
@@ -539,7 +542,7 @@ function transformElement$3(path, info) {
539
542
  if (wrapSVG) results.template = "<svg>" + results.template;
540
543
  if (!info.skipId) results.id = path.scope.generateUidIdentifier("el$");
541
544
  transformAttributes$2(path, results);
542
- if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1)) {
545
+ if (config.contextToCustomElements && (tagName === "slot" || isCustomElement)) {
543
546
  contextToCustomElement(path, results);
544
547
  }
545
548
  results.template += ">";
@@ -593,7 +596,7 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
593
596
  }
594
597
 
595
598
  if (!isSVG && name === "class") {
596
- 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]);
597
600
  }
598
601
 
599
602
  if (name === "classList") {
@@ -1147,6 +1150,7 @@ function transformChildren$2(path, results, config) {
1147
1150
  results.exprs.push(...child.exprs);
1148
1151
  results.dynamics.push(...child.dynamics);
1149
1152
  results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
1153
+ results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
1150
1154
  tempPath = child.id.name;
1151
1155
  nextPlaceholder = null;
1152
1156
  i++;
@@ -1375,6 +1379,10 @@ function registerTemplate(path, results) {
1375
1379
  registerImportMethod(path, "getNextElement", getRendererConfig(path, "dom").moduleName),
1376
1380
  templateId ? [templateId] : []
1377
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
+ ])
1378
1386
  : t__namespace.callExpression(t__namespace.memberExpression(templateId, t__namespace.identifier("cloneNode")), [
1379
1387
  t__namespace.booleanLiteral(true)
1380
1388
  ])
@@ -1395,7 +1403,9 @@ function wrapDynamics$1(path, dynamics) {
1395
1403
  dynamics[0].key === "classList" || dynamics[0].key === "style"
1396
1404
  ? t__namespace.identifier("_$p")
1397
1405
  : undefined;
1398
-
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
+ }
1399
1409
  return t__namespace.expressionStatement(
1400
1410
  t__namespace.callExpression(effectWrapperId, [
1401
1411
  t__namespace.arrowFunctionExpression(
@@ -1416,7 +1426,9 @@ function wrapDynamics$1(path, dynamics) {
1416
1426
  prevId = t__namespace.identifier("_p$");
1417
1427
  dynamics.forEach(({ elem, key, value, isSVG, isCE }) => {
1418
1428
  const identifier = path.scope.generateUidIdentifier("v$");
1419
- 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);
1420
1432
  decls.push(t__namespace.variableDeclarator(identifier, value));
1421
1433
  if (key === "classList" || key === "style") {
1422
1434
  const prev = t__namespace.memberExpression(prevId, identifier);
@@ -1556,7 +1568,7 @@ function toAttribute(key, isSVG) {
1556
1568
  return key;
1557
1569
  }
1558
1570
 
1559
- function setAttr$1(results, name, value, isSVG) {
1571
+ function setAttr$1(attribute, results, name, value, isSVG) {
1560
1572
  // strip out namespaces for now, everything at this point is an attribute
1561
1573
  let parts;
1562
1574
  if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
@@ -1564,9 +1576,18 @@ function setAttr$1(results, name, value, isSVG) {
1564
1576
  }
1565
1577
 
1566
1578
  name = toAttribute(name, isSVG);
1567
- appendToTemplate(results.template, ` ${name}="`);
1568
- results.template.push(`"`);
1569
- 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
+ }
1570
1591
  }
1571
1592
 
1572
1593
  function escapeExpression(path, expression, attr) {
@@ -1753,23 +1774,15 @@ function transformAttributes$1(path, results) {
1753
1774
  children = value;
1754
1775
  if (key === "innerHTML") path.doNotEscape = true;
1755
1776
  } else {
1756
- let dynamic = false,
1757
- doEscape = true;
1758
- if (
1759
- isDynamic(attribute.get("value").get("expression"), {
1760
- checkMember: true,
1761
- native: true
1762
- })
1763
- )
1764
- dynamic = true;
1765
-
1777
+ let doEscape = true;
1766
1778
  if (BooleanAttributes.has(key)) {
1767
1779
  results.template.push("");
1768
- const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrBoolean"), [
1780
+ const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
1769
1781
  t__namespace.stringLiteral(key),
1770
- value.expression
1782
+ value.expression,
1783
+ t__namespace.booleanLiteral(true)
1771
1784
  ]);
1772
- results.templateValues.push(dynamic ? t__namespace.arrowFunctionExpression([], fn) : fn);
1785
+ results.templateValues.push(fn);
1773
1786
  return;
1774
1787
  }
1775
1788
  if (key === "style") {
@@ -1828,13 +1841,15 @@ function transformAttributes$1(path, results) {
1828
1841
  key = "class";
1829
1842
  doEscape = false;
1830
1843
  }
1831
- if (dynamic)
1832
- value.expression = t__namespace.arrowFunctionExpression(
1833
- [],
1834
- doEscape ? escapeExpression(path, value.expression, true) : value.expression
1835
- );
1836
- else if (doEscape) value.expression = escapeExpression(path, value.expression, true);
1837
- setAttr$1(results, key, value.expression, isSVG);
1844
+ if (doEscape)
1845
+ value.expression = escapeExpression(path, value.expression, true);
1846
+
1847
+ if (!doEscape || t__namespace.isLiteral(value.expression) || t__namespace.isBinaryExpression(value.expression)) {
1848
+ key = toAttribute(key, isSVG);
1849
+ appendToTemplate(results.template, ` ${key}="`);
1850
+ results.template.push(`"`);
1851
+ results.templateValues.push(value.expression);
1852
+ } else setAttr$1(attribute, results, key, value.expression, isSVG);
1838
1853
  }
1839
1854
  } else {
1840
1855
  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.16",
4
+ "version": "0.33.7",
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": "e8f40d02a9e46bf37be05662a7bcb19bd42126b1"
26
+ "gitHead": "adea58b5d73a28af4f95afcb4d05f2418433e696"
27
27
  }