1import { createMacro } from 'babel-plugin-macros';
2import { makeHelpers } from './transform';
3
4function reghexMacro({ references, babel }) {
5 const helpers = makeHelpers(babel);
6 const defaultRefs = references.default || [];
7
8 defaultRefs.forEach((ref) => {
9 if (!t.isCallExpression(ref.parentPath.node)) return;
10 const path = ref.parentPath.parentPath;
11 if (!helpers.isMatch(path)) return;
12
13 const importPath = helpers.getMatchImport(path);
14 if (!importPath) return;
15
16 helpers.updateImport(importPath);
17 helpers.transformMatch(path);
18 });
19
20 return {
21 keepImports: true,
22 };
23}
24
25export default createMacro(reghexMacro);