oxc-transform-react-compiler-experimental 0.0.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.
package/index.d.ts ADDED
@@ -0,0 +1,782 @@
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
+ export interface ArrowFunctionsOptions {
40
+ /**
41
+ * This option enables the following:
42
+ * * Wrap the generated function in .bind(this) and keeps uses of this inside the function as-is, instead of using a renamed this.
43
+ * * Add a runtime check to ensure the functions are not instantiated.
44
+ * * Add names to arrow functions.
45
+ *
46
+ * @default false
47
+ */
48
+ spec?: boolean
49
+ }
50
+
51
+ export interface CompilerAssumptions {
52
+ ignoreFunctionLength?: boolean
53
+ noDocumentAll?: boolean
54
+ objectRestNoSymbols?: boolean
55
+ pureGetters?: boolean
56
+ /**
57
+ * When using public class fields, assume that they don't shadow any getter in the current class,
58
+ * in its subclasses or in its superclass. Thus, it's safe to assign them rather than using
59
+ * `Object.defineProperty`.
60
+ *
61
+ * For example:
62
+ *
63
+ * Input:
64
+ * ```js
65
+ * class Test {
66
+ * field = 2;
67
+ *
68
+ * static staticField = 3;
69
+ * }
70
+ * ```
71
+ *
72
+ * When `set_public_class_fields` is `true`, the output will be:
73
+ * ```js
74
+ * class Test {
75
+ * constructor() {
76
+ * this.field = 2;
77
+ * }
78
+ * }
79
+ * Test.staticField = 3;
80
+ * ```
81
+ *
82
+ * Otherwise, the output will be:
83
+ * ```js
84
+ * import _defineProperty from "@oxc-project/runtime/helpers/defineProperty";
85
+ * class Test {
86
+ * constructor() {
87
+ * _defineProperty(this, "field", 2);
88
+ * }
89
+ * }
90
+ * _defineProperty(Test, "staticField", 3);
91
+ * ```
92
+ *
93
+ * NOTE: For TypeScript, if you wanted behavior is equivalent to `useDefineForClassFields: false`, you should
94
+ * set both `set_public_class_fields` and [`crate::TypeScriptOptions::remove_class_fields_without_initializer`]
95
+ * to `true`.
96
+ */
97
+ setPublicClassFields?: boolean
98
+ }
99
+
100
+ export interface DecoratorOptions {
101
+ /**
102
+ * Enables experimental support for decorators, which is a version of decorators that predates the TC39 standardization process.
103
+ *
104
+ * Decorators are a language feature which hasn’t yet been fully ratified into the JavaScript specification.
105
+ * This means that the implementation version in TypeScript may differ from the implementation in JavaScript when it it decided by TC39.
106
+ *
107
+ * @see https://www.typescriptlang.org/tsconfig/#experimentalDecorators
108
+ * @default false
109
+ */
110
+ legacy?: boolean
111
+ /**
112
+ * Enables emitting decorator metadata.
113
+ *
114
+ * This option the same as [emitDecoratorMetadata](https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata)
115
+ * in TypeScript, and it only works when `legacy` is true.
116
+ *
117
+ * @see https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata
118
+ * @default false
119
+ */
120
+ emitDecoratorMetadata?: boolean
121
+ }
122
+
123
+ /** Configuration for dynamic gating via `use memo if(...)` directives. */
124
+ export interface DynamicGatingConfig {
125
+ /** The module source to import from. */
126
+ source: string
127
+ }
128
+
129
+ export interface Es2015Options {
130
+ /** Transform arrow functions into function expressions. */
131
+ arrowFunction?: ArrowFunctionsOptions
132
+ }
133
+
134
+ /** Configuration for an external function import used for gating. */
135
+ export interface ExternalFunctionConfig {
136
+ /** The module source to import from. */
137
+ source: string
138
+ /** The import specifier name. */
139
+ importSpecifierName: string
140
+ }
141
+
142
+ export declare const enum HelperMode {
143
+ /**
144
+ * Runtime mode (default): Helper functions are imported from a runtime package.
145
+ *
146
+ * Example:
147
+ *
148
+ * ```js
149
+ * import helperName from "@oxc-project/runtime/helpers/helperName";
150
+ * helperName(...arguments);
151
+ * ```
152
+ */
153
+ Runtime = 'Runtime',
154
+ /**
155
+ * External mode: Helper functions are accessed from a global `babelHelpers` object.
156
+ *
157
+ * Example:
158
+ *
159
+ * ```js
160
+ * babelHelpers.helperName(...arguments);
161
+ * ```
162
+ */
163
+ External = 'External'
164
+ }
165
+
166
+ export interface Helpers {
167
+ mode?: HelperMode
168
+ }
169
+
170
+ /**
171
+ * TypeScript Isolated Declarations for Standalone DTS Emit (async)
172
+ *
173
+ * Note: This function can be slower than `isolatedDeclarationSync` due to the overhead of spawning a thread.
174
+ */
175
+ export declare function isolatedDeclaration(filename: string, sourceText: string, options?: IsolatedDeclarationsOptions | undefined | null): Promise<IsolatedDeclarationsResult>
176
+
177
+ export interface IsolatedDeclarationsOptions {
178
+ /**
179
+ * Do not emit declarations for code that has an @internal annotation in its JSDoc comment.
180
+ * This is an internal compiler option; use at your own risk, because the compiler does not check that the result is valid.
181
+ *
182
+ * Default: `false`
183
+ *
184
+ * See <https://www.typescriptlang.org/tsconfig/#stripInternal>
185
+ */
186
+ stripInternal?: boolean
187
+ sourcemap?: boolean
188
+ }
189
+
190
+ export interface IsolatedDeclarationsResult {
191
+ code: string
192
+ map?: SourceMap
193
+ errors: Array<OxcError>
194
+ }
195
+
196
+ /** TypeScript Isolated Declarations for Standalone DTS Emit */
197
+ export declare function isolatedDeclarationSync(filename: string, sourceText: string, options?: IsolatedDeclarationsOptions | undefined | null): IsolatedDeclarationsResult
198
+
199
+ /**
200
+ * Configure how TSX and JSX are transformed.
201
+ *
202
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/jsx}
203
+ */
204
+ export interface JsxOptions {
205
+ /**
206
+ * Decides which runtime to use.
207
+ *
208
+ * - 'automatic' - auto-import the correct JSX factories
209
+ * - 'classic' - no auto-import
210
+ *
211
+ * @default 'automatic'
212
+ */
213
+ runtime?: 'classic' | 'automatic'
214
+ /**
215
+ * Emit development-specific information, such as `__source` and `__self`.
216
+ *
217
+ * @default false
218
+ */
219
+ development?: boolean
220
+ /**
221
+ * Toggles whether or not to throw an error if an XML namespaced tag name
222
+ * is used.
223
+ *
224
+ * Though the JSX spec allows this, it is disabled by default since React's
225
+ * JSX does not currently have support for it.
226
+ *
227
+ * @default true
228
+ */
229
+ throwIfNamespace?: boolean
230
+ /**
231
+ * Mark JSX elements and top-level React method calls as pure for tree shaking.
232
+ *
233
+ * @default true
234
+ */
235
+ pure?: boolean
236
+ /**
237
+ * Replaces the import source when importing functions.
238
+ *
239
+ * @default 'react'
240
+ */
241
+ importSource?: string
242
+ /**
243
+ * Replace the function used when compiling JSX expressions. It should be a
244
+ * qualified name (e.g. `React.createElement`) or an identifier (e.g.
245
+ * `createElement`).
246
+ *
247
+ * Only used for `classic` {@link runtime}.
248
+ *
249
+ * @default 'React.createElement'
250
+ */
251
+ pragma?: string
252
+ /**
253
+ * Replace the component used when compiling JSX fragments. It should be a
254
+ * valid JSX tag name.
255
+ *
256
+ * Only used for `classic` {@link runtime}.
257
+ *
258
+ * @default 'React.Fragment'
259
+ */
260
+ pragmaFrag?: string
261
+ /**
262
+ * Enable React Fast Refresh .
263
+ *
264
+ * Conforms to the implementation in {@link https://github.com/facebook/react/tree/v18.3.1/packages/react-refresh}
265
+ *
266
+ * @default false
267
+ */
268
+ refresh?: boolean | ReactRefreshOptions
269
+ }
270
+
271
+ /**
272
+ * Transform JavaScript code to a Vite Node runnable module.
273
+ *
274
+ * @param filename The name of the file being transformed.
275
+ * @param sourceText the source code itself
276
+ * @param options The options for the transformation. See {@link
277
+ * ModuleRunnerTransformOptions} for more information.
278
+ *
279
+ * @returns an object containing the transformed code, source maps, and any
280
+ * errors that occurred during parsing or transformation.
281
+ *
282
+ * Note: This function can be slower than `moduleRunnerTransformSync` due to the overhead of spawning a thread.
283
+ *
284
+ * @deprecated Only works for Vite.
285
+ */
286
+ export declare function moduleRunnerTransform(filename: string, sourceText: string, options?: ModuleRunnerTransformOptions | undefined | null): Promise<ModuleRunnerTransformResult>
287
+
288
+ export interface ModuleRunnerTransformOptions {
289
+ /**
290
+ * Enable source map generation.
291
+ *
292
+ * When `true`, the `sourceMap` field of transform result objects will be populated.
293
+ *
294
+ * @default false
295
+ *
296
+ * @see {@link SourceMap}
297
+ */
298
+ sourcemap?: boolean
299
+ }
300
+
301
+ export interface ModuleRunnerTransformResult {
302
+ /**
303
+ * The transformed code.
304
+ *
305
+ * If parsing failed, this will be an empty string.
306
+ */
307
+ code: string
308
+ /**
309
+ * The source map for the transformed code.
310
+ *
311
+ * This will be set if {@link TransformOptions#sourcemap} is `true`.
312
+ */
313
+ map?: SourceMap
314
+ deps: Array<string>
315
+ dynamicDeps: Array<string>
316
+ /**
317
+ * Parse and transformation errors.
318
+ *
319
+ * Oxc's parser recovers from common syntax errors, meaning that
320
+ * transformed code may still be available even if there are errors in this
321
+ * list.
322
+ */
323
+ errors: Array<OxcError>
324
+ }
325
+
326
+ /** @deprecated Only works for Vite. */
327
+ export declare function moduleRunnerTransformSync(filename: string, sourceText: string, options?: ModuleRunnerTransformOptions | undefined | null): ModuleRunnerTransformResult
328
+
329
+ export interface PluginsOptions {
330
+ styledComponents?: StyledComponentsOptions
331
+ taggedTemplateEscape?: boolean
332
+ reactCompiler?: boolean | ReactCompilerOptions
333
+ }
334
+
335
+ /** Configure React Compiler behavior in the transformer pipeline. */
336
+ export interface ReactCompilerOptions {
337
+ /**
338
+ * Enables the React Compiler plugin.
339
+ *
340
+ * @default true
341
+ */
342
+ enabled?: boolean
343
+ /**
344
+ * Strategy used to decide which functions to compile.
345
+ *
346
+ * - "infer" - infer components/hooks by naming convention
347
+ * - "annotation" - compile only opt-in directives
348
+ * - "all" - compile all functions
349
+ * - "syntax" - compile only syntax-marked functions
350
+ *
351
+ * @default "infer"
352
+ */
353
+ compilationMode?: string
354
+ /**
355
+ * Panic threshold for compilation failures.
356
+ *
357
+ * - "none"
358
+ * - "critical_errors"
359
+ * - "all_errors"
360
+ *
361
+ * @default "none"
362
+ */
363
+ panicThreshold?: string
364
+ /**
365
+ * Target React version.
366
+ *
367
+ * Controls which runtime module to import:
368
+ * - "react-17" / "react-18" -> "react-compiler-runtime" (npm package)
369
+ * - "react-19" (default) -> "react/compiler-runtime" (from react namespace)
370
+ *
371
+ * @default "react-19"
372
+ */
373
+ target?: string
374
+ /**
375
+ * Whether to validate hooks usage (Rules of Hooks).
376
+ *
377
+ * @default true
378
+ */
379
+ validateHooksUsage?: boolean
380
+ /**
381
+ * Whether to validate ref access during render.
382
+ *
383
+ * @default true
384
+ */
385
+ validateRefAccessDuringRender?: boolean
386
+ /**
387
+ * Whether to validate no setState in render.
388
+ *
389
+ * @default true
390
+ */
391
+ validateNoSetStateInRender?: boolean
392
+ /**
393
+ * Output mode: "client", "ssr", "lint".
394
+ * When not set, defaults to "client" (or "lint" if `noEmit` is true).
395
+ */
396
+ outputMode?: string
397
+ /**
398
+ * When true, the compiler still runs validation but does not emit compiled output.
399
+ * Equivalent to setting `outputMode` to "lint".
400
+ */
401
+ noEmit?: boolean
402
+ /** Whether to ignore "use no forget" / "use no memo" directives. */
403
+ ignoreUseNoForget?: boolean
404
+ /** Custom opt-out directives (in addition to "use no memo" / "use no forget"). */
405
+ customOptOutDirectives?: Array<string>
406
+ /**
407
+ * Gating function config. When set, emits gated output that wraps
408
+ * compiled + original functions behind a feature flag.
409
+ */
410
+ gating?: ExternalFunctionConfig
411
+ /** Dynamic gating config. When set, enables `use memo if(...)` directives. */
412
+ dynamicGating?: DynamicGatingConfig
413
+ /**
414
+ * ESLint suppression rules to check for when scanning for suppression comments.
415
+ *
416
+ * @default `["react-hooks/rules-of-hooks", "react-hooks/exhaustive-deps"]`
417
+ */
418
+ eslintSuppressionRules?: Array<string>
419
+ /**
420
+ * Whether to bail on Flow suppression comments.
421
+ *
422
+ * @default true
423
+ */
424
+ flowSuppressions?: boolean
425
+ /**
426
+ * Array of filename regex patterns to filter which files get compiled.
427
+ * When set, only files whose path matches at least one pattern will be compiled.
428
+ */
429
+ sources?: Array<string>
430
+ /**
431
+ * Enable optional dependency tracking for optional chain expressions.
432
+ *
433
+ * @default true
434
+ */
435
+ enableOptionalDependencies?: boolean
436
+ /**
437
+ * Enable transitive freezing of function expression captures.
438
+ *
439
+ * @default true
440
+ */
441
+ enableTransitivelyFreezeFunctionExpressions?: boolean
442
+ /**
443
+ * Enable treating ref-like identifiers as refs for type inference.
444
+ *
445
+ * @default true
446
+ */
447
+ enableTreatRefLikeIdentifiersAsRefs?: boolean
448
+ /**
449
+ * Validate that useMemo/useCallback results are not void.
450
+ *
451
+ * @default true
452
+ */
453
+ validateNoVoidUseMemo?: boolean
454
+ /**
455
+ * Validate exhaustive memoization dependencies.
456
+ *
457
+ * @default true
458
+ */
459
+ validateExhaustiveMemoizationDependencies?: boolean
460
+ }
461
+
462
+ export interface ReactRefreshOptions {
463
+ /**
464
+ * Specify the identifier of the refresh registration variable.
465
+ *
466
+ * @default `$RefreshReg$`.
467
+ */
468
+ refreshReg?: string
469
+ /**
470
+ * Specify the identifier of the refresh signature variable.
471
+ *
472
+ * @default `$RefreshSig$`.
473
+ */
474
+ refreshSig?: string
475
+ emitFullSignatures?: boolean
476
+ }
477
+
478
+ /**
479
+ * Configure how styled-components are transformed.
480
+ *
481
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/plugins#styled-components}
482
+ */
483
+ export interface StyledComponentsOptions {
484
+ /**
485
+ * Enhances the attached CSS class name on each component with richer output to help
486
+ * identify your components in the DOM without React DevTools.
487
+ *
488
+ * @default true
489
+ */
490
+ displayName?: boolean
491
+ /**
492
+ * Controls whether the `displayName` of a component will be prefixed with the filename
493
+ * to make the component name as unique as possible.
494
+ *
495
+ * @default true
496
+ */
497
+ fileName?: boolean
498
+ /**
499
+ * Adds a unique identifier to every styled component to avoid checksum mismatches
500
+ * due to different class generation on the client and server during server-side rendering.
501
+ *
502
+ * @default true
503
+ */
504
+ ssr?: boolean
505
+ /**
506
+ * Transpiles styled-components tagged template literals to a smaller representation
507
+ * than what Babel normally creates, helping to reduce bundle size.
508
+ *
509
+ * @default true
510
+ */
511
+ transpileTemplateLiterals?: boolean
512
+ /**
513
+ * Minifies CSS content by removing all whitespace and comments from your CSS,
514
+ * keeping valuable bytes out of your bundles.
515
+ *
516
+ * @default true
517
+ */
518
+ minify?: boolean
519
+ /**
520
+ * Enables transformation of JSX `css` prop when using styled-components.
521
+ *
522
+ * **Note: This feature is not yet implemented in oxc.**
523
+ *
524
+ * @default true
525
+ */
526
+ cssProp?: boolean
527
+ /**
528
+ * Enables "pure annotation" to aid dead code elimination by bundlers.
529
+ *
530
+ * @default false
531
+ */
532
+ pure?: boolean
533
+ /**
534
+ * Adds a namespace prefix to component identifiers to ensure class names are unique.
535
+ *
536
+ * Example: With `namespace: "my-app"`, generates `componentId: "my-app__sc-3rfj0a-1"`
537
+ */
538
+ namespace?: string
539
+ /**
540
+ * List of file names that are considered meaningless for component naming purposes.
541
+ *
542
+ * When the `fileName` option is enabled and a component is in a file with a name
543
+ * from this list, the directory name will be used instead of the file name for
544
+ * the component's display name.
545
+ *
546
+ * @default `["index"]`
547
+ */
548
+ meaninglessFileNames?: Array<string>
549
+ /**
550
+ * Import paths to be considered as styled-components imports at the top level.
551
+ *
552
+ * **Note: This feature is not yet implemented in oxc.**
553
+ */
554
+ topLevelImportPaths?: Array<string>
555
+ }
556
+
557
+ /**
558
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
559
+ *
560
+ * Note: This function can be slower than `transform` due to the overhead of spawning a thread.
561
+ *
562
+ * @param filename The name of the file being transformed. If this is a
563
+ * relative path, consider setting the {@link TransformOptions#cwd} option.
564
+ * @param sourceText the source code itself
565
+ * @param options The options for the transformation. See {@link
566
+ * TransformOptions} for more information.
567
+ *
568
+ * @returns a promise that resolves to an object containing the transformed code,
569
+ * source maps, and any errors that occurred during parsing or transformation.
570
+ */
571
+ export declare function transform(filename: string, sourceText: string, options?: TransformOptions | undefined | null): Promise<TransformResult>
572
+
573
+ /**
574
+ * Options for transforming a JavaScript or TypeScript file.
575
+ *
576
+ * @see {@link transform}
577
+ */
578
+ export interface TransformOptions {
579
+ /** Treat the source text as `js`, `jsx`, `ts`, `tsx`, or `dts`. */
580
+ lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
581
+ /** Treat the source text as `script` or `module` code. */
582
+ sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined
583
+ /**
584
+ * The current working directory. Used to resolve relative paths in other
585
+ * options.
586
+ */
587
+ cwd?: string
588
+ /**
589
+ * Enable source map generation.
590
+ *
591
+ * When `true`, the `sourceMap` field of transform result objects will be populated.
592
+ *
593
+ * @default false
594
+ *
595
+ * @see {@link SourceMap}
596
+ */
597
+ sourcemap?: boolean
598
+ /** Set assumptions in order to produce smaller output. */
599
+ assumptions?: CompilerAssumptions
600
+ /**
601
+ * Configure how TypeScript is transformed.
602
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/typescript}
603
+ */
604
+ typescript?: TypeScriptOptions
605
+ /**
606
+ * Configure how TSX and JSX are transformed.
607
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/jsx}
608
+ */
609
+ jsx?: 'preserve' | JsxOptions
610
+ /**
611
+ * Sets the target environment for the generated JavaScript.
612
+ *
613
+ * The lowest target is `es2015`.
614
+ *
615
+ * Example:
616
+ *
617
+ * * `'es2015'`
618
+ * * `['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11']`
619
+ *
620
+ * @default `esnext` (No transformation)
621
+ *
622
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/lowering#target}
623
+ */
624
+ target?: string | Array<string>
625
+ /** Behaviour for runtime helpers. */
626
+ helpers?: Helpers
627
+ /**
628
+ * Define Plugin
629
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#define}
630
+ */
631
+ define?: Record<string, string>
632
+ /**
633
+ * Inject Plugin
634
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#inject}
635
+ */
636
+ inject?: Record<string, string | [string, string]>
637
+ /** Decorator plugin */
638
+ decorator?: DecoratorOptions
639
+ /**
640
+ * Third-party plugins to use.
641
+ * @see {@link https://oxc.rs/docs/guide/usage/transformer/plugins}
642
+ */
643
+ plugins?: PluginsOptions
644
+ }
645
+
646
+ export interface TransformResult {
647
+ /**
648
+ * The transformed code.
649
+ *
650
+ * If parsing failed, this will be an empty string.
651
+ */
652
+ code: string
653
+ /**
654
+ * The source map for the transformed code.
655
+ *
656
+ * This will be set if {@link TransformOptions#sourcemap} is `true`.
657
+ */
658
+ map?: SourceMap
659
+ /**
660
+ * The `.d.ts` declaration file for the transformed code. Declarations are
661
+ * only generated if `declaration` is set to `true` and a TypeScript file
662
+ * is provided.
663
+ *
664
+ * If parsing failed and `declaration` is set, this will be an empty string.
665
+ *
666
+ * @see {@link TypeScriptOptions#declaration}
667
+ * @see [declaration tsconfig option](https://www.typescriptlang.org/tsconfig/#declaration)
668
+ */
669
+ declaration?: string
670
+ /**
671
+ * Declaration source map. Only generated if both
672
+ * {@link TypeScriptOptions#declaration declaration} and
673
+ * {@link TransformOptions#sourcemap sourcemap} are set to `true`.
674
+ */
675
+ declarationMap?: SourceMap
676
+ /**
677
+ * Helpers used.
678
+ *
679
+ * @internal
680
+ *
681
+ * Example:
682
+ *
683
+ * ```text
684
+ * { "_objectSpread": "@oxc-project/runtime/helpers/objectSpread2" }
685
+ * ```
686
+ */
687
+ helpersUsed: Record<string, string>
688
+ /**
689
+ * Parse and transformation errors.
690
+ *
691
+ * Oxc's parser recovers from common syntax errors, meaning that
692
+ * transformed code may still be available even if there are errors in this
693
+ * list.
694
+ */
695
+ errors: Array<OxcError>
696
+ }
697
+
698
+ /**
699
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version.
700
+ *
701
+ * @param filename The name of the file being transformed. If this is a
702
+ * relative path, consider setting the {@link TransformOptions#cwd} option..
703
+ * @param sourceText the source code itself
704
+ * @param options The options for the transformation. See {@link
705
+ * TransformOptions} for more information.
706
+ *
707
+ * @returns an object containing the transformed code, source maps, and any
708
+ * errors that occurred during parsing or transformation.
709
+ */
710
+ export declare function transformSync(filename: string, sourceText: string, options?: TransformOptions | undefined | null): TransformResult
711
+
712
+ export interface TypeScriptOptions {
713
+ jsxPragma?: string
714
+ jsxPragmaFrag?: string
715
+ onlyRemoveTypeImports?: boolean
716
+ allowNamespaces?: boolean
717
+ /**
718
+ * When enabled, type-only class fields are only removed if they are prefixed with the declare modifier:
719
+ *
720
+ * @deprecated
721
+ *
722
+ * Allowing `declare` fields is built-in support in Oxc without any option. If you want to remove class fields
723
+ * without initializer, you can use `remove_class_fields_without_initializer: true` instead.
724
+ */
725
+ allowDeclareFields?: boolean
726
+ /**
727
+ * When enabled, class fields without initializers are removed.
728
+ *
729
+ * For example:
730
+ * ```ts
731
+ * class Foo {
732
+ * x: number;
733
+ * y: number = 0;
734
+ * }
735
+ * ```
736
+ * // transform into
737
+ * ```js
738
+ * class Foo {
739
+ * x: number;
740
+ * }
741
+ * ```
742
+ *
743
+ * The option is used to align with the behavior of TypeScript's `useDefineForClassFields: false` option.
744
+ * When you want to enable this, you also need to set [`crate::CompilerAssumptions::set_public_class_fields`]
745
+ * to `true`. The `set_public_class_fields: true` + `remove_class_fields_without_initializer: true` is
746
+ * equivalent to `useDefineForClassFields: false` in TypeScript.
747
+ *
748
+ * When `set_public_class_fields` is true and class-properties plugin is enabled, the above example transforms into:
749
+ *
750
+ * ```js
751
+ * class Foo {
752
+ * constructor() {
753
+ * this.y = 0;
754
+ * }
755
+ * }
756
+ * ```
757
+ *
758
+ * Defaults to `false`.
759
+ */
760
+ removeClassFieldsWithoutInitializer?: boolean
761
+ /**
762
+ * Also generate a `.d.ts` declaration file for TypeScript files.
763
+ *
764
+ * The source file must be compliant with all
765
+ * [`isolatedDeclarations`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations)
766
+ * requirements.
767
+ *
768
+ * @default false
769
+ */
770
+ declaration?: IsolatedDeclarationsOptions
771
+ /**
772
+ * Rewrite or remove TypeScript import/export declaration extensions.
773
+ *
774
+ * - When set to `rewrite`, it will change `.ts`, `.mts`, `.cts` extensions to `.js`, `.mjs`, `.cjs` respectively.
775
+ * - When set to `remove`, it will remove `.ts`/`.mts`/`.cts`/`.tsx` extension entirely.
776
+ * - When set to `true`, it's equivalent to `rewrite`.
777
+ * - When set to `false` or omitted, no changes will be made to the extensions.
778
+ *
779
+ * @default false
780
+ */
781
+ rewriteImportExtensions?: 'rewrite' | 'remove' | boolean
782
+ }