@oxc-transform-react/binding-wasm32-wasi 0.0.1 → 0.142.0

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.
@@ -0,0 +1,322 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export interface Comment {
4
+ type: 'Line' | 'Block'
5
+ value: string
6
+ start: number
7
+ end: number
8
+ }
9
+
10
+ export interface ErrorLabel {
11
+ message: string | null
12
+ start: number
13
+ end: number
14
+ }
15
+
16
+ export interface OxcError {
17
+ severity: Severity
18
+ message: string
19
+ labels: Array<ErrorLabel>
20
+ helpMessage: string | null
21
+ codeframe: string | null
22
+ }
23
+
24
+ export declare const enum Severity {
25
+ Error = 'Error',
26
+ Warning = 'Warning',
27
+ Advice = 'Advice'
28
+ }
29
+ export interface SourceMap {
30
+ file?: string
31
+ mappings: string
32
+ names: Array<string>
33
+ sourceRoot?: string
34
+ sources: Array<string>
35
+ sourcesContent?: Array<string>
36
+ version: number
37
+ x_google_ignoreList?: Array<number>
38
+ }
39
+ /**
40
+ * Configure how TSX and JSX are transformed.
41
+ *
42
+ * @see <https://oxc.rs/docs/guide/usage/transformer/jsx>
43
+ */
44
+ export interface JsxOptions {
45
+ /**
46
+ * Decides which runtime to use.
47
+ *
48
+ * - 'automatic' - auto-import the correct JSX factories
49
+ * - 'classic' - no auto-import
50
+ *
51
+ * @default 'automatic'
52
+ */
53
+ runtime?: 'classic' | 'automatic'
54
+ /**
55
+ * Emit development-specific information, such as `__source` and `__self`.
56
+ *
57
+ * @default false
58
+ */
59
+ development?: boolean
60
+ /**
61
+ * Toggles whether or not to throw an error if an XML namespaced tag name
62
+ * is used.
63
+ *
64
+ * Though the JSX spec allows this, it is disabled by default since React's
65
+ * JSX does not currently have support for it.
66
+ *
67
+ * @default true
68
+ */
69
+ throwIfNamespace?: boolean
70
+ /**
71
+ * Mark JSX elements and top-level React method calls as pure for tree shaking.
72
+ *
73
+ * @default true
74
+ */
75
+ pure?: boolean
76
+ /**
77
+ * Replaces the import source when importing functions.
78
+ *
79
+ * @default 'react'
80
+ */
81
+ importSource?: string
82
+ /**
83
+ * Replace the function used when compiling JSX expressions. It should be a
84
+ * qualified name (e.g. `React.createElement`) or an identifier (e.g.
85
+ * `createElement`).
86
+ *
87
+ * Only used for `classic` {@link runtime}.
88
+ *
89
+ * @default 'React.createElement'
90
+ */
91
+ pragma?: string
92
+ /**
93
+ * Replace the component used when compiling JSX fragments. It should be a
94
+ * valid JSX tag name.
95
+ *
96
+ * Only used for `classic` {@link runtime}.
97
+ *
98
+ * @default 'React.Fragment'
99
+ */
100
+ pragmaFrag?: string
101
+ /**
102
+ * Enable React Fast Refresh.
103
+ *
104
+ * @default false
105
+ */
106
+ refresh?: boolean | ReactRefreshOptions
107
+ }
108
+
109
+ /** Dynamic feature-gating import. */
110
+ export interface ReactCompilerDynamicGating {
111
+ source: string
112
+ }
113
+
114
+ /**
115
+ * Partial React Compiler environment configuration.
116
+ *
117
+ * Unset fields retain compiler defaults. Callback-valued providers and the
118
+ * compiler's test-only panic switch are intentionally not exposed.
119
+ */
120
+ export interface ReactCompilerEnvironmentOptions {
121
+ customMacros?: Array<string>
122
+ enableResetCacheOnSourceFileChanges?: boolean
123
+ enablePreserveExistingMemoizationGuarantees?: boolean
124
+ validatePreserveExistingMemoizationGuarantees?: boolean
125
+ validateExhaustiveMemoizationDependencies?: boolean
126
+ validateExhaustiveEffectDependencies?: 'off' | 'all' | 'missing-only' | 'extra-only'
127
+ enableOptionalDependencies?: boolean
128
+ enableNameAnonymousFunctions?: boolean
129
+ validateHooksUsage?: boolean
130
+ validateRefAccessDuringRender?: boolean
131
+ validateNoSetStateInRender?: boolean
132
+ enableUseKeyedState?: boolean
133
+ validateNoSetStateInEffects?: boolean
134
+ validateNoDerivedComputationsInEffects?: boolean
135
+ validateNoDerivedComputationsInEffectsExp?: boolean
136
+ validateNoJsxInTryStatements?: boolean
137
+ validateStaticComponents?: boolean
138
+ validateNoCapitalizedCalls?: Array<string>
139
+ validateBlocklistedImports?: Array<string>
140
+ validateSourceLocations?: boolean
141
+ validateNoImpureFunctionsInRender?: boolean
142
+ validateNoFreezingKnownMutableFunctions?: boolean
143
+ enableAssumeHooksFollowRulesOfReact?: boolean
144
+ enableTransitivelyFreezeFunctionExpressions?: boolean
145
+ enableFunctionOutlining?: boolean
146
+ enableJsxOutlining?: boolean
147
+ assertValidMutableRanges?: boolean
148
+ enableCustomTypeDefinitionForReanimated?: boolean
149
+ enableTreatRefLikeIdentifiersAsRefs?: boolean
150
+ enableTreatSetIdentifiersAsStateSetters?: boolean
151
+ validateNoVoidUseMemo?: boolean
152
+ enableAllowSetStateFromRefsInEffects?: boolean
153
+ enableVerboseNoSetStateInEffect?: boolean
154
+ enableForest?: boolean
155
+ }
156
+
157
+ /** Static feature-gating import. */
158
+ export interface ReactCompilerGating {
159
+ source: string
160
+ importSpecifierName: string
161
+ }
162
+
163
+ /** Meta-internal React runtime target. */
164
+ export interface ReactCompilerMetaTarget {
165
+ kind: 'donotuse_meta_internal'
166
+ runtimeModule?: string
167
+ }
168
+
169
+ /**
170
+ * React Compiler options.
171
+ *
172
+ * Fields mirror `babel-plugin-react-compiler` and `react-compiler-napi`.
173
+ */
174
+ export interface ReactCompilerOptions {
175
+ /**
176
+ * Which functions the compiler attempts to compile.
177
+ *
178
+ * @default 'infer'
179
+ */
180
+ compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all'
181
+ /**
182
+ * When compiler diagnostics escalate into a hard failure.
183
+ *
184
+ * @default 'none'
185
+ */
186
+ panicThreshold?: 'none' | 'critical_errors' | 'all_errors'
187
+ /**
188
+ * React runtime target. React 17 and 18 use `react-compiler-runtime`;
189
+ * React 19 uses `react/compiler-runtime`.
190
+ *
191
+ * @default '19'
192
+ */
193
+ target?: '17' | '18' | '19' | ReactCompilerMetaTarget
194
+ /** Emit both compiled and original functions behind an imported feature gate. */
195
+ gating?: ReactCompilerGating
196
+ /** Enable `"use memo if(...)"` directive-driven gating. */
197
+ dynamicGating?: ReactCompilerDynamicGating
198
+ /**
199
+ * Analyze and report diagnostics without applying compiler output.
200
+ *
201
+ * @deprecated Prefer `outputMode: "lint"`.
202
+ * @default false
203
+ */
204
+ noEmit?: boolean
205
+ /** Select client, SSR, or lint output. */
206
+ outputMode?: 'client' | 'ssr' | 'lint'
207
+ /**
208
+ * ESLint rule names whose suppressions opt a function out of compilation when
209
+ * hooks usage or exhaustive memoization dependency validation is disabled.
210
+ */
211
+ eslintSuppressionRules?: Array<string>
212
+ /**
213
+ * Treat Flow suppression comments as opt-outs.
214
+ *
215
+ * @default true
216
+ */
217
+ flowSuppressions?: boolean
218
+ /**
219
+ * Compile functions carrying `"use no memo"` or `"use no forget"`.
220
+ *
221
+ * @default false
222
+ */
223
+ ignoreUseNoForget?: boolean
224
+ /** Additional directives that opt a function out of compilation. */
225
+ customOptOutDirectives?: Array<string>
226
+ /**
227
+ * Only run the React Compiler when the filename contains one of these strings.
228
+ *
229
+ * Function-valued `sources` filters from the Babel plugin are intentionally
230
+ * unsupported across the native boundary.
231
+ */
232
+ sources?: Array<string>
233
+ /** Feature flags and validation settings for compiler passes. */
234
+ environment?: ReactCompilerEnvironmentOptions
235
+ }
236
+
237
+ /** React Fast Refresh options. */
238
+ export interface ReactRefreshOptions {
239
+ /**
240
+ * Specify the identifier of the refresh registration variable.
241
+ *
242
+ * @default `$RefreshReg$`
243
+ */
244
+ refreshReg?: string
245
+ /**
246
+ * Specify the identifier of the refresh signature variable.
247
+ *
248
+ * @default `$RefreshSig$`
249
+ */
250
+ refreshSig?: string
251
+ /**
252
+ * Emit full hook signatures instead of compact hashes.
253
+ *
254
+ * @default false
255
+ */
256
+ emitFullSignatures?: boolean
257
+ }
258
+
259
+ /**
260
+ * Compile a JavaScript or TypeScript React module asynchronously.
261
+ *
262
+ * This uses a worker-pool thread and can be slower than `transformSync` for a
263
+ * single small module.
264
+ */
265
+ export declare function transform(filename: string, sourceText: string, options?: TransformOptions | undefined | null): Promise<TransformResult>
266
+
267
+ /**
268
+ * Options for compiling a JavaScript or TypeScript React module.
269
+ *
270
+ * `lang`, `sourceType`, and `sourcemap` configure the surrounding Oxc
271
+ * parse/codegen pipeline. React Compiler and JSX transforms are configured
272
+ * independently.
273
+ */
274
+ export interface TransformOptions {
275
+ /** Treat the source as `js`, `jsx`, `ts`, `tsx`, or `dts`. */
276
+ lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
277
+ /** Treat the source as script, module, CommonJS, or infer it from syntax. */
278
+ sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous'
279
+ /**
280
+ * Generate a source map.
281
+ *
282
+ * @default false
283
+ */
284
+ sourcemap?: boolean
285
+ /**
286
+ * Configure how TSX and JSX are transformed, or preserve JSX syntax.
287
+ *
288
+ * @see <https://oxc.rs/docs/guide/usage/transformer/jsx>
289
+ */
290
+ jsx?: 'preserve' | JsxOptions
291
+ /**
292
+ * Configure React Compiler, or disable it with `false`.
293
+ *
294
+ * @default true
295
+ */
296
+ reactCompiler?: boolean | ReactCompilerOptions
297
+ }
298
+
299
+ /** Result returned by the React Compiler transform. */
300
+ export interface TransformResult {
301
+ /** Whether the transform was aborted without emitting code. */
302
+ fatal: boolean
303
+ /**
304
+ * Transformed JavaScript code.
305
+ *
306
+ * This is empty when parsing, semantic analysis, option validation, or the
307
+ * React Compiler reports a fatal error.
308
+ */
309
+ code: string
310
+ /** Source map, populated when `sourcemap` is `true`. */
311
+ map?: SourceMap
312
+ /** Parse, semantic, React Compiler, and downstream transform diagnostics. */
313
+ errors: Array<OxcError>
314
+ }
315
+
316
+ /**
317
+ * Compile a JavaScript or TypeScript React module synchronously.
318
+ *
319
+ * The React Compiler runs first on the pristine AST. TypeScript syntax is
320
+ * removed and configured JSX transforms run afterwards.
321
+ */
322
+ export declare function transformSync(filename: string, sourceText: string, options?: TransformOptions | undefined | null): TransformResult
Binary file
@@ -0,0 +1,45 @@
1
+ import {
2
+ instantiateNapiModuleSync,
3
+ MessageHandler,
4
+ WASI,
5
+ emnapiAsyncWorkPlugin,
6
+ emnapiTSFNPlugin,
7
+ } from '@napi-rs/wasm-runtime'
8
+
9
+ const handler = new MessageHandler({
10
+ onLoad({ wasmModule, wasmMemory }) {
11
+ const wasi = new WASI({
12
+ print: function () {
13
+ // eslint-disable-next-line no-console
14
+ console.log.apply(console, arguments)
15
+ },
16
+ printErr: function() {
17
+ // eslint-disable-next-line no-console
18
+ console.error.apply(console, arguments)
19
+
20
+ },
21
+ })
22
+ return instantiateNapiModuleSync(wasmModule, {
23
+ childThread: true,
24
+ wasi,
25
+ // The wasm links a "basic" emnapi archive (no C async-work /
26
+ // threadsafe-function implementations), so every thread that
27
+ // instantiates it must provide the JavaScript implementations
28
+ // through the emnapi plugins.
29
+ plugins: [emnapiAsyncWorkPlugin, emnapiTSFNPlugin],
30
+ overwriteImports(importObject) {
31
+ importObject.env = {
32
+ ...importObject.env,
33
+ ...importObject.napi,
34
+ ...importObject.emnapi,
35
+ memory: wasmMemory,
36
+ }
37
+ },
38
+ })
39
+ },
40
+
41
+ })
42
+
43
+ globalThis.onmessage = function (e) {
44
+ handler.handle(e)
45
+ }
@@ -0,0 +1,74 @@
1
+ import fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { parse } from "node:path";
4
+ import { WASI } from "node:wasi";
5
+ import { parentPort, Worker } from "node:worker_threads";
6
+
7
+ const require = createRequire(import.meta.url);
8
+
9
+ const {
10
+ instantiateNapiModuleSync,
11
+ MessageHandler,
12
+ getDefaultContext,
13
+ emnapiAsyncWorkPlugin,
14
+ emnapiTSFNPlugin,
15
+ } = require("@napi-rs/wasm-runtime");
16
+
17
+ if (parentPort) {
18
+ parentPort.on("message", (data) => {
19
+ globalThis.onmessage({ data });
20
+ });
21
+ }
22
+
23
+ Object.assign(globalThis, {
24
+ self: globalThis,
25
+ require,
26
+ Worker,
27
+ importScripts: function (f) {
28
+ ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
29
+ },
30
+ postMessage: function (msg) {
31
+ if (parentPort) {
32
+ parentPort.postMessage(msg);
33
+ }
34
+ },
35
+ });
36
+
37
+ const emnapiContext = getDefaultContext();
38
+
39
+ const __rootDir = parse(process.cwd()).root;
40
+
41
+ const handler = new MessageHandler({
42
+ onLoad({ wasmModule, wasmMemory }) {
43
+ const wasi = new WASI({
44
+ version: 'preview1',
45
+ env: process.env,
46
+ preopens: {
47
+ [__rootDir]: __rootDir,
48
+ },
49
+ });
50
+
51
+ return instantiateNapiModuleSync(wasmModule, {
52
+ childThread: true,
53
+ wasi,
54
+ context: emnapiContext,
55
+ // The wasm links a "basic" emnapi archive (no C async-work /
56
+ // threadsafe-function implementations), so every thread that
57
+ // instantiates it must provide the JavaScript implementations
58
+ // through the emnapi plugins.
59
+ plugins: [emnapiAsyncWorkPlugin, emnapiTSFNPlugin],
60
+ overwriteImports(importObject) {
61
+ importObject.env = {
62
+ ...importObject.env,
63
+ ...importObject.napi,
64
+ ...importObject.emnapi,
65
+ memory: wasmMemory
66
+ };
67
+ },
68
+ });
69
+ },
70
+ });
71
+
72
+ globalThis.onmessage = function (e) {
73
+ handler.handle(e);
74
+ };