babel-plugin-jsx-dom-expressions 0.35.16 → 0.35.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/README.md +14 -10
- package/index.js +41 -40
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,29 +38,33 @@ const view = ({ item }) => {
|
|
|
38
38
|
Compiles to:
|
|
39
39
|
|
|
40
40
|
```jsx
|
|
41
|
-
import {
|
|
41
|
+
import { template as _$template } from "dom";
|
|
42
|
+
import { delegateEvents as _$delegateEvents } from "dom";
|
|
43
|
+
import { className as _$className } from "dom";
|
|
42
44
|
import { effect as _$effect } from "dom";
|
|
45
|
+
import { insert as _$insert } from "dom";
|
|
43
46
|
|
|
44
|
-
const _tmpl$ =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const _tmpl$ = /*#__PURE__*/_$template(`<tr><td class="col-md-1"></td><td class="col-md-4"><a></a></td><td class="col-md-1"><a><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr>`, 16);
|
|
48
|
+
const view = ({
|
|
49
|
+
item
|
|
50
|
+
}) => {
|
|
48
51
|
const itemId = item.id;
|
|
49
|
-
return (
|
|
50
|
-
const _el$ = _tmpl$.
|
|
52
|
+
return (() => {
|
|
53
|
+
const _el$ = _tmpl$.cloneNode(true),
|
|
51
54
|
_el$2 = _el$.firstChild,
|
|
52
55
|
_el$3 = _el$2.nextSibling,
|
|
53
56
|
_el$4 = _el$3.firstChild,
|
|
54
57
|
_el$5 = _el$3.nextSibling,
|
|
55
58
|
_el$6 = _el$5.firstChild;
|
|
56
|
-
_$effect(() => (_el$.className = itemId === selected() ? "danger" : ""));
|
|
57
59
|
_$insert(_el$2, itemId);
|
|
58
|
-
_el$4
|
|
60
|
+
_el$4.$$click = e => select(item, e);
|
|
59
61
|
_$insert(_el$4, () => item.label);
|
|
60
|
-
_el$6
|
|
62
|
+
_el$6.$$click = e => del(item, e);
|
|
63
|
+
_$effect(() => _$className(_el$, itemId === selected() ? "danger" : ""));
|
|
61
64
|
return _el$;
|
|
62
65
|
})();
|
|
63
66
|
};
|
|
67
|
+
_$delegateEvents(["click"]);
|
|
64
68
|
```
|
|
65
69
|
|
|
66
70
|
The use of cloneNode improves repeat insert performance and precompilation reduces the number of references to the minimal traversal path. This is a basic example which doesn't leverage event delegation or any of the more advanced features described below.
|
package/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var SyntaxJSX = require('@babel/plugin-syntax-jsx');
|
|
4
4
|
var t = require('@babel/types');
|
|
5
|
-
var helperModuleImports = require('@babel/helper-module-imports');
|
|
6
5
|
var htmlEntities = require('html-entities');
|
|
6
|
+
var helperModuleImports = require('@babel/helper-module-imports');
|
|
7
7
|
|
|
8
8
|
function _interopNamespaceDefault(e) {
|
|
9
9
|
var n = Object.create(null);
|
|
@@ -261,7 +261,7 @@ function registerImportMethod(path, name, moduleName) {
|
|
|
261
261
|
// the cloning is required to play well with babel-preset-env which is
|
|
262
262
|
// transpiling import as we add them and using the same identifier causes
|
|
263
263
|
// problems with the multiple identifiers of the same thing
|
|
264
|
-
return t__namespace.
|
|
264
|
+
return t__namespace.cloneNode(iden);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -585,7 +585,7 @@ function transformElement$3(path, info) {
|
|
|
585
585
|
isCustomElement = tagName.indexOf("-") > -1,
|
|
586
586
|
results = {
|
|
587
587
|
template: `<${tagName}`,
|
|
588
|
-
|
|
588
|
+
declarations: [],
|
|
589
589
|
exprs: [],
|
|
590
590
|
dynamics: [],
|
|
591
591
|
postExprs: [],
|
|
@@ -1157,7 +1157,7 @@ function transformAttributes$2(path, results) {
|
|
|
1157
1157
|
nextElem = attribute.scope.generateUidIdentifier("el$");
|
|
1158
1158
|
children = t__namespace.JSXText(" ");
|
|
1159
1159
|
children.extra = { raw: " ", rawValue: " " };
|
|
1160
|
-
results.
|
|
1160
|
+
results.declarations.push(
|
|
1161
1161
|
t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild")))
|
|
1162
1162
|
);
|
|
1163
1163
|
}
|
|
@@ -1181,7 +1181,7 @@ function transformAttributes$2(path, results) {
|
|
|
1181
1181
|
} else {
|
|
1182
1182
|
!isSVG && (key = key.toLowerCase());
|
|
1183
1183
|
results.template += ` ${key}`;
|
|
1184
|
-
results.template += value ? `="${escapeBackticks(escapeHTML(value.value, true))}"` : "";
|
|
1184
|
+
results.template += value ? `="${escapeBackticks(escapeHTML(htmlEntities.decode(value.value), true))}"` : "";
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
1187
1187
|
});
|
|
@@ -1258,7 +1258,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1258
1258
|
t__namespace.identifier(tempPath),
|
|
1259
1259
|
t__namespace.identifier(i === 0 ? "firstChild" : "nextSibling")
|
|
1260
1260
|
);
|
|
1261
|
-
results.
|
|
1261
|
+
results.declarations.push(
|
|
1262
1262
|
t__namespace.variableDeclarator(
|
|
1263
1263
|
child.id,
|
|
1264
1264
|
config.hydratable && tagName === "html"
|
|
@@ -1266,7 +1266,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1266
1266
|
: walk
|
|
1267
1267
|
)
|
|
1268
1268
|
);
|
|
1269
|
-
results.
|
|
1269
|
+
results.declarations.push(...child.declarations);
|
|
1270
1270
|
results.exprs.push(...child.exprs);
|
|
1271
1271
|
results.dynamics.push(...child.dynamics);
|
|
1272
1272
|
results.postExprs.push(...child.postExprs);
|
|
@@ -1326,7 +1326,7 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1326
1326
|
results.template += `<!${char}>`;
|
|
1327
1327
|
if (config.hydratable && char === "/") {
|
|
1328
1328
|
contentId = path.scope.generateUidIdentifier("co$");
|
|
1329
|
-
results.
|
|
1329
|
+
results.declarations.push(
|
|
1330
1330
|
t__namespace.variableDeclarator(
|
|
1331
1331
|
t__namespace.arrayPattern([exprId, contentId]),
|
|
1332
1332
|
t__namespace.callExpression(
|
|
@@ -1336,7 +1336,7 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1336
1336
|
)
|
|
1337
1337
|
);
|
|
1338
1338
|
} else
|
|
1339
|
-
results.
|
|
1339
|
+
results.declarations.push(
|
|
1340
1340
|
t__namespace.variableDeclarator(
|
|
1341
1341
|
exprId,
|
|
1342
1342
|
t__namespace.memberExpression(
|
|
@@ -1602,8 +1602,8 @@ function registerTemplate(path, results) {
|
|
|
1602
1602
|
])
|
|
1603
1603
|
);
|
|
1604
1604
|
}
|
|
1605
|
-
results.
|
|
1606
|
-
results.decl = t__namespace.variableDeclaration("const", results.
|
|
1605
|
+
results.declarations.unshift(decl);
|
|
1606
|
+
results.decl = t__namespace.variableDeclaration("const", results.declarations);
|
|
1607
1607
|
}
|
|
1608
1608
|
|
|
1609
1609
|
function wrapDynamics$1(path, dynamics) {
|
|
@@ -1639,7 +1639,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1639
1639
|
])
|
|
1640
1640
|
);
|
|
1641
1641
|
}
|
|
1642
|
-
const
|
|
1642
|
+
const declarations = [],
|
|
1643
1643
|
statements = [],
|
|
1644
1644
|
identifiers = [],
|
|
1645
1645
|
prevId = t__namespace.identifier("_p$");
|
|
@@ -1649,7 +1649,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1649
1649
|
value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
|
|
1650
1650
|
}
|
|
1651
1651
|
identifiers.push(identifier);
|
|
1652
|
-
|
|
1652
|
+
declarations.push(t__namespace.variableDeclarator(identifier, value));
|
|
1653
1653
|
if (key === "classList" || key === "style") {
|
|
1654
1654
|
const prev = t__namespace.memberExpression(prevId, identifier);
|
|
1655
1655
|
statements.push(
|
|
@@ -1685,7 +1685,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1685
1685
|
t__namespace.arrowFunctionExpression(
|
|
1686
1686
|
[prevId],
|
|
1687
1687
|
t__namespace.blockStatement([
|
|
1688
|
-
t__namespace.variableDeclaration("const",
|
|
1688
|
+
t__namespace.variableDeclaration("const", declarations),
|
|
1689
1689
|
...statements,
|
|
1690
1690
|
t__namespace.returnStatement(prevId)
|
|
1691
1691
|
])
|
|
@@ -1786,7 +1786,7 @@ function transformElement$2(path, info) {
|
|
|
1786
1786
|
results = {
|
|
1787
1787
|
template: [`<${tagName}`],
|
|
1788
1788
|
templateValues: [],
|
|
1789
|
-
|
|
1789
|
+
declarations: [],
|
|
1790
1790
|
exprs: [],
|
|
1791
1791
|
dynamics: [],
|
|
1792
1792
|
tagName,
|
|
@@ -2126,7 +2126,7 @@ function transformAttributes$1(path, results, info) {
|
|
|
2126
2126
|
if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
|
|
2127
2127
|
key = toAttribute(key, isSVG);
|
|
2128
2128
|
appendToTemplate(results.template, ` ${key}`);
|
|
2129
|
-
appendToTemplate(results.template, value ? `="${escapeHTML(value.value, true)}"` : "");
|
|
2129
|
+
appendToTemplate(results.template, value ? `="${escapeHTML(htmlEntities.decode(value.value), true)}"` : "");
|
|
2130
2130
|
}
|
|
2131
2131
|
});
|
|
2132
2132
|
if (!hasChildren && children) {
|
|
@@ -2387,7 +2387,7 @@ function transformElement$1(path, info) {
|
|
|
2387
2387
|
let tagName = getTagName(path.node),
|
|
2388
2388
|
results = {
|
|
2389
2389
|
id: path.scope.generateUidIdentifier("el$"),
|
|
2390
|
-
|
|
2390
|
+
declarations: [],
|
|
2391
2391
|
exprs: [],
|
|
2392
2392
|
dynamics: [],
|
|
2393
2393
|
postExprs: [],
|
|
@@ -2395,7 +2395,7 @@ function transformElement$1(path, info) {
|
|
|
2395
2395
|
renderer: "universal"
|
|
2396
2396
|
};
|
|
2397
2397
|
|
|
2398
|
-
results.
|
|
2398
|
+
results.declarations.push(
|
|
2399
2399
|
t__namespace.variableDeclarator(
|
|
2400
2400
|
results.id,
|
|
2401
2401
|
t__namespace.callExpression(
|
|
@@ -2611,7 +2611,7 @@ function transformChildren(path, results) {
|
|
|
2611
2611
|
getRendererConfig(path, "universal").moduleName
|
|
2612
2612
|
);
|
|
2613
2613
|
if (multi) {
|
|
2614
|
-
results.
|
|
2614
|
+
results.declarations.push(
|
|
2615
2615
|
t__namespace.variableDeclarator(
|
|
2616
2616
|
child.id,
|
|
2617
2617
|
t__namespace.callExpression(createTextNode, [
|
|
@@ -2625,7 +2625,7 @@ function transformChildren(path, results) {
|
|
|
2625
2625
|
]);
|
|
2626
2626
|
}
|
|
2627
2627
|
appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
|
|
2628
|
-
results.
|
|
2628
|
+
results.declarations.push(...child.declarations);
|
|
2629
2629
|
results.exprs.push(...child.exprs);
|
|
2630
2630
|
results.dynamics.push(...child.dynamics);
|
|
2631
2631
|
} else if (child.exprs.length) {
|
|
@@ -2749,7 +2749,7 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
2749
2749
|
function createTemplate(path, result, wrap) {
|
|
2750
2750
|
const config = getConfig(path);
|
|
2751
2751
|
if (result.id) {
|
|
2752
|
-
result.decl = t__namespace.variableDeclaration("const", result.
|
|
2752
|
+
result.decl = t__namespace.variableDeclaration("const", result.declarations);
|
|
2753
2753
|
if (
|
|
2754
2754
|
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
2755
2755
|
result.decl.declarations.length === 1
|
|
@@ -2799,14 +2799,14 @@ function wrapDynamics(path, dynamics) {
|
|
|
2799
2799
|
])
|
|
2800
2800
|
);
|
|
2801
2801
|
}
|
|
2802
|
-
const
|
|
2802
|
+
const declarations = [],
|
|
2803
2803
|
statements = [],
|
|
2804
2804
|
identifiers = [],
|
|
2805
2805
|
prevId = t__namespace.identifier("_p$");
|
|
2806
2806
|
dynamics.forEach(({ elem, key, value }) => {
|
|
2807
2807
|
const identifier = path.scope.generateUidIdentifier("v$");
|
|
2808
2808
|
identifiers.push(identifier);
|
|
2809
|
-
|
|
2809
|
+
declarations.push(t__namespace.variableDeclarator(identifier, value));
|
|
2810
2810
|
const prev = t__namespace.memberExpression(prevId, identifier);
|
|
2811
2811
|
statements.push(
|
|
2812
2812
|
t__namespace.expressionStatement(
|
|
@@ -2830,7 +2830,7 @@ function wrapDynamics(path, dynamics) {
|
|
|
2830
2830
|
t__namespace.arrowFunctionExpression(
|
|
2831
2831
|
[prevId],
|
|
2832
2832
|
t__namespace.blockStatement([
|
|
2833
|
-
t__namespace.variableDeclaration("const",
|
|
2833
|
+
t__namespace.variableDeclaration("const", declarations),
|
|
2834
2834
|
...statements,
|
|
2835
2835
|
t__namespace.returnStatement(prevId)
|
|
2836
2836
|
])
|
|
@@ -3032,11 +3032,15 @@ function transformComponentChildren(children, config) {
|
|
|
3032
3032
|
const filteredChildren = filterChildren(children);
|
|
3033
3033
|
if (!filteredChildren.length) return;
|
|
3034
3034
|
let dynamic = false;
|
|
3035
|
+
let pathNodes = [];
|
|
3035
3036
|
|
|
3036
3037
|
let transformedChildren = filteredChildren.reduce((memo, path) => {
|
|
3037
3038
|
if (t__namespace.isJSXText(path.node)) {
|
|
3038
3039
|
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
3039
|
-
if (v.length)
|
|
3040
|
+
if (v.length) {
|
|
3041
|
+
pathNodes.push(path.node);
|
|
3042
|
+
memo.push(t__namespace.stringLiteral(v));
|
|
3043
|
+
}
|
|
3040
3044
|
} else {
|
|
3041
3045
|
const child = transformNode(path, {
|
|
3042
3046
|
topLevel: true,
|
|
@@ -3051,6 +3055,7 @@ function transformComponentChildren(children, config) {
|
|
|
3051
3055
|
) {
|
|
3052
3056
|
child.exprs[0] = child.exprs[0].body;
|
|
3053
3057
|
}
|
|
3058
|
+
pathNodes.push(path.node);
|
|
3054
3059
|
memo.push(getCreateTemplate(config, path, child)(path, child, filteredChildren.length > 1));
|
|
3055
3060
|
}
|
|
3056
3061
|
return memo;
|
|
@@ -3059,9 +3064,9 @@ function transformComponentChildren(children, config) {
|
|
|
3059
3064
|
if (transformedChildren.length === 1) {
|
|
3060
3065
|
transformedChildren = transformedChildren[0];
|
|
3061
3066
|
if (
|
|
3062
|
-
!t__namespace.isJSXExpressionContainer(
|
|
3063
|
-
!t__namespace.isJSXSpreadChild(
|
|
3064
|
-
!t__namespace.isJSXText(
|
|
3067
|
+
!t__namespace.isJSXExpressionContainer(pathNodes[0]) &&
|
|
3068
|
+
!t__namespace.isJSXSpreadChild(pathNodes[0]) &&
|
|
3069
|
+
!t__namespace.isJSXText(pathNodes[0])
|
|
3065
3070
|
) {
|
|
3066
3071
|
transformedChildren =
|
|
3067
3072
|
t__namespace.isCallExpression(transformedChildren) &&
|
|
@@ -3137,21 +3142,21 @@ function transformNode(path, info = {}) {
|
|
|
3137
3142
|
if (t__namespace.isJSXElement(node)) {
|
|
3138
3143
|
return transformElement(config, path, info);
|
|
3139
3144
|
} else if (t__namespace.isJSXFragment(node)) {
|
|
3140
|
-
let results = { template: "",
|
|
3145
|
+
let results = { template: "", declarations: [], exprs: [], dynamics: [] };
|
|
3141
3146
|
// <><div /><Component /></>
|
|
3142
3147
|
transformFragmentChildren(path.get("children"), results, config);
|
|
3143
3148
|
return results;
|
|
3144
3149
|
} else if (t__namespace.isJSXText(node) || (staticValue = getStaticExpression(path))) {
|
|
3145
3150
|
const text =
|
|
3146
3151
|
staticValue !== undefined
|
|
3147
|
-
?
|
|
3148
|
-
?
|
|
3149
|
-
: staticValue.toString()
|
|
3152
|
+
? info.doNotEscape
|
|
3153
|
+
? staticValue.toString()
|
|
3154
|
+
: escapeHTML(staticValue.toString())
|
|
3150
3155
|
: trimWhitespace(node.extra.raw);
|
|
3151
3156
|
if (!text.length) return null;
|
|
3152
3157
|
const results = {
|
|
3153
3158
|
template: config.generate === "ssr" ? text : escapeBackticks(text),
|
|
3154
|
-
|
|
3159
|
+
declarations: [],
|
|
3155
3160
|
exprs: [],
|
|
3156
3161
|
dynamics: [],
|
|
3157
3162
|
postExprs: [],
|
|
@@ -3237,13 +3242,9 @@ function transformElement(config, path, info = {}) {
|
|
|
3237
3242
|
// <div ...></div>
|
|
3238
3243
|
// const element = getTransformElemet(config, path, tagName);
|
|
3239
3244
|
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
tagRenderer = renderer;
|
|
3244
|
-
break;
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
3245
|
+
const tagRenderer = (config.renderers ?? []).find(
|
|
3246
|
+
renderer => renderer.elements.includes(tagName)
|
|
3247
|
+
);
|
|
3247
3248
|
|
|
3248
3249
|
if (tagRenderer?.name === "dom" || getConfig(path).generate === "dom") {
|
|
3249
3250
|
return transformElement$3(path, info);
|
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.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": "fbbe545542d31315282b78accbba552b686085b5"
|
|
35
35
|
}
|