Describe the bug
swc compiles a Flow component-typed binding whose value is an arrow into an arrow function. The reference transform (hermes-parser + @react-native/babel-preset, which react-native uses) emits a named function instead. The difference matters because an arrow has no .prototype.
react-native's core components (Text, View, ScrollView, ...) are written this way, and react-native's own jest mock (react-native/jest/mockComponent.js) reads RealComponent.prototype.constructor, which throws on the arrow, so react-native can't be transformed with @swc/jest.
Input code
const MyComponent: component(ref?: mixed, ...props: mixed) = ({ ref, ...rest }) => null;
Config
{
"jsc": {
"parser": { "syntax": "flow", "jsx": true, "components": true },
"target": "es2022"
}
}
Link to the code that reproduces this issue
https://github.com/bigpun86/swc-flow-component-arrow-repro
SWC Info output
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 25.5.0
CPU: (16 cores) Apple M4 Max
Binaries:
Node: 24.14.1
npm: 11.11.0
Yarn: 4.17.0
Relevant Packages:
@swc/core: 1.15.43
@swc/types: 0.1.27
Expected behavior
swc emits a named function (with a .prototype), matching hermes/babel:
var MyComponent = function MyComponent(_ref) { ... };
Actual behavior
swc emits an arrow function (no .prototype):
const MyComponent = ({ ref, ...rest }) => null; // MyComponent.prototype === undefined
react-native's jest mock then throws:
TypeError: Cannot read properties of undefined (reading 'constructor')
Version
1.15.43
Additional context
The repro has two scripts: npm run repro runs react-native's real Text.js through swc (shows the arrow), npm run minimal is a runnable version that reproduces the crash. hermes/babel output verified via babel-preset-expo on the same file.
Arrows are valid JS so possibly intentional, but matching the reference would let react-native work under @swc/jest.
Describe the bug
swc compiles a Flow
component-typed binding whose value is an arrow into an arrow function. The reference transform (hermes-parser +@react-native/babel-preset, which react-native uses) emits a named function instead. The difference matters because an arrow has no.prototype.react-native's core components (Text, View, ScrollView, ...) are written this way, and react-native's own jest mock (
react-native/jest/mockComponent.js) readsRealComponent.prototype.constructor, which throws on the arrow, so react-native can't be transformed with @swc/jest.Input code
Config
{ "jsc": { "parser": { "syntax": "flow", "jsx": true, "components": true }, "target": "es2022" } }Link to the code that reproduces this issue
https://github.com/bigpun86/swc-flow-component-arrow-repro
SWC Info output
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 25.5.0
CPU: (16 cores) Apple M4 Max
Binaries:
Node: 24.14.1
npm: 11.11.0
Yarn: 4.17.0
Relevant Packages:
@swc/core: 1.15.43
@swc/types: 0.1.27
Expected behavior
swc emits a named function (with a
.prototype), matching hermes/babel:var MyComponent = function MyComponent(_ref) { ... };
Actual behavior
swc emits an arrow function (no
.prototype):const MyComponent = ({ ref, ...rest }) => null; // MyComponent.prototype === undefined
react-native's jest mock then throws:
TypeError: Cannot read properties of undefined (reading 'constructor')
Version
1.15.43
Additional context
The repro has two scripts:
npm run reproruns react-native's real Text.js through swc (shows the arrow),npm run minimalis a runnable version that reproduces the crash. hermes/babel output verified viababel-preset-expoon the same file.Arrows are valid JS so possibly intentional, but matching the reference would let react-native work under @swc/jest.