@@ -88,19 +88,43 @@ export default class AsBindTransform {
88
88
throw Error ( `Can’t import or export generic functions.` ) ;
89
89
}
90
90
importedFunction = importedFunction . instances . get ( "" ) ;
91
+
92
+ let external_module ;
93
+ let external_name ;
94
+
95
+ let decorators = importedFunction . declaration . decorators ;
96
+
97
+ if ( decorators ) {
98
+ for ( let decorator of decorators ) {
99
+ if ( decorator . name . text !== "external" ) continue ;
100
+ if ( ! decorator . args ) continue ; // sanity check
101
+
102
+ if ( decorator . args . length > 1 ) {
103
+ external_module = decorator . args [ 0 ] . value ;
104
+ external_name = decorator . args [ 1 ] . value ;
105
+ } else {
106
+ external_name = decorator . args [ 0 ] . value ;
107
+ }
108
+ }
109
+ }
110
+
91
111
// To know under what module name an imported function will be expected,
92
112
// we have to find the containing module of the given function, take the
93
113
// internal name (which is effectively the file path without extension)
94
114
// and only take the part after the last `/`
95
115
// (i.e. the file name without extension).
96
- const moduleName = containingModule ( importedFunction )
97
- . internalName . split ( "/" )
98
- . slice ( - 1 ) [ 0 ] ;
116
+ const moduleName =
117
+ external_module ||
118
+ containingModule ( importedFunction )
119
+ . internalName . split ( "/" )
120
+ . slice ( - 1 ) [ 0 ] ;
99
121
if ( ! importedFunctions . hasOwnProperty ( moduleName ) ) {
100
122
importedFunctions [ moduleName ] = { } ;
101
123
}
102
124
let importedFunctionName = importedFunction . name ;
103
- if (
125
+ if ( external_name ) {
126
+ importedFunctionName = external_name ;
127
+ } else if (
104
128
importedFunction . parent &&
105
129
importedFunction . parent . kind === ElementKind . NAMESPACE
106
130
) {
0 commit comments