solid-optimizer 1.0.0-next.4 → 1.0.0-next.5
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 +2 -1
- package/dist/{compile-Dx577-sp.mjs → compile-By9Fecbx.mjs} +611 -147
- package/dist/compile-By9Fecbx.mjs.map +1 -0
- package/dist/{compile-CwH9mvHD.d.mts → compile-X_SMDFr2.d.mts} +9 -1
- package/dist/compile-X_SMDFr2.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +195 -74
- package/dist/vite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ast.ts +4 -3
- package/src/compile.ts +39 -6
- package/src/conditional.ts +540 -0
- package/src/constants.ts +9 -5
- package/src/context.ts +1 -1
- package/src/fold.ts +109 -57
- package/src/inline.ts +274 -112
- package/src/jsx.ts +13 -9
- package/src/memo.ts +13 -13
- package/src/provider.ts +62 -40
- package/src/size.ts +6 -1
- package/src/value.ts +32 -15
- package/src/vite/globals.ts +26 -11
- package/src/vite/index.ts +169 -66
- package/src/vite/inject.ts +27 -15
- package/src/vite/report.ts +21 -12
- package/src/vite/runtime.ts +32 -6
- package/src/vite/usage.ts +89 -48
- package/dist/compile-CwH9mvHD.d.mts.map +0 -1
- package/dist/compile-Dx577-sp.mjs.map +0 -1
|
@@ -67,7 +67,7 @@ function collectParents(program) {
|
|
|
67
67
|
const RAW_TRANSFER = rawTransferSupported();
|
|
68
68
|
function parse(filename, code) {
|
|
69
69
|
const options = {
|
|
70
|
-
lang:
|
|
70
|
+
lang: getLanguage(filename),
|
|
71
71
|
sourceType: "module",
|
|
72
72
|
preserveParens: true,
|
|
73
73
|
experimentalRawTransfer: RAW_TRANSFER
|
|
@@ -77,7 +77,7 @@ function parse(filename, code) {
|
|
|
77
77
|
if (error) throw new SyntaxError(`[solid-optimizer] ${filename}: ${error.codeframe ?? error.message}`);
|
|
78
78
|
return result.program;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function getLanguage(filename) {
|
|
81
81
|
if (/\.tsx$/i.test(filename)) return "tsx";
|
|
82
82
|
if (/\.[cm]?ts$/i.test(filename)) return "ts";
|
|
83
83
|
return "jsx";
|
|
@@ -87,7 +87,7 @@ function languageOf(filename) {
|
|
|
87
87
|
*/
|
|
88
88
|
function unwrap(node) {
|
|
89
89
|
let current = node;
|
|
90
|
-
while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion") current = current.expression;
|
|
90
|
+
while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion" || current.type === "TSInstantiationExpression") current = current.expression;
|
|
91
91
|
return current;
|
|
92
92
|
}
|
|
93
93
|
function isFunctionNode(node) {
|
|
@@ -221,7 +221,7 @@ function recordSkip(context, pass, reason, name) {
|
|
|
221
221
|
/**
|
|
222
222
|
* The current text of `node`, including the edits made inside it so far.
|
|
223
223
|
*/
|
|
224
|
-
function
|
|
224
|
+
function getText(context, node) {
|
|
225
225
|
return context.s.slice(node.start, node.end);
|
|
226
226
|
}
|
|
227
227
|
//#endregion
|
|
@@ -728,6 +728,10 @@ function truthiness(node, lookup) {
|
|
|
728
728
|
const value = evaluate(node, lookup);
|
|
729
729
|
return value ? !!value.value : void 0;
|
|
730
730
|
}
|
|
731
|
+
function areSideEffectFree(nodes) {
|
|
732
|
+
for (const node of nodes) if (!isSideEffectFree(node)) return false;
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
731
735
|
/**
|
|
732
736
|
* Whether skipping `node` entirely loses nothing observable.
|
|
733
737
|
*
|
|
@@ -743,14 +747,18 @@ function isSideEffectFree(node) {
|
|
|
743
747
|
case "ArrowFunctionExpression":
|
|
744
748
|
case "FunctionExpression": return true;
|
|
745
749
|
case "ParenthesizedExpression": return isSideEffectFree(node.expression);
|
|
746
|
-
case "TemplateLiteral": return node.expressions
|
|
750
|
+
case "TemplateLiteral": return areSideEffectFree(node.expressions);
|
|
747
751
|
case "UnaryExpression": return node.operator !== "delete" && isSideEffectFree(node.argument);
|
|
748
752
|
case "BinaryExpression": return node.operator !== "in" && node.operator !== "instanceof" && isSideEffectFree(node.left) && isSideEffectFree(node.right);
|
|
749
753
|
case "LogicalExpression": return isSideEffectFree(node.left) && isSideEffectFree(node.right);
|
|
750
|
-
case "SequenceExpression": return node.expressions
|
|
754
|
+
case "SequenceExpression": return areSideEffectFree(node.expressions);
|
|
751
755
|
case "ConditionalExpression": return isSideEffectFree(node.test) && isSideEffectFree(node.consequent) && isSideEffectFree(node.alternate);
|
|
752
|
-
case "ArrayExpression":
|
|
753
|
-
|
|
756
|
+
case "ArrayExpression":
|
|
757
|
+
for (const element of node.elements) if (element !== null && (element.type === "SpreadElement" || !isSideEffectFree(element))) return false;
|
|
758
|
+
return true;
|
|
759
|
+
case "ObjectExpression":
|
|
760
|
+
for (const property of node.properties) if (property.type !== "Property" || property.computed && !isSideEffectFree(property.key) || !isSideEffectFree(property.value)) return false;
|
|
761
|
+
return true;
|
|
754
762
|
default: return false;
|
|
755
763
|
}
|
|
756
764
|
}
|
|
@@ -771,7 +779,7 @@ function effectfulParts(node, parts = []) {
|
|
|
771
779
|
function arrayLiteralLength(node) {
|
|
772
780
|
if (node.type === "ParenthesizedExpression") return arrayLiteralLength(node.expression);
|
|
773
781
|
if (node.type !== "ArrayExpression") return;
|
|
774
|
-
|
|
782
|
+
for (const element of node.elements) if (element?.type === "SpreadElement") return;
|
|
775
783
|
return node.elements.length;
|
|
776
784
|
}
|
|
777
785
|
/**
|
|
@@ -806,7 +814,11 @@ function isLiteralForm(node) {
|
|
|
806
814
|
//#region src/constants.ts
|
|
807
815
|
function resolveImportedConstants(constants) {
|
|
808
816
|
const result = /* @__PURE__ */ new Map();
|
|
809
|
-
for (const [source, exports] of Object.entries(constants ?? {}))
|
|
817
|
+
for (const [source, exports] of Object.entries(constants ?? {})) {
|
|
818
|
+
const entries = /* @__PURE__ */ new Map();
|
|
819
|
+
for (const [name, value] of Object.entries(exports)) entries.set(name, { value });
|
|
820
|
+
result.set(source, entries);
|
|
821
|
+
}
|
|
810
822
|
return result;
|
|
811
823
|
}
|
|
812
824
|
function globalValue(name) {
|
|
@@ -829,7 +841,7 @@ var ConstantTable = class {
|
|
|
829
841
|
if (reference.type === "MemberExpression") return this.namespaceMember(scopes, reference) ?? this.globalMember(scopes, reference);
|
|
830
842
|
if (!scopes.references.has(reference) || reference.type !== "Identifier") return;
|
|
831
843
|
const binding = scopes.references.get(reference);
|
|
832
|
-
if (binding) return this.
|
|
844
|
+
if (binding) return this.getConstant(binding);
|
|
833
845
|
return this.globalConstant(reference.name) ?? globalValue(reference.name);
|
|
834
846
|
};
|
|
835
847
|
}
|
|
@@ -877,7 +889,7 @@ var ConstantTable = class {
|
|
|
877
889
|
* A reference that runs before its declaration throws at runtime, and
|
|
878
890
|
* folding turns it into the value. Minifiers make the same trade.
|
|
879
891
|
*/
|
|
880
|
-
|
|
892
|
+
getConstant(binding) {
|
|
881
893
|
const cached = this.constants.get(binding);
|
|
882
894
|
if (cached !== void 0) return cached ?? void 0;
|
|
883
895
|
let value;
|
|
@@ -956,7 +968,7 @@ function constantExports(program, options, scopes = analyzeScopes(program)) {
|
|
|
956
968
|
if (declaration?.type === "VariableDeclaration") {
|
|
957
969
|
for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier") {
|
|
958
970
|
const binding = topLevel.bindings.get(declarator.id.name);
|
|
959
|
-
add(declarator.id.name, binding ? table.
|
|
971
|
+
add(declarator.id.name, binding ? table.getConstant(binding) : void 0);
|
|
960
972
|
}
|
|
961
973
|
continue;
|
|
962
974
|
}
|
|
@@ -968,7 +980,7 @@ function constantExports(program, options, scopes = analyzeScopes(program)) {
|
|
|
968
980
|
if (statement.source) add(exported, options.importedConstants.get(statement.source.value)?.get(local));
|
|
969
981
|
else {
|
|
970
982
|
const binding = topLevel.bindings.get(local);
|
|
971
|
-
add(exported, binding ? table.
|
|
983
|
+
add(exported, binding ? table.getConstant(binding) : void 0);
|
|
972
984
|
}
|
|
973
985
|
}
|
|
974
986
|
}
|
|
@@ -1064,19 +1076,21 @@ function findAttribute(element, name) {
|
|
|
1064
1076
|
for (const attribute of element.openingElement.attributes) if (attribute.type === "JSXAttribute" && attribute.name.type === "JSXIdentifier" && attribute.name.name === name) return attribute;
|
|
1065
1077
|
}
|
|
1066
1078
|
function hasSpreadAttribute(element) {
|
|
1067
|
-
|
|
1079
|
+
for (const attribute of element.openingElement.attributes) if (attribute.type === "JSXSpreadAttribute") return true;
|
|
1080
|
+
return false;
|
|
1068
1081
|
}
|
|
1069
1082
|
/**
|
|
1070
1083
|
* Whether any child is a function, which the runtime may call with the
|
|
1071
1084
|
* narrowed value. Folding one away would drop that call.
|
|
1072
1085
|
*/
|
|
1073
1086
|
function hasCallbackChild(children) {
|
|
1074
|
-
|
|
1075
|
-
if (child.type !== "JSXExpressionContainer")
|
|
1087
|
+
for (const child of children) {
|
|
1088
|
+
if (child.type !== "JSXExpressionContainer") continue;
|
|
1076
1089
|
let expression = child.expression;
|
|
1077
1090
|
while (expression.type === "ParenthesizedExpression") expression = expression.expression;
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1091
|
+
if (expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression") return true;
|
|
1092
|
+
}
|
|
1093
|
+
return false;
|
|
1080
1094
|
}
|
|
1081
1095
|
/**
|
|
1082
1096
|
* The text between an element's tags, or an empty string for a self-closing element.
|
|
@@ -1255,7 +1269,8 @@ var SizeEstimator = class {
|
|
|
1255
1269
|
}
|
|
1256
1270
|
} else size += name.length + GETTER + this.jsx(value, false);
|
|
1257
1271
|
}
|
|
1258
|
-
const significant =
|
|
1272
|
+
const significant = [];
|
|
1273
|
+
for (const child of element.children) if (!isInsignificant(child)) significant.push(child);
|
|
1259
1274
|
if (significant.length > 0) size += 24 + this.children(significant);
|
|
1260
1275
|
return size + (spread ? MERGE : 0);
|
|
1261
1276
|
}
|
|
@@ -1335,6 +1350,29 @@ function containsHoistedDeclaration(statement) {
|
|
|
1335
1350
|
visit(statement);
|
|
1336
1351
|
return found;
|
|
1337
1352
|
}
|
|
1353
|
+
/** The source text of each node. */
|
|
1354
|
+
function getTexts(context, nodes) {
|
|
1355
|
+
const texts = [];
|
|
1356
|
+
for (const node of nodes) texts.push(getText(context, node));
|
|
1357
|
+
return texts;
|
|
1358
|
+
}
|
|
1359
|
+
/** The children that are not whitespace-only text or an empty expression. */
|
|
1360
|
+
function getSignificant(children) {
|
|
1361
|
+
const significant = [];
|
|
1362
|
+
for (const child of children) if (!isInsignificant(child)) significant.push(child);
|
|
1363
|
+
return significant;
|
|
1364
|
+
}
|
|
1365
|
+
/** Whether the element has a `keyed` attribute that is not `{false}`. */
|
|
1366
|
+
function hasEnabledKeyed(element) {
|
|
1367
|
+
for (const attribute of element.openingElement.attributes) if (attribute.type === "JSXAttribute" && attribute.name.type === "JSXIdentifier" && attribute.name.name === "keyed" && !(attribute.value?.type === "JSXExpressionContainer" && attribute.value.expression.type === "Literal" && attribute.value.expression.value === false)) return true;
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
/** The summed size estimate of the children of a fragment spliced into a template. */
|
|
1371
|
+
function estimateChildren(estimator, children) {
|
|
1372
|
+
let size = 0;
|
|
1373
|
+
for (const child of children) size += child.type === "JSXElement" ? estimator.jsx(child, true) : estimator.node(child);
|
|
1374
|
+
return size;
|
|
1375
|
+
}
|
|
1338
1376
|
/**
|
|
1339
1377
|
* Whether a statement starting with `text` could join the statement before
|
|
1340
1378
|
* it when that one has no semicolon.
|
|
@@ -1356,9 +1394,9 @@ function primitiveText(context, node) {
|
|
|
1356
1394
|
let expression = node;
|
|
1357
1395
|
while (expression.type === "ParenthesizedExpression") expression = expression.expression;
|
|
1358
1396
|
switch (expression.type) {
|
|
1359
|
-
case "Literal": return "regex" in expression ? void 0 :
|
|
1360
|
-
case "TemplateLiteral": return expression.expressions.length === 0 ?
|
|
1361
|
-
case "UnaryExpression": return expression.operator === "-" && expression.argument.type === "Literal" && typeof expression.argument.value === "number" ?
|
|
1397
|
+
case "Literal": return "regex" in expression ? void 0 : getText(context, expression);
|
|
1398
|
+
case "TemplateLiteral": return expression.expressions.length === 0 ? getText(context, expression) : void 0;
|
|
1399
|
+
case "UnaryExpression": return expression.operator === "-" && expression.argument.type === "Literal" && typeof expression.argument.value === "number" ? getText(context, expression) : void 0;
|
|
1362
1400
|
default: return;
|
|
1363
1401
|
}
|
|
1364
1402
|
}
|
|
@@ -1442,7 +1480,7 @@ var Folder = class {
|
|
|
1442
1480
|
return isJSXChild(node, this.context.parents) || this.context.parents.get(node)?.type === "JSXAttribute";
|
|
1443
1481
|
}
|
|
1444
1482
|
replace(node, text) {
|
|
1445
|
-
if (
|
|
1483
|
+
if (getText(this.context, node) === text) return;
|
|
1446
1484
|
this.context.s.overwrite(node.start, node.end, text);
|
|
1447
1485
|
this.changed = true;
|
|
1448
1486
|
}
|
|
@@ -1502,11 +1540,11 @@ var Folder = class {
|
|
|
1502
1540
|
keepAfter(target, discarded, value) {
|
|
1503
1541
|
const parts = discarded ? effectfulParts(discarded) : [];
|
|
1504
1542
|
if (parts.length === 0) {
|
|
1505
|
-
const text =
|
|
1543
|
+
const text = getText(this.context, value);
|
|
1506
1544
|
return needsParensAt(target, value, this.context.parents) ? `(${text})` : text;
|
|
1507
1545
|
}
|
|
1508
|
-
const texts =
|
|
1509
|
-
texts.push(
|
|
1546
|
+
const texts = getTexts(this.context, parts);
|
|
1547
|
+
texts.push(getText(this.context, value));
|
|
1510
1548
|
return `(${texts.join(", ")})`;
|
|
1511
1549
|
}
|
|
1512
1550
|
foldLogical(node) {
|
|
@@ -1630,17 +1668,17 @@ var Folder = class {
|
|
|
1630
1668
|
case "JSXElement":
|
|
1631
1669
|
case "JSXFragment": return {
|
|
1632
1670
|
kind: "jsx",
|
|
1633
|
-
text:
|
|
1671
|
+
text: getText(this.context, value)
|
|
1634
1672
|
};
|
|
1635
1673
|
default:
|
|
1636
1674
|
if (value.expression.type === "JSXEmptyExpression") return EMPTY;
|
|
1637
1675
|
if (value.expression.type === "JSXElement" || value.expression.type === "JSXFragment") return {
|
|
1638
1676
|
kind: "jsx",
|
|
1639
|
-
text:
|
|
1677
|
+
text: getText(this.context, value.expression)
|
|
1640
1678
|
};
|
|
1641
1679
|
return {
|
|
1642
1680
|
kind: "expression",
|
|
1643
|
-
text:
|
|
1681
|
+
text: getText(this.context, value.expression),
|
|
1644
1682
|
primary: isPrimary(value.expression)
|
|
1645
1683
|
};
|
|
1646
1684
|
}
|
|
@@ -1676,11 +1714,11 @@ var Folder = class {
|
|
|
1676
1714
|
* would run while the copy is made, so either one keeps the loop.
|
|
1677
1715
|
*/
|
|
1678
1716
|
unrollFor(element, expression) {
|
|
1679
|
-
if (element
|
|
1717
|
+
if (hasEnabledKeyed(element)) return;
|
|
1680
1718
|
const byIndex = findAttribute(element, "keyed") !== void 0;
|
|
1681
1719
|
const list = this.constantList(expression);
|
|
1682
1720
|
if (!list) return;
|
|
1683
|
-
const significant = element.children
|
|
1721
|
+
const significant = getSignificant(element.children);
|
|
1684
1722
|
const only = significant.at(0);
|
|
1685
1723
|
if (significant.length !== 1 || only?.type !== "JSXExpressionContainer") return;
|
|
1686
1724
|
let row = only.expression;
|
|
@@ -1718,16 +1756,20 @@ var Folder = class {
|
|
|
1718
1756
|
* `<For>` reads it.
|
|
1719
1757
|
*/
|
|
1720
1758
|
constantList(expression) {
|
|
1721
|
-
let node = expression;
|
|
1722
|
-
while (node.type === "ParenthesizedExpression") node = node.expression;
|
|
1759
|
+
let node = unwrap(expression);
|
|
1723
1760
|
let declaration;
|
|
1724
1761
|
if (node.type === "Identifier") {
|
|
1725
1762
|
const binding = this.context.scopes.references.get(node);
|
|
1726
1763
|
if (binding?.declaration.type !== "VariableDeclarator" || binding.declaration.id !== binding.identifier || !binding.declaration.init || !isConstantDeclaration(binding, this.context.options)) return;
|
|
1727
1764
|
const statement = this.context.parents.get(binding.declaration);
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1765
|
+
const owner = statement ? this.context.parents.get(statement) : void 0;
|
|
1766
|
+
let onlyForEach = true;
|
|
1767
|
+
for (const reference of binding.references) if (!this.isForEach(reference)) {
|
|
1768
|
+
onlyForEach = false;
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
if (owner?.type === "ExportNamedDeclaration" || !onlyForEach) return;
|
|
1772
|
+
node = unwrap(binding.declaration.init);
|
|
1731
1773
|
declaration = binding.references.length === 1 && statement?.type === "VariableDeclaration" && statement.declarations.length === 1 ? statement : void 0;
|
|
1732
1774
|
}
|
|
1733
1775
|
if (node.type !== "ArrayExpression") return;
|
|
@@ -1827,7 +1869,7 @@ var Folder = class {
|
|
|
1827
1869
|
const init = statement?.type === "VariableDeclaration" ? statement.declarations.at(0)?.init : void 0;
|
|
1828
1870
|
if (init?.type !== "JSXFragment") return false;
|
|
1829
1871
|
const estimator = new SizeEstimator(code);
|
|
1830
|
-
return (inTemplate ?
|
|
1872
|
+
return (inTemplate ? estimateChildren(estimator, init.children) : estimator.jsx(init, false)) <= loop;
|
|
1831
1873
|
}
|
|
1832
1874
|
/** Whether an element sits directly in an element or fragment whose template it joins. */
|
|
1833
1875
|
joinsParentTemplate(element) {
|
|
@@ -1859,8 +1901,16 @@ var Folder = class {
|
|
|
1859
1901
|
});
|
|
1860
1902
|
}
|
|
1861
1903
|
if (matches.length === 0) return;
|
|
1862
|
-
|
|
1863
|
-
|
|
1904
|
+
let winner = -1;
|
|
1905
|
+
let allFalse = true;
|
|
1906
|
+
for (const [index, item] of matches.entries()) {
|
|
1907
|
+
if (item.when === true) {
|
|
1908
|
+
winner = index;
|
|
1909
|
+
break;
|
|
1910
|
+
}
|
|
1911
|
+
if (item.when !== false) allFalse = false;
|
|
1912
|
+
}
|
|
1913
|
+
if (winner !== -1 && allFalse) {
|
|
1864
1914
|
const match = matches.at(winner);
|
|
1865
1915
|
if (!match || hasCallbackChild(match.element.children)) return;
|
|
1866
1916
|
return {
|
|
@@ -1868,7 +1918,7 @@ var Folder = class {
|
|
|
1868
1918
|
children: match.element.children
|
|
1869
1919
|
};
|
|
1870
1920
|
}
|
|
1871
|
-
if (
|
|
1921
|
+
if (winner === -1 && allFalse) return this.fallback(element);
|
|
1872
1922
|
for (const item of matches) if (item.when === false) {
|
|
1873
1923
|
this.context.s.remove(item.element.start, item.element.end);
|
|
1874
1924
|
this.changed = true;
|
|
@@ -1899,7 +1949,8 @@ var Folder = class {
|
|
|
1899
1949
|
}
|
|
1900
1950
|
}
|
|
1901
1951
|
if (tag === void 0) return;
|
|
1902
|
-
const attributes =
|
|
1952
|
+
const attributes = [];
|
|
1953
|
+
for (const attribute of element.openingElement.attributes) if (attribute !== component) attributes.push(getText(this.context, attribute));
|
|
1903
1954
|
const opening = [tag, ...attributes].join(" ");
|
|
1904
1955
|
return {
|
|
1905
1956
|
kind: "jsx",
|
|
@@ -1920,10 +1971,10 @@ var Folder = class {
|
|
|
1920
1971
|
case "jsx": return resolved.text;
|
|
1921
1972
|
case "expression": return resolved.primary ? resolved.text : `(${resolved.text})`;
|
|
1922
1973
|
default: {
|
|
1923
|
-
const significant = resolved.children
|
|
1974
|
+
const significant = getSignificant(resolved.children);
|
|
1924
1975
|
const only = significant.at(0);
|
|
1925
1976
|
if (only === void 0) return "null";
|
|
1926
|
-
if (significant.length === 1 && (only.type === "JSXElement" || only.type === "JSXFragment")) return
|
|
1977
|
+
if (significant.length === 1 && (only.type === "JSXElement" || only.type === "JSXFragment")) return getText(this.context, only);
|
|
1927
1978
|
const first = resolved.children.at(0);
|
|
1928
1979
|
const last = resolved.children.at(-1);
|
|
1929
1980
|
if (!first || !last) return "null";
|
|
@@ -2018,9 +2069,9 @@ var Folder = class {
|
|
|
2018
2069
|
let node = arg;
|
|
2019
2070
|
while (node.type === "ParenthesizedExpression") node = node.expression;
|
|
2020
2071
|
switch (node.type) {
|
|
2021
|
-
case "Literal": return "regex" in node ? void 0 :
|
|
2022
|
-
case "TemplateLiteral": return node.expressions.length === 0 ?
|
|
2023
|
-
case "UnaryExpression": return node.operator === "-" && node.argument.type === "Literal" ? `(${
|
|
2072
|
+
case "Literal": return "regex" in node ? void 0 : getText(this.context, node);
|
|
2073
|
+
case "TemplateLiteral": return node.expressions.length === 0 ? getText(this.context, node) : void 0;
|
|
2074
|
+
case "UnaryExpression": return node.operator === "-" && node.argument.type === "Literal" ? `(${getText(this.context, node)})` : void 0;
|
|
2024
2075
|
case "Identifier": {
|
|
2025
2076
|
const binding = this.context.scopes.references.get(node);
|
|
2026
2077
|
return binding && !binding.mutated ? node.name : void 0;
|
|
@@ -2042,7 +2093,12 @@ var Folder = class {
|
|
|
2042
2093
|
const unreachable = statements.slice(terminator + 1);
|
|
2043
2094
|
const first = unreachable.at(0);
|
|
2044
2095
|
const last = unreachable.at(-1);
|
|
2045
|
-
|
|
2096
|
+
let hoists = false;
|
|
2097
|
+
for (const statement of unreachable) if (containsHoistedDeclaration(statement)) {
|
|
2098
|
+
hoists = true;
|
|
2099
|
+
break;
|
|
2100
|
+
}
|
|
2101
|
+
if (first && last && !hoists) {
|
|
2046
2102
|
this.context.s.remove(first.start, last.end);
|
|
2047
2103
|
this.changed = true;
|
|
2048
2104
|
}
|
|
@@ -2063,7 +2119,7 @@ var Folder = class {
|
|
|
2063
2119
|
const parts = effectfulParts(test);
|
|
2064
2120
|
const first = parts.at(0);
|
|
2065
2121
|
if (first === void 0) return;
|
|
2066
|
-
const text =
|
|
2122
|
+
const text = getTexts(this.context, parts).join(", ");
|
|
2067
2123
|
return startsLikeStatement(first) ? `(${text});` : `${text};`;
|
|
2068
2124
|
}
|
|
2069
2125
|
/**
|
|
@@ -2080,7 +2136,7 @@ var Folder = class {
|
|
|
2080
2136
|
const parts = [];
|
|
2081
2137
|
const effect = this.discardedTest(statement.test);
|
|
2082
2138
|
if (effect !== void 0) parts.push(effect);
|
|
2083
|
-
if (kept) parts.push(
|
|
2139
|
+
if (kept) parts.push(getText(this.context, kept));
|
|
2084
2140
|
this.replaceStatement(statement, parts.join(" "));
|
|
2085
2141
|
return kept;
|
|
2086
2142
|
}
|
|
@@ -2136,7 +2192,7 @@ const ACCESSOR_PAIRS = /* @__PURE__ */ new Set([
|
|
|
2136
2192
|
* `useContext` throws when the value and the default are both `undefined`,
|
|
2137
2193
|
* so a value that could be `undefined` keeps its provider.
|
|
2138
2194
|
*/
|
|
2139
|
-
function
|
|
2195
|
+
function findProvider(context, element) {
|
|
2140
2196
|
const binding = contextBinding(context, element.openingElement.name);
|
|
2141
2197
|
if (!binding || element.openingElement.selfClosing) return;
|
|
2142
2198
|
const { attributes } = element.openingElement;
|
|
@@ -2196,7 +2252,7 @@ function isDefined(context, node, depth) {
|
|
|
2196
2252
|
case "Identifier": {
|
|
2197
2253
|
const binding = context.scopes.references.get(expression);
|
|
2198
2254
|
if (!binding || binding.mutated || depth > 2) return false;
|
|
2199
|
-
if (binding.kind === "function" || binding.kind === "class" || isAccessor(context, binding)) return true;
|
|
2255
|
+
if (binding.kind === "function" || binding.kind === "class" || isAccessor$1(context, binding)) return true;
|
|
2200
2256
|
const { declaration } = binding;
|
|
2201
2257
|
return isConstantDeclaration(binding, context.options) && declaration.type === "VariableDeclarator" && declaration.id === binding.identifier && declaration.init !== null && isDefined(context, declaration.init, depth + 1);
|
|
2202
2258
|
}
|
|
@@ -2234,7 +2290,7 @@ function isHandlerFunction(attribute) {
|
|
|
2234
2290
|
* Whether a binding is a signal or store getter or setter, or a memo, which
|
|
2235
2291
|
* run no code of the app when called.
|
|
2236
2292
|
*/
|
|
2237
|
-
function isAccessor(context, binding) {
|
|
2293
|
+
function isAccessor$1(context, binding) {
|
|
2238
2294
|
if (binding.mutated) return false;
|
|
2239
2295
|
const { declaration } = binding;
|
|
2240
2296
|
if (declaration.type !== "VariableDeclarator") return false;
|
|
@@ -2244,8 +2300,8 @@ function isAccessor(context, binding) {
|
|
|
2244
2300
|
const callee = solidCallee(context, call);
|
|
2245
2301
|
if (id === binding.identifier) return callee === "createMemo";
|
|
2246
2302
|
if (id.type !== "ArrayPattern" || callee === void 0 || !ACCESSOR_PAIRS.has(callee)) return false;
|
|
2247
|
-
const index
|
|
2248
|
-
return
|
|
2303
|
+
for (const [index, element] of id.elements.entries()) if (element === binding.identifier) return index === 0 || index === 1;
|
|
2304
|
+
return false;
|
|
2249
2305
|
}
|
|
2250
2306
|
/**
|
|
2251
2307
|
* Whether all code that can run under `root` is visible, so a provider
|
|
@@ -2322,7 +2378,7 @@ function isClosed(context, root, options) {
|
|
|
2322
2378
|
*/
|
|
2323
2379
|
function runsOutsideCode(context, binding, root, options, depth) {
|
|
2324
2380
|
const { identifier, declaration } = binding;
|
|
2325
|
-
if (binding === options.props || identifier.start >= root.start && identifier.end <= root.end || isAccessor(context, binding) || solidExport(binding, context.options) !== void 0) return false;
|
|
2381
|
+
if (binding === options.props || identifier.start >= root.start && identifier.end <= root.end || isAccessor$1(context, binding) || solidExport(binding, context.options) !== void 0) return false;
|
|
2326
2382
|
if (binding.kind === "param" || binding.kind === "function" || depth > 4) return true;
|
|
2327
2383
|
if (declaration.type !== "VariableDeclarator" || !declaration.init) return false;
|
|
2328
2384
|
const init = unwrap(declaration.init);
|
|
@@ -2359,11 +2415,12 @@ function isOwnView(context, node, props, depth) {
|
|
|
2359
2415
|
if (call?.type !== "CallExpression") return false;
|
|
2360
2416
|
const callee = solidCallee(context, call);
|
|
2361
2417
|
if (callee !== "merge" && callee !== "omit") return false;
|
|
2362
|
-
|
|
2418
|
+
for (const argument of call.arguments) {
|
|
2363
2419
|
if (argument.type === "SpreadElement") return false;
|
|
2364
2420
|
const inner = unwrap(argument);
|
|
2365
|
-
|
|
2366
|
-
}
|
|
2421
|
+
if (inner.type !== "ObjectExpression" && !(inner.type === "Literal" && typeof inner.value === "string") && !isOwnView(context, inner, props, depth + 1)) return false;
|
|
2422
|
+
}
|
|
2423
|
+
return true;
|
|
2367
2424
|
}
|
|
2368
2425
|
function isVisibleElement(context, element, options) {
|
|
2369
2426
|
const { name } = element.openingElement;
|
|
@@ -2394,13 +2451,13 @@ function isAccessorValue(context, node, options, depth) {
|
|
|
2394
2451
|
const expression = unwrap(node);
|
|
2395
2452
|
if (depth > 4) return false;
|
|
2396
2453
|
if (expression.type === "CallExpression") {
|
|
2397
|
-
const value =
|
|
2454
|
+
const value = findContextValue(context, expression, options);
|
|
2398
2455
|
return value !== void 0 && isAccessorValue(context, value, options, depth + 1);
|
|
2399
2456
|
}
|
|
2400
2457
|
if (expression.type !== "Identifier") return false;
|
|
2401
2458
|
const binding = context.scopes.references.get(expression);
|
|
2402
2459
|
if (!binding) return false;
|
|
2403
|
-
if (isAccessor(context, binding)) return true;
|
|
2460
|
+
if (isAccessor$1(context, binding)) return true;
|
|
2404
2461
|
const init = constantInit(context, binding);
|
|
2405
2462
|
return init !== void 0 && isAccessorValue(context, init, options, depth + 1);
|
|
2406
2463
|
}
|
|
@@ -2415,7 +2472,7 @@ function constantInit(context, binding) {
|
|
|
2415
2472
|
/**
|
|
2416
2473
|
* The value `useContext(Ctx)` returns, when the provider is known.
|
|
2417
2474
|
*/
|
|
2418
|
-
function
|
|
2475
|
+
function findContextValue(context, call, options) {
|
|
2419
2476
|
const argument = call.arguments.at(0);
|
|
2420
2477
|
if (solidCallee(context, call) !== "useContext" || call.arguments.length !== 1 || argument === void 0 || argument.type === "SpreadElement") return;
|
|
2421
2478
|
const target = contextBinding(context, unwrap(argument));
|
|
@@ -2428,10 +2485,14 @@ function contextValueOf(context, call, options) {
|
|
|
2428
2485
|
*/
|
|
2429
2486
|
function isVisibleMethod(context, member, options) {
|
|
2430
2487
|
if (member.computed || member.property.type !== "Identifier" || member.optional) return false;
|
|
2431
|
-
const object =
|
|
2432
|
-
if (!object
|
|
2488
|
+
const object = findObjectLiteral(context, member.object, options, 0);
|
|
2489
|
+
if (!object) return false;
|
|
2433
2490
|
const { name } = member.property;
|
|
2434
|
-
const matches =
|
|
2491
|
+
const matches = [];
|
|
2492
|
+
for (const property of object.properties) {
|
|
2493
|
+
if (property.type !== "Property") return false;
|
|
2494
|
+
if (!property.computed && property.key.type === "Identifier" && property.key.name === name) matches.push(property);
|
|
2495
|
+
}
|
|
2435
2496
|
const property = matches.at(0);
|
|
2436
2497
|
if (matches.length !== 1 || property?.type !== "Property" || property.kind !== "init") return false;
|
|
2437
2498
|
const value = unwrap(property.value);
|
|
@@ -2446,18 +2507,18 @@ function isVisibleMethod(context, member, options) {
|
|
|
2446
2507
|
* The object literal an expression evaluates to, through bindings that
|
|
2447
2508
|
* never change and reads of a context whose value is known.
|
|
2448
2509
|
*/
|
|
2449
|
-
function
|
|
2510
|
+
function findObjectLiteral(context, node, options, depth) {
|
|
2450
2511
|
const expression = unwrap(node);
|
|
2451
2512
|
if (depth > 4) return;
|
|
2452
2513
|
if (expression.type === "ObjectExpression") return expression;
|
|
2453
2514
|
if (expression.type === "CallExpression") {
|
|
2454
|
-
const value =
|
|
2455
|
-
return value ?
|
|
2515
|
+
const value = findContextValue(context, expression, options);
|
|
2516
|
+
return value ? findObjectLiteral(context, value, options, depth + 1) : void 0;
|
|
2456
2517
|
}
|
|
2457
2518
|
if (expression.type !== "Identifier") return;
|
|
2458
2519
|
const binding = context.scopes.references.get(expression);
|
|
2459
2520
|
const init = binding ? constantInit(context, binding) : void 0;
|
|
2460
|
-
return init ?
|
|
2521
|
+
return init ? findObjectLiteral(context, init, options, depth + 1) : void 0;
|
|
2461
2522
|
}
|
|
2462
2523
|
/**
|
|
2463
2524
|
* The `useContext(Ctx)` calls under `root` that run under its owner, so
|
|
@@ -2502,7 +2563,7 @@ function findProviders(context) {
|
|
|
2502
2563
|
const providers = [];
|
|
2503
2564
|
const visit = (node) => {
|
|
2504
2565
|
if (node.type === "JSXElement") {
|
|
2505
|
-
const provider =
|
|
2566
|
+
const provider = findProvider(context, node);
|
|
2506
2567
|
if (provider) providers.push(provider);
|
|
2507
2568
|
}
|
|
2508
2569
|
forEachChild(node, visit);
|
|
@@ -2519,7 +2580,12 @@ var ProviderRemover = class {
|
|
|
2519
2580
|
run() {
|
|
2520
2581
|
for (const provider of findProviders(this.context)) {
|
|
2521
2582
|
const { element } = provider;
|
|
2522
|
-
|
|
2583
|
+
let overlaps = false;
|
|
2584
|
+
for (const other of this.removed) if (element.start < other.end && other.start < element.end) {
|
|
2585
|
+
overlaps = true;
|
|
2586
|
+
break;
|
|
2587
|
+
}
|
|
2588
|
+
if (overlaps) continue;
|
|
2523
2589
|
if (hasNestedProvider(this.context, provider)) this.skip(provider, "provider-nested");
|
|
2524
2590
|
else if (this.tryRemove(provider)) this.removed.push(element);
|
|
2525
2591
|
}
|
|
@@ -2536,7 +2602,7 @@ var ProviderRemover = class {
|
|
|
2536
2602
|
const visit = (node) => {
|
|
2537
2603
|
if (node.type === "JSXElement") {
|
|
2538
2604
|
const binding = contextBinding(this.context, node.openingElement.name);
|
|
2539
|
-
if (binding && !
|
|
2605
|
+
if (binding && !findProvider(this.context, node)) {
|
|
2540
2606
|
const { attributes } = node.openingElement;
|
|
2541
2607
|
const attribute = attributes.at(0);
|
|
2542
2608
|
const onlyValue = attributes.length === 1 && attribute?.type === "JSXAttribute" && attribute.name.type === "JSXIdentifier" && attribute.name.name === "value";
|
|
@@ -2551,17 +2617,24 @@ var ProviderRemover = class {
|
|
|
2551
2617
|
const { element } = provider;
|
|
2552
2618
|
const children = element.children;
|
|
2553
2619
|
let reason = "open-other";
|
|
2554
|
-
|
|
2620
|
+
const closure = {
|
|
2555
2621
|
component: () => false,
|
|
2556
2622
|
contextValue: (target) => target === provider.context ? provider.value : void 0,
|
|
2557
2623
|
onOpen: (open) => {
|
|
2558
2624
|
reason = open;
|
|
2559
2625
|
}
|
|
2560
|
-
}
|
|
2626
|
+
};
|
|
2627
|
+
let closed = true;
|
|
2628
|
+
for (const child of children) if (!isClosed(this.context, child, closure)) {
|
|
2629
|
+
closed = false;
|
|
2630
|
+
break;
|
|
2631
|
+
}
|
|
2632
|
+
if (!closed) {
|
|
2561
2633
|
this.skip(provider, reason);
|
|
2562
2634
|
return false;
|
|
2563
2635
|
}
|
|
2564
|
-
const reads =
|
|
2636
|
+
const reads = [];
|
|
2637
|
+
for (const child of children) reads.push(...contextReads(this.context, child, provider.context));
|
|
2565
2638
|
const texts = [];
|
|
2566
2639
|
for (const read of reads) {
|
|
2567
2640
|
const text = stableValueText(this.context, provider, read);
|
|
@@ -2753,7 +2826,8 @@ function inBodyOrder(sites) {
|
|
|
2753
2826
|
const pending = [...sites];
|
|
2754
2827
|
const ordered = [];
|
|
2755
2828
|
while (pending.length > 0) {
|
|
2756
|
-
const ready =
|
|
2829
|
+
const ready = [];
|
|
2830
|
+
for (const site of pending) if (!hasPendingDependency(pending, site)) ready.push(site);
|
|
2757
2831
|
const next = ready.length > 0 ? ready : pending;
|
|
2758
2832
|
for (const site of next) {
|
|
2759
2833
|
ordered.push(site);
|
|
@@ -2910,7 +2984,7 @@ function acceptsAnyExpression(context, node) {
|
|
|
2910
2984
|
/**
|
|
2911
2985
|
* The function a top-level binding declares, if it declares one.
|
|
2912
2986
|
*/
|
|
2913
|
-
function
|
|
2987
|
+
function findComponentFunction(binding, options) {
|
|
2914
2988
|
const { declaration } = binding;
|
|
2915
2989
|
if (binding.kind === "function" && declaration.type === "FunctionDeclaration") return declaration;
|
|
2916
2990
|
if (isConstantDeclaration(binding, options) && declaration.type === "VariableDeclarator" && declaration.id === binding.identifier && declaration.init) {
|
|
@@ -2921,7 +2995,7 @@ function functionOf(binding, options) {
|
|
|
2921
2995
|
/**
|
|
2922
2996
|
* The attributes of a call site by name, or `undefined` when one cannot be inlined.
|
|
2923
2997
|
*/
|
|
2924
|
-
function
|
|
2998
|
+
function getAttributes(context, element) {
|
|
2925
2999
|
const attributes = /* @__PURE__ */ new Map();
|
|
2926
3000
|
for (const attribute of element.openingElement.attributes) {
|
|
2927
3001
|
if (attribute.type !== "JSXAttribute" || attribute.name.type !== "JSXIdentifier" || attribute.name.name === "ref" && !isForwardableRef(context, attribute) || attributes.has(attribute.name.name)) return;
|
|
@@ -2936,7 +3010,7 @@ function attributesOf(context, element) {
|
|
|
2936
3010
|
*/
|
|
2937
3011
|
function isDataDeclaration(statement) {
|
|
2938
3012
|
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
2939
|
-
return declaration?.type === "VariableDeclaration" && !declaration.declare && (declaration.kind === "const" || declaration.kind === "var") && declaration.declarations
|
|
3013
|
+
return declaration?.type === "VariableDeclaration" && !declaration.declare && (declaration.kind === "const" || declaration.kind === "var") && areDataDeclarators(declaration.declarations);
|
|
2940
3014
|
}
|
|
2941
3015
|
/** Whether an expression is a literal, or an array or object literal of them. */
|
|
2942
3016
|
function isDataLiteral(node) {
|
|
@@ -2947,8 +3021,8 @@ function isDataLiteral(node) {
|
|
|
2947
3021
|
case "ParenthesizedExpression":
|
|
2948
3022
|
case "TSAsExpression":
|
|
2949
3023
|
case "TSSatisfiesExpression": return isDataLiteral(node.expression);
|
|
2950
|
-
case "ArrayExpression": return node.elements
|
|
2951
|
-
case "ObjectExpression": return node.properties
|
|
3024
|
+
case "ArrayExpression": return areDataElements(node.elements);
|
|
3025
|
+
case "ObjectExpression": return areDataProperties(node.properties);
|
|
2952
3026
|
default: return false;
|
|
2953
3027
|
}
|
|
2954
3028
|
}
|
|
@@ -2972,7 +3046,10 @@ function isForwardableRef(context, attribute) {
|
|
|
2972
3046
|
if (value?.type !== "JSXExpressionContainer" || value.expression.type === "JSXEmptyExpression") return false;
|
|
2973
3047
|
const isTarget = (node, inArray) => {
|
|
2974
3048
|
const inner = unwrap(node);
|
|
2975
|
-
if (inner.type === "ArrayExpression")
|
|
3049
|
+
if (inner.type === "ArrayExpression") {
|
|
3050
|
+
for (const element of inner.elements) if (element === null || element.type === "SpreadElement" || !isTarget(element, true)) return false;
|
|
3051
|
+
return true;
|
|
3052
|
+
}
|
|
2976
3053
|
if (inArray && isVoidZero(inner)) return true;
|
|
2977
3054
|
if (inArray && inner.type === "CallExpression" && solidCallee(context, inner) === "untrack") {
|
|
2978
3055
|
const callback = inner.arguments.at(0);
|
|
@@ -2987,7 +3064,7 @@ function isVoidZero(node) {
|
|
|
2987
3064
|
return node.type === "UnaryExpression" && node.operator === "void" && node.argument.type === "Literal" && node.argument.value === 0;
|
|
2988
3065
|
}
|
|
2989
3066
|
/**
|
|
2990
|
-
* Why `
|
|
3067
|
+
* Why `getAttributes` turns down a call site, for the report.
|
|
2991
3068
|
*/
|
|
2992
3069
|
function callSiteReason(element) {
|
|
2993
3070
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -3050,7 +3127,7 @@ var Inliner = class {
|
|
|
3050
3127
|
visit(loader);
|
|
3051
3128
|
return imports;
|
|
3052
3129
|
}
|
|
3053
|
-
|
|
3130
|
+
getScope(fn) {
|
|
3054
3131
|
return this.context.scopes.scopes.get(fn);
|
|
3055
3132
|
}
|
|
3056
3133
|
/**
|
|
@@ -3090,7 +3167,7 @@ var Inliner = class {
|
|
|
3090
3167
|
this.reason = "component-mutated";
|
|
3091
3168
|
return;
|
|
3092
3169
|
}
|
|
3093
|
-
const fn =
|
|
3170
|
+
const fn = findComponentFunction(binding, this.context.options);
|
|
3094
3171
|
if (!fn?.body) {
|
|
3095
3172
|
this.reason = this.isLazy(binding) ? "lazy" : "not-a-function";
|
|
3096
3173
|
return;
|
|
@@ -3103,7 +3180,7 @@ var Inliner = class {
|
|
|
3103
3180
|
this.reason = "component-params";
|
|
3104
3181
|
return;
|
|
3105
3182
|
}
|
|
3106
|
-
const scope = this.
|
|
3183
|
+
const scope = this.getScope(fn);
|
|
3107
3184
|
if (!scope) {
|
|
3108
3185
|
this.reason = "not-a-function";
|
|
3109
3186
|
return;
|
|
@@ -3172,7 +3249,9 @@ var Inliner = class {
|
|
|
3172
3249
|
}
|
|
3173
3250
|
props.push(read);
|
|
3174
3251
|
}
|
|
3175
|
-
|
|
3252
|
+
const kept = [];
|
|
3253
|
+
for (const statement of statements) if (!views.declarations.includes(statement)) kept.push(statement);
|
|
3254
|
+
statements = kept;
|
|
3176
3255
|
const locals = [];
|
|
3177
3256
|
const seen = /* @__PURE__ */ new Set();
|
|
3178
3257
|
for (const inner of this.context.scopes.scopes.values()) {
|
|
@@ -3249,7 +3328,7 @@ var Inliner = class {
|
|
|
3249
3328
|
const init = unwrap(declarator.init);
|
|
3250
3329
|
const callee = init.type === "CallExpression" ? solidCallee(this.context, init) : void 0;
|
|
3251
3330
|
if (init.type !== "CallExpression" || callee !== "merge" && callee !== "omit") continue;
|
|
3252
|
-
const view = this.
|
|
3331
|
+
const view = this.resolveView(callee, init, param, views, args);
|
|
3253
3332
|
if (view === null) continue;
|
|
3254
3333
|
const binding = scope.bindings.get(declarator.id.name);
|
|
3255
3334
|
if (!view || !binding || binding.mutated) return;
|
|
@@ -3316,12 +3395,12 @@ var Inliner = class {
|
|
|
3316
3395
|
* take the props or another view, and `undefined` when it does but its
|
|
3317
3396
|
* other arguments are not literal.
|
|
3318
3397
|
*/
|
|
3319
|
-
|
|
3320
|
-
const
|
|
3398
|
+
resolveView(callee, call, param, views, args) {
|
|
3399
|
+
const resolveSources = (argument) => {
|
|
3321
3400
|
if (argument.type === "CallExpression") {
|
|
3322
3401
|
const nested = solidCallee(this.context, argument);
|
|
3323
3402
|
if (nested !== "merge" && nested !== "omit") return;
|
|
3324
|
-
return this.
|
|
3403
|
+
return this.resolveView(nested, argument, param, views, args)?.sources;
|
|
3325
3404
|
}
|
|
3326
3405
|
if (argument.type !== "Identifier") return;
|
|
3327
3406
|
const binding = this.context.scopes.references.get(argument);
|
|
@@ -3331,13 +3410,18 @@ var Inliner = class {
|
|
|
3331
3410
|
}];
|
|
3332
3411
|
return binding ? views.get(binding)?.sources : void 0;
|
|
3333
3412
|
};
|
|
3334
|
-
|
|
3413
|
+
let involved = false;
|
|
3414
|
+
for (const argument of call.arguments) if (argument.type !== "SpreadElement" && resolveSources(unwrap(argument)) !== void 0) {
|
|
3415
|
+
involved = true;
|
|
3416
|
+
break;
|
|
3417
|
+
}
|
|
3418
|
+
if (!involved) return null;
|
|
3335
3419
|
if (callee === "omit") {
|
|
3336
3420
|
const first = call.arguments.at(0);
|
|
3337
3421
|
const keys = call.arguments.slice(1);
|
|
3338
3422
|
if (first === void 0 || first.type === "SpreadElement") return;
|
|
3339
3423
|
const target = unwrap(first);
|
|
3340
|
-
const base =
|
|
3424
|
+
const base = resolveSources(target);
|
|
3341
3425
|
const hidden = [];
|
|
3342
3426
|
for (const key of keys) {
|
|
3343
3427
|
if (key.type !== "Literal" || typeof key.value !== "string") return;
|
|
@@ -3345,16 +3429,18 @@ var Inliner = class {
|
|
|
3345
3429
|
}
|
|
3346
3430
|
if (!base) return;
|
|
3347
3431
|
args.add(target);
|
|
3348
|
-
|
|
3432
|
+
const hiddenSources = [];
|
|
3433
|
+
for (const source of base) hiddenSources.push({
|
|
3349
3434
|
defaults: source.defaults,
|
|
3350
3435
|
hidden: /* @__PURE__ */ new Set([...source.hidden, ...hidden])
|
|
3351
|
-
})
|
|
3436
|
+
});
|
|
3437
|
+
return { sources: hiddenSources };
|
|
3352
3438
|
}
|
|
3353
3439
|
const sources = [];
|
|
3354
3440
|
for (const argument of call.arguments) {
|
|
3355
3441
|
if (argument.type === "SpreadElement") return;
|
|
3356
3442
|
const inner = unwrap(argument);
|
|
3357
|
-
const existing =
|
|
3443
|
+
const existing = resolveSources(inner);
|
|
3358
3444
|
if (existing) {
|
|
3359
3445
|
args.add(inner);
|
|
3360
3446
|
sources.push(...existing);
|
|
@@ -3409,7 +3495,7 @@ var Inliner = class {
|
|
|
3409
3495
|
if (parent?.type === "CallExpression") return parent.arguments.at(0) === node && this.solidCallee(parent.callee) === "render";
|
|
3410
3496
|
const element = parent?.type === "JSXExpressionContainer" ? this.context.parents.get(parent) : void 0;
|
|
3411
3497
|
if (element?.type !== "JSXElement") return false;
|
|
3412
|
-
const significant = element.children
|
|
3498
|
+
const significant = getSignificantChildren(element.children);
|
|
3413
3499
|
if (significant.length !== 1 || significant.at(0) !== parent) return false;
|
|
3414
3500
|
switch (this.solidCallee(element.openingElement.name)) {
|
|
3415
3501
|
case "For":
|
|
@@ -3432,7 +3518,7 @@ var Inliner = class {
|
|
|
3432
3518
|
* returned JSX of a component, with only intrinsic elements, fragments,
|
|
3433
3519
|
* and closed providers between it and the call.
|
|
3434
3520
|
*/
|
|
3435
|
-
|
|
3521
|
+
findHost(element) {
|
|
3436
3522
|
let node = element;
|
|
3437
3523
|
for (;;) {
|
|
3438
3524
|
const parent = this.context.parents.get(node);
|
|
@@ -3441,7 +3527,7 @@ var Inliner = class {
|
|
|
3441
3527
|
const { name } = parent.openingElement;
|
|
3442
3528
|
if (!(this.assumedHosts?.has(parent) === true || name.type === "JSXIdentifier" && (isIntrinsicTag(name.name) || this.transparent.has(parent)))) return;
|
|
3443
3529
|
const child = node;
|
|
3444
|
-
if (!parent.children
|
|
3530
|
+
if (!hasChild(parent.children, child)) return;
|
|
3445
3531
|
} else if (parent.type === "ReturnStatement") {
|
|
3446
3532
|
const list = this.context.parents.get(parent);
|
|
3447
3533
|
if (list?.type !== "BlockStatement" && list?.type !== "SwitchCase") return;
|
|
@@ -3470,8 +3556,8 @@ var Inliner = class {
|
|
|
3470
3556
|
}
|
|
3471
3557
|
childrenValue(element, reads, fresh, snapshots) {
|
|
3472
3558
|
const { children } = element;
|
|
3473
|
-
if (children
|
|
3474
|
-
const significant = children
|
|
3559
|
+
if (hasSpreadChild(children)) return;
|
|
3560
|
+
const significant = getSignificantChildren(children);
|
|
3475
3561
|
const only = significant.at(0);
|
|
3476
3562
|
if (only === void 0) return {
|
|
3477
3563
|
kind: "children",
|
|
@@ -3485,10 +3571,10 @@ var Inliner = class {
|
|
|
3485
3571
|
else if (only.type === "JSXExpressionContainer") {
|
|
3486
3572
|
if (only.expression.type === "JSXEmptyExpression") return;
|
|
3487
3573
|
const value = this.expressionValue(only.expression, "children", reads, fresh, snapshots);
|
|
3488
|
-
if (value.kind !== "expression" || value.text !==
|
|
3574
|
+
if (value.kind !== "expression" || value.text !== getText(this.context, only.expression)) return value;
|
|
3489
3575
|
text = value.text;
|
|
3490
3576
|
primary = value.primary;
|
|
3491
|
-
} else text =
|
|
3577
|
+
} else text = getText(this.context, only);
|
|
3492
3578
|
return {
|
|
3493
3579
|
kind: "children",
|
|
3494
3580
|
children,
|
|
@@ -3515,7 +3601,7 @@ var Inliner = class {
|
|
|
3515
3601
|
}
|
|
3516
3602
|
return {
|
|
3517
3603
|
kind: "expression",
|
|
3518
|
-
text:
|
|
3604
|
+
text: getText(this.context, value.expression),
|
|
3519
3605
|
primary: true
|
|
3520
3606
|
};
|
|
3521
3607
|
}
|
|
@@ -3542,7 +3628,7 @@ var Inliner = class {
|
|
|
3542
3628
|
case "JSXElement":
|
|
3543
3629
|
case "JSXFragment": return {
|
|
3544
3630
|
kind: "jsx",
|
|
3545
|
-
text:
|
|
3631
|
+
text: getText(this.context, value),
|
|
3546
3632
|
primary: true
|
|
3547
3633
|
};
|
|
3548
3634
|
}
|
|
@@ -3555,7 +3641,7 @@ var Inliner = class {
|
|
|
3555
3641
|
* How an expression passed as a prop reads in a copy of the component.
|
|
3556
3642
|
*/
|
|
3557
3643
|
expressionValue(expression, name, reads, fresh, snapshots) {
|
|
3558
|
-
const text =
|
|
3644
|
+
const text = getText(this.context, expression);
|
|
3559
3645
|
const inner = unwrap(expression);
|
|
3560
3646
|
if (inner.type === "JSXElement" || inner.type === "JSXFragment") return {
|
|
3561
3647
|
kind: "jsx",
|
|
@@ -3617,12 +3703,12 @@ var Inliner = class {
|
|
|
3617
3703
|
* when it cannot be inlined there. Nothing is written until `commit`.
|
|
3618
3704
|
*/
|
|
3619
3705
|
prepare(component, element) {
|
|
3620
|
-
const attributes =
|
|
3706
|
+
const attributes = getAttributes(this.context, element);
|
|
3621
3707
|
if (!attributes) {
|
|
3622
3708
|
this.reason = callSiteReason(element);
|
|
3623
3709
|
return;
|
|
3624
3710
|
}
|
|
3625
|
-
const hasChildren = element.children.
|
|
3711
|
+
const hasChildren = getSignificantChildren(element.children).length > 0;
|
|
3626
3712
|
if (hasChildren && attributes.has("children")) {
|
|
3627
3713
|
this.reason = "call-children";
|
|
3628
3714
|
return;
|
|
@@ -3668,7 +3754,7 @@ var Inliner = class {
|
|
|
3668
3754
|
return;
|
|
3669
3755
|
}
|
|
3670
3756
|
const hoisted = component.statements.length > 0 || snapshots.length > 0;
|
|
3671
|
-
const host = hoisted ? this.
|
|
3757
|
+
const host = hoisted ? this.findHost(element) : void 0;
|
|
3672
3758
|
if (hoisted && !host) {
|
|
3673
3759
|
this.reason = "no-host";
|
|
3674
3760
|
return;
|
|
@@ -3745,7 +3831,8 @@ var Inliner = class {
|
|
|
3745
3831
|
* stored in a `const` of the host first, so every read gets the same one.
|
|
3746
3832
|
*/
|
|
3747
3833
|
findTransparentProviders(components, sites) {
|
|
3748
|
-
const byBinding = new Map(
|
|
3834
|
+
const byBinding = /* @__PURE__ */ new Map();
|
|
3835
|
+
for (const component of components) byBinding.set(component.binding, component);
|
|
3749
3836
|
const closedUnder = (provider) => {
|
|
3750
3837
|
const closedComponents = /* @__PURE__ */ new Map();
|
|
3751
3838
|
const options = {
|
|
@@ -3770,21 +3857,26 @@ var Inliner = class {
|
|
|
3770
3857
|
const changed = [];
|
|
3771
3858
|
for (const provider of findProviders(this.context)) {
|
|
3772
3859
|
const { element } = provider;
|
|
3773
|
-
if (!sites
|
|
3860
|
+
if (!hasSiteInside(sites, element)) continue;
|
|
3774
3861
|
const isClosedNode = closedUnder(provider);
|
|
3775
|
-
|
|
3862
|
+
let closed = true;
|
|
3863
|
+
for (const child of element.children) if (!isClosedNode(child)) {
|
|
3864
|
+
closed = false;
|
|
3865
|
+
break;
|
|
3866
|
+
}
|
|
3867
|
+
if (!closed) continue;
|
|
3776
3868
|
if (stableValueText(this.context, provider, element) !== void 0) {
|
|
3777
3869
|
this.transparent.set(element, { provider });
|
|
3778
3870
|
continue;
|
|
3779
3871
|
}
|
|
3780
|
-
const host = this.
|
|
3872
|
+
const host = this.findHost(element);
|
|
3781
3873
|
if (!host) continue;
|
|
3782
3874
|
const name = this.freshName(`${provider.context.name.charAt(0).toLowerCase()}${provider.context.name.slice(1)}Value`);
|
|
3783
3875
|
const entry = this.hosts.get(host.fn) ?? {
|
|
3784
3876
|
host: host.host,
|
|
3785
3877
|
texts: []
|
|
3786
3878
|
};
|
|
3787
|
-
entry.texts.push(`const ${name} = ${
|
|
3879
|
+
entry.texts.push(`const ${name} = ${getText(this.context, provider.value)};`);
|
|
3788
3880
|
this.hosts.set(host.fn, entry);
|
|
3789
3881
|
this.context.s.overwrite(provider.value.start, provider.value.end, name);
|
|
3790
3882
|
this.transparent.set(element, {
|
|
@@ -3830,7 +3922,8 @@ var Inliner = class {
|
|
|
3830
3922
|
const order = [];
|
|
3831
3923
|
for (const source of spread.view.sources) {
|
|
3832
3924
|
const keys = source.defaults ? [...source.defaults.keys()] : callKeys;
|
|
3833
|
-
for (const key of keys
|
|
3925
|
+
for (const key of keys) {
|
|
3926
|
+
if (source.hidden.has(key)) continue;
|
|
3834
3927
|
const index = order.indexOf(key);
|
|
3835
3928
|
if (index !== -1) order.splice(index, 1);
|
|
3836
3929
|
order.push(key);
|
|
@@ -3839,7 +3932,7 @@ var Inliner = class {
|
|
|
3839
3932
|
let names = taken.get(spread.element);
|
|
3840
3933
|
if (!names) {
|
|
3841
3934
|
names = /* @__PURE__ */ new Set();
|
|
3842
|
-
for (const attribute of spread.element.openingElement.attributes) if (attribute.type === "JSXAttribute") names.add(attribute.name.type === "JSXIdentifier" ? attribute.name.name :
|
|
3935
|
+
for (const attribute of spread.element.openingElement.attributes) if (attribute.type === "JSXAttribute") names.add(attribute.name.type === "JSXIdentifier" ? attribute.name.name : getText(this.context, attribute.name));
|
|
3843
3936
|
taken.set(spread.element, names);
|
|
3844
3937
|
}
|
|
3845
3938
|
const keys = /* @__PURE__ */ new Map();
|
|
@@ -3928,7 +4021,11 @@ var Inliner = class {
|
|
|
3928
4021
|
const bare = value.primary || acceptsAnyExpression(this.context, read.member);
|
|
3929
4022
|
copy.overwrite(read.member.start, read.member.end, bare ? value.text : `(${value.text})`);
|
|
3930
4023
|
}
|
|
3931
|
-
for (const [parent, pieces] of spliced)
|
|
4024
|
+
for (const [parent, pieces] of spliced) {
|
|
4025
|
+
const children = [];
|
|
4026
|
+
for (const child of parent.children) children.push(pieces.get(child) ?? keptPiece(child));
|
|
4027
|
+
writePieces(copy, children);
|
|
4028
|
+
}
|
|
3932
4029
|
}
|
|
3933
4030
|
splicedPiece(container, value) {
|
|
3934
4031
|
if (value.kind === "children") {
|
|
@@ -3966,12 +4063,16 @@ var Inliner = class {
|
|
|
3966
4063
|
this.scratchNames = new Set(this.context.scopes.names);
|
|
3967
4064
|
try {
|
|
3968
4065
|
const copiesOf = /* @__PURE__ */ new Map();
|
|
3969
|
-
for (const [component, elements] of byComponent)
|
|
4066
|
+
for (const [component, elements] of byComponent) {
|
|
4067
|
+
const prepared = /* @__PURE__ */ new Map();
|
|
4068
|
+
for (const element of elements) prepared.set(element, this.prepare(component, element));
|
|
4069
|
+
copiesOf.set(component, prepared);
|
|
4070
|
+
}
|
|
3970
4071
|
this.sites = sites;
|
|
3971
4072
|
this.otherUses = otherUses;
|
|
3972
4073
|
this.blocked = /* @__PURE__ */ new Map();
|
|
3973
4074
|
for (const [inner, byElement] of copiesOf) for (const [element, copy] of byElement) {
|
|
3974
|
-
const outer = copy ? void 0 : this.components
|
|
4075
|
+
const outer = copy ? void 0 : findOuterComponent(this.components, inner, element);
|
|
3975
4076
|
if (outer) {
|
|
3976
4077
|
const list = this.blocked.get(outer) ?? [];
|
|
3977
4078
|
list.push(inner);
|
|
@@ -3979,7 +4080,7 @@ var Inliner = class {
|
|
|
3979
4080
|
}
|
|
3980
4081
|
}
|
|
3981
4082
|
for (const [component, byElement] of copiesOf) {
|
|
3982
|
-
const copies =
|
|
4083
|
+
const copies = collectPrepared(byElement.values());
|
|
3983
4084
|
if (copies.length === 0) continue;
|
|
3984
4085
|
if (this.inliningGain(component, copies, this.removedShare(component, byElement, otherUses)) + this.enabledGain(component, copies, copiesOf, otherUses) >= 0) result.add(component);
|
|
3985
4086
|
}
|
|
@@ -3997,7 +4098,7 @@ var Inliner = class {
|
|
|
3997
4098
|
* keeps it.
|
|
3998
4099
|
*/
|
|
3999
4100
|
removedShare(component, copies, otherUses) {
|
|
4000
|
-
if (component.declaration === void 0 || otherUses.get(component) !== 0 ||
|
|
4101
|
+
if (component.declaration === void 0 || otherUses.get(component) !== 0 || hasMissingCopy(copies.values())) return 0;
|
|
4001
4102
|
const users = this.context.options.sharedComponents.get(component.binding.name) ?? 1;
|
|
4002
4103
|
return users > 0 ? 1 / users : 0;
|
|
4003
4104
|
}
|
|
@@ -4007,7 +4108,8 @@ var Inliner = class {
|
|
|
4007
4108
|
* element around its call to hoist them to.
|
|
4008
4109
|
*/
|
|
4009
4110
|
enabledGain(component, copies, copiesOf, otherUses) {
|
|
4010
|
-
const elements =
|
|
4111
|
+
const elements = [];
|
|
4112
|
+
for (const copy of copies) elements.push(copy.element);
|
|
4011
4113
|
this.assumedHosts = new Set(elements);
|
|
4012
4114
|
let gain = 0;
|
|
4013
4115
|
try {
|
|
@@ -4015,14 +4117,14 @@ var Inliner = class {
|
|
|
4015
4117
|
if (other === component) continue;
|
|
4016
4118
|
const enabled = new Map(byElement);
|
|
4017
4119
|
let changed = false;
|
|
4018
|
-
for (const [element, copy] of byElement) if (!copy &&
|
|
4120
|
+
for (const [element, copy] of byElement) if (!copy && isWithinAny(element, elements)) {
|
|
4019
4121
|
const next = this.prepare(other, element);
|
|
4020
4122
|
enabled.set(element, next);
|
|
4021
4123
|
changed ||= next !== void 0;
|
|
4022
4124
|
}
|
|
4023
4125
|
if (!changed) continue;
|
|
4024
|
-
const now =
|
|
4025
|
-
const then =
|
|
4126
|
+
const now = collectPrepared(byElement.values());
|
|
4127
|
+
const then = collectPrepared(enabled.values());
|
|
4026
4128
|
const before = now.length > 0 ? Math.max(0, this.inliningGain(other, now, 0)) : 0;
|
|
4027
4129
|
const after = this.inliningGain(other, then, this.removedShare(other, enabled, otherUses));
|
|
4028
4130
|
gain += Math.max(0, after - before);
|
|
@@ -4048,7 +4150,7 @@ var Inliner = class {
|
|
|
4048
4150
|
calls += estimator.jsx(copy.element, inTemplate);
|
|
4049
4151
|
const measured = { code: "" };
|
|
4050
4152
|
inlined += copySize(this.context.filename, this.sizeHeader(), copy, inTemplate, this.context.options, blocked.length > 0 ? {
|
|
4051
|
-
declarations: this.
|
|
4153
|
+
declarations: this.createDeclarations(blocked),
|
|
4052
4154
|
inline
|
|
4053
4155
|
} : void 0, measured);
|
|
4054
4156
|
const body = measured.code.slice(measured.code.lastIndexOf(COPY_WRAPPER));
|
|
@@ -4074,17 +4176,19 @@ var Inliner = class {
|
|
|
4074
4176
|
return found;
|
|
4075
4177
|
}
|
|
4076
4178
|
/** The declarations of components, for a copy measured on its own. */
|
|
4077
|
-
|
|
4179
|
+
createDeclarations(components) {
|
|
4078
4180
|
const texts = [];
|
|
4079
4181
|
for (const component of components) {
|
|
4080
4182
|
const statement = this.topLevelStatement(component.binding.declaration);
|
|
4081
|
-
if (statement) texts.push(
|
|
4183
|
+
if (statement) texts.push(getText(this.context, statement));
|
|
4082
4184
|
}
|
|
4083
4185
|
return texts.join("\n");
|
|
4084
4186
|
}
|
|
4085
4187
|
/** Whether every call of `inner` is in `outer`, and nothing else uses it. */
|
|
4086
4188
|
onlyUsedWithin(inner, outer) {
|
|
4087
|
-
|
|
4189
|
+
if (this.otherUses?.get(inner) !== 0) return false;
|
|
4190
|
+
for (const site of this.sites) if (site.component === inner && !isWithin(site.element, outer.fn)) return false;
|
|
4191
|
+
return true;
|
|
4088
4192
|
}
|
|
4089
4193
|
/**
|
|
4090
4194
|
* Whether an element sits directly in an intrinsic element, whose
|
|
@@ -4116,7 +4220,8 @@ var Inliner = class {
|
|
|
4116
4220
|
*/
|
|
4117
4221
|
sizeHeader() {
|
|
4118
4222
|
if (this.header === void 0) {
|
|
4119
|
-
const imports =
|
|
4223
|
+
const imports = [];
|
|
4224
|
+
for (const statement of this.context.program.body) if (statement.type === "ImportDeclaration" || isDataDeclaration(statement)) imports.push(this.context.code.slice(statement.start, statement.end));
|
|
4120
4225
|
const aliases = [...this.context.options.builtInAliases.keys()];
|
|
4121
4226
|
if (aliases.length > 0) imports.push(`var ${aliases.join(", ")};`);
|
|
4122
4227
|
this.header = imports.join("\n");
|
|
@@ -4230,7 +4335,7 @@ var Inliner = class {
|
|
|
4230
4335
|
this.report(rejected, siteReasons);
|
|
4231
4336
|
const copied = [...inlined.keys()];
|
|
4232
4337
|
for (const [component, elements] of inlined) {
|
|
4233
|
-
const insideCopy =
|
|
4338
|
+
const insideCopy = isInsideOtherCopy(component, elements, copied);
|
|
4234
4339
|
if (component.declaration && otherUses.get(component) === 0 && !insideCopy) {
|
|
4235
4340
|
this.context.s.remove(component.declaration.start, component.declaration.end);
|
|
4236
4341
|
for (const alias of aliases.get(component) ?? []) this.context.s.remove(alias.start, alias.end);
|
|
@@ -4271,7 +4376,7 @@ var Inliner = class {
|
|
|
4271
4376
|
const tag = element.openingElement.name;
|
|
4272
4377
|
if (tag.type === "JSXMemberExpression") return {
|
|
4273
4378
|
reason: "member-tag",
|
|
4274
|
-
name:
|
|
4379
|
+
name: getText(this.context, tag)
|
|
4275
4380
|
};
|
|
4276
4381
|
if (tag.type !== "JSXIdentifier" || !isCapitalized(tag.name)) return;
|
|
4277
4382
|
const { name } = tag;
|
|
@@ -4307,7 +4412,9 @@ var Inliner = class {
|
|
|
4307
4412
|
writeHosts() {
|
|
4308
4413
|
for (const { host, texts } of this.hosts.values()) if (host.kind === "return") {
|
|
4309
4414
|
const indent = this.indentationAt(host.statement.start);
|
|
4310
|
-
|
|
4415
|
+
let written = "";
|
|
4416
|
+
for (const text of texts) written += `${text}\n${indent}`;
|
|
4417
|
+
this.context.s.prependRight(host.statement.start, written);
|
|
4311
4418
|
} else {
|
|
4312
4419
|
this.context.s.prependRight(host.body.start, `{ ${texts.join(" ")} return `);
|
|
4313
4420
|
this.context.s.appendLeft(host.body.end, "; }");
|
|
@@ -4322,6 +4429,60 @@ function inline(context) {
|
|
|
4322
4429
|
inliner.run();
|
|
4323
4430
|
return inliner.changed;
|
|
4324
4431
|
}
|
|
4432
|
+
/** Whether another pending site must be done before this one. */
|
|
4433
|
+
function hasPendingDependency(pending, site) {
|
|
4434
|
+
for (const other of pending) if (other !== site && (isWithin(other.element, site.component.fn) || isWithin(other.element, site.element))) return true;
|
|
4435
|
+
return false;
|
|
4436
|
+
}
|
|
4437
|
+
function areDataDeclarators(declarators) {
|
|
4438
|
+
for (const declarator of declarators) if (declarator.id.type !== "Identifier" || declarator.init === null || !isDataLiteral(declarator.init)) return false;
|
|
4439
|
+
return true;
|
|
4440
|
+
}
|
|
4441
|
+
function areDataElements(elements) {
|
|
4442
|
+
for (const element of elements) if (element === null || element.type === "SpreadElement" || !isDataLiteral(element)) return false;
|
|
4443
|
+
return true;
|
|
4444
|
+
}
|
|
4445
|
+
function areDataProperties(properties) {
|
|
4446
|
+
for (const property of properties) if (property.type !== "Property" || property.kind !== "init" || property.method || property.computed || !isDataLiteral(property.value)) return false;
|
|
4447
|
+
return true;
|
|
4448
|
+
}
|
|
4449
|
+
function getSignificantChildren(children) {
|
|
4450
|
+
const significant = [];
|
|
4451
|
+
for (const child of children) if (!isInsignificant(child)) significant.push(child);
|
|
4452
|
+
return significant;
|
|
4453
|
+
}
|
|
4454
|
+
function hasSpreadChild(children) {
|
|
4455
|
+
for (const child of children) if (child.type === "JSXSpreadChild") return true;
|
|
4456
|
+
return false;
|
|
4457
|
+
}
|
|
4458
|
+
function hasSiteInside(sites, element) {
|
|
4459
|
+
for (const site of sites) if (isWithin(site.element, element) && site.element !== element) return true;
|
|
4460
|
+
return false;
|
|
4461
|
+
}
|
|
4462
|
+
function findOuterComponent(components, inner, element) {
|
|
4463
|
+
for (const item of components) if (item !== inner && isWithin(element, item.fn)) return item;
|
|
4464
|
+
}
|
|
4465
|
+
function collectPrepared(copies) {
|
|
4466
|
+
const prepared = [];
|
|
4467
|
+
for (const copy of copies) if (copy !== void 0) prepared.push(copy);
|
|
4468
|
+
return prepared;
|
|
4469
|
+
}
|
|
4470
|
+
function hasMissingCopy(copies) {
|
|
4471
|
+
for (const copy of copies) if (copy === void 0) return true;
|
|
4472
|
+
return false;
|
|
4473
|
+
}
|
|
4474
|
+
function isWithinAny(element, outers) {
|
|
4475
|
+
for (const outer of outers) if (isWithin(element, outer)) return true;
|
|
4476
|
+
return false;
|
|
4477
|
+
}
|
|
4478
|
+
function isInsideOtherCopy(component, elements, copied) {
|
|
4479
|
+
for (const element of elements) for (const other of copied) if (other !== component && element.start >= other.fn.start && element.end <= other.fn.end) return true;
|
|
4480
|
+
return false;
|
|
4481
|
+
}
|
|
4482
|
+
function hasChild(children, child) {
|
|
4483
|
+
for (const item of children) if (item === child) return true;
|
|
4484
|
+
return false;
|
|
4485
|
+
}
|
|
4325
4486
|
//#endregion
|
|
4326
4487
|
//#region src/memo.ts
|
|
4327
4488
|
/**
|
|
@@ -4364,9 +4525,9 @@ function isFresh(node) {
|
|
|
4364
4525
|
function constantText(context, node) {
|
|
4365
4526
|
const expression = unwrap(node);
|
|
4366
4527
|
switch (expression.type) {
|
|
4367
|
-
case "Literal": return "regex" in expression ? void 0 :
|
|
4368
|
-
case "TemplateLiteral": return expression.expressions.length === 0 ?
|
|
4369
|
-
case "UnaryExpression": return expression.operator === "-" && expression.argument.type === "Literal" && typeof expression.argument.value === "number" ?
|
|
4528
|
+
case "Literal": return "regex" in expression ? void 0 : getText(context, expression);
|
|
4529
|
+
case "TemplateLiteral": return expression.expressions.length === 0 ? getText(context, expression) : void 0;
|
|
4530
|
+
case "UnaryExpression": return expression.operator === "-" && expression.argument.type === "Literal" && typeof expression.argument.value === "number" ? getText(context, expression) : void 0;
|
|
4370
4531
|
default: return;
|
|
4371
4532
|
}
|
|
4372
4533
|
}
|
|
@@ -4471,13 +4632,13 @@ var MemoInliner = class {
|
|
|
4471
4632
|
/**
|
|
4472
4633
|
* The function a node runs in.
|
|
4473
4634
|
*/
|
|
4474
|
-
|
|
4635
|
+
findEnclosingFunction(node) {
|
|
4475
4636
|
let current = this.context.parents.get(node);
|
|
4476
4637
|
while (current && !isFunctionNode(current)) current = this.context.parents.get(current);
|
|
4477
4638
|
return current;
|
|
4478
4639
|
}
|
|
4479
4640
|
/** The JSX expression container a call is the whole of. */
|
|
4480
|
-
|
|
4641
|
+
findContainer(call) {
|
|
4481
4642
|
let parent = this.context.parents.get(call);
|
|
4482
4643
|
while (parent?.type === "ParenthesizedExpression") parent = this.context.parents.get(parent);
|
|
4483
4644
|
return parent?.type === "JSXExpressionContainer" ? parent : void 0;
|
|
@@ -4510,11 +4671,11 @@ var MemoInliner = class {
|
|
|
4510
4671
|
const tag = element.openingElement.name.name;
|
|
4511
4672
|
if (isIntrinsicTag(tag)) {
|
|
4512
4673
|
if (attribute.startsWith("on") || attribute === "ref") return false;
|
|
4513
|
-
} else if (this.
|
|
4674
|
+
} else if (this.getBuiltIn(element.openingElement.name) !== tag || TRACKED_PROPS.get(tag) !== attribute) return false;
|
|
4514
4675
|
} else return false;
|
|
4515
4676
|
return this.isStaticJSX(element, fn);
|
|
4516
4677
|
}
|
|
4517
|
-
|
|
4678
|
+
getBuiltIn(name) {
|
|
4518
4679
|
if (name.type !== "JSXIdentifier") return;
|
|
4519
4680
|
const { references } = this.context.scopes;
|
|
4520
4681
|
if (!references.has(name)) return;
|
|
@@ -4539,7 +4700,7 @@ var MemoInliner = class {
|
|
|
4539
4700
|
}
|
|
4540
4701
|
case "JSXFragment":
|
|
4541
4702
|
case "ParenthesizedExpression": break;
|
|
4542
|
-
case "ReturnStatement": return this.
|
|
4703
|
+
case "ReturnStatement": return this.findEnclosingFunction(parent) === fn && !this.inLoop(parent, fn);
|
|
4543
4704
|
default: return false;
|
|
4544
4705
|
}
|
|
4545
4706
|
node = parent;
|
|
@@ -4590,7 +4751,7 @@ var MemoInliner = class {
|
|
|
4590
4751
|
return;
|
|
4591
4752
|
}
|
|
4592
4753
|
const statement = this.context.parents.get(declarator);
|
|
4593
|
-
const fn = this.
|
|
4754
|
+
const fn = this.findEnclosingFunction(declarator);
|
|
4594
4755
|
if (statement?.type !== "VariableDeclaration" || statement.declarations.length !== 1 || !fn) {
|
|
4595
4756
|
this.reason = "memo-declaration";
|
|
4596
4757
|
return;
|
|
@@ -4605,7 +4766,7 @@ var MemoInliner = class {
|
|
|
4605
4766
|
this.reason = "memo-read-place";
|
|
4606
4767
|
return;
|
|
4607
4768
|
}
|
|
4608
|
-
const container = this.
|
|
4769
|
+
const container = this.findContainer(call);
|
|
4609
4770
|
const owner = container ? this.context.parents.get(container) : void 0;
|
|
4610
4771
|
if (kind === "children" && (!container || owner?.type !== "JSXElement" && owner?.type !== "JSXFragment")) {
|
|
4611
4772
|
this.reason = "memo-read-place";
|
|
@@ -4615,8 +4776,8 @@ var MemoInliner = class {
|
|
|
4615
4776
|
this.reason = "memo-scope";
|
|
4616
4777
|
return;
|
|
4617
4778
|
}
|
|
4618
|
-
if (kind === "children" && container) this.context.s.overwrite(container.start, container.end,
|
|
4619
|
-
else this.context.s.overwrite(call.start, call.end,
|
|
4779
|
+
if (kind === "children" && container) this.context.s.overwrite(container.start, container.end, getText(this.context, expression));
|
|
4780
|
+
else this.context.s.overwrite(call.start, call.end, getText(this.context, expression));
|
|
4620
4781
|
this.context.s.remove(statement.start, statement.end);
|
|
4621
4782
|
this.changed = true;
|
|
4622
4783
|
return true;
|
|
@@ -4640,6 +4801,301 @@ function inlineMemos(context) {
|
|
|
4640
4801
|
return inliner.changed;
|
|
4641
4802
|
}
|
|
4642
4803
|
//#endregion
|
|
4804
|
+
//#region src/conditional.ts
|
|
4805
|
+
/**
|
|
4806
|
+
* Rewrites each `<Show>` and `<Switch>` that can be lowered. One inside
|
|
4807
|
+
* another that is lowered stays for the next run, since both would edit the
|
|
4808
|
+
* same text.
|
|
4809
|
+
*/
|
|
4810
|
+
function lowerConditionals(context) {
|
|
4811
|
+
let changed = false;
|
|
4812
|
+
visit(context.program);
|
|
4813
|
+
return changed;
|
|
4814
|
+
function visit(node) {
|
|
4815
|
+
if (node.type === "JSXElement") {
|
|
4816
|
+
const ternary = ternaryOf(context, node);
|
|
4817
|
+
const form = ternary === void 0 ? void 0 : formAt(context, node);
|
|
4818
|
+
if (ternary !== void 0 && form !== void 0) {
|
|
4819
|
+
context.s.overwrite(node.start, node.end, form === "container" ? `{${ternary}}` : `<>{${ternary}}</>`);
|
|
4820
|
+
changed = true;
|
|
4821
|
+
return;
|
|
4822
|
+
}
|
|
4823
|
+
}
|
|
4824
|
+
forEachChild(node, visit);
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
/**
|
|
4828
|
+
* The Solid built-in an element's tag resolves to, by the name Solid exports it under.
|
|
4829
|
+
*/
|
|
4830
|
+
function builtInOf(context, element) {
|
|
4831
|
+
const { name } = element.openingElement;
|
|
4832
|
+
if (name.type !== "JSXIdentifier") return;
|
|
4833
|
+
const { references } = context.scopes;
|
|
4834
|
+
if (!references.has(name)) return;
|
|
4835
|
+
const binding = references.get(name);
|
|
4836
|
+
const identity = binding ? solidExport(binding, context.options) : name.name;
|
|
4837
|
+
return identity !== void 0 && context.options.builtIns.has(identity) ? identity : void 0;
|
|
4838
|
+
}
|
|
4839
|
+
/**
|
|
4840
|
+
* The ternary a `<Show>` or `<Switch>` lowers to, or `undefined` when its
|
|
4841
|
+
* props or children need the component.
|
|
4842
|
+
*/
|
|
4843
|
+
function ternaryOf(context, element) {
|
|
4844
|
+
switch (builtInOf(context, element)) {
|
|
4845
|
+
case "Show": {
|
|
4846
|
+
const branch = branchOf(context, element, ["when", "fallback"]);
|
|
4847
|
+
if (branch === void 0) return;
|
|
4848
|
+
return `${branch.when} ? ${branch.children} : ${branch.fallback ?? "undefined"}`;
|
|
4849
|
+
}
|
|
4850
|
+
case "Switch": return switchTernary(context, element);
|
|
4851
|
+
default: return;
|
|
4852
|
+
}
|
|
4853
|
+
}
|
|
4854
|
+
/**
|
|
4855
|
+
* A `<Switch>` whose children are all `<Match>`es that lower, as a chain of ternaries.
|
|
4856
|
+
*/
|
|
4857
|
+
function switchTernary(context, element) {
|
|
4858
|
+
const props = propsOf(context, element, ["fallback"]);
|
|
4859
|
+
if (props === void 0) return;
|
|
4860
|
+
let chain = "";
|
|
4861
|
+
let count = 0;
|
|
4862
|
+
for (const child of significantChildren(element.children)) {
|
|
4863
|
+
if (child.type !== "JSXElement" || builtInOf(context, child) !== "Match") return;
|
|
4864
|
+
const branch = branchOf(context, child, ["when"]);
|
|
4865
|
+
if (branch === void 0) return;
|
|
4866
|
+
chain += `${branch.when} ? ${branch.children} : `;
|
|
4867
|
+
count += 1;
|
|
4868
|
+
}
|
|
4869
|
+
if (count === 0) return;
|
|
4870
|
+
return `${chain}${props.get("fallback") ?? "undefined"}`;
|
|
4871
|
+
}
|
|
4872
|
+
/**
|
|
4873
|
+
* How a `<Show>` or `<Switch>` at this position is written once lowered, or `undefined`
|
|
4874
|
+
* when the position is not supported.
|
|
4875
|
+
*/
|
|
4876
|
+
function formAt(context, element) {
|
|
4877
|
+
const parent = context.parents.get(element);
|
|
4878
|
+
if (parent === void 0) return "fragment";
|
|
4879
|
+
switch (parent.type) {
|
|
4880
|
+
case "JSXFragment": return "container";
|
|
4881
|
+
case "JSXElement": {
|
|
4882
|
+
const { name } = parent.openingElement;
|
|
4883
|
+
if (name.type === "JSXNamespacedName" || name.type === "JSXIdentifier" && isIntrinsicTag(name.name)) return "container";
|
|
4884
|
+
return isSoleChild(parent.children, element) ? "fragment" : void 0;
|
|
4885
|
+
}
|
|
4886
|
+
case "JSXExpressionContainer":
|
|
4887
|
+
case "JSXAttribute": return;
|
|
4888
|
+
default: return isInJSXExpression(context, parent) ? void 0 : "fragment";
|
|
4889
|
+
}
|
|
4890
|
+
}
|
|
4891
|
+
/**
|
|
4892
|
+
* Whether a node is part of an expression in a JSX container, such as
|
|
4893
|
+
* `{ok && <Show />}`, where a function boundary does not separate them.
|
|
4894
|
+
*/
|
|
4895
|
+
function isInJSXExpression(context, node) {
|
|
4896
|
+
let current = node;
|
|
4897
|
+
while (current !== void 0 && !isFunctionNode(current)) {
|
|
4898
|
+
if (current.type === "JSXExpressionContainer") return true;
|
|
4899
|
+
current = context.parents.get(current);
|
|
4900
|
+
}
|
|
4901
|
+
return false;
|
|
4902
|
+
}
|
|
4903
|
+
function isSoleChild(children, element) {
|
|
4904
|
+
for (const child of children) if (child !== element && !isInsignificant(child)) return false;
|
|
4905
|
+
return true;
|
|
4906
|
+
}
|
|
4907
|
+
/**
|
|
4908
|
+
* The text of each prop of an element, or `undefined` when it has a prop
|
|
4909
|
+
* other than `names`, a spread, or a prop more than once. A repeated prop
|
|
4910
|
+
* takes its last value, and a spread could hold any prop, such as `keyed`.
|
|
4911
|
+
*/
|
|
4912
|
+
function propsOf(context, element, names) {
|
|
4913
|
+
const props = /* @__PURE__ */ new Map();
|
|
4914
|
+
for (const attribute of element.openingElement.attributes) {
|
|
4915
|
+
if (attribute.type !== "JSXAttribute" || attribute.name.type !== "JSXIdentifier" || !names.includes(attribute.name.name) || props.has(attribute.name.name)) return;
|
|
4916
|
+
const text = expressionText(context, attribute);
|
|
4917
|
+
if (text === void 0) return;
|
|
4918
|
+
props.set(attribute.name.name, text);
|
|
4919
|
+
}
|
|
4920
|
+
return props;
|
|
4921
|
+
}
|
|
4922
|
+
/**
|
|
4923
|
+
* The condition and children of a `<Show>` or `<Match>`, or `undefined` when
|
|
4924
|
+
* the children could need the narrowed value.
|
|
4925
|
+
*/
|
|
4926
|
+
function branchOf(context, element, names) {
|
|
4927
|
+
const props = propsOf(context, element, names);
|
|
4928
|
+
const when = props?.get("when");
|
|
4929
|
+
if (props === void 0 || when === void 0) return;
|
|
4930
|
+
const significant = significantChildren(element.children);
|
|
4931
|
+
const sole = significant.length === 1 ? significant[0] : void 0;
|
|
4932
|
+
const callback = sole?.type === "JSXExpressionContainer" && sole.expression.type !== "JSXEmptyExpression" ? unwrap(sole.expression) : void 0;
|
|
4933
|
+
if (callback?.type === "ArrowFunctionExpression") {
|
|
4934
|
+
const body = callbackBody(context, element, callback);
|
|
4935
|
+
return body === void 0 ? void 0 : {
|
|
4936
|
+
when,
|
|
4937
|
+
children: body,
|
|
4938
|
+
fallback: props.get("fallback")
|
|
4939
|
+
};
|
|
4940
|
+
}
|
|
4941
|
+
if (sole?.type === "JSXExpressionContainer" && sole.expression.type !== "JSXEmptyExpression" && !isNeverFunction(sole.expression)) return;
|
|
4942
|
+
for (const child of significant) if (child.type === "JSXExpressionContainer" && child.expression.type !== "JSXEmptyExpression" && isFunctionNode(unwrap(child.expression))) return;
|
|
4943
|
+
const { closingElement } = element;
|
|
4944
|
+
const inner = closingElement ? context.s.slice(element.openingElement.end, closingElement.start) : "";
|
|
4945
|
+
return {
|
|
4946
|
+
when,
|
|
4947
|
+
children: significant.length > 0 ? `<>${inner}</>` : "undefined",
|
|
4948
|
+
fallback: props.get("fallback")
|
|
4949
|
+
};
|
|
4950
|
+
}
|
|
4951
|
+
/**
|
|
4952
|
+
* The body of a callback child with each read of its parameter written as
|
|
4953
|
+
* `when`, or `undefined` when that could change what the body renders.
|
|
4954
|
+
*/
|
|
4955
|
+
function callbackBody(context, element, callback) {
|
|
4956
|
+
const param = callback.params.at(0);
|
|
4957
|
+
if (callback.async || callback.body.type === "BlockStatement" || callback.params.length !== 1 || param?.type !== "Identifier") return;
|
|
4958
|
+
const body = unwrap(callback.body);
|
|
4959
|
+
if (body.type !== "JSXElement" && body.type !== "JSXFragment") return;
|
|
4960
|
+
const value = findAttribute(element, "when")?.value;
|
|
4961
|
+
if (value?.type !== "JSXExpressionContainer" || value.expression.type === "JSXEmptyExpression" || !isPlainRead(context, value.expression)) return;
|
|
4962
|
+
const when = value.expression;
|
|
4963
|
+
const whenText = `(${context.s.slice(when.start, when.end)})`;
|
|
4964
|
+
const names = [];
|
|
4965
|
+
collectReferences(context, when, names);
|
|
4966
|
+
const binding = lookup(scopeAt(context.scopes, context.parents, param), param.name);
|
|
4967
|
+
if (binding?.identifier !== param || binding.mutated || namesInTypes(body, param.name)) return;
|
|
4968
|
+
const edits = [];
|
|
4969
|
+
for (const reference of binding.references) {
|
|
4970
|
+
if (reference.type !== "Identifier") return;
|
|
4971
|
+
const scope = scopeAt(context.scopes, context.parents, reference);
|
|
4972
|
+
for (const name of names) if (name.type !== "Identifier" || lookup(scope, name.name) !== context.scopes.references.get(name)) return;
|
|
4973
|
+
const parent = context.parents.get(reference);
|
|
4974
|
+
if (parent?.type === "CallExpression" && parent.callee === reference && parent.arguments.length === 0 && !parent.optional) edits.push({
|
|
4975
|
+
start: parent.start,
|
|
4976
|
+
end: parent.end,
|
|
4977
|
+
text: whenText
|
|
4978
|
+
});
|
|
4979
|
+
else if (parent?.type === "Property" && parent.shorthand) return;
|
|
4980
|
+
else edits.push({
|
|
4981
|
+
start: reference.start,
|
|
4982
|
+
end: reference.end,
|
|
4983
|
+
text: `(() => ${whenText})`
|
|
4984
|
+
});
|
|
4985
|
+
}
|
|
4986
|
+
edits.sort((a, b) => a.start - b.start);
|
|
4987
|
+
let text = "";
|
|
4988
|
+
let at = body.start;
|
|
4989
|
+
for (const edit of edits) {
|
|
4990
|
+
text += context.s.slice(at, edit.start) + edit.text;
|
|
4991
|
+
at = edit.end;
|
|
4992
|
+
}
|
|
4993
|
+
return text + context.s.slice(at, body.end);
|
|
4994
|
+
}
|
|
4995
|
+
/**
|
|
4996
|
+
* Whether reading an expression again gives the same value, with nothing run
|
|
4997
|
+
* between the reads: names, members, literals, and operators, and calls of
|
|
4998
|
+
* a signal or a memo. Another call could change something or return
|
|
4999
|
+
* something new, and `this` changes inside a `function` in the body.
|
|
5000
|
+
*/
|
|
5001
|
+
function isPlainRead(context, node) {
|
|
5002
|
+
switch (node.type) {
|
|
5003
|
+
case "Identifier":
|
|
5004
|
+
case "Literal": return true;
|
|
5005
|
+
case "ParenthesizedExpression":
|
|
5006
|
+
case "TSAsExpression":
|
|
5007
|
+
case "TSSatisfiesExpression":
|
|
5008
|
+
case "TSNonNullExpression":
|
|
5009
|
+
case "ChainExpression": return isPlainRead(context, node.expression);
|
|
5010
|
+
case "MemberExpression": return isPlainRead(context, node.object) && (!node.computed || isPlainRead(context, node.property));
|
|
5011
|
+
case "CallExpression": return node.arguments.length === 0 && isAccessor(context, node.callee);
|
|
5012
|
+
case "UnaryExpression": return node.operator !== "delete" && isPlainRead(context, node.argument);
|
|
5013
|
+
case "BinaryExpression":
|
|
5014
|
+
case "LogicalExpression": return isPlainRead(context, node.left) && isPlainRead(context, node.right);
|
|
5015
|
+
case "ConditionalExpression": return isPlainRead(context, node.test) && isPlainRead(context, node.consequent) && isPlainRead(context, node.alternate);
|
|
5016
|
+
default: return false;
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
/**
|
|
5020
|
+
* Whether a callee is the getter of a `createSignal` or a `createMemo` from
|
|
5021
|
+
* Solid, declared with `const` and never written, which returns its current
|
|
5022
|
+
* value without running anything else.
|
|
5023
|
+
*/
|
|
5024
|
+
function isAccessor(context, callee) {
|
|
5025
|
+
if (callee.type !== "Identifier") return false;
|
|
5026
|
+
const binding = context.scopes.references.get(callee);
|
|
5027
|
+
if (!binding || binding.mutated || binding.kind !== "const") return false;
|
|
5028
|
+
const { declaration } = binding;
|
|
5029
|
+
if (declaration.type !== "VariableDeclarator" || !declaration.init) return false;
|
|
5030
|
+
const init = unwrap(declaration.init);
|
|
5031
|
+
if (init.type !== "CallExpression" || init.callee.type !== "Identifier") return false;
|
|
5032
|
+
const factory = context.scopes.references.get(init.callee);
|
|
5033
|
+
const name = factory ? solidExport(factory, context.options) : void 0;
|
|
5034
|
+
if (name === "createMemo") return declaration.id === binding.identifier;
|
|
5035
|
+
return name === "createSignal" && declaration.id.type === "ArrayPattern" && declaration.id.elements.at(0) === binding.identifier;
|
|
5036
|
+
}
|
|
5037
|
+
/** Whether a TypeScript type in `node`, like `typeof v`, names `name`. */
|
|
5038
|
+
function namesInTypes(node, name) {
|
|
5039
|
+
if (typeof node !== "object" || node === null) return false;
|
|
5040
|
+
if (Array.isArray(node)) {
|
|
5041
|
+
for (const item of node) if (namesInTypes(item, name)) return true;
|
|
5042
|
+
return false;
|
|
5043
|
+
}
|
|
5044
|
+
if (Reflect.get(node, "type") === "TSTypeQuery") {
|
|
5045
|
+
const exprName = Reflect.get(node, "exprName");
|
|
5046
|
+
return typeof exprName === "object" && exprName !== null && Reflect.get(exprName, "name") === name;
|
|
5047
|
+
}
|
|
5048
|
+
for (const key of Object.keys(node)) if (key !== "parent" && namesInTypes(Reflect.get(node, key), name)) return true;
|
|
5049
|
+
return false;
|
|
5050
|
+
}
|
|
5051
|
+
/** The identifiers in an expression that refer to a binding or a global. */
|
|
5052
|
+
function collectReferences(context, node, out) {
|
|
5053
|
+
if (node.type === "Identifier" && context.scopes.references.has(node)) out.push(node);
|
|
5054
|
+
forEachChild(node, (child) => {
|
|
5055
|
+
collectReferences(context, child, out);
|
|
5056
|
+
});
|
|
5057
|
+
}
|
|
5058
|
+
/**
|
|
5059
|
+
* Whether an expression's value can never be a function: a literal, JSX, or
|
|
5060
|
+
* an operator that returns a string, number, or boolean.
|
|
5061
|
+
*/
|
|
5062
|
+
function isNeverFunction(node) {
|
|
5063
|
+
switch (node.type) {
|
|
5064
|
+
case "Literal":
|
|
5065
|
+
case "TemplateLiteral":
|
|
5066
|
+
case "JSXElement":
|
|
5067
|
+
case "JSXFragment":
|
|
5068
|
+
case "BinaryExpression":
|
|
5069
|
+
case "UnaryExpression":
|
|
5070
|
+
case "UpdateExpression": return true;
|
|
5071
|
+
case "ParenthesizedExpression": return isNeverFunction(node.expression);
|
|
5072
|
+
case "ConditionalExpression": return isNeverFunction(node.consequent) && isNeverFunction(node.alternate);
|
|
5073
|
+
case "LogicalExpression": return isNeverFunction(node.left) && isNeverFunction(node.right);
|
|
5074
|
+
default: return false;
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
function significantChildren(children) {
|
|
5078
|
+
const result = [];
|
|
5079
|
+
for (const child of children) if (!isInsignificant(child)) result.push(child);
|
|
5080
|
+
return result;
|
|
5081
|
+
}
|
|
5082
|
+
/**
|
|
5083
|
+
* The text of an attribute's value as an expression, or `undefined` when the
|
|
5084
|
+
* value is not supported.
|
|
5085
|
+
*/
|
|
5086
|
+
function expressionText(context, attribute) {
|
|
5087
|
+
const { value } = attribute;
|
|
5088
|
+
if (value === null) return;
|
|
5089
|
+
switch (value.type) {
|
|
5090
|
+
case "JSXExpressionContainer":
|
|
5091
|
+
if (value.expression.type === "JSXEmptyExpression") return;
|
|
5092
|
+
return `(${context.s.slice(value.expression.start, value.expression.end)})`;
|
|
5093
|
+
case "JSXElement":
|
|
5094
|
+
case "JSXFragment": return context.s.slice(value.start, value.end);
|
|
5095
|
+
default: return;
|
|
5096
|
+
}
|
|
5097
|
+
}
|
|
5098
|
+
//#endregion
|
|
4643
5099
|
//#region src/compile.ts
|
|
4644
5100
|
const DEFAULT_BUILT_INS = [
|
|
4645
5101
|
"For",
|
|
@@ -4655,6 +5111,8 @@ const DEFAULT_BUILT_INS = [
|
|
|
4655
5111
|
];
|
|
4656
5112
|
const DEFAULT_MODULE_SOURCES = ["solid-js", "@solidjs/web"];
|
|
4657
5113
|
function resolveOptions(options) {
|
|
5114
|
+
const importedContexts = /* @__PURE__ */ new Map();
|
|
5115
|
+
for (const [source, names] of Object.entries(options.importedContexts ?? {})) importedContexts.set(source, new Set(names));
|
|
4658
5116
|
return {
|
|
4659
5117
|
builtIns: new Set(options.builtIns ?? DEFAULT_BUILT_INS),
|
|
4660
5118
|
moduleSources: options.moduleSources ?? DEFAULT_MODULE_SOURCES,
|
|
@@ -4662,7 +5120,7 @@ function resolveOptions(options) {
|
|
|
4662
5120
|
constantVars: options.constantVars ?? false,
|
|
4663
5121
|
importedConstants: resolveImportedConstants(options.importedConstants),
|
|
4664
5122
|
globalConstants: new Map(Object.entries(options.globalConstants ?? {})),
|
|
4665
|
-
importedContexts
|
|
5123
|
+
importedContexts,
|
|
4666
5124
|
sharedComponents: new Map(Object.entries(options.sharedComponents ?? {})),
|
|
4667
5125
|
alwaysInline: options.alwaysInline ?? false,
|
|
4668
5126
|
alwaysInlineComponents: new Set(options.alwaysInlineComponents ?? [])
|
|
@@ -4744,6 +5202,12 @@ function compile(code, options = {}) {
|
|
|
4744
5202
|
}
|
|
4745
5203
|
if (!changed) break;
|
|
4746
5204
|
}
|
|
5205
|
+
if (options.conditionals ?? true) for (let round = 0; round < maxPasses; round += 1) {
|
|
5206
|
+
const result = runPass(parsedCurrent(), filename, resolved, sourceMap, lowerConditionals, void 0);
|
|
5207
|
+
if (!result) break;
|
|
5208
|
+
current = result.code;
|
|
5209
|
+
if (result.map !== void 0) maps.push(result.map);
|
|
5210
|
+
}
|
|
4747
5211
|
const report = skipped ? { skipped } : {};
|
|
4748
5212
|
if (maps.length === 0) return {
|
|
4749
5213
|
code: current,
|
|
@@ -4773,4 +5237,4 @@ function readModuleConstants(code, options = {}) {
|
|
|
4773
5237
|
//#endregion
|
|
4774
5238
|
export { lookup as a, forEachChild as c, unwrap as d, analyzeScopes as i, isIntrinsicTag as l, readModuleConstants as n, scopeAt as o, CONTEXT_SAFE_PRIMITIVES as r, collectParents as s, compile as t, parse as u };
|
|
4775
5239
|
|
|
4776
|
-
//# sourceMappingURL=compile-
|
|
5240
|
+
//# sourceMappingURL=compile-By9Fecbx.mjs.map
|