Skip to content

Commit

Permalink
fix for removed fcct imports
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Oct 27, 2023
1 parent df22c9e commit 4ece042
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NodePath } from '@babel/traverse';
import { NodePath } from '@babel/traverse';
import type * as Babel from '@babel/core';
import type { types as t } from '@babel/core';
import { ImportUtil } from 'babel-import-util';
Expand Down Expand Up @@ -156,6 +156,38 @@ export function makePlugin<EnvSpecificOptions>(loadOptions: (opts: EnvSpecificOp
let t = babel.types;

return {
pre(state) {
const imports = state.ast.program.body.filter(
(b) => b.type === 'ImportDeclaration'
) as t.ImportDeclaration[];
const templateCompilerImport = imports.find(
(i) => i.source.value === '@ember/template-compiler'
);

if (templateCompilerImport) {
const program = NodePath.get({
hub: state.hub,
key: 'program',
parent: state.ast,
parentPath: null,
container: state.ast,
});
const p = program.get('body');
for (const i of imports) {
const idx = state.ast.program.body.indexOf(i);
const impNodePath = p[idx] as NodePath<t.ImportDeclaration>;
const specifiers = impNodePath.get('specifiers');
for (const specifier of specifiers) {
const local = specifier.get('local');
if (!state.scope.getBinding(local.node.name)?.referencePaths.length) {
state.scope.getBinding(local.node.name)?.referencePaths.push(program);
}
}
}
}
// const exp = t.export(imports as radomname)
// state.ast.program.body.push(exp)
},
visitor: {
Program: {
enter(path: NodePath<t.Program>, state: State<EnvSpecificOptions>) {
Expand Down

0 comments on commit 4ece042

Please sign in to comment.