babel-plugin-jsx-dom-expressions 0.37.7 → 0.37.9
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 +82 -17
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -36,6 +36,7 @@ const booleans = [
|
|
|
36
36
|
"formnovalidate",
|
|
37
37
|
"hidden",
|
|
38
38
|
"indeterminate",
|
|
39
|
+
"inert",
|
|
39
40
|
"ismap",
|
|
40
41
|
"loop",
|
|
41
42
|
"multiple",
|
|
@@ -321,16 +322,50 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
321
322
|
expr.leadingComments.shift();
|
|
322
323
|
return false;
|
|
323
324
|
}
|
|
325
|
+
|
|
324
326
|
if (
|
|
325
|
-
|
|
326
|
-
(
|
|
327
|
-
|
|
328
|
-
t__namespace.isOptionalMemberExpression(expr) ||
|
|
329
|
-
t__namespace.isSpreadElement(expr) ||
|
|
330
|
-
(t__namespace.isBinaryExpression(expr) && expr.operator === "in"))) ||
|
|
331
|
-
(checkTags && (t__namespace.isJSXElement(expr) || t__namespace.isJSXFragment(expr)))
|
|
332
|
-
)
|
|
327
|
+
checkCallExpressions &&
|
|
328
|
+
(t__namespace.isCallExpression(expr) || t__namespace.isOptionalCallExpression(expr))
|
|
329
|
+
) {
|
|
333
330
|
return true;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (checkMember && t__namespace.isMemberExpression(expr)) {
|
|
334
|
+
// Do not assume property access on namespaced imports as dynamic.
|
|
335
|
+
const object = path.get("object").node;
|
|
336
|
+
|
|
337
|
+
if (
|
|
338
|
+
t__namespace.isIdentifier(object) &&
|
|
339
|
+
(!expr.computed ||
|
|
340
|
+
!isDynamic(path.get("property"), {
|
|
341
|
+
checkMember,
|
|
342
|
+
checkTags,
|
|
343
|
+
checkCallExpressions,
|
|
344
|
+
native,
|
|
345
|
+
}))
|
|
346
|
+
) {
|
|
347
|
+
const binding = path.scope.getBinding(object.name);
|
|
348
|
+
|
|
349
|
+
if (binding && binding.path.isImportNamespaceSpecifier()) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (
|
|
358
|
+
checkMember &&
|
|
359
|
+
(t__namespace.isOptionalMemberExpression(expr) ||
|
|
360
|
+
t__namespace.isSpreadElement(expr) ||
|
|
361
|
+
(t__namespace.isBinaryExpression(expr) && expr.operator === "in"))
|
|
362
|
+
) {
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (checkTags && (t__namespace.isJSXElement(expr) || t__namespace.isJSXFragment(expr))) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
334
369
|
|
|
335
370
|
let dynamic;
|
|
336
371
|
path.traverse({
|
|
@@ -2378,7 +2413,7 @@ function transformAttributes$1(path, results, info) {
|
|
|
2378
2413
|
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
2379
2414
|
key = toAttribute(key, isSVG);
|
|
2380
2415
|
const isBoolean = BooleanAttributes.has(key);
|
|
2381
|
-
if (isBoolean && value.value !== "" && !value.value) return;
|
|
2416
|
+
if (isBoolean && value && value.value !== "" && !value.value) return;
|
|
2382
2417
|
appendToTemplate(results.template, ` ${key}`);
|
|
2383
2418
|
if (!value) return;
|
|
2384
2419
|
let text = isBoolean ? "" : value.value;
|
|
@@ -3054,6 +3089,7 @@ function wrapDynamics(path, dynamics) {
|
|
|
3054
3089
|
|
|
3055
3090
|
function convertComponentIdentifier(node) {
|
|
3056
3091
|
if (t__namespace.isJSXIdentifier(node)) {
|
|
3092
|
+
if (node.name === 'this') return t__namespace.thisExpression();
|
|
3057
3093
|
if (t__namespace.isValidIdentifier(node.name)) node.type = "Identifier";
|
|
3058
3094
|
else return t__namespace.stringLiteral(node.name);
|
|
3059
3095
|
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
@@ -3352,21 +3388,50 @@ function transformJSX(path) {
|
|
|
3352
3388
|
path.replaceWith(replace(template(path, result, false)));
|
|
3353
3389
|
}
|
|
3354
3390
|
|
|
3391
|
+
function getTargetFunctionParent(path, parent) {
|
|
3392
|
+
let current = path.scope.getFunctionParent();
|
|
3393
|
+
while (current !== parent && current.path.isArrowFunctionExpression()) {
|
|
3394
|
+
current = current.path.parentPath.scope.getFunctionParent();
|
|
3395
|
+
}
|
|
3396
|
+
return current;
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3355
3399
|
function transformThis(path) {
|
|
3400
|
+
const parent = path.scope.getFunctionParent();
|
|
3356
3401
|
let thisId;
|
|
3357
3402
|
path.traverse({
|
|
3358
3403
|
ThisExpression(path) {
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3404
|
+
const current = getTargetFunctionParent(path, parent);
|
|
3405
|
+
if (current === parent) {
|
|
3406
|
+
thisId || (thisId = path.scope.generateUidIdentifier("self$"));
|
|
3407
|
+
path.replaceWith(thisId);
|
|
3408
|
+
}
|
|
3409
|
+
},
|
|
3410
|
+
JSXElement(path) {
|
|
3411
|
+
let source = path.get('openingElement').get('name');
|
|
3412
|
+
while (source.isJSXMemberExpression()) {
|
|
3413
|
+
source = source.get('object');
|
|
3414
|
+
}
|
|
3415
|
+
if (source.isJSXIdentifier() && source.node.name === 'this') {
|
|
3416
|
+
const current = getTargetFunctionParent(path, parent);
|
|
3417
|
+
if (current === parent) {
|
|
3418
|
+
thisId || (thisId = path.scope.generateUidIdentifier("self$"));
|
|
3419
|
+
source.replaceWith(t__namespace.jsxIdentifier(thisId.name));
|
|
3420
|
+
|
|
3421
|
+
if (path.node.closingElement) {
|
|
3422
|
+
path.node.closingElement.name = path.node.openingElement.name;
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
},
|
|
3362
3427
|
});
|
|
3363
3428
|
return node => {
|
|
3364
3429
|
if (thisId) {
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3430
|
+
parent.push({
|
|
3431
|
+
id: thisId,
|
|
3432
|
+
init: t__namespace.thisExpression(),
|
|
3433
|
+
kind: 'const',
|
|
3434
|
+
});
|
|
3370
3435
|
}
|
|
3371
3436
|
return node;
|
|
3372
3437
|
};
|
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.9",
|
|
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": "2079bbeb5908166253370dd02ba1ce99afb2a2d4"
|
|
35
35
|
}
|