Skip to content

Commit ef3abe4

Browse files
committed
fix for removed fcct imports
1 parent df22c9e commit ef3abe4

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

Diff for: src/plugin.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NodePath } from '@babel/traverse';
1+
import { NodePath } from '@babel/traverse';
22
import type * as Babel from '@babel/core';
33
import type { types as t } from '@babel/core';
44
import { ImportUtil } from 'babel-import-util';
@@ -156,6 +156,36 @@ export function makePlugin<EnvSpecificOptions>(loadOptions: (opts: EnvSpecificOp
156156
let t = babel.types;
157157

158158
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+
},
159189
visitor: {
160190
Program: {
161191
enter(path: NodePath<t.Program>, state: State<EnvSpecificOptions>) {

0 commit comments

Comments
 (0)