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

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 +89 -81
  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",
@@ -592,26 +592,28 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
592
592
  }
593
593
 
594
594
  if (name === "style") {
595
- 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
+ );
596
599
  }
597
600
 
598
601
  if (!isSVG && name === "class") {
599
- 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
+ );
600
606
  }
601
607
 
602
608
  if (name === "classList") {
603
- return t__namespace.callExpression(registerImportMethod(
604
- path,
605
- "classList",
606
- getRendererConfig(path, "dom").moduleName
607
- ), 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
+ );
608
613
  }
609
614
 
610
615
  if (config.hydratable && name === "innerHTML") {
611
- return t__namespace.callExpression(
612
- registerImportMethod(path, "innerHTML"),
613
- [elem, value]
614
- );
616
+ return t__namespace.callExpression(registerImportMethod(path, "innerHTML"), [elem, value]);
615
617
  }
616
618
 
617
619
  if (dynamic && name === "textContent") {
@@ -635,22 +637,15 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
635
637
  !isSVG && (name = name.toLowerCase());
636
638
  const ns = isNameSpaced && SVGNamespace[name.split(":")[0]];
637
639
  if (ns) {
638
- return t__namespace.callExpression(registerImportMethod(
639
- path,
640
- "setAttributeNS",
641
- getRendererConfig(path, "dom").moduleName
642
- ), [
643
- elem,
644
- t__namespace.stringLiteral(ns),
645
- t__namespace.stringLiteral(name),
646
- value
647
- ]);
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
+ );
648
644
  } else {
649
- return t__namespace.callExpression(registerImportMethod(
650
- path,
651
- "setAttribute",
652
- getRendererConfig(path, "dom").moduleName
653
- ), [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
+ );
654
649
  }
655
650
  }
656
651
 
@@ -810,22 +805,21 @@ function transformAttributes$2(path, results) {
810
805
  if (t__namespace.isJSXSpreadAttribute(node)) {
811
806
  results.exprs.push(
812
807
  t__namespace.expressionStatement(
813
- t__namespace.callExpression(registerImportMethod(
814
- attribute,
815
- "spread",
816
- getRendererConfig(path, "dom").moduleName
817
- ), [
818
- elem,
819
- isDynamic(attribute.get("argument"), {
820
- checkMember: true
821
- })
822
- ? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
823
- ? node.argument.callee
824
- : t__namespace.arrowFunctionExpression([], node.argument)
825
- : node.argument,
826
- t__namespace.booleanLiteral(isSVG),
827
- t__namespace.booleanLiteral(hasChildren)
828
- ])
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
+ )
829
823
  )
830
824
  );
831
825
  //NOTE: can't be checked at compile time so add to compiled output
@@ -917,7 +911,7 @@ function transformAttributes$2(path, results) {
917
911
  }
918
912
  } else if (key.startsWith("use:")) {
919
913
  // Some trick to treat JSXIdentifier as Identifier
920
- node.name.name.type = 'Identifier';
914
+ node.name.name.type = "Identifier";
921
915
  results.exprs.unshift(
922
916
  t__namespace.expressionStatement(
923
917
  t__namespace.callExpression(node.name.name, [
@@ -994,16 +988,14 @@ function transformAttributes$2(path, results) {
994
988
  } else {
995
989
  results.exprs.unshift(
996
990
  t__namespace.expressionStatement(
997
- t__namespace.callExpression(registerImportMethod(
998
- path,
999
- "addEventListener",
1000
- getRendererConfig(path, "dom").moduleName
1001
- ), [
1002
- elem,
1003
- t__namespace.stringLiteral(ev),
1004
- handler,
1005
- t__namespace.booleanLiteral(true)
1006
- ])
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
+ )
1007
999
  )
1008
1000
  );
1009
1001
  }
@@ -1037,11 +1029,14 @@ function transformAttributes$2(path, results) {
1037
1029
  } else {
1038
1030
  results.exprs.unshift(
1039
1031
  t__namespace.expressionStatement(
1040
- t__namespace.callExpression(registerImportMethod(
1041
- path,
1042
- "addEventListener",
1043
- getRendererConfig(path, "dom").moduleName
1044
- ), [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
+ )
1045
1040
  )
1046
1041
  );
1047
1042
  }
@@ -1053,6 +1048,23 @@ function transformAttributes$2(path, results) {
1053
1048
  })
1054
1049
  ) {
1055
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
+ }
1056
1068
  if (key === "textContent") {
1057
1069
  nextElem = attribute.scope.generateUidIdentifier("el$");
1058
1070
  children = t__namespace.JSXText(" ");
@@ -1099,19 +1111,18 @@ function transformChildren$2(path, results, config) {
1099
1111
  i = 0;
1100
1112
  const filteredChildren = filterChildren(path.get("children")),
1101
1113
  childNodes = filteredChildren
1102
- .map(
1103
- (child, index) =>
1104
- transformNode(child, {
1105
- skipId: !results.id || !detectExpressions(filteredChildren, index, config)
1106
- })
1107
- // combine adjacent textNodes
1108
- )
1109
- .reduce((memo, child) => {
1110
- if (!child) return memo;
1114
+ .reduce((memo, child, index) => {
1115
+ if (child.isJSXFragment()) {
1116
+ throw new Error(`Fragments can only be used top level in JSX. Not used under a <${tagName}>.`);
1117
+ }
1118
+ const transformed = transformNode(child, {
1119
+ skipId: !results.id || !detectExpressions(filteredChildren, index, config)
1120
+ });
1121
+ if (!transformed) return memo;
1111
1122
  const i = memo.length;
1112
- if (child.text && i && memo[i - 1].text) {
1113
- memo[i - 1].template += child.template;
1114
- } else memo.push(child);
1123
+ if (transformed.text && i && memo[i - 1].text) {
1124
+ memo[i - 1].template += transformed.template;
1125
+ } else memo.push(transformed);
1115
1126
  return memo;
1116
1127
  }, []);
1117
1128
 
@@ -1149,6 +1160,7 @@ function transformChildren$2(path, results, config) {
1149
1160
  results.decl.push(...child.decl);
1150
1161
  results.exprs.push(...child.exprs);
1151
1162
  results.dynamics.push(...child.dynamics);
1163
+ results.postExprs.push(...child.postExprs);
1152
1164
  results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
1153
1165
  results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
1154
1166
  tempPath = child.id.name;
@@ -1191,12 +1203,7 @@ function transformChildren$2(path, results, config) {
1191
1203
  );
1192
1204
  } else {
1193
1205
  results.exprs.push(
1194
- t__namespace.expressionStatement(
1195
- t__namespace.callExpression(
1196
- insert,
1197
- [results.id, child.exprs[0]]
1198
- )
1199
- )
1206
+ t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]]))
1200
1207
  );
1201
1208
  }
1202
1209
  } else nextPlaceholder = null;
@@ -1718,6 +1725,7 @@ function transformAttributes$1(path, results) {
1718
1725
  }
1719
1726
  i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
1720
1727
  }
1728
+ first.name = t__namespace.JSXIdentifier("class");
1721
1729
  first.value = t__namespace.JSXExpressionContainer(t__namespace.TemplateLiteral(quasis, values));
1722
1730
  }
1723
1731
  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.7",
4
+ "version": "0.33.11",
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": "adea58b5d73a28af4f95afcb4d05f2418433e696"
26
+ "gitHead": "c7153ffa28924ecdf687501f5edb18712c8f64c1"
27
27
  }