@farm.js/react 0.1.0-beta.26 → 0.1.0-beta.28
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/dist/compiler-runtime.cjs +76 -95
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.mjs +76 -95
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/list.cjs +1 -1
- package/dist/list.cjs.map +1 -1
- package/dist/list.mjs +1 -1
- package/dist/list.mjs.map +1 -1
- package/dist/vite.cjs +173 -45
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.mts +2 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.mjs +173 -45
- package/dist/vite.mjs.map +1 -1
- package/package.json +5 -5
package/dist/vite.d.mts
CHANGED
|
@@ -2,6 +2,8 @@ import { Plugin } from 'vite';
|
|
|
2
2
|
|
|
3
3
|
interface RendererPluginOptions {
|
|
4
4
|
ssr?: boolean;
|
|
5
|
+
/** Build-owned disposal signal shared by discovery, client and SSR graphs. */
|
|
6
|
+
buildLifetime?: AbortSignal;
|
|
5
7
|
rendererOptions?: Readonly<Record<string, unknown>>;
|
|
6
8
|
}
|
|
7
9
|
declare function createFarmRendererPlugin(options?: RendererPluginOptions): Plugin[];
|
package/dist/vite.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Plugin } from 'vite';
|
|
|
2
2
|
|
|
3
3
|
interface RendererPluginOptions {
|
|
4
4
|
ssr?: boolean;
|
|
5
|
+
/** Build-owned disposal signal shared by discovery, client and SSR graphs. */
|
|
6
|
+
buildLifetime?: AbortSignal;
|
|
5
7
|
rendererOptions?: Readonly<Record<string, unknown>>;
|
|
6
8
|
}
|
|
7
9
|
declare function createFarmRendererPlugin(options?: RendererPluginOptions): Plugin[];
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizePath } from 'vite';
|
|
2
2
|
import { transformAsync, types, traverse } from '@babel/core';
|
|
3
|
+
import { serialize, deserialize } from 'v8';
|
|
3
4
|
import { mkdir, writeFile, realpath, lstat } from 'fs/promises';
|
|
4
5
|
import { resolve, dirname, relative, sep, isAbsolute } from 'path';
|
|
5
6
|
|
|
@@ -218,21 +219,39 @@ function expressionFile(expression) {
|
|
|
218
219
|
return types.file(types.program([types.expressionStatement(expression)]));
|
|
219
220
|
}
|
|
220
221
|
function collectStateDependencies(expression, statesByValue) {
|
|
222
|
+
if (statesByValue.size === 0) return [];
|
|
223
|
+
let possible = false;
|
|
224
|
+
types.traverseFast(expression, (node) => {
|
|
225
|
+
if ((types.isIdentifier(node) || types.isJSXIdentifier(node)) && statesByValue.has(node.name)) {
|
|
226
|
+
possible = true;
|
|
227
|
+
return types.traverseFast.stop;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (!possible) return [];
|
|
221
231
|
const dependencies = /* @__PURE__ */ new Set();
|
|
222
232
|
const file = expressionFile(cloneExpression(expression));
|
|
223
233
|
traverse(file, {
|
|
224
234
|
ReferencedIdentifier(path) {
|
|
225
235
|
const state = statesByValue.get(path.node.name);
|
|
226
|
-
if (state && !path.scope.hasBinding(path.node.name))
|
|
236
|
+
if (state && !path.scope.hasBinding(path.node.name, { noGlobals: true }))
|
|
237
|
+
dependencies.add(state.index);
|
|
227
238
|
}
|
|
228
239
|
});
|
|
229
240
|
return [...dependencies].sort((left, right) => left - right);
|
|
230
241
|
}
|
|
231
242
|
function referencesIdentifier(expression, name) {
|
|
243
|
+
let possible = false;
|
|
244
|
+
types.traverseFast(expression, (node) => {
|
|
245
|
+
if ((types.isIdentifier(node) || types.isJSXIdentifier(node)) && node.name === name) {
|
|
246
|
+
possible = true;
|
|
247
|
+
return types.traverseFast.stop;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (!possible) return false;
|
|
232
251
|
let referenced = false;
|
|
233
252
|
traverse(expressionFile(cloneExpression(expression)), {
|
|
234
253
|
ReferencedIdentifier(path) {
|
|
235
|
-
if (path.node.name === name && !path.scope.hasBinding(name)) {
|
|
254
|
+
if (path.node.name === name && !path.scope.hasBinding(name, { noGlobals: true })) {
|
|
236
255
|
referenced = true;
|
|
237
256
|
}
|
|
238
257
|
}
|
|
@@ -244,7 +263,7 @@ function rewriteFreeIdentifierNames(expression, replacements) {
|
|
|
244
263
|
const file = expressionFile(cloneExpression(expression));
|
|
245
264
|
traverse(file, {
|
|
246
265
|
ReferencedIdentifier(path) {
|
|
247
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
266
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
248
267
|
const replacement = replacements.get(path.node.name);
|
|
249
268
|
if (!replacement) return;
|
|
250
269
|
path.replaceWith(types.cloneNode(replacement));
|
|
@@ -273,7 +292,7 @@ function keyedIdentityTarget(binding, keyCallback, renderCallback, reactiveByVal
|
|
|
273
292
|
let comparisons = 0;
|
|
274
293
|
traverse(file, {
|
|
275
294
|
ReferencedIdentifier(path) {
|
|
276
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
295
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
277
296
|
const reactive = reactiveByValue.get(path.node.name);
|
|
278
297
|
if (!reactive) return;
|
|
279
298
|
if (reactive.index !== dependencies[0] || target && target !== reactive) {
|
|
@@ -355,7 +374,7 @@ function keyedMembershipTarget(binding, keyCallback, renderCallback, reactiveByV
|
|
|
355
374
|
let calls = 0;
|
|
356
375
|
traverse(file, {
|
|
357
376
|
ReferencedIdentifier(path) {
|
|
358
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
377
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
359
378
|
const reactive = reactiveByValue.get(path.node.name);
|
|
360
379
|
if (!reactive) return;
|
|
361
380
|
const member = path.parentPath;
|
|
@@ -391,7 +410,7 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
391
410
|
let calls = 0;
|
|
392
411
|
traverse(file, {
|
|
393
412
|
ReferencedIdentifier(path) {
|
|
394
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
413
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
395
414
|
const reactive = reactiveByValue.get(path.node.name);
|
|
396
415
|
if (!reactive) return;
|
|
397
416
|
const member = path.parentPath;
|
|
@@ -408,10 +427,11 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
408
427
|
return valid && target && calls > 0 ? { dependency: target.index, value: types.identifier(target.valueName) } : void 0;
|
|
409
428
|
}
|
|
410
429
|
function collectReferencedLocals(expression, names) {
|
|
430
|
+
if (names.size === 0) return [];
|
|
411
431
|
const references = /* @__PURE__ */ new Set();
|
|
412
432
|
traverse(expressionFile(cloneExpression(expression)), {
|
|
413
433
|
ReferencedIdentifier(path) {
|
|
414
|
-
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name)) {
|
|
434
|
+
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
415
435
|
references.add(path.node.name);
|
|
416
436
|
}
|
|
417
437
|
}
|
|
@@ -419,10 +439,11 @@ function collectReferencedLocals(expression, names) {
|
|
|
419
439
|
return [...references];
|
|
420
440
|
}
|
|
421
441
|
function rewriteDerivedAccess(expression, derivedByName) {
|
|
442
|
+
if (derivedByName.size === 0) return cloneExpression(expression);
|
|
422
443
|
const file = expressionFile(cloneExpression(expression));
|
|
423
444
|
traverse(file, {
|
|
424
445
|
ReferencedIdentifier(path) {
|
|
425
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
446
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
426
447
|
const derived = derivedByName.get(path.node.name);
|
|
427
448
|
if (!derived) return;
|
|
428
449
|
path.replaceWith(cloneExpression(derived));
|
|
@@ -436,7 +457,8 @@ function rewriteDestructuredPropAccess(expression, names, propsParameter) {
|
|
|
436
457
|
const file = expressionFile(cloneExpression(expression));
|
|
437
458
|
traverse(file, {
|
|
438
459
|
ReferencedIdentifier(path) {
|
|
439
|
-
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name))
|
|
460
|
+
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name, { noGlobals: true }))
|
|
461
|
+
return;
|
|
440
462
|
if (path.parentPath.isJSXOpeningElement() || path.parentPath.isJSXClosingElement()) return;
|
|
441
463
|
path.replaceWith(
|
|
442
464
|
types.memberExpression(types.cloneNode(propsParameter), types.identifier(path.node.name))
|
|
@@ -483,7 +505,7 @@ function rewriteHandlerAccess(root, handlersByName) {
|
|
|
483
505
|
let reason;
|
|
484
506
|
traverse(file, {
|
|
485
507
|
ReferencedIdentifier(path) {
|
|
486
|
-
if (reason || path.scope.hasBinding(path.node.name)) return;
|
|
508
|
+
if (reason || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
487
509
|
const handler = handlersByName.get(path.node.name);
|
|
488
510
|
if (!handler) return;
|
|
489
511
|
const container = path.parentPath;
|
|
@@ -561,7 +583,7 @@ function validateSetterUsage(root, statesBySetter) {
|
|
|
561
583
|
ReferencedIdentifier(path) {
|
|
562
584
|
if (reason) return;
|
|
563
585
|
const state = statesBySetter.get(path.node.name);
|
|
564
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
586
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
565
587
|
const parent = path.parentPath;
|
|
566
588
|
if (!parent.isCallExpression() || parent.node.callee !== path.node || !findContainingEvent(parent)) {
|
|
567
589
|
reason = `${state.setterName} must be called inside a JSX event handler`;
|
|
@@ -676,13 +698,14 @@ function keyedMapUpdatePipeline(expression, parameterName, safeGlobals) {
|
|
|
676
698
|
return outerCallbacks.reverse();
|
|
677
699
|
}
|
|
678
700
|
function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
679
|
-
if (hintedStateIndices.size === 0) return { root
|
|
701
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
680
702
|
const file = expressionFile(types.cloneNode(root, true));
|
|
681
703
|
let count = 0;
|
|
682
704
|
traverse(file, {
|
|
683
705
|
CallExpression(path) {
|
|
684
706
|
const callee = path.get("callee");
|
|
685
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
707
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
708
|
+
return;
|
|
686
709
|
const state = statesBySetter.get(callee.node.name);
|
|
687
710
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
688
711
|
return;
|
|
@@ -747,13 +770,14 @@ function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, he
|
|
|
747
770
|
};
|
|
748
771
|
}
|
|
749
772
|
function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
750
|
-
if (hintedStateIndices.size === 0) return { root
|
|
773
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
751
774
|
const file = expressionFile(types.cloneNode(root, true));
|
|
752
775
|
let count = 0;
|
|
753
776
|
traverse(file, {
|
|
754
777
|
CallExpression(path) {
|
|
755
778
|
const callee = path.get("callee");
|
|
756
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
779
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
780
|
+
return;
|
|
757
781
|
const state = statesBySetter.get(callee.node.name);
|
|
758
782
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
759
783
|
return;
|
|
@@ -818,7 +842,7 @@ function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter,
|
|
|
818
842
|
}
|
|
819
843
|
function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
820
844
|
if (hintedStateIndices.size === 0) {
|
|
821
|
-
return { root
|
|
845
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
822
846
|
}
|
|
823
847
|
const file = expressionFile(types.cloneNode(root, true));
|
|
824
848
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -826,7 +850,8 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
826
850
|
traverse(file, {
|
|
827
851
|
CallExpression(path) {
|
|
828
852
|
const callee = path.get("callee");
|
|
829
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
853
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
854
|
+
return;
|
|
830
855
|
const state = statesBySetter.get(callee.node.name);
|
|
831
856
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
832
857
|
return;
|
|
@@ -895,7 +920,7 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
895
920
|
}
|
|
896
921
|
function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesBySetter, sliceHelperIdentifier, rollingWindowHelperIdentifier, safeGlobals) {
|
|
897
922
|
if (hintedStateIndices.size === 0) {
|
|
898
|
-
return { root
|
|
923
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
899
924
|
}
|
|
900
925
|
const file = expressionFile(types.cloneNode(root, true));
|
|
901
926
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -903,7 +928,8 @@ function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesByS
|
|
|
903
928
|
traverse(file, {
|
|
904
929
|
CallExpression(path) {
|
|
905
930
|
const callee = path.get("callee");
|
|
906
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
931
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
932
|
+
return;
|
|
907
933
|
const state = statesBySetter.get(callee.node.name);
|
|
908
934
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
909
935
|
return;
|
|
@@ -1013,7 +1039,7 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
|
|
|
1013
1039
|
function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
|
|
1014
1040
|
if (hintedStateIndices.size === 0) {
|
|
1015
1041
|
return {
|
|
1016
|
-
root
|
|
1042
|
+
root,
|
|
1017
1043
|
count: 0,
|
|
1018
1044
|
batchInsertCount: 0,
|
|
1019
1045
|
windowReplaceCount: 0,
|
|
@@ -1028,7 +1054,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1028
1054
|
traverse(file, {
|
|
1029
1055
|
CallExpression(path) {
|
|
1030
1056
|
const callee = path.get("callee");
|
|
1031
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1057
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1058
|
+
return;
|
|
1032
1059
|
const state = statesBySetter.get(callee.node.name);
|
|
1033
1060
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1034
1061
|
return;
|
|
@@ -1109,7 +1136,7 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1109
1136
|
}
|
|
1110
1137
|
function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter, helperIdentifier) {
|
|
1111
1138
|
if (hintedStateIndices.size === 0) {
|
|
1112
|
-
return { root
|
|
1139
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
1113
1140
|
}
|
|
1114
1141
|
const file = expressionFile(types.cloneNode(root, true));
|
|
1115
1142
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -1117,7 +1144,8 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
|
|
|
1117
1144
|
traverse(file, {
|
|
1118
1145
|
CallExpression(path) {
|
|
1119
1146
|
const callee = path.get("callee");
|
|
1120
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1147
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1148
|
+
return;
|
|
1121
1149
|
const state = statesBySetter.get(callee.node.name);
|
|
1122
1150
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1123
1151
|
return;
|
|
@@ -1249,7 +1277,7 @@ function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
|
|
|
1249
1277
|
function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesBySetter, filterHelperIdentifier, mapHelperIdentifier, mapReorderHelperIdentifier, mappedStructuralHelperIdentifier, reorderHelperIdentifier, structuralReorderHelperIdentifier, sliceHelperIdentifier, sortHelperIdentifier, structuralSortHelperIdentifier, safeGlobals, allowMapPipelines) {
|
|
1250
1278
|
if (hintedStateIndices.size === 0) {
|
|
1251
1279
|
return {
|
|
1252
|
-
root
|
|
1280
|
+
root,
|
|
1253
1281
|
filterCount: 0,
|
|
1254
1282
|
mapCount: 0,
|
|
1255
1283
|
mapReorderCount: 0,
|
|
@@ -1278,7 +1306,8 @@ function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesB
|
|
|
1278
1306
|
traverse(file, {
|
|
1279
1307
|
CallExpression(path) {
|
|
1280
1308
|
const callee = path.get("callee");
|
|
1281
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1309
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1310
|
+
return;
|
|
1282
1311
|
const state = statesBySetter.get(callee.node.name);
|
|
1283
1312
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1284
1313
|
return;
|
|
@@ -1470,7 +1499,7 @@ function rewriteQueuedKeyedArrayReorderMapHints(root, statesBySetter, mapUpdateI
|
|
|
1470
1499
|
continue;
|
|
1471
1500
|
}
|
|
1472
1501
|
const setterCall = statement.expression;
|
|
1473
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1502
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1474
1503
|
queuedReorderState = void 0;
|
|
1475
1504
|
continue;
|
|
1476
1505
|
}
|
|
@@ -1565,7 +1594,7 @@ function rewriteQueuedKeyedArrayMappedStructuralHints(root, statesBySetter, mapU
|
|
|
1565
1594
|
continue;
|
|
1566
1595
|
}
|
|
1567
1596
|
const setterCall = statement.expression;
|
|
1568
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1597
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1569
1598
|
mappedStructuralState = void 0;
|
|
1570
1599
|
pendingMaps = [];
|
|
1571
1600
|
continue;
|
|
@@ -1677,7 +1706,7 @@ function rewriteQueuedKeyedArrayStructuralMapHints(root, statesBySetter, mapUpda
|
|
|
1677
1706
|
continue;
|
|
1678
1707
|
}
|
|
1679
1708
|
const setterCall = statement.expression;
|
|
1680
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1709
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1681
1710
|
structuralState = void 0;
|
|
1682
1711
|
structuralAppendState = void 0;
|
|
1683
1712
|
structuralMapState = void 0;
|
|
@@ -1801,7 +1830,7 @@ function rewriteQueuedKeyedArrayStructuralPrependMapHints(root, statesBySetter,
|
|
|
1801
1830
|
continue;
|
|
1802
1831
|
}
|
|
1803
1832
|
const setterCall = statement.expression;
|
|
1804
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1833
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1805
1834
|
structuralState = void 0;
|
|
1806
1835
|
structuralPrependState = void 0;
|
|
1807
1836
|
structuralMapState = void 0;
|
|
@@ -2000,7 +2029,7 @@ function rewriteQueuedKeyedArrayRollingWindowMapHints(root, statesBySetter, mapU
|
|
|
2000
2029
|
continue;
|
|
2001
2030
|
}
|
|
2002
2031
|
const setterCall = statement.expression;
|
|
2003
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2032
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2004
2033
|
flushSegment();
|
|
2005
2034
|
continue;
|
|
2006
2035
|
}
|
|
@@ -2064,7 +2093,7 @@ function rewriteQueuedKeyedArrayStructuralReorderHints(root, statesBySetter, fil
|
|
|
2064
2093
|
continue;
|
|
2065
2094
|
}
|
|
2066
2095
|
const setterCall = statement.expression;
|
|
2067
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2096
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2068
2097
|
structuralState = void 0;
|
|
2069
2098
|
continue;
|
|
2070
2099
|
}
|
|
@@ -2192,7 +2221,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2192
2221
|
continue;
|
|
2193
2222
|
}
|
|
2194
2223
|
const setterCall = statement.expression;
|
|
2195
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2224
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2196
2225
|
mappedReorderState = void 0;
|
|
2197
2226
|
pendingMaps = [];
|
|
2198
2227
|
continue;
|
|
@@ -2282,7 +2311,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2282
2311
|
}
|
|
2283
2312
|
function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2284
2313
|
if (hintedStateIndices.size === 0) {
|
|
2285
|
-
return { root
|
|
2314
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2286
2315
|
}
|
|
2287
2316
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2288
2317
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2290,7 +2319,8 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2290
2319
|
traverse(file, {
|
|
2291
2320
|
CallExpression(path) {
|
|
2292
2321
|
const callee = path.get("callee");
|
|
2293
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2322
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2323
|
+
return;
|
|
2294
2324
|
const state = statesBySetter.get(callee.node.name);
|
|
2295
2325
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2296
2326
|
return;
|
|
@@ -2341,7 +2371,7 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2341
2371
|
}
|
|
2342
2372
|
function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2343
2373
|
if (hintedStateIndices.size === 0) {
|
|
2344
|
-
return { root
|
|
2374
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2345
2375
|
}
|
|
2346
2376
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2347
2377
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2349,7 +2379,8 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2349
2379
|
traverse(file, {
|
|
2350
2380
|
CallExpression(path) {
|
|
2351
2381
|
const callee = path.get("callee");
|
|
2352
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2382
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2383
|
+
return;
|
|
2353
2384
|
const state = statesBySetter.get(callee.node.name);
|
|
2354
2385
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2355
2386
|
return;
|
|
@@ -2402,7 +2433,7 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2402
2433
|
}
|
|
2403
2434
|
function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2404
2435
|
if (hintedStateIndices.size === 0) {
|
|
2405
|
-
return { root
|
|
2436
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2406
2437
|
}
|
|
2407
2438
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2408
2439
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2410,7 +2441,8 @@ function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter,
|
|
|
2410
2441
|
traverse(file, {
|
|
2411
2442
|
CallExpression(path) {
|
|
2412
2443
|
const callee = path.get("callee");
|
|
2413
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2444
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2445
|
+
return;
|
|
2414
2446
|
const state = statesBySetter.get(callee.node.name);
|
|
2415
2447
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2416
2448
|
return;
|
|
@@ -2489,7 +2521,7 @@ function collectionStateHasOnlyOwnedReads(root, state, kind) {
|
|
|
2489
2521
|
const readMethods = kind === "set" ? /* @__PURE__ */ new Set(["has"]) : /* @__PURE__ */ new Set(["get", "has"]);
|
|
2490
2522
|
traverse(file, {
|
|
2491
2523
|
ReferencedIdentifier(path) {
|
|
2492
|
-
if (!valid || !types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name)) {
|
|
2524
|
+
if (!valid || !types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
2493
2525
|
return;
|
|
2494
2526
|
}
|
|
2495
2527
|
const parent = path.parentPath;
|
|
@@ -2706,7 +2738,7 @@ function prepareKeyedCollectionUpdater(updater, kind, updateHelper, mutationHelp
|
|
|
2706
2738
|
return types.isArrowFunctionExpression(prepared) || types.isFunctionExpression(prepared) ? { updater: prepared, mutations } : void 0;
|
|
2707
2739
|
}
|
|
2708
2740
|
function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySetter, updateHelper, mutationHelper, globalCollections) {
|
|
2709
|
-
if (targetKinds.size === 0) return { root
|
|
2741
|
+
if (targetKinds.size === 0) return { root, count: 0 };
|
|
2710
2742
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2711
2743
|
let count = 0;
|
|
2712
2744
|
for (const [stateIndex, kind] of targetKinds) {
|
|
@@ -2724,7 +2756,7 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
|
|
|
2724
2756
|
CallExpression(path) {
|
|
2725
2757
|
if (!valid) return;
|
|
2726
2758
|
const callee = path.get("callee");
|
|
2727
|
-
if (!callee.isIdentifier({ name: state.setterName }) || callee.scope.hasBinding(callee.node.name) || statesBySetter.get(callee.node.name)?.index !== stateIndex) {
|
|
2759
|
+
if (!callee.isIdentifier({ name: state.setterName }) || callee.scope.hasBinding(callee.node.name, { noGlobals: true }) || statesBySetter.get(callee.node.name)?.index !== stateIndex) {
|
|
2728
2760
|
return;
|
|
2729
2761
|
}
|
|
2730
2762
|
if (path.node.arguments.length !== 1 || !types.isExpression(path.node.arguments[0])) {
|
|
@@ -2795,7 +2827,8 @@ function snapshotDeferredHandlerReads(root, reactiveNames) {
|
|
|
2795
2827
|
handler.traverse({
|
|
2796
2828
|
ReferencedIdentifier(reference) {
|
|
2797
2829
|
const name = reference.node.name;
|
|
2798
|
-
if (!reactiveNames.has(name) || reference.scope.hasBinding(name))
|
|
2830
|
+
if (!reactiveNames.has(name) || reference.scope.hasBinding(name, { noGlobals: true }))
|
|
2831
|
+
return;
|
|
2799
2832
|
let snapshot = snapshots.get(name);
|
|
2800
2833
|
if (!snapshot) {
|
|
2801
2834
|
snapshot = handler.scope.generateUidIdentifier(name);
|
|
@@ -2822,7 +2855,8 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2822
2855
|
traverse(file, {
|
|
2823
2856
|
CallExpression(path) {
|
|
2824
2857
|
const callee = path.get("callee");
|
|
2825
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2858
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2859
|
+
return;
|
|
2826
2860
|
const state = statesBySetter.get(callee.node.name);
|
|
2827
2861
|
if (!state) return;
|
|
2828
2862
|
callee.replaceWith(
|
|
@@ -2834,7 +2868,7 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2834
2868
|
},
|
|
2835
2869
|
ReferencedIdentifier(path) {
|
|
2836
2870
|
const state = statesByValue.get(path.node.name);
|
|
2837
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
2871
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
2838
2872
|
path.replaceWith(
|
|
2839
2873
|
types.callExpression(
|
|
2840
2874
|
types.memberExpression(
|
|
@@ -7804,6 +7838,89 @@ async function compileReactModule(code, id, options) {
|
|
|
7804
7838
|
optimizations: optimizationCounts
|
|
7805
7839
|
};
|
|
7806
7840
|
}
|
|
7841
|
+
var MAX_BYTES = 16 * 1024 * 1024;
|
|
7842
|
+
var MAX_ENTRIES = 128;
|
|
7843
|
+
var ReactCompilerBuildCache = class {
|
|
7844
|
+
constructor(maxBytes = MAX_BYTES, maxEntries = MAX_ENTRIES) {
|
|
7845
|
+
this.maxBytes = maxBytes;
|
|
7846
|
+
this.maxEntries = maxEntries;
|
|
7847
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
7848
|
+
this.bytes = 0;
|
|
7849
|
+
this.disposed = false;
|
|
7850
|
+
}
|
|
7851
|
+
get size() {
|
|
7852
|
+
return this.entries.size;
|
|
7853
|
+
}
|
|
7854
|
+
get retainedBytes() {
|
|
7855
|
+
return this.bytes;
|
|
7856
|
+
}
|
|
7857
|
+
dispose() {
|
|
7858
|
+
this.disposed = true;
|
|
7859
|
+
this.entries.clear();
|
|
7860
|
+
this.bytes = 0;
|
|
7861
|
+
}
|
|
7862
|
+
async compile(key, compile) {
|
|
7863
|
+
const keyBytes = key.length * 2;
|
|
7864
|
+
if (this.disposed || keyBytes > this.maxBytes || this.maxEntries === 0) return compile();
|
|
7865
|
+
let entry = this.entries.get(key);
|
|
7866
|
+
if (entry) {
|
|
7867
|
+
this.entries.delete(key);
|
|
7868
|
+
this.entries.set(key, entry);
|
|
7869
|
+
} else {
|
|
7870
|
+
const created = {
|
|
7871
|
+
bytes: keyBytes,
|
|
7872
|
+
result: Promise.resolve().then(compile).then((result) => {
|
|
7873
|
+
const serialized = serialize(result);
|
|
7874
|
+
if (this.entries.get(key) === created) {
|
|
7875
|
+
created.bytes += serialized.byteLength;
|
|
7876
|
+
this.bytes += serialized.byteLength;
|
|
7877
|
+
this.trim();
|
|
7878
|
+
}
|
|
7879
|
+
return serialized;
|
|
7880
|
+
}).catch((error) => {
|
|
7881
|
+
if (this.entries.get(key) === created) this.remove(key, created);
|
|
7882
|
+
throw error;
|
|
7883
|
+
})
|
|
7884
|
+
};
|
|
7885
|
+
entry = created;
|
|
7886
|
+
this.entries.set(key, created);
|
|
7887
|
+
this.bytes += keyBytes;
|
|
7888
|
+
this.trim();
|
|
7889
|
+
}
|
|
7890
|
+
return deserialize(await entry.result);
|
|
7891
|
+
}
|
|
7892
|
+
remove(key, entry) {
|
|
7893
|
+
this.entries.delete(key);
|
|
7894
|
+
this.bytes -= entry.bytes;
|
|
7895
|
+
}
|
|
7896
|
+
trim() {
|
|
7897
|
+
while (this.bytes > this.maxBytes || this.entries.size > this.maxEntries) {
|
|
7898
|
+
const oldest = this.entries.entries().next().value;
|
|
7899
|
+
if (!oldest) break;
|
|
7900
|
+
this.remove(...oldest);
|
|
7901
|
+
}
|
|
7902
|
+
}
|
|
7903
|
+
};
|
|
7904
|
+
var buildCaches;
|
|
7905
|
+
function getReactCompilerBuildCache(lifetime) {
|
|
7906
|
+
if (lifetime.aborted) return void 0;
|
|
7907
|
+
buildCaches ?? (buildCaches = /* @__PURE__ */ new WeakMap());
|
|
7908
|
+
let cache = buildCaches.get(lifetime);
|
|
7909
|
+
if (!cache) {
|
|
7910
|
+
const created = new ReactCompilerBuildCache();
|
|
7911
|
+
cache = created;
|
|
7912
|
+
buildCaches.set(lifetime, cache);
|
|
7913
|
+
lifetime.addEventListener(
|
|
7914
|
+
"abort",
|
|
7915
|
+
() => {
|
|
7916
|
+
created.dispose();
|
|
7917
|
+
buildCaches?.delete(lifetime);
|
|
7918
|
+
},
|
|
7919
|
+
{ once: true }
|
|
7920
|
+
);
|
|
7921
|
+
}
|
|
7922
|
+
return cache;
|
|
7923
|
+
}
|
|
7807
7924
|
|
|
7808
7925
|
// src/compiler-options.ts
|
|
7809
7926
|
var warnedExperimentalCompiler = false;
|
|
@@ -8025,7 +8142,18 @@ function createFarmRendererPlugin(options = {}) {
|
|
|
8025
8142
|
const cleanId = normalizePath(id.split("?", 1)[0]);
|
|
8026
8143
|
if (!/\.[jt]sx$/.test(cleanId) || cleanId.includes("/node_modules/") || projectRoot && !cleanId.startsWith(`${projectRoot}/`))
|
|
8027
8144
|
return null;
|
|
8028
|
-
const
|
|
8145
|
+
const cache = options.buildLifetime && getReactCompilerBuildCache(options.buildLifetime);
|
|
8146
|
+
const result = cache ? await cache.compile(
|
|
8147
|
+
JSON.stringify([
|
|
8148
|
+
projectRoot,
|
|
8149
|
+
cleanId,
|
|
8150
|
+
compilerOptions,
|
|
8151
|
+
process.env.NODE_ENV,
|
|
8152
|
+
process.env.BABEL_ENV,
|
|
8153
|
+
code
|
|
8154
|
+
]),
|
|
8155
|
+
() => compileReactModule(code, cleanId, compilerOptions)
|
|
8156
|
+
) : await compileReactModule(code, cleanId, compilerOptions);
|
|
8029
8157
|
if (reportEnabled) {
|
|
8030
8158
|
if (result.compiled.length > 0 || result.diagnostics.length > 0) {
|
|
8031
8159
|
reportObservations.set(cleanId, { id: cleanId, result });
|