ember-codemod-add-component-signatures
Version:
Codemod to add component signatures
42 lines (41 loc) • 1.5 kB
JavaScript
import { AST } from '@codemod-utils/ast-javascript';
export function getBaseComponent(file) {
const traverse = AST.traverse(true);
let baseComponentName;
let importPath;
traverse(file, {
visitImportDeclaration(path) {
switch (path.node.source.value) {
case '@ember/component':
case '@ember/component/template-only':
case '@glimmer/component': {
const defaultImport = path.node.specifiers.find(({ type }) => {
return type === 'ImportDefaultSpecifier';
});
if (!defaultImport) {
return false;
}
baseComponentName = defaultImport.local.name;
importPath = path.node.source.value;
return false;
}
case '@ember/template-compiler': {
const namedImport = path.node.specifiers.find(({ type }) => {
return type === 'ImportSpecifier';
});
if (!namedImport) {
return false;
}
baseComponentName = namedImport.local.name;
importPath = path.node.source.value;
return false;
}
}
return false;
},
});
return {
baseComponentName,
importPath,
};
}