Skip to content

Commit 07676d5

Browse files
authoredJan 12, 2023
fix(es/compat): Ignore this in nested scopes in classes pass (#6796)
**Related issue:** - Closes #6506.
1 parent 2efcbdd commit 07676d5

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed
 

‎crates/swc/tests/exec.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ fn init_helpers() -> Arc<PathBuf> {
5555

5656
let helper_dir = project_root.join("packages").join("swc-helpers");
5757

58+
if env::var("SKIP_HELPERS").unwrap_or_default() == "1" {
59+
return Arc::new(helper_dir);
60+
}
61+
5862
let yarn = find_executable("yarn").expect("failed to find yarn");
5963
let npm = find_executable("npm").expect("failed to find npm");
6064
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Foo { }
2+
3+
class Bar extends Foo {
4+
constructor() {
5+
super();
6+
this.node = 1;
7+
const self = this;
8+
this.root = {
9+
get node() {
10+
return self.node;
11+
}
12+
};
13+
}
14+
}
15+
16+
console.log((new Bar()).root.node);

‎crates/swc/tests/tsc-references/derivedClassSuperProperties.1.normal.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ var DerivedWithObjectAccessors = /*#__PURE__*/ function(Base) {
486486
var _this;
487487
var obj = {
488488
get prop () {
489-
return _possible_constructor_return(_this, true);
489+
return true;
490490
},
491491
set prop (param){
492492
_this._prop = param;
@@ -509,7 +509,7 @@ var DerivedWithObjectAccessorsUsingThisInKeys = /*#__PURE__*/ function(Base) {
509509
var obj = (_obj = {
510510
_prop: "prop"
511511
}, _mutatorMap[_this.propName] = _mutatorMap[_this.propName] || {}, _mutatorMap[_this.propName].get = function() {
512-
return _possible_constructor_return(_this, true);
512+
return true;
513513
}, _mutatorMap[_this.propName] = _mutatorMap[_this.propName] || {}, _mutatorMap[_this.propName].set = function(param1) {
514514
_this._prop = param1;
515515
}, _define_enumerable_properties(_obj, _mutatorMap), _obj);
@@ -529,7 +529,7 @@ var DerivedWithObjectAccessorsUsingThisInBodies = /*#__PURE__*/ function(Base) {
529529
var obj = {
530530
_prop: "prop",
531531
get prop () {
532-
return _possible_constructor_return(_this, _this._prop);
532+
return _this._prop;
533533
},
534534
set prop (param){
535535
_this._prop = param;

‎crates/swc_ecma_transforms_compat/src/es2015/classes/constructor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ impl VisitMut for ConstructorFolder<'_> {
187187

188188
ignore_return!(visit_mut_constructor, Constructor);
189189

190+
ignore_return!(visit_mut_getter_prop, GetterProp);
191+
192+
ignore_return!(visit_mut_setter_prop, SetterProp);
193+
190194
fn visit_mut_function(&mut self, _: &mut Function) {}
191195

192196
fn visit_mut_expr(&mut self, expr: &mut Expr) {

0 commit comments

Comments
 (0)
Please sign in to comment.