babel-plugin-jsx-dom-expressions 0.35.14 → 0.35.16
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 +117 -50
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1911,7 +1911,7 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
|
|
|
1911
1911
|
} else
|
|
1912
1912
|
expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
|
|
1913
1913
|
return expression;
|
|
1914
|
-
} else if(t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
1914
|
+
} else if (t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
|
|
1915
1915
|
expression.wontEscape = true;
|
|
1916
1916
|
return expression;
|
|
1917
1917
|
}
|
|
@@ -2240,66 +2240,133 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2240
2240
|
return memo;
|
|
2241
2241
|
}, []);
|
|
2242
2242
|
|
|
2243
|
-
let
|
|
2243
|
+
let props;
|
|
2244
2244
|
if (attributes.length === 1) {
|
|
2245
|
-
|
|
2245
|
+
props = [attributes[0].node.argument];
|
|
2246
2246
|
} else {
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
const node = attribute.node;
|
|
2252
|
-
|
|
2253
|
-
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
2254
|
-
const expr = node.argument;
|
|
2255
|
-
memo.push(t__namespace.spreadElement(expr));
|
|
2256
|
-
return memo;
|
|
2257
|
-
}
|
|
2258
|
-
let value = node.value,
|
|
2259
|
-
key = t__namespace.isJSXNamespacedName(node.name)
|
|
2260
|
-
? `${node.name.namespace.name}:${node.name.name.name}`
|
|
2261
|
-
: node.name.name,
|
|
2262
|
-
reservedNameSpace =
|
|
2263
|
-
t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
2264
|
-
if (
|
|
2265
|
-
((t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
|
|
2266
|
-
!t__namespace.isJSXExpressionContainer(value)
|
|
2267
|
-
) {
|
|
2268
|
-
node.value = value = t__namespace.JSXExpressionContainer(value || t__namespace.JSXEmptyExpression());
|
|
2269
|
-
}
|
|
2247
|
+
props = [];
|
|
2248
|
+
let runningObject = [],
|
|
2249
|
+
dynamicSpread = false,
|
|
2250
|
+
hasChildren = path.node.children.length > 0;
|
|
2270
2251
|
|
|
2252
|
+
attributes.forEach(attribute => {
|
|
2253
|
+
const node = attribute.node;
|
|
2254
|
+
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
2255
|
+
if (runningObject.length) {
|
|
2256
|
+
props.push(t__namespace.objectExpression(runningObject));
|
|
2257
|
+
runningObject = [];
|
|
2258
|
+
}
|
|
2259
|
+
props.push(
|
|
2260
|
+
isDynamic(attribute.get("argument"), {
|
|
2261
|
+
checkMember: true
|
|
2262
|
+
}) && (dynamicSpread = true)
|
|
2263
|
+
? t__namespace.isCallExpression(node.argument) &&
|
|
2264
|
+
!node.argument.arguments.length &&
|
|
2265
|
+
!t__namespace.isCallExpression(node.argument.callee) &&
|
|
2266
|
+
!t__namespace.isMemberExpression(node.argument.callee)
|
|
2267
|
+
? node.argument.callee
|
|
2268
|
+
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
2269
|
+
: node.argument
|
|
2270
|
+
);
|
|
2271
|
+
} else {
|
|
2272
|
+
const value = node.value || t__namespace.booleanLiteral(true),
|
|
2273
|
+
id = convertJSXIdentifier(node.name),
|
|
2274
|
+
key = t__namespace.isJSXNamespacedName(node.name)
|
|
2275
|
+
? `${node.name.namespace.name}:${node.name.name.name}`
|
|
2276
|
+
: node.name.name;
|
|
2277
|
+
|
|
2278
|
+
if (hasChildren && key === "children") return;
|
|
2279
|
+
if (
|
|
2280
|
+
key === "ref" ||
|
|
2281
|
+
key.startsWith("use:") ||
|
|
2282
|
+
key.startsWith("prop:") ||
|
|
2283
|
+
key.startsWith("on")
|
|
2284
|
+
)
|
|
2285
|
+
return;
|
|
2286
|
+
if (t__namespace.isJSXExpressionContainer(value))
|
|
2271
2287
|
if (
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2288
|
+
isDynamic(attribute.get("value").get("expression"), {
|
|
2289
|
+
checkMember: true,
|
|
2290
|
+
checkTags: true
|
|
2291
|
+
})
|
|
2276
2292
|
) {
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
} else {
|
|
2287
|
-
if (key === "$ServerOnly") return memo;
|
|
2288
|
-
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
2289
|
-
memo.push(
|
|
2290
|
-
t__namespace.objectProperty(t__namespace.stringLiteral(key), value ? value : t__namespace.booleanLiteral(true))
|
|
2293
|
+
let expr = t__namespace.arrowFunctionExpression([], value.expression);
|
|
2294
|
+
runningObject.push(
|
|
2295
|
+
t__namespace.objectMethod(
|
|
2296
|
+
"get",
|
|
2297
|
+
id,
|
|
2298
|
+
[],
|
|
2299
|
+
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
2300
|
+
!t__namespace.isValidIdentifier(key)
|
|
2301
|
+
)
|
|
2291
2302
|
);
|
|
2292
|
-
}
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2303
|
+
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
2304
|
+
else runningObject.push(t__namespace.objectProperty(id, value));
|
|
2305
|
+
}
|
|
2306
|
+
});
|
|
2307
|
+
|
|
2308
|
+
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
2309
|
+
|
|
2310
|
+
if (props.length > 1 || dynamicSpread) {
|
|
2311
|
+
props = [t__namespace.callExpression(registerImportMethod(path, "mergeProps"), props)];
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
// transformed = t.arrowFunctionExpression(
|
|
2315
|
+
// [],
|
|
2316
|
+
// t.objectExpression(
|
|
2317
|
+
// attributes.reduce((memo, attribute) => {
|
|
2318
|
+
// const node = attribute.node;
|
|
2319
|
+
|
|
2320
|
+
// if (t.isJSXSpreadAttribute(node)) {
|
|
2321
|
+
// const expr = node.argument;
|
|
2322
|
+
// memo.push(t.spreadElement(expr));
|
|
2323
|
+
// return memo;
|
|
2324
|
+
// }
|
|
2325
|
+
// let value = node.value,
|
|
2326
|
+
// key = t.isJSXNamespacedName(node.name)
|
|
2327
|
+
// ? `${node.name.namespace.name}:${node.name.name.name}`
|
|
2328
|
+
// : node.name.name,
|
|
2329
|
+
// reservedNameSpace =
|
|
2330
|
+
// t.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
2331
|
+
// if (
|
|
2332
|
+
// ((t.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
|
|
2333
|
+
// !t.isJSXExpressionContainer(value)
|
|
2334
|
+
// ) {
|
|
2335
|
+
// node.value = value = t.JSXExpressionContainer(value || t.JSXEmptyExpression());
|
|
2336
|
+
// }
|
|
2337
|
+
|
|
2338
|
+
// if (
|
|
2339
|
+
// t.isJSXExpressionContainer(value) &&
|
|
2340
|
+
// (reservedNameSpace ||
|
|
2341
|
+
// ChildProperties.has(key) ||
|
|
2342
|
+
// !(t.isStringLiteral(value.expression) || t.isNumericLiteral(value.expression)))
|
|
2343
|
+
// ) {
|
|
2344
|
+
// if (
|
|
2345
|
+
// key === "ref" ||
|
|
2346
|
+
// key.startsWith("use:") ||
|
|
2347
|
+
// key.startsWith("prop:") ||
|
|
2348
|
+
// key.startsWith("on")
|
|
2349
|
+
// )
|
|
2350
|
+
// return memo;
|
|
2351
|
+
|
|
2352
|
+
// memo.push(t.objectProperty(t.stringLiteral(key), value.expression));
|
|
2353
|
+
// } else {
|
|
2354
|
+
// if (key === "$ServerOnly") return memo;
|
|
2355
|
+
// if (t.isJSXExpressionContainer(value)) value = value.expression;
|
|
2356
|
+
// memo.push(
|
|
2357
|
+
// t.objectProperty(t.stringLiteral(key), value ? value : t.booleanLiteral(true))
|
|
2358
|
+
// );
|
|
2359
|
+
// }
|
|
2360
|
+
// return memo;
|
|
2361
|
+
// }, [])
|
|
2362
|
+
// )
|
|
2363
|
+
// );
|
|
2297
2364
|
}
|
|
2298
2365
|
|
|
2299
2366
|
const exprs = [
|
|
2300
2367
|
t__namespace.callExpression(registerImportMethod(path, "ssrElement"), [
|
|
2301
2368
|
t__namespace.stringLiteral(tagName),
|
|
2302
|
-
|
|
2369
|
+
props[0],
|
|
2303
2370
|
childNodes.length
|
|
2304
2371
|
? hydratable
|
|
2305
2372
|
? t__namespace.arrowFunctionExpression(
|
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.16",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@babel/plugin-syntax-jsx": "^7.18.6",
|
|
24
24
|
"@babel/types": "^7.20.7",
|
|
25
25
|
"html-entities": "2.3.3",
|
|
26
|
-
"validate-html-nesting": "^1.2.
|
|
26
|
+
"validate-html-nesting": "^1.2.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@babel/core": "^7.20.12"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@babel/core": "^7.20.12"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "764c717918d199a630bb0c7f85c7b8f772ef9e07"
|
|
35
35
|
}
|