Skip to content

Commit

Permalink
fix(es/compat): Ignore this in nested scopes in classes pass (#6796)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #6506.
  • Loading branch information
kdy1 committed Jan 12, 2023
1 parent 2efcbdd commit 07676d5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/swc/tests/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ fn init_helpers() -> Arc<PathBuf> {

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

if env::var("SKIP_HELPERS").unwrap_or_default() == "1" {
return Arc::new(helper_dir);
}

let yarn = find_executable("yarn").expect("failed to find yarn");
let npm = find_executable("npm").expect("failed to find npm");
{
Expand Down
16 changes: 16 additions & 0 deletions crates/swc/tests/exec/issues-6xxx/6506/1/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Foo { }

class Bar extends Foo {
constructor() {
super();
this.node = 1;
const self = this;
this.root = {
get node() {
return self.node;
}
};
}
}

console.log((new Bar()).root.node);
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ var DerivedWithObjectAccessors = /*#__PURE__*/ function(Base) {
var _this;
var obj = {
get prop () {
return _possible_constructor_return(_this, true);
return true;
},
set prop (param){
_this._prop = param;
Expand All @@ -509,7 +509,7 @@ var DerivedWithObjectAccessorsUsingThisInKeys = /*#__PURE__*/ function(Base) {
var obj = (_obj = {
_prop: "prop"
}, _mutatorMap[_this.propName] = _mutatorMap[_this.propName] || {}, _mutatorMap[_this.propName].get = function() {
return _possible_constructor_return(_this, true);
return true;
}, _mutatorMap[_this.propName] = _mutatorMap[_this.propName] || {}, _mutatorMap[_this.propName].set = function(param1) {
_this._prop = param1;
}, _define_enumerable_properties(_obj, _mutatorMap), _obj);
Expand All @@ -529,7 +529,7 @@ var DerivedWithObjectAccessorsUsingThisInBodies = /*#__PURE__*/ function(Base) {
var obj = {
_prop: "prop",
get prop () {
return _possible_constructor_return(_this, _this._prop);
return _this._prop;
},
set prop (param){
_this._prop = param;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ impl VisitMut for ConstructorFolder<'_> {

ignore_return!(visit_mut_constructor, Constructor);

ignore_return!(visit_mut_getter_prop, GetterProp);

ignore_return!(visit_mut_setter_prop, SetterProp);

fn visit_mut_function(&mut self, _: &mut Function) {}

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

0 comments on commit 07676d5

Please sign in to comment.