babel-plugin-jsx-dom-expressions 0.30.9 → 0.31.0-beta.0
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 +68 -48
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1098,6 +1098,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1098
1098
|
if (!child) return;
|
|
1099
1099
|
results.template += child.template;
|
|
1100
1100
|
if (child.id) {
|
|
1101
|
+
if (child.tagName === "head") return;
|
|
1101
1102
|
if (config.hydratable && tagName === "html") {
|
|
1102
1103
|
registerImportMethod(path, "getNextMatch");
|
|
1103
1104
|
}
|
|
@@ -1449,6 +1450,52 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1449
1450
|
);
|
|
1450
1451
|
}
|
|
1451
1452
|
|
|
1453
|
+
function createTemplate$1(path, result) {
|
|
1454
|
+
if (!result.template) {
|
|
1455
|
+
return result.exprs[0];
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
let template, id;
|
|
1459
|
+
|
|
1460
|
+
registerImportMethod(path, "ssr");
|
|
1461
|
+
if (!Array.isArray(result.template)) {
|
|
1462
|
+
template = t__namespace.stringLiteral(result.template);
|
|
1463
|
+
} else if (result.template.length === 1) {
|
|
1464
|
+
template = t__namespace.stringLiteral(result.template[0]);
|
|
1465
|
+
} else {
|
|
1466
|
+
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
1467
|
+
template = t__namespace.arrayExpression(strings);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
const templates =
|
|
1471
|
+
path.scope.getProgramParent().data.templates ||
|
|
1472
|
+
(path.scope.getProgramParent().data.templates = []);
|
|
1473
|
+
const found = templates.find(tmp => {
|
|
1474
|
+
if (t__namespace.isArrayExpression(tmp[1]) && t__namespace.isArrayExpression(template)) {
|
|
1475
|
+
return tmp[1].elements.every(
|
|
1476
|
+
(el, i) => template.elements[i] && el.value === template.elements[i].value
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
return tmp[1].value === template.value;
|
|
1480
|
+
});
|
|
1481
|
+
if (!found) {
|
|
1482
|
+
id = path.scope.generateUidIdentifier("tmpl$");
|
|
1483
|
+
templates.push([id, template]);
|
|
1484
|
+
} else id = found[0];
|
|
1485
|
+
|
|
1486
|
+
return t__namespace.callExpression(
|
|
1487
|
+
t__namespace.identifier(`_$ssr`),
|
|
1488
|
+
result.template.length > 1 ? [id, ...result.templateValues] : [id]
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
function appendTemplates(path, templates) {
|
|
1493
|
+
const declarators = templates.map(template => {
|
|
1494
|
+
return t__namespace.variableDeclarator(template[0], template[1]);
|
|
1495
|
+
});
|
|
1496
|
+
path.node.body.unshift(t__namespace.variableDeclaration("const", declarators));
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1452
1499
|
function appendToTemplate(template, value) {
|
|
1453
1500
|
let array;
|
|
1454
1501
|
if (Array.isArray(value)) {
|
|
@@ -1467,7 +1514,8 @@ function transformElement$1(path, info) {
|
|
|
1467
1514
|
templateValues: [],
|
|
1468
1515
|
decl: [],
|
|
1469
1516
|
exprs: [],
|
|
1470
|
-
dynamics: []
|
|
1517
|
+
dynamics: [],
|
|
1518
|
+
tagName
|
|
1471
1519
|
};
|
|
1472
1520
|
if (info.topLevel && config.hydratable) {
|
|
1473
1521
|
registerImportMethod(path, "ssrHydrationKey");
|
|
@@ -1477,7 +1525,7 @@ function transformElement$1(path, info) {
|
|
|
1477
1525
|
transformAttributes$1(path, results);
|
|
1478
1526
|
appendToTemplate(results.template, ">");
|
|
1479
1527
|
if (!voidTag) {
|
|
1480
|
-
transformChildren$1(path, results, config);
|
|
1528
|
+
transformChildren$1(path, results, {...config, ...info});
|
|
1481
1529
|
appendToTemplate(results.template, `</${tagName}>`);
|
|
1482
1530
|
}
|
|
1483
1531
|
return results;
|
|
@@ -1814,6 +1862,24 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
1814
1862
|
const doNotEscape = path.doNotEscape;
|
|
1815
1863
|
const filteredChildren = filterChildren(path.get("children"));
|
|
1816
1864
|
filteredChildren.forEach(node => {
|
|
1865
|
+
if (t__namespace.isJSXElement(node.node) && (getTagName(node.node) === "head")) {
|
|
1866
|
+
const child = transformNode(node, { doNotEscape, hydratable: false });
|
|
1867
|
+
registerImportMethod(path, "NoHydration");
|
|
1868
|
+
results.template.push("");
|
|
1869
|
+
results.templateValues.push(
|
|
1870
|
+
t__namespace.callExpression(t__namespace.identifier("_$NoHydration"), [
|
|
1871
|
+
t__namespace.objectExpression([
|
|
1872
|
+
t__namespace.objectMethod(
|
|
1873
|
+
"get",
|
|
1874
|
+
t__namespace.identifier("children"),
|
|
1875
|
+
[],
|
|
1876
|
+
t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$1(path, child))])
|
|
1877
|
+
)
|
|
1878
|
+
])
|
|
1879
|
+
])
|
|
1880
|
+
);
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1817
1883
|
const child = transformNode(node, { doNotEscape });
|
|
1818
1884
|
appendToTemplate(results.template, child.template);
|
|
1819
1885
|
results.templateValues.push.apply(results.templateValues, child.templateValues || []);
|
|
@@ -1837,52 +1903,6 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
1837
1903
|
});
|
|
1838
1904
|
}
|
|
1839
1905
|
|
|
1840
|
-
function createTemplate$1(path, result) {
|
|
1841
|
-
if (!result.template) {
|
|
1842
|
-
return result.exprs[0];
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
let template, id;
|
|
1846
|
-
|
|
1847
|
-
registerImportMethod(path, "ssr");
|
|
1848
|
-
if (!Array.isArray(result.template)) {
|
|
1849
|
-
template = t__namespace.stringLiteral(result.template);
|
|
1850
|
-
} else if (result.template.length === 1) {
|
|
1851
|
-
template = t__namespace.stringLiteral(result.template[0]);
|
|
1852
|
-
} else {
|
|
1853
|
-
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
1854
|
-
template = t__namespace.arrayExpression(strings);
|
|
1855
|
-
}
|
|
1856
|
-
|
|
1857
|
-
const templates =
|
|
1858
|
-
path.scope.getProgramParent().data.templates ||
|
|
1859
|
-
(path.scope.getProgramParent().data.templates = []);
|
|
1860
|
-
const found = templates.find(tmp => {
|
|
1861
|
-
if (t__namespace.isArrayExpression(tmp[1]) && t__namespace.isArrayExpression(template)) {
|
|
1862
|
-
return tmp[1].elements.every(
|
|
1863
|
-
(el, i) => template.elements[i] && el.value === template.elements[i].value
|
|
1864
|
-
);
|
|
1865
|
-
}
|
|
1866
|
-
return tmp[1].value === template.value;
|
|
1867
|
-
});
|
|
1868
|
-
if (!found) {
|
|
1869
|
-
id = path.scope.generateUidIdentifier("tmpl$");
|
|
1870
|
-
templates.push([id, template]);
|
|
1871
|
-
} else id = found[0];
|
|
1872
|
-
|
|
1873
|
-
return t__namespace.callExpression(
|
|
1874
|
-
t__namespace.identifier(`_$ssr`),
|
|
1875
|
-
result.template.length > 1 ? [id, ...result.templateValues] : [id]
|
|
1876
|
-
);
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
|
-
function appendTemplates(path, templates) {
|
|
1880
|
-
const declarators = templates.map(template => {
|
|
1881
|
-
return t__namespace.variableDeclarator(template[0], template[1]);
|
|
1882
|
-
});
|
|
1883
|
-
path.node.body.unshift(t__namespace.variableDeclaration("const", declarators));
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
1906
|
function transformElement(path, info) {
|
|
1887
1907
|
let tagName = getTagName(path.node),
|
|
1888
1908
|
results = {
|
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.
|
|
4
|
+
"version": "0.31.0-beta.0",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"@babel/types": "^7.11.5",
|
|
24
24
|
"html-entities": "2.3.2"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "bdb5b31867eb9002d0f87738a23d912ed025211b"
|
|
27
27
|
}
|