@oxc-transform-react/binding-wasm32-wasi 0.0.1 → 0.144.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,327 @@
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
+ /**
126
+ * Enable exhaustive manual memo dependency validation.
127
+ *
128
+ * @default false
129
+ */
130
+ validateExhaustiveMemoizationDependencies?: boolean
131
+ validateExhaustiveEffectDependencies?: 'off' | 'all' | 'missing-only' | 'extra-only'
132
+ enableOptionalDependencies?: boolean
133
+ enableNameAnonymousFunctions?: boolean
134
+ validateHooksUsage?: boolean
135
+ validateRefAccessDuringRender?: boolean
136
+ validateNoSetStateInRender?: boolean
137
+ enableUseKeyedState?: boolean
138
+ validateNoSetStateInEffects?: boolean
139
+ validateNoDerivedComputationsInEffects?: boolean
140
+ validateNoDerivedComputationsInEffectsExp?: boolean
141
+ validateNoJsxInTryStatements?: boolean
142
+ validateStaticComponents?: boolean
143
+ validateNoCapitalizedCalls?: Array<string>
144
+ validateBlocklistedImports?: Array<string>
145
+ validateSourceLocations?: boolean
146
+ validateNoImpureFunctionsInRender?: boolean
147
+ validateNoFreezingKnownMutableFunctions?: boolean
148
+ enableAssumeHooksFollowRulesOfReact?: boolean
149
+ enableTransitivelyFreezeFunctionExpressions?: boolean
150
+ enableFunctionOutlining?: boolean
151
+ enableJsxOutlining?: boolean
152
+ assertValidMutableRanges?: boolean
153
+ enableCustomTypeDefinitionForReanimated?: boolean
154
+ enableTreatRefLikeIdentifiersAsRefs?: boolean
155
+ enableTreatSetIdentifiersAsStateSetters?: boolean
156
+ validateNoVoidUseMemo?: boolean
157
+ enableAllowSetStateFromRefsInEffects?: boolean
158
+ enableVerboseNoSetStateInEffect?: boolean
159
+ enableForest?: boolean
160
+ }
161
+
162
+ /** Static feature-gating import. */
163
+ export interface ReactCompilerGating {
164
+ source: string
165
+ importSpecifierName: string
166
+ }
167
+
168
+ /** Meta-internal React runtime target. */
169
+ export interface ReactCompilerMetaTarget {
170
+ kind: 'donotuse_meta_internal'
171
+ runtimeModule?: string
172
+ }
173
+
174
+ /**
175
+ * React Compiler options.
176
+ *
177
+ * Fields mirror `babel-plugin-react-compiler` and `react-compiler-napi`.
178
+ */
179
+ export interface ReactCompilerOptions {
180
+ /**
181
+ * Which functions the compiler attempts to compile.
182
+ *
183
+ * @default 'infer'
184
+ */
185
+ compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all'
186
+ /**
187
+ * When compiler diagnostics escalate into a hard failure.
188
+ *
189
+ * @default 'none'
190
+ */
191
+ panicThreshold?: 'none' | 'critical_errors' | 'all_errors'
192
+ /**
193
+ * React runtime target. React 17 and 18 use `react-compiler-runtime`;
194
+ * React 19 uses `react/compiler-runtime`.
195
+ *
196
+ * @default '19'
197
+ */
198
+ target?: '17' | '18' | '19' | ReactCompilerMetaTarget
199
+ /** Emit both compiled and original functions behind an imported feature gate. */
200
+ gating?: ReactCompilerGating
201
+ /** Enable `"use memo if(...)"` directive-driven gating. */
202
+ dynamicGating?: ReactCompilerDynamicGating
203
+ /**
204
+ * Analyze and report diagnostics without applying compiler output.
205
+ *
206
+ * @deprecated Prefer `outputMode: "lint"`.
207
+ * @default false
208
+ */
209
+ noEmit?: boolean
210
+ /** Select client, SSR, or lint output. */
211
+ outputMode?: 'client' | 'ssr' | 'lint'
212
+ /**
213
+ * ESLint rule names whose suppressions opt a function out of compilation when
214
+ * hooks usage or exhaustive memoization dependency validation is disabled.
215
+ */
216
+ eslintSuppressionRules?: Array<string>
217
+ /**
218
+ * Treat Flow suppression comments as opt-outs.
219
+ *
220
+ * @default true
221
+ */
222
+ flowSuppressions?: boolean
223
+ /**
224
+ * Compile functions carrying `"use no memo"` or `"use no forget"`.
225
+ *
226
+ * @default false
227
+ */
228
+ ignoreUseNoForget?: boolean
229
+ /** Additional directives that opt a function out of compilation. */
230
+ customOptOutDirectives?: Array<string>
231
+ /**
232
+ * Only run the React Compiler when the filename contains one of these strings.
233
+ *
234
+ * Function-valued `sources` filters from the Babel plugin are intentionally
235
+ * unsupported across the native boundary.
236
+ */
237
+ sources?: Array<string>
238
+ /** Feature flags and validation settings for compiler passes. */
239
+ environment?: ReactCompilerEnvironmentOptions
240
+ }
241
+
242
+ /** React Fast Refresh options. */
243
+ export interface ReactRefreshOptions {
244
+ /**
245
+ * Specify the identifier of the refresh registration variable.
246
+ *
247
+ * @default `$RefreshReg$`
248
+ */
249
+ refreshReg?: string
250
+ /**
251
+ * Specify the identifier of the refresh signature variable.
252
+ *
253
+ * @default `$RefreshSig$`
254
+ */
255
+ refreshSig?: string
256
+ /**
257
+ * Emit full hook signatures instead of compact hashes.
258
+ *
259
+ * @default false
260
+ */
261
+ emitFullSignatures?: boolean
262
+ }
263
+
264
+ /**
265
+ * Compile a JavaScript or TypeScript React module asynchronously.
266
+ *
267
+ * This uses a worker-pool thread and can be slower than `transformSync` for a
268
+ * single small module.
269
+ */
270
+ export declare function transform(filename: string, sourceText: string, options?: TransformOptions | undefined | null): Promise<TransformResult>
271
+
272
+ /**
273
+ * Options for compiling a JavaScript or TypeScript React module.
274
+ *
275
+ * `lang`, `sourceType`, and `sourcemap` configure the surrounding Oxc
276
+ * parse/codegen pipeline. React Compiler and JSX transforms are configured
277
+ * independently.
278
+ */
279
+ export interface TransformOptions {
280
+ /** Treat the source as `js`, `jsx`, `ts`, `tsx`, or `dts`. */
281
+ lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
282
+ /** Treat the source as script, module, CommonJS, or infer it from syntax. */
283
+ sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous'
284
+ /**
285
+ * Generate a source map.
286
+ *
287
+ * @default false
288
+ */
289
+ sourcemap?: boolean
290
+ /**
291
+ * Configure how TSX and JSX are transformed, or preserve JSX syntax.
292
+ *
293
+ * @see <https://oxc.rs/docs/guide/usage/transformer/jsx>
294
+ */
295
+ jsx?: 'preserve' | JsxOptions
296
+ /**
297
+ * Configure React Compiler, or disable it with `false`.
298
+ *
299
+ * @default true
300
+ */
301
+ reactCompiler?: boolean | ReactCompilerOptions
302
+ }
303
+
304
+ /** Result returned by the React Compiler transform. */
305
+ export interface TransformResult {
306
+ /** Whether the transform was aborted without emitting code. */
307
+ fatal: boolean
308
+ /**
309
+ * Transformed JavaScript code.
310
+ *
311
+ * This is empty when parsing, semantic analysis, option validation, or the
312
+ * React Compiler reports a fatal error.
313
+ */
314
+ code: string
315
+ /** Source map, populated when `sourcemap` is `true`. */
316
+ map?: SourceMap
317
+ /** Parse, semantic, React Compiler, and downstream transform diagnostics. */
318
+ errors: Array<OxcError>
319
+ }
320
+
321
+ /**
322
+ * Compile a JavaScript or TypeScript React module synchronously.
323
+ *
324
+ * The React Compiler runs first on the pristine AST. TypeScript syntax is
325
+ * removed and configured JSX transforms run afterwards.
326
+ */
327
+ 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
+ };