Skip to content

Commit 50354a1

Browse files
authored
feat(@swc/types): Add preserve to react.runtime (#11068)
**Description:** Add TypeScript definition for `react.runtime: 'preserve'`. **Related issue:** - #9929 (comment) - #11025
1 parent d6e0a49 commit 50354a1

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

bindings/binding_core_wasm/src/types.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,14 +887,23 @@ export interface ReactConfig {
887887
};
888888
889889
/**
890-
* jsx runtime
890+
* Decides which runtime to use when transforming JSX.
891+
* - `"automatic"` - Automatically imports the functions that JSX transpiles to.
892+
* This is the modern approach introduced in React 17+ that eliminates the need to
893+
* manually import React in every file that uses JSX.
894+
* - `"classic"` - Uses the traditional JSX transform that relies on `React.createElement`
895+
* calls. Requires React to be in scope, which was the standard behavior before React 17.
896+
* - `"preserve"` - Leaves JSX syntax unchanged without transforming it.
897+
* @default "classic"
891898
*/
892-
runtime?: 'automatic' | 'classic'
899+
runtime?: "automatic" | "classic" | "preserve";
893900
894901
/**
895-
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory functions when using `runtime` 'automatic'
902+
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory
903+
* functions when using `runtime` 'automatic'
904+
* @default "react"
896905
*/
897-
importSource?: string
906+
importSource?: string;
898907
}
899908
/**
900909
* - `import { DEBUG } from '@ember/env-flags';`

bindings/binding_minifier_wasm/src/types.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,23 @@ export interface ReactConfig {
888888
};
889889
890890
/**
891-
* jsx runtime
891+
* Decides which runtime to use when transforming JSX.
892+
* - `"automatic"` - Automatically imports the functions that JSX transpiles to.
893+
* This is the modern approach introduced in React 17+ that eliminates the need to
894+
* manually import React in every file that uses JSX.
895+
* - `"classic"` - Uses the traditional JSX transform that relies on `React.createElement`
896+
* calls. Requires React to be in scope, which was the standard behavior before React 17.
897+
* - `"preserve"` - Leaves JSX syntax unchanged without transforming it.
898+
* @default "classic"
892899
*/
893-
runtime?: 'automatic' | 'classic'
900+
runtime?: "automatic" | "classic" | "preserve";
894901
895902
/**
896-
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory functions when using `runtime` 'automatic'
903+
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory
904+
* functions when using `runtime` 'automatic'
905+
* @default "react"
897906
*/
898-
importSource?: string
907+
importSource?: string;
899908
}
900909
/**
901910
* - `import { DEBUG } from '@ember/env-flags';`

packages/types/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,21 @@ export interface ReactConfig {
945945
};
946946

947947
/**
948-
* jsx runtime
948+
* Decides which runtime to use when transforming JSX.
949+
* - `"automatic"` - Automatically imports the functions that JSX transpiles to.
950+
* This is the modern approach introduced in React 17+ that eliminates the need to
951+
* manually import React in every file that uses JSX.
952+
* - `"classic"` - Uses the traditional JSX transform that relies on `React.createElement`
953+
* calls. Requires React to be in scope, which was the standard behavior before React 17.
954+
* - `"preserve"` - Leaves JSX syntax unchanged without transforming it.
955+
* @default "classic"
949956
*/
950-
runtime?: "automatic" | "classic";
957+
runtime?: "automatic" | "classic" | "preserve";
951958

952959
/**
953-
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory functions when using `runtime` 'automatic'
960+
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory
961+
* functions when using `runtime` 'automatic'
962+
* @default "react"
954963
*/
955964
importSource?: string;
956965
}

0 commit comments

Comments
 (0)