
24 Code Assists for Variables
- Convert destructuring to regular variable declaration
Convert all variables that are declared via destructuring into separate regular variable declarations.
- Convert let to const
Replace
let
declarations that have no re-assignment withconst
declarations. - Convert 'new Array(…)' to '[…]'
Replace
new Array(…)
calls with[…]
. - Convert to destructuring assignment
Convert a variable declaration that accesses an object property to a destructuring assignment.
- Extract variable
Extract one or more occurrences of an expression into a
const
variable. - Flatten array rest/spread property
Merge a ...[] expression into the outer array literal or destructuring expression.
- Replace assignment with return
Convert a variable assignment to a
return
statement. - Move default value into parameter
Replace default value assignment expressions with default parameter values.
- Merge into preceding destructuring assignment
Combine an object destructuring assignment with its preceding sibling.
- Merge variable declaration and initialization
Convert the initial assignment of a variable into its declaration initializer.
- Move constant to top-level scope
Move a constant to the top-level scope of the module.
- Extract destructured expression into separate variable declaration
Move a destructured expression inside a variable declaration into a separate variable declaration.
- Move field initialization into constructor
Moves the assignment of the initial field value into the class constructor.
- Move initialization into field declaration
Moves the assignment of the initial field value into the field declaration.
- Move variable declaration
Move a variable declaration up or down.
- Push variable declaration into initial value
Inlines a variable that is initialized with another variable into the declaration of that variable.
- Push parameter into IIFE/IIAF
Push a parameter of an immediately-invoked function expressions (IIFEs) or an immediately-invoked arrow functions (IIAFs) into the function body.
- Remove trailing array destructuring holes
Remove trailing array destructuring holes and empty array destructuring expressions.
- Remove unused variable
Remove a variable that is not read or written.
- Replace with existing variable
Replace an expression with an existing variable.
- Convert var to let or const
Replace
var
with block-scoped variableslet
andconst
. - Split variable declaration sequence
Convert declarations with multiple variables into separate declarations for each variable.
- Split variable declaration and initialization
Separate the variable initialization from its declaration.
- Use nullish coalescence in default expression
Replace default value expression with nullish coalescing operator (
??
) expressions.