Skip to content

Commit

Permalink
fix: ref rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Mar 31, 2023
1 parent bab3925 commit c09e926
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/swc-helpers/scripts/ast_grep.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,28 @@ export function ast_grep() {
rule: {
pattern: import_binding,
kind: "identifier",
inside: { kind: "call_expression", field: "function" },
inside: {
not: {
kind: "import_specifier",
},
},
},
})
.forEach((match) => {
const range = match.range();
const call_name = match.text();
const ref_name = match.text();

const is_func_call = match.inside("$FUN($$$)");

source.update(
range.start.index,
range.end.index,
`(0, ${import_binding}.${call_name})`,
`${import_binding}.${ref_name}`,
);

if (is_func_call) {
source.appendLeft(range.start.index, "(0, ").appendRight(range.end.index, ")");
}
});
});

Expand Down

0 comments on commit c09e926

Please sign in to comment.