@farm.js/react 0.1.0-beta.7 → 0.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +409 -67
- package/dist/compiler-runtime.cjs +2690 -226
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +70 -3
- package/dist/compiler-runtime.d.ts +70 -3
- package/dist/compiler-runtime.mjs +2644 -227
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/vite.cjs +1630 -111
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +1632 -113
- package/dist/vite.mjs.map +1 -1
- package/package.json +5 -4
package/dist/vite.cjs
CHANGED
|
@@ -70,44 +70,77 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
|
70
70
|
"keyed-rows": "keyedRowsRuntimeFeature",
|
|
71
71
|
"keyed-rows-hinted": "keyedRowsHintedRuntimeFeature",
|
|
72
72
|
"keyed-rows-position-hinted": "keyedRowsPositionHintedRuntimeFeature",
|
|
73
|
+
"keyed-rows-batch-position-hinted": "keyedRowsBatchPositionHintedRuntimeFeature",
|
|
74
|
+
"keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
|
|
73
75
|
"keyed-rows-reorder-hinted": "keyedRowsReorderHintedRuntimeFeature",
|
|
76
|
+
"keyed-rows-map-reorder-hinted": "keyedRowsMapReorderHintedRuntimeFeature",
|
|
74
77
|
"keyed-rows-all-hinted": "keyedRowsAllHintedRuntimeFeature",
|
|
75
78
|
"keyed-rows-every-hinted": "keyedRowsEveryHintedRuntimeFeature",
|
|
79
|
+
"keyed-rows-batch-every-hinted": "keyedRowsBatchEveryHintedRuntimeFeature",
|
|
80
|
+
"keyed-rows-window-every-hinted": "keyedRowsWindowEveryHintedRuntimeFeature",
|
|
76
81
|
"keyed-rows-filter-hinted": "keyedRowsFilterHintedRuntimeFeature",
|
|
82
|
+
"keyed-rows-structural-append-hinted": "keyedRowsStructuralAppendHintedRuntimeFeature",
|
|
83
|
+
"keyed-rows-structural-append-map-hinted": "keyedRowsStructuralAppendMapHintedRuntimeFeature",
|
|
84
|
+
"keyed-rows-structural-prepend-hinted": "keyedRowsStructuralPrependHintedRuntimeFeature",
|
|
85
|
+
"keyed-rows-structural-prepend-map-hinted": "keyedRowsStructuralPrependMapHintedRuntimeFeature",
|
|
77
86
|
"keyed-rows-prepend-hinted": "keyedRowsPrependHintedRuntimeFeature",
|
|
78
87
|
"keyed-rows-filter-prepend-hinted": "keyedRowsFilterPrependHintedRuntimeFeature",
|
|
79
88
|
"keyed-rows-conditional": "keyedRowsConditionalRuntimeFeature",
|
|
80
89
|
"keyed-rows-conditional-hinted": "keyedRowsConditionalHintedRuntimeFeature",
|
|
81
90
|
"keyed-rows-conditional-position-hinted": "keyedRowsConditionalPositionHintedRuntimeFeature",
|
|
91
|
+
"keyed-rows-conditional-batch-position-hinted": "keyedRowsConditionalBatchPositionHintedRuntimeFeature",
|
|
92
|
+
"keyed-rows-conditional-window-position-hinted": "keyedRowsConditionalWindowPositionHintedRuntimeFeature",
|
|
82
93
|
"keyed-rows-conditional-reorder-hinted": "keyedRowsConditionalReorderHintedRuntimeFeature",
|
|
83
94
|
"keyed-rows-conditional-all-hinted": "keyedRowsConditionalAllHintedRuntimeFeature",
|
|
84
95
|
"keyed-rows-conditional-every-hinted": "keyedRowsConditionalEveryHintedRuntimeFeature",
|
|
96
|
+
"keyed-rows-conditional-batch-every-hinted": "keyedRowsConditionalBatchEveryHintedRuntimeFeature",
|
|
97
|
+
"keyed-rows-conditional-window-every-hinted": "keyedRowsConditionalWindowEveryHintedRuntimeFeature",
|
|
85
98
|
"keyed-rows-conditional-filter-hinted": "keyedRowsConditionalFilterHintedRuntimeFeature",
|
|
99
|
+
"keyed-rows-conditional-structural-append-hinted": "keyedRowsConditionalStructuralAppendHintedRuntimeFeature",
|
|
100
|
+
"keyed-rows-conditional-structural-append-map-hinted": "keyedRowsConditionalStructuralAppendMapHintedRuntimeFeature",
|
|
101
|
+
"keyed-rows-conditional-structural-prepend-hinted": "keyedRowsConditionalStructuralPrependHintedRuntimeFeature",
|
|
102
|
+
"keyed-rows-conditional-structural-prepend-map-hinted": "keyedRowsConditionalStructuralPrependMapHintedRuntimeFeature",
|
|
86
103
|
"keyed-rows-conditional-prepend-hinted": "keyedRowsConditionalPrependHintedRuntimeFeature",
|
|
87
104
|
"keyed-rows-conditional-filter-prepend-hinted": "keyedRowsConditionalFilterPrependHintedRuntimeFeature",
|
|
88
105
|
"keyed-rows-host": "keyedRowsHostRuntimeFeature",
|
|
89
106
|
"keyed-rows-host-hinted": "keyedRowsHostHintedRuntimeFeature",
|
|
90
107
|
"keyed-rows-host-position-hinted": "keyedRowsHostPositionHintedRuntimeFeature",
|
|
108
|
+
"keyed-rows-host-batch-position-hinted": "keyedRowsHostBatchPositionHintedRuntimeFeature",
|
|
109
|
+
"keyed-rows-host-window-position-hinted": "keyedRowsHostWindowPositionHintedRuntimeFeature",
|
|
91
110
|
"keyed-rows-host-reorder-hinted": "keyedRowsHostReorderHintedRuntimeFeature",
|
|
92
111
|
"keyed-rows-host-all-hinted": "keyedRowsHostAllHintedRuntimeFeature",
|
|
93
112
|
"keyed-rows-host-every-hinted": "keyedRowsHostEveryHintedRuntimeFeature",
|
|
113
|
+
"keyed-rows-host-batch-every-hinted": "keyedRowsHostBatchEveryHintedRuntimeFeature",
|
|
114
|
+
"keyed-rows-host-window-every-hinted": "keyedRowsHostWindowEveryHintedRuntimeFeature",
|
|
94
115
|
"keyed-rows-host-filter-hinted": "keyedRowsHostFilterHintedRuntimeFeature",
|
|
116
|
+
"keyed-rows-host-structural-append-hinted": "keyedRowsHostStructuralAppendHintedRuntimeFeature",
|
|
117
|
+
"keyed-rows-host-structural-append-map-hinted": "keyedRowsHostStructuralAppendMapHintedRuntimeFeature",
|
|
118
|
+
"keyed-rows-host-structural-prepend-hinted": "keyedRowsHostStructuralPrependHintedRuntimeFeature",
|
|
119
|
+
"keyed-rows-host-structural-prepend-map-hinted": "keyedRowsHostStructuralPrependMapHintedRuntimeFeature",
|
|
95
120
|
"keyed-rows-host-prepend-hinted": "keyedRowsHostPrependHintedRuntimeFeature",
|
|
96
121
|
"keyed-rows-host-filter-prepend-hinted": "keyedRowsHostFilterPrependHintedRuntimeFeature",
|
|
97
122
|
"keyed-rows-complete": "keyedRowsCompleteRuntimeFeature",
|
|
98
123
|
"keyed-rows-complete-hinted": "keyedRowsCompleteHintedRuntimeFeature",
|
|
99
124
|
"keyed-rows-complete-position-hinted": "keyedRowsCompletePositionHintedRuntimeFeature",
|
|
125
|
+
"keyed-rows-complete-batch-position-hinted": "keyedRowsCompleteBatchPositionHintedRuntimeFeature",
|
|
126
|
+
"keyed-rows-complete-window-position-hinted": "keyedRowsCompleteWindowPositionHintedRuntimeFeature",
|
|
100
127
|
"keyed-rows-complete-reorder-hinted": "keyedRowsCompleteReorderHintedRuntimeFeature",
|
|
101
128
|
"keyed-rows-complete-all-hinted": "keyedRowsCompleteAllHintedRuntimeFeature",
|
|
102
129
|
"keyed-rows-complete-every-hinted": "keyedRowsCompleteEveryHintedRuntimeFeature",
|
|
130
|
+
"keyed-rows-complete-batch-every-hinted": "keyedRowsCompleteBatchEveryHintedRuntimeFeature",
|
|
131
|
+
"keyed-rows-complete-window-every-hinted": "keyedRowsCompleteWindowEveryHintedRuntimeFeature",
|
|
103
132
|
"keyed-rows-complete-filter-hinted": "keyedRowsCompleteFilterHintedRuntimeFeature",
|
|
133
|
+
"keyed-rows-complete-structural-append-hinted": "keyedRowsCompleteStructuralAppendHintedRuntimeFeature",
|
|
134
|
+
"keyed-rows-complete-structural-append-map-hinted": "keyedRowsCompleteStructuralAppendMapHintedRuntimeFeature",
|
|
135
|
+
"keyed-rows-complete-structural-prepend-hinted": "keyedRowsCompleteStructuralPrependHintedRuntimeFeature",
|
|
136
|
+
"keyed-rows-complete-structural-prepend-map-hinted": "keyedRowsCompleteStructuralPrependMapHintedRuntimeFeature",
|
|
104
137
|
"keyed-rows-complete-prepend-hinted": "keyedRowsCompletePrependHintedRuntimeFeature",
|
|
105
138
|
"keyed-rows-complete-filter-prepend-hinted": "keyedRowsCompleteFilterPrependHintedRuntimeFeature",
|
|
106
139
|
"keyed-ranges": "keyedRangesRuntimeFeature",
|
|
107
140
|
"mixed-ranges": "mixedRangesRuntimeFeature",
|
|
108
141
|
component: "componentRuntimeFeature"
|
|
109
142
|
};
|
|
110
|
-
function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHints, keyedArrayPrependHints, keyedArrayPositionHints, keyedArrayReorderHints, keyedArrayRollingWindowHints) {
|
|
143
|
+
function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayRollingWindowHints) {
|
|
111
144
|
const features = /* @__PURE__ */ new Set();
|
|
112
145
|
let keyedRowsHaveConditionals = false;
|
|
113
146
|
let keyedRowsHaveHostBlocks = false;
|
|
@@ -124,7 +157,8 @@ function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHin
|
|
|
124
157
|
if (plans.some((plan) => plan.kind === "keyed-rows")) {
|
|
125
158
|
const keyedRowsFeature = keyedRowsHaveConditionals && keyedRowsHaveHostBlocks ? "keyed-rows-complete" : keyedRowsHaveConditionals ? "keyed-rows-conditional" : keyedRowsHaveHostBlocks ? "keyed-rows-host" : "keyed-rows";
|
|
126
159
|
const arrayRangeHints = keyedArrayRollingWindowHints || keyedArrayFilterHints || keyedArrayPrependHints;
|
|
127
|
-
const
|
|
160
|
+
const needsCombinedStructuralPrependRuntime = keyedArrayStructuralPrependHints && (keyedArrayStructuralAppendMapHints || keyedArrayStructuralAppendHints || keyedArrayWindowReplaceHints || keyedArrayBatchInsertHints || keyedArrayPositionHints || keyedArrayReorderHints || keyedArrayRollingWindowHints);
|
|
161
|
+
const hintSuffix = keyedArrayStructuralPrependMapHints ? "-structural-prepend-map-hinted" : needsCombinedStructuralPrependRuntime ? "-structural-prepend-hinted" : keyedArrayStructuralAppendMapHints ? "-structural-append-map-hinted" : keyedArrayStructuralAppendHints ? "-structural-append-hinted" : keyedArrayWindowReplaceHints ? arrayRangeHints || keyedArrayReorderHints ? "-window-every-hinted" : "-window-position-hinted" : keyedArrayBatchInsertHints ? arrayRangeHints || keyedArrayReorderHints ? "-batch-every-hinted" : "-batch-position-hinted" : keyedArrayPositionHints && (arrayRangeHints || keyedArrayReorderHints) || keyedArrayReorderHints && arrayRangeHints ? "-every-hinted" : keyedArrayRollingWindowHints ? "-all-hinted" : keyedArrayPositionHints ? "-position-hinted" : keyedArrayMapReorderHints && keyedRowsFeature === "keyed-rows" ? "-map-reorder-hinted" : keyedArrayReorderHints ? "-reorder-hinted" : keyedArrayFilterHints && keyedArrayPrependHints ? "-filter-prepend-hinted" : keyedArrayFilterHints ? "-filter-hinted" : keyedArrayPrependHints ? "-prepend-hinted" : keyedMapUpdateHints ? "-hinted" : "";
|
|
128
162
|
features.add(`${keyedRowsFeature}${hintSuffix}`);
|
|
129
163
|
}
|
|
130
164
|
return [...features].sort();
|
|
@@ -529,6 +563,22 @@ function isSafeKeyedMapResult(expression, item, safeGlobals) {
|
|
|
529
563
|
if (validateDerivedExpression(expression.test, safeGlobals)) return false;
|
|
530
564
|
return isUnchangedMapItem(expression.consequent, item) && isSafeKeyedMapReplacement(expression.alternate, item, safeGlobals) || isUnchangedMapItem(expression.alternate, item) && isSafeKeyedMapReplacement(expression.consequent, item, safeGlobals);
|
|
531
565
|
}
|
|
566
|
+
function keyedMapUpdatePipeline(expression, parameterName, safeGlobals) {
|
|
567
|
+
const outerCallbacks = [];
|
|
568
|
+
let current = expression;
|
|
569
|
+
while (core.types.isCallExpression(current) && current.arguments.length === 1 && core.types.isMemberExpression(current.callee) && !current.callee.computed && core.types.isIdentifier(current.callee.property, { name: "map" }) && core.types.isExpression(current.callee.object)) {
|
|
570
|
+
const callback = current.arguments[0];
|
|
571
|
+
if (!core.types.isArrowFunctionExpression(callback) || callback.async || callback.generator || callback.params.length === 0 || callback.params.length > 3 || callback.params.some((parameter) => !core.types.isIdentifier(parameter)) || !core.types.isExpression(callback.body) || !isSafeKeyedMapResult(callback.body, callback.params[0], safeGlobals)) {
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
outerCallbacks.push(callback);
|
|
575
|
+
current = current.callee.object;
|
|
576
|
+
}
|
|
577
|
+
if (!core.types.isIdentifier(current, { name: parameterName }) || outerCallbacks.length === 0) {
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
return outerCallbacks.reverse();
|
|
581
|
+
}
|
|
532
582
|
function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
533
583
|
if (hintedStateIndices.size === 0) return { root: core.types.cloneNode(root, true), count: 0 };
|
|
534
584
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
@@ -542,58 +592,50 @@ function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, he
|
|
|
542
592
|
return;
|
|
543
593
|
}
|
|
544
594
|
const updater = path.node.arguments[0];
|
|
545
|
-
if (!core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0]) || !core.types.
|
|
546
|
-
name: updater.params[0].name
|
|
547
|
-
}) || !core.types.isIdentifier(updater.body.callee.property, { name: "map" })) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
const callback = updater.body.arguments[0];
|
|
551
|
-
if (!core.types.isArrowFunctionExpression(callback) || callback.async || callback.generator || callback.params.length === 0 || callback.params.length > 3 || callback.params.some((parameter) => !core.types.isIdentifier(parameter)) || !core.types.isExpression(callback.body)) {
|
|
595
|
+
if (!core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0]) || !core.types.isExpression(updater.body)) {
|
|
552
596
|
return;
|
|
553
597
|
}
|
|
554
|
-
const
|
|
555
|
-
if (!
|
|
556
|
-
const changedIndices = path.scope.generateUidIdentifier("farmChangedIndices");
|
|
557
|
-
const mappedItem = path.scope.generateUidIdentifier("farmMappedItem");
|
|
558
|
-
const nextValue = path.scope.generateUidIdentifier("farmNextItems");
|
|
559
|
-
const index = core.types.isIdentifier(callback.params[1]) ? core.types.cloneNode(callback.params[1]) : path.scope.generateUidIdentifier("farmMapIndex");
|
|
560
|
-
const wrappedCallback = core.types.cloneNode(callback, true);
|
|
561
|
-
if (wrappedCallback.params.length === 1) wrappedCallback.params.push(core.types.cloneNode(index));
|
|
562
|
-
wrappedCallback.body = core.types.blockStatement([
|
|
563
|
-
core.types.variableDeclaration("const", [
|
|
564
|
-
core.types.variableDeclarator(core.types.cloneNode(mappedItem), core.types.cloneNode(callback.body, true))
|
|
565
|
-
]),
|
|
566
|
-
core.types.ifStatement(
|
|
567
|
-
core.types.binaryExpression("!==", core.types.cloneNode(mappedItem), core.types.cloneNode(item)),
|
|
568
|
-
core.types.expressionStatement(
|
|
569
|
-
core.types.callExpression(
|
|
570
|
-
core.types.memberExpression(core.types.cloneNode(changedIndices), core.types.identifier("push")),
|
|
571
|
-
[core.types.cloneNode(index)]
|
|
572
|
-
)
|
|
573
|
-
)
|
|
574
|
-
),
|
|
575
|
-
core.types.returnStatement(core.types.cloneNode(mappedItem))
|
|
576
|
-
]);
|
|
577
|
-
const mapCall = core.types.cloneNode(updater.body, true);
|
|
578
|
-
mapCall.arguments[0] = wrappedCallback;
|
|
598
|
+
const callbacks = keyedMapUpdatePipeline(updater.body, updater.params[0].name, safeGlobals);
|
|
599
|
+
if (!callbacks) return;
|
|
579
600
|
const previous = core.types.cloneNode(updater.params[0]);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
601
|
+
const pipelineValue = path.scope.generateUidIdentifier("farmMapValue");
|
|
602
|
+
const applyMap = path.scope.generateUidIdentifier("farmApplyMap");
|
|
603
|
+
const statements = [];
|
|
604
|
+
let current = core.types.cloneNode(pipelineValue);
|
|
605
|
+
for (let index = 0; index < callbacks.length; index += 1) {
|
|
606
|
+
const method = path.scope.generateUidIdentifier(`farmMap${index + 1}`);
|
|
607
|
+
const nextValue = path.scope.generateUidIdentifier(`farmMappedItems${index + 1}`);
|
|
608
|
+
statements.push(
|
|
583
609
|
core.types.variableDeclaration("const", [
|
|
584
|
-
core.types.variableDeclarator(
|
|
610
|
+
core.types.variableDeclarator(
|
|
611
|
+
core.types.cloneNode(method),
|
|
612
|
+
core.types.memberExpression(core.types.cloneNode(current), core.types.identifier("map"))
|
|
613
|
+
)
|
|
585
614
|
]),
|
|
586
|
-
core.types.variableDeclaration("const", [
|
|
587
|
-
|
|
588
|
-
core.types.callExpression(core.types.cloneNode(helperIdentifier), [
|
|
589
|
-
core.types.cloneNode(previous),
|
|
615
|
+
core.types.variableDeclaration("const", [
|
|
616
|
+
core.types.variableDeclarator(
|
|
590
617
|
core.types.cloneNode(nextValue),
|
|
591
|
-
core.types.cloneNode(
|
|
592
|
-
|
|
618
|
+
core.types.callExpression(core.types.cloneNode(applyMap), [
|
|
619
|
+
core.types.cloneNode(current),
|
|
620
|
+
core.types.cloneNode(method),
|
|
621
|
+
core.types.cloneNode(callbacks[index], true)
|
|
622
|
+
])
|
|
623
|
+
)
|
|
624
|
+
])
|
|
625
|
+
);
|
|
626
|
+
current = nextValue;
|
|
627
|
+
}
|
|
628
|
+
path.node.arguments[0] = core.types.arrowFunctionExpression(
|
|
629
|
+
[core.types.cloneNode(previous)],
|
|
630
|
+
core.types.callExpression(core.types.cloneNode(helperIdentifier), [
|
|
631
|
+
core.types.cloneNode(previous),
|
|
632
|
+
core.types.arrowFunctionExpression(
|
|
633
|
+
[core.types.cloneNode(pipelineValue), core.types.cloneNode(applyMap)],
|
|
634
|
+
core.types.blockStatement([...statements, core.types.returnStatement(core.types.cloneNode(current))])
|
|
593
635
|
)
|
|
594
636
|
])
|
|
595
637
|
);
|
|
596
|
-
count +=
|
|
638
|
+
count += callbacks.length;
|
|
597
639
|
path.skip();
|
|
598
640
|
}
|
|
599
641
|
});
|
|
@@ -766,8 +808,10 @@ function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesByS
|
|
|
766
808
|
}) || !core.types.isIdentifier(retainedSpread.argument.callee.property, { name: "slice" }) || !core.types.isExpression(retainedSpread.argument.arguments[0])) {
|
|
767
809
|
return;
|
|
768
810
|
}
|
|
769
|
-
const retainedStart =
|
|
770
|
-
if (retainedStart
|
|
811
|
+
const retainedStart = retainedSpread.argument.arguments[0];
|
|
812
|
+
if (validateKeyedArrayPositionExpression(retainedStart, safeGlobals) !== void 0 || staticSliceIndex(retainedStart) === 0) {
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
771
815
|
const safeIncomingValue = (value) => {
|
|
772
816
|
if (core.types.isArrayExpression(value)) {
|
|
773
817
|
return value.elements.every(
|
|
@@ -810,7 +854,7 @@ function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesByS
|
|
|
810
854
|
core.types.callExpression(core.types.cloneNode(sliceHelperIdentifier), [
|
|
811
855
|
core.types.cloneNode(previous),
|
|
812
856
|
core.types.cloneNode(sliceMethod),
|
|
813
|
-
core.types.
|
|
857
|
+
core.types.cloneNode(retainedStart, true)
|
|
814
858
|
])
|
|
815
859
|
),
|
|
816
860
|
core.types.variableDeclarator(core.types.cloneNode(nextValue), core.types.arrayExpression(nextElements))
|
|
@@ -852,13 +896,21 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
|
|
|
852
896
|
}
|
|
853
897
|
return validateDerivedExpression(expression, safeGlobals);
|
|
854
898
|
}
|
|
855
|
-
function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
899
|
+
function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
|
|
856
900
|
if (hintedStateIndices.size === 0) {
|
|
857
|
-
return {
|
|
901
|
+
return {
|
|
902
|
+
root: core.types.cloneNode(root, true),
|
|
903
|
+
count: 0,
|
|
904
|
+
batchInsertCount: 0,
|
|
905
|
+
windowReplaceCount: 0,
|
|
906
|
+
stateIndices: /* @__PURE__ */ new Set()
|
|
907
|
+
};
|
|
858
908
|
}
|
|
859
909
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
860
910
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
861
911
|
let count = 0;
|
|
912
|
+
let batchInsertCount = 0;
|
|
913
|
+
let windowReplaceCount = 0;
|
|
862
914
|
core.traverse(file, {
|
|
863
915
|
CallExpression(path) {
|
|
864
916
|
const callee = path.get("callee");
|
|
@@ -873,11 +925,19 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
873
925
|
}
|
|
874
926
|
const methodName = updater.body.callee.property.name;
|
|
875
927
|
const args = updater.body.arguments;
|
|
876
|
-
const
|
|
928
|
+
const deleteCountExpression = methodName === "toSpliced" && args.length >= 2 && core.types.isExpression(args[1]) ? args[1] : void 0;
|
|
929
|
+
const toSplicedDeleteCount = deleteCountExpression ? staticSliceIndex(deleteCountExpression) : void 0;
|
|
930
|
+
const hasRuntimeDeleteCount = deleteCountExpression !== void 0 && toSplicedDeleteCount === void 0 && validateKeyedArrayPositionExpression(deleteCountExpression, safeGlobals) === void 0;
|
|
931
|
+
const isBatchInsert = methodName === "toSpliced" && args.length >= 3 && core.types.isNumericLiteral(args[1], { value: 0 }) && (args.length > 3 || core.types.isSpreadElement(args[2]));
|
|
932
|
+
const isWindowReplace = methodName === "toSpliced" && (args.length >= 3 && toSplicedDeleteCount !== void 0 && Number.isSafeInteger(toSplicedDeleteCount) && toSplicedDeleteCount > 0 && (toSplicedDeleteCount !== 1 || args.length > 3 || core.types.isSpreadElement(args[2])) || hasRuntimeDeleteCount);
|
|
933
|
+
const kind = isBatchInsert ? "batch-insert" : isWindowReplace ? "window-replace" : methodName === "with" && args.length === 2 ? "replace" : methodName === "toSpliced" && args.length === 3 && core.types.isNumericLiteral(args[1], { value: 0 }) ? "insert" : methodName === "toSpliced" && args.length === 3 && core.types.isNumericLiteral(args[1], { value: 1 }) ? "replace" : args.length === 2 && toSplicedDeleteCount !== void 0 && Number.isSafeInteger(toSplicedDeleteCount) && toSplicedDeleteCount > 0 ? "remove" : void 0;
|
|
877
934
|
if (!kind || !core.types.isExpression(args[0])) return;
|
|
878
935
|
const position = args[0];
|
|
879
|
-
const
|
|
880
|
-
if (validateKeyedArrayPositionExpression(position, safeGlobals) !== void 0 ||
|
|
936
|
+
const incoming = kind === "batch-insert" || kind === "window-replace" ? args.slice(2) : [args.at(-1)];
|
|
937
|
+
if (validateKeyedArrayPositionExpression(position, safeGlobals) !== void 0 || kind === "window-replace" && (!deleteCountExpression || validateKeyedArrayPositionExpression(deleteCountExpression, safeGlobals) !== void 0) || kind !== "remove" && incoming.some((item) => {
|
|
938
|
+
const expression = core.types.isSpreadElement(item) ? item.argument : item;
|
|
939
|
+
return !expression || !core.types.isExpression(expression) || validateDerivedExpression(expression, safeGlobals) !== void 0;
|
|
940
|
+
})) {
|
|
881
941
|
return;
|
|
882
942
|
}
|
|
883
943
|
const previous = core.types.cloneNode(updater.params[0]);
|
|
@@ -894,7 +954,18 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
894
954
|
)
|
|
895
955
|
]),
|
|
896
956
|
core.types.returnStatement(
|
|
897
|
-
core.types.callExpression(core.types.cloneNode(
|
|
957
|
+
kind === "batch-insert" ? core.types.callExpression(core.types.cloneNode(batchInsertHelperIdentifier), [
|
|
958
|
+
core.types.cloneNode(previous),
|
|
959
|
+
core.types.cloneNode(method),
|
|
960
|
+
core.types.cloneNode(position, true),
|
|
961
|
+
...args.slice(2).map((argument) => core.types.cloneNode(argument, true))
|
|
962
|
+
]) : kind === "window-replace" ? core.types.callExpression(core.types.cloneNode(windowReplaceHelperIdentifier), [
|
|
963
|
+
core.types.cloneNode(previous),
|
|
964
|
+
core.types.cloneNode(method),
|
|
965
|
+
core.types.cloneNode(position, true),
|
|
966
|
+
core.types.cloneNode(args[1], true),
|
|
967
|
+
...args.slice(2).map((argument) => core.types.cloneNode(argument, true))
|
|
968
|
+
]) : core.types.callExpression(core.types.cloneNode(helperIdentifier), [
|
|
898
969
|
core.types.cloneNode(previous),
|
|
899
970
|
core.types.cloneNode(method),
|
|
900
971
|
core.types.stringLiteral(kind),
|
|
@@ -904,6 +975,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
904
975
|
])
|
|
905
976
|
);
|
|
906
977
|
count += 1;
|
|
978
|
+
if (kind === "batch-insert") batchInsertCount += 1;
|
|
979
|
+
if (kind === "window-replace") windowReplaceCount += 1;
|
|
907
980
|
stateIndices.add(state.index);
|
|
908
981
|
path.skip();
|
|
909
982
|
}
|
|
@@ -911,6 +984,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
911
984
|
return {
|
|
912
985
|
root: file.program.body[0].expression,
|
|
913
986
|
count,
|
|
987
|
+
batchInsertCount,
|
|
988
|
+
windowReplaceCount,
|
|
914
989
|
stateIndices
|
|
915
990
|
};
|
|
916
991
|
}
|
|
@@ -933,34 +1008,976 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
|
|
|
933
1008
|
if (!core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0]) || !core.types.isCallExpression(updater.body) || updater.body.arguments.length !== 0 || !core.types.isMemberExpression(updater.body.callee) || updater.body.callee.computed || !core.types.isIdentifier(updater.body.callee.object, { name: updater.params[0].name }) || !core.types.isIdentifier(updater.body.callee.property, { name: "toReversed" })) {
|
|
934
1009
|
return;
|
|
935
1010
|
}
|
|
936
|
-
const previous = core.types.cloneNode(updater.params[0]);
|
|
937
|
-
const method = path.scope.generateUidIdentifier("farmToReversed");
|
|
938
|
-
path.node.arguments[0] = core.types.arrowFunctionExpression(
|
|
939
|
-
[core.types.cloneNode(previous)],
|
|
940
|
-
core.types.blockStatement([
|
|
941
|
-
core.types.variableDeclaration("const", [
|
|
942
|
-
core.types.variableDeclarator(
|
|
943
|
-
core.types.cloneNode(method),
|
|
944
|
-
core.types.memberExpression(core.types.cloneNode(previous), core.types.identifier("toReversed"))
|
|
945
|
-
)
|
|
946
|
-
]),
|
|
947
|
-
core.types.returnStatement(
|
|
948
|
-
core.types.callExpression(core.types.cloneNode(helperIdentifier), [
|
|
949
|
-
core.types.cloneNode(previous),
|
|
950
|
-
core.types.cloneNode(method)
|
|
951
|
-
])
|
|
952
|
-
)
|
|
953
|
-
])
|
|
954
|
-
);
|
|
955
|
-
count += 1;
|
|
956
|
-
stateIndices.add(state.index);
|
|
957
|
-
path.skip();
|
|
1011
|
+
const previous = core.types.cloneNode(updater.params[0]);
|
|
1012
|
+
const method = path.scope.generateUidIdentifier("farmToReversed");
|
|
1013
|
+
path.node.arguments[0] = core.types.arrowFunctionExpression(
|
|
1014
|
+
[core.types.cloneNode(previous)],
|
|
1015
|
+
core.types.blockStatement([
|
|
1016
|
+
core.types.variableDeclaration("const", [
|
|
1017
|
+
core.types.variableDeclarator(
|
|
1018
|
+
core.types.cloneNode(method),
|
|
1019
|
+
core.types.memberExpression(core.types.cloneNode(previous), core.types.identifier("toReversed"))
|
|
1020
|
+
)
|
|
1021
|
+
]),
|
|
1022
|
+
core.types.returnStatement(
|
|
1023
|
+
core.types.callExpression(core.types.cloneNode(helperIdentifier), [
|
|
1024
|
+
core.types.cloneNode(previous),
|
|
1025
|
+
core.types.cloneNode(method)
|
|
1026
|
+
])
|
|
1027
|
+
)
|
|
1028
|
+
])
|
|
1029
|
+
);
|
|
1030
|
+
count += 1;
|
|
1031
|
+
stateIndices.add(state.index);
|
|
1032
|
+
path.skip();
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
return {
|
|
1036
|
+
root: file.program.body[0].expression,
|
|
1037
|
+
count,
|
|
1038
|
+
stateIndices
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
|
|
1042
|
+
const outerSteps = [];
|
|
1043
|
+
let current = expression;
|
|
1044
|
+
while (core.types.isCallExpression(current) && core.types.isMemberExpression(current.callee) && !current.callee.computed && core.types.isIdentifier(current.callee.property) && core.types.isExpression(current.callee.object)) {
|
|
1045
|
+
const methodName = current.callee.property.name;
|
|
1046
|
+
if (methodName === "map") {
|
|
1047
|
+
if (current.arguments.length !== 1) return void 0;
|
|
1048
|
+
const callback = current.arguments[0];
|
|
1049
|
+
if (!core.types.isArrowFunctionExpression(callback) || callback.async || callback.generator || callback.params.length === 0 || callback.params.length > 3 || callback.params.some((parameter) => !core.types.isIdentifier(parameter)) || !core.types.isExpression(callback.body) || !isSafeKeyedMapResult(callback.body, callback.params[0], safeGlobals)) {
|
|
1050
|
+
return void 0;
|
|
1051
|
+
}
|
|
1052
|
+
outerSteps.push({ callback, kind: "map" });
|
|
1053
|
+
} else if (methodName === "filter") {
|
|
1054
|
+
if (current.arguments.length !== 1) return void 0;
|
|
1055
|
+
const predicate = current.arguments[0];
|
|
1056
|
+
if (!core.types.isArrowFunctionExpression(predicate) || predicate.async || predicate.generator || predicate.params.length !== 1 || !core.types.isIdentifier(predicate.params[0]) || !core.types.isExpression(predicate.body) || validateDerivedExpression(predicate.body, safeGlobals)) {
|
|
1057
|
+
return void 0;
|
|
1058
|
+
}
|
|
1059
|
+
outerSteps.push({ kind: "filter", predicate });
|
|
1060
|
+
} else if (methodName === "slice") {
|
|
1061
|
+
if (current.arguments.length < 1 || current.arguments.length > 2) return void 0;
|
|
1062
|
+
const bounds = [];
|
|
1063
|
+
for (const argument of current.arguments) {
|
|
1064
|
+
if (!core.types.isExpression(argument)) return void 0;
|
|
1065
|
+
if (validateKeyedArrayPositionExpression(argument, safeGlobals) !== void 0) {
|
|
1066
|
+
return void 0;
|
|
1067
|
+
}
|
|
1068
|
+
bounds.push(argument);
|
|
1069
|
+
}
|
|
1070
|
+
if (bounds.length === 1 && staticSliceIndex(bounds[0]) === 0) return void 0;
|
|
1071
|
+
outerSteps.push({ bounds, kind: "slice" });
|
|
1072
|
+
} else if (methodName === "toReversed") {
|
|
1073
|
+
if (current.arguments.length !== 0) return void 0;
|
|
1074
|
+
outerSteps.push({ kind: "reverse" });
|
|
1075
|
+
} else if (methodName === "toSorted") {
|
|
1076
|
+
if (current.arguments.length > 1) return void 0;
|
|
1077
|
+
const comparator = current.arguments[0];
|
|
1078
|
+
if (comparator && !core.types.isArrowFunctionExpression(comparator) && !core.types.isFunctionExpression(comparator)) {
|
|
1079
|
+
return void 0;
|
|
1080
|
+
}
|
|
1081
|
+
if (comparator && validateCollectionCallback(comparator, "toSorted", safeGlobals)) {
|
|
1082
|
+
return void 0;
|
|
1083
|
+
}
|
|
1084
|
+
outerSteps.push({ kind: "sort", ...comparator ? { comparator } : {} });
|
|
1085
|
+
} else {
|
|
1086
|
+
return void 0;
|
|
1087
|
+
}
|
|
1088
|
+
current = current.callee.object;
|
|
1089
|
+
}
|
|
1090
|
+
if (!core.types.isIdentifier(current, { name: parameterName }) || outerSteps.length < 2) {
|
|
1091
|
+
return void 0;
|
|
1092
|
+
}
|
|
1093
|
+
const steps = outerSteps.reverse();
|
|
1094
|
+
let mapSteps = 0;
|
|
1095
|
+
let structuralSteps = 0;
|
|
1096
|
+
let reorderSteps = 0;
|
|
1097
|
+
let reachedReorder = false;
|
|
1098
|
+
for (const step of steps) {
|
|
1099
|
+
if (step.kind === "map") {
|
|
1100
|
+
if (reachedReorder && structuralSteps > 0) return void 0;
|
|
1101
|
+
mapSteps += 1;
|
|
1102
|
+
} else if (step.kind === "filter" || step.kind === "slice") {
|
|
1103
|
+
if (reachedReorder) return void 0;
|
|
1104
|
+
structuralSteps += 1;
|
|
1105
|
+
} else {
|
|
1106
|
+
reachedReorder = true;
|
|
1107
|
+
reorderSteps += 1;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
if (reorderSteps < 1) {
|
|
1111
|
+
return structuralSteps > 0 && mapSteps > 0 ? steps : void 0;
|
|
1112
|
+
}
|
|
1113
|
+
if (mapSteps > 0 && reorderSteps >= 1) return steps;
|
|
1114
|
+
if (structuralSteps < 1 && reorderSteps < 2) return void 0;
|
|
1115
|
+
return steps;
|
|
1116
|
+
}
|
|
1117
|
+
function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesBySetter, filterHelperIdentifier, mapHelperIdentifier, mapReorderHelperIdentifier, mappedStructuralHelperIdentifier, reorderHelperIdentifier, structuralReorderHelperIdentifier, sliceHelperIdentifier, sortHelperIdentifier, structuralSortHelperIdentifier, safeGlobals, allowMapPipelines) {
|
|
1118
|
+
if (hintedStateIndices.size === 0) {
|
|
1119
|
+
return {
|
|
1120
|
+
root: core.types.cloneNode(root, true),
|
|
1121
|
+
filterCount: 0,
|
|
1122
|
+
mapCount: 0,
|
|
1123
|
+
mapReorderCount: 0,
|
|
1124
|
+
mapSortCount: 0,
|
|
1125
|
+
reorderCount: 0,
|
|
1126
|
+
sliceCount: 0,
|
|
1127
|
+
sortCount: 0,
|
|
1128
|
+
structuralReorderCount: 0,
|
|
1129
|
+
terminalStructuralPipelineCount: 0,
|
|
1130
|
+
structuralSortCount: 0,
|
|
1131
|
+
stateIndices: /* @__PURE__ */ new Set()
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1135
|
+
const stateIndices = /* @__PURE__ */ new Set();
|
|
1136
|
+
let filterCount = 0;
|
|
1137
|
+
let mapCount = 0;
|
|
1138
|
+
let mapReorderCount = 0;
|
|
1139
|
+
let mapSortCount = 0;
|
|
1140
|
+
let reorderCount = 0;
|
|
1141
|
+
let sliceCount = 0;
|
|
1142
|
+
let sortCount = 0;
|
|
1143
|
+
let structuralReorderCount = 0;
|
|
1144
|
+
let terminalStructuralPipelineCount = 0;
|
|
1145
|
+
let structuralSortCount = 0;
|
|
1146
|
+
core.traverse(file, {
|
|
1147
|
+
CallExpression(path) {
|
|
1148
|
+
const callee = path.get("callee");
|
|
1149
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name)) return;
|
|
1150
|
+
const state = statesBySetter.get(callee.node.name);
|
|
1151
|
+
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
const updater = path.node.arguments[0];
|
|
1155
|
+
if (!core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0]) || !core.types.isExpression(updater.body)) {
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
const steps = keyedArrayReorderPipeline(updater.body, updater.params[0].name, safeGlobals);
|
|
1159
|
+
if (!steps) return;
|
|
1160
|
+
const structuralPipeline = steps.some(
|
|
1161
|
+
(step) => step.kind === "filter" || step.kind === "slice"
|
|
1162
|
+
);
|
|
1163
|
+
const mapPipeline = steps.some((step) => step.kind === "map");
|
|
1164
|
+
if (mapPipeline && !allowMapPipelines) return;
|
|
1165
|
+
const terminalStructuralPipeline = mapPipeline && structuralPipeline && steps.every((step) => step.kind !== "reverse" && step.kind !== "sort");
|
|
1166
|
+
const previous = core.types.cloneNode(updater.params[0]);
|
|
1167
|
+
const statements = [];
|
|
1168
|
+
let value = core.types.cloneNode(previous);
|
|
1169
|
+
let hasMappedLineage = false;
|
|
1170
|
+
for (let stepIndex = 0; stepIndex < steps.length; stepIndex += 1) {
|
|
1171
|
+
const step = steps[stepIndex];
|
|
1172
|
+
if (step.kind === "map") {
|
|
1173
|
+
let mapEnd = stepIndex + 1;
|
|
1174
|
+
while (steps[mapEnd]?.kind === "map") mapEnd += 1;
|
|
1175
|
+
if (mapEnd - stepIndex > 1) {
|
|
1176
|
+
const pipelineValue = path.scope.generateUidIdentifier("farmMapValue");
|
|
1177
|
+
const applyMap = path.scope.generateUidIdentifier("farmApplyMap");
|
|
1178
|
+
const pipelineStatements = [];
|
|
1179
|
+
let current = core.types.cloneNode(pipelineValue);
|
|
1180
|
+
for (let mapIndex = stepIndex; mapIndex < mapEnd; mapIndex += 1) {
|
|
1181
|
+
const mapStep = steps[mapIndex];
|
|
1182
|
+
if (mapStep.kind !== "map") break;
|
|
1183
|
+
const method2 = path.scope.generateUidIdentifier(`farmMap${mapIndex + 1}`);
|
|
1184
|
+
const result3 = path.scope.generateUidIdentifier(`farmMappedItems${mapIndex + 1}`);
|
|
1185
|
+
pipelineStatements.push(
|
|
1186
|
+
core.types.variableDeclaration("const", [
|
|
1187
|
+
core.types.variableDeclarator(
|
|
1188
|
+
core.types.cloneNode(method2),
|
|
1189
|
+
core.types.memberExpression(core.types.cloneNode(current), core.types.identifier("map"))
|
|
1190
|
+
)
|
|
1191
|
+
]),
|
|
1192
|
+
core.types.variableDeclaration("const", [
|
|
1193
|
+
core.types.variableDeclarator(
|
|
1194
|
+
core.types.cloneNode(result3),
|
|
1195
|
+
core.types.callExpression(core.types.cloneNode(applyMap), [
|
|
1196
|
+
core.types.cloneNode(current),
|
|
1197
|
+
core.types.cloneNode(method2),
|
|
1198
|
+
core.types.cloneNode(mapStep.callback, true)
|
|
1199
|
+
])
|
|
1200
|
+
)
|
|
1201
|
+
])
|
|
1202
|
+
);
|
|
1203
|
+
current = core.types.cloneNode(result3);
|
|
1204
|
+
}
|
|
1205
|
+
const result2 = path.scope.generateUidIdentifier("farmPipelineValue");
|
|
1206
|
+
statements.push(
|
|
1207
|
+
core.types.variableDeclaration("const", [
|
|
1208
|
+
core.types.variableDeclarator(
|
|
1209
|
+
core.types.cloneNode(result2),
|
|
1210
|
+
core.types.callExpression(core.types.cloneNode(mapHelperIdentifier), [
|
|
1211
|
+
core.types.cloneNode(value),
|
|
1212
|
+
core.types.arrowFunctionExpression(
|
|
1213
|
+
[core.types.cloneNode(pipelineValue), core.types.cloneNode(applyMap)],
|
|
1214
|
+
core.types.blockStatement([
|
|
1215
|
+
...pipelineStatements,
|
|
1216
|
+
core.types.returnStatement(core.types.cloneNode(current))
|
|
1217
|
+
])
|
|
1218
|
+
)
|
|
1219
|
+
])
|
|
1220
|
+
)
|
|
1221
|
+
])
|
|
1222
|
+
);
|
|
1223
|
+
value = core.types.cloneNode(result2);
|
|
1224
|
+
mapCount += mapEnd - stepIndex;
|
|
1225
|
+
hasMappedLineage = true;
|
|
1226
|
+
stepIndex = mapEnd - 1;
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
const methodName = step.kind === "map" ? "map" : step.kind === "filter" ? "filter" : step.kind === "slice" ? "slice" : step.kind === "reverse" ? "toReversed" : "toSorted";
|
|
1231
|
+
const method = path.scope.generateUidIdentifier(
|
|
1232
|
+
step.kind === "filter" ? "farmFilter" : step.kind === "map" ? "farmMap" : step.kind === "slice" ? "farmSlice" : step.kind === "reverse" ? "farmToReversed" : "farmToSorted"
|
|
1233
|
+
);
|
|
1234
|
+
const result = path.scope.generateUidIdentifier("farmPipelineValue");
|
|
1235
|
+
const helper = step.kind === "map" ? mapHelperIdentifier : step.kind === "filter" ? filterHelperIdentifier : step.kind === "slice" ? sliceHelperIdentifier : step.kind === "reverse" ? structuralPipeline ? structuralReorderHelperIdentifier : hasMappedLineage ? mapReorderHelperIdentifier : reorderHelperIdentifier : structuralPipeline ? structuralSortHelperIdentifier : hasMappedLineage ? mapReorderHelperIdentifier : sortHelperIdentifier;
|
|
1236
|
+
const args = step.kind === "map" ? [core.types.cloneNode(step.callback, true)] : step.kind === "filter" ? [core.types.cloneNode(step.predicate, true)] : step.kind === "slice" ? step.bounds.map((bound) => core.types.cloneNode(bound, true)) : step.kind === "sort" && step.comparator ? [core.types.cloneNode(step.comparator, true)] : [];
|
|
1237
|
+
statements.push(
|
|
1238
|
+
core.types.variableDeclaration("const", [
|
|
1239
|
+
core.types.variableDeclarator(
|
|
1240
|
+
core.types.cloneNode(method),
|
|
1241
|
+
core.types.memberExpression(core.types.cloneNode(value), core.types.identifier(methodName))
|
|
1242
|
+
)
|
|
1243
|
+
]),
|
|
1244
|
+
core.types.variableDeclaration("const", [
|
|
1245
|
+
core.types.variableDeclarator(
|
|
1246
|
+
core.types.cloneNode(result),
|
|
1247
|
+
core.types.callExpression(core.types.cloneNode(helper), [
|
|
1248
|
+
core.types.cloneNode(value),
|
|
1249
|
+
core.types.cloneNode(method),
|
|
1250
|
+
...args
|
|
1251
|
+
])
|
|
1252
|
+
)
|
|
1253
|
+
])
|
|
1254
|
+
);
|
|
1255
|
+
value = core.types.cloneNode(result);
|
|
1256
|
+
if (step.kind === "map") {
|
|
1257
|
+
mapCount += 1;
|
|
1258
|
+
hasMappedLineage = true;
|
|
1259
|
+
} else if (step.kind === "filter") filterCount += 1;
|
|
1260
|
+
else if (step.kind === "slice") sliceCount += 1;
|
|
1261
|
+
else if (step.kind === "reverse") {
|
|
1262
|
+
reorderCount += 1;
|
|
1263
|
+
if (hasMappedLineage && !structuralPipeline) mapReorderCount += 1;
|
|
1264
|
+
if (structuralPipeline) structuralReorderCount += 1;
|
|
1265
|
+
} else {
|
|
1266
|
+
sortCount += 1;
|
|
1267
|
+
if (hasMappedLineage && !structuralPipeline) mapSortCount += 1;
|
|
1268
|
+
if (structuralPipeline) structuralSortCount += 1;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
statements.push(
|
|
1272
|
+
core.types.returnStatement(
|
|
1273
|
+
terminalStructuralPipeline ? core.types.callExpression(core.types.cloneNode(mappedStructuralHelperIdentifier), [core.types.cloneNode(value)]) : core.types.cloneNode(value)
|
|
1274
|
+
)
|
|
1275
|
+
);
|
|
1276
|
+
if (terminalStructuralPipeline) terminalStructuralPipelineCount += 1;
|
|
1277
|
+
path.node.arguments[0] = core.types.arrowFunctionExpression(
|
|
1278
|
+
[core.types.cloneNode(previous)],
|
|
1279
|
+
core.types.blockStatement(statements)
|
|
1280
|
+
);
|
|
1281
|
+
stateIndices.add(state.index);
|
|
1282
|
+
path.skip();
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
return {
|
|
1286
|
+
root: file.program.body[0].expression,
|
|
1287
|
+
filterCount,
|
|
1288
|
+
mapCount,
|
|
1289
|
+
mapReorderCount,
|
|
1290
|
+
mapSortCount,
|
|
1291
|
+
reorderCount,
|
|
1292
|
+
sliceCount,
|
|
1293
|
+
sortCount,
|
|
1294
|
+
structuralReorderCount,
|
|
1295
|
+
terminalStructuralPipelineCount,
|
|
1296
|
+
structuralSortCount,
|
|
1297
|
+
stateIndices
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
function rewriteQueuedKeyedArrayReorderMapHints(root, statesBySetter, mapUpdateIdentifier, queuedMapPipelineIdentifier, mapReorderIdentifier, reorderIdentifier, sortIdentifier, structuralReorderIdentifier, structuralSortIdentifier, allowed) {
|
|
1301
|
+
if (!allowed) return { root: core.types.cloneNode(root, true), mapCount: 0 };
|
|
1302
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1303
|
+
let mapCount = 0;
|
|
1304
|
+
const containsHelperCall = (updater, helperNames) => {
|
|
1305
|
+
let found = false;
|
|
1306
|
+
core.types.traverseFast(updater.body, (node) => {
|
|
1307
|
+
if (!found && core.types.isCallExpression(node) && core.types.isIdentifier(node.callee) && helperNames.has(node.callee.name)) {
|
|
1308
|
+
found = true;
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
return found;
|
|
1312
|
+
};
|
|
1313
|
+
const reorderHelperNames = /* @__PURE__ */ new Set([
|
|
1314
|
+
mapReorderIdentifier.name,
|
|
1315
|
+
reorderIdentifier.name,
|
|
1316
|
+
sortIdentifier.name
|
|
1317
|
+
]);
|
|
1318
|
+
const structuralHelperNames = /* @__PURE__ */ new Set([
|
|
1319
|
+
structuralReorderIdentifier.name,
|
|
1320
|
+
structuralSortIdentifier.name
|
|
1321
|
+
]);
|
|
1322
|
+
core.traverse(file, {
|
|
1323
|
+
BlockStatement(path) {
|
|
1324
|
+
let queuedReorderState;
|
|
1325
|
+
const statements = path.get("body");
|
|
1326
|
+
for (const statementPath of statements) {
|
|
1327
|
+
const statement = statementPath.node;
|
|
1328
|
+
if (!core.types.isExpressionStatement(statement) || !core.types.isCallExpression(statement.expression)) {
|
|
1329
|
+
queuedReorderState = void 0;
|
|
1330
|
+
continue;
|
|
1331
|
+
}
|
|
1332
|
+
const setterCall = statement.expression;
|
|
1333
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1334
|
+
queuedReorderState = void 0;
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const state = statesBySetter.get(setterCall.callee.name);
|
|
1338
|
+
const updater = setterCall.arguments[0];
|
|
1339
|
+
if (!state || !core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0])) {
|
|
1340
|
+
queuedReorderState = void 0;
|
|
1341
|
+
continue;
|
|
1342
|
+
}
|
|
1343
|
+
if (containsHelperCall(updater, reorderHelperNames) && !containsHelperCall(updater, structuralHelperNames)) {
|
|
1344
|
+
queuedReorderState = state.index;
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
if (queuedReorderState !== state.index || !core.types.isCallExpression(updater.body) || !core.types.isIdentifier(updater.body.callee, { name: mapUpdateIdentifier.name }) || updater.body.arguments.length !== 2) {
|
|
1348
|
+
queuedReorderState = void 0;
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
const pipeline = updater.body.arguments[1];
|
|
1352
|
+
if (!core.types.isArrowFunctionExpression(pipeline) || pipeline.params.length !== 2 || !core.types.isIdentifier(pipeline.params[1])) {
|
|
1353
|
+
queuedReorderState = void 0;
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
let pipelineMapCount = 0;
|
|
1357
|
+
const applyMapName = pipeline.params[1].name;
|
|
1358
|
+
core.types.traverseFast(pipeline.body, (node) => {
|
|
1359
|
+
if (core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: applyMapName })) {
|
|
1360
|
+
pipelineMapCount += 1;
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
if (pipelineMapCount === 0) {
|
|
1364
|
+
queuedReorderState = void 0;
|
|
1365
|
+
continue;
|
|
1366
|
+
}
|
|
1367
|
+
updater.body.callee = core.types.cloneNode(queuedMapPipelineIdentifier);
|
|
1368
|
+
mapCount += pipelineMapCount;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
return {
|
|
1373
|
+
root: file.program.body[0].expression,
|
|
1374
|
+
mapCount
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
function countKeyedArrayMapPipeline(updater, mapUpdateIdentifier) {
|
|
1378
|
+
if (!core.types.isCallExpression(updater.body) || !core.types.isIdentifier(updater.body.callee, { name: mapUpdateIdentifier.name }) || updater.body.arguments.length !== 2) {
|
|
1379
|
+
return 0;
|
|
1380
|
+
}
|
|
1381
|
+
const pipeline = updater.body.arguments[1];
|
|
1382
|
+
if (!core.types.isArrowFunctionExpression(pipeline) || pipeline.params.length !== 2 || !core.types.isIdentifier(pipeline.params[1])) {
|
|
1383
|
+
return 0;
|
|
1384
|
+
}
|
|
1385
|
+
const applyMapName = pipeline.params[1].name;
|
|
1386
|
+
let count = 0;
|
|
1387
|
+
core.types.traverseFast(pipeline.body, (node) => {
|
|
1388
|
+
if (core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: applyMapName })) {
|
|
1389
|
+
count += 1;
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
return count;
|
|
1393
|
+
}
|
|
1394
|
+
function rewriteQueuedKeyedArrayMappedStructuralHints(root, statesBySetter, mapUpdateIdentifier, queuedMapPipelineIdentifier, mappedStructuralIdentifier, filterIdentifier, sliceIdentifier, allowed) {
|
|
1395
|
+
if (!allowed) {
|
|
1396
|
+
return {
|
|
1397
|
+
root: core.types.cloneNode(root, true),
|
|
1398
|
+
mapCount: 0,
|
|
1399
|
+
structuralCount: 0,
|
|
1400
|
+
stateIndices: /* @__PURE__ */ new Set()
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1404
|
+
let mapCount = 0;
|
|
1405
|
+
let structuralCount = 0;
|
|
1406
|
+
const stateIndices = /* @__PURE__ */ new Set();
|
|
1407
|
+
const terminalStructuralReturn = (updater) => {
|
|
1408
|
+
if (!core.types.isBlockStatement(updater.body)) return void 0;
|
|
1409
|
+
const statement = updater.body.body.at(-1);
|
|
1410
|
+
if (!core.types.isReturnStatement(statement) || !statement.argument || !core.types.isCallExpression(statement.argument) || !core.types.isIdentifier(statement.argument.callee) || statement.argument.callee.name !== filterIdentifier.name && statement.argument.callee.name !== sliceIdentifier.name) {
|
|
1411
|
+
return void 0;
|
|
1412
|
+
}
|
|
1413
|
+
return statement;
|
|
1414
|
+
};
|
|
1415
|
+
core.traverse(file, {
|
|
1416
|
+
BlockStatement(path) {
|
|
1417
|
+
let mappedStructuralState;
|
|
1418
|
+
let pendingMaps = [];
|
|
1419
|
+
const statements = path.get("body");
|
|
1420
|
+
for (const statementPath of statements) {
|
|
1421
|
+
const statement = statementPath.node;
|
|
1422
|
+
if (!core.types.isExpressionStatement(statement) || !core.types.isCallExpression(statement.expression)) {
|
|
1423
|
+
mappedStructuralState = void 0;
|
|
1424
|
+
pendingMaps = [];
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
const setterCall = statement.expression;
|
|
1428
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1429
|
+
mappedStructuralState = void 0;
|
|
1430
|
+
pendingMaps = [];
|
|
1431
|
+
continue;
|
|
1432
|
+
}
|
|
1433
|
+
const state = statesBySetter.get(setterCall.callee.name);
|
|
1434
|
+
const updater = setterCall.arguments[0];
|
|
1435
|
+
if (!state || !core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0])) {
|
|
1436
|
+
mappedStructuralState = void 0;
|
|
1437
|
+
pendingMaps = [];
|
|
1438
|
+
continue;
|
|
1439
|
+
}
|
|
1440
|
+
const pipelineMapCount = countKeyedArrayMapPipeline(updater, mapUpdateIdentifier);
|
|
1441
|
+
if (pipelineMapCount > 0) {
|
|
1442
|
+
if (mappedStructuralState !== void 0) {
|
|
1443
|
+
mappedStructuralState = void 0;
|
|
1444
|
+
pendingMaps = [];
|
|
1445
|
+
continue;
|
|
1446
|
+
}
|
|
1447
|
+
const candidate = {
|
|
1448
|
+
count: pipelineMapCount,
|
|
1449
|
+
stateIndex: state.index,
|
|
1450
|
+
updater
|
|
1451
|
+
};
|
|
1452
|
+
pendingMaps = pendingMaps[0]?.stateIndex === state.index ? [...pendingMaps, candidate] : [candidate];
|
|
1453
|
+
continue;
|
|
1454
|
+
}
|
|
1455
|
+
const structuralReturn = terminalStructuralReturn(updater);
|
|
1456
|
+
const hasPendingMaps = pendingMaps.length > 0 && pendingMaps[0].stateIndex === state.index;
|
|
1457
|
+
if (!structuralReturn || !hasPendingMaps && mappedStructuralState !== state.index) {
|
|
1458
|
+
mappedStructuralState = void 0;
|
|
1459
|
+
pendingMaps = [];
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
if (hasPendingMaps) {
|
|
1463
|
+
for (const candidate of pendingMaps) {
|
|
1464
|
+
candidate.updater.body.callee = core.types.cloneNode(queuedMapPipelineIdentifier);
|
|
1465
|
+
mapCount += candidate.count;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
const structuralValue = structuralReturn.argument;
|
|
1469
|
+
if (!core.types.isExpression(structuralValue)) {
|
|
1470
|
+
mappedStructuralState = void 0;
|
|
1471
|
+
pendingMaps = [];
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
structuralReturn.argument = core.types.callExpression(core.types.cloneNode(mappedStructuralIdentifier), [
|
|
1475
|
+
core.types.cloneNode(structuralValue)
|
|
1476
|
+
]);
|
|
1477
|
+
structuralCount += 1;
|
|
1478
|
+
stateIndices.add(state.index);
|
|
1479
|
+
mappedStructuralState = state.index;
|
|
1480
|
+
pendingMaps = [];
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
return {
|
|
1485
|
+
root: file.program.body[0].expression,
|
|
1486
|
+
mapCount,
|
|
1487
|
+
structuralCount,
|
|
1488
|
+
stateIndices
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
function rewriteQueuedKeyedArrayStructuralMapHints(root, statesBySetter, mapUpdateIdentifier, mapPipelineIdentifier, appendIdentifier, mappedStructuralAppendIdentifier, structuralAppendMapPipelineIdentifier, filterIdentifier, sliceIdentifier, mappedStructuralIdentifier, allowed) {
|
|
1492
|
+
if (!allowed) {
|
|
1493
|
+
return {
|
|
1494
|
+
root: core.types.cloneNode(root, true),
|
|
1495
|
+
mapCount: 0,
|
|
1496
|
+
mappedStructuralAppendCount: 0,
|
|
1497
|
+
structuralAppendMapCount: 0,
|
|
1498
|
+
stateIndices: /* @__PURE__ */ new Set()
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1502
|
+
let mapCount = 0;
|
|
1503
|
+
let mappedStructuralAppendCount = 0;
|
|
1504
|
+
let structuralAppendMapCount = 0;
|
|
1505
|
+
const stateIndices = /* @__PURE__ */ new Set();
|
|
1506
|
+
const structuralUpdateKind = (updater) => {
|
|
1507
|
+
if (!core.types.isBlockStatement(updater.body)) return void 0;
|
|
1508
|
+
const statement = updater.body.body.at(-1);
|
|
1509
|
+
if (!core.types.isReturnStatement(statement) || !statement.argument) return void 0;
|
|
1510
|
+
let found;
|
|
1511
|
+
let mapped = false;
|
|
1512
|
+
core.types.traverseFast(statement.argument, (node) => {
|
|
1513
|
+
if (!found && core.types.isCallExpression(node) && core.types.isIdentifier(node.callee)) {
|
|
1514
|
+
if (node.callee.name === filterIdentifier.name) found = "filter";
|
|
1515
|
+
if (node.callee.name === sliceIdentifier.name) found = "slice";
|
|
1516
|
+
}
|
|
1517
|
+
if (!mapped && core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: mappedStructuralIdentifier.name })) {
|
|
1518
|
+
mapped = true;
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
return found ? { kind: found, mapped } : void 0;
|
|
1522
|
+
};
|
|
1523
|
+
core.traverse(file, {
|
|
1524
|
+
BlockStatement(path) {
|
|
1525
|
+
let structuralState;
|
|
1526
|
+
let structuralAppendState;
|
|
1527
|
+
let structuralMapState;
|
|
1528
|
+
let structuralKind;
|
|
1529
|
+
const statements = path.get("body");
|
|
1530
|
+
for (const statementPath of statements) {
|
|
1531
|
+
const statement = statementPath.node;
|
|
1532
|
+
if (!core.types.isExpressionStatement(statement) || !core.types.isCallExpression(statement.expression)) {
|
|
1533
|
+
structuralState = void 0;
|
|
1534
|
+
structuralAppendState = void 0;
|
|
1535
|
+
structuralMapState = void 0;
|
|
1536
|
+
structuralKind = void 0;
|
|
1537
|
+
continue;
|
|
1538
|
+
}
|
|
1539
|
+
const setterCall = statement.expression;
|
|
1540
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1541
|
+
structuralState = void 0;
|
|
1542
|
+
structuralAppendState = void 0;
|
|
1543
|
+
structuralMapState = void 0;
|
|
1544
|
+
structuralKind = void 0;
|
|
1545
|
+
continue;
|
|
1546
|
+
}
|
|
1547
|
+
const state = statesBySetter.get(setterCall.callee.name);
|
|
1548
|
+
const updater = setterCall.arguments[0];
|
|
1549
|
+
if (!state || !core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0])) {
|
|
1550
|
+
structuralState = void 0;
|
|
1551
|
+
structuralAppendState = void 0;
|
|
1552
|
+
structuralMapState = void 0;
|
|
1553
|
+
structuralKind = void 0;
|
|
1554
|
+
continue;
|
|
1555
|
+
}
|
|
1556
|
+
const nextStructuralKind = structuralUpdateKind(updater);
|
|
1557
|
+
if (nextStructuralKind) {
|
|
1558
|
+
structuralState = state.index;
|
|
1559
|
+
structuralAppendState = void 0;
|
|
1560
|
+
structuralMapState = nextStructuralKind.mapped ? state.index : void 0;
|
|
1561
|
+
structuralKind = nextStructuralKind.kind;
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
const appendCalls = [];
|
|
1565
|
+
core.types.traverseFast(updater.body, (node) => {
|
|
1566
|
+
if (core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: appendIdentifier.name })) {
|
|
1567
|
+
appendCalls.push(node);
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
if (appendCalls.length > 0) {
|
|
1571
|
+
if (structuralState === state.index && structuralKind !== void 0) {
|
|
1572
|
+
structuralAppendState = state.index;
|
|
1573
|
+
if (structuralMapState === state.index) {
|
|
1574
|
+
for (const call of appendCalls) {
|
|
1575
|
+
call.callee = core.types.cloneNode(mappedStructuralAppendIdentifier);
|
|
1576
|
+
}
|
|
1577
|
+
mappedStructuralAppendCount += appendCalls.length;
|
|
1578
|
+
}
|
|
1579
|
+
} else {
|
|
1580
|
+
structuralState = void 0;
|
|
1581
|
+
structuralAppendState = void 0;
|
|
1582
|
+
structuralMapState = void 0;
|
|
1583
|
+
structuralKind = void 0;
|
|
1584
|
+
}
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1587
|
+
const pipelineMapCount = countKeyedArrayMapPipeline(updater, mapUpdateIdentifier);
|
|
1588
|
+
if (structuralState !== state.index || pipelineMapCount === 0) {
|
|
1589
|
+
structuralState = void 0;
|
|
1590
|
+
structuralAppendState = void 0;
|
|
1591
|
+
structuralMapState = void 0;
|
|
1592
|
+
structuralKind = void 0;
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
updater.body.callee = core.types.cloneNode(
|
|
1596
|
+
structuralAppendState === state.index ? structuralAppendMapPipelineIdentifier : mapPipelineIdentifier
|
|
1597
|
+
);
|
|
1598
|
+
mapCount += pipelineMapCount;
|
|
1599
|
+
if (structuralAppendState === state.index) {
|
|
1600
|
+
structuralAppendMapCount += pipelineMapCount;
|
|
1601
|
+
}
|
|
1602
|
+
structuralMapState = state.index;
|
|
1603
|
+
stateIndices.add(state.index);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
return {
|
|
1608
|
+
root: file.program.body[0].expression,
|
|
1609
|
+
mapCount,
|
|
1610
|
+
mappedStructuralAppendCount,
|
|
1611
|
+
structuralAppendMapCount,
|
|
1612
|
+
stateIndices
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
function rewriteQueuedKeyedArrayStructuralPrependMapHints(root, statesBySetter, mapUpdateIdentifier, mapPipelineIdentifier, prependIdentifier, mappedStructuralPrependIdentifier, structuralPrependMapPipelineIdentifier, filterIdentifier, sliceIdentifier, mappedStructuralIdentifier, allowed) {
|
|
1616
|
+
if (!allowed) {
|
|
1617
|
+
return {
|
|
1618
|
+
root: core.types.cloneNode(root, true),
|
|
1619
|
+
mapCount: 0,
|
|
1620
|
+
mappedStructuralPrependCount: 0,
|
|
1621
|
+
structuralPrependMapCount: 0,
|
|
1622
|
+
stateIndices: /* @__PURE__ */ new Set()
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1626
|
+
let mapCount = 0;
|
|
1627
|
+
let mappedStructuralPrependCount = 0;
|
|
1628
|
+
let structuralPrependMapCount = 0;
|
|
1629
|
+
const stateIndices = /* @__PURE__ */ new Set();
|
|
1630
|
+
const structuralUpdateKind = (updater) => {
|
|
1631
|
+
if (!core.types.isBlockStatement(updater.body)) return void 0;
|
|
1632
|
+
const statement = updater.body.body.at(-1);
|
|
1633
|
+
if (!core.types.isReturnStatement(statement) || !statement.argument) return void 0;
|
|
1634
|
+
let found;
|
|
1635
|
+
let mapped = false;
|
|
1636
|
+
core.types.traverseFast(statement.argument, (node) => {
|
|
1637
|
+
if (!found && core.types.isCallExpression(node) && core.types.isIdentifier(node.callee)) {
|
|
1638
|
+
if (node.callee.name === filterIdentifier.name) found = "filter";
|
|
1639
|
+
if (node.callee.name === sliceIdentifier.name) found = "slice";
|
|
1640
|
+
}
|
|
1641
|
+
if (!mapped && core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: mappedStructuralIdentifier.name })) {
|
|
1642
|
+
mapped = true;
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1645
|
+
return found ? { kind: found, mapped } : void 0;
|
|
1646
|
+
};
|
|
1647
|
+
core.traverse(file, {
|
|
1648
|
+
BlockStatement(path) {
|
|
1649
|
+
let structuralState;
|
|
1650
|
+
let structuralPrependState;
|
|
1651
|
+
let structuralMapState;
|
|
1652
|
+
let structuralKind;
|
|
1653
|
+
const statements = path.get("body");
|
|
1654
|
+
for (const statementPath of statements) {
|
|
1655
|
+
const statement = statementPath.node;
|
|
1656
|
+
if (!core.types.isExpressionStatement(statement) || !core.types.isCallExpression(statement.expression)) {
|
|
1657
|
+
structuralState = void 0;
|
|
1658
|
+
structuralPrependState = void 0;
|
|
1659
|
+
structuralMapState = void 0;
|
|
1660
|
+
structuralKind = void 0;
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
const setterCall = statement.expression;
|
|
1664
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1665
|
+
structuralState = void 0;
|
|
1666
|
+
structuralPrependState = void 0;
|
|
1667
|
+
structuralMapState = void 0;
|
|
1668
|
+
structuralKind = void 0;
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
const state = statesBySetter.get(setterCall.callee.name);
|
|
1672
|
+
const updater = setterCall.arguments[0];
|
|
1673
|
+
if (!state || !core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0])) {
|
|
1674
|
+
structuralState = void 0;
|
|
1675
|
+
structuralPrependState = void 0;
|
|
1676
|
+
structuralMapState = void 0;
|
|
1677
|
+
structuralKind = void 0;
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1680
|
+
const nextStructuralKind = structuralUpdateKind(updater);
|
|
1681
|
+
if (nextStructuralKind) {
|
|
1682
|
+
structuralState = state.index;
|
|
1683
|
+
structuralPrependState = void 0;
|
|
1684
|
+
structuralMapState = nextStructuralKind.mapped ? state.index : void 0;
|
|
1685
|
+
structuralKind = nextStructuralKind.kind;
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
const prependCalls = [];
|
|
1689
|
+
core.types.traverseFast(updater.body, (node) => {
|
|
1690
|
+
if (core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: prependIdentifier.name })) {
|
|
1691
|
+
prependCalls.push(node);
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
if (prependCalls.length > 0) {
|
|
1695
|
+
if (structuralState === state.index && structuralKind !== void 0) {
|
|
1696
|
+
structuralPrependState = state.index;
|
|
1697
|
+
if (structuralMapState === state.index) {
|
|
1698
|
+
for (const call of prependCalls) {
|
|
1699
|
+
call.callee = core.types.cloneNode(mappedStructuralPrependIdentifier);
|
|
1700
|
+
}
|
|
1701
|
+
mappedStructuralPrependCount += prependCalls.length;
|
|
1702
|
+
}
|
|
1703
|
+
} else {
|
|
1704
|
+
structuralState = void 0;
|
|
1705
|
+
structuralPrependState = void 0;
|
|
1706
|
+
structuralMapState = void 0;
|
|
1707
|
+
structuralKind = void 0;
|
|
1708
|
+
}
|
|
1709
|
+
continue;
|
|
1710
|
+
}
|
|
1711
|
+
const pipelineMapCount = countKeyedArrayMapPipeline(updater, mapUpdateIdentifier) || countKeyedArrayMapPipeline(updater, mapPipelineIdentifier);
|
|
1712
|
+
if (structuralState !== state.index || pipelineMapCount === 0) {
|
|
1713
|
+
structuralState = void 0;
|
|
1714
|
+
structuralPrependState = void 0;
|
|
1715
|
+
structuralMapState = void 0;
|
|
1716
|
+
structuralKind = void 0;
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
updater.body.callee = core.types.cloneNode(
|
|
1720
|
+
structuralPrependState === state.index ? structuralPrependMapPipelineIdentifier : mapPipelineIdentifier
|
|
1721
|
+
);
|
|
1722
|
+
mapCount += pipelineMapCount;
|
|
1723
|
+
if (structuralPrependState === state.index) {
|
|
1724
|
+
structuralPrependMapCount += pipelineMapCount;
|
|
1725
|
+
}
|
|
1726
|
+
structuralMapState = state.index;
|
|
1727
|
+
stateIndices.add(state.index);
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
return {
|
|
1732
|
+
root: file.program.body[0].expression,
|
|
1733
|
+
mapCount,
|
|
1734
|
+
mappedStructuralPrependCount,
|
|
1735
|
+
structuralPrependMapCount,
|
|
1736
|
+
stateIndices
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
function rewriteQueuedKeyedArrayStructuralReorderHints(root, statesBySetter, filterIdentifier, sliceIdentifier, mapPipelineIdentifier, queuedMapPipelineIdentifier, mappedStructuralIdentifier, mapReorderIdentifier, reorderIdentifier, sortIdentifier, structuralReorderIdentifier, structuralSortIdentifier, allowed) {
|
|
1740
|
+
if (!allowed) {
|
|
1741
|
+
return {
|
|
1742
|
+
root: core.types.cloneNode(root, true),
|
|
1743
|
+
reorderCount: 0,
|
|
1744
|
+
sortCount: 0,
|
|
1745
|
+
replacedMapReorderCount: 0,
|
|
1746
|
+
replacedMapSortCount: 0,
|
|
1747
|
+
replacedQueuedMapCount: 0
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1751
|
+
let reorderCount = 0;
|
|
1752
|
+
let sortCount = 0;
|
|
1753
|
+
let replacedMapReorderCount = 0;
|
|
1754
|
+
let replacedMapSortCount = 0;
|
|
1755
|
+
let replacedQueuedMapCount = 0;
|
|
1756
|
+
core.traverse(file, {
|
|
1757
|
+
BlockStatement(path) {
|
|
1758
|
+
let structuralState;
|
|
1759
|
+
const statements = path.get("body");
|
|
1760
|
+
for (const statementPath of statements) {
|
|
1761
|
+
const statement = statementPath.node;
|
|
1762
|
+
if (!core.types.isExpressionStatement(statement) || !core.types.isCallExpression(statement.expression)) {
|
|
1763
|
+
structuralState = void 0;
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
const setterCall = statement.expression;
|
|
1767
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1768
|
+
structuralState = void 0;
|
|
1769
|
+
continue;
|
|
1770
|
+
}
|
|
1771
|
+
const state = statesBySetter.get(setterCall.callee.name);
|
|
1772
|
+
const updater = setterCall.arguments[0];
|
|
1773
|
+
if (!state || !core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0])) {
|
|
1774
|
+
structuralState = void 0;
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
const methodKinds = /* @__PURE__ */ new Map();
|
|
1778
|
+
core.types.traverseFast(updater.body, (node) => {
|
|
1779
|
+
if (!core.types.isVariableDeclarator(node) || !core.types.isIdentifier(node.id) || !core.types.isMemberExpression(node.init) || node.init.computed || !core.types.isIdentifier(node.init.property)) {
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
if (node.init.property.name === "toReversed") methodKinds.set(node.id.name, "reverse");
|
|
1783
|
+
if (node.init.property.name === "toSorted") methodKinds.set(node.id.name, "sort");
|
|
1784
|
+
});
|
|
1785
|
+
let startsStructuralLineage = false;
|
|
1786
|
+
let continuesStructuralLineage = false;
|
|
1787
|
+
let unsupported = false;
|
|
1788
|
+
const queuedMaps = [];
|
|
1789
|
+
const reorderCalls = [];
|
|
1790
|
+
core.types.traverseFast(updater.body, (node) => {
|
|
1791
|
+
if (!core.types.isCallExpression(node) || !core.types.isIdentifier(node.callee)) return;
|
|
1792
|
+
const helperName = node.callee.name;
|
|
1793
|
+
if (helperName === filterIdentifier.name || helperName === sliceIdentifier.name || helperName === mappedStructuralIdentifier.name) {
|
|
1794
|
+
startsStructuralLineage = true;
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
if (helperName === structuralReorderIdentifier.name || helperName === structuralSortIdentifier.name) {
|
|
1798
|
+
startsStructuralLineage = true;
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
if (helperName === mapPipelineIdentifier.name) {
|
|
1802
|
+
continuesStructuralLineage = true;
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
if (helperName === queuedMapPipelineIdentifier.name) {
|
|
1806
|
+
continuesStructuralLineage = true;
|
|
1807
|
+
queuedMaps.push(node);
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
if (helperName === reorderIdentifier.name) {
|
|
1811
|
+
continuesStructuralLineage = true;
|
|
1812
|
+
reorderCalls.push({ call: node, kind: "reverse", mapped: false });
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
if (helperName === sortIdentifier.name) {
|
|
1816
|
+
continuesStructuralLineage = true;
|
|
1817
|
+
reorderCalls.push({ call: node, kind: "sort", mapped: false });
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
if (helperName === mapReorderIdentifier.name) {
|
|
1821
|
+
const method = node.arguments[1];
|
|
1822
|
+
const kind = core.types.isIdentifier(method) ? methodKinds.get(method.name) : void 0;
|
|
1823
|
+
if (!kind) {
|
|
1824
|
+
unsupported = true;
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
continuesStructuralLineage = true;
|
|
1828
|
+
reorderCalls.push({ call: node, kind, mapped: true });
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
const hasStructuralLineage = startsStructuralLineage || structuralState === state.index;
|
|
1832
|
+
if (unsupported || !startsStructuralLineage && !continuesStructuralLineage) {
|
|
1833
|
+
structuralState = void 0;
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
if (!hasStructuralLineage) {
|
|
1837
|
+
structuralState = void 0;
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
for (const call of queuedMaps) {
|
|
1841
|
+
call.callee = core.types.cloneNode(mapPipelineIdentifier);
|
|
1842
|
+
replacedQueuedMapCount += 1;
|
|
1843
|
+
}
|
|
1844
|
+
for (const { call, kind, mapped } of reorderCalls) {
|
|
1845
|
+
call.callee = core.types.cloneNode(
|
|
1846
|
+
kind === "reverse" ? structuralReorderIdentifier : structuralSortIdentifier
|
|
1847
|
+
);
|
|
1848
|
+
if (kind === "reverse") {
|
|
1849
|
+
reorderCount += 1;
|
|
1850
|
+
if (mapped) replacedMapReorderCount += 1;
|
|
1851
|
+
} else {
|
|
1852
|
+
sortCount += 1;
|
|
1853
|
+
if (mapped) replacedMapSortCount += 1;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
structuralState = state.index;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
});
|
|
1860
|
+
return {
|
|
1861
|
+
root: file.program.body[0].expression,
|
|
1862
|
+
reorderCount,
|
|
1863
|
+
sortCount,
|
|
1864
|
+
replacedMapReorderCount,
|
|
1865
|
+
replacedMapSortCount,
|
|
1866
|
+
replacedQueuedMapCount
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateIdentifier, queuedMapPipelineIdentifier, mapReorderIdentifier, reorderIdentifier, sortIdentifier, structuralReorderIdentifier, structuralSortIdentifier, allowed) {
|
|
1870
|
+
if (!allowed) {
|
|
1871
|
+
return {
|
|
1872
|
+
root: core.types.cloneNode(root, true),
|
|
1873
|
+
mapCount: 0,
|
|
1874
|
+
mapReorderCount: 0,
|
|
1875
|
+
mapSortCount: 0
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1879
|
+
let mapCount = 0;
|
|
1880
|
+
let mapReorderCount = 0;
|
|
1881
|
+
let mapSortCount = 0;
|
|
1882
|
+
core.traverse(file, {
|
|
1883
|
+
BlockStatement(path) {
|
|
1884
|
+
let mappedReorderState;
|
|
1885
|
+
let pendingMaps = [];
|
|
1886
|
+
const statements = path.get("body");
|
|
1887
|
+
for (const statementPath of statements) {
|
|
1888
|
+
const statement = statementPath.node;
|
|
1889
|
+
if (!core.types.isExpressionStatement(statement) || !core.types.isCallExpression(statement.expression)) {
|
|
1890
|
+
mappedReorderState = void 0;
|
|
1891
|
+
pendingMaps = [];
|
|
1892
|
+
continue;
|
|
1893
|
+
}
|
|
1894
|
+
const setterCall = statement.expression;
|
|
1895
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1896
|
+
mappedReorderState = void 0;
|
|
1897
|
+
pendingMaps = [];
|
|
1898
|
+
continue;
|
|
1899
|
+
}
|
|
1900
|
+
const state = statesBySetter.get(setterCall.callee.name);
|
|
1901
|
+
const updater = setterCall.arguments[0];
|
|
1902
|
+
if (!state || !core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0])) {
|
|
1903
|
+
mappedReorderState = void 0;
|
|
1904
|
+
pendingMaps = [];
|
|
1905
|
+
continue;
|
|
1906
|
+
}
|
|
1907
|
+
if (core.types.isCallExpression(updater.body) && core.types.isIdentifier(updater.body.callee, { name: mapUpdateIdentifier.name }) && updater.body.arguments.length === 2) {
|
|
1908
|
+
const pipeline = updater.body.arguments[1];
|
|
1909
|
+
let pipelineMapCount = 0;
|
|
1910
|
+
if (core.types.isArrowFunctionExpression(pipeline) && pipeline.params.length === 2 && core.types.isIdentifier(pipeline.params[1])) {
|
|
1911
|
+
const applyMapName = pipeline.params[1].name;
|
|
1912
|
+
core.types.traverseFast(pipeline.body, (node) => {
|
|
1913
|
+
if (core.types.isCallExpression(node) && core.types.isIdentifier(node.callee, { name: applyMapName })) {
|
|
1914
|
+
pipelineMapCount += 1;
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
if (pipelineMapCount > 0) {
|
|
1919
|
+
const candidate = {
|
|
1920
|
+
count: pipelineMapCount,
|
|
1921
|
+
stateIndex: state.index,
|
|
1922
|
+
updater
|
|
1923
|
+
};
|
|
1924
|
+
pendingMaps = pendingMaps[0]?.stateIndex === state.index ? [...pendingMaps, candidate] : [candidate];
|
|
1925
|
+
if (mappedReorderState !== state.index) mappedReorderState = void 0;
|
|
1926
|
+
continue;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
let containsMappedReorder = false;
|
|
1930
|
+
const reorderCalls = [];
|
|
1931
|
+
let structural = false;
|
|
1932
|
+
core.types.traverseFast(updater.body, (node) => {
|
|
1933
|
+
if (!core.types.isCallExpression(node) || !core.types.isIdentifier(node.callee)) return;
|
|
1934
|
+
if (node.callee.name === structuralReorderIdentifier.name || node.callee.name === structuralSortIdentifier.name) {
|
|
1935
|
+
structural = true;
|
|
1936
|
+
} else if (node.callee.name === mapReorderIdentifier.name) {
|
|
1937
|
+
containsMappedReorder = true;
|
|
1938
|
+
} else if (node.callee.name === reorderIdentifier.name) {
|
|
1939
|
+
reorderCalls.push({ call: node, kind: "reverse" });
|
|
1940
|
+
} else if (node.callee.name === sortIdentifier.name) {
|
|
1941
|
+
reorderCalls.push({ call: node, kind: "sort" });
|
|
1942
|
+
}
|
|
1943
|
+
});
|
|
1944
|
+
if (structural) {
|
|
1945
|
+
mappedReorderState = void 0;
|
|
1946
|
+
pendingMaps = [];
|
|
1947
|
+
continue;
|
|
1948
|
+
}
|
|
1949
|
+
const hasPendingMaps = pendingMaps.length > 0 && pendingMaps[0].stateIndex === state.index;
|
|
1950
|
+
if (containsMappedReorder && reorderCalls.length === 0) {
|
|
1951
|
+
mappedReorderState = pendingMaps.length === 0 ? state.index : void 0;
|
|
1952
|
+
pendingMaps = [];
|
|
1953
|
+
continue;
|
|
1954
|
+
}
|
|
1955
|
+
if (containsMappedReorder || reorderCalls.length === 0 || !hasPendingMaps && mappedReorderState !== state.index) {
|
|
1956
|
+
mappedReorderState = void 0;
|
|
1957
|
+
pendingMaps = [];
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
if (hasPendingMaps) {
|
|
1961
|
+
for (const candidate of pendingMaps) {
|
|
1962
|
+
candidate.updater.body.callee = core.types.cloneNode(queuedMapPipelineIdentifier);
|
|
1963
|
+
mapCount += candidate.count;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
for (const { call, kind } of reorderCalls) {
|
|
1967
|
+
call.callee = core.types.cloneNode(mapReorderIdentifier);
|
|
1968
|
+
if (kind === "reverse") mapReorderCount += 1;
|
|
1969
|
+
else mapSortCount += 1;
|
|
1970
|
+
}
|
|
1971
|
+
mappedReorderState = state.index;
|
|
1972
|
+
pendingMaps = [];
|
|
1973
|
+
}
|
|
958
1974
|
}
|
|
959
1975
|
});
|
|
960
1976
|
return {
|
|
961
1977
|
root: file.program.body[0].expression,
|
|
962
|
-
|
|
963
|
-
|
|
1978
|
+
mapCount,
|
|
1979
|
+
mapReorderCount,
|
|
1980
|
+
mapSortCount
|
|
964
1981
|
};
|
|
965
1982
|
}
|
|
966
1983
|
function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
@@ -1018,7 +2035,7 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
1018
2035
|
stateIndices
|
|
1019
2036
|
};
|
|
1020
2037
|
}
|
|
1021
|
-
function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier) {
|
|
2038
|
+
function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
1022
2039
|
if (hintedStateIndices.size === 0) {
|
|
1023
2040
|
return { root: core.types.cloneNode(root, true), count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
1024
2041
|
}
|
|
@@ -1037,14 +2054,13 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
1037
2054
|
if (!core.types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !core.types.isIdentifier(updater.params[0]) || !core.types.isCallExpression(updater.body) || updater.body.arguments.length < 1 || updater.body.arguments.length > 2 || !core.types.isMemberExpression(updater.body.callee) || updater.body.callee.computed || !core.types.isIdentifier(updater.body.callee.object, { name: updater.params[0].name }) || !core.types.isIdentifier(updater.body.callee.property, { name: "slice" })) {
|
|
1038
2055
|
return;
|
|
1039
2056
|
}
|
|
1040
|
-
const
|
|
2057
|
+
const bounds = [];
|
|
1041
2058
|
for (const argument of updater.body.arguments) {
|
|
1042
2059
|
if (!core.types.isExpression(argument)) return;
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
indexes.push(value);
|
|
2060
|
+
if (validateKeyedArrayPositionExpression(argument, safeGlobals) !== void 0) return;
|
|
2061
|
+
bounds.push(argument);
|
|
1046
2062
|
}
|
|
1047
|
-
if (
|
|
2063
|
+
if (bounds.length === 1 && staticSliceIndex(bounds[0]) === 0) return;
|
|
1048
2064
|
const previous = core.types.cloneNode(updater.params[0]);
|
|
1049
2065
|
const sliceMethod = path.scope.generateUidIdentifier("farmSlice");
|
|
1050
2066
|
path.node.arguments[0] = core.types.arrowFunctionExpression(
|
|
@@ -1060,7 +2076,7 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
1060
2076
|
core.types.callExpression(core.types.cloneNode(helperIdentifier), [
|
|
1061
2077
|
core.types.cloneNode(previous),
|
|
1062
2078
|
core.types.cloneNode(sliceMethod),
|
|
1063
|
-
...
|
|
2079
|
+
...bounds.map((bound) => core.types.cloneNode(bound, true))
|
|
1064
2080
|
])
|
|
1065
2081
|
)
|
|
1066
2082
|
])
|
|
@@ -4819,7 +5835,7 @@ function wrapperElement(definitionIdentifier, props) {
|
|
|
4819
5835
|
const attributes = props ? [core.types.jsxSpreadAttribute(core.types.cloneNode(props))] : [];
|
|
4820
5836
|
return core.types.jsxElement(core.types.jsxOpeningElement(name, attributes, true), null, [], true);
|
|
4821
5837
|
}
|
|
4822
|
-
function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayReorderIdentifier, keyedArraySortIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
5838
|
+
function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayMapPipelineIdentifier, keyedArrayMappedStructuralAppendIdentifier, keyedArrayStructuralAppendMapPipelineIdentifier, keyedArrayMappedStructuralPrependIdentifier, keyedArrayStructuralPrependMapPipelineIdentifier, keyedArrayQueuedMapPipelineIdentifier, keyedArrayMapReorderIdentifier, keyedArrayMappedStructuralIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayBatchInsertIdentifier, keyedArrayWindowReplaceIdentifier, keyedArrayReorderIdentifier, keyedArrayStructuralReorderIdentifier, keyedArraySortIdentifier, keyedArrayStructuralSortIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, compilerUsage, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
4823
5839
|
const { path, name, statementPath } = candidate;
|
|
4824
5840
|
if (path.node.async || path.node.generator)
|
|
4825
5841
|
return "async and generator components are not supported";
|
|
@@ -5191,9 +6207,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5191
6207
|
shiftedIndexIndependentStateIndices,
|
|
5192
6208
|
statesBySetter,
|
|
5193
6209
|
keyedArrayPositionIdentifier,
|
|
6210
|
+
keyedArrayBatchInsertIdentifier,
|
|
6211
|
+
keyedArrayWindowReplaceIdentifier,
|
|
5194
6212
|
safeGlobals
|
|
5195
6213
|
);
|
|
5196
6214
|
let appliedKeyedArrayPositionHints = 0;
|
|
6215
|
+
let appliedKeyedArrayBatchInsertHints = 0;
|
|
6216
|
+
let appliedKeyedArrayWindowReplaceHints = 0;
|
|
5197
6217
|
let appliedPositionHintedStateIndices = /* @__PURE__ */ new Set();
|
|
5198
6218
|
if (positionHintedRoot.count > 0) {
|
|
5199
6219
|
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
@@ -5217,8 +6237,78 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5217
6237
|
blockAnalysis = hintedBlockAnalysis;
|
|
5218
6238
|
analysis = hintedAnalysis;
|
|
5219
6239
|
appliedKeyedArrayPositionHints = positionHintedRoot.count;
|
|
6240
|
+
appliedKeyedArrayBatchInsertHints = positionHintedRoot.batchInsertCount;
|
|
6241
|
+
appliedKeyedArrayWindowReplaceHints = positionHintedRoot.windowReplaceCount;
|
|
5220
6242
|
appliedPositionHintedStateIndices = positionHintedRoot.stateIndices;
|
|
5221
6243
|
optimizationCounts.keyedArrayPositionHints += positionHintedRoot.count;
|
|
6244
|
+
compilerUsage.keyedArrayBatchInsertHints += positionHintedRoot.batchInsertCount;
|
|
6245
|
+
compilerUsage.keyedArrayWindowReplaceHints += positionHintedRoot.windowReplaceCount;
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
const allowKeyedArrayMapPipelines = (blockAnalysis.plans || []).every(
|
|
6249
|
+
(plan) => plan.kind !== "keyed-rows" || plan.conditionals.length === 0 && !plan.descriptorBlocks?.size
|
|
6250
|
+
);
|
|
6251
|
+
const reorderPipelineHintedRoot = rewriteKeyedArrayReorderPipelineHints(
|
|
6252
|
+
expandedReactiveRoot,
|
|
6253
|
+
shiftedIndexIndependentStateIndices,
|
|
6254
|
+
statesBySetter,
|
|
6255
|
+
keyedArrayFilterIdentifier,
|
|
6256
|
+
keyedArrayMapPipelineIdentifier,
|
|
6257
|
+
keyedArrayMapReorderIdentifier,
|
|
6258
|
+
keyedArrayMappedStructuralIdentifier,
|
|
6259
|
+
keyedArrayReorderIdentifier,
|
|
6260
|
+
keyedArrayStructuralReorderIdentifier,
|
|
6261
|
+
keyedArraySliceIdentifier,
|
|
6262
|
+
keyedArraySortIdentifier,
|
|
6263
|
+
keyedArrayStructuralSortIdentifier,
|
|
6264
|
+
safeGlobals,
|
|
6265
|
+
allowKeyedArrayMapPipelines
|
|
6266
|
+
);
|
|
6267
|
+
let appliedPipelineFilterHints = 0;
|
|
6268
|
+
let appliedPipelineMapHints = 0;
|
|
6269
|
+
let appliedPipelineReorderHints = 0;
|
|
6270
|
+
let appliedPipelineSliceHints = 0;
|
|
6271
|
+
let appliedPipelineSortHints = 0;
|
|
6272
|
+
let appliedPipelineHintedStateIndices = /* @__PURE__ */ new Set();
|
|
6273
|
+
if (reorderPipelineHintedRoot.filterCount > 0 || reorderPipelineHintedRoot.reorderCount > 0 || reorderPipelineHintedRoot.sliceCount > 0 || reorderPipelineHintedRoot.sortCount > 0) {
|
|
6274
|
+
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
6275
|
+
reorderPipelineHintedRoot.root,
|
|
6276
|
+
reactiveByValue,
|
|
6277
|
+
safeGlobals,
|
|
6278
|
+
listNames,
|
|
6279
|
+
allowedComponentNames
|
|
6280
|
+
);
|
|
6281
|
+
const hintedAnalysis = analyzeHostTree(
|
|
6282
|
+
reorderPipelineHintedRoot.root,
|
|
6283
|
+
reactiveByValue,
|
|
6284
|
+
safeGlobals,
|
|
6285
|
+
hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
|
|
6286
|
+
hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
|
|
6287
|
+
hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
|
|
6288
|
+
hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
|
|
6289
|
+
);
|
|
6290
|
+
if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
|
|
6291
|
+
expandedReactiveRoot = reorderPipelineHintedRoot.root;
|
|
6292
|
+
blockAnalysis = hintedBlockAnalysis;
|
|
6293
|
+
analysis = hintedAnalysis;
|
|
6294
|
+
appliedPipelineFilterHints = reorderPipelineHintedRoot.filterCount;
|
|
6295
|
+
appliedPipelineMapHints = reorderPipelineHintedRoot.mapCount;
|
|
6296
|
+
appliedKeyedMapUpdateHints += reorderPipelineHintedRoot.mapCount;
|
|
6297
|
+
appliedPipelineReorderHints = reorderPipelineHintedRoot.reorderCount + reorderPipelineHintedRoot.terminalStructuralPipelineCount;
|
|
6298
|
+
appliedPipelineSliceHints = reorderPipelineHintedRoot.sliceCount;
|
|
6299
|
+
appliedPipelineSortHints = reorderPipelineHintedRoot.sortCount;
|
|
6300
|
+
appliedPipelineHintedStateIndices = reorderPipelineHintedRoot.stateIndices;
|
|
6301
|
+
optimizationCounts.keyedArrayFilterHints += reorderPipelineHintedRoot.filterCount;
|
|
6302
|
+
optimizationCounts.keyedMapUpdateHints += reorderPipelineHintedRoot.mapCount;
|
|
6303
|
+
optimizationCounts.keyedArrayReorderHints += reorderPipelineHintedRoot.reorderCount;
|
|
6304
|
+
optimizationCounts.keyedArraySliceHints += reorderPipelineHintedRoot.sliceCount;
|
|
6305
|
+
optimizationCounts.keyedArraySortHints += reorderPipelineHintedRoot.sortCount;
|
|
6306
|
+
compilerUsage.keyedArrayStructuralReorderHints += reorderPipelineHintedRoot.structuralReorderCount;
|
|
6307
|
+
compilerUsage.keyedArrayStructuralSortHints += reorderPipelineHintedRoot.structuralSortCount;
|
|
6308
|
+
compilerUsage.keyedArrayMapUpdateHints += reorderPipelineHintedRoot.mapCount;
|
|
6309
|
+
compilerUsage.keyedArrayMapReorderHints += reorderPipelineHintedRoot.mapReorderCount;
|
|
6310
|
+
compilerUsage.keyedArrayMapSortHints += reorderPipelineHintedRoot.mapSortCount;
|
|
6311
|
+
compilerUsage.keyedArrayMappedStructuralHints += reorderPipelineHintedRoot.terminalStructuralPipelineCount;
|
|
5222
6312
|
}
|
|
5223
6313
|
}
|
|
5224
6314
|
const reorderHintedRoot = rewriteKeyedArrayReorderHints(
|
|
@@ -5227,8 +6317,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5227
6317
|
statesBySetter,
|
|
5228
6318
|
keyedArrayReorderIdentifier
|
|
5229
6319
|
);
|
|
5230
|
-
let appliedKeyedArrayReorderHints =
|
|
5231
|
-
let appliedReorderHintedStateIndices =
|
|
6320
|
+
let appliedKeyedArrayReorderHints = appliedPipelineReorderHints;
|
|
6321
|
+
let appliedReorderHintedStateIndices = appliedPipelineHintedStateIndices;
|
|
5232
6322
|
if (reorderHintedRoot.count > 0) {
|
|
5233
6323
|
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
5234
6324
|
reorderHintedRoot.root,
|
|
@@ -5250,8 +6340,11 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5250
6340
|
expandedReactiveRoot = reorderHintedRoot.root;
|
|
5251
6341
|
blockAnalysis = hintedBlockAnalysis;
|
|
5252
6342
|
analysis = hintedAnalysis;
|
|
5253
|
-
appliedKeyedArrayReorderHints
|
|
5254
|
-
appliedReorderHintedStateIndices =
|
|
6343
|
+
appliedKeyedArrayReorderHints += reorderHintedRoot.count;
|
|
6344
|
+
appliedReorderHintedStateIndices = /* @__PURE__ */ new Set([
|
|
6345
|
+
...appliedReorderHintedStateIndices,
|
|
6346
|
+
...reorderHintedRoot.stateIndices
|
|
6347
|
+
]);
|
|
5255
6348
|
optimizationCounts.keyedArrayReorderHints += reorderHintedRoot.count;
|
|
5256
6349
|
}
|
|
5257
6350
|
}
|
|
@@ -5262,8 +6355,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5262
6355
|
keyedArraySortIdentifier,
|
|
5263
6356
|
safeGlobals
|
|
5264
6357
|
);
|
|
5265
|
-
let appliedKeyedArraySortHints =
|
|
5266
|
-
let appliedSortHintedStateIndices =
|
|
6358
|
+
let appliedKeyedArraySortHints = appliedPipelineSortHints;
|
|
6359
|
+
let appliedSortHintedStateIndices = appliedPipelineHintedStateIndices;
|
|
5267
6360
|
if (sortHintedRoot.count > 0) {
|
|
5268
6361
|
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
5269
6362
|
sortHintedRoot.root,
|
|
@@ -5285,8 +6378,11 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5285
6378
|
expandedReactiveRoot = sortHintedRoot.root;
|
|
5286
6379
|
blockAnalysis = hintedBlockAnalysis;
|
|
5287
6380
|
analysis = hintedAnalysis;
|
|
5288
|
-
appliedKeyedArraySortHints
|
|
5289
|
-
appliedSortHintedStateIndices =
|
|
6381
|
+
appliedKeyedArraySortHints += sortHintedRoot.count;
|
|
6382
|
+
appliedSortHintedStateIndices = /* @__PURE__ */ new Set([
|
|
6383
|
+
...appliedSortHintedStateIndices,
|
|
6384
|
+
...sortHintedRoot.stateIndices
|
|
6385
|
+
]);
|
|
5290
6386
|
optimizationCounts.keyedArraySortHints += sortHintedRoot.count;
|
|
5291
6387
|
}
|
|
5292
6388
|
}
|
|
@@ -5294,10 +6390,11 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5294
6390
|
expandedReactiveRoot,
|
|
5295
6391
|
shiftedIndexIndependentStateIndices,
|
|
5296
6392
|
statesBySetter,
|
|
5297
|
-
keyedArraySliceIdentifier
|
|
6393
|
+
keyedArraySliceIdentifier,
|
|
6394
|
+
safeGlobals
|
|
5298
6395
|
);
|
|
5299
|
-
let appliedKeyedArraySliceHints =
|
|
5300
|
-
let appliedSliceHintedStateIndices = /* @__PURE__ */ new Set();
|
|
6396
|
+
let appliedKeyedArraySliceHints = appliedPipelineSliceHints;
|
|
6397
|
+
let appliedSliceHintedStateIndices = appliedPipelineSliceHints > 0 ? appliedPipelineHintedStateIndices : /* @__PURE__ */ new Set();
|
|
5301
6398
|
if (sliceHintedRoot.count > 0) {
|
|
5302
6399
|
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
5303
6400
|
sliceHintedRoot.root,
|
|
@@ -5319,8 +6416,11 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5319
6416
|
expandedReactiveRoot = sliceHintedRoot.root;
|
|
5320
6417
|
blockAnalysis = hintedBlockAnalysis;
|
|
5321
6418
|
analysis = hintedAnalysis;
|
|
5322
|
-
appliedKeyedArraySliceHints
|
|
5323
|
-
appliedSliceHintedStateIndices =
|
|
6419
|
+
appliedKeyedArraySliceHints += sliceHintedRoot.count;
|
|
6420
|
+
appliedSliceHintedStateIndices = /* @__PURE__ */ new Set([
|
|
6421
|
+
...appliedSliceHintedStateIndices,
|
|
6422
|
+
...sliceHintedRoot.stateIndices
|
|
6423
|
+
]);
|
|
5324
6424
|
optimizationCounts.keyedArraySliceHints += sliceHintedRoot.count;
|
|
5325
6425
|
}
|
|
5326
6426
|
}
|
|
@@ -5331,8 +6431,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5331
6431
|
keyedArrayFilterIdentifier,
|
|
5332
6432
|
safeGlobals
|
|
5333
6433
|
);
|
|
5334
|
-
let appliedKeyedArrayFilterHints =
|
|
5335
|
-
let appliedFilterHintedStateIndices = /* @__PURE__ */ new Set();
|
|
6434
|
+
let appliedKeyedArrayFilterHints = appliedPipelineFilterHints;
|
|
6435
|
+
let appliedFilterHintedStateIndices = appliedPipelineFilterHints > 0 ? appliedPipelineHintedStateIndices : /* @__PURE__ */ new Set();
|
|
5336
6436
|
if (filterHintedRoot.count > 0) {
|
|
5337
6437
|
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
5338
6438
|
filterHintedRoot.root,
|
|
@@ -5354,11 +6454,243 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5354
6454
|
expandedReactiveRoot = filterHintedRoot.root;
|
|
5355
6455
|
blockAnalysis = hintedBlockAnalysis;
|
|
5356
6456
|
analysis = hintedAnalysis;
|
|
5357
|
-
appliedKeyedArrayFilterHints
|
|
5358
|
-
appliedFilterHintedStateIndices =
|
|
6457
|
+
appliedKeyedArrayFilterHints += filterHintedRoot.count;
|
|
6458
|
+
appliedFilterHintedStateIndices = /* @__PURE__ */ new Set([
|
|
6459
|
+
...appliedFilterHintedStateIndices,
|
|
6460
|
+
...filterHintedRoot.stateIndices
|
|
6461
|
+
]);
|
|
5359
6462
|
optimizationCounts.keyedArrayFilterHints += filterHintedRoot.count;
|
|
5360
6463
|
}
|
|
5361
6464
|
}
|
|
6465
|
+
const queuedMappedStructuralHintedRoot = rewriteQueuedKeyedArrayMappedStructuralHints(
|
|
6466
|
+
expandedReactiveRoot,
|
|
6467
|
+
statesBySetter,
|
|
6468
|
+
keyedMapUpdateIdentifier,
|
|
6469
|
+
keyedArrayQueuedMapPipelineIdentifier,
|
|
6470
|
+
keyedArrayMappedStructuralIdentifier,
|
|
6471
|
+
keyedArrayFilterIdentifier,
|
|
6472
|
+
keyedArraySliceIdentifier,
|
|
6473
|
+
allowKeyedArrayMapPipelines
|
|
6474
|
+
);
|
|
6475
|
+
let appliedQueuedMappedStructuralHints = 0;
|
|
6476
|
+
if (queuedMappedStructuralHintedRoot.mapCount > 0 && queuedMappedStructuralHintedRoot.structuralCount > 0) {
|
|
6477
|
+
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
6478
|
+
queuedMappedStructuralHintedRoot.root,
|
|
6479
|
+
reactiveByValue,
|
|
6480
|
+
safeGlobals,
|
|
6481
|
+
listNames,
|
|
6482
|
+
allowedComponentNames
|
|
6483
|
+
);
|
|
6484
|
+
const hintedAnalysis = analyzeHostTree(
|
|
6485
|
+
queuedMappedStructuralHintedRoot.root,
|
|
6486
|
+
reactiveByValue,
|
|
6487
|
+
safeGlobals,
|
|
6488
|
+
hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
|
|
6489
|
+
hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
|
|
6490
|
+
hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
|
|
6491
|
+
hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
|
|
6492
|
+
);
|
|
6493
|
+
if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
|
|
6494
|
+
expandedReactiveRoot = queuedMappedStructuralHintedRoot.root;
|
|
6495
|
+
blockAnalysis = hintedBlockAnalysis;
|
|
6496
|
+
analysis = hintedAnalysis;
|
|
6497
|
+
appliedQueuedMappedStructuralHints = queuedMappedStructuralHintedRoot.mapCount + queuedMappedStructuralHintedRoot.structuralCount;
|
|
6498
|
+
appliedKeyedArrayReorderHints += queuedMappedStructuralHintedRoot.structuralCount;
|
|
6499
|
+
appliedReorderHintedStateIndices = /* @__PURE__ */ new Set([
|
|
6500
|
+
...appliedReorderHintedStateIndices,
|
|
6501
|
+
...queuedMappedStructuralHintedRoot.stateIndices
|
|
6502
|
+
]);
|
|
6503
|
+
compilerUsage.keyedArrayMapUpdateHints += queuedMappedStructuralHintedRoot.mapCount;
|
|
6504
|
+
compilerUsage.keyedArrayQueuedMapUpdateHints += queuedMappedStructuralHintedRoot.mapCount;
|
|
6505
|
+
compilerUsage.keyedArrayMappedStructuralHints += queuedMappedStructuralHintedRoot.structuralCount;
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
const queuedStructuralMapHintedRoot = rewriteQueuedKeyedArrayStructuralMapHints(
|
|
6509
|
+
expandedReactiveRoot,
|
|
6510
|
+
statesBySetter,
|
|
6511
|
+
keyedMapUpdateIdentifier,
|
|
6512
|
+
keyedArrayMapPipelineIdentifier,
|
|
6513
|
+
keyedArrayAppendIdentifier,
|
|
6514
|
+
keyedArrayMappedStructuralAppendIdentifier,
|
|
6515
|
+
keyedArrayStructuralAppendMapPipelineIdentifier,
|
|
6516
|
+
keyedArrayFilterIdentifier,
|
|
6517
|
+
keyedArraySliceIdentifier,
|
|
6518
|
+
keyedArrayMappedStructuralIdentifier,
|
|
6519
|
+
allowKeyedArrayMapPipelines
|
|
6520
|
+
);
|
|
6521
|
+
let appliedQueuedStructuralMapHints = 0;
|
|
6522
|
+
let appliedQueuedStructuralAppendMapHints = 0;
|
|
6523
|
+
if (queuedStructuralMapHintedRoot.mapCount > 0 || queuedStructuralMapHintedRoot.mappedStructuralAppendCount > 0) {
|
|
6524
|
+
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
6525
|
+
queuedStructuralMapHintedRoot.root,
|
|
6526
|
+
reactiveByValue,
|
|
6527
|
+
safeGlobals,
|
|
6528
|
+
listNames,
|
|
6529
|
+
allowedComponentNames
|
|
6530
|
+
);
|
|
6531
|
+
const hintedAnalysis = analyzeHostTree(
|
|
6532
|
+
queuedStructuralMapHintedRoot.root,
|
|
6533
|
+
reactiveByValue,
|
|
6534
|
+
safeGlobals,
|
|
6535
|
+
hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
|
|
6536
|
+
hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
|
|
6537
|
+
hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
|
|
6538
|
+
hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
|
|
6539
|
+
);
|
|
6540
|
+
if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
|
|
6541
|
+
expandedReactiveRoot = queuedStructuralMapHintedRoot.root;
|
|
6542
|
+
blockAnalysis = hintedBlockAnalysis;
|
|
6543
|
+
analysis = hintedAnalysis;
|
|
6544
|
+
appliedQueuedStructuralMapHints = queuedStructuralMapHintedRoot.mapCount;
|
|
6545
|
+
appliedQueuedStructuralAppendMapHints = queuedStructuralMapHintedRoot.structuralAppendMapCount + queuedStructuralMapHintedRoot.mappedStructuralAppendCount;
|
|
6546
|
+
appliedKeyedArrayReorderHints += queuedStructuralMapHintedRoot.mapCount;
|
|
6547
|
+
appliedReorderHintedStateIndices = /* @__PURE__ */ new Set([
|
|
6548
|
+
...appliedReorderHintedStateIndices,
|
|
6549
|
+
...queuedStructuralMapHintedRoot.stateIndices
|
|
6550
|
+
]);
|
|
6551
|
+
compilerUsage.keyedArrayMapUpdateHints += queuedStructuralMapHintedRoot.mapCount;
|
|
6552
|
+
compilerUsage.keyedArrayMappedStructuralAppendHints += queuedStructuralMapHintedRoot.mappedStructuralAppendCount;
|
|
6553
|
+
compilerUsage.keyedArrayStructuralAppendMapHints += queuedStructuralMapHintedRoot.structuralAppendMapCount;
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
const queuedStructuralPrependMapHintedRoot = rewriteQueuedKeyedArrayStructuralPrependMapHints(
|
|
6557
|
+
expandedReactiveRoot,
|
|
6558
|
+
statesBySetter,
|
|
6559
|
+
keyedMapUpdateIdentifier,
|
|
6560
|
+
keyedArrayMapPipelineIdentifier,
|
|
6561
|
+
keyedArrayPrependIdentifier,
|
|
6562
|
+
keyedArrayMappedStructuralPrependIdentifier,
|
|
6563
|
+
keyedArrayStructuralPrependMapPipelineIdentifier,
|
|
6564
|
+
keyedArrayFilterIdentifier,
|
|
6565
|
+
keyedArraySliceIdentifier,
|
|
6566
|
+
keyedArrayMappedStructuralIdentifier,
|
|
6567
|
+
allowKeyedArrayMapPipelines
|
|
6568
|
+
);
|
|
6569
|
+
let appliedQueuedStructuralPrependMapHints = 0;
|
|
6570
|
+
if (queuedStructuralPrependMapHintedRoot.structuralPrependMapCount > 0 || queuedStructuralPrependMapHintedRoot.mappedStructuralPrependCount > 0) {
|
|
6571
|
+
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
6572
|
+
queuedStructuralPrependMapHintedRoot.root,
|
|
6573
|
+
reactiveByValue,
|
|
6574
|
+
safeGlobals,
|
|
6575
|
+
listNames,
|
|
6576
|
+
allowedComponentNames
|
|
6577
|
+
);
|
|
6578
|
+
const hintedAnalysis = analyzeHostTree(
|
|
6579
|
+
queuedStructuralPrependMapHintedRoot.root,
|
|
6580
|
+
reactiveByValue,
|
|
6581
|
+
safeGlobals,
|
|
6582
|
+
hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
|
|
6583
|
+
hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
|
|
6584
|
+
hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
|
|
6585
|
+
hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
|
|
6586
|
+
);
|
|
6587
|
+
if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
|
|
6588
|
+
expandedReactiveRoot = queuedStructuralPrependMapHintedRoot.root;
|
|
6589
|
+
blockAnalysis = hintedBlockAnalysis;
|
|
6590
|
+
analysis = hintedAnalysis;
|
|
6591
|
+
appliedQueuedStructuralPrependMapHints = queuedStructuralPrependMapHintedRoot.structuralPrependMapCount + queuedStructuralPrependMapHintedRoot.mappedStructuralPrependCount;
|
|
6592
|
+
compilerUsage.keyedArrayMappedStructuralPrependHints += queuedStructuralPrependMapHintedRoot.mappedStructuralPrependCount;
|
|
6593
|
+
compilerUsage.keyedArrayStructuralPrependMapHints += queuedStructuralPrependMapHintedRoot.structuralPrependMapCount;
|
|
6594
|
+
}
|
|
6595
|
+
}
|
|
6596
|
+
const queuedMapReorderHintedRoot = rewriteQueuedKeyedArrayMapReorderHints(
|
|
6597
|
+
expandedReactiveRoot,
|
|
6598
|
+
statesBySetter,
|
|
6599
|
+
keyedMapUpdateIdentifier,
|
|
6600
|
+
keyedArrayQueuedMapPipelineIdentifier,
|
|
6601
|
+
keyedArrayMapReorderIdentifier,
|
|
6602
|
+
keyedArrayReorderIdentifier,
|
|
6603
|
+
keyedArraySortIdentifier,
|
|
6604
|
+
keyedArrayStructuralReorderIdentifier,
|
|
6605
|
+
keyedArrayStructuralSortIdentifier,
|
|
6606
|
+
allowKeyedArrayMapPipelines
|
|
6607
|
+
);
|
|
6608
|
+
const queuedReorderMapHintedRoot = rewriteQueuedKeyedArrayReorderMapHints(
|
|
6609
|
+
queuedMapReorderHintedRoot.root,
|
|
6610
|
+
statesBySetter,
|
|
6611
|
+
keyedMapUpdateIdentifier,
|
|
6612
|
+
keyedArrayQueuedMapPipelineIdentifier,
|
|
6613
|
+
keyedArrayMapReorderIdentifier,
|
|
6614
|
+
keyedArrayReorderIdentifier,
|
|
6615
|
+
keyedArraySortIdentifier,
|
|
6616
|
+
keyedArrayStructuralReorderIdentifier,
|
|
6617
|
+
keyedArrayStructuralSortIdentifier,
|
|
6618
|
+
allowKeyedArrayMapPipelines
|
|
6619
|
+
);
|
|
6620
|
+
let appliedQueuedReorderMapHints = 0;
|
|
6621
|
+
const queuedMapCount = queuedMapReorderHintedRoot.mapCount + queuedReorderMapHintedRoot.mapCount;
|
|
6622
|
+
const queuedMapReorderCount = queuedMapReorderHintedRoot.mapReorderCount + queuedMapReorderHintedRoot.mapSortCount;
|
|
6623
|
+
if (queuedMapCount > 0 || queuedMapReorderCount > 0) {
|
|
6624
|
+
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
6625
|
+
queuedReorderMapHintedRoot.root,
|
|
6626
|
+
reactiveByValue,
|
|
6627
|
+
safeGlobals,
|
|
6628
|
+
listNames,
|
|
6629
|
+
allowedComponentNames
|
|
6630
|
+
);
|
|
6631
|
+
const hintedAnalysis = analyzeHostTree(
|
|
6632
|
+
queuedReorderMapHintedRoot.root,
|
|
6633
|
+
reactiveByValue,
|
|
6634
|
+
safeGlobals,
|
|
6635
|
+
hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
|
|
6636
|
+
hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
|
|
6637
|
+
hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
|
|
6638
|
+
hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
|
|
6639
|
+
);
|
|
6640
|
+
if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
|
|
6641
|
+
expandedReactiveRoot = queuedReorderMapHintedRoot.root;
|
|
6642
|
+
blockAnalysis = hintedBlockAnalysis;
|
|
6643
|
+
analysis = hintedAnalysis;
|
|
6644
|
+
appliedQueuedReorderMapHints = queuedMapCount + queuedMapReorderCount;
|
|
6645
|
+
compilerUsage.keyedArrayMapUpdateHints += queuedMapCount;
|
|
6646
|
+
compilerUsage.keyedArrayQueuedMapUpdateHints += queuedMapCount;
|
|
6647
|
+
compilerUsage.keyedArrayMapReorderHints += queuedMapReorderHintedRoot.mapReorderCount;
|
|
6648
|
+
compilerUsage.keyedArrayMapSortHints += queuedMapReorderHintedRoot.mapSortCount;
|
|
6649
|
+
}
|
|
6650
|
+
}
|
|
6651
|
+
const queuedStructuralReorderHintedRoot = rewriteQueuedKeyedArrayStructuralReorderHints(
|
|
6652
|
+
expandedReactiveRoot,
|
|
6653
|
+
statesBySetter,
|
|
6654
|
+
keyedArrayFilterIdentifier,
|
|
6655
|
+
keyedArraySliceIdentifier,
|
|
6656
|
+
keyedArrayMapPipelineIdentifier,
|
|
6657
|
+
keyedArrayQueuedMapPipelineIdentifier,
|
|
6658
|
+
keyedArrayMappedStructuralIdentifier,
|
|
6659
|
+
keyedArrayMapReorderIdentifier,
|
|
6660
|
+
keyedArrayReorderIdentifier,
|
|
6661
|
+
keyedArraySortIdentifier,
|
|
6662
|
+
keyedArrayStructuralReorderIdentifier,
|
|
6663
|
+
keyedArrayStructuralSortIdentifier,
|
|
6664
|
+
allowKeyedArrayMapPipelines
|
|
6665
|
+
);
|
|
6666
|
+
if (queuedStructuralReorderHintedRoot.reorderCount > 0 || queuedStructuralReorderHintedRoot.sortCount > 0 || queuedStructuralReorderHintedRoot.replacedQueuedMapCount > 0) {
|
|
6667
|
+
const hintedBlockAnalysis = analyzeComposableBlocks(
|
|
6668
|
+
queuedStructuralReorderHintedRoot.root,
|
|
6669
|
+
reactiveByValue,
|
|
6670
|
+
safeGlobals,
|
|
6671
|
+
listNames,
|
|
6672
|
+
allowedComponentNames
|
|
6673
|
+
);
|
|
6674
|
+
const hintedAnalysis = analyzeHostTree(
|
|
6675
|
+
queuedStructuralReorderHintedRoot.root,
|
|
6676
|
+
reactiveByValue,
|
|
6677
|
+
safeGlobals,
|
|
6678
|
+
hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
|
|
6679
|
+
hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
|
|
6680
|
+
hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
|
|
6681
|
+
hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
|
|
6682
|
+
);
|
|
6683
|
+
if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
|
|
6684
|
+
expandedReactiveRoot = queuedStructuralReorderHintedRoot.root;
|
|
6685
|
+
blockAnalysis = hintedBlockAnalysis;
|
|
6686
|
+
analysis = hintedAnalysis;
|
|
6687
|
+
compilerUsage.keyedArrayQueuedMapUpdateHints -= queuedStructuralReorderHintedRoot.replacedQueuedMapCount;
|
|
6688
|
+
compilerUsage.keyedArrayMapReorderHints -= queuedStructuralReorderHintedRoot.replacedMapReorderCount;
|
|
6689
|
+
compilerUsage.keyedArrayMapSortHints -= queuedStructuralReorderHintedRoot.replacedMapSortCount;
|
|
6690
|
+
compilerUsage.keyedArrayStructuralReorderHints += queuedStructuralReorderHintedRoot.reorderCount;
|
|
6691
|
+
compilerUsage.keyedArrayStructuralSortHints += queuedStructuralReorderHintedRoot.sortCount;
|
|
6692
|
+
}
|
|
6693
|
+
}
|
|
5362
6694
|
const keyedCollectionTargetKinds = /* @__PURE__ */ new Map();
|
|
5363
6695
|
const conflictingKeyedCollectionTargets = /* @__PURE__ */ new Set();
|
|
5364
6696
|
for (const plan of blockAnalysis.plans || []) {
|
|
@@ -5430,9 +6762,16 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
5430
6762
|
blockPlans,
|
|
5431
6763
|
hasKeyedUpdateHints,
|
|
5432
6764
|
hasKeyedArrayRemovalHints,
|
|
6765
|
+
appliedKeyedArrayAppendHints > 0 && (appliedKeyedArrayFilterHints > 0 || appliedKeyedArraySliceHints > 0),
|
|
6766
|
+
appliedQueuedStructuralAppendMapHints > 0,
|
|
5433
6767
|
appliedKeyedArrayPrependHints > 0,
|
|
6768
|
+
appliedKeyedArrayPrependHints > 0 && hasKeyedArrayRemovalHints,
|
|
6769
|
+
appliedQueuedStructuralPrependMapHints > 0,
|
|
5434
6770
|
appliedKeyedArrayPositionHints > 0,
|
|
6771
|
+
appliedKeyedArrayBatchInsertHints > 0,
|
|
6772
|
+
appliedKeyedArrayWindowReplaceHints > 0,
|
|
5435
6773
|
appliedKeyedArrayReorderHints > 0 || appliedKeyedArraySortHints > 0,
|
|
6774
|
+
appliedPipelineMapHints > 0 || appliedQueuedReorderMapHints > 0 || appliedQueuedMappedStructuralHints > 0 || appliedQueuedStructuralMapHints > 0,
|
|
5436
6775
|
appliedKeyedArrayRollingWindowHints > 0
|
|
5437
6776
|
);
|
|
5438
6777
|
markShortCircuitBindings(analysis.bindings || []);
|
|
@@ -5614,6 +6953,21 @@ async function compileReactModule(code, id, options) {
|
|
|
5614
6953
|
keyedMembershipTargets: 0,
|
|
5615
6954
|
keyedMapUpdateHints: 0
|
|
5616
6955
|
};
|
|
6956
|
+
const compilerUsage = {
|
|
6957
|
+
keyedArrayBatchInsertHints: 0,
|
|
6958
|
+
keyedArrayMapReorderHints: 0,
|
|
6959
|
+
keyedArrayMapSortHints: 0,
|
|
6960
|
+
keyedArrayMapUpdateHints: 0,
|
|
6961
|
+
keyedArrayMappedStructuralHints: 0,
|
|
6962
|
+
keyedArrayMappedStructuralAppendHints: 0,
|
|
6963
|
+
keyedArrayMappedStructuralPrependHints: 0,
|
|
6964
|
+
keyedArrayQueuedMapUpdateHints: 0,
|
|
6965
|
+
keyedArrayStructuralAppendMapHints: 0,
|
|
6966
|
+
keyedArrayStructuralPrependMapHints: 0,
|
|
6967
|
+
keyedArrayStructuralReorderHints: 0,
|
|
6968
|
+
keyedArrayStructuralSortHints: 0,
|
|
6969
|
+
keyedArrayWindowReplaceHints: 0
|
|
6970
|
+
};
|
|
5617
6971
|
const plugin = () => ({
|
|
5618
6972
|
name: "farm-react-aot",
|
|
5619
6973
|
visitor: {
|
|
@@ -5652,18 +7006,54 @@ async function compileReactModule(code, id, options) {
|
|
|
5652
7006
|
const keyedArrayFilterIdentifier = programPath.scope.generateUidIdentifier(
|
|
5653
7007
|
"createCompilerKeyedArrayFilter"
|
|
5654
7008
|
);
|
|
7009
|
+
const keyedArrayMapPipelineIdentifier = programPath.scope.generateUidIdentifier(
|
|
7010
|
+
"createCompilerKeyedArrayMapPipeline"
|
|
7011
|
+
);
|
|
7012
|
+
const keyedArrayMappedStructuralAppendIdentifier = programPath.scope.generateUidIdentifier(
|
|
7013
|
+
"createCompilerKeyedArrayMappedStructuralAppend"
|
|
7014
|
+
);
|
|
7015
|
+
const keyedArrayStructuralAppendMapPipelineIdentifier = programPath.scope.generateUidIdentifier(
|
|
7016
|
+
"createCompilerKeyedArrayStructuralAppendMapPipeline"
|
|
7017
|
+
);
|
|
7018
|
+
const keyedArrayMappedStructuralPrependIdentifier = programPath.scope.generateUidIdentifier(
|
|
7019
|
+
"createCompilerKeyedArrayMappedStructuralPrepend"
|
|
7020
|
+
);
|
|
7021
|
+
const keyedArrayStructuralPrependMapPipelineIdentifier = programPath.scope.generateUidIdentifier(
|
|
7022
|
+
"createCompilerKeyedArrayStructuralPrependMapPipeline"
|
|
7023
|
+
);
|
|
7024
|
+
const keyedArrayQueuedMapPipelineIdentifier = programPath.scope.generateUidIdentifier(
|
|
7025
|
+
"createCompilerKeyedArrayQueuedMapPipeline"
|
|
7026
|
+
);
|
|
7027
|
+
const keyedArrayMapReorderIdentifier = programPath.scope.generateUidIdentifier(
|
|
7028
|
+
"createCompilerKeyedArrayMapReorder"
|
|
7029
|
+
);
|
|
7030
|
+
const keyedArrayMappedStructuralIdentifier = programPath.scope.generateUidIdentifier(
|
|
7031
|
+
"finalizeCompilerKeyedArrayMappedStructuralUpdate"
|
|
7032
|
+
);
|
|
5655
7033
|
const keyedArrayPrependIdentifier = programPath.scope.generateUidIdentifier(
|
|
5656
7034
|
"createCompilerKeyedArrayPrepend"
|
|
5657
7035
|
);
|
|
5658
7036
|
const keyedArrayPositionIdentifier = programPath.scope.generateUidIdentifier(
|
|
5659
7037
|
"createCompilerKeyedArrayPositionUpdate"
|
|
5660
7038
|
);
|
|
7039
|
+
const keyedArrayBatchInsertIdentifier = programPath.scope.generateUidIdentifier(
|
|
7040
|
+
"createCompilerKeyedArrayBatchInsert"
|
|
7041
|
+
);
|
|
7042
|
+
const keyedArrayWindowReplaceIdentifier = programPath.scope.generateUidIdentifier(
|
|
7043
|
+
"createCompilerKeyedArrayWindowReplace"
|
|
7044
|
+
);
|
|
5661
7045
|
const keyedArrayReorderIdentifier = programPath.scope.generateUidIdentifier(
|
|
5662
7046
|
"createCompilerKeyedArrayReorder"
|
|
5663
7047
|
);
|
|
7048
|
+
const keyedArrayStructuralReorderIdentifier = programPath.scope.generateUidIdentifier(
|
|
7049
|
+
"createCompilerKeyedArrayStructuralReorder"
|
|
7050
|
+
);
|
|
5664
7051
|
const keyedArraySortIdentifier = programPath.scope.generateUidIdentifier(
|
|
5665
7052
|
"createCompilerKeyedArraySort"
|
|
5666
7053
|
);
|
|
7054
|
+
const keyedArrayStructuralSortIdentifier = programPath.scope.generateUidIdentifier(
|
|
7055
|
+
"createCompilerKeyedArrayStructuralSort"
|
|
7056
|
+
);
|
|
5667
7057
|
const keyedArrayRollingWindowIdentifier = programPath.scope.generateUidIdentifier(
|
|
5668
7058
|
"createCompilerKeyedArrayRollingWindow"
|
|
5669
7059
|
);
|
|
@@ -5696,10 +7086,22 @@ async function compileReactModule(code, id, options) {
|
|
|
5696
7086
|
keyedMapUpdateIdentifier,
|
|
5697
7087
|
keyedArrayAppendIdentifier,
|
|
5698
7088
|
keyedArrayFilterIdentifier,
|
|
7089
|
+
keyedArrayMapPipelineIdentifier,
|
|
7090
|
+
keyedArrayMappedStructuralAppendIdentifier,
|
|
7091
|
+
keyedArrayStructuralAppendMapPipelineIdentifier,
|
|
7092
|
+
keyedArrayMappedStructuralPrependIdentifier,
|
|
7093
|
+
keyedArrayStructuralPrependMapPipelineIdentifier,
|
|
7094
|
+
keyedArrayQueuedMapPipelineIdentifier,
|
|
7095
|
+
keyedArrayMapReorderIdentifier,
|
|
7096
|
+
keyedArrayMappedStructuralIdentifier,
|
|
5699
7097
|
keyedArrayPrependIdentifier,
|
|
5700
7098
|
keyedArrayPositionIdentifier,
|
|
7099
|
+
keyedArrayBatchInsertIdentifier,
|
|
7100
|
+
keyedArrayWindowReplaceIdentifier,
|
|
5701
7101
|
keyedArrayReorderIdentifier,
|
|
7102
|
+
keyedArrayStructuralReorderIdentifier,
|
|
5702
7103
|
keyedArraySortIdentifier,
|
|
7104
|
+
keyedArrayStructuralSortIdentifier,
|
|
5703
7105
|
keyedArrayRollingWindowIdentifier,
|
|
5704
7106
|
keyedArraySliceIdentifier,
|
|
5705
7107
|
keyedCollectionUpdateIdentifier,
|
|
@@ -5707,6 +7109,7 @@ async function compileReactModule(code, id, options) {
|
|
|
5707
7109
|
runtimeFeatureIdentifiers,
|
|
5708
7110
|
usedRuntimeFeatures,
|
|
5709
7111
|
optimizationCounts,
|
|
7112
|
+
compilerUsage,
|
|
5710
7113
|
useStateNames,
|
|
5711
7114
|
reactNames,
|
|
5712
7115
|
listNames,
|
|
@@ -5723,6 +7126,12 @@ async function compileReactModule(code, id, options) {
|
|
|
5723
7126
|
compiled.push(candidate.name);
|
|
5724
7127
|
}
|
|
5725
7128
|
}
|
|
7129
|
+
const hasEagerKeyedArrayMapUpdateHints = compilerUsage.keyedArrayMapUpdateHints > compilerUsage.keyedArrayQueuedMapUpdateHints + compilerUsage.keyedArrayStructuralAppendMapHints + compilerUsage.keyedArrayStructuralPrependMapHints;
|
|
7130
|
+
const hasKeyedArrayMapReorderHints = compilerUsage.keyedArrayMapReorderHints + compilerUsage.keyedArrayMapSortHints > 0;
|
|
7131
|
+
const hasKeyedArrayStructuralAppendHints = optimizationCounts.keyedArrayAppendHints > 0 && (optimizationCounts.keyedArrayFilterHints > 0 || optimizationCounts.keyedArraySliceHints > 0);
|
|
7132
|
+
const hasUnmappedKeyedArrayAppendHints = optimizationCounts.keyedArrayAppendHints > compilerUsage.keyedArrayMappedStructuralAppendHints;
|
|
7133
|
+
const hasKeyedArrayStructuralPrependHints = optimizationCounts.keyedArrayPrependHints > 0 && (optimizationCounts.keyedArrayFilterHints > 0 || optimizationCounts.keyedArraySliceHints > 0);
|
|
7134
|
+
const hasUnmappedKeyedArrayPrependHints = optimizationCounts.keyedArrayPrependHints > compilerUsage.keyedArrayMappedStructuralPrependHints;
|
|
5726
7135
|
if (compiled.length > 0) {
|
|
5727
7136
|
programPath.unshiftContainer(
|
|
5728
7137
|
"body",
|
|
@@ -5732,16 +7141,66 @@ async function compileReactModule(code, id, options) {
|
|
|
5732
7141
|
createComponentIdentifier,
|
|
5733
7142
|
core.types.identifier("createCompiledComponentWithFeatures")
|
|
5734
7143
|
),
|
|
5735
|
-
...optimizationCounts.keyedMapUpdateHints >
|
|
7144
|
+
...optimizationCounts.keyedMapUpdateHints > compilerUsage.keyedArrayMapUpdateHints ? [
|
|
5736
7145
|
core.types.importSpecifier(
|
|
5737
7146
|
keyedMapUpdateIdentifier,
|
|
5738
7147
|
core.types.identifier("createCompilerKeyedMapUpdate")
|
|
5739
7148
|
)
|
|
5740
7149
|
] : [],
|
|
5741
|
-
...
|
|
7150
|
+
...hasEagerKeyedArrayMapUpdateHints ? [
|
|
7151
|
+
core.types.importSpecifier(
|
|
7152
|
+
keyedArrayMapPipelineIdentifier,
|
|
7153
|
+
core.types.identifier("createCompilerKeyedArrayMapPipeline")
|
|
7154
|
+
)
|
|
7155
|
+
] : [],
|
|
7156
|
+
...compilerUsage.keyedArrayStructuralAppendMapHints > 0 ? [
|
|
7157
|
+
core.types.importSpecifier(
|
|
7158
|
+
keyedArrayStructuralAppendMapPipelineIdentifier,
|
|
7159
|
+
core.types.identifier("createCompilerKeyedArrayStructuralAppendMapPipeline")
|
|
7160
|
+
)
|
|
7161
|
+
] : [],
|
|
7162
|
+
...compilerUsage.keyedArrayStructuralPrependMapHints > 0 ? [
|
|
7163
|
+
core.types.importSpecifier(
|
|
7164
|
+
keyedArrayStructuralPrependMapPipelineIdentifier,
|
|
7165
|
+
core.types.identifier("createCompilerKeyedArrayStructuralPrependMapPipeline")
|
|
7166
|
+
)
|
|
7167
|
+
] : [],
|
|
7168
|
+
...hasKeyedArrayMapReorderHints ? [
|
|
7169
|
+
core.types.importSpecifier(
|
|
7170
|
+
keyedArrayMapReorderIdentifier,
|
|
7171
|
+
core.types.identifier("createCompilerKeyedArrayMapReorder")
|
|
7172
|
+
)
|
|
7173
|
+
] : [],
|
|
7174
|
+
...compilerUsage.keyedArrayMappedStructuralHints > 0 ? [
|
|
7175
|
+
core.types.importSpecifier(
|
|
7176
|
+
keyedArrayMappedStructuralIdentifier,
|
|
7177
|
+
core.types.identifier("finalizeCompilerKeyedArrayMappedStructuralUpdate")
|
|
7178
|
+
)
|
|
7179
|
+
] : [],
|
|
7180
|
+
...compilerUsage.keyedArrayMappedStructuralAppendHints > 0 ? [
|
|
7181
|
+
core.types.importSpecifier(
|
|
7182
|
+
keyedArrayMappedStructuralAppendIdentifier,
|
|
7183
|
+
core.types.identifier("createCompilerKeyedArrayMappedStructuralAppend")
|
|
7184
|
+
)
|
|
7185
|
+
] : [],
|
|
7186
|
+
...compilerUsage.keyedArrayMappedStructuralPrependHints > 0 ? [
|
|
7187
|
+
core.types.importSpecifier(
|
|
7188
|
+
keyedArrayMappedStructuralPrependIdentifier,
|
|
7189
|
+
core.types.identifier("createCompilerKeyedArrayMappedStructuralPrepend")
|
|
7190
|
+
)
|
|
7191
|
+
] : [],
|
|
7192
|
+
...compilerUsage.keyedArrayQueuedMapUpdateHints > 0 ? [
|
|
7193
|
+
core.types.importSpecifier(
|
|
7194
|
+
keyedArrayQueuedMapPipelineIdentifier,
|
|
7195
|
+
core.types.identifier("createCompilerKeyedArrayQueuedMapPipeline")
|
|
7196
|
+
)
|
|
7197
|
+
] : [],
|
|
7198
|
+
...hasUnmappedKeyedArrayAppendHints ? [
|
|
5742
7199
|
core.types.importSpecifier(
|
|
5743
7200
|
keyedArrayAppendIdentifier,
|
|
5744
|
-
core.types.identifier(
|
|
7201
|
+
core.types.identifier(
|
|
7202
|
+
hasKeyedArrayStructuralAppendHints ? "createCompilerKeyedArrayStructuralAppend" : "createCompilerKeyedArrayAppend"
|
|
7203
|
+
)
|
|
5745
7204
|
)
|
|
5746
7205
|
] : [],
|
|
5747
7206
|
...optimizationCounts.keyedArrayFilterHints > 0 ? [
|
|
@@ -5750,30 +7209,56 @@ async function compileReactModule(code, id, options) {
|
|
|
5750
7209
|
core.types.identifier("createCompilerKeyedArrayFilter")
|
|
5751
7210
|
)
|
|
5752
7211
|
] : [],
|
|
5753
|
-
...
|
|
7212
|
+
...hasUnmappedKeyedArrayPrependHints ? [
|
|
5754
7213
|
core.types.importSpecifier(
|
|
5755
7214
|
keyedArrayPrependIdentifier,
|
|
5756
|
-
core.types.identifier(
|
|
7215
|
+
core.types.identifier(
|
|
7216
|
+
hasKeyedArrayStructuralPrependHints ? "createCompilerKeyedArrayStructuralPrepend" : "createCompilerKeyedArrayPrepend"
|
|
7217
|
+
)
|
|
5757
7218
|
)
|
|
5758
7219
|
] : [],
|
|
5759
|
-
...optimizationCounts.keyedArrayPositionHints >
|
|
7220
|
+
...optimizationCounts.keyedArrayPositionHints > compilerUsage.keyedArrayBatchInsertHints + compilerUsage.keyedArrayWindowReplaceHints ? [
|
|
5760
7221
|
core.types.importSpecifier(
|
|
5761
7222
|
keyedArrayPositionIdentifier,
|
|
5762
7223
|
core.types.identifier("createCompilerKeyedArrayPositionUpdate")
|
|
5763
7224
|
)
|
|
5764
7225
|
] : [],
|
|
5765
|
-
...
|
|
7226
|
+
...compilerUsage.keyedArrayBatchInsertHints > 0 ? [
|
|
7227
|
+
core.types.importSpecifier(
|
|
7228
|
+
keyedArrayBatchInsertIdentifier,
|
|
7229
|
+
core.types.identifier("createCompilerKeyedArrayBatchInsert")
|
|
7230
|
+
)
|
|
7231
|
+
] : [],
|
|
7232
|
+
...compilerUsage.keyedArrayWindowReplaceHints > 0 ? [
|
|
7233
|
+
core.types.importSpecifier(
|
|
7234
|
+
keyedArrayWindowReplaceIdentifier,
|
|
7235
|
+
core.types.identifier("createCompilerKeyedArrayWindowReplace")
|
|
7236
|
+
)
|
|
7237
|
+
] : [],
|
|
7238
|
+
...optimizationCounts.keyedArrayReorderHints > compilerUsage.keyedArrayStructuralReorderHints + compilerUsage.keyedArrayMapReorderHints ? [
|
|
5766
7239
|
core.types.importSpecifier(
|
|
5767
7240
|
keyedArrayReorderIdentifier,
|
|
5768
7241
|
core.types.identifier("createCompilerKeyedArrayReorder")
|
|
5769
7242
|
)
|
|
5770
7243
|
] : [],
|
|
5771
|
-
...
|
|
7244
|
+
...compilerUsage.keyedArrayStructuralReorderHints > 0 ? [
|
|
7245
|
+
core.types.importSpecifier(
|
|
7246
|
+
keyedArrayStructuralReorderIdentifier,
|
|
7247
|
+
core.types.identifier("createCompilerKeyedArrayStructuralReorder")
|
|
7248
|
+
)
|
|
7249
|
+
] : [],
|
|
7250
|
+
...optimizationCounts.keyedArraySortHints > compilerUsage.keyedArrayStructuralSortHints + compilerUsage.keyedArrayMapSortHints ? [
|
|
5772
7251
|
core.types.importSpecifier(
|
|
5773
7252
|
keyedArraySortIdentifier,
|
|
5774
7253
|
core.types.identifier("createCompilerKeyedArraySort")
|
|
5775
7254
|
)
|
|
5776
7255
|
] : [],
|
|
7256
|
+
...compilerUsage.keyedArrayStructuralSortHints > 0 ? [
|
|
7257
|
+
core.types.importSpecifier(
|
|
7258
|
+
keyedArrayStructuralSortIdentifier,
|
|
7259
|
+
core.types.identifier("createCompilerKeyedArrayStructuralSort")
|
|
7260
|
+
)
|
|
7261
|
+
] : [],
|
|
5777
7262
|
...optimizationCounts.keyedArrayRollingWindowHints > 0 ? [
|
|
5778
7263
|
core.types.importSpecifier(
|
|
5779
7264
|
keyedArrayRollingWindowIdentifier,
|
|
@@ -5914,12 +7399,46 @@ function createReactCompilerReport(projectRoot, observations) {
|
|
|
5914
7399
|
}
|
|
5915
7400
|
async function writeReactCompilerReport(projectRoot, reportFile, observations) {
|
|
5916
7401
|
const outputPath = path.resolve(projectRoot, reportFile);
|
|
7402
|
+
await assertReportPathInsideProject(projectRoot, outputPath);
|
|
5917
7403
|
const report = createReactCompilerReport(projectRoot, observations);
|
|
5918
7404
|
await promises.mkdir(path.dirname(outputPath), { recursive: true });
|
|
5919
7405
|
await promises.writeFile(outputPath, `${JSON.stringify(report, null, 2)}
|
|
5920
7406
|
`, "utf8");
|
|
5921
7407
|
return outputPath;
|
|
5922
7408
|
}
|
|
7409
|
+
async function assertReportPathInsideProject(projectRoot, outputPath) {
|
|
7410
|
+
const realProjectRoot = await promises.realpath(projectRoot);
|
|
7411
|
+
let existingAncestor = outputPath;
|
|
7412
|
+
while (true) {
|
|
7413
|
+
try {
|
|
7414
|
+
existingAncestor = await promises.realpath(existingAncestor);
|
|
7415
|
+
break;
|
|
7416
|
+
} catch (error) {
|
|
7417
|
+
if (error.code !== "ENOENT") throw error;
|
|
7418
|
+
let existingEntry = false;
|
|
7419
|
+
try {
|
|
7420
|
+
await promises.lstat(existingAncestor);
|
|
7421
|
+
existingEntry = true;
|
|
7422
|
+
} catch (statError) {
|
|
7423
|
+
if (statError.code !== "ENOENT") throw statError;
|
|
7424
|
+
}
|
|
7425
|
+
if (existingEntry) {
|
|
7426
|
+
throw new Error(
|
|
7427
|
+
"The React compiler report file must stay inside the project root, including through symlinks."
|
|
7428
|
+
);
|
|
7429
|
+
}
|
|
7430
|
+
const parent = path.dirname(existingAncestor);
|
|
7431
|
+
if (parent === existingAncestor) throw error;
|
|
7432
|
+
existingAncestor = parent;
|
|
7433
|
+
}
|
|
7434
|
+
}
|
|
7435
|
+
const relativePath = path.relative(realProjectRoot, existingAncestor);
|
|
7436
|
+
if (relativePath === ".." || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath)) {
|
|
7437
|
+
throw new Error(
|
|
7438
|
+
"The React compiler report file must stay inside the project root, including through symlinks."
|
|
7439
|
+
);
|
|
7440
|
+
}
|
|
7441
|
+
}
|
|
5923
7442
|
|
|
5924
7443
|
// src/index.ts
|
|
5925
7444
|
var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|