-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reference to class expression in private method (#13429)
Co-authored-by: Henry Zhu <[email protected]> Co-authored-by: Federico Ciardi <[email protected]> Co-authored-by: Nicolò Ribaudo <[email protected]>
- Loading branch information
1 parent
69f423b
commit 903b600
Showing
10 changed files
with
128 additions
and
3 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
15 changes: 15 additions & 0 deletions
15
...es/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/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,15 @@ | ||
const f = class Foo { | ||
static #x = Foo; | ||
static y = Foo; | ||
|
||
static extract() { | ||
return { | ||
x: Foo.#x, | ||
y: Foo.y, | ||
} | ||
} | ||
}; | ||
|
||
const { x, y } = f.extract(); | ||
expect(x).toBe(f) | ||
expect(y).toBe(f) |
4 changes: 4 additions & 0 deletions
4
...s/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/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,4 @@ | ||
const f = class Foo { | ||
static #x = Foo; | ||
static y = Foo; | ||
} |
3 changes: 3 additions & 0 deletions
3
...bel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/options.json
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,3 @@ | ||
{ | ||
"plugins": ["proposal-class-properties", "transform-block-scoping"] | ||
} |
6 changes: 6 additions & 0 deletions
6
.../babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/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,6 @@ | ||
var _class, _temp, _x; | ||
|
||
var f = (_temp = _class = class Foo {}, _x = { | ||
writable: true, | ||
value: _class | ||
}, babelHelpers.defineProperty(_class, "y", _class), _temp); |
31 changes: 31 additions & 0 deletions
31
...s/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-method/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,31 @@ | ||
const f = class Foo { | ||
static #bar() { | ||
return Foo; | ||
} | ||
|
||
static #method() { | ||
return function inner() { | ||
return Foo; | ||
}; | ||
} | ||
static #method_shadowed() { | ||
new Foo(); | ||
return function inner() { | ||
let Foo = 3; | ||
return Foo; | ||
} | ||
} | ||
|
||
static extract() { | ||
return { | ||
bar: Foo.#bar, | ||
method: Foo.#method, | ||
method_shadowed: Foo.#method_shadowed | ||
} | ||
} | ||
}; | ||
|
||
const { bar, method, method_shadowed } = f.extract(); | ||
expect(bar()).toBe(f) | ||
expect(method()()).toBe(f) | ||
expect(method_shadowed()()).toBe(3) |
18 changes: 18 additions & 0 deletions
18
.../babel-plugin-proposal-class-properties/test/fixtures/private/static-self-method/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,18 @@ | ||
const f = class Foo { | ||
static #bar() { | ||
return Foo; | ||
} | ||
|
||
static #method() { | ||
return function inner() { | ||
return Foo; | ||
}; | ||
} | ||
static #method_shadowed() { | ||
new Foo(); | ||
return function inner() { | ||
let Foo = 3; | ||
return Foo; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...el-plugin-proposal-class-properties/test/fixtures/private/static-self-method/options.json
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,3 @@ | ||
{ | ||
"plugins": ["proposal-class-properties", "transform-block-scoping"] | ||
} |
21 changes: 21 additions & 0 deletions
21
...babel-plugin-proposal-class-properties/test/fixtures/private/static-self-method/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,21 @@ | ||
var _class; | ||
|
||
var f = _class = class Foo {}; | ||
|
||
function _bar() { | ||
return _class; | ||
} | ||
|
||
function _method() { | ||
return function inner() { | ||
return _class; | ||
}; | ||
} | ||
|
||
function _method_shadowed() { | ||
new _class(); | ||
return function inner() { | ||
var Foo = 3; | ||
return Foo; | ||
}; | ||
} |