babel-plugin-jsx-dom-expressions 0.31.0-beta.9 → 0.31.5

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 +35 -18
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -225,15 +225,15 @@ function getConfig(path) {
225
225
  function registerImportMethod(path, name) {
226
226
  const imports =
227
227
  path.scope.getProgramParent().data.imports ||
228
- (path.scope.getProgramParent().data.imports = new Map());
228
+ (path.scope.getProgramParent().data.imports = new Set());
229
+ const identifier = t__namespace.identifier(`_$${name}`);
229
230
  if (!imports.has(name)) {
230
- const identifier = helperModuleImports.addNamed(path, name, getConfig(path).moduleName, {
231
+ helperModuleImports.addNamed(path, name, getConfig(path).moduleName, {
231
232
  nameHint: `_$${name}`
232
233
  });
233
- imports.set(name, identifier);
234
- return identifier;
234
+ imports.add(name);
235
235
  }
236
- return imports.get(name);
236
+ return identifier;
237
237
  }
238
238
 
239
239
  function jsxElementNameToString(node) {
@@ -465,6 +465,10 @@ function transformCondition(path, inline, deep) {
465
465
  return deep ? expr : t__namespace.arrowFunctionExpression([], expr);
466
466
  }
467
467
 
468
+ function escapeBackticks(value) {
469
+ return value.replace(/`/g, "\\`");
470
+ }
471
+
468
472
  function escapeHTML(s, attr) {
469
473
  if (typeof s !== "string") return s;
470
474
  const delim = attr ? '"' : "<";
@@ -1042,7 +1046,7 @@ function transformAttributes$2(path, results) {
1042
1046
  } else {
1043
1047
  !isSVG && (key = key.toLowerCase());
1044
1048
  results.template += ` ${key}`;
1045
- results.template += value ? `="${value.value}"` : "";
1049
+ results.template += value ? `="${escapeBackticks(value.value)}"` : "";
1046
1050
  }
1047
1051
  }
1048
1052
  });
@@ -1494,12 +1498,14 @@ function transformElement$1(path, info) {
1494
1498
  };
1495
1499
  if (info.topLevel && config.hydratable) {
1496
1500
  results.template.push("");
1497
- results.templateValues.push(t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), []));
1501
+ results.templateValues.push(
1502
+ t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), [])
1503
+ );
1498
1504
  }
1499
1505
  transformAttributes$1(path, results);
1500
1506
  appendToTemplate(results.template, ">");
1501
1507
  if (!voidTag) {
1502
- transformChildren$1(path, results, {...config, ...info});
1508
+ transformChildren$1(path, results, { ...config, ...info });
1503
1509
  appendToTemplate(results.template, `</${tagName}>`);
1504
1510
  }
1505
1511
  return results;
@@ -1573,7 +1579,7 @@ function transformToObject(attrName, attributes, selectedAttributes) {
1573
1579
  const attr = selectedAttributes[i].node;
1574
1580
  const computed = !t__namespace.isValidIdentifier(attr.name.name.name);
1575
1581
  if (!computed) {
1576
- attr.name.name.type = 'Identifier';
1582
+ attr.name.name.type = "Identifier";
1577
1583
  }
1578
1584
  properties.push(
1579
1585
  t__namespace.objectProperty(
@@ -1745,7 +1751,10 @@ function transformAttributes$1(path, results) {
1745
1751
  ? p.value
1746
1752
  : t__namespace.isTemplateLiteral(p.value) && p.value.expressions.length === 0
1747
1753
  ? t__namespace.stringLiteral(escapeHTML(p.value.quasis[0].value.raw))
1748
- : t__namespace.callExpression(registerImportMethod(path, "escape"), [p.value, t__namespace.booleanLiteral(true)])
1754
+ : t__namespace.callExpression(registerImportMethod(path, "escape"), [
1755
+ p.value,
1756
+ t__namespace.booleanLiteral(true)
1757
+ ])
1749
1758
  )
1750
1759
  );
1751
1760
  let res = props[0];
@@ -1754,7 +1763,9 @@ function transformAttributes$1(path, results) {
1754
1763
  }
1755
1764
  value.expression = res;
1756
1765
  } else {
1757
- value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrStyle"), [value.expression]);
1766
+ value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrStyle"), [
1767
+ value.expression
1768
+ ]);
1758
1769
  }
1759
1770
  doEscape = false;
1760
1771
  }
@@ -1771,7 +1782,9 @@ function transformAttributes$1(path, results) {
1771
1782
  value.expression = values[0];
1772
1783
  } else value.expression = t__namespace.templateLiteral(quasis, values);
1773
1784
  } else {
1774
- value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [value.expression]);
1785
+ value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [
1786
+ value.expression
1787
+ ]);
1775
1788
  }
1776
1789
  key = "class";
1777
1790
  doEscape = false;
@@ -1803,7 +1816,10 @@ function transformClasslistObject(path, expr, values, quasis) {
1803
1816
  let key = prop.key;
1804
1817
  if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);
1805
1818
  else if (prop.computed) {
1806
- key = t__namespace.callExpression(registerImportMethod(path, "escape"), [prop.key, t__namespace.booleanLiteral(true)]);
1819
+ key = t__namespace.callExpression(registerImportMethod(path, "escape"), [
1820
+ prop.key,
1821
+ t__namespace.booleanLiteral(true)
1822
+ ]);
1807
1823
  } else key = t__namespace.stringLiteral(escapeHTML(prop.key.value));
1808
1824
  if (t__namespace.isBooleanLiteral(prop.value)) {
1809
1825
  if (prop.value.value === true) {
@@ -1831,7 +1847,7 @@ function transformChildren$1(path, results, { hydratable }) {
1831
1847
  const doNotEscape = path.doNotEscape;
1832
1848
  const filteredChildren = filterChildren(path.get("children"));
1833
1849
  filteredChildren.forEach(node => {
1834
- if (t__namespace.isJSXElement(node.node) && (getTagName(node.node) === "head")) {
1850
+ if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === "head") {
1835
1851
  const child = transformNode(node, { doNotEscape, hydratable: false });
1836
1852
  registerImportMethod(path, "NoHydration");
1837
1853
  results.template.push("");
@@ -1850,6 +1866,7 @@ function transformChildren$1(path, results, { hydratable }) {
1850
1866
  return;
1851
1867
  }
1852
1868
  const child = transformNode(node, { doNotEscape });
1869
+ if (!child) return;
1853
1870
  appendToTemplate(results.template, child.template);
1854
1871
  results.templateValues.push.apply(results.templateValues, child.templateValues || []);
1855
1872
  if (child.exprs.length) {
@@ -2213,7 +2230,7 @@ function convertComponentIdentifier(node) {
2213
2230
 
2214
2231
  function convertJSXIdentifier(node) {
2215
2232
  if (t__namespace.isJSXIdentifier(node)) {
2216
- if (t__namespace.isValidIdentifier(node.name, false)) {
2233
+ if (t__namespace.isValidIdentifier(node.name)) {
2217
2234
  node.type = "Identifier";
2218
2235
  } else {
2219
2236
  return t__namespace.stringLiteral(node.name);
@@ -2541,7 +2558,7 @@ function transformNode(path, info = {}) {
2541
2558
  : trimWhitespace(node.extra.raw);
2542
2559
  if (!text.length) return null;
2543
2560
  const results = {
2544
- template: text,
2561
+ template: config.generate === "dom" ? escapeBackticks(text) : text,
2545
2562
  decl: [],
2546
2563
  exprs: [],
2547
2564
  dynamics: [],
@@ -2641,8 +2658,8 @@ var config = {
2641
2658
  };
2642
2659
 
2643
2660
  var preprocess = (path, { opts }) => {
2644
- path.hub.file.metadata.config = Object.assign({}, config, opts);
2645
- const lib = config.requireImportSource;
2661
+ const merged = path.hub.file.metadata.config = Object.assign({}, config, opts);
2662
+ const lib = merged.requireImportSource;
2646
2663
  if (lib) {
2647
2664
  const comments = path.hub.file.ast.comments;
2648
2665
  for(let i = 0; i < comments.length; i++) {
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.31.0-beta.9",
4
+ "version": "0.31.5",
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": "2c421965e1f194d4ff7fae88ae278c0a50baa161"
26
+ "gitHead": "4ef6930208d91931a87074733a134b0fcbebe428"
27
27
  }