babel-plugin-jsx-dom-expressions 0.37.16 → 0.37.17

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 +25 -11
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -554,10 +554,6 @@ function transformCondition(path, inline, deep) {
554
554
  return deep ? expr : t__namespace.arrowFunctionExpression([], expr);
555
555
  }
556
556
 
557
- function escapeBackticks(value) {
558
- return value.replace(/`/g, "\\`");
559
- }
560
-
561
557
  function escapeHTML(s, attr) {
562
558
  if (typeof s !== "string") return s;
563
559
  const delim = attr ? '"' : "<";
@@ -646,6 +642,24 @@ function getNumberedId(num) {
646
642
  return out;
647
643
  }
648
644
 
645
+ function escapeStringForTemplate(str) {
646
+ return str.replace(/[{\\`\n\t\b\f\v\r\u2028\u2029]/g, ch => templateEscapes.get(ch))
647
+ }
648
+
649
+ const templateEscapes = new Map([
650
+ ['{', '\\{'],
651
+ ['`', '\\`'],
652
+ ['\\', '\\\\'],
653
+ ['\n', '\\n'],
654
+ ['\t', '\\t'],
655
+ ['\b', '\\b'],
656
+ ['\f', '\\f'],
657
+ ['\v', '\\v'],
658
+ ['\r', '\\r'],
659
+ ['\u2028', '\\u2028'],
660
+ ['\u2029', '\\u2029']
661
+ ]);
662
+
649
663
  const InlineElements = [
650
664
  "a",
651
665
  "abbr",
@@ -1466,10 +1480,10 @@ function transformAttributes$2(path, results) {
1466
1480
 
1467
1481
  if (needsQuoting) {
1468
1482
  needsSpacing = false;
1469
- results.template += `="${escapeBackticks(escapeHTML(text, true))}"`;
1483
+ results.template += `="${escapeHTML(text, true)}"`;
1470
1484
  } else {
1471
1485
  needsSpacing = true;
1472
- results.template += `=${escapeBackticks(escapeHTML(text, true))}`;
1486
+ results.template += `=${escapeHTML(text, true)}`;
1473
1487
  }
1474
1488
  }
1475
1489
  }
@@ -1847,7 +1861,7 @@ function appendTemplates$1(path, templates) {
1847
1861
  const declarators = templates.map(template => {
1848
1862
  const tmpl = {
1849
1863
  cooked: template.template,
1850
- raw: template.template
1864
+ raw: escapeStringForTemplate(template.template)
1851
1865
  };
1852
1866
  return t__namespace.variableDeclarator(
1853
1867
  template.id,
@@ -2897,13 +2911,13 @@ function transformChildren(path, results) {
2897
2911
  t__namespace.variableDeclarator(
2898
2912
  child.id,
2899
2913
  t__namespace.callExpression(createTextNode, [
2900
- t__namespace.templateLiteral([t__namespace.templateElement({ raw: child.template })], [])
2914
+ t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])
2901
2915
  ])
2902
2916
  )
2903
2917
  );
2904
2918
  } else
2905
2919
  insert = t__namespace.callExpression(createTextNode, [
2906
- t__namespace.templateLiteral([t__namespace.templateElement({ raw: child.template })], [])
2920
+ t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])
2907
2921
  ]);
2908
2922
  }
2909
2923
  appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
@@ -3468,7 +3482,7 @@ function transformThis(path) {
3468
3482
  path.node.closingElement.name = path.node.openingElement.name;
3469
3483
  }
3470
3484
  }
3471
- }
3485
+ }
3472
3486
  },
3473
3487
  });
3474
3488
  return node => {
@@ -3503,7 +3517,7 @@ function transformNode(path, info = {}) {
3503
3517
  : trimWhitespace(node.extra.raw);
3504
3518
  if (!text.length) return null;
3505
3519
  const results = {
3506
- template: config.generate === "ssr" ? text : escapeBackticks(text),
3520
+ template: text,
3507
3521
  declarations: [],
3508
3522
  exprs: [],
3509
3523
  dynamics: [],
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.37.16",
4
+ "version": "0.37.17",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -31,5 +31,5 @@
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.20.12"
33
33
  },
34
- "gitHead": "1c561b9430ff5b16391443338eb07f7a6ca98e20"
34
+ "gitHead": "099d1eaa9d59a794a1c8cbe4e6a03d2e847c1081"
35
35
  }