Skip to content

Commit cfb6d87

Browse files
fix(es/compat): Revert redundant hoister visits in getter/setter props
This commit reverts the changes to visit_mut_getter_prop and visit_mut_setter_prop that were introduced in commit 2bf316a. These changes introduced redundant visits to the hoister, which is incorrect. Unlike arrow functions which need special handling, getters and setters already create new hoister scopes via `old_rep = self.hoister.take()`, so the additional hoister visit before the main visit is unnecessary and incorrect. Changes: - Reverted visit_mut_getter_prop to original implementation - Reverted visit_mut_setter_prop to original implementation - Reverted getter-setter/output.js test snapshot to original The original fix for issue #11422 (arrow function this context) remains intact. Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
1 parent 2bf316a commit cfb6d87

File tree

2 files changed

+6
-19
lines changed
  • crates
    • swc_ecma_compat_es2015/src
    • swc_ecma_transforms_compat/tests/arrow/getter-setter

2 files changed

+6
-19
lines changed

crates/swc_ecma_compat_es2015/src/arrow.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ impl VisitMut for Arrow {
198198
if let Some(body) = &mut f.body {
199199
let old_rep = self.hoister.take();
200200

201-
// First, replace `this` with `_this` in the body
202-
// This must happen before converting nested arrow functions
203-
body.visit_mut_with(&mut self.hoister);
204-
205-
// Then, convert nested arrow functions
206201
body.visit_mut_with(self);
207202

208203
let decl = mem::replace(&mut self.hoister, old_rep).to_stmt();
@@ -240,11 +235,6 @@ impl VisitMut for Arrow {
240235
if let Some(body) = &mut f.body {
241236
let old_rep = self.hoister.take();
242237

243-
// First, replace `this` with `_this` in the body
244-
// This must happen before converting nested arrow functions
245-
body.visit_mut_with(&mut self.hoister);
246-
247-
// Then, convert nested arrow functions
248238
body.visit_mut_with(self);
249239

250240
let decl = mem::replace(&mut self.hoister, old_rep).to_stmt();

crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/output.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ var _this = this;
22
const a1 = function() {
33
return {
44
get this () {
5-
var _this1 = this, _arguments = arguments;
6-
_this1;
7-
_arguments;
5+
this;
6+
arguments;
87
},
98
set arguments (a = this){
10-
var _this2 = this, _arguments1 = arguments;
11-
_this2;
12-
_arguments1;
9+
this;
10+
arguments;
1311
},
1412
get [_this] () {
15-
var _this3 = this, _arguments2 = arguments;
16-
_this3;
17-
_arguments2;
13+
this;
14+
arguments;
1815
}
1916
};
2017
};

0 commit comments

Comments
 (0)