@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/list.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
10
10
|
|
|
11
11
|
// src/iterable.ts
|
|
12
12
|
var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
|
|
13
|
-
var arrayIterator = Array.prototype[Symbol.iterator];
|
|
13
|
+
var arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();
|
|
14
14
|
function materializeIterable(source) {
|
|
15
15
|
if (source == null) return [];
|
|
16
16
|
if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
|
package/dist/list.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items","React"],"mappings":";;;;;;;;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE,IAAM,
|
|
1
|
+
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items","React"],"mappings":";;;;;;;;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE,IAAM,gCAAiC,CAAA,MAAM,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA,GAAG;AAGxE,SAAS,oBAA0B,MAAA,EAAmD;AAC3F,EAAA,IAAI,MAAA,IAAU,IAAA,EAAM,OAAO,EAAC;AAE5B,EAAA,IACE,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,IACpB,OAAO,cAAA,CAAe,MAAM,CAAA,KAAM,KAAA,CAAM,SAAA,IACxC,MAAA,CAAO,MAAA,CAAO,QAAQ,MAAM,aAAA,EAC5B;AACA,IAAA,MAAMA,SAAgB,EAAC;AACvB,IAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,MAAA,CAAO,MAAA,EAAQ,KAAA,IAAS,CAAA,EAAGA,MAAAA,CAAM,IAAA,CAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAC/E,IAAA,OAAOA,MAAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,MAAA,CAAO,QAAQ,CAAA,EAAE;AACzC,EAAA,MAAM,UACJ,QAAA,KAAc,MAAA,KACb,OAAO,MAAA,KAAW,QAAA,IAAY,OAAO,MAAA,KAAW,UAAA,CAAA;AACnD,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,MAAM,MAAA,GAAS,gBAAA,CAAiB,GAAA,CAAI,MAAgB,CAAA;AACpD,IAAA,IAAI,QAAQ,OAAO,MAAA;AAAA,EACrB;AAEA,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,EAAE,CAAC,OAAO,QAAQ,GAAG,MAAM,QAAA,EAAU,CAAA;AAC9D,EAAA,IAAI,OAAA,EAAS,gBAAA,CAAiB,GAAA,CAAI,MAAA,EAAkB,KAAK,CAAA;AACzD,EAAA,OAAO,KAAA;AACT;;;ACXO,SAAS,IAAA,CAAW,EAAE,IAAA,EAAM,EAAA,EAAI,UAAS,EAAwC;AACtF,EAAA,MAAM,IAAA,GAAO,oBAAoB,IAAI,CAAA;AACrC,EAAA,OAAOC,sBAAA,CAAM,aAAA;AAAA,IACXA,sBAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAACA,sBAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAOA,sBAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.cjs","sourcesContent":["const oneShotSnapshots = new WeakMap<object, readonly unknown[]>();\n\nconst arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();\n\n/** Materialize an iterable without consuming a one-shot iterator more than once. */\nexport function materializeIterable<Item>(source: Iterable<Item> | null | undefined): Item[] {\n if (source == null) return [];\n // A plain array iterates by index, so copy it without the iterator protocol.\n if (\n Array.isArray(source) &&\n Object.getPrototypeOf(source) === Array.prototype &&\n source[Symbol.iterator] === arrayIterator\n ) {\n const items: Item[] = [];\n for (let index = 0; index < source.length; index += 1) items.push(source[index]);\n return items;\n }\n\n const iterator = source[Symbol.iterator]();\n const oneShot =\n iterator === (source as unknown) &&\n (typeof source === \"object\" || typeof source === \"function\");\n if (oneShot) {\n const cached = oneShotSnapshots.get(source as object);\n if (cached) return cached as Item[];\n }\n\n const items = Array.from({ [Symbol.iterator]: () => iterator });\n if (oneShot) oneShotSnapshots.set(source as object, items);\n return items;\n}\n","import React from \"react\";\nimport { materializeIterable } from \"./iterable\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = materializeIterable(each);\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
|
package/dist/list.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import React from 'react';
|
|
|
4
4
|
|
|
5
5
|
// src/iterable.ts
|
|
6
6
|
var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
var arrayIterator = Array.prototype[Symbol.iterator];
|
|
7
|
+
var arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();
|
|
8
8
|
function materializeIterable(source) {
|
|
9
9
|
if (source == null) return [];
|
|
10
10
|
if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
|
package/dist/list.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items"],"mappings":";;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE,IAAM,
|
|
1
|
+
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items"],"mappings":";;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE,IAAM,gCAAiC,CAAA,MAAM,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA,GAAG;AAGxE,SAAS,oBAA0B,MAAA,EAAmD;AAC3F,EAAA,IAAI,MAAA,IAAU,IAAA,EAAM,OAAO,EAAC;AAE5B,EAAA,IACE,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,IACpB,OAAO,cAAA,CAAe,MAAM,CAAA,KAAM,KAAA,CAAM,SAAA,IACxC,MAAA,CAAO,MAAA,CAAO,QAAQ,MAAM,aAAA,EAC5B;AACA,IAAA,MAAMA,SAAgB,EAAC;AACvB,IAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,MAAA,CAAO,MAAA,EAAQ,KAAA,IAAS,CAAA,EAAGA,MAAAA,CAAM,IAAA,CAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAC/E,IAAA,OAAOA,MAAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,MAAA,CAAO,QAAQ,CAAA,EAAE;AACzC,EAAA,MAAM,UACJ,QAAA,KAAc,MAAA,KACb,OAAO,MAAA,KAAW,QAAA,IAAY,OAAO,MAAA,KAAW,UAAA,CAAA;AACnD,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,MAAM,MAAA,GAAS,gBAAA,CAAiB,GAAA,CAAI,MAAgB,CAAA;AACpD,IAAA,IAAI,QAAQ,OAAO,MAAA;AAAA,EACrB;AAEA,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,EAAE,CAAC,OAAO,QAAQ,GAAG,MAAM,QAAA,EAAU,CAAA;AAC9D,EAAA,IAAI,OAAA,EAAS,gBAAA,CAAiB,GAAA,CAAI,MAAA,EAAkB,KAAK,CAAA;AACzD,EAAA,OAAO,KAAA;AACT;;;ACXO,SAAS,IAAA,CAAW,EAAE,IAAA,EAAM,EAAA,EAAI,UAAS,EAAwC;AACtF,EAAA,MAAM,IAAA,GAAO,oBAAoB,IAAI,CAAA;AACrC,EAAA,OAAO,KAAA,CAAM,aAAA;AAAA,IACX,KAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAAC,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAO,KAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.mjs","sourcesContent":["const oneShotSnapshots = new WeakMap<object, readonly unknown[]>();\n\nconst arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();\n\n/** Materialize an iterable without consuming a one-shot iterator more than once. */\nexport function materializeIterable<Item>(source: Iterable<Item> | null | undefined): Item[] {\n if (source == null) return [];\n // A plain array iterates by index, so copy it without the iterator protocol.\n if (\n Array.isArray(source) &&\n Object.getPrototypeOf(source) === Array.prototype &&\n source[Symbol.iterator] === arrayIterator\n ) {\n const items: Item[] = [];\n for (let index = 0; index < source.length; index += 1) items.push(source[index]);\n return items;\n }\n\n const iterator = source[Symbol.iterator]();\n const oneShot =\n iterator === (source as unknown) &&\n (typeof source === \"object\" || typeof source === \"function\");\n if (oneShot) {\n const cached = oneShotSnapshots.get(source as object);\n if (cached) return cached as Item[];\n }\n\n const items = Array.from({ [Symbol.iterator]: () => iterator });\n if (oneShot) oneShotSnapshots.set(source as object, items);\n return items;\n}\n","import React from \"react\";\nimport { materializeIterable } from \"./iterable\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = materializeIterable(each);\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
|
package/dist/vite.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var vite = require('vite');
|
|
4
4
|
var core = require('@babel/core');
|
|
5
|
+
var v8 = require('v8');
|
|
5
6
|
var promises = require('fs/promises');
|
|
6
7
|
var path = require('path');
|
|
7
8
|
|
|
@@ -220,21 +221,39 @@ function expressionFile(expression) {
|
|
|
220
221
|
return core.types.file(core.types.program([core.types.expressionStatement(expression)]));
|
|
221
222
|
}
|
|
222
223
|
function collectStateDependencies(expression, statesByValue) {
|
|
224
|
+
if (statesByValue.size === 0) return [];
|
|
225
|
+
let possible = false;
|
|
226
|
+
core.types.traverseFast(expression, (node) => {
|
|
227
|
+
if ((core.types.isIdentifier(node) || core.types.isJSXIdentifier(node)) && statesByValue.has(node.name)) {
|
|
228
|
+
possible = true;
|
|
229
|
+
return core.types.traverseFast.stop;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (!possible) return [];
|
|
223
233
|
const dependencies = /* @__PURE__ */ new Set();
|
|
224
234
|
const file = expressionFile(cloneExpression(expression));
|
|
225
235
|
core.traverse(file, {
|
|
226
236
|
ReferencedIdentifier(path) {
|
|
227
237
|
const state = statesByValue.get(path.node.name);
|
|
228
|
-
if (state && !path.scope.hasBinding(path.node.name))
|
|
238
|
+
if (state && !path.scope.hasBinding(path.node.name, { noGlobals: true }))
|
|
239
|
+
dependencies.add(state.index);
|
|
229
240
|
}
|
|
230
241
|
});
|
|
231
242
|
return [...dependencies].sort((left, right) => left - right);
|
|
232
243
|
}
|
|
233
244
|
function referencesIdentifier(expression, name) {
|
|
245
|
+
let possible = false;
|
|
246
|
+
core.types.traverseFast(expression, (node) => {
|
|
247
|
+
if ((core.types.isIdentifier(node) || core.types.isJSXIdentifier(node)) && node.name === name) {
|
|
248
|
+
possible = true;
|
|
249
|
+
return core.types.traverseFast.stop;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
if (!possible) return false;
|
|
234
253
|
let referenced = false;
|
|
235
254
|
core.traverse(expressionFile(cloneExpression(expression)), {
|
|
236
255
|
ReferencedIdentifier(path) {
|
|
237
|
-
if (path.node.name === name && !path.scope.hasBinding(name)) {
|
|
256
|
+
if (path.node.name === name && !path.scope.hasBinding(name, { noGlobals: true })) {
|
|
238
257
|
referenced = true;
|
|
239
258
|
}
|
|
240
259
|
}
|
|
@@ -246,7 +265,7 @@ function rewriteFreeIdentifierNames(expression, replacements) {
|
|
|
246
265
|
const file = expressionFile(cloneExpression(expression));
|
|
247
266
|
core.traverse(file, {
|
|
248
267
|
ReferencedIdentifier(path) {
|
|
249
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
268
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
250
269
|
const replacement = replacements.get(path.node.name);
|
|
251
270
|
if (!replacement) return;
|
|
252
271
|
path.replaceWith(core.types.cloneNode(replacement));
|
|
@@ -275,7 +294,7 @@ function keyedIdentityTarget(binding, keyCallback, renderCallback, reactiveByVal
|
|
|
275
294
|
let comparisons = 0;
|
|
276
295
|
core.traverse(file, {
|
|
277
296
|
ReferencedIdentifier(path) {
|
|
278
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
297
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
279
298
|
const reactive = reactiveByValue.get(path.node.name);
|
|
280
299
|
if (!reactive) return;
|
|
281
300
|
if (reactive.index !== dependencies[0] || target && target !== reactive) {
|
|
@@ -357,7 +376,7 @@ function keyedMembershipTarget(binding, keyCallback, renderCallback, reactiveByV
|
|
|
357
376
|
let calls = 0;
|
|
358
377
|
core.traverse(file, {
|
|
359
378
|
ReferencedIdentifier(path) {
|
|
360
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
379
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
361
380
|
const reactive = reactiveByValue.get(path.node.name);
|
|
362
381
|
if (!reactive) return;
|
|
363
382
|
const member = path.parentPath;
|
|
@@ -393,7 +412,7 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
393
412
|
let calls = 0;
|
|
394
413
|
core.traverse(file, {
|
|
395
414
|
ReferencedIdentifier(path) {
|
|
396
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
415
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
397
416
|
const reactive = reactiveByValue.get(path.node.name);
|
|
398
417
|
if (!reactive) return;
|
|
399
418
|
const member = path.parentPath;
|
|
@@ -410,10 +429,11 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
410
429
|
return valid && target && calls > 0 ? { dependency: target.index, value: core.types.identifier(target.valueName) } : void 0;
|
|
411
430
|
}
|
|
412
431
|
function collectReferencedLocals(expression, names) {
|
|
432
|
+
if (names.size === 0) return [];
|
|
413
433
|
const references = /* @__PURE__ */ new Set();
|
|
414
434
|
core.traverse(expressionFile(cloneExpression(expression)), {
|
|
415
435
|
ReferencedIdentifier(path) {
|
|
416
|
-
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name)) {
|
|
436
|
+
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
417
437
|
references.add(path.node.name);
|
|
418
438
|
}
|
|
419
439
|
}
|
|
@@ -421,10 +441,11 @@ function collectReferencedLocals(expression, names) {
|
|
|
421
441
|
return [...references];
|
|
422
442
|
}
|
|
423
443
|
function rewriteDerivedAccess(expression, derivedByName) {
|
|
444
|
+
if (derivedByName.size === 0) return cloneExpression(expression);
|
|
424
445
|
const file = expressionFile(cloneExpression(expression));
|
|
425
446
|
core.traverse(file, {
|
|
426
447
|
ReferencedIdentifier(path) {
|
|
427
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
448
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
428
449
|
const derived = derivedByName.get(path.node.name);
|
|
429
450
|
if (!derived) return;
|
|
430
451
|
path.replaceWith(cloneExpression(derived));
|
|
@@ -438,7 +459,8 @@ function rewriteDestructuredPropAccess(expression, names, propsParameter) {
|
|
|
438
459
|
const file = expressionFile(cloneExpression(expression));
|
|
439
460
|
core.traverse(file, {
|
|
440
461
|
ReferencedIdentifier(path) {
|
|
441
|
-
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name))
|
|
462
|
+
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name, { noGlobals: true }))
|
|
463
|
+
return;
|
|
442
464
|
if (path.parentPath.isJSXOpeningElement() || path.parentPath.isJSXClosingElement()) return;
|
|
443
465
|
path.replaceWith(
|
|
444
466
|
core.types.memberExpression(core.types.cloneNode(propsParameter), core.types.identifier(path.node.name))
|
|
@@ -485,7 +507,7 @@ function rewriteHandlerAccess(root, handlersByName) {
|
|
|
485
507
|
let reason;
|
|
486
508
|
core.traverse(file, {
|
|
487
509
|
ReferencedIdentifier(path) {
|
|
488
|
-
if (reason || path.scope.hasBinding(path.node.name)) return;
|
|
510
|
+
if (reason || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
489
511
|
const handler = handlersByName.get(path.node.name);
|
|
490
512
|
if (!handler) return;
|
|
491
513
|
const container = path.parentPath;
|
|
@@ -563,7 +585,7 @@ function validateSetterUsage(root, statesBySetter) {
|
|
|
563
585
|
ReferencedIdentifier(path) {
|
|
564
586
|
if (reason) return;
|
|
565
587
|
const state = statesBySetter.get(path.node.name);
|
|
566
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
588
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
567
589
|
const parent = path.parentPath;
|
|
568
590
|
if (!parent.isCallExpression() || parent.node.callee !== path.node || !findContainingEvent(parent)) {
|
|
569
591
|
reason = `${state.setterName} must be called inside a JSX event handler`;
|
|
@@ -678,13 +700,14 @@ function keyedMapUpdatePipeline(expression, parameterName, safeGlobals) {
|
|
|
678
700
|
return outerCallbacks.reverse();
|
|
679
701
|
}
|
|
680
702
|
function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
681
|
-
if (hintedStateIndices.size === 0) return { root
|
|
703
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
682
704
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
683
705
|
let count = 0;
|
|
684
706
|
core.traverse(file, {
|
|
685
707
|
CallExpression(path) {
|
|
686
708
|
const callee = path.get("callee");
|
|
687
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
709
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
710
|
+
return;
|
|
688
711
|
const state = statesBySetter.get(callee.node.name);
|
|
689
712
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
690
713
|
return;
|
|
@@ -749,13 +772,14 @@ function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, he
|
|
|
749
772
|
};
|
|
750
773
|
}
|
|
751
774
|
function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
752
|
-
if (hintedStateIndices.size === 0) return { root
|
|
775
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
753
776
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
754
777
|
let count = 0;
|
|
755
778
|
core.traverse(file, {
|
|
756
779
|
CallExpression(path) {
|
|
757
780
|
const callee = path.get("callee");
|
|
758
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
781
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
782
|
+
return;
|
|
759
783
|
const state = statesBySetter.get(callee.node.name);
|
|
760
784
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
761
785
|
return;
|
|
@@ -820,7 +844,7 @@ function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter,
|
|
|
820
844
|
}
|
|
821
845
|
function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
822
846
|
if (hintedStateIndices.size === 0) {
|
|
823
|
-
return { root
|
|
847
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
824
848
|
}
|
|
825
849
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
826
850
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -828,7 +852,8 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
828
852
|
core.traverse(file, {
|
|
829
853
|
CallExpression(path) {
|
|
830
854
|
const callee = path.get("callee");
|
|
831
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
855
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
856
|
+
return;
|
|
832
857
|
const state = statesBySetter.get(callee.node.name);
|
|
833
858
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
834
859
|
return;
|
|
@@ -897,7 +922,7 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
897
922
|
}
|
|
898
923
|
function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesBySetter, sliceHelperIdentifier, rollingWindowHelperIdentifier, safeGlobals) {
|
|
899
924
|
if (hintedStateIndices.size === 0) {
|
|
900
|
-
return { root
|
|
925
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
901
926
|
}
|
|
902
927
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
903
928
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -905,7 +930,8 @@ function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesByS
|
|
|
905
930
|
core.traverse(file, {
|
|
906
931
|
CallExpression(path) {
|
|
907
932
|
const callee = path.get("callee");
|
|
908
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
933
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
934
|
+
return;
|
|
909
935
|
const state = statesBySetter.get(callee.node.name);
|
|
910
936
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
911
937
|
return;
|
|
@@ -1015,7 +1041,7 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
|
|
|
1015
1041
|
function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
|
|
1016
1042
|
if (hintedStateIndices.size === 0) {
|
|
1017
1043
|
return {
|
|
1018
|
-
root
|
|
1044
|
+
root,
|
|
1019
1045
|
count: 0,
|
|
1020
1046
|
batchInsertCount: 0,
|
|
1021
1047
|
windowReplaceCount: 0,
|
|
@@ -1030,7 +1056,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1030
1056
|
core.traverse(file, {
|
|
1031
1057
|
CallExpression(path) {
|
|
1032
1058
|
const callee = path.get("callee");
|
|
1033
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1059
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1060
|
+
return;
|
|
1034
1061
|
const state = statesBySetter.get(callee.node.name);
|
|
1035
1062
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1036
1063
|
return;
|
|
@@ -1111,7 +1138,7 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1111
1138
|
}
|
|
1112
1139
|
function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter, helperIdentifier) {
|
|
1113
1140
|
if (hintedStateIndices.size === 0) {
|
|
1114
|
-
return { root
|
|
1141
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
1115
1142
|
}
|
|
1116
1143
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1117
1144
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -1119,7 +1146,8 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
|
|
|
1119
1146
|
core.traverse(file, {
|
|
1120
1147
|
CallExpression(path) {
|
|
1121
1148
|
const callee = path.get("callee");
|
|
1122
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1149
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1150
|
+
return;
|
|
1123
1151
|
const state = statesBySetter.get(callee.node.name);
|
|
1124
1152
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1125
1153
|
return;
|
|
@@ -1251,7 +1279,7 @@ function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
|
|
|
1251
1279
|
function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesBySetter, filterHelperIdentifier, mapHelperIdentifier, mapReorderHelperIdentifier, mappedStructuralHelperIdentifier, reorderHelperIdentifier, structuralReorderHelperIdentifier, sliceHelperIdentifier, sortHelperIdentifier, structuralSortHelperIdentifier, safeGlobals, allowMapPipelines) {
|
|
1252
1280
|
if (hintedStateIndices.size === 0) {
|
|
1253
1281
|
return {
|
|
1254
|
-
root
|
|
1282
|
+
root,
|
|
1255
1283
|
filterCount: 0,
|
|
1256
1284
|
mapCount: 0,
|
|
1257
1285
|
mapReorderCount: 0,
|
|
@@ -1280,7 +1308,8 @@ function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesB
|
|
|
1280
1308
|
core.traverse(file, {
|
|
1281
1309
|
CallExpression(path) {
|
|
1282
1310
|
const callee = path.get("callee");
|
|
1283
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1311
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1312
|
+
return;
|
|
1284
1313
|
const state = statesBySetter.get(callee.node.name);
|
|
1285
1314
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1286
1315
|
return;
|
|
@@ -1472,7 +1501,7 @@ function rewriteQueuedKeyedArrayReorderMapHints(root, statesBySetter, mapUpdateI
|
|
|
1472
1501
|
continue;
|
|
1473
1502
|
}
|
|
1474
1503
|
const setterCall = statement.expression;
|
|
1475
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1504
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1476
1505
|
queuedReorderState = void 0;
|
|
1477
1506
|
continue;
|
|
1478
1507
|
}
|
|
@@ -1567,7 +1596,7 @@ function rewriteQueuedKeyedArrayMappedStructuralHints(root, statesBySetter, mapU
|
|
|
1567
1596
|
continue;
|
|
1568
1597
|
}
|
|
1569
1598
|
const setterCall = statement.expression;
|
|
1570
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1599
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1571
1600
|
mappedStructuralState = void 0;
|
|
1572
1601
|
pendingMaps = [];
|
|
1573
1602
|
continue;
|
|
@@ -1679,7 +1708,7 @@ function rewriteQueuedKeyedArrayStructuralMapHints(root, statesBySetter, mapUpda
|
|
|
1679
1708
|
continue;
|
|
1680
1709
|
}
|
|
1681
1710
|
const setterCall = statement.expression;
|
|
1682
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1711
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1683
1712
|
structuralState = void 0;
|
|
1684
1713
|
structuralAppendState = void 0;
|
|
1685
1714
|
structuralMapState = void 0;
|
|
@@ -1803,7 +1832,7 @@ function rewriteQueuedKeyedArrayStructuralPrependMapHints(root, statesBySetter,
|
|
|
1803
1832
|
continue;
|
|
1804
1833
|
}
|
|
1805
1834
|
const setterCall = statement.expression;
|
|
1806
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1835
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1807
1836
|
structuralState = void 0;
|
|
1808
1837
|
structuralPrependState = void 0;
|
|
1809
1838
|
structuralMapState = void 0;
|
|
@@ -2002,7 +2031,7 @@ function rewriteQueuedKeyedArrayRollingWindowMapHints(root, statesBySetter, mapU
|
|
|
2002
2031
|
continue;
|
|
2003
2032
|
}
|
|
2004
2033
|
const setterCall = statement.expression;
|
|
2005
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2034
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2006
2035
|
flushSegment();
|
|
2007
2036
|
continue;
|
|
2008
2037
|
}
|
|
@@ -2066,7 +2095,7 @@ function rewriteQueuedKeyedArrayStructuralReorderHints(root, statesBySetter, fil
|
|
|
2066
2095
|
continue;
|
|
2067
2096
|
}
|
|
2068
2097
|
const setterCall = statement.expression;
|
|
2069
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2098
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2070
2099
|
structuralState = void 0;
|
|
2071
2100
|
continue;
|
|
2072
2101
|
}
|
|
@@ -2194,7 +2223,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2194
2223
|
continue;
|
|
2195
2224
|
}
|
|
2196
2225
|
const setterCall = statement.expression;
|
|
2197
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2226
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2198
2227
|
mappedReorderState = void 0;
|
|
2199
2228
|
pendingMaps = [];
|
|
2200
2229
|
continue;
|
|
@@ -2284,7 +2313,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2284
2313
|
}
|
|
2285
2314
|
function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2286
2315
|
if (hintedStateIndices.size === 0) {
|
|
2287
|
-
return { root
|
|
2316
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2288
2317
|
}
|
|
2289
2318
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2290
2319
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2292,7 +2321,8 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2292
2321
|
core.traverse(file, {
|
|
2293
2322
|
CallExpression(path) {
|
|
2294
2323
|
const callee = path.get("callee");
|
|
2295
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2324
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2325
|
+
return;
|
|
2296
2326
|
const state = statesBySetter.get(callee.node.name);
|
|
2297
2327
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2298
2328
|
return;
|
|
@@ -2343,7 +2373,7 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2343
2373
|
}
|
|
2344
2374
|
function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2345
2375
|
if (hintedStateIndices.size === 0) {
|
|
2346
|
-
return { root
|
|
2376
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2347
2377
|
}
|
|
2348
2378
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2349
2379
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2351,7 +2381,8 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2351
2381
|
core.traverse(file, {
|
|
2352
2382
|
CallExpression(path) {
|
|
2353
2383
|
const callee = path.get("callee");
|
|
2354
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2384
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2385
|
+
return;
|
|
2355
2386
|
const state = statesBySetter.get(callee.node.name);
|
|
2356
2387
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2357
2388
|
return;
|
|
@@ -2404,7 +2435,7 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2404
2435
|
}
|
|
2405
2436
|
function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2406
2437
|
if (hintedStateIndices.size === 0) {
|
|
2407
|
-
return { root
|
|
2438
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2408
2439
|
}
|
|
2409
2440
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2410
2441
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2412,7 +2443,8 @@ function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter,
|
|
|
2412
2443
|
core.traverse(file, {
|
|
2413
2444
|
CallExpression(path) {
|
|
2414
2445
|
const callee = path.get("callee");
|
|
2415
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2446
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2447
|
+
return;
|
|
2416
2448
|
const state = statesBySetter.get(callee.node.name);
|
|
2417
2449
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2418
2450
|
return;
|
|
@@ -2491,7 +2523,7 @@ function collectionStateHasOnlyOwnedReads(root, state, kind) {
|
|
|
2491
2523
|
const readMethods = kind === "set" ? /* @__PURE__ */ new Set(["has"]) : /* @__PURE__ */ new Set(["get", "has"]);
|
|
2492
2524
|
core.traverse(file, {
|
|
2493
2525
|
ReferencedIdentifier(path) {
|
|
2494
|
-
if (!valid || !core.types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name)) {
|
|
2526
|
+
if (!valid || !core.types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
2495
2527
|
return;
|
|
2496
2528
|
}
|
|
2497
2529
|
const parent = path.parentPath;
|
|
@@ -2708,7 +2740,7 @@ function prepareKeyedCollectionUpdater(updater, kind, updateHelper, mutationHelp
|
|
|
2708
2740
|
return core.types.isArrowFunctionExpression(prepared) || core.types.isFunctionExpression(prepared) ? { updater: prepared, mutations } : void 0;
|
|
2709
2741
|
}
|
|
2710
2742
|
function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySetter, updateHelper, mutationHelper, globalCollections) {
|
|
2711
|
-
if (targetKinds.size === 0) return { root
|
|
2743
|
+
if (targetKinds.size === 0) return { root, count: 0 };
|
|
2712
2744
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2713
2745
|
let count = 0;
|
|
2714
2746
|
for (const [stateIndex, kind] of targetKinds) {
|
|
@@ -2726,7 +2758,7 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
|
|
|
2726
2758
|
CallExpression(path) {
|
|
2727
2759
|
if (!valid) return;
|
|
2728
2760
|
const callee = path.get("callee");
|
|
2729
|
-
if (!callee.isIdentifier({ name: state.setterName }) || callee.scope.hasBinding(callee.node.name) || statesBySetter.get(callee.node.name)?.index !== stateIndex) {
|
|
2761
|
+
if (!callee.isIdentifier({ name: state.setterName }) || callee.scope.hasBinding(callee.node.name, { noGlobals: true }) || statesBySetter.get(callee.node.name)?.index !== stateIndex) {
|
|
2730
2762
|
return;
|
|
2731
2763
|
}
|
|
2732
2764
|
if (path.node.arguments.length !== 1 || !core.types.isExpression(path.node.arguments[0])) {
|
|
@@ -2797,7 +2829,8 @@ function snapshotDeferredHandlerReads(root, reactiveNames) {
|
|
|
2797
2829
|
handler.traverse({
|
|
2798
2830
|
ReferencedIdentifier(reference) {
|
|
2799
2831
|
const name = reference.node.name;
|
|
2800
|
-
if (!reactiveNames.has(name) || reference.scope.hasBinding(name))
|
|
2832
|
+
if (!reactiveNames.has(name) || reference.scope.hasBinding(name, { noGlobals: true }))
|
|
2833
|
+
return;
|
|
2801
2834
|
let snapshot = snapshots.get(name);
|
|
2802
2835
|
if (!snapshot) {
|
|
2803
2836
|
snapshot = handler.scope.generateUidIdentifier(name);
|
|
@@ -2824,7 +2857,8 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2824
2857
|
core.traverse(file, {
|
|
2825
2858
|
CallExpression(path) {
|
|
2826
2859
|
const callee = path.get("callee");
|
|
2827
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2860
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2861
|
+
return;
|
|
2828
2862
|
const state = statesBySetter.get(callee.node.name);
|
|
2829
2863
|
if (!state) return;
|
|
2830
2864
|
callee.replaceWith(
|
|
@@ -2836,7 +2870,7 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2836
2870
|
},
|
|
2837
2871
|
ReferencedIdentifier(path) {
|
|
2838
2872
|
const state = statesByValue.get(path.node.name);
|
|
2839
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
2873
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
2840
2874
|
path.replaceWith(
|
|
2841
2875
|
core.types.callExpression(
|
|
2842
2876
|
core.types.memberExpression(
|
|
@@ -7806,6 +7840,89 @@ async function compileReactModule(code, id, options) {
|
|
|
7806
7840
|
optimizations: optimizationCounts
|
|
7807
7841
|
};
|
|
7808
7842
|
}
|
|
7843
|
+
var MAX_BYTES = 16 * 1024 * 1024;
|
|
7844
|
+
var MAX_ENTRIES = 128;
|
|
7845
|
+
var ReactCompilerBuildCache = class {
|
|
7846
|
+
constructor(maxBytes = MAX_BYTES, maxEntries = MAX_ENTRIES) {
|
|
7847
|
+
this.maxBytes = maxBytes;
|
|
7848
|
+
this.maxEntries = maxEntries;
|
|
7849
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
7850
|
+
this.bytes = 0;
|
|
7851
|
+
this.disposed = false;
|
|
7852
|
+
}
|
|
7853
|
+
get size() {
|
|
7854
|
+
return this.entries.size;
|
|
7855
|
+
}
|
|
7856
|
+
get retainedBytes() {
|
|
7857
|
+
return this.bytes;
|
|
7858
|
+
}
|
|
7859
|
+
dispose() {
|
|
7860
|
+
this.disposed = true;
|
|
7861
|
+
this.entries.clear();
|
|
7862
|
+
this.bytes = 0;
|
|
7863
|
+
}
|
|
7864
|
+
async compile(key, compile) {
|
|
7865
|
+
const keyBytes = key.length * 2;
|
|
7866
|
+
if (this.disposed || keyBytes > this.maxBytes || this.maxEntries === 0) return compile();
|
|
7867
|
+
let entry = this.entries.get(key);
|
|
7868
|
+
if (entry) {
|
|
7869
|
+
this.entries.delete(key);
|
|
7870
|
+
this.entries.set(key, entry);
|
|
7871
|
+
} else {
|
|
7872
|
+
const created = {
|
|
7873
|
+
bytes: keyBytes,
|
|
7874
|
+
result: Promise.resolve().then(compile).then((result) => {
|
|
7875
|
+
const serialized = v8.serialize(result);
|
|
7876
|
+
if (this.entries.get(key) === created) {
|
|
7877
|
+
created.bytes += serialized.byteLength;
|
|
7878
|
+
this.bytes += serialized.byteLength;
|
|
7879
|
+
this.trim();
|
|
7880
|
+
}
|
|
7881
|
+
return serialized;
|
|
7882
|
+
}).catch((error) => {
|
|
7883
|
+
if (this.entries.get(key) === created) this.remove(key, created);
|
|
7884
|
+
throw error;
|
|
7885
|
+
})
|
|
7886
|
+
};
|
|
7887
|
+
entry = created;
|
|
7888
|
+
this.entries.set(key, created);
|
|
7889
|
+
this.bytes += keyBytes;
|
|
7890
|
+
this.trim();
|
|
7891
|
+
}
|
|
7892
|
+
return v8.deserialize(await entry.result);
|
|
7893
|
+
}
|
|
7894
|
+
remove(key, entry) {
|
|
7895
|
+
this.entries.delete(key);
|
|
7896
|
+
this.bytes -= entry.bytes;
|
|
7897
|
+
}
|
|
7898
|
+
trim() {
|
|
7899
|
+
while (this.bytes > this.maxBytes || this.entries.size > this.maxEntries) {
|
|
7900
|
+
const oldest = this.entries.entries().next().value;
|
|
7901
|
+
if (!oldest) break;
|
|
7902
|
+
this.remove(...oldest);
|
|
7903
|
+
}
|
|
7904
|
+
}
|
|
7905
|
+
};
|
|
7906
|
+
var buildCaches;
|
|
7907
|
+
function getReactCompilerBuildCache(lifetime) {
|
|
7908
|
+
if (lifetime.aborted) return void 0;
|
|
7909
|
+
buildCaches ?? (buildCaches = /* @__PURE__ */ new WeakMap());
|
|
7910
|
+
let cache = buildCaches.get(lifetime);
|
|
7911
|
+
if (!cache) {
|
|
7912
|
+
const created = new ReactCompilerBuildCache();
|
|
7913
|
+
cache = created;
|
|
7914
|
+
buildCaches.set(lifetime, cache);
|
|
7915
|
+
lifetime.addEventListener(
|
|
7916
|
+
"abort",
|
|
7917
|
+
() => {
|
|
7918
|
+
created.dispose();
|
|
7919
|
+
buildCaches?.delete(lifetime);
|
|
7920
|
+
},
|
|
7921
|
+
{ once: true }
|
|
7922
|
+
);
|
|
7923
|
+
}
|
|
7924
|
+
return cache;
|
|
7925
|
+
}
|
|
7809
7926
|
|
|
7810
7927
|
// src/compiler-options.ts
|
|
7811
7928
|
var warnedExperimentalCompiler = false;
|
|
@@ -8027,7 +8144,18 @@ function createFarmRendererPlugin(options = {}) {
|
|
|
8027
8144
|
const cleanId = vite.normalizePath(id.split("?", 1)[0]);
|
|
8028
8145
|
if (!/\.[jt]sx$/.test(cleanId) || cleanId.includes("/node_modules/") || projectRoot && !cleanId.startsWith(`${projectRoot}/`))
|
|
8029
8146
|
return null;
|
|
8030
|
-
const
|
|
8147
|
+
const cache = options.buildLifetime && getReactCompilerBuildCache(options.buildLifetime);
|
|
8148
|
+
const result = cache ? await cache.compile(
|
|
8149
|
+
JSON.stringify([
|
|
8150
|
+
projectRoot,
|
|
8151
|
+
cleanId,
|
|
8152
|
+
compilerOptions,
|
|
8153
|
+
process.env.NODE_ENV,
|
|
8154
|
+
process.env.BABEL_ENV,
|
|
8155
|
+
code
|
|
8156
|
+
]),
|
|
8157
|
+
() => compileReactModule(code, cleanId, compilerOptions)
|
|
8158
|
+
) : await compileReactModule(code, cleanId, compilerOptions);
|
|
8031
8159
|
if (reportEnabled) {
|
|
8032
8160
|
if (result.compiled.length > 0 || result.diagnostics.length > 0) {
|
|
8033
8161
|
reportObservations.set(cleanId, { id: cleanId, result });
|