Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split declaration & init when working inside class #883

Open
Hifilo opened this issue May 28, 2023 · 0 comments
Open

split declaration & init when working inside class #883

Hifilo opened this issue May 28, 2023 · 0 comments
Labels
✨ Feature New refactoring or feature

Comments

@Hifilo
Copy link

Hifilo commented May 28, 2023

Hello, thanks for making this extension. I came across something, and I'm not sure if it would constitute a new feature or an enhancement.

In Javascript, when working in class methods, I need to make a constructor variable from an existing variable. The current split declaration/init doesn't consider classes.

Describe the solution you'd like

Some way to refactor an existing variable from within the method, into the class constructor with this. prefix.

A clear and concise description of what you want to happen.

It would be nice if Abracadabra could take the selected variable and split the declaration/init into the constructor.

It would replace the original let variable = some code inside the class method with this.variable = some code, and would create the declaration this.variable = null inside the constructor.

This feature would be identical to the existing feature but for a JS class.

class Thing {
    constructor(x, y) {
    this.x = x
    this.y = y
    }

method ( ) {
let a = 10
let b = 10
let size = a * b;

}
}

would become

class Thing {
    constructor(x, y) {
    this.x = x
    this.y = y
    this.size = null
    }

method ( ) {
let a = 10
let b = 10
this.size = a * b;
}
}

There are some factors to consider that I can see:

The variable may appear in other methods that you may or may not want to change.

I think one way is to just split the variable, place it in the constructor, and then the dev/user would go through the methods, replacing the variable as necessary.

If further enhancement was worthwhile, an option could be added for the algorithm to go through all the methods inside the class, replacing the variable wherever it appears

Additional context

As a novice, I can't speak on the scope/complexity of a feature like this or its usability with other languages. There may also be ways of working I'm not aware of that would make a feature like this unnecessary or very difficult to implement. If not the case I think this would improve the extension.

@Hifilo Hifilo added the ✨ Feature New refactoring or feature label May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature New refactoring or feature
Projects
None yet
Development

No branches or pull requests

1 participant