fix(ct-angular): resolve Angular component usages
This commit is contained in:
parent
78596d9bad
commit
89b885a273
|
|
@ -21,6 +21,7 @@ import { setTransformData } from 'playwright/lib/transform/transform';
|
||||||
const t: typeof T = types;
|
const t: typeof T = types;
|
||||||
|
|
||||||
let jsxComponentNames: Set<string>;
|
let jsxComponentNames: Set<string>;
|
||||||
|
let classComponentNames: Set<string>;
|
||||||
let importInfos: Map<string, ImportInfo>;
|
let importInfos: Map<string, ImportInfo>;
|
||||||
|
|
||||||
export default declare((api: BabelAPI) => {
|
export default declare((api: BabelAPI) => {
|
||||||
|
|
@ -32,6 +33,7 @@ export default declare((api: BabelAPI) => {
|
||||||
Program: {
|
Program: {
|
||||||
enter(path) {
|
enter(path) {
|
||||||
jsxComponentNames = collectJsxComponentUsages(path.node);
|
jsxComponentNames = collectJsxComponentUsages(path.node);
|
||||||
|
classComponentNames = collectClassMountUsages(path.node);
|
||||||
importInfos = new Map();
|
importInfos = new Map();
|
||||||
},
|
},
|
||||||
exit(path) {
|
exit(path) {
|
||||||
|
|
@ -93,7 +95,7 @@ export default declare((api: BabelAPI) => {
|
||||||
if (t.isImportNamespaceSpecifier(specifier))
|
if (t.isImportNamespaceSpecifier(specifier))
|
||||||
continue;
|
continue;
|
||||||
const { localName, info } = importInfo(importNode, specifier, this.filename!);
|
const { localName, info } = importInfo(importNode, specifier, this.filename!);
|
||||||
if (jsxComponentNames.has(localName)) {
|
if (jsxComponentNames.has(localName) || classComponentNames.has(localName)) {
|
||||||
importInfos.set(localName, info);
|
importInfos.set(localName, info);
|
||||||
++importCount;
|
++importCount;
|
||||||
}
|
}
|
||||||
|
|
@ -141,6 +143,20 @@ function collectJsxComponentUsages(node: T.Node): Set<string> {
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function collectClassMountUsages(node: T.Node): Set<string> {
|
||||||
|
const names = new Set<string>();
|
||||||
|
traverse(node, {
|
||||||
|
enter: p => {
|
||||||
|
// Treat calls to mount as component usages.
|
||||||
|
// e.g. mount(MyComponent, ...)
|
||||||
|
if (t.isCallExpression(p.node) && t.isIdentifier(p.node.callee) && p.node.callee.name === 'mount' && t.isIdentifier(p.node.arguments[0]))
|
||||||
|
names.add(p.node.arguments[0].name);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
export type ImportInfo = {
|
export type ImportInfo = {
|
||||||
id: string;
|
id: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue