babel-plugin-jsx-dom-expressions 0.35.9 → 0.35.12
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 +71 -15
- package/package.json +16 -12
package/index.js
CHANGED
|
@@ -5,10 +5,7 @@ var t = require('@babel/types');
|
|
|
5
5
|
var helperModuleImports = require('@babel/helper-module-imports');
|
|
6
6
|
var htmlEntities = require('html-entities');
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
function _interopNamespace(e) {
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
12
9
|
var n = Object.create(null);
|
|
13
10
|
if (e) {
|
|
14
11
|
Object.keys(e).forEach(function (k) {
|
|
@@ -21,12 +18,11 @@ function _interopNamespace(e) {
|
|
|
21
18
|
}
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
|
-
n
|
|
21
|
+
n.default = e;
|
|
25
22
|
return Object.freeze(n);
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
var
|
|
29
|
-
var t__namespace = /*#__PURE__*/_interopNamespace(t);
|
|
25
|
+
var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
|
|
30
26
|
|
|
31
27
|
const booleans = [
|
|
32
28
|
"allowfullscreen",
|
|
@@ -1735,9 +1731,31 @@ function createTemplate$1(path, result) {
|
|
|
1735
1731
|
});
|
|
1736
1732
|
} else id = found.id;
|
|
1737
1733
|
|
|
1734
|
+
if (result.wontEscape) {
|
|
1735
|
+
if (!Array.isArray(result.template) || result.template.length === 1) return id;
|
|
1736
|
+
else if (
|
|
1737
|
+
Array.isArray(result.template) &&
|
|
1738
|
+
result.template.length === 2 &&
|
|
1739
|
+
result.templateValues[0].type === "CallExpression" &&
|
|
1740
|
+
result.templateValues[0].callee.name === "_$ssrHydrationKey"
|
|
1741
|
+
) {
|
|
1742
|
+
// remove unnecessary ssr call when only hydration key is used
|
|
1743
|
+
return t__namespace.binaryExpression(
|
|
1744
|
+
"+",
|
|
1745
|
+
t__namespace.binaryExpression(
|
|
1746
|
+
"+",
|
|
1747
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(0), true),
|
|
1748
|
+
result.templateValues[0]
|
|
1749
|
+
),
|
|
1750
|
+
t__namespace.memberExpression(id, t__namespace.numericLiteral(1), true)
|
|
1751
|
+
);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1738
1754
|
return t__namespace.callExpression(
|
|
1739
1755
|
registerImportMethod(path, "ssr"),
|
|
1740
|
-
Array.isArray(result.template) && result.template.length > 1
|
|
1756
|
+
Array.isArray(result.template) && result.template.length > 1
|
|
1757
|
+
? [id, ...result.templateValues]
|
|
1758
|
+
: [id]
|
|
1741
1759
|
);
|
|
1742
1760
|
}
|
|
1743
1761
|
|
|
@@ -1772,6 +1790,7 @@ function transformElement$2(path, info) {
|
|
|
1772
1790
|
exprs: [],
|
|
1773
1791
|
dynamics: [],
|
|
1774
1792
|
tagName,
|
|
1793
|
+
wontEscape: path.node.wontEscape,
|
|
1775
1794
|
renderer: "ssr"
|
|
1776
1795
|
};
|
|
1777
1796
|
|
|
@@ -1821,6 +1840,7 @@ function setAttr$1(attribute, results, name, value, isSVG) {
|
|
|
1821
1840
|
let parts;
|
|
1822
1841
|
if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
|
|
1823
1842
|
name = parts[1];
|
|
1843
|
+
parts[0];
|
|
1824
1844
|
}
|
|
1825
1845
|
|
|
1826
1846
|
name = toAttribute(name, isSVG);
|
|
@@ -1890,6 +1910,9 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
|
1890
1910
|
} else
|
|
1891
1911
|
expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
|
|
1892
1912
|
return expression;
|
|
1913
|
+
} else if(t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
1914
|
+
expression.wontEscape = true;
|
|
1915
|
+
return expression;
|
|
1893
1916
|
}
|
|
1894
1917
|
|
|
1895
1918
|
return t__namespace.callExpression(
|
|
@@ -3196,27 +3219,60 @@ var config = {
|
|
|
3196
3219
|
contextToCustomElements: false,
|
|
3197
3220
|
staticMarker: "@once",
|
|
3198
3221
|
effectWrapper: "effect",
|
|
3199
|
-
memoWrapper: "memo"
|
|
3222
|
+
memoWrapper: "memo",
|
|
3223
|
+
validate: false
|
|
3224
|
+
};
|
|
3225
|
+
|
|
3226
|
+
const { isValidHTMLNesting } = require("validate-html-nesting");
|
|
3227
|
+
|
|
3228
|
+
// From https://github.com/MananTank/babel-plugin-validate-jsx-nesting/blob/main/src/index.js
|
|
3229
|
+
const JSXValidator = {
|
|
3230
|
+
JSXElement(path) {
|
|
3231
|
+
const elName = path.node.openingElement.name;
|
|
3232
|
+
if (!t__namespace.isJSXIdentifier(elName)) return;
|
|
3233
|
+
const elTagName = elName.name;
|
|
3234
|
+
if (!isComponent(elTagName)) return;
|
|
3235
|
+
const parent = path.parent;
|
|
3236
|
+
if (!t__namespace.isJSXElement(parent)) return;
|
|
3237
|
+
const parentElName = parent.openingElement.name;
|
|
3238
|
+
if (!t__namespace.isJSXIdentifier(parentElName)) return;
|
|
3239
|
+
const parentElTagName = parentElName.name;
|
|
3240
|
+
if (!isComponent(parentElTagName)) {
|
|
3241
|
+
if (!isValidHTMLNesting(parentElTagName, elTagName)) {
|
|
3242
|
+
throw path.buildCodeFrameError(
|
|
3243
|
+
`Invalid JSX: <${elTagName}> cannot be child of <${parentElTagName}>`
|
|
3244
|
+
);
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3200
3248
|
};
|
|
3201
3249
|
|
|
3202
|
-
var preprocess = (path, { opts })
|
|
3203
|
-
const merged = path.hub.file.metadata.config = Object.assign({}, config, opts);
|
|
3250
|
+
var preprocess = (path, { opts }) => {
|
|
3251
|
+
const merged = (path.hub.file.metadata.config = Object.assign({}, config, opts));
|
|
3204
3252
|
const lib = merged.requireImportSource;
|
|
3205
3253
|
if (lib) {
|
|
3206
3254
|
const comments = path.hub.file.ast.comments;
|
|
3207
|
-
|
|
3255
|
+
let process = false;
|
|
3256
|
+
for (let i = 0; i < comments.length; i++) {
|
|
3208
3257
|
const comment = comments[i];
|
|
3209
3258
|
const index = comment.value.indexOf("@jsxImportSource");
|
|
3210
|
-
if (index > -1 && comment.value.slice(index).includes(lib))
|
|
3259
|
+
if (index > -1 && comment.value.slice(index).includes(lib)) {
|
|
3260
|
+
process = true;
|
|
3261
|
+
break;
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
if (!process) {
|
|
3265
|
+
path.skip();
|
|
3266
|
+
return;
|
|
3211
3267
|
}
|
|
3212
|
-
path.skip();
|
|
3213
3268
|
}
|
|
3269
|
+
if (merged.validate) path.traverse(JSXValidator);
|
|
3214
3270
|
};
|
|
3215
3271
|
|
|
3216
3272
|
var index = () => {
|
|
3217
3273
|
return {
|
|
3218
3274
|
name: "JSX DOM Expressions",
|
|
3219
|
-
inherits:
|
|
3275
|
+
inherits: SyntaxJSX.default,
|
|
3220
3276
|
visitor: {
|
|
3221
3277
|
JSXElement: transformJSX,
|
|
3222
3278
|
JSXFragment: transformJSX,
|
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.12",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -12,20 +12,24 @@
|
|
|
12
12
|
"main": "index.js",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "rollup -c",
|
|
16
|
-
"test": "
|
|
17
|
-
"test:coverage": "
|
|
18
|
-
"prepublishOnly": "
|
|
19
|
-
"prepare": "
|
|
15
|
+
"build": "rollup -c --bundleConfigAsCjs",
|
|
16
|
+
"test": "pnpm run build && jest --no-cache",
|
|
17
|
+
"test:coverage": "pnpm run build && jest --coverage --no-cache",
|
|
18
|
+
"prepublishOnly": "pnpm run build",
|
|
19
|
+
"prepare": "pnpm run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/helper-module-imports": "7.
|
|
23
|
-
"@babel/plugin-syntax-jsx": "^7.
|
|
24
|
-
"@babel/types": "^7.
|
|
25
|
-
"html-entities": "2.3.
|
|
22
|
+
"@babel/helper-module-imports": "7.18.6",
|
|
23
|
+
"@babel/plugin-syntax-jsx": "^7.18.6",
|
|
24
|
+
"@babel/types": "^7.20.7",
|
|
25
|
+
"html-entities": "2.3.3",
|
|
26
|
+
"validate-html-nesting": "^1.0.2"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"@babel/core": "^7.
|
|
29
|
+
"@babel/core": "^7.20.12"
|
|
29
30
|
},
|
|
30
|
-
"
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@babel/core": "^7.20.12"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "7c83569e6b30a64cc08e5c8cbdc4b44235551b4b"
|
|
31
35
|
}
|