Skip to content

.rename() does not rename functions. #26

@FrankSpierings

Description

@FrankSpierings

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions