Skip to content

Commit ffe659f

Browse files
Dunqingoverlookmotel
authored andcommitted
refactor(var-declarations): remove unnecessary init parameter from insert_var
1 parent 0bd5333 commit ffe659f

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

crates/oxc_transformer/src/common/var_declarations.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,14 @@ impl<'a> VarDeclarationsStore<'a> {
8888

8989
/// Add a `var` declaration to be inserted at top of current enclosing statement block,
9090
/// given a `BoundIdentifier`.
91-
pub fn insert_var(
92-
&self,
93-
binding: &BoundIdentifier<'a>,
94-
init: Option<Expression<'a>>,
95-
ctx: &TraverseCtx<'a>,
96-
) {
91+
#[inline]
92+
pub fn insert_var(&self, binding: &BoundIdentifier<'a>, ctx: &TraverseCtx<'a>) {
9793
let pattern = binding.create_binding_pattern(ctx);
98-
self.insert_var_binding_pattern(pattern, init, ctx);
94+
self.insert_var_binding_pattern(pattern, None, ctx);
9995
}
10096

10197
/// Add a `var` declaration with the given init expression to be inserted at top of
10298
/// current enclosing statement block, given a `BoundIdentifier`.
103-
#[expect(unused)]
10499
#[inline]
105100
pub fn insert_var_with_init(
106101
&self,
@@ -117,7 +112,7 @@ impl<'a> VarDeclarationsStore<'a> {
117112
#[inline]
118113
pub fn create_var(&self, name: &str, ctx: &mut TraverseCtx<'a>) -> BoundIdentifier<'a> {
119114
let binding = ctx.generate_uid_in_current_hoist_scope(name);
120-
self.insert_var(&binding, None, ctx);
115+
self.insert_var(&binding, ctx);
121116
binding
122117
}
123118

@@ -132,7 +127,7 @@ impl<'a> VarDeclarationsStore<'a> {
132127
ctx: &mut TraverseCtx<'a>,
133128
) -> BoundIdentifier<'a> {
134129
let binding = ctx.generate_uid_in_current_hoist_scope(name);
135-
self.insert_var(&binding, Some(expression), ctx);
130+
self.insert_var_with_init(&binding, expression, ctx);
136131
binding
137132
}
138133

@@ -145,7 +140,7 @@ impl<'a> VarDeclarationsStore<'a> {
145140
ctx: &mut TraverseCtx<'a>,
146141
) -> BoundIdentifier<'a> {
147142
let binding = ctx.generate_uid_in_current_hoist_scope_based_on_node(node);
148-
self.insert_var(&binding, None, ctx);
143+
self.insert_var(&binding, ctx);
149144
binding
150145
}
151146

crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a, 'ctx> NullishCoalescingOperator<'a, 'ctx> {
172172
// `(x) => x;` -> `((x) => x)();`
173173
new_expr = ctx.ast.expression_call(SPAN, arrow_function, NONE, ctx.ast.vec(), false);
174174
} else {
175-
self.ctx.var_declarations.insert_var(&binding, None, ctx);
175+
self.ctx.var_declarations.insert_var(&binding, ctx);
176176
}
177177

178178
new_expr

crates/oxc_transformer/src/es2022/class_properties/class.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
114114
// Insert `var _prop;` declaration.
115115
// Do it here rather than when binding was created to maintain same order of `var`
116116
// declarations as Babel. `c = class C { #x = 1; static y = 2; }` -> `var _C, _x;`
117-
self.ctx.var_declarations.insert_var(&prop.binding, None, ctx);
117+
self.ctx.var_declarations.insert_var(&prop.binding, ctx);
118118

119119
if prop.is_static {
120120
return None;
@@ -137,7 +137,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
137137
if let Some(binding) = &self.class_bindings.temp {
138138
// Insert `var _Class` statement, if it wasn't already in `transform_class`
139139
if !self.temp_var_is_created {
140-
self.ctx.var_declarations.insert_var(binding, None, ctx);
140+
self.ctx.var_declarations.insert_var(binding, ctx);
141141
}
142142

143143
// `_Class = class {}`
@@ -188,7 +188,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
188188
if let Some(ident) = &class.id {
189189
// Insert `var _Class` statement, if it wasn't already in `transform_class`
190190
if !self.temp_var_is_created {
191-
self.ctx.var_declarations.insert_var(temp_binding, None, ctx);
191+
self.ctx.var_declarations.insert_var(temp_binding, ctx);
192192
}
193193

194194
// Insert `_Class = Class` after class.
@@ -342,7 +342,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
342342
// TODO(improve-on-babel): Inserting the temp var `var _Class` statement here is only
343343
// to match Babel's output. It'd be simpler just to insert it at the end and get rid of
344344
// `temp_var_is_created` that tracks whether it's done already or not.
345-
self.ctx.var_declarations.insert_var(&temp_binding, None, ctx);
345+
self.ctx.var_declarations.insert_var(&temp_binding, ctx);
346346
}
347347
Some(temp_binding)
348348
} else {

0 commit comments

Comments
 (0)