@farm.js/react 0.1.0-beta.25 → 0.1.0-beta.27
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 +113 -119
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.mjs +113 -119
- 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 +165 -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 +165 -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,12 +219,22 @@ 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);
|
|
@@ -232,7 +243,7 @@ function referencesIdentifier(expression, name) {
|
|
|
232
243
|
let referenced = false;
|
|
233
244
|
traverse(expressionFile(cloneExpression(expression)), {
|
|
234
245
|
ReferencedIdentifier(path) {
|
|
235
|
-
if (path.node.name === name && !path.scope.hasBinding(name)) {
|
|
246
|
+
if (path.node.name === name && !path.scope.hasBinding(name, { noGlobals: true })) {
|
|
236
247
|
referenced = true;
|
|
237
248
|
}
|
|
238
249
|
}
|
|
@@ -244,7 +255,7 @@ function rewriteFreeIdentifierNames(expression, replacements) {
|
|
|
244
255
|
const file = expressionFile(cloneExpression(expression));
|
|
245
256
|
traverse(file, {
|
|
246
257
|
ReferencedIdentifier(path) {
|
|
247
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
258
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
248
259
|
const replacement = replacements.get(path.node.name);
|
|
249
260
|
if (!replacement) return;
|
|
250
261
|
path.replaceWith(types.cloneNode(replacement));
|
|
@@ -273,7 +284,7 @@ function keyedIdentityTarget(binding, keyCallback, renderCallback, reactiveByVal
|
|
|
273
284
|
let comparisons = 0;
|
|
274
285
|
traverse(file, {
|
|
275
286
|
ReferencedIdentifier(path) {
|
|
276
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
287
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
277
288
|
const reactive = reactiveByValue.get(path.node.name);
|
|
278
289
|
if (!reactive) return;
|
|
279
290
|
if (reactive.index !== dependencies[0] || target && target !== reactive) {
|
|
@@ -355,7 +366,7 @@ function keyedMembershipTarget(binding, keyCallback, renderCallback, reactiveByV
|
|
|
355
366
|
let calls = 0;
|
|
356
367
|
traverse(file, {
|
|
357
368
|
ReferencedIdentifier(path) {
|
|
358
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
369
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
359
370
|
const reactive = reactiveByValue.get(path.node.name);
|
|
360
371
|
if (!reactive) return;
|
|
361
372
|
const member = path.parentPath;
|
|
@@ -391,7 +402,7 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
391
402
|
let calls = 0;
|
|
392
403
|
traverse(file, {
|
|
393
404
|
ReferencedIdentifier(path) {
|
|
394
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
405
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
395
406
|
const reactive = reactiveByValue.get(path.node.name);
|
|
396
407
|
if (!reactive) return;
|
|
397
408
|
const member = path.parentPath;
|
|
@@ -408,10 +419,11 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
408
419
|
return valid && target && calls > 0 ? { dependency: target.index, value: types.identifier(target.valueName) } : void 0;
|
|
409
420
|
}
|
|
410
421
|
function collectReferencedLocals(expression, names) {
|
|
422
|
+
if (names.size === 0) return [];
|
|
411
423
|
const references = /* @__PURE__ */ new Set();
|
|
412
424
|
traverse(expressionFile(cloneExpression(expression)), {
|
|
413
425
|
ReferencedIdentifier(path) {
|
|
414
|
-
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name)) {
|
|
426
|
+
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
415
427
|
references.add(path.node.name);
|
|
416
428
|
}
|
|
417
429
|
}
|
|
@@ -419,10 +431,11 @@ function collectReferencedLocals(expression, names) {
|
|
|
419
431
|
return [...references];
|
|
420
432
|
}
|
|
421
433
|
function rewriteDerivedAccess(expression, derivedByName) {
|
|
434
|
+
if (derivedByName.size === 0) return cloneExpression(expression);
|
|
422
435
|
const file = expressionFile(cloneExpression(expression));
|
|
423
436
|
traverse(file, {
|
|
424
437
|
ReferencedIdentifier(path) {
|
|
425
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
438
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
426
439
|
const derived = derivedByName.get(path.node.name);
|
|
427
440
|
if (!derived) return;
|
|
428
441
|
path.replaceWith(cloneExpression(derived));
|
|
@@ -436,7 +449,8 @@ function rewriteDestructuredPropAccess(expression, names, propsParameter) {
|
|
|
436
449
|
const file = expressionFile(cloneExpression(expression));
|
|
437
450
|
traverse(file, {
|
|
438
451
|
ReferencedIdentifier(path) {
|
|
439
|
-
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name))
|
|
452
|
+
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name, { noGlobals: true }))
|
|
453
|
+
return;
|
|
440
454
|
if (path.parentPath.isJSXOpeningElement() || path.parentPath.isJSXClosingElement()) return;
|
|
441
455
|
path.replaceWith(
|
|
442
456
|
types.memberExpression(types.cloneNode(propsParameter), types.identifier(path.node.name))
|
|
@@ -483,7 +497,7 @@ function rewriteHandlerAccess(root, handlersByName) {
|
|
|
483
497
|
let reason;
|
|
484
498
|
traverse(file, {
|
|
485
499
|
ReferencedIdentifier(path) {
|
|
486
|
-
if (reason || path.scope.hasBinding(path.node.name)) return;
|
|
500
|
+
if (reason || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
487
501
|
const handler = handlersByName.get(path.node.name);
|
|
488
502
|
if (!handler) return;
|
|
489
503
|
const container = path.parentPath;
|
|
@@ -561,7 +575,7 @@ function validateSetterUsage(root, statesBySetter) {
|
|
|
561
575
|
ReferencedIdentifier(path) {
|
|
562
576
|
if (reason) return;
|
|
563
577
|
const state = statesBySetter.get(path.node.name);
|
|
564
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
578
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
565
579
|
const parent = path.parentPath;
|
|
566
580
|
if (!parent.isCallExpression() || parent.node.callee !== path.node || !findContainingEvent(parent)) {
|
|
567
581
|
reason = `${state.setterName} must be called inside a JSX event handler`;
|
|
@@ -676,13 +690,14 @@ function keyedMapUpdatePipeline(expression, parameterName, safeGlobals) {
|
|
|
676
690
|
return outerCallbacks.reverse();
|
|
677
691
|
}
|
|
678
692
|
function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
679
|
-
if (hintedStateIndices.size === 0) return { root
|
|
693
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
680
694
|
const file = expressionFile(types.cloneNode(root, true));
|
|
681
695
|
let count = 0;
|
|
682
696
|
traverse(file, {
|
|
683
697
|
CallExpression(path) {
|
|
684
698
|
const callee = path.get("callee");
|
|
685
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
699
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
700
|
+
return;
|
|
686
701
|
const state = statesBySetter.get(callee.node.name);
|
|
687
702
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
688
703
|
return;
|
|
@@ -747,13 +762,14 @@ function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, he
|
|
|
747
762
|
};
|
|
748
763
|
}
|
|
749
764
|
function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
750
|
-
if (hintedStateIndices.size === 0) return { root
|
|
765
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
751
766
|
const file = expressionFile(types.cloneNode(root, true));
|
|
752
767
|
let count = 0;
|
|
753
768
|
traverse(file, {
|
|
754
769
|
CallExpression(path) {
|
|
755
770
|
const callee = path.get("callee");
|
|
756
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
771
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
772
|
+
return;
|
|
757
773
|
const state = statesBySetter.get(callee.node.name);
|
|
758
774
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
759
775
|
return;
|
|
@@ -818,7 +834,7 @@ function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter,
|
|
|
818
834
|
}
|
|
819
835
|
function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
820
836
|
if (hintedStateIndices.size === 0) {
|
|
821
|
-
return { root
|
|
837
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
822
838
|
}
|
|
823
839
|
const file = expressionFile(types.cloneNode(root, true));
|
|
824
840
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -826,7 +842,8 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
826
842
|
traverse(file, {
|
|
827
843
|
CallExpression(path) {
|
|
828
844
|
const callee = path.get("callee");
|
|
829
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
845
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
846
|
+
return;
|
|
830
847
|
const state = statesBySetter.get(callee.node.name);
|
|
831
848
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
832
849
|
return;
|
|
@@ -895,7 +912,7 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
895
912
|
}
|
|
896
913
|
function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesBySetter, sliceHelperIdentifier, rollingWindowHelperIdentifier, safeGlobals) {
|
|
897
914
|
if (hintedStateIndices.size === 0) {
|
|
898
|
-
return { root
|
|
915
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
899
916
|
}
|
|
900
917
|
const file = expressionFile(types.cloneNode(root, true));
|
|
901
918
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -903,7 +920,8 @@ function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesByS
|
|
|
903
920
|
traverse(file, {
|
|
904
921
|
CallExpression(path) {
|
|
905
922
|
const callee = path.get("callee");
|
|
906
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
923
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
924
|
+
return;
|
|
907
925
|
const state = statesBySetter.get(callee.node.name);
|
|
908
926
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
909
927
|
return;
|
|
@@ -1013,7 +1031,7 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
|
|
|
1013
1031
|
function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
|
|
1014
1032
|
if (hintedStateIndices.size === 0) {
|
|
1015
1033
|
return {
|
|
1016
|
-
root
|
|
1034
|
+
root,
|
|
1017
1035
|
count: 0,
|
|
1018
1036
|
batchInsertCount: 0,
|
|
1019
1037
|
windowReplaceCount: 0,
|
|
@@ -1028,7 +1046,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1028
1046
|
traverse(file, {
|
|
1029
1047
|
CallExpression(path) {
|
|
1030
1048
|
const callee = path.get("callee");
|
|
1031
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1049
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1050
|
+
return;
|
|
1032
1051
|
const state = statesBySetter.get(callee.node.name);
|
|
1033
1052
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1034
1053
|
return;
|
|
@@ -1109,7 +1128,7 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1109
1128
|
}
|
|
1110
1129
|
function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter, helperIdentifier) {
|
|
1111
1130
|
if (hintedStateIndices.size === 0) {
|
|
1112
|
-
return { root
|
|
1131
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
1113
1132
|
}
|
|
1114
1133
|
const file = expressionFile(types.cloneNode(root, true));
|
|
1115
1134
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -1117,7 +1136,8 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
|
|
|
1117
1136
|
traverse(file, {
|
|
1118
1137
|
CallExpression(path) {
|
|
1119
1138
|
const callee = path.get("callee");
|
|
1120
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1139
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1140
|
+
return;
|
|
1121
1141
|
const state = statesBySetter.get(callee.node.name);
|
|
1122
1142
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1123
1143
|
return;
|
|
@@ -1249,7 +1269,7 @@ function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
|
|
|
1249
1269
|
function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesBySetter, filterHelperIdentifier, mapHelperIdentifier, mapReorderHelperIdentifier, mappedStructuralHelperIdentifier, reorderHelperIdentifier, structuralReorderHelperIdentifier, sliceHelperIdentifier, sortHelperIdentifier, structuralSortHelperIdentifier, safeGlobals, allowMapPipelines) {
|
|
1250
1270
|
if (hintedStateIndices.size === 0) {
|
|
1251
1271
|
return {
|
|
1252
|
-
root
|
|
1272
|
+
root,
|
|
1253
1273
|
filterCount: 0,
|
|
1254
1274
|
mapCount: 0,
|
|
1255
1275
|
mapReorderCount: 0,
|
|
@@ -1278,7 +1298,8 @@ function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesB
|
|
|
1278
1298
|
traverse(file, {
|
|
1279
1299
|
CallExpression(path) {
|
|
1280
1300
|
const callee = path.get("callee");
|
|
1281
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1301
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1302
|
+
return;
|
|
1282
1303
|
const state = statesBySetter.get(callee.node.name);
|
|
1283
1304
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1284
1305
|
return;
|
|
@@ -1470,7 +1491,7 @@ function rewriteQueuedKeyedArrayReorderMapHints(root, statesBySetter, mapUpdateI
|
|
|
1470
1491
|
continue;
|
|
1471
1492
|
}
|
|
1472
1493
|
const setterCall = statement.expression;
|
|
1473
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1494
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1474
1495
|
queuedReorderState = void 0;
|
|
1475
1496
|
continue;
|
|
1476
1497
|
}
|
|
@@ -1565,7 +1586,7 @@ function rewriteQueuedKeyedArrayMappedStructuralHints(root, statesBySetter, mapU
|
|
|
1565
1586
|
continue;
|
|
1566
1587
|
}
|
|
1567
1588
|
const setterCall = statement.expression;
|
|
1568
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1589
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1569
1590
|
mappedStructuralState = void 0;
|
|
1570
1591
|
pendingMaps = [];
|
|
1571
1592
|
continue;
|
|
@@ -1677,7 +1698,7 @@ function rewriteQueuedKeyedArrayStructuralMapHints(root, statesBySetter, mapUpda
|
|
|
1677
1698
|
continue;
|
|
1678
1699
|
}
|
|
1679
1700
|
const setterCall = statement.expression;
|
|
1680
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1701
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1681
1702
|
structuralState = void 0;
|
|
1682
1703
|
structuralAppendState = void 0;
|
|
1683
1704
|
structuralMapState = void 0;
|
|
@@ -1801,7 +1822,7 @@ function rewriteQueuedKeyedArrayStructuralPrependMapHints(root, statesBySetter,
|
|
|
1801
1822
|
continue;
|
|
1802
1823
|
}
|
|
1803
1824
|
const setterCall = statement.expression;
|
|
1804
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1825
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1805
1826
|
structuralState = void 0;
|
|
1806
1827
|
structuralPrependState = void 0;
|
|
1807
1828
|
structuralMapState = void 0;
|
|
@@ -2000,7 +2021,7 @@ function rewriteQueuedKeyedArrayRollingWindowMapHints(root, statesBySetter, mapU
|
|
|
2000
2021
|
continue;
|
|
2001
2022
|
}
|
|
2002
2023
|
const setterCall = statement.expression;
|
|
2003
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2024
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2004
2025
|
flushSegment();
|
|
2005
2026
|
continue;
|
|
2006
2027
|
}
|
|
@@ -2064,7 +2085,7 @@ function rewriteQueuedKeyedArrayStructuralReorderHints(root, statesBySetter, fil
|
|
|
2064
2085
|
continue;
|
|
2065
2086
|
}
|
|
2066
2087
|
const setterCall = statement.expression;
|
|
2067
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2088
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2068
2089
|
structuralState = void 0;
|
|
2069
2090
|
continue;
|
|
2070
2091
|
}
|
|
@@ -2192,7 +2213,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2192
2213
|
continue;
|
|
2193
2214
|
}
|
|
2194
2215
|
const setterCall = statement.expression;
|
|
2195
|
-
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2216
|
+
if (!types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2196
2217
|
mappedReorderState = void 0;
|
|
2197
2218
|
pendingMaps = [];
|
|
2198
2219
|
continue;
|
|
@@ -2282,7 +2303,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2282
2303
|
}
|
|
2283
2304
|
function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2284
2305
|
if (hintedStateIndices.size === 0) {
|
|
2285
|
-
return { root
|
|
2306
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2286
2307
|
}
|
|
2287
2308
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2288
2309
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2290,7 +2311,8 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2290
2311
|
traverse(file, {
|
|
2291
2312
|
CallExpression(path) {
|
|
2292
2313
|
const callee = path.get("callee");
|
|
2293
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2314
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2315
|
+
return;
|
|
2294
2316
|
const state = statesBySetter.get(callee.node.name);
|
|
2295
2317
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2296
2318
|
return;
|
|
@@ -2341,7 +2363,7 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2341
2363
|
}
|
|
2342
2364
|
function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2343
2365
|
if (hintedStateIndices.size === 0) {
|
|
2344
|
-
return { root
|
|
2366
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2345
2367
|
}
|
|
2346
2368
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2347
2369
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2349,7 +2371,8 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2349
2371
|
traverse(file, {
|
|
2350
2372
|
CallExpression(path) {
|
|
2351
2373
|
const callee = path.get("callee");
|
|
2352
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2374
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2375
|
+
return;
|
|
2353
2376
|
const state = statesBySetter.get(callee.node.name);
|
|
2354
2377
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2355
2378
|
return;
|
|
@@ -2402,7 +2425,7 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2402
2425
|
}
|
|
2403
2426
|
function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2404
2427
|
if (hintedStateIndices.size === 0) {
|
|
2405
|
-
return { root
|
|
2428
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2406
2429
|
}
|
|
2407
2430
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2408
2431
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2410,7 +2433,8 @@ function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter,
|
|
|
2410
2433
|
traverse(file, {
|
|
2411
2434
|
CallExpression(path) {
|
|
2412
2435
|
const callee = path.get("callee");
|
|
2413
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2436
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2437
|
+
return;
|
|
2414
2438
|
const state = statesBySetter.get(callee.node.name);
|
|
2415
2439
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2416
2440
|
return;
|
|
@@ -2489,7 +2513,7 @@ function collectionStateHasOnlyOwnedReads(root, state, kind) {
|
|
|
2489
2513
|
const readMethods = kind === "set" ? /* @__PURE__ */ new Set(["has"]) : /* @__PURE__ */ new Set(["get", "has"]);
|
|
2490
2514
|
traverse(file, {
|
|
2491
2515
|
ReferencedIdentifier(path) {
|
|
2492
|
-
if (!valid || !types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name)) {
|
|
2516
|
+
if (!valid || !types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
2493
2517
|
return;
|
|
2494
2518
|
}
|
|
2495
2519
|
const parent = path.parentPath;
|
|
@@ -2706,7 +2730,7 @@ function prepareKeyedCollectionUpdater(updater, kind, updateHelper, mutationHelp
|
|
|
2706
2730
|
return types.isArrowFunctionExpression(prepared) || types.isFunctionExpression(prepared) ? { updater: prepared, mutations } : void 0;
|
|
2707
2731
|
}
|
|
2708
2732
|
function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySetter, updateHelper, mutationHelper, globalCollections) {
|
|
2709
|
-
if (targetKinds.size === 0) return { root
|
|
2733
|
+
if (targetKinds.size === 0) return { root, count: 0 };
|
|
2710
2734
|
const file = expressionFile(types.cloneNode(root, true));
|
|
2711
2735
|
let count = 0;
|
|
2712
2736
|
for (const [stateIndex, kind] of targetKinds) {
|
|
@@ -2724,7 +2748,7 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
|
|
|
2724
2748
|
CallExpression(path) {
|
|
2725
2749
|
if (!valid) return;
|
|
2726
2750
|
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) {
|
|
2751
|
+
if (!callee.isIdentifier({ name: state.setterName }) || callee.scope.hasBinding(callee.node.name, { noGlobals: true }) || statesBySetter.get(callee.node.name)?.index !== stateIndex) {
|
|
2728
2752
|
return;
|
|
2729
2753
|
}
|
|
2730
2754
|
if (path.node.arguments.length !== 1 || !types.isExpression(path.node.arguments[0])) {
|
|
@@ -2795,7 +2819,8 @@ function snapshotDeferredHandlerReads(root, reactiveNames) {
|
|
|
2795
2819
|
handler.traverse({
|
|
2796
2820
|
ReferencedIdentifier(reference) {
|
|
2797
2821
|
const name = reference.node.name;
|
|
2798
|
-
if (!reactiveNames.has(name) || reference.scope.hasBinding(name))
|
|
2822
|
+
if (!reactiveNames.has(name) || reference.scope.hasBinding(name, { noGlobals: true }))
|
|
2823
|
+
return;
|
|
2799
2824
|
let snapshot = snapshots.get(name);
|
|
2800
2825
|
if (!snapshot) {
|
|
2801
2826
|
snapshot = handler.scope.generateUidIdentifier(name);
|
|
@@ -2822,7 +2847,8 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2822
2847
|
traverse(file, {
|
|
2823
2848
|
CallExpression(path) {
|
|
2824
2849
|
const callee = path.get("callee");
|
|
2825
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2850
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2851
|
+
return;
|
|
2826
2852
|
const state = statesBySetter.get(callee.node.name);
|
|
2827
2853
|
if (!state) return;
|
|
2828
2854
|
callee.replaceWith(
|
|
@@ -2834,7 +2860,7 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2834
2860
|
},
|
|
2835
2861
|
ReferencedIdentifier(path) {
|
|
2836
2862
|
const state = statesByValue.get(path.node.name);
|
|
2837
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
2863
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
2838
2864
|
path.replaceWith(
|
|
2839
2865
|
types.callExpression(
|
|
2840
2866
|
types.memberExpression(
|
|
@@ -7804,6 +7830,89 @@ async function compileReactModule(code, id, options) {
|
|
|
7804
7830
|
optimizations: optimizationCounts
|
|
7805
7831
|
};
|
|
7806
7832
|
}
|
|
7833
|
+
var MAX_BYTES = 16 * 1024 * 1024;
|
|
7834
|
+
var MAX_ENTRIES = 128;
|
|
7835
|
+
var ReactCompilerBuildCache = class {
|
|
7836
|
+
constructor(maxBytes = MAX_BYTES, maxEntries = MAX_ENTRIES) {
|
|
7837
|
+
this.maxBytes = maxBytes;
|
|
7838
|
+
this.maxEntries = maxEntries;
|
|
7839
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
7840
|
+
this.bytes = 0;
|
|
7841
|
+
this.disposed = false;
|
|
7842
|
+
}
|
|
7843
|
+
get size() {
|
|
7844
|
+
return this.entries.size;
|
|
7845
|
+
}
|
|
7846
|
+
get retainedBytes() {
|
|
7847
|
+
return this.bytes;
|
|
7848
|
+
}
|
|
7849
|
+
dispose() {
|
|
7850
|
+
this.disposed = true;
|
|
7851
|
+
this.entries.clear();
|
|
7852
|
+
this.bytes = 0;
|
|
7853
|
+
}
|
|
7854
|
+
async compile(key, compile) {
|
|
7855
|
+
const keyBytes = key.length * 2;
|
|
7856
|
+
if (this.disposed || keyBytes > this.maxBytes || this.maxEntries === 0) return compile();
|
|
7857
|
+
let entry = this.entries.get(key);
|
|
7858
|
+
if (entry) {
|
|
7859
|
+
this.entries.delete(key);
|
|
7860
|
+
this.entries.set(key, entry);
|
|
7861
|
+
} else {
|
|
7862
|
+
const created = {
|
|
7863
|
+
bytes: keyBytes,
|
|
7864
|
+
result: Promise.resolve().then(compile).then((result) => {
|
|
7865
|
+
const serialized = serialize(result);
|
|
7866
|
+
if (this.entries.get(key) === created) {
|
|
7867
|
+
created.bytes += serialized.byteLength;
|
|
7868
|
+
this.bytes += serialized.byteLength;
|
|
7869
|
+
this.trim();
|
|
7870
|
+
}
|
|
7871
|
+
return serialized;
|
|
7872
|
+
}).catch((error) => {
|
|
7873
|
+
if (this.entries.get(key) === created) this.remove(key, created);
|
|
7874
|
+
throw error;
|
|
7875
|
+
})
|
|
7876
|
+
};
|
|
7877
|
+
entry = created;
|
|
7878
|
+
this.entries.set(key, created);
|
|
7879
|
+
this.bytes += keyBytes;
|
|
7880
|
+
this.trim();
|
|
7881
|
+
}
|
|
7882
|
+
return deserialize(await entry.result);
|
|
7883
|
+
}
|
|
7884
|
+
remove(key, entry) {
|
|
7885
|
+
this.entries.delete(key);
|
|
7886
|
+
this.bytes -= entry.bytes;
|
|
7887
|
+
}
|
|
7888
|
+
trim() {
|
|
7889
|
+
while (this.bytes > this.maxBytes || this.entries.size > this.maxEntries) {
|
|
7890
|
+
const oldest = this.entries.entries().next().value;
|
|
7891
|
+
if (!oldest) break;
|
|
7892
|
+
this.remove(...oldest);
|
|
7893
|
+
}
|
|
7894
|
+
}
|
|
7895
|
+
};
|
|
7896
|
+
var buildCaches;
|
|
7897
|
+
function getReactCompilerBuildCache(lifetime) {
|
|
7898
|
+
if (lifetime.aborted) return void 0;
|
|
7899
|
+
buildCaches ?? (buildCaches = /* @__PURE__ */ new WeakMap());
|
|
7900
|
+
let cache = buildCaches.get(lifetime);
|
|
7901
|
+
if (!cache) {
|
|
7902
|
+
const created = new ReactCompilerBuildCache();
|
|
7903
|
+
cache = created;
|
|
7904
|
+
buildCaches.set(lifetime, cache);
|
|
7905
|
+
lifetime.addEventListener(
|
|
7906
|
+
"abort",
|
|
7907
|
+
() => {
|
|
7908
|
+
created.dispose();
|
|
7909
|
+
buildCaches?.delete(lifetime);
|
|
7910
|
+
},
|
|
7911
|
+
{ once: true }
|
|
7912
|
+
);
|
|
7913
|
+
}
|
|
7914
|
+
return cache;
|
|
7915
|
+
}
|
|
7807
7916
|
|
|
7808
7917
|
// src/compiler-options.ts
|
|
7809
7918
|
var warnedExperimentalCompiler = false;
|
|
@@ -8025,7 +8134,18 @@ function createFarmRendererPlugin(options = {}) {
|
|
|
8025
8134
|
const cleanId = normalizePath(id.split("?", 1)[0]);
|
|
8026
8135
|
if (!/\.[jt]sx$/.test(cleanId) || cleanId.includes("/node_modules/") || projectRoot && !cleanId.startsWith(`${projectRoot}/`))
|
|
8027
8136
|
return null;
|
|
8028
|
-
const
|
|
8137
|
+
const cache = options.buildLifetime && getReactCompilerBuildCache(options.buildLifetime);
|
|
8138
|
+
const result = cache ? await cache.compile(
|
|
8139
|
+
JSON.stringify([
|
|
8140
|
+
projectRoot,
|
|
8141
|
+
cleanId,
|
|
8142
|
+
compilerOptions,
|
|
8143
|
+
process.env.NODE_ENV,
|
|
8144
|
+
process.env.BABEL_ENV,
|
|
8145
|
+
code
|
|
8146
|
+
]),
|
|
8147
|
+
() => compileReactModule(code, cleanId, compilerOptions)
|
|
8148
|
+
) : await compileReactModule(code, cleanId, compilerOptions);
|
|
8029
8149
|
if (reportEnabled) {
|
|
8030
8150
|
if (result.compiled.length > 0 || result.diagnostics.length > 0) {
|
|
8031
8151
|
reportObservations.set(cleanId, { id: cleanId, result });
|