babel-plugin-jsx-dom-expressions 0.35.8 → 0.35.10
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 +61 -28
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1735,9 +1735,31 @@ function createTemplate$1(path, result) {
|
|
|
1735
1735
|
});
|
|
1736
1736
|
} else id = found.id;
|
|
1737
1737
|
|
|
1738
|
+
if (result.wontEscape) {
|
|
1739
|
+
if (!Array.isArray(result.template) || result.template.length === 1) return id;
|
|
1740
|
+
else if (
|
|
1741
|
+
Array.isArray(result.template) &&
|
|
1742
|
+
result.template.length === 2 &&
|
|
1743
|
+
result.templateValues[0].type === "CallExpression" &&
|
|
1744
|
+
result.templateValues[0].callee.name === "_$ssrHydrationKey"
|
|
1745
|
+
) {
|
|
1746
|
+
// remove unnecessary ssr call when only hydration key is used
|
|
1747
|
+
return t__namespace.binaryExpression(
|
|
1748
|
+
"+",
|
|
1749
|
+
t__namespace.binaryExpression(
|
|
1750
|
+
"+",
|
|
1751
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(0), true),
|
|
1752
|
+
result.templateValues[0]
|
|
1753
|
+
),
|
|
1754
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(1), true)
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1738
1758
|
return t__namespace.callExpression(
|
|
1739
1759
|
registerImportMethod(path, "ssr"),
|
|
1740
|
-
Array.isArray(result.template) && result.template.length > 1
|
|
1760
|
+
Array.isArray(result.template) && result.template.length > 1
|
|
1761
|
+
? [id, ...result.templateValues]
|
|
1762
|
+
: [id]
|
|
1741
1763
|
);
|
|
1742
1764
|
}
|
|
1743
1765
|
|
|
@@ -1772,6 +1794,7 @@ function transformElement$2(path, info) {
|
|
|
1772
1794
|
exprs: [],
|
|
1773
1795
|
dynamics: [],
|
|
1774
1796
|
tagName,
|
|
1797
|
+
wontEscape: path.node.wontEscape,
|
|
1775
1798
|
renderer: "ssr"
|
|
1776
1799
|
};
|
|
1777
1800
|
|
|
@@ -1838,44 +1861,60 @@ function setAttr$1(attribute, results, name, value, isSVG) {
|
|
|
1838
1861
|
}
|
|
1839
1862
|
}
|
|
1840
1863
|
|
|
1841
|
-
function escapeExpression(path, expression, attr) {
|
|
1842
|
-
if (
|
|
1864
|
+
function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
1865
|
+
if (
|
|
1866
|
+
t__namespace.isStringLiteral(expression) ||
|
|
1867
|
+
t__namespace.isNumericLiteral(expression) ||
|
|
1868
|
+
(t__namespace.isTemplateLiteral(expression) && expression.expressions.length === 0)
|
|
1869
|
+
) {
|
|
1870
|
+
if (escapeLiterals) {
|
|
1871
|
+
if (t__namespace.isStringLiteral(expression)) return t__namespace.stringLiteral(escapeHTML(expression.value, attr));
|
|
1872
|
+
else if (t__namespace.isTemplateLiteral(expression))
|
|
1873
|
+
return t__namespace.stringLiteral(escapeHTML(expression.quasis[0].value.raw, attr));
|
|
1874
|
+
}
|
|
1843
1875
|
return expression;
|
|
1844
1876
|
} else if (t__namespace.isFunction(expression)) {
|
|
1845
1877
|
if (t__namespace.isBlockStatement(expression.body)) {
|
|
1846
1878
|
expression.body.body = expression.body.body.map(e => {
|
|
1847
|
-
if (t__namespace.isReturnStatement(e))
|
|
1879
|
+
if (t__namespace.isReturnStatement(e))
|
|
1880
|
+
e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
1848
1881
|
return e;
|
|
1849
1882
|
});
|
|
1850
|
-
} else expression.body = escapeExpression(path, expression.body, attr);
|
|
1883
|
+
} else expression.body = escapeExpression(path, expression.body, attr, escapeLiterals);
|
|
1851
1884
|
return expression;
|
|
1852
1885
|
} else if (t__namespace.isTemplateLiteral(expression)) {
|
|
1853
|
-
expression.expressions = expression.expressions.map(e =>
|
|
1886
|
+
expression.expressions = expression.expressions.map(e =>
|
|
1887
|
+
escapeExpression(path, e, attr, escapeLiterals)
|
|
1888
|
+
);
|
|
1854
1889
|
return expression;
|
|
1855
1890
|
} else if (t__namespace.isUnaryExpression(expression)) {
|
|
1856
|
-
expression.argument = escapeExpression(path, expression.argument, attr);
|
|
1857
1891
|
return expression;
|
|
1858
1892
|
} else if (t__namespace.isBinaryExpression(expression)) {
|
|
1859
|
-
expression.left = escapeExpression(path, expression.left, attr);
|
|
1860
|
-
expression.right = escapeExpression(path, expression.right, attr);
|
|
1893
|
+
expression.left = escapeExpression(path, expression.left, attr, escapeLiterals);
|
|
1894
|
+
expression.right = escapeExpression(path, expression.right, attr, escapeLiterals);
|
|
1861
1895
|
return expression;
|
|
1862
1896
|
} else if (t__namespace.isConditionalExpression(expression)) {
|
|
1863
|
-
expression.consequent = escapeExpression(path, expression.consequent, attr);
|
|
1864
|
-
expression.alternate = escapeExpression(path, expression.alternate, attr);
|
|
1897
|
+
expression.consequent = escapeExpression(path, expression.consequent, attr, escapeLiterals);
|
|
1898
|
+
expression.alternate = escapeExpression(path, expression.alternate, attr, escapeLiterals);
|
|
1865
1899
|
return expression;
|
|
1866
1900
|
} else if (t__namespace.isLogicalExpression(expression)) {
|
|
1867
|
-
expression.right = escapeExpression(path, expression.right, attr);
|
|
1901
|
+
expression.right = escapeExpression(path, expression.right, attr, escapeLiterals);
|
|
1868
1902
|
if (expression.operator !== "&&") {
|
|
1869
|
-
expression.left = escapeExpression(path, expression.left, attr);
|
|
1903
|
+
expression.left = escapeExpression(path, expression.left, attr, escapeLiterals);
|
|
1870
1904
|
}
|
|
1871
1905
|
return expression;
|
|
1872
1906
|
} else if (t__namespace.isCallExpression(expression) && t__namespace.isFunction(expression.callee)) {
|
|
1873
1907
|
if (t__namespace.isBlockStatement(expression.callee.body)) {
|
|
1874
1908
|
expression.callee.body.body = expression.callee.body.body.map(e => {
|
|
1875
|
-
if (t__namespace.isReturnStatement(e))
|
|
1909
|
+
if (t__namespace.isReturnStatement(e))
|
|
1910
|
+
e.argument = escapeExpression(path, e.argument, attr, escapeLiterals);
|
|
1876
1911
|
return e;
|
|
1877
1912
|
});
|
|
1878
|
-
} else
|
|
1913
|
+
} else
|
|
1914
|
+
expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
|
|
1915
|
+
return expression;
|
|
1916
|
+
} else if(t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
1917
|
+
expression.wontEscape = true;
|
|
1879
1918
|
return expression;
|
|
1880
1919
|
}
|
|
1881
1920
|
|
|
@@ -2040,16 +2079,7 @@ function transformAttributes$1(path, results, info) {
|
|
|
2040
2079
|
t__namespace.stringLiteral(
|
|
2041
2080
|
(i ? ";" : "") + (t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value) + ":"
|
|
2042
2081
|
),
|
|
2043
|
-
|
|
2044
|
-
? t__namespace.stringLiteral(escapeHTML(p.value.value))
|
|
2045
|
-
: t__namespace.isNumericLiteral(p.value)
|
|
2046
|
-
? p.value
|
|
2047
|
-
: t__namespace.isTemplateLiteral(p.value) && p.value.expressions.length === 0
|
|
2048
|
-
? t__namespace.stringLiteral(escapeHTML(p.value.quasis[0].value.raw))
|
|
2049
|
-
: t__namespace.callExpression(registerImportMethod(path, "escape"), [
|
|
2050
|
-
p.value,
|
|
2051
|
-
t__namespace.booleanLiteral(true)
|
|
2052
|
-
])
|
|
2082
|
+
escapeExpression(path, p.value, true, true)
|
|
2053
2083
|
)
|
|
2054
2084
|
);
|
|
2055
2085
|
let res = props[0];
|
|
@@ -2201,10 +2231,13 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2201
2231
|
if (v.length) memo.push(t__namespace.stringLiteral(v));
|
|
2202
2232
|
} else {
|
|
2203
2233
|
const child = transformNode(path);
|
|
2204
|
-
if (markers && child.exprs.length && !child.spreadElement)
|
|
2205
|
-
|
|
2234
|
+
if (markers && child.exprs.length && !child.spreadElement)
|
|
2235
|
+
memo.push(t__namespace.stringLiteral("<!--#-->"));
|
|
2236
|
+
if (child.exprs.length && !child.spreadElement)
|
|
2237
|
+
child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
2206
2238
|
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
2207
|
-
if (markers && child.exprs.length && !child.spreadElement)
|
|
2239
|
+
if (markers && child.exprs.length && !child.spreadElement)
|
|
2240
|
+
memo.push(t__namespace.stringLiteral("<!--/-->"));
|
|
2208
2241
|
}
|
|
2209
2242
|
return memo;
|
|
2210
2243
|
}, []);
|
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.
|
|
4
|
+
"version": "0.35.10",
|
|
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": "
|
|
30
|
+
"gitHead": "fa02473265bc994e8f858ae60be40527a584c66f"
|
|
31
31
|
}
|