-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Describe the bug
SWC incorrectly transpiles local usage of react component within namespace
Input code
import * as React from 'react';
export namespace FooNs {
export const Shared = () => 'I\'m shared component';
export const Main = () => <Shared/>;
}Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"target": "es2015",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}Playground link (or link to the minimal reproduction)
Expected behavior
SWC should output code like this.
import * as React from 'react';
export var FooNs;
(function(FooNs) {
FooNs.Shared = ()=>'I\'m shared component';
FooNs.Main = ()=>React.createElement(FooNs.Shared, null); // <===== Fix
})(FooNs || (FooNs = {}));Actual behavior
Transpiled code produces an error "Shared is not defined"
import * as React from 'react';
export var FooNs;
(function(FooNs) {
FooNs.Shared = ()=>'I\'m shared component';
FooNs.Main = ()=>React.createElement(Shared, null);
})(FooNs || (FooNs = {}));Version
1.3.107
Additional context
Interesting, that swc produces correct code, if we don't export 'Shared' component from namespace
Input
import * as React from 'react';
export namespace FooNs {
const Shared = () => 'I\'m shared component';
export const Main = () => <Shared/>;
}Output
import * as React from 'react';
export var FooNs;
(function(FooNs) {
const Shared = ()=>'I\'m shared component';
FooNs.Main = ()=>React.createElement(Shared, null);
})(FooNs || (FooNs = {}));