babel-plugin-jsx-dom-expressions 0.33.0 → 0.33.10

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 +92 -72
  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 += ">";
@@ -590,26 +592,28 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
590
592
  }
591
593
 
592
594
  if (name === "style") {
593
- return t__namespace.callExpression(registerImportMethod(path, "style", getRendererConfig(path, "dom").moduleName), prevId ? [elem, value, prevId] : [elem, value]);
595
+ return t__namespace.callExpression(
596
+ registerImportMethod(path, "style", getRendererConfig(path, "dom").moduleName),
597
+ prevId ? [elem, value, prevId] : [elem, value]
598
+ );
594
599
  }
595
600
 
596
601
  if (!isSVG && name === "class") {
597
- return t__namespace.callExpression(registerImportMethod(path, "className", getRendererConfig(path, "dom").moduleName), [elem, value]);
602
+ return t__namespace.callExpression(
603
+ registerImportMethod(path, "className", getRendererConfig(path, "dom").moduleName),
604
+ [elem, value]
605
+ );
598
606
  }
599
607
 
600
608
  if (name === "classList") {
601
- return t__namespace.callExpression(registerImportMethod(
602
- path,
603
- "classList",
604
- getRendererConfig(path, "dom").moduleName
605
- ), prevId ? [elem, value, prevId] : [elem, value]);
609
+ return t__namespace.callExpression(
610
+ registerImportMethod(path, "classList", getRendererConfig(path, "dom").moduleName),
611
+ prevId ? [elem, value, prevId] : [elem, value]
612
+ );
606
613
  }
607
614
 
608
615
  if (config.hydratable && name === "innerHTML") {
609
- return t__namespace.callExpression(
610
- registerImportMethod(path, "innerHTML"),
611
- [elem, value]
612
- );
616
+ return t__namespace.callExpression(registerImportMethod(path, "innerHTML"), [elem, value]);
613
617
  }
614
618
 
615
619
  if (dynamic && name === "textContent") {
@@ -633,22 +637,15 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
633
637
  !isSVG && (name = name.toLowerCase());
634
638
  const ns = isNameSpaced && SVGNamespace[name.split(":")[0]];
635
639
  if (ns) {
636
- return t__namespace.callExpression(registerImportMethod(
637
- path,
638
- "setAttributeNS",
639
- getRendererConfig(path, "dom").moduleName
640
- ), [
641
- elem,
642
- t__namespace.stringLiteral(ns),
643
- t__namespace.stringLiteral(name),
644
- value
645
- ]);
640
+ return t__namespace.callExpression(
641
+ registerImportMethod(path, "setAttributeNS", getRendererConfig(path, "dom").moduleName),
642
+ [elem, t__namespace.stringLiteral(ns), t__namespace.stringLiteral(name), value]
643
+ );
646
644
  } else {
647
- return t__namespace.callExpression(registerImportMethod(
648
- path,
649
- "setAttribute",
650
- getRendererConfig(path, "dom").moduleName
651
- ), [elem, t__namespace.stringLiteral(name), value]);
645
+ return t__namespace.callExpression(
646
+ registerImportMethod(path, "setAttribute", getRendererConfig(path, "dom").moduleName),
647
+ [elem, t__namespace.stringLiteral(name), value]
648
+ );
652
649
  }
653
650
  }
654
651
 
@@ -808,22 +805,21 @@ function transformAttributes$2(path, results) {
808
805
  if (t__namespace.isJSXSpreadAttribute(node)) {
809
806
  results.exprs.push(
810
807
  t__namespace.expressionStatement(
811
- t__namespace.callExpression(registerImportMethod(
812
- attribute,
813
- "spread",
814
- getRendererConfig(path, "dom").moduleName
815
- ), [
816
- elem,
817
- isDynamic(attribute.get("argument"), {
818
- checkMember: true
819
- })
820
- ? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
821
- ? node.argument.callee
822
- : t__namespace.arrowFunctionExpression([], node.argument)
823
- : node.argument,
824
- t__namespace.booleanLiteral(isSVG),
825
- t__namespace.booleanLiteral(hasChildren)
826
- ])
808
+ t__namespace.callExpression(
809
+ registerImportMethod(attribute, "spread", getRendererConfig(path, "dom").moduleName),
810
+ [
811
+ elem,
812
+ isDynamic(attribute.get("argument"), {
813
+ checkMember: true
814
+ })
815
+ ? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
816
+ ? node.argument.callee
817
+ : t__namespace.arrowFunctionExpression([], node.argument)
818
+ : node.argument,
819
+ t__namespace.booleanLiteral(isSVG),
820
+ t__namespace.booleanLiteral(hasChildren)
821
+ ]
822
+ )
827
823
  )
828
824
  );
829
825
  //NOTE: can't be checked at compile time so add to compiled output
@@ -915,7 +911,7 @@ function transformAttributes$2(path, results) {
915
911
  }
916
912
  } else if (key.startsWith("use:")) {
917
913
  // Some trick to treat JSXIdentifier as Identifier
918
- node.name.name.type = 'Identifier';
914
+ node.name.name.type = "Identifier";
919
915
  results.exprs.unshift(
920
916
  t__namespace.expressionStatement(
921
917
  t__namespace.callExpression(node.name.name, [
@@ -992,16 +988,14 @@ function transformAttributes$2(path, results) {
992
988
  } else {
993
989
  results.exprs.unshift(
994
990
  t__namespace.expressionStatement(
995
- t__namespace.callExpression(registerImportMethod(
996
- path,
997
- "addEventListener",
998
- getRendererConfig(path, "dom").moduleName
999
- ), [
1000
- elem,
1001
- t__namespace.stringLiteral(ev),
1002
- handler,
1003
- t__namespace.booleanLiteral(true)
1004
- ])
991
+ t__namespace.callExpression(
992
+ registerImportMethod(
993
+ path,
994
+ "addEventListener",
995
+ getRendererConfig(path, "dom").moduleName
996
+ ),
997
+ [elem, t__namespace.stringLiteral(ev), handler, t__namespace.booleanLiteral(true)]
998
+ )
1005
999
  )
1006
1000
  );
1007
1001
  }
@@ -1035,11 +1029,14 @@ function transformAttributes$2(path, results) {
1035
1029
  } else {
1036
1030
  results.exprs.unshift(
1037
1031
  t__namespace.expressionStatement(
1038
- t__namespace.callExpression(registerImportMethod(
1039
- path,
1040
- "addEventListener",
1041
- getRendererConfig(path, "dom").moduleName
1042
- ), [elem, t__namespace.stringLiteral(ev), handler])
1032
+ t__namespace.callExpression(
1033
+ registerImportMethod(
1034
+ path,
1035
+ "addEventListener",
1036
+ getRendererConfig(path, "dom").moduleName
1037
+ ),
1038
+ [elem, t__namespace.stringLiteral(ev), handler]
1039
+ )
1043
1040
  )
1044
1041
  );
1045
1042
  }
@@ -1051,6 +1048,23 @@ function transformAttributes$2(path, results) {
1051
1048
  })
1052
1049
  ) {
1053
1050
  let nextElem = elem;
1051
+ if (key === "value" || key === "checked") {
1052
+ const effectWrapperId = registerImportMethod(path, config.effectWrapper);
1053
+ results.postExprs.push(
1054
+ t__namespace.expressionStatement(
1055
+ t__namespace.callExpression(effectWrapperId, [
1056
+ t__namespace.arrowFunctionExpression(
1057
+ [],
1058
+ setAttr$2(path, elem, key, value.expression, {
1059
+ isSVG,
1060
+ isCE
1061
+ })
1062
+ )
1063
+ ])
1064
+ )
1065
+ );
1066
+ return;
1067
+ }
1054
1068
  if (key === "textContent") {
1055
1069
  nextElem = attribute.scope.generateUidIdentifier("el$");
1056
1070
  children = t__namespace.JSXText(" ");
@@ -1147,7 +1161,9 @@ function transformChildren$2(path, results, config) {
1147
1161
  results.decl.push(...child.decl);
1148
1162
  results.exprs.push(...child.exprs);
1149
1163
  results.dynamics.push(...child.dynamics);
1164
+ results.postExprs.push(...child.postExprs);
1150
1165
  results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
1166
+ results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
1151
1167
  tempPath = child.id.name;
1152
1168
  nextPlaceholder = null;
1153
1169
  i++;
@@ -1188,12 +1204,7 @@ function transformChildren$2(path, results, config) {
1188
1204
  );
1189
1205
  } else {
1190
1206
  results.exprs.push(
1191
- t__namespace.expressionStatement(
1192
- t__namespace.callExpression(
1193
- insert,
1194
- [results.id, child.exprs[0]]
1195
- )
1196
- )
1207
+ t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]]))
1197
1208
  );
1198
1209
  }
1199
1210
  } else nextPlaceholder = null;
@@ -1376,6 +1387,10 @@ function registerTemplate(path, results) {
1376
1387
  registerImportMethod(path, "getNextElement", getRendererConfig(path, "dom").moduleName),
1377
1388
  templateId ? [templateId] : []
1378
1389
  )
1390
+ : results.hasCustomElement
1391
+ ? t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier("document"), t__namespace.identifier("importNode")), [
1392
+ templateId, t__namespace.booleanLiteral(true)
1393
+ ])
1379
1394
  : t__namespace.callExpression(t__namespace.memberExpression(templateId, t__namespace.identifier("cloneNode")), [
1380
1395
  t__namespace.booleanLiteral(true)
1381
1396
  ])
@@ -1396,7 +1411,9 @@ function wrapDynamics$1(path, dynamics) {
1396
1411
  dynamics[0].key === "classList" || dynamics[0].key === "style"
1397
1412
  ? t__namespace.identifier("_$p")
1398
1413
  : undefined;
1399
-
1414
+ if (dynamics[0].key.startsWith("class:") && !t__namespace.isBooleanLiteral(dynamics[0].value) && !t__namespace.isUnaryExpression(dynamics[0].value)) {
1415
+ dynamics[0].value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", dynamics[0].value));
1416
+ }
1400
1417
  return t__namespace.expressionStatement(
1401
1418
  t__namespace.callExpression(effectWrapperId, [
1402
1419
  t__namespace.arrowFunctionExpression(
@@ -1417,7 +1434,9 @@ function wrapDynamics$1(path, dynamics) {
1417
1434
  prevId = t__namespace.identifier("_p$");
1418
1435
  dynamics.forEach(({ elem, key, value, isSVG, isCE }) => {
1419
1436
  const identifier = path.scope.generateUidIdentifier("v$");
1420
- identifiers.push(identifier);
1437
+ if (key.startsWith("class:") && !t__namespace.isBooleanLiteral(value) && !t__namespace.isUnaryExpression(value)) {
1438
+ value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
1439
+ } identifiers.push(identifier);
1421
1440
  decls.push(t__namespace.variableDeclarator(identifier, value));
1422
1441
  if (key === "classList" || key === "style") {
1423
1442
  const prev = t__namespace.memberExpression(prevId, identifier);
@@ -1707,6 +1726,7 @@ function transformAttributes$1(path, results) {
1707
1726
  }
1708
1727
  i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
1709
1728
  }
1729
+ first.name = t__namespace.JSXIdentifier("class");
1710
1730
  first.value = t__namespace.JSXExpressionContainer(t__namespace.TemplateLiteral(quasis, values));
1711
1731
  }
1712
1732
  if (styleAttributes.length) transformToObject("style", attributes, styleAttributes);
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.33.0",
4
+ "version": "0.33.10",
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": "1f388eacd1601e06e84689837a5363f13ae5ffe7"
26
+ "gitHead": "56d368d4a63606844811008c5a2e3b1d2dc0a4de"
27
27
  }