@@ -5,7 +5,27 @@ import MacroJS from "./macroJs"
5
5
import MacroJSX from "./macroJsx"
6
6
7
7
const config = getConfig ( { configPath : process . env . LINGUI_CONFIG } )
8
- const [ i18nImportModule , i18nImportName = "i18n" ] = config . runtimeConfigModule
8
+
9
+ const getSymbolSource = ( name : string ) => {
10
+ if ( Array . isArray ( config . runtimeConfigModule ) ) {
11
+ if ( name === "i18n" ) {
12
+ return config . runtimeConfigModule
13
+ } else {
14
+ return [ "@lingui/react" , name ]
15
+ }
16
+ } else {
17
+ if (
18
+ Object . prototype . hasOwnProperty . call ( config . runtimeConfigModule , name )
19
+ ) {
20
+ return config . runtimeConfigModule [ name ]
21
+ } else {
22
+ return [ "@lingui/react" , name ]
23
+ }
24
+ }
25
+ }
26
+
27
+ const [ i18nImportModule , i18nImportName = "i18n" ] = getSymbolSource ( "i18n" )
28
+ const [ TransImportModule , TransImportName = "Trans" ] = getSymbolSource ( "Trans" )
9
29
10
30
function macro ( { references, state, babel } ) {
11
31
const jsxNodes = [ ]
@@ -47,7 +67,7 @@ function macro({ references, state, babel }) {
47
67
}
48
68
49
69
if ( jsxNodes . length ) {
50
- addImport ( babel , state , "@lingui/react" , "Trans" )
70
+ addImport ( babel , state , TransImportModule , TransImportName )
51
71
}
52
72
53
73
if ( process . env . LINGUI_EXTRACT === "1" ) {
@@ -61,7 +81,8 @@ function addImport(babel, state, module, importName) {
61
81
const { types : t } = babel
62
82
63
83
const linguiImport = state . file . path . node . body . find (
64
- ( importNode ) => t . isImportDeclaration ( importNode ) &&
84
+ ( importNode ) =>
85
+ t . isImportDeclaration ( importNode ) &&
65
86
importNode . source . value === module &&
66
87
// https://github.com/lingui/js-lingui/issues/777
67
88
importNode . importKind !== "type"
0 commit comments