@farm.js/react 0.1.0-beta.26 → 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 +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 +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/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,12 +221,22 @@ 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);
|
|
@@ -234,7 +245,7 @@ function referencesIdentifier(expression, name) {
|
|
|
234
245
|
let referenced = false;
|
|
235
246
|
core.traverse(expressionFile(cloneExpression(expression)), {
|
|
236
247
|
ReferencedIdentifier(path) {
|
|
237
|
-
if (path.node.name === name && !path.scope.hasBinding(name)) {
|
|
248
|
+
if (path.node.name === name && !path.scope.hasBinding(name, { noGlobals: true })) {
|
|
238
249
|
referenced = true;
|
|
239
250
|
}
|
|
240
251
|
}
|
|
@@ -246,7 +257,7 @@ function rewriteFreeIdentifierNames(expression, replacements) {
|
|
|
246
257
|
const file = expressionFile(cloneExpression(expression));
|
|
247
258
|
core.traverse(file, {
|
|
248
259
|
ReferencedIdentifier(path) {
|
|
249
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
260
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
250
261
|
const replacement = replacements.get(path.node.name);
|
|
251
262
|
if (!replacement) return;
|
|
252
263
|
path.replaceWith(core.types.cloneNode(replacement));
|
|
@@ -275,7 +286,7 @@ function keyedIdentityTarget(binding, keyCallback, renderCallback, reactiveByVal
|
|
|
275
286
|
let comparisons = 0;
|
|
276
287
|
core.traverse(file, {
|
|
277
288
|
ReferencedIdentifier(path) {
|
|
278
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
289
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
279
290
|
const reactive = reactiveByValue.get(path.node.name);
|
|
280
291
|
if (!reactive) return;
|
|
281
292
|
if (reactive.index !== dependencies[0] || target && target !== reactive) {
|
|
@@ -357,7 +368,7 @@ function keyedMembershipTarget(binding, keyCallback, renderCallback, reactiveByV
|
|
|
357
368
|
let calls = 0;
|
|
358
369
|
core.traverse(file, {
|
|
359
370
|
ReferencedIdentifier(path) {
|
|
360
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
371
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
361
372
|
const reactive = reactiveByValue.get(path.node.name);
|
|
362
373
|
if (!reactive) return;
|
|
363
374
|
const member = path.parentPath;
|
|
@@ -393,7 +404,7 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
393
404
|
let calls = 0;
|
|
394
405
|
core.traverse(file, {
|
|
395
406
|
ReferencedIdentifier(path) {
|
|
396
|
-
if (!valid || path.scope.hasBinding(path.node.name)) return;
|
|
407
|
+
if (!valid || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
397
408
|
const reactive = reactiveByValue.get(path.node.name);
|
|
398
409
|
if (!reactive) return;
|
|
399
410
|
const member = path.parentPath;
|
|
@@ -410,10 +421,11 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
|
|
|
410
421
|
return valid && target && calls > 0 ? { dependency: target.index, value: core.types.identifier(target.valueName) } : void 0;
|
|
411
422
|
}
|
|
412
423
|
function collectReferencedLocals(expression, names) {
|
|
424
|
+
if (names.size === 0) return [];
|
|
413
425
|
const references = /* @__PURE__ */ new Set();
|
|
414
426
|
core.traverse(expressionFile(cloneExpression(expression)), {
|
|
415
427
|
ReferencedIdentifier(path) {
|
|
416
|
-
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name)) {
|
|
428
|
+
if (names.has(path.node.name) && !path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
417
429
|
references.add(path.node.name);
|
|
418
430
|
}
|
|
419
431
|
}
|
|
@@ -421,10 +433,11 @@ function collectReferencedLocals(expression, names) {
|
|
|
421
433
|
return [...references];
|
|
422
434
|
}
|
|
423
435
|
function rewriteDerivedAccess(expression, derivedByName) {
|
|
436
|
+
if (derivedByName.size === 0) return cloneExpression(expression);
|
|
424
437
|
const file = expressionFile(cloneExpression(expression));
|
|
425
438
|
core.traverse(file, {
|
|
426
439
|
ReferencedIdentifier(path) {
|
|
427
|
-
if (path.scope.hasBinding(path.node.name)) return;
|
|
440
|
+
if (path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
428
441
|
const derived = derivedByName.get(path.node.name);
|
|
429
442
|
if (!derived) return;
|
|
430
443
|
path.replaceWith(cloneExpression(derived));
|
|
@@ -438,7 +451,8 @@ function rewriteDestructuredPropAccess(expression, names, propsParameter) {
|
|
|
438
451
|
const file = expressionFile(cloneExpression(expression));
|
|
439
452
|
core.traverse(file, {
|
|
440
453
|
ReferencedIdentifier(path) {
|
|
441
|
-
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name))
|
|
454
|
+
if (!names.has(path.node.name) || path.scope.hasBinding(path.node.name, { noGlobals: true }))
|
|
455
|
+
return;
|
|
442
456
|
if (path.parentPath.isJSXOpeningElement() || path.parentPath.isJSXClosingElement()) return;
|
|
443
457
|
path.replaceWith(
|
|
444
458
|
core.types.memberExpression(core.types.cloneNode(propsParameter), core.types.identifier(path.node.name))
|
|
@@ -485,7 +499,7 @@ function rewriteHandlerAccess(root, handlersByName) {
|
|
|
485
499
|
let reason;
|
|
486
500
|
core.traverse(file, {
|
|
487
501
|
ReferencedIdentifier(path) {
|
|
488
|
-
if (reason || path.scope.hasBinding(path.node.name)) return;
|
|
502
|
+
if (reason || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
489
503
|
const handler = handlersByName.get(path.node.name);
|
|
490
504
|
if (!handler) return;
|
|
491
505
|
const container = path.parentPath;
|
|
@@ -563,7 +577,7 @@ function validateSetterUsage(root, statesBySetter) {
|
|
|
563
577
|
ReferencedIdentifier(path) {
|
|
564
578
|
if (reason) return;
|
|
565
579
|
const state = statesBySetter.get(path.node.name);
|
|
566
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
580
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
567
581
|
const parent = path.parentPath;
|
|
568
582
|
if (!parent.isCallExpression() || parent.node.callee !== path.node || !findContainingEvent(parent)) {
|
|
569
583
|
reason = `${state.setterName} must be called inside a JSX event handler`;
|
|
@@ -678,13 +692,14 @@ function keyedMapUpdatePipeline(expression, parameterName, safeGlobals) {
|
|
|
678
692
|
return outerCallbacks.reverse();
|
|
679
693
|
}
|
|
680
694
|
function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
681
|
-
if (hintedStateIndices.size === 0) return { root
|
|
695
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
682
696
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
683
697
|
let count = 0;
|
|
684
698
|
core.traverse(file, {
|
|
685
699
|
CallExpression(path) {
|
|
686
700
|
const callee = path.get("callee");
|
|
687
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
701
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
702
|
+
return;
|
|
688
703
|
const state = statesBySetter.get(callee.node.name);
|
|
689
704
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
690
705
|
return;
|
|
@@ -749,13 +764,14 @@ function rewriteKeyedMapUpdateHints(root, hintedStateIndices, statesBySetter, he
|
|
|
749
764
|
};
|
|
750
765
|
}
|
|
751
766
|
function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
752
|
-
if (hintedStateIndices.size === 0) return { root
|
|
767
|
+
if (hintedStateIndices.size === 0) return { root, count: 0 };
|
|
753
768
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
754
769
|
let count = 0;
|
|
755
770
|
core.traverse(file, {
|
|
756
771
|
CallExpression(path) {
|
|
757
772
|
const callee = path.get("callee");
|
|
758
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
773
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
774
|
+
return;
|
|
759
775
|
const state = statesBySetter.get(callee.node.name);
|
|
760
776
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
761
777
|
return;
|
|
@@ -820,7 +836,7 @@ function rewriteKeyedArrayAppendHints(root, hintedStateIndices, statesBySetter,
|
|
|
820
836
|
}
|
|
821
837
|
function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
822
838
|
if (hintedStateIndices.size === 0) {
|
|
823
|
-
return { root
|
|
839
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
824
840
|
}
|
|
825
841
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
826
842
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -828,7 +844,8 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
828
844
|
core.traverse(file, {
|
|
829
845
|
CallExpression(path) {
|
|
830
846
|
const callee = path.get("callee");
|
|
831
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
847
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
848
|
+
return;
|
|
832
849
|
const state = statesBySetter.get(callee.node.name);
|
|
833
850
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
834
851
|
return;
|
|
@@ -897,7 +914,7 @@ function rewriteKeyedArrayPrependHints(root, hintedStateIndices, statesBySetter,
|
|
|
897
914
|
}
|
|
898
915
|
function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesBySetter, sliceHelperIdentifier, rollingWindowHelperIdentifier, safeGlobals) {
|
|
899
916
|
if (hintedStateIndices.size === 0) {
|
|
900
|
-
return { root
|
|
917
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
901
918
|
}
|
|
902
919
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
903
920
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -905,7 +922,8 @@ function rewriteKeyedArrayRollingWindowHints(root, hintedStateIndices, statesByS
|
|
|
905
922
|
core.traverse(file, {
|
|
906
923
|
CallExpression(path) {
|
|
907
924
|
const callee = path.get("callee");
|
|
908
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
925
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
926
|
+
return;
|
|
909
927
|
const state = statesBySetter.get(callee.node.name);
|
|
910
928
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
911
929
|
return;
|
|
@@ -1015,7 +1033,7 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
|
|
|
1015
1033
|
function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
|
|
1016
1034
|
if (hintedStateIndices.size === 0) {
|
|
1017
1035
|
return {
|
|
1018
|
-
root
|
|
1036
|
+
root,
|
|
1019
1037
|
count: 0,
|
|
1020
1038
|
batchInsertCount: 0,
|
|
1021
1039
|
windowReplaceCount: 0,
|
|
@@ -1030,7 +1048,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1030
1048
|
core.traverse(file, {
|
|
1031
1049
|
CallExpression(path) {
|
|
1032
1050
|
const callee = path.get("callee");
|
|
1033
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1051
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1052
|
+
return;
|
|
1034
1053
|
const state = statesBySetter.get(callee.node.name);
|
|
1035
1054
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1036
1055
|
return;
|
|
@@ -1111,7 +1130,7 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
|
|
|
1111
1130
|
}
|
|
1112
1131
|
function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter, helperIdentifier) {
|
|
1113
1132
|
if (hintedStateIndices.size === 0) {
|
|
1114
|
-
return { root
|
|
1133
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
1115
1134
|
}
|
|
1116
1135
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
1117
1136
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -1119,7 +1138,8 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
|
|
|
1119
1138
|
core.traverse(file, {
|
|
1120
1139
|
CallExpression(path) {
|
|
1121
1140
|
const callee = path.get("callee");
|
|
1122
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1141
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1142
|
+
return;
|
|
1123
1143
|
const state = statesBySetter.get(callee.node.name);
|
|
1124
1144
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1125
1145
|
return;
|
|
@@ -1251,7 +1271,7 @@ function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
|
|
|
1251
1271
|
function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesBySetter, filterHelperIdentifier, mapHelperIdentifier, mapReorderHelperIdentifier, mappedStructuralHelperIdentifier, reorderHelperIdentifier, structuralReorderHelperIdentifier, sliceHelperIdentifier, sortHelperIdentifier, structuralSortHelperIdentifier, safeGlobals, allowMapPipelines) {
|
|
1252
1272
|
if (hintedStateIndices.size === 0) {
|
|
1253
1273
|
return {
|
|
1254
|
-
root
|
|
1274
|
+
root,
|
|
1255
1275
|
filterCount: 0,
|
|
1256
1276
|
mapCount: 0,
|
|
1257
1277
|
mapReorderCount: 0,
|
|
@@ -1280,7 +1300,8 @@ function rewriteKeyedArrayReorderPipelineHints(root, hintedStateIndices, statesB
|
|
|
1280
1300
|
core.traverse(file, {
|
|
1281
1301
|
CallExpression(path) {
|
|
1282
1302
|
const callee = path.get("callee");
|
|
1283
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
1303
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
1304
|
+
return;
|
|
1284
1305
|
const state = statesBySetter.get(callee.node.name);
|
|
1285
1306
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
1286
1307
|
return;
|
|
@@ -1472,7 +1493,7 @@ function rewriteQueuedKeyedArrayReorderMapHints(root, statesBySetter, mapUpdateI
|
|
|
1472
1493
|
continue;
|
|
1473
1494
|
}
|
|
1474
1495
|
const setterCall = statement.expression;
|
|
1475
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1496
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1476
1497
|
queuedReorderState = void 0;
|
|
1477
1498
|
continue;
|
|
1478
1499
|
}
|
|
@@ -1567,7 +1588,7 @@ function rewriteQueuedKeyedArrayMappedStructuralHints(root, statesBySetter, mapU
|
|
|
1567
1588
|
continue;
|
|
1568
1589
|
}
|
|
1569
1590
|
const setterCall = statement.expression;
|
|
1570
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1591
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1571
1592
|
mappedStructuralState = void 0;
|
|
1572
1593
|
pendingMaps = [];
|
|
1573
1594
|
continue;
|
|
@@ -1679,7 +1700,7 @@ function rewriteQueuedKeyedArrayStructuralMapHints(root, statesBySetter, mapUpda
|
|
|
1679
1700
|
continue;
|
|
1680
1701
|
}
|
|
1681
1702
|
const setterCall = statement.expression;
|
|
1682
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1703
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1683
1704
|
structuralState = void 0;
|
|
1684
1705
|
structuralAppendState = void 0;
|
|
1685
1706
|
structuralMapState = void 0;
|
|
@@ -1803,7 +1824,7 @@ function rewriteQueuedKeyedArrayStructuralPrependMapHints(root, statesBySetter,
|
|
|
1803
1824
|
continue;
|
|
1804
1825
|
}
|
|
1805
1826
|
const setterCall = statement.expression;
|
|
1806
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
1827
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
1807
1828
|
structuralState = void 0;
|
|
1808
1829
|
structuralPrependState = void 0;
|
|
1809
1830
|
structuralMapState = void 0;
|
|
@@ -2002,7 +2023,7 @@ function rewriteQueuedKeyedArrayRollingWindowMapHints(root, statesBySetter, mapU
|
|
|
2002
2023
|
continue;
|
|
2003
2024
|
}
|
|
2004
2025
|
const setterCall = statement.expression;
|
|
2005
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2026
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2006
2027
|
flushSegment();
|
|
2007
2028
|
continue;
|
|
2008
2029
|
}
|
|
@@ -2066,7 +2087,7 @@ function rewriteQueuedKeyedArrayStructuralReorderHints(root, statesBySetter, fil
|
|
|
2066
2087
|
continue;
|
|
2067
2088
|
}
|
|
2068
2089
|
const setterCall = statement.expression;
|
|
2069
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2090
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2070
2091
|
structuralState = void 0;
|
|
2071
2092
|
continue;
|
|
2072
2093
|
}
|
|
@@ -2194,7 +2215,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2194
2215
|
continue;
|
|
2195
2216
|
}
|
|
2196
2217
|
const setterCall = statement.expression;
|
|
2197
|
-
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name) || setterCall.arguments.length !== 1) {
|
|
2218
|
+
if (!core.types.isIdentifier(setterCall.callee) || statementPath.scope.hasBinding(setterCall.callee.name, { noGlobals: true }) || setterCall.arguments.length !== 1) {
|
|
2198
2219
|
mappedReorderState = void 0;
|
|
2199
2220
|
pendingMaps = [];
|
|
2200
2221
|
continue;
|
|
@@ -2284,7 +2305,7 @@ function rewriteQueuedKeyedArrayMapReorderHints(root, statesBySetter, mapUpdateI
|
|
|
2284
2305
|
}
|
|
2285
2306
|
function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2286
2307
|
if (hintedStateIndices.size === 0) {
|
|
2287
|
-
return { root
|
|
2308
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2288
2309
|
}
|
|
2289
2310
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2290
2311
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2292,7 +2313,8 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2292
2313
|
core.traverse(file, {
|
|
2293
2314
|
CallExpression(path) {
|
|
2294
2315
|
const callee = path.get("callee");
|
|
2295
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2316
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2317
|
+
return;
|
|
2296
2318
|
const state = statesBySetter.get(callee.node.name);
|
|
2297
2319
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2298
2320
|
return;
|
|
@@ -2343,7 +2365,7 @@ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, he
|
|
|
2343
2365
|
}
|
|
2344
2366
|
function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2345
2367
|
if (hintedStateIndices.size === 0) {
|
|
2346
|
-
return { root
|
|
2368
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2347
2369
|
}
|
|
2348
2370
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2349
2371
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2351,7 +2373,8 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2351
2373
|
core.traverse(file, {
|
|
2352
2374
|
CallExpression(path) {
|
|
2353
2375
|
const callee = path.get("callee");
|
|
2354
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2376
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2377
|
+
return;
|
|
2355
2378
|
const state = statesBySetter.get(callee.node.name);
|
|
2356
2379
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2357
2380
|
return;
|
|
@@ -2404,7 +2427,7 @@ function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, h
|
|
|
2404
2427
|
}
|
|
2405
2428
|
function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
|
|
2406
2429
|
if (hintedStateIndices.size === 0) {
|
|
2407
|
-
return { root
|
|
2430
|
+
return { root, count: 0, stateIndices: /* @__PURE__ */ new Set() };
|
|
2408
2431
|
}
|
|
2409
2432
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2410
2433
|
const stateIndices = /* @__PURE__ */ new Set();
|
|
@@ -2412,7 +2435,8 @@ function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter,
|
|
|
2412
2435
|
core.traverse(file, {
|
|
2413
2436
|
CallExpression(path) {
|
|
2414
2437
|
const callee = path.get("callee");
|
|
2415
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2438
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2439
|
+
return;
|
|
2416
2440
|
const state = statesBySetter.get(callee.node.name);
|
|
2417
2441
|
if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
|
|
2418
2442
|
return;
|
|
@@ -2491,7 +2515,7 @@ function collectionStateHasOnlyOwnedReads(root, state, kind) {
|
|
|
2491
2515
|
const readMethods = kind === "set" ? /* @__PURE__ */ new Set(["has"]) : /* @__PURE__ */ new Set(["get", "has"]);
|
|
2492
2516
|
core.traverse(file, {
|
|
2493
2517
|
ReferencedIdentifier(path) {
|
|
2494
|
-
if (!valid || !core.types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name)) {
|
|
2518
|
+
if (!valid || !core.types.isIdentifier(path.node) || path.node.name !== state.valueName || path.scope.hasBinding(path.node.name, { noGlobals: true })) {
|
|
2495
2519
|
return;
|
|
2496
2520
|
}
|
|
2497
2521
|
const parent = path.parentPath;
|
|
@@ -2708,7 +2732,7 @@ function prepareKeyedCollectionUpdater(updater, kind, updateHelper, mutationHelp
|
|
|
2708
2732
|
return core.types.isArrowFunctionExpression(prepared) || core.types.isFunctionExpression(prepared) ? { updater: prepared, mutations } : void 0;
|
|
2709
2733
|
}
|
|
2710
2734
|
function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySetter, updateHelper, mutationHelper, globalCollections) {
|
|
2711
|
-
if (targetKinds.size === 0) return { root
|
|
2735
|
+
if (targetKinds.size === 0) return { root, count: 0 };
|
|
2712
2736
|
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2713
2737
|
let count = 0;
|
|
2714
2738
|
for (const [stateIndex, kind] of targetKinds) {
|
|
@@ -2726,7 +2750,7 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
|
|
|
2726
2750
|
CallExpression(path) {
|
|
2727
2751
|
if (!valid) return;
|
|
2728
2752
|
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) {
|
|
2753
|
+
if (!callee.isIdentifier({ name: state.setterName }) || callee.scope.hasBinding(callee.node.name, { noGlobals: true }) || statesBySetter.get(callee.node.name)?.index !== stateIndex) {
|
|
2730
2754
|
return;
|
|
2731
2755
|
}
|
|
2732
2756
|
if (path.node.arguments.length !== 1 || !core.types.isExpression(path.node.arguments[0])) {
|
|
@@ -2797,7 +2821,8 @@ function snapshotDeferredHandlerReads(root, reactiveNames) {
|
|
|
2797
2821
|
handler.traverse({
|
|
2798
2822
|
ReferencedIdentifier(reference) {
|
|
2799
2823
|
const name = reference.node.name;
|
|
2800
|
-
if (!reactiveNames.has(name) || reference.scope.hasBinding(name))
|
|
2824
|
+
if (!reactiveNames.has(name) || reference.scope.hasBinding(name, { noGlobals: true }))
|
|
2825
|
+
return;
|
|
2801
2826
|
let snapshot = snapshots.get(name);
|
|
2802
2827
|
if (!snapshot) {
|
|
2803
2828
|
snapshot = handler.scope.generateUidIdentifier(name);
|
|
@@ -2824,7 +2849,8 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2824
2849
|
core.traverse(file, {
|
|
2825
2850
|
CallExpression(path) {
|
|
2826
2851
|
const callee = path.get("callee");
|
|
2827
|
-
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name))
|
|
2852
|
+
if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name, { noGlobals: true }))
|
|
2853
|
+
return;
|
|
2828
2854
|
const state = statesBySetter.get(callee.node.name);
|
|
2829
2855
|
if (!state) return;
|
|
2830
2856
|
callee.replaceWith(
|
|
@@ -2836,7 +2862,7 @@ function rewriteStateAccess(expression, stateParameter, statesByValue, statesByS
|
|
|
2836
2862
|
},
|
|
2837
2863
|
ReferencedIdentifier(path) {
|
|
2838
2864
|
const state = statesByValue.get(path.node.name);
|
|
2839
|
-
if (!state || path.scope.hasBinding(path.node.name)) return;
|
|
2865
|
+
if (!state || path.scope.hasBinding(path.node.name, { noGlobals: true })) return;
|
|
2840
2866
|
path.replaceWith(
|
|
2841
2867
|
core.types.callExpression(
|
|
2842
2868
|
core.types.memberExpression(
|
|
@@ -7806,6 +7832,89 @@ async function compileReactModule(code, id, options) {
|
|
|
7806
7832
|
optimizations: optimizationCounts
|
|
7807
7833
|
};
|
|
7808
7834
|
}
|
|
7835
|
+
var MAX_BYTES = 16 * 1024 * 1024;
|
|
7836
|
+
var MAX_ENTRIES = 128;
|
|
7837
|
+
var ReactCompilerBuildCache = class {
|
|
7838
|
+
constructor(maxBytes = MAX_BYTES, maxEntries = MAX_ENTRIES) {
|
|
7839
|
+
this.maxBytes = maxBytes;
|
|
7840
|
+
this.maxEntries = maxEntries;
|
|
7841
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
7842
|
+
this.bytes = 0;
|
|
7843
|
+
this.disposed = false;
|
|
7844
|
+
}
|
|
7845
|
+
get size() {
|
|
7846
|
+
return this.entries.size;
|
|
7847
|
+
}
|
|
7848
|
+
get retainedBytes() {
|
|
7849
|
+
return this.bytes;
|
|
7850
|
+
}
|
|
7851
|
+
dispose() {
|
|
7852
|
+
this.disposed = true;
|
|
7853
|
+
this.entries.clear();
|
|
7854
|
+
this.bytes = 0;
|
|
7855
|
+
}
|
|
7856
|
+
async compile(key, compile) {
|
|
7857
|
+
const keyBytes = key.length * 2;
|
|
7858
|
+
if (this.disposed || keyBytes > this.maxBytes || this.maxEntries === 0) return compile();
|
|
7859
|
+
let entry = this.entries.get(key);
|
|
7860
|
+
if (entry) {
|
|
7861
|
+
this.entries.delete(key);
|
|
7862
|
+
this.entries.set(key, entry);
|
|
7863
|
+
} else {
|
|
7864
|
+
const created = {
|
|
7865
|
+
bytes: keyBytes,
|
|
7866
|
+
result: Promise.resolve().then(compile).then((result) => {
|
|
7867
|
+
const serialized = v8.serialize(result);
|
|
7868
|
+
if (this.entries.get(key) === created) {
|
|
7869
|
+
created.bytes += serialized.byteLength;
|
|
7870
|
+
this.bytes += serialized.byteLength;
|
|
7871
|
+
this.trim();
|
|
7872
|
+
}
|
|
7873
|
+
return serialized;
|
|
7874
|
+
}).catch((error) => {
|
|
7875
|
+
if (this.entries.get(key) === created) this.remove(key, created);
|
|
7876
|
+
throw error;
|
|
7877
|
+
})
|
|
7878
|
+
};
|
|
7879
|
+
entry = created;
|
|
7880
|
+
this.entries.set(key, created);
|
|
7881
|
+
this.bytes += keyBytes;
|
|
7882
|
+
this.trim();
|
|
7883
|
+
}
|
|
7884
|
+
return v8.deserialize(await entry.result);
|
|
7885
|
+
}
|
|
7886
|
+
remove(key, entry) {
|
|
7887
|
+
this.entries.delete(key);
|
|
7888
|
+
this.bytes -= entry.bytes;
|
|
7889
|
+
}
|
|
7890
|
+
trim() {
|
|
7891
|
+
while (this.bytes > this.maxBytes || this.entries.size > this.maxEntries) {
|
|
7892
|
+
const oldest = this.entries.entries().next().value;
|
|
7893
|
+
if (!oldest) break;
|
|
7894
|
+
this.remove(...oldest);
|
|
7895
|
+
}
|
|
7896
|
+
}
|
|
7897
|
+
};
|
|
7898
|
+
var buildCaches;
|
|
7899
|
+
function getReactCompilerBuildCache(lifetime) {
|
|
7900
|
+
if (lifetime.aborted) return void 0;
|
|
7901
|
+
buildCaches ?? (buildCaches = /* @__PURE__ */ new WeakMap());
|
|
7902
|
+
let cache = buildCaches.get(lifetime);
|
|
7903
|
+
if (!cache) {
|
|
7904
|
+
const created = new ReactCompilerBuildCache();
|
|
7905
|
+
cache = created;
|
|
7906
|
+
buildCaches.set(lifetime, cache);
|
|
7907
|
+
lifetime.addEventListener(
|
|
7908
|
+
"abort",
|
|
7909
|
+
() => {
|
|
7910
|
+
created.dispose();
|
|
7911
|
+
buildCaches?.delete(lifetime);
|
|
7912
|
+
},
|
|
7913
|
+
{ once: true }
|
|
7914
|
+
);
|
|
7915
|
+
}
|
|
7916
|
+
return cache;
|
|
7917
|
+
}
|
|
7809
7918
|
|
|
7810
7919
|
// src/compiler-options.ts
|
|
7811
7920
|
var warnedExperimentalCompiler = false;
|
|
@@ -8027,7 +8136,18 @@ function createFarmRendererPlugin(options = {}) {
|
|
|
8027
8136
|
const cleanId = vite.normalizePath(id.split("?", 1)[0]);
|
|
8028
8137
|
if (!/\.[jt]sx$/.test(cleanId) || cleanId.includes("/node_modules/") || projectRoot && !cleanId.startsWith(`${projectRoot}/`))
|
|
8029
8138
|
return null;
|
|
8030
|
-
const
|
|
8139
|
+
const cache = options.buildLifetime && getReactCompilerBuildCache(options.buildLifetime);
|
|
8140
|
+
const result = cache ? await cache.compile(
|
|
8141
|
+
JSON.stringify([
|
|
8142
|
+
projectRoot,
|
|
8143
|
+
cleanId,
|
|
8144
|
+
compilerOptions,
|
|
8145
|
+
process.env.NODE_ENV,
|
|
8146
|
+
process.env.BABEL_ENV,
|
|
8147
|
+
code
|
|
8148
|
+
]),
|
|
8149
|
+
() => compileReactModule(code, cleanId, compilerOptions)
|
|
8150
|
+
) : await compileReactModule(code, cleanId, compilerOptions);
|
|
8031
8151
|
if (reportEnabled) {
|
|
8032
8152
|
if (result.compiled.length > 0 || result.diagnostics.length > 0) {
|
|
8033
8153
|
reportObservations.set(cleanId, { id: cleanId, result });
|