babel-plugin-jsx-dom-expressions 0.37.13 → 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.
- package/index.js +28 -12
- 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",
|
|
@@ -1142,7 +1156,9 @@ function transformAttributes$2(path, results) {
|
|
|
1142
1156
|
evaluated !== undefined &&
|
|
1143
1157
|
((type = typeof evaluated) === "string" || type === "number")
|
|
1144
1158
|
) {
|
|
1145
|
-
|
|
1159
|
+
if (type === "number" && (Properties.has(key) || key.startsWith("prop:"))) {
|
|
1160
|
+
value = t__namespace.jsxExpressionContainer(t__namespace.numericLiteral(evaluated));
|
|
1161
|
+
} else value = t__namespace.stringLiteral(String(evaluated));
|
|
1146
1162
|
}
|
|
1147
1163
|
}
|
|
1148
1164
|
if (
|
|
@@ -1464,10 +1480,10 @@ function transformAttributes$2(path, results) {
|
|
|
1464
1480
|
|
|
1465
1481
|
if (needsQuoting) {
|
|
1466
1482
|
needsSpacing = false;
|
|
1467
|
-
results.template += `="${
|
|
1483
|
+
results.template += `="${escapeHTML(text, true)}"`;
|
|
1468
1484
|
} else {
|
|
1469
1485
|
needsSpacing = true;
|
|
1470
|
-
results.template += `=${
|
|
1486
|
+
results.template += `=${escapeHTML(text, true)}`;
|
|
1471
1487
|
}
|
|
1472
1488
|
}
|
|
1473
1489
|
}
|
|
@@ -1845,7 +1861,7 @@ function appendTemplates$1(path, templates) {
|
|
|
1845
1861
|
const declarators = templates.map(template => {
|
|
1846
1862
|
const tmpl = {
|
|
1847
1863
|
cooked: template.template,
|
|
1848
|
-
raw: template.template
|
|
1864
|
+
raw: escapeStringForTemplate(template.template)
|
|
1849
1865
|
};
|
|
1850
1866
|
return t__namespace.variableDeclarator(
|
|
1851
1867
|
template.id,
|
|
@@ -2895,13 +2911,13 @@ function transformChildren(path, results) {
|
|
|
2895
2911
|
t__namespace.variableDeclarator(
|
|
2896
2912
|
child.id,
|
|
2897
2913
|
t__namespace.callExpression(createTextNode, [
|
|
2898
|
-
t__namespace.templateLiteral([t__namespace.templateElement({ raw: child.template })], [])
|
|
2914
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])
|
|
2899
2915
|
])
|
|
2900
2916
|
)
|
|
2901
2917
|
);
|
|
2902
2918
|
} else
|
|
2903
2919
|
insert = t__namespace.callExpression(createTextNode, [
|
|
2904
|
-
t__namespace.templateLiteral([t__namespace.templateElement({ raw: child.template })], [])
|
|
2920
|
+
t__namespace.templateLiteral([t__namespace.templateElement({ raw: escapeStringForTemplate(child.template) })], [])
|
|
2905
2921
|
]);
|
|
2906
2922
|
}
|
|
2907
2923
|
appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
|
|
@@ -3466,7 +3482,7 @@ function transformThis(path) {
|
|
|
3466
3482
|
path.node.closingElement.name = path.node.openingElement.name;
|
|
3467
3483
|
}
|
|
3468
3484
|
}
|
|
3469
|
-
}
|
|
3485
|
+
}
|
|
3470
3486
|
},
|
|
3471
3487
|
});
|
|
3472
3488
|
return node => {
|
|
@@ -3501,7 +3517,7 @@ function transformNode(path, info = {}) {
|
|
|
3501
3517
|
: trimWhitespace(node.extra.raw);
|
|
3502
3518
|
if (!text.length) return null;
|
|
3503
3519
|
const results = {
|
|
3504
|
-
template:
|
|
3520
|
+
template: text,
|
|
3505
3521
|
declarations: [],
|
|
3506
3522
|
exprs: [],
|
|
3507
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.
|
|
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": "
|
|
34
|
+
"gitHead": "099d1eaa9d59a794a1c8cbe4e6a03d2e847c1081"
|
|
35
35
|
}
|