babel-plugin-jsx-dom-expressions 0.34.0-beta.2 → 0.34.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 +16 -9
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1570,12 +1570,12 @@ function appendToTemplate(template, value) {
1570
1570
  }
1571
1571
 
1572
1572
  function transformElement$2(path, info) {
1573
+ const config = getConfig(path);
1573
1574
  // contains spread attributes
1574
1575
  if (path.node.openingElement.attributes.some(a => t__namespace.isJSXSpreadAttribute(a)))
1575
- return createElement(path, info);
1576
+ return createElement(path, { ...info, ...config });
1576
1577
 
1577
1578
  const tagName = getTagName(path.node),
1578
- config = getConfig(path),
1579
1579
  voidTag = VoidElements.indexOf(tagName) > -1,
1580
1580
  results = {
1581
1581
  template: [`<${tagName}`],
@@ -1593,7 +1593,7 @@ function transformElement$2(path, info) {
1593
1593
  t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), [])
1594
1594
  );
1595
1595
  }
1596
- transformAttributes$1(path, results);
1596
+ transformAttributes$1(path, results, { ...config, ...info });
1597
1597
  appendToTemplate(results.template, ">");
1598
1598
  if (!voidTag) {
1599
1599
  transformChildren$1(path, results, { ...config, ...info });
@@ -1761,7 +1761,7 @@ function normalizeAttributes(path) {
1761
1761
  return attributes;
1762
1762
  }
1763
1763
 
1764
- function transformAttributes$1(path, results) {
1764
+ function transformAttributes$1(path, results, info) {
1765
1765
  const tagName = getTagName(path.node),
1766
1766
  isSVG = SVGElements.has(tagName),
1767
1767
  hasChildren = path.node.children.length > 0,
@@ -1798,8 +1798,11 @@ function transformAttributes$1(path, results) {
1798
1798
  )
1799
1799
  return;
1800
1800
  else if (ChildProperties.has(key)) {
1801
- children = value;
1801
+ if (info.hydratable && key === "textContent" && value && value.expression) {
1802
+ value.expression = t__namespace.logicalExpression("||", value.expression, t__namespace.stringLiteral(" "));
1803
+ }
1802
1804
  if (key === "innerHTML") path.doNotEscape = true;
1805
+ children = value;
1803
1806
  } else {
1804
1807
  let doEscape = true;
1805
1808
  if (BooleanAttributes.has(key)) {
@@ -1926,6 +1929,8 @@ function transformClasslistObject(path, expr, values, quasis) {
1926
1929
  function transformChildren$1(path, results, { hydratable }) {
1927
1930
  const doNotEscape = path.doNotEscape;
1928
1931
  const filteredChildren = filterChildren(path.get("children"));
1932
+ const multi = checkLength(filteredChildren),
1933
+ markers = hydratable && multi;
1929
1934
  filteredChildren.forEach(node => {
1930
1935
  if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === "head") {
1931
1936
  const child = transformNode(node, { doNotEscape, hydratable: false });
@@ -1950,9 +1955,6 @@ function transformChildren$1(path, results, { hydratable }) {
1950
1955
  appendToTemplate(results.template, child.template);
1951
1956
  results.templateValues.push.apply(results.templateValues, child.templateValues || []);
1952
1957
  if (child.exprs.length) {
1953
- const multi = checkLength(filteredChildren),
1954
- markers = hydratable && multi;
1955
-
1956
1958
  if (!doNotEscape) child.exprs[0] = escapeExpression(path, child.exprs[0]);
1957
1959
 
1958
1960
  // boxed by textNodes
@@ -1969,19 +1971,24 @@ function transformChildren$1(path, results, { hydratable }) {
1969
1971
  });
1970
1972
  }
1971
1973
 
1972
- function createElement(path, { topLevel }) {
1974
+ function createElement(path, { topLevel, hydratable }) {
1973
1975
  const tagName = getTagName(path.node),
1974
1976
  config = getConfig(path),
1975
1977
  attributes = normalizeAttributes(path);
1976
1978
 
1977
1979
  const filteredChildren = filterChildren(path.get("children")),
1980
+ multi = checkLength(filteredChildren),
1981
+ markers = hydratable && multi,
1978
1982
  childNodes = filteredChildren.reduce((memo, path) => {
1979
1983
  if (t__namespace.isJSXText(path.node)) {
1980
1984
  const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
1981
1985
  if (v.length) memo.push(t__namespace.stringLiteral(v));
1982
1986
  } else {
1983
1987
  const child = transformNode(path);
1988
+ if (markers && child.exprs.length) memo.push(t__namespace.stringLiteral("<!--#-->"));
1989
+ if (hydratable && child.exprs.length) child.exprs[0] = t__namespace.arrowFunctionExpression([], child.exprs[0]);
1984
1990
  memo.push(getCreateTemplate(config, path, child)(path, child, true));
1991
+ if (markers && child.exprs.length) memo.push(t__namespace.stringLiteral("<!--/-->"));
1985
1992
  }
1986
1993
  return memo;
1987
1994
  }, []);
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.34.0-beta.2",
4
+ "version": "0.34.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": "80b54ffb1029d3fc735fd0604ead837758071fec"
30
+ "gitHead": "06b4f8106558dccae5071d4974b876b79e431b00"
31
31
  }