Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix static private field shadowed by local variable (#13656)
* fix: fix static private field shadowed by local variable currently throw an error, maybe we could generate correct code fix #12960 * feat: rename local variable and add test cases * feat: add unshadow to privateIn visitor also add test cases * test: add reference to shadowed variable * refactor: apply suggested changes simplify logic and add comments
- Loading branch information
Showing
22 changed files
with
291 additions
and
8 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
.../babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/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 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
static method() { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return this.#x + Test; | ||
} | ||
return func() + Test; | ||
} | ||
} | ||
|
||
expect(Test.method()).toBe(6) |
13 changes: 13 additions & 0 deletions
13
...babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/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,13 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
static method() { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return this.#x + Test; | ||
} | ||
return func() + Test; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...l-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/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"] | ||
} |
18 changes: 18 additions & 0 deletions
18
...abel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/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,18 @@ | ||
class Test { | ||
static method() { | ||
const _Test2 = 2; | ||
|
||
const func = () => { | ||
const _Test = 3; | ||
return babelHelpers.classStaticPrivateFieldSpecGet(this, Test, _x) + _Test; | ||
}; | ||
|
||
return func() + _Test2; | ||
} | ||
|
||
} | ||
|
||
var _x = { | ||
writable: true, | ||
value: 1 | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/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 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
static method() { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return this.#x + Test; | ||
} | ||
return func() + Test; | ||
} | ||
} | ||
|
||
expect(Test.method()).toBe(6) |
13 changes: 13 additions & 0 deletions
13
packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/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,13 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
static method() { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return this.#x + Test; | ||
} | ||
return func() + Test; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/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"] | ||
} |
18 changes: 18 additions & 0 deletions
18
...ages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/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,18 @@ | ||
class Test { | ||
static method() { | ||
const _Test2 = 2; | ||
|
||
const func = () => { | ||
const _Test = 3; | ||
return babelHelpers.classStaticPrivateFieldSpecGet(this, Test, _x) + _Test; | ||
}; | ||
|
||
return func() + _Test2; | ||
} | ||
|
||
} | ||
|
||
var _x = { | ||
writable: true, | ||
value: 1 | ||
}; |
17 changes: 17 additions & 0 deletions
17
...gin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/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 Test { | ||
|
||
static #x = 1 | ||
|
||
method(other) { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return #x in other && Test; | ||
} | ||
return func() + Test; | ||
} | ||
} | ||
|
||
const t = new Test(); | ||
const t2 = new Test(); | ||
expect(t.method(Test)).toBe(5) |
13 changes: 13 additions & 0 deletions
13
...in-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/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,13 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
method(other) { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return #x in other && Test; | ||
} | ||
return func() + Test; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...roposal-private-property-in-object/test/fixtures/private-loose/static-shadow/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"] | ||
} |
18 changes: 18 additions & 0 deletions
18
...n-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/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,18 @@ | ||
class Test { | ||
method(other) { | ||
const _Test2 = 2; | ||
|
||
const func = () => { | ||
const _Test = 3; | ||
return other === Test && _Test; | ||
}; | ||
|
||
return func() + _Test2; | ||
} | ||
|
||
} | ||
|
||
var _x = { | ||
writable: true, | ||
value: 1 | ||
}; |
17 changes: 17 additions & 0 deletions
17
...el-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/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 Test { | ||
|
||
static #x = 1 | ||
|
||
method(other) { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return #x in other && Test; | ||
} | ||
return func() + Test; | ||
} | ||
} | ||
|
||
const t = new Test(); | ||
const t2 = new Test(); | ||
expect(t.method(Test)).toBe(5) |
13 changes: 13 additions & 0 deletions
13
...l-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/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,13 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
method(other) { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return #x in other && Test; | ||
} | ||
return func() + Test; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/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"] | ||
} |
18 changes: 18 additions & 0 deletions
18
...-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/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,18 @@ | ||
class Test { | ||
method(other) { | ||
const _Test2 = 2; | ||
|
||
const func = () => { | ||
const _Test = 3; | ||
return other === Test && _Test; | ||
}; | ||
|
||
return func() + _Test2; | ||
} | ||
|
||
} | ||
|
||
var _x = { | ||
writable: true, | ||
value: 1 | ||
}; |
17 changes: 17 additions & 0 deletions
17
...-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/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 Test { | ||
|
||
static #x = 1 | ||
|
||
method(other) { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return #x in other && Test; | ||
} | ||
return func() + Test; | ||
} | ||
} | ||
|
||
const t = new Test(); | ||
const t2 = new Test(); | ||
expect(t.method(Test)).toBe(5) |
13 changes: 13 additions & 0 deletions
13
...proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/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,13 @@ | ||
class Test { | ||
|
||
static #x = 1 | ||
|
||
method(other) { | ||
const Test = 2; | ||
const func = () => { | ||
const Test = 3; | ||
return #x in other && Test; | ||
} | ||
return func() + Test; | ||
} | ||
} |
Oops, something went wrong.