鉴于此输入:
const NOT_REFERENCED = 'abc';
class NotReferencedEither extends React.Component {
static something() {
// ...
}
someMethod() {
NotReferencedEither.something();
}
render() {
return <span>Foo</span>;
}
}
这个Babel插件:
export default function ({types: t}) {
return {
visitor: {
Program(path, state) {
Object.keys(path.scope.bindings).forEach(bindingName => {
const binding = path.scope.bindings[bindingName];
if (!binding.referenced) {
binding.path.remove();
}
});
},
}
};
}
我希望最终得到一个空文件。不幸的是,由于NotReferencedEither
具有对自身的引用,因此它不会通过删除测试。
如何扩充此插件,以便仅删除仅引用自身的NotReferencedEither
?