release notes
release notes
Published 7/28/2022
PatchContains new featuresAdd support for React 17's automatic JSX transform (#334, #718, #1172, #2318, #2349)
This adds support for the new "automatic" JSX runtime from React 17+ to esbuild for both the build and transform APIs.
New CLI flags and API options:
--jsx, jsx — Set this to "automatic" to opt in to this new transform--jsx-dev, jsxDev — Toggles development mode for the automatic runtime--jsx-import-source, jsxImportSource — Overrides the root import for runtime functions (default "react")New JSX pragma comments:
[@jsxRuntime](https://github.com/jsxRuntime) — Sets the runtime (automatic or classic)[@jsxImportSource](https://github.com/jsxImportSource) — Sets the import source (only valid with automatic runtime)The existing [@jsxFragment](https://github.com/jsxFragment) and [@jsxFactory](https://github.com/jsxFactory) pragma comments are only valid with "classic" runtime.
TSConfig resolving:
Along with accepting the new options directly via CLI or API, option inference from tsconfig.json compiler options was also implemented:
"jsx": "preserve" or "jsx": "react-native" → Same as --jsx=preserve in esbuild"jsx": "react" → Same as --jsx=transform in esbuild (which is the default behavior)"jsx": "react-jsx" → Same as --jsx=automatic in esbuild"jsx": "react-jsxdev" → Same as --jsx=automatic --jsx-dev in esbuildIt also reads the value of "jsxImportSource" from tsconfig.json if specified.
For react-jsx it's important to note that it doesn't implicitly disable --jsx-dev. This is to support the case where a user sets "react-jsx" in their tsconfig.json but then toggles development mode directly in esbuild.
esbuild vs Babel vs TS vs...
There are a few differences between the various technologies that implement automatic JSX runtimes. The JSX transform in esbuild follows a mix of Babel's and TypeScript's behavior:
When an element has __source or __self props:
Element has an "implicit true" key prop, e.g. <a key />:
Element has spread children, e.g. <a>{...children}</a>
Also note that TypeScript has some bugs regarding JSX development mode and the generation of lineNumber and columnNumber values. Babel's values are accurate though, so esbuild's line and column numbers match Babel. Both numbers are 1-based and columns are counted in terms of UTF-16 code units.
This feature was contributed by @jgoz.
release notes
Published 7/28/2022
PatchContains new featuresAdd support for React 17's automatic JSX transform (#334, #718, #1172, #2318, #2349)
This adds support for the new "automatic" JSX runtime from React 17+ to esbuild for both the build and transform APIs.
New CLI flags and API options:
--jsx, jsx — Set this to "automatic" to opt in to this new transform--jsx-dev, jsxDev — Toggles development mode for the automatic runtime--jsx-import-source, jsxImportSource — Overrides the root import for runtime functions (default "react")New JSX pragma comments:
[@jsxRuntime](https://github.com/jsxRuntime) — Sets the runtime (automatic or classic)[@jsxImportSource](https://github.com/jsxImportSource) — Sets the import source (only valid with automatic runtime)The existing [@jsxFragment](https://github.com/jsxFragment) and [@jsxFactory](https://github.com/jsxFactory) pragma comments are only valid with "classic" runtime.
TSConfig resolving:
Along with accepting the new options directly via CLI or API, option inference from tsconfig.json compiler options was also implemented:
"jsx": "preserve" or "jsx": "react-native" → Same as --jsx=preserve in esbuild"jsx": "react" → Same as --jsx=transform in esbuild (which is the default behavior)"jsx": "react-jsx" → Same as --jsx=automatic in esbuild"jsx": "react-jsxdev" → Same as --jsx=automatic --jsx-dev in esbuildIt also reads the value of "jsxImportSource" from tsconfig.json if specified.
For react-jsx it's important to note that it doesn't implicitly disable --jsx-dev. This is to support the case where a user sets "react-jsx" in their tsconfig.json but then toggles development mode directly in esbuild.
esbuild vs Babel vs TS vs...
There are a few differences between the various technologies that implement automatic JSX runtimes. The JSX transform in esbuild follows a mix of Babel's and TypeScript's behavior:
When an element has __source or __self props:
Element has an "implicit true" key prop, e.g. <a key />:
Element has spread children, e.g. <a>{...children}</a>
Also note that TypeScript has some bugs regarding JSX development mode and the generation of lineNumber and columnNumber values. Babel's values are accurate though, so esbuild's line and column numbers match Babel. Both numbers are 1-based and columns are counted in terms of UTF-16 code units.
This feature was contributed by @jgoz.
An extremely fast bundler for the web