babel-plugin-jsx-dom-expressions 0.35.0-beta.1 → 0.35.0-beta.2

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 +101 -22
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -57,24 +57,36 @@ const booleans = [
57
57
 
58
58
  const BooleanAttributes = /*#__PURE__*/ new Set(booleans);
59
59
 
60
- const Properties = /*#__PURE__*/ new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]);
60
+ const Properties = /*#__PURE__*/ new Set([
61
+ "className",
62
+ "value",
63
+ "readOnly",
64
+ "formNoValidate",
65
+ "isMap",
66
+ "noModule",
67
+ "playsInline",
68
+ ...booleans
69
+ ]);
61
70
 
62
- const ChildProperties = /*#__PURE__*/ new Set(["innerHTML", "textContent", "innerText", "children"]);
71
+ const ChildProperties = /*#__PURE__*/ new Set([
72
+ "innerHTML",
73
+ "textContent",
74
+ "innerText",
75
+ "children"
76
+ ]);
63
77
 
64
78
  // React Compat
65
- const Aliases = {
66
- className: "class",
67
- htmlFor: "for"
68
- };
69
-
70
- const PropAliases = {
71
- class: "className",
72
- formnovalidate: "formNoValidate",
73
- ismap: "isMap",
74
- nomodule: "noModule",
75
- playsinline: "playsInline",
76
- readonly: "readOnly"
77
- };
79
+ const Aliases = Object.create(null);
80
+ Aliases.className = "class";
81
+ Aliases.htmlFor = "for";
82
+
83
+ const PropAliases = Object.create(null);
84
+ PropAliases.class = "className";
85
+ PropAliases.formnovalidate = "formNoValidate";
86
+ PropAliases.ismap = "isMap";
87
+ PropAliases.nomodule = "noModule";
88
+ PropAliases.playsinline = "playsInline";
89
+ PropAliases.readonly = "readOnly";
78
90
 
79
91
  // list of Element events that will be delegated
80
92
  const DelegatedEvents = /*#__PURE__*/ new Set([
@@ -585,8 +597,27 @@ function transformElement$3(path, info) {
585
597
  tagName,
586
598
  renderer: "dom"
587
599
  };
588
- if (config.hydratable && (tagName === "html" || tagName === "head" || tagName === "body"))
600
+ if (config.hydratable && (tagName === "html" || tagName === "head" || tagName === "body")) {
589
601
  results.skipTemplate = true;
602
+ if (tagName === "head" && info.topLevel) {
603
+ const createComponent = registerImportMethod(
604
+ path,
605
+ "createComponent",
606
+ getRendererConfig(path, "dom").moduleName
607
+ );
608
+ const NoHydration = registerImportMethod(
609
+ path,
610
+ "NoHydration",
611
+ getRendererConfig(path, "dom").moduleName
612
+ );
613
+ results.exprs.push(
614
+ t__namespace.expressionStatement(
615
+ t__namespace.callExpression(createComponent, [NoHydration, t__namespace.objectExpression([])])
616
+ )
617
+ );
618
+ return results;
619
+ }
620
+ }
590
621
  if (wrapSVG) results.template = "<svg>" + results.template;
591
622
  if (!info.skipId) results.id = path.scope.generateUidIdentifier("el$");
592
623
  transformAttributes$2(path, results);
@@ -1197,7 +1228,26 @@ function transformChildren$2(path, results, config) {
1197
1228
 
1198
1229
  results.template += child.template;
1199
1230
  if (child.id) {
1200
- if (child.tagName === "head") return;
1231
+ if (child.tagName === "head") {
1232
+ if (config.hydratable) {
1233
+ const createComponent = registerImportMethod(
1234
+ path,
1235
+ "createComponent",
1236
+ getRendererConfig(path, "dom").moduleName
1237
+ );
1238
+ const NoHydration = registerImportMethod(
1239
+ path,
1240
+ "NoHydration",
1241
+ getRendererConfig(path, "dom").moduleName
1242
+ );
1243
+ results.exprs.push(
1244
+ t__namespace.expressionStatement(
1245
+ t__namespace.callExpression(createComponent, [NoHydration, t__namespace.objectExpression([])])
1246
+ )
1247
+ );
1248
+ }
1249
+ return;
1250
+ }
1201
1251
 
1202
1252
  let getNextMatch;
1203
1253
  if (config.hydratable && tagName === "html") {
@@ -1408,7 +1458,8 @@ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapCond
1408
1458
  const id = convertJSXIdentifier(node.name);
1409
1459
  let expr =
1410
1460
  wrapConditionals &&
1411
- (t__namespace.isLogicalExpression(node.value.expression) || t__namespace.isConditionalExpression(node.value.expression))
1461
+ (t__namespace.isLogicalExpression(node.value.expression) ||
1462
+ t__namespace.isConditionalExpression(node.value.expression))
1412
1463
  ? transformCondition(attribute.get("value").get("expression"), true)
1413
1464
  : t__namespace.arrowFunctionExpression([], node.value.expression);
1414
1465
  runningObject.push(
@@ -1724,6 +1775,26 @@ function transformElement$2(path, info) {
1724
1775
  };
1725
1776
 
1726
1777
  if (info.topLevel && config.hydratable) {
1778
+ if (tagName === "head") {
1779
+ registerImportMethod(path, "NoHydration");
1780
+ registerImportMethod(path, "createComponent");
1781
+ const child = transformElement$2(path, { ...info, topLevel: false });
1782
+ results.template = "";
1783
+ results.exprs.push(
1784
+ t__namespace.callExpression(t__namespace.identifier("_$createComponent"), [
1785
+ t__namespace.identifier("_$NoHydration"),
1786
+ t__namespace.objectExpression([
1787
+ t__namespace.objectMethod(
1788
+ "get",
1789
+ t__namespace.identifier("children"),
1790
+ [],
1791
+ t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$1(path, child))])
1792
+ )
1793
+ ])
1794
+ ])
1795
+ );
1796
+ return results;
1797
+ }
1727
1798
  results.template.push("");
1728
1799
  results.templateValues.push(
1729
1800
  t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), [])
@@ -2070,12 +2141,20 @@ function transformChildren$1(path, results, { hydratable }) {
2070
2141
  filteredChildren.forEach(node => {
2071
2142
  if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === "head") {
2072
2143
  const child = transformNode(node, { doNotEscape, hydratable: false });
2073
- registerImportMethod(path, "setHydratable");
2144
+ registerImportMethod(path, "NoHydration");
2145
+ registerImportMethod(path, "createComponent");
2074
2146
  results.template.push("");
2075
2147
  results.templateValues.push(
2076
- t__namespace.callExpression(t__namespace.identifier("_$setHydratable"), [
2077
- t__namespace.arrowFunctionExpression([], createTemplate$1(path, child)),
2078
- t__namespace.booleanLiteral(false)
2148
+ t__namespace.callExpression(t__namespace.identifier("_$createComponent"), [
2149
+ t__namespace.identifier("_$NoHydration"),
2150
+ t__namespace.objectExpression([
2151
+ t__namespace.objectMethod(
2152
+ "get",
2153
+ t__namespace.identifier("children"),
2154
+ [],
2155
+ t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$1(path, child))])
2156
+ )
2157
+ ])
2079
2158
  ])
2080
2159
  );
2081
2160
  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.35.0-beta.1",
4
+ "version": "0.35.0-beta.2",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -27,5 +27,5 @@
27
27
  "peerDependencies": {
28
28
  "@babel/core": "^7.0.0"
29
29
  },
30
- "gitHead": "2d62fd655ecdf2462f7c9e10232f4f8aaa4b7fd5"
30
+ "gitHead": "b059481668f4ec2e47b01bd7ab421102b0ff18b0"
31
31
  }