@farm.js/react 0.1.0-beta.21 → 0.1.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -12
- package/dist/compiler-runtime.cjs +285 -231
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +5 -0
- package/dist/compiler-runtime.d.ts +5 -0
- package/dist/compiler-runtime.mjs +285 -231
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/index.cjs +25 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +25 -2
- package/dist/index.mjs.map +1 -1
- package/dist/list.cjs +6 -0
- package/dist/list.cjs.map +1 -1
- package/dist/list.mjs +6 -0
- package/dist/list.mjs.map +1 -1
- package/dist/vite.cjs +43 -8
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +43 -8
- package/dist/vite.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/compiler-options.ts
|
|
4
|
+
var warnedExperimentalCompiler = false;
|
|
5
|
+
function resolveCompilerOption(options = {}, warnDeprecated = false) {
|
|
6
|
+
const experimental = options.experimental;
|
|
7
|
+
const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
|
|
8
|
+
if (legacy !== void 0 && options.compiler !== void 0) {
|
|
9
|
+
throw new TypeError(
|
|
10
|
+
"Configure the React compiler with `compiler` only; remove `experimental.compiler`."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const compiler = legacy === void 0 ? options.compiler : legacy;
|
|
14
|
+
if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
|
|
15
|
+
throw new TypeError("React compiler must be a boolean or compiler options object.");
|
|
16
|
+
}
|
|
17
|
+
if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
|
|
18
|
+
warnedExperimentalCompiler = true;
|
|
19
|
+
console.warn(
|
|
20
|
+
"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return compiler;
|
|
24
|
+
}
|
|
25
|
+
|
|
3
26
|
// src/index.ts
|
|
4
27
|
var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
5
28
|
var DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
@@ -70,7 +93,7 @@ var REACT_RENDERER = Object.freeze({
|
|
|
70
93
|
}
|
|
71
94
|
});
|
|
72
95
|
function react(options = {}) {
|
|
73
|
-
const compiler = options
|
|
96
|
+
const compiler = resolveCompilerOption(options, true);
|
|
74
97
|
const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;
|
|
75
98
|
return {
|
|
76
99
|
...REACT_RENDERER,
|
|
@@ -87,7 +110,7 @@ function react(options = {}) {
|
|
|
87
110
|
functionComponents: true
|
|
88
111
|
},
|
|
89
112
|
options: {
|
|
90
|
-
|
|
113
|
+
compiler: normalizedCompiler
|
|
91
114
|
}
|
|
92
115
|
};
|
|
93
116
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAwCO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,4BAAA;AAChC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,MAAK,EAAG;AAC9C,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,MAAM,aAAa,KAAA,CAAM,IAAA,EAAK,CAAE,OAAA,CAAQ,OAAO,GAA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AM,EAAE,MAAM,KAAA,EAAO,GAAA,EAAK,MAAK;AAAE,KAC/C;AAAA,IACA,kBAAA,EAAoB;AAAA;AAExB,CAAC;AAGM,SAAS,KAAA,CAAM,OAAA,GAAgC,EAAC,EAAiB;AACtE,EAAA,MAAM,QAAA,GAAW,QAAQ,YAAA,EAAc,QAAA;AACvC,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,mBAAA,EAAqB,IAAA;AAAA,MACrB,SAAA,EAAW;AAAA,QACT,GAAG,eAAe,YAAA,EAAc,SAAA;AAAA,QAChC,QAAA,EAAU;AAAA,UACR,MAAM,EAAE,GAAG,eAAe,YAAA,EAAc,SAAA,EAAW,UAAU,IAAA;AAAK;AACpE,OACF;AAAA,MACA,kBAAA,EAAoB;AAAA,KACtB;AAAA,IACA,OAAA,EAAS;AAAA,MACP,YAAA,EAAc,EAAE,QAAA,EAAU,kBAAA;AAAmB;AAC/C,GACF;AACF","file":"index.cjs","sourcesContent":["import type { FarmRenderer } from \"@farm.js/core/renderer\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n experimental?: {\n /** `true` enables automatic inference; an object customizes selection. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's experimental AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = options.experimental?.compiler;\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n experimental: { compiler: normalizedCompiler },\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}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AA,MACT,IAAA,EAAM,IAAA;AAAA,MACN,GAAA,EAAK,KAAA;AAAA,MACL,QAAA,EAAU,EAAE,IAAA,EAAM,EAAE,MAAM,KAAA,EAAO,GAAA,EAAK,MAAK;AAAE,KAC/C;AAAA,IACA,kBAAA,EAAoB;AAAA;AAExB,CAAC;AAGM,SAAS,KAAA,CAAM,OAAA,GAAgC,EAAC,EAAiB;AACtE,EAAA,MAAM,QAAA,GAAW,qBAAA,CAAsB,OAAA,EAAS,IAAI,CAAA;AACpD,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,mBAAA,EAAqB,IAAA;AAAA,MACrB,SAAA,EAAW;AAAA,QACT,GAAG,eAAe,YAAA,EAAc,SAAA;AAAA,QAChC,QAAA,EAAU;AAAA,UACR,MAAM,EAAE,GAAG,eAAe,YAAA,EAAc,SAAA,EAAW,UAAU,IAAA;AAAK;AACpE,OACF;AAAA,MACA,kBAAA,EAAoB;AAAA,KACtB;AAAA,IACA,OAAA,EAAS;AAAA,MACP,QAAA,EAAU;AAAA;AACZ,GACF;AACF","file":"index.cjs","sourcesContent":["import type { ReactCompilerOptions } from \"./index\";\n\nlet warnedExperimentalCompiler = false;\n\n// Shared by react() and the Vite adapter, including descriptors from older renderers.\nexport function resolveCompilerOption(\n options: { compiler?: unknown; experimental?: unknown } = {},\n warnDeprecated = false,\n): boolean | ReactCompilerOptions | undefined {\n const experimental = options.experimental;\n const legacy =\n experimental && typeof experimental === \"object\"\n ? (experimental as { compiler?: unknown }).compiler\n : undefined;\n if (legacy !== undefined && options.compiler !== undefined) {\n throw new TypeError(\n \"Configure the React compiler with `compiler` only; remove `experimental.compiler`.\",\n );\n }\n const compiler = legacy === undefined ? options.compiler : legacy;\n if (\n compiler !== undefined &&\n typeof compiler !== \"boolean\" &&\n (compiler === null || typeof compiler !== \"object\" || Array.isArray(compiler))\n ) {\n throw new TypeError(\"React compiler must be a boolean or compiler options object.\");\n }\n if (legacy !== undefined && warnDeprecated && !warnedExperimentalCompiler) {\n warnedExperimentalCompiler = true;\n console.warn(\n \"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`.\",\n );\n }\n return compiler as boolean | ReactCompilerOptions | undefined;\n}\n","import type { FarmRenderer } from \"@farm.js/core/renderer\";\nimport { resolveCompilerOption } from \"./compiler-options\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n /**\n * Farm's AOT compiler. `true` enables automatic inference; an object\n * customizes selection. Unsupported components always stay on React.\n */\n compiler?: boolean | ReactCompilerOptions;\n experimental?: {\n /** @deprecated Use the top-level `compiler` option. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = resolveCompilerOption(options, true);\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n compiler: normalizedCompiler,\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -22,8 +22,13 @@ interface ReactCompilerOptions {
|
|
|
22
22
|
reportFile?: string;
|
|
23
23
|
}
|
|
24
24
|
interface ReactRendererOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Farm's AOT compiler. `true` enables automatic inference; an object
|
|
27
|
+
* customizes selection. Unsupported components always stay on React.
|
|
28
|
+
*/
|
|
29
|
+
compiler?: boolean | ReactCompilerOptions;
|
|
25
30
|
experimental?: {
|
|
26
|
-
/**
|
|
31
|
+
/** @deprecated Use the top-level `compiler` option. */
|
|
27
32
|
compiler?: boolean | ReactCompilerOptions;
|
|
28
33
|
};
|
|
29
34
|
}
|
|
@@ -39,7 +44,7 @@ declare const DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
|
39
44
|
declare const DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
40
45
|
declare function normalizeReactCompilerOptions(value: true | ReactCompilerOptions): NormalizedReactCompilerOptions;
|
|
41
46
|
declare const REACT_RENDERER: Readonly<FarmRenderer>;
|
|
42
|
-
/** Select React and optionally enable Farm's
|
|
47
|
+
/** Select React and optionally enable Farm's AOT compiler. */
|
|
43
48
|
declare function react(options?: ReactRendererOptions): FarmRenderer;
|
|
44
49
|
|
|
45
50
|
export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactCompilerReactivity, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,8 +22,13 @@ interface ReactCompilerOptions {
|
|
|
22
22
|
reportFile?: string;
|
|
23
23
|
}
|
|
24
24
|
interface ReactRendererOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Farm's AOT compiler. `true` enables automatic inference; an object
|
|
27
|
+
* customizes selection. Unsupported components always stay on React.
|
|
28
|
+
*/
|
|
29
|
+
compiler?: boolean | ReactCompilerOptions;
|
|
25
30
|
experimental?: {
|
|
26
|
-
/**
|
|
31
|
+
/** @deprecated Use the top-level `compiler` option. */
|
|
27
32
|
compiler?: boolean | ReactCompilerOptions;
|
|
28
33
|
};
|
|
29
34
|
}
|
|
@@ -39,7 +44,7 @@ declare const DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
|
39
44
|
declare const DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
40
45
|
declare function normalizeReactCompilerOptions(value: true | ReactCompilerOptions): NormalizedReactCompilerOptions;
|
|
41
46
|
declare const REACT_RENDERER: Readonly<FarmRenderer>;
|
|
42
|
-
/** Select React and optionally enable Farm's
|
|
47
|
+
/** Select React and optionally enable Farm's AOT compiler. */
|
|
43
48
|
declare function react(options?: ReactRendererOptions): FarmRenderer;
|
|
44
49
|
|
|
45
50
|
export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactCompilerReactivity, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
// src/compiler-options.ts
|
|
2
|
+
var warnedExperimentalCompiler = false;
|
|
3
|
+
function resolveCompilerOption(options = {}, warnDeprecated = false) {
|
|
4
|
+
const experimental = options.experimental;
|
|
5
|
+
const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
|
|
6
|
+
if (legacy !== void 0 && options.compiler !== void 0) {
|
|
7
|
+
throw new TypeError(
|
|
8
|
+
"Configure the React compiler with `compiler` only; remove `experimental.compiler`."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const compiler = legacy === void 0 ? options.compiler : legacy;
|
|
12
|
+
if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
|
|
13
|
+
throw new TypeError("React compiler must be a boolean or compiler options object.");
|
|
14
|
+
}
|
|
15
|
+
if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
|
|
16
|
+
warnedExperimentalCompiler = true;
|
|
17
|
+
console.warn(
|
|
18
|
+
"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return compiler;
|
|
22
|
+
}
|
|
23
|
+
|
|
1
24
|
// src/index.ts
|
|
2
25
|
var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
3
26
|
var DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
@@ -68,7 +91,7 @@ var REACT_RENDERER = Object.freeze({
|
|
|
68
91
|
}
|
|
69
92
|
});
|
|
70
93
|
function react(options = {}) {
|
|
71
|
-
const compiler = options
|
|
94
|
+
const compiler = resolveCompilerOption(options, true);
|
|
72
95
|
const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;
|
|
73
96
|
return {
|
|
74
97
|
...REACT_RENDERER,
|
|
@@ -85,7 +108,7 @@ function react(options = {}) {
|
|
|
85
108
|
functionComponents: true
|
|
86
109
|
},
|
|
87
110
|
options: {
|
|
88
|
-
|
|
111
|
+
compiler: normalizedCompiler
|
|
89
112
|
}
|
|
90
113
|
};
|
|
91
114
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAwCO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,4BAAA;AAChC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,MAAK,EAAG;AAC9C,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,MAAM,aAAa,KAAA,CAAM,IAAA,EAAK,CAAE,OAAA,CAAQ,OAAO,GAAG,CAAA;AAClD,EAAA,IACE,UAAA,CAAW,UAAA,CAAW,GAAG,CAAA,IACzB,eAAe,IAAA,CAAK,UAAU,CAAA,IAC9B,UAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA,EACnC;AACA,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,OAAO,UAAA;AACT;AAEO,SAAS,8BACd,KAAA,EAC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KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,mBAAA,EAAqB,IAAA;AAAA,MACrB,SAAA,EAAW;AAAA,QACT,GAAG,eAAe,YAAA,EAAc,SAAA;AAAA,QAChC,QAAA,EAAU;AAAA,UACR,MAAM,EAAE,GAAG,eAAe,YAAA,EAAc,SAAA,EAAW,UAAU,IAAA;AAAK;AACpE,OACF;AAAA,MACA,kBAAA,EAAoB;AAAA,KACtB;AAAA,IACA,OAAA,EAAS;AAAA,MACP,YAAA,EAAc,EAAE,QAAA,EAAU,kBAAA;AAAmB;AAC/C,GACF;AACF","file":"index.mjs","sourcesContent":["import type { FarmRenderer } from \"@farm.js/core/renderer\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n experimental?: {\n /** `true` enables automatic inference; an object customizes selection. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's experimental AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = options.experimental?.compiler;\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n experimental: { compiler: normalizedCompiler },\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/compiler-options.ts","../src/index.ts"],"names":[],"mappings":";AAEA,IAAI,0BAAA,GAA6B,KAAA;AAG1B,SAAS,qBAAA,CACd,OAAA,GAA0D,EAAC,EAC3D,iBAAiB,KAAA,EAC2B;AAC5C,EAAA,MAAM,eAAe,OAAA,CAAQ,YAAA;AAC7B,EAAA,MAAM,SACJ,YAAA,IAAgB,OAAO,YAAA,KAAiB,QAAA,GACnC,a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,OAAA,EAAS,IAAI,CAAA;AACpD,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,mBAAA,EAAqB,IAAA;AAAA,MACrB,SAAA,EAAW;AAAA,QACT,GAAG,eAAe,YAAA,EAAc,SAAA;AAAA,QAChC,QAAA,EAAU;AAAA,UACR,MAAM,EAAE,GAAG,eAAe,YAAA,EAAc,SAAA,EAAW,UAAU,IAAA;AAAK;AACpE,OACF;AAAA,MACA,kBAAA,EAAoB;AAAA,KACtB;AAAA,IACA,OAAA,EAAS;AAAA,MACP,QAAA,EAAU;AAAA;AACZ,GACF;AACF","file":"index.mjs","sourcesContent":["import type { ReactCompilerOptions } from \"./index\";\n\nlet warnedExperimentalCompiler = false;\n\n// Shared by react() and the Vite adapter, including descriptors from older renderers.\nexport function resolveCompilerOption(\n options: { compiler?: unknown; experimental?: unknown } = {},\n warnDeprecated = false,\n): boolean | ReactCompilerOptions | undefined {\n const experimental = options.experimental;\n const legacy =\n experimental && typeof experimental === \"object\"\n ? (experimental as { compiler?: unknown }).compiler\n : undefined;\n if (legacy !== undefined && options.compiler !== undefined) {\n throw new TypeError(\n \"Configure the React compiler with `compiler` only; remove `experimental.compiler`.\",\n );\n }\n const compiler = legacy === undefined ? options.compiler : legacy;\n if (\n compiler !== undefined &&\n typeof compiler !== \"boolean\" &&\n (compiler === null || typeof compiler !== \"object\" || Array.isArray(compiler))\n ) {\n throw new TypeError(\"React compiler must be a boolean or compiler options object.\");\n }\n if (legacy !== undefined && warnDeprecated && !warnedExperimentalCompiler) {\n warnedExperimentalCompiler = true;\n console.warn(\n \"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`.\",\n );\n }\n return compiler as boolean | ReactCompilerOptions | undefined;\n}\n","import type { FarmRenderer } from \"@farm.js/core/renderer\";\nimport { resolveCompilerOption } from \"./compiler-options\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n /**\n * Farm's AOT compiler. `true` enables automatic inference; an object\n * customizes selection. Unsupported components always stay on React.\n */\n compiler?: boolean | ReactCompilerOptions;\n experimental?: {\n /** @deprecated Use the top-level `compiler` option. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = resolveCompilerOption(options, true);\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n compiler: normalizedCompiler,\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
package/dist/list.cjs
CHANGED
|
@@ -10,8 +10,14 @@ 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
14
|
function materializeIterable(source) {
|
|
14
15
|
if (source == null) return [];
|
|
16
|
+
if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
|
|
17
|
+
const items2 = [];
|
|
18
|
+
for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
|
|
19
|
+
return items2;
|
|
20
|
+
}
|
|
15
21
|
const iterator = source[Symbol.iterator]();
|
|
16
22
|
const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
|
|
17
23
|
if (oneShot) {
|
package/dist/list.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["React"],"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A,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 = 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,8 +4,14 @@ 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
8
|
function materializeIterable(source) {
|
|
8
9
|
if (source == null) return [];
|
|
10
|
+
if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
|
|
11
|
+
const items2 = [];
|
|
12
|
+
for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
|
|
13
|
+
return items2;
|
|
14
|
+
}
|
|
9
15
|
const iterator = source[Symbol.iterator]();
|
|
10
16
|
const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
|
|
11
17
|
if (oneShot) {
|
package/dist/list.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM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K,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 = 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
|
@@ -4787,6 +4787,19 @@ function keyedRowConditionalObject(conditional, parameters) {
|
|
|
4787
4787
|
}
|
|
4788
4788
|
return core.types.objectExpression(properties);
|
|
4789
4789
|
}
|
|
4790
|
+
var UNCLONEABLE_KEYED_ROW_TAGS = /* @__PURE__ */ new Set(["input", "option", "select", "textarea"]);
|
|
4791
|
+
function canCloneKeyedRows(plan) {
|
|
4792
|
+
if (plan.descriptorBlocks?.size || plan.conditionals.length > 0) return false;
|
|
4793
|
+
if (plan.bindings.some((binding) => binding.kind === "style")) return false;
|
|
4794
|
+
const cloneable = (element) => {
|
|
4795
|
+
const tag = element.openingElement.name;
|
|
4796
|
+
if (!core.types.isJSXIdentifier(tag) || tag.name.includes("-") || UNCLONEABLE_KEYED_ROW_TAGS.has(tag.name)) {
|
|
4797
|
+
return false;
|
|
4798
|
+
}
|
|
4799
|
+
return element.children.every((child) => !core.types.isJSXElement(child) || cloneable(child));
|
|
4800
|
+
};
|
|
4801
|
+
return cloneable(plan.row);
|
|
4802
|
+
}
|
|
4790
4803
|
function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFilterHintedStateIndices, keyedArrayPrependHintedStateIndices, keyedArrayPositionHintedStateIndices, keyedArrayReorderHintedStateIndices) {
|
|
4791
4804
|
const name = core.types.jsxMemberExpression(
|
|
4792
4805
|
core.types.jsxIdentifier(blockRuntime.name),
|
|
@@ -4923,6 +4936,12 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
|
|
|
4923
4936
|
core.types.jsxIdentifier("hostBlocks"),
|
|
4924
4937
|
core.types.jsxExpressionContainer(core.types.booleanLiteral(true))
|
|
4925
4938
|
)
|
|
4939
|
+
] : [],
|
|
4940
|
+
...canCloneKeyedRows(plan) ? [
|
|
4941
|
+
core.types.jsxAttribute(
|
|
4942
|
+
core.types.jsxIdentifier("cloneRows"),
|
|
4943
|
+
core.types.jsxExpressionContainer(core.types.booleanLiteral(true))
|
|
4944
|
+
)
|
|
4926
4945
|
] : []
|
|
4927
4946
|
],
|
|
4928
4947
|
true
|
|
@@ -7704,6 +7723,29 @@ async function compileReactModule(code, id, options) {
|
|
|
7704
7723
|
optimizations: optimizationCounts
|
|
7705
7724
|
};
|
|
7706
7725
|
}
|
|
7726
|
+
|
|
7727
|
+
// src/compiler-options.ts
|
|
7728
|
+
var warnedExperimentalCompiler = false;
|
|
7729
|
+
function resolveCompilerOption(options = {}, warnDeprecated = false) {
|
|
7730
|
+
const experimental = options.experimental;
|
|
7731
|
+
const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
|
|
7732
|
+
if (legacy !== void 0 && options.compiler !== void 0) {
|
|
7733
|
+
throw new TypeError(
|
|
7734
|
+
"Configure the React compiler with `compiler` only; remove `experimental.compiler`."
|
|
7735
|
+
);
|
|
7736
|
+
}
|
|
7737
|
+
const compiler = legacy === void 0 ? options.compiler : legacy;
|
|
7738
|
+
if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
|
|
7739
|
+
throw new TypeError("React compiler must be a boolean or compiler options object.");
|
|
7740
|
+
}
|
|
7741
|
+
if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
|
|
7742
|
+
warnedExperimentalCompiler = true;
|
|
7743
|
+
console.warn(
|
|
7744
|
+
"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
|
|
7745
|
+
);
|
|
7746
|
+
}
|
|
7747
|
+
return compiler;
|
|
7748
|
+
}
|
|
7707
7749
|
function projectRelativeId(projectRoot, id) {
|
|
7708
7750
|
return path.relative(projectRoot, id).replace(/\\/g, "/");
|
|
7709
7751
|
}
|
|
@@ -7873,16 +7915,9 @@ function normalizeReactCompilerOptions(value) {
|
|
|
7873
7915
|
|
|
7874
7916
|
// src/vite.ts
|
|
7875
7917
|
function readCompilerOptions(rendererOptions) {
|
|
7876
|
-
const
|
|
7877
|
-
if (!experimental || typeof experimental !== "object") return false;
|
|
7878
|
-
const compiler = experimental.compiler;
|
|
7918
|
+
const compiler = resolveCompilerOption(rendererOptions);
|
|
7879
7919
|
if (!compiler) return false;
|
|
7880
7920
|
if (compiler === true) return normalizeReactCompilerOptions(true);
|
|
7881
|
-
if (typeof compiler !== "object") {
|
|
7882
|
-
throw new TypeError(
|
|
7883
|
-
"React experimental.compiler must be a boolean or compiler options object."
|
|
7884
|
-
);
|
|
7885
|
-
}
|
|
7886
7921
|
const normalized = compiler;
|
|
7887
7922
|
if ((normalized.mode === "infer" || normalized.mode === "annotation") && typeof normalized.directive === "string" && (normalized.reactivity === "static" || normalized.reactivity === "hybrid") && (normalized.onUnsupported === "fallback" || normalized.onUnsupported === "warn" || normalized.onUnsupported === "error")) {
|
|
7888
7923
|
return normalized;
|