File tree 1 file changed +31
-1
lines changed
1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
- import type { NodePath } from '@babel/traverse' ;
1
+ import { NodePath } from '@babel/traverse' ;
2
2
import type * as Babel from '@babel/core' ;
3
3
import type { types as t } from '@babel/core' ;
4
4
import { ImportUtil } from 'babel-import-util' ;
@@ -156,6 +156,36 @@ export function makePlugin<EnvSpecificOptions>(loadOptions: (opts: EnvSpecificOp
156
156
let t = babel . types ;
157
157
158
158
return {
159
+ pre ( state ) {
160
+ const imports = state . ast . program . body . filter (
161
+ ( b ) => b . type === 'ImportDeclaration'
162
+ ) as t . ImportDeclaration [ ] ;
163
+ const templateCompilerImport = imports . find (
164
+ ( i ) => i . source . value === '@ember/template-compiler'
165
+ ) ;
166
+
167
+ if ( templateCompilerImport ) {
168
+ const program = NodePath . get ( {
169
+ hub : state . hub ,
170
+ key : 'program' ,
171
+ parent : state . ast ,
172
+ parentPath : null ,
173
+ container : state . ast ,
174
+ } ) ;
175
+ const p = program . get ( 'body' ) ;
176
+ for ( const i of imports ) {
177
+ const idx = state . ast . program . body . indexOf ( i ) ;
178
+ const impNodePath = p [ idx ] as NodePath < t . ImportDeclaration > ;
179
+ const specifiers = impNodePath . get ( 'specifiers' ) ;
180
+ for ( const specifier of specifiers ) {
181
+ const local = specifier . get ( 'local' ) ;
182
+ if ( ! state . scope . getBinding ( local . node . name ) ?. referencePaths . length ) {
183
+ state . scope . getBinding ( local . node . name ) ?. referencePaths . push ( program ) ;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ } ,
159
189
visitor : {
160
190
Program : {
161
191
enter ( path : NodePath < t . Program > , state : State < EnvSpecificOptions > ) {
You can’t perform that action at this time.
0 commit comments