/* tslint:disable */ /* eslint-disable */ /* auto-generated by NAPI-RS */ export interface TransformNodiffBundleOptions { filename: string pluginName: string sourceFileName?: string sourcemap: boolean | string extractStr: boolean | ExtractStrConfig minify?: boolean } export interface TransformNodiffBundleOutput { code: string map?: string selectStrVec?: Array useWorklet?: boolean errors: Array warnings: Array } /** * This is esbuild's PartialMessage definition. * https://github.com/evanw/esbuild/blob/043ab306c490f692c68e8d254bbf00b6468be87d/lib/shared/types.ts#L421 */ export interface PartialMessage { id?: string pluginName?: string text?: string location?: PartialLocation notes?: Array detail?: string } export interface PartialNote { text?: string location?: PartialLocation } export interface PartialLocation { file?: string namespace?: string line?: number column?: number length?: number lineText?: string suggestion?: string } export interface UiSourceMapRecord { uiSourceMap: number filename: string lineNumber: number columnNumber: number snapshotId?: string } export interface DarkModeConfig { /** * @public * Theme expression to be used for dark mode */ themeExpr: string } /** * {@inheritDoc CompatVisitorConfig.addComponentElement} * @public */ export interface AddComponentElementConfig { /** * @public * Whether to only add component element during compilation * * @example * * Note that this only take effects on `Component` imported from {@link CompatVisitorConfig.oldRuntimePkg}. * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * addComponentElement: { compilerOnly: true } * }, * }) * ], * }) * ``` */ compilerOnly: boolean } /** * {@inheritDoc PluginReactLynxOptions.compat} * @public */ export interface CompatVisitorConfig { /** @internal */ target: 'LEPUS' | 'JS' | 'MIXED' /** * @public * Specifies the list of component package names that need compatibility processing * * @defaultValue `['@lynx-js/react-components']` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * componentsPkg: ['@my-org/components', '@legacy/ui-kit'] * }, * }) * ], * }) * ``` */ componentsPkg: Array /** * @public * Specifies the list of old runtime package names that need compatibility processing * * @defaultValue `['@lynx-js/react-runtime']` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * oldRuntimePkg: ['@my-org/runtime', '@legacy/runtime'] * }, * }) * ], * }) * ``` */ oldRuntimePkg: Array /** * @public * Specifies the new runtime package name * * @defaultValue `'@lynx-js/react'` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * newRuntimePkg: '@my-org/react' * }, * }) * ], * }) * ``` */ newRuntimePkg: string /** * @public * Specifies additional component attributes list, these attributes will be passed to the wrapped `` instead of the component. * * @defaultValue `[]` * * @remarks * This only takes effect when {@link CompatVisitorConfig.addComponentElement} is enabled. * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * additionalComponentAttributes: ['custom-attr', 'data-special'] * }, * }) * ], * }) * ``` */ additionalComponentAttributes: Array /** * @public * Controls whether to add wrapper elements for components * * @defaultValue `false` * * @example * * Add a `` wrapper element for all components during runtime. * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * addComponentElement: true * }, * }) * ], * }) * ``` * * @example * * Only add component element during compilation. * Note that this only take effects on `Component` imported from {@link CompatVisitorConfig.oldRuntimePkg}. * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * addComponentElement: { compilerOnly: true } * }, * }) * ], * }) * ``` */ addComponentElement: boolean | AddComponentElementConfig /** * @public * Whether to simplify constructor calls like ReactLynx 2 * * @deprecated * Using `simplifyCtorLikeReactLynx2` is not recommended as it introduces implicit behaviors that can: * * - Make code harder to understand and maintain * * - Create hidden dependencies between components * * - Complicate debugging and testing processes * * Instead, use `background-only` on class methods for explicit and maintainable behavior * * @defaultValue `false` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * simplifyCtorLikeReactLynx2: true * }, * }) * ], * }) * ``` */ simplifyCtorLikeReactLynx2: boolean /** * @public * Whether to transform legacy event attribute names on Lynx elements. * * When enabled, legacy event attributes such as `onClick` and * `onClickCatch` are transformed to `bindtap` and `catchtap`. * Disable this when another transform owns event attribute-name conversion. * * @defaultValue `true` */ transformLegacyEventAttributeNames?: boolean /** * @public * Regular expression used to remove component attributes * * @deprecated It's recommended to use `background-only`. * * If your code depends on this switch, when distributing it to other projects through npm packages or other means, you'll also need to enable this switch. This will lead to the proliferation of switches, which is not conducive to code reuse between different projects. * * @defaultValue `undefined` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * removeComponentAttrRegex: '^data-test-' * }, * }) * ], * }) * ``` */ removeComponentAttrRegex?: string /** * @public * Whether to disable deprecated warnings * * @defaultValue `false` * * @example * * Disable all the `DEPRECATED:` warnings. * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * disableDeprecatedWarning: true * }, * }) * ], * }) * ``` */ disableDeprecatedWarning: boolean /** * Dark mode configuration * * @public * @deprecated * * @defaultValue `undefined` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * darkMode: true * }, * }) * ], * }) * ``` */ darkMode?: boolean | DarkModeConfig /** * Compile dynamic children as children + wrapper (the pre-SlotV2 slot * codegen: `Slot`/`Children` dynamic parts rendered through wrapper * elements) instead of the default SlotV2 codegen (`$N` slot props). * * @remarks * * Enable this when the compiled output needs to run on legacy * `@lynx-js/react` runtimes without `SlotV2` support (`< 0.120.0`), * e.g. a standalone lazy bundle consumed by a host App that ships an * older runtime. It only changes the compile output; the runtime * supports both forms. * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * compat: { * legacySlot: true, * }, * }) * ], * }) * ``` * * @defaultValue `false` */ legacySlot?: boolean } export interface CssScopeVisitorConfig { /** @public */ mode: 'all' | 'none' | 'modules' /** @public */ filename: string } /** * {@inheritDoc PluginReactLynxOptions.defineDCE} * @public */ export interface DefineDceVisitorConfig { /** * @public * Replaces variables in your code with other values or expressions at compile time. * * @remarks * Caveat: differences between `source.define` * * `defineDCE` happens before transforming `background-only` directives. * So it's useful for eliminating code that is only used in the background from main-thread. * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * defineDCE: { * define: { * __FOO__: 'false', * 'process.env.PLATFORM': '"lynx"', * }, * }, * }) * ], * }) * ``` * * Then, `__FOO__` and `process.env.PLATFORM` could be used in source code. * * ``` * if (process.env.PLATFORM === 'lynx') { * console.log('lynx') * } * * function FooOrBar() { * if (__FOO__) { * return foo * } else { * return bar * } * } * ``` */ define: Record } export interface DirectiveDceVisitorConfig { /** @internal */ target: 'LEPUS' | 'JS' | 'MIXED' } export interface DynamicImportVisitorConfig { /** @internal */ runtimePkg: string /** @internal */ layer: string /** @internal */ injectLazyBundle?: boolean } /** * {@inheritDoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.extractStr} * @public */ export interface ExtractStrConfig { /** * @public * The minimum length of string literals to be extracted. * * @defaultValue `20` * * @example * * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * extractStr: { * strLength: 10, * }, * }) * ], * }) * ``` */ strLength: number /** @internal */ extractedStrArr?: Array } export interface InjectVisitorConfig { inject: Record } export interface RefreshVisitorConfig { library?: Array } /** * {@inheritDoc PluginReactLynxOptions.shake} * @public */ export interface ShakeVisitorConfig { /** * Package names to identify runtime imports that need to be processed * * @example * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * shake: { * pkgName: ['@lynx-js/react-runtime'] * } * }) * ] * }) * ``` * * @defaultValue `['@lynx-js/react-runtime']` * * @remarks * The provided values will be merged with the default values instead of replacing them. * * @public */ pkgName: Array /** * Properties that should be retained in the component class * * @example * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * shake: { * retainProp: ['myCustomMethod'] * } * }) * ] * }) * ``` * * @defaultValue `['constructor', 'render', 'getDerivedStateFromProps', 'state', 'defaultDataProcessor', 'dataProcessors', 'contextType', 'defaultProps']` * * @remarks * The provided values will be merged with the default values instead of replacing them. * * @public */ retainProp: Array /** * Function names whose calls should be replaced with `undefined` during transformation * * @example * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * shake: { * removeCall: ['useMyCustomEffect'] * } * }) * ] * }) * ``` * * @defaultValue `['useEffect', 'useLayoutEffect', '__runInJS', 'useLynxGlobalEventListener', 'useImperativeHandle']` * * @remarks * The provided values will be merged with the default values instead of replacing them. * * @public */ removeCall: Array /** * Function names whose parameters should be removed during transformation * * @example * ```js * import { defineConfig } from '@lynx-js/rspeedy' * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' * * export default defineConfig({ * plugins: [ * pluginReactLynx({ * shake: { * removeCallParams: ['useMyCustomEffect'] * } * }) * ] * }) * ``` * * @defaultValue `[]` * * @remarks * The provided values will be merged with the default values instead of replacing them. * * @public */ removeCallParams: Array } /** @internal */ export interface JsxTransformerConfig { /** @internal */ preserveJsx: boolean /** @internal */ runtimePkg: string /** @internal */ jsxImportSource?: string /** @internal */ filename: string /** @internal */ target: 'LEPUS' | 'JS' | 'MIXED' /** @internal */ enableUiSourceMap?: boolean /** @internal */ isDynamicComponent?: boolean /** @internal */ isExternalBundle?: boolean /** @internal */ legacySlot?: boolean } /** @internal */ export interface ElementTemplateConfig { /** @internal */ preserveJsx: boolean /** @internal */ runtimePkg: string /** @internal */ jsxImportSource?: string /** @internal */ filename: string /** @internal */ target: 'LEPUS' | 'JS' | 'MIXED' /** @internal */ isDynamicComponent?: boolean /** @internal */ isExternalBundle?: boolean } export interface WorkletVisitorConfig { /** * @public * During the compilation of worklet, when extracting external variable identifiers, * global identifiers available in lepus context need to be ignored. * In addition to the default lepus global identifier list provided by the compiler, * users can customize the global identifier list through this option. * This configuration will take effect together with the default lepus global identifier list. */ customGlobalIdentNames?: Array /** @internal */ filename: string /** @internal */ target: 'LEPUS' | 'JS' | 'MIXED' /** * Module providing worklet helpers. The init entry uses this path with a * trailing `/internal` removed, followed by `/worklet-runtime/init`. */ runtimePkg: string } /** * Serializable rules for transforming builtin element attribute names. * * Exact entries in `rename` take precedence over `preserve`, followed by the * fallback behavior selected by `mode`. * * @public */ export interface TransformBuiltinAttributeNamesOptions { /** * The fallback behavior for attribute names not listed in `rename` or * `preserve`. * * `'dash-case'` also applies the default React-style event mappings. * `'mapping-only'` leaves all remaining names unchanged. * * @defaultValue `'dash-case'` */ mode?: 'dash-case' | 'mapping-only' /** * Attribute names that should remain unchanged unless an exact `rename` * entry is also present. */ preserve?: ReadonlyArray /** * Exact mappings from source attribute names to transformed attribute names. */ rename?: Readonly> } export interface TransformNodiffOptions { /** * @internal * This is used internally to make sure the test output is consistent. */ mode?: 'production' | 'development' | 'test' pluginName: string filename: string sourceFileName?: string sourcemap: boolean | string sourceMapColumns?: boolean inlineSourcesContent?: boolean /** * @public * This is swc syntax config in JSON format */ syntaxConfig?: string isModule?: boolean | 'unknown' cssScope: boolean | CssScopeVisitorConfig snapshot?: boolean | JsxTransformerConfig elementTemplate?: boolean | ElementTemplateConfig engineVersion?: string shake: boolean | ShakeVisitorConfig compat: boolean | CompatVisitorConfig refresh: boolean | RefreshVisitorConfig defineDCE: boolean | DefineDceVisitorConfig directiveDCE: boolean | DirectiveDceVisitorConfig worklet: boolean | WorkletVisitorConfig dynamicImport?: boolean | DynamicImportVisitorConfig /** * Transform attribute names on Lynx builtin elements. * * `true` applies the default rule: `onClick` becomes `bindtap`, * `onCatchTap` becomes `catchtap`, other `onXXX` names become `bindxxx`, * and remaining camelCase names become dash-case. An object provides * serializable custom rules. * Explicit JSX attributes are transformed during compilation. Attributes * supplied through JSX spreads are transformed by the runtime with the same * rules. * * @experimental */ experimental_transformBuiltinAttributeNames?: boolean | TransformBuiltinAttributeNamesOptions /** @internal */ inject?: boolean | InjectVisitorConfig inputSourceMap?: string } export interface TransformNodiffOutput { code: string map?: string errors: Array warnings: Array uiSourceMapRecords: Array /** @internal */ elementTemplates?: Array /** @internal */ runtimeRequirements: TransformRuntimeRequirements /** @internal */ definesForSnapshot?: Array /** @internal */ definesForWorklet?: Array } /** @internal */ export interface TransformRuntimeRequirements { /** @internal */ mainThreadProgrammability: boolean } /** * @internal * A snapshot or worklet definition collected from the module. The same * definition is emitted regardless of the compile target. */ export interface Define { /** * @internal * The snapshot uid or the worklet hash. Definitions that share an id are * interchangeable, so duplicates can be dropped. */ id: string /** * @internal * A statement list registering the definition, using the bindings in imports. */ code: string /** * @internal * Set when the definition cannot run inside an injected module, e.g. a * worklet closing over a shared-runtime import. The build must fail when * the main thread lacks such a definition. */ unmergeable?: boolean /** @internal Compiler requirements of the extracted registration. */ runtimeRequirements?: TransformRuntimeRequirements /** @internal Imports required by this definition. */ imports?: DefineImport[] } /** @internal */ export interface DefineImport { /** @internal */ source: string /** @internal */ imported: string /** @internal */ local: string /** @internal */ namespace?: boolean } /** @internal */ export interface ElementTemplateAsset { /** @internal */ templateId: string /** @internal */ compiledTemplate: unknown /** @internal */ sourceFile: string } export function transformReactLynxSync(code: string, options?: TransformNodiffOptions | undefined | null): TransformNodiffOutput export function transformReactLynx(code: string, options?: TransformNodiffOptions | undefined | null): Promise export function transformBundleResultSync(code: string, options?: TransformNodiffBundleOptions | undefined | null): TransformNodiffBundleOutput export function transformBundleResult(code: string, options?: TransformNodiffBundleOptions | undefined | null): Promise