-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
The code below does not rename function z, while it does rename variable a. I would expect that the .rename method would handle functions as well.
const { refactor } = require('shift-refactor');
const fs = require('fs');
const src = `
var a = 1;
function x() {
z();
a = 3;
}
function y() {
z();
}
function z() {}`;
const $script = refactor(src);
var a = $script('VariableDeclarator[binding.name="a"]');
var z = $script('FunctionDeclaration[name.name="z"]');
a.rename('new_var_a'); //Will rename the variable.
z.rename('new_func_z'); //Won't rename the function.
console.log($script.print());Original:
var a = 1;
function x() {
z();
a = 3;
}
function y() {
z();
}
function z() {}Output:
var new_var_a = 1;
function x() {
z();
new_var_a = 3;
}
function y() {
z();
}
function z() {}Metadata
Metadata
Assignees
Labels
No labels