babel-plugin-jsx-dom-expressions 0.34.0-beta.1 → 0.34.1
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 +78 -31
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -548,7 +548,8 @@ function transformElement$3(path, info) {
|
|
|
548
548
|
tagName,
|
|
549
549
|
renderer: "dom"
|
|
550
550
|
};
|
|
551
|
-
if (tagName === "html"
|
|
551
|
+
if (config.hydratable && (tagName === "html" || tagName === "head" || tagName === "body"))
|
|
552
|
+
results.skipTemplate = true;
|
|
552
553
|
if (wrapSVG) results.template = "<svg>" + results.template;
|
|
553
554
|
if (!info.skipId) results.id = path.scope.generateUidIdentifier("el$");
|
|
554
555
|
transformAttributes$2(path, results);
|
|
@@ -891,14 +892,22 @@ function transformAttributes$2(path, results) {
|
|
|
891
892
|
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
892
893
|
t__namespace.stringLiteral("function")
|
|
893
894
|
),
|
|
894
|
-
t__namespace.callExpression(
|
|
895
|
+
t__namespace.callExpression(
|
|
896
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
897
|
+
[refIdentifier, elem]
|
|
898
|
+
),
|
|
895
899
|
t__namespace.assignmentExpression("=", value.expression, elem)
|
|
896
900
|
)
|
|
897
901
|
)
|
|
898
902
|
);
|
|
899
903
|
} else if (isFunction || t__namespace.isFunction(value.expression)) {
|
|
900
904
|
results.exprs.unshift(
|
|
901
|
-
t__namespace.expressionStatement(
|
|
905
|
+
t__namespace.expressionStatement(
|
|
906
|
+
t__namespace.callExpression(
|
|
907
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
908
|
+
[value.expression, elem]
|
|
909
|
+
)
|
|
910
|
+
)
|
|
902
911
|
);
|
|
903
912
|
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
904
913
|
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
@@ -914,7 +923,10 @@ function transformAttributes$2(path, results) {
|
|
|
914
923
|
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
915
924
|
t__namespace.stringLiteral("function")
|
|
916
925
|
),
|
|
917
|
-
t__namespace.callExpression(
|
|
926
|
+
t__namespace.callExpression(
|
|
927
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
928
|
+
[refIdentifier, elem]
|
|
929
|
+
)
|
|
918
930
|
)
|
|
919
931
|
)
|
|
920
932
|
);
|
|
@@ -924,15 +936,19 @@ function transformAttributes$2(path, results) {
|
|
|
924
936
|
node.name.name.type = "Identifier";
|
|
925
937
|
results.exprs.unshift(
|
|
926
938
|
t__namespace.expressionStatement(
|
|
927
|
-
t__namespace.callExpression(
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
939
|
+
t__namespace.callExpression(
|
|
940
|
+
registerImportMethod(path, "use", getRendererConfig(path, "dom").moduleName),
|
|
941
|
+
[
|
|
942
|
+
node.name.name,
|
|
943
|
+
elem,
|
|
944
|
+
t__namespace.arrowFunctionExpression(
|
|
945
|
+
[],
|
|
946
|
+
t__namespace.isJSXEmptyExpression(value.expression)
|
|
947
|
+
? t__namespace.booleanLiteral(true)
|
|
948
|
+
: value.expression
|
|
949
|
+
)
|
|
950
|
+
]
|
|
951
|
+
)
|
|
936
952
|
)
|
|
937
953
|
);
|
|
938
954
|
} else if (key === "children") {
|
|
@@ -1554,12 +1570,12 @@ function appendToTemplate(template, value) {
|
|
|
1554
1570
|
}
|
|
1555
1571
|
|
|
1556
1572
|
function transformElement$2(path, info) {
|
|
1573
|
+
const config = getConfig(path);
|
|
1557
1574
|
// contains spread attributes
|
|
1558
1575
|
if (path.node.openingElement.attributes.some(a => t__namespace.isJSXSpreadAttribute(a)))
|
|
1559
|
-
return createElement(path, info);
|
|
1576
|
+
return createElement(path, { ...info, ...config });
|
|
1560
1577
|
|
|
1561
1578
|
const tagName = getTagName(path.node),
|
|
1562
|
-
config = getConfig(path),
|
|
1563
1579
|
voidTag = VoidElements.indexOf(tagName) > -1,
|
|
1564
1580
|
results = {
|
|
1565
1581
|
template: [`<${tagName}`],
|
|
@@ -1910,6 +1926,8 @@ function transformClasslistObject(path, expr, values, quasis) {
|
|
|
1910
1926
|
function transformChildren$1(path, results, { hydratable }) {
|
|
1911
1927
|
const doNotEscape = path.doNotEscape;
|
|
1912
1928
|
const filteredChildren = filterChildren(path.get("children"));
|
|
1929
|
+
const multi = checkLength(filteredChildren),
|
|
1930
|
+
markers = hydratable && multi;
|
|
1913
1931
|
filteredChildren.forEach(node => {
|
|
1914
1932
|
if (t__namespace.isJSXElement(node.node) && getTagName(node.node) === "head") {
|
|
1915
1933
|
const child = transformNode(node, { doNotEscape, hydratable: false });
|
|
@@ -1934,9 +1952,6 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
1934
1952
|
appendToTemplate(results.template, child.template);
|
|
1935
1953
|
results.templateValues.push.apply(results.templateValues, child.templateValues || []);
|
|
1936
1954
|
if (child.exprs.length) {
|
|
1937
|
-
const multi = checkLength(filteredChildren),
|
|
1938
|
-
markers = hydratable && multi;
|
|
1939
|
-
|
|
1940
1955
|
if (!doNotEscape) child.exprs[0] = escapeExpression(path, child.exprs[0]);
|
|
1941
1956
|
|
|
1942
1957
|
// boxed by textNodes
|
|
@@ -1953,19 +1968,24 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
1953
1968
|
});
|
|
1954
1969
|
}
|
|
1955
1970
|
|
|
1956
|
-
function createElement(path, { topLevel }) {
|
|
1971
|
+
function createElement(path, { topLevel, hydratable }) {
|
|
1957
1972
|
const tagName = getTagName(path.node),
|
|
1958
1973
|
config = getConfig(path),
|
|
1959
1974
|
attributes = normalizeAttributes(path);
|
|
1960
1975
|
|
|
1961
1976
|
const filteredChildren = filterChildren(path.get("children")),
|
|
1977
|
+
multi = checkLength(filteredChildren),
|
|
1978
|
+
markers = hydratable && multi,
|
|
1962
1979
|
childNodes = filteredChildren.reduce((memo, path) => {
|
|
1963
1980
|
if (t__namespace.isJSXText(path.node)) {
|
|
1964
1981
|
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
1965
1982
|
if (v.length) memo.push(t__namespace.stringLiteral(v));
|
|
1966
1983
|
} else {
|
|
1967
1984
|
const child = transformNode(path);
|
|
1985
|
+
if (markers && child.exprs.length) memo.push(t__namespace.stringLiteral("<!--#-->"));
|
|
1986
|
+
if (hydratable && child.exprs.length) child.exprs[0] = t__namespace.arrowFunctionExpression([], child.exprs[0]);
|
|
1968
1987
|
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
1988
|
+
if (markers && child.exprs.length) memo.push(t__namespace.stringLiteral("<!--/-->"));
|
|
1969
1989
|
}
|
|
1970
1990
|
return memo;
|
|
1971
1991
|
}, []);
|
|
@@ -2139,14 +2159,30 @@ function transformAttributes(path, results) {
|
|
|
2139
2159
|
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
2140
2160
|
t__namespace.stringLiteral("function")
|
|
2141
2161
|
),
|
|
2142
|
-
t__namespace.callExpression(
|
|
2162
|
+
t__namespace.callExpression(
|
|
2163
|
+
registerImportMethod(
|
|
2164
|
+
path,
|
|
2165
|
+
"use",
|
|
2166
|
+
getRendererConfig(path, "universal").moduleName
|
|
2167
|
+
),
|
|
2168
|
+
[refIdentifier, elem]
|
|
2169
|
+
),
|
|
2143
2170
|
t__namespace.assignmentExpression("=", value.expression, elem)
|
|
2144
2171
|
)
|
|
2145
2172
|
)
|
|
2146
2173
|
);
|
|
2147
2174
|
} else if (t__namespace.isFunction(value.expression)) {
|
|
2148
2175
|
results.exprs.unshift(
|
|
2149
|
-
t__namespace.expressionStatement(
|
|
2176
|
+
t__namespace.expressionStatement(
|
|
2177
|
+
t__namespace.callExpression(
|
|
2178
|
+
registerImportMethod(
|
|
2179
|
+
path,
|
|
2180
|
+
"use",
|
|
2181
|
+
getRendererConfig(path, "universal").moduleName
|
|
2182
|
+
),
|
|
2183
|
+
[value.expression, elem]
|
|
2184
|
+
)
|
|
2185
|
+
)
|
|
2150
2186
|
);
|
|
2151
2187
|
} else if (t__namespace.isCallExpression(value.expression)) {
|
|
2152
2188
|
const refIdentifier = path.scope.generateUidIdentifier("_ref$");
|
|
@@ -2162,7 +2198,14 @@ function transformAttributes(path, results) {
|
|
|
2162
2198
|
t__namespace.unaryExpression("typeof", refIdentifier),
|
|
2163
2199
|
t__namespace.stringLiteral("function")
|
|
2164
2200
|
),
|
|
2165
|
-
t__namespace.callExpression(
|
|
2201
|
+
t__namespace.callExpression(
|
|
2202
|
+
registerImportMethod(
|
|
2203
|
+
path,
|
|
2204
|
+
"use",
|
|
2205
|
+
getRendererConfig(path, "universal").moduleName
|
|
2206
|
+
),
|
|
2207
|
+
[refIdentifier, elem]
|
|
2208
|
+
)
|
|
2166
2209
|
)
|
|
2167
2210
|
)
|
|
2168
2211
|
);
|
|
@@ -2172,15 +2215,19 @@ function transformAttributes(path, results) {
|
|
|
2172
2215
|
node.name.name.type = "Identifier";
|
|
2173
2216
|
results.exprs.unshift(
|
|
2174
2217
|
t__namespace.expressionStatement(
|
|
2175
|
-
t__namespace.callExpression(
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2218
|
+
t__namespace.callExpression(
|
|
2219
|
+
registerImportMethod(path, "use", getRendererConfig(path, "universal").moduleName),
|
|
2220
|
+
[
|
|
2221
|
+
node.name.name,
|
|
2222
|
+
elem,
|
|
2223
|
+
t__namespace.arrowFunctionExpression(
|
|
2224
|
+
[],
|
|
2225
|
+
t__namespace.isJSXEmptyExpression(value.expression)
|
|
2226
|
+
? t__namespace.booleanLiteral(true)
|
|
2227
|
+
: value.expression
|
|
2228
|
+
)
|
|
2229
|
+
]
|
|
2230
|
+
)
|
|
2184
2231
|
)
|
|
2185
2232
|
);
|
|
2186
2233
|
} else if (key === "children") {
|
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.34.
|
|
4
|
+
"version": "0.34.1",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@babel/core": "^7.0.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "5e49406921a4fde147b9b64edbfa8fc8c096fbda"
|
|
31
31
|
}
|