-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
super
Method Calls in Class Private Methods (#9704)
This fixes an issue with the use of super method calls in class private methods. See #9580 for more info re: behavior of the bug.
- Loading branch information
1 parent
48d66eb
commit e068281
Showing
8 changed files
with
137 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...es/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/super/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Base { | ||
superMethod() { | ||
return 1017; | ||
} | ||
} | ||
|
||
class Sub extends Base { | ||
#privateMethod() { | ||
return super.superMethod(); | ||
} | ||
|
||
publicMethod() { | ||
return this.#privateMethod(); | ||
} | ||
} | ||
|
||
expect((new Sub()).publicMethod()).toEqual(1017); |
15 changes: 15 additions & 0 deletions
15
...s/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/super/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Base { | ||
superMethod() { | ||
return 1017; | ||
} | ||
} | ||
|
||
class Sub extends Base { | ||
#privateMethod() { | ||
return super.superMethod(); | ||
} | ||
|
||
publicMethod() { | ||
return this.#privateMethod(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/super/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Base { | ||
superMethod() { | ||
return 1017; | ||
} | ||
|
||
} | ||
|
||
class Sub extends Base { | ||
constructor(...args) { | ||
super(...args); | ||
Object.defineProperty(this, _privateMethod, { | ||
value: _privateMethod2 | ||
}); | ||
} | ||
|
||
publicMethod() { | ||
return babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod](); | ||
} | ||
|
||
} | ||
|
||
var _privateMethod = babelHelpers.classPrivateFieldLooseKey("privateMethod"); | ||
|
||
var _privateMethod2 = function _privateMethod2() { | ||
return Base.prototype.superMethod.call(this); | ||
}; |
17 changes: 17 additions & 0 deletions
17
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Base { | ||
superMethod() { | ||
return 1017; | ||
} | ||
} | ||
|
||
class Sub extends Base { | ||
#privateMethod() { | ||
return super.superMethod(); | ||
} | ||
|
||
publicMethod() { | ||
return this.#privateMethod(); | ||
} | ||
} | ||
|
||
expect((new Sub()).publicMethod()).toEqual(1017); |
15 changes: 15 additions & 0 deletions
15
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Base { | ||
superMethod() { | ||
return 1017; | ||
} | ||
} | ||
|
||
class Sub extends Base { | ||
#privateMethod() { | ||
return super.superMethod(); | ||
} | ||
|
||
publicMethod() { | ||
return this.#privateMethod(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Base { | ||
superMethod() { | ||
return 1017; | ||
} | ||
|
||
} | ||
|
||
class Sub extends Base { | ||
constructor(...args) { | ||
super(...args); | ||
|
||
_privateMethod.add(this); | ||
} | ||
|
||
publicMethod() { | ||
return babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this); | ||
} | ||
|
||
} | ||
|
||
var _privateMethod = new WeakSet(); | ||
|
||
var _privateMethod2 = function _privateMethod2() { | ||
return babelHelpers.get(babelHelpers.getPrototypeOf(this), "superMethod", this).call(this); | ||
}; |