forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve decorated private method check (babel#16226)
* refactor: extract createPrivateMethodUpdateError * fix: check private method update after transform * fix: do not throw when a private name shadow decorated method * cleanup typings * review comments
- Loading branch information
1 parent
26e775c
commit 0da0161
Showing
30 changed files
with
140 additions
and
72 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
2 changes: 1 addition & 1 deletion
2
...corators/test/fixtures/2021-12-misc/setting-private-method-via-array-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-for-of/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...orators/test/fixtures/2021-12-misc/setting-private-method-via-object-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...oposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-rest/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-update/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...corators/test/fixtures/2022-03-misc/setting-private-method-via-array-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2022-03-misc/setting-private-method-via-for-of/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...orators/test/fixtures/2022-03-misc/setting-private-method-via-object-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...oposal-decorators/test/fixtures/2022-03-misc/setting-private-method-via-rest/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2022-03-misc/setting-private-method-via-update/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...plugin-proposal-decorators/test/fixtures/2022-03-misc/setting-private-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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...corators/test/fixtures/2023-01-misc/setting-private-method-via-array-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2023-01-misc/setting-private-method-via-for-of/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...orators/test/fixtures/2023-01-misc/setting-private-method-via-object-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...oposal-decorators/test/fixtures/2023-01-misc/setting-private-method-via-rest/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2023-01-misc/setting-private-method-via-update/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...plugin-proposal-decorators/test/fixtures/2023-01-misc/setting-private-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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
6 changes: 6 additions & 0 deletions
6
...in-proposal-decorators/test/fixtures/2023-05-misc/setting-private-method-in-body/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,6 @@ | ||
const dec = () => {}; | ||
class Foo { | ||
@dec #x() { | ||
this.#x = 123; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...roposal-decorators/test/fixtures/2023-05-misc/setting-private-method-in-body/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 @@ | ||
{ | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...corators/test/fixtures/2023-05-misc/setting-private-method-via-array-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2023-05-misc/setting-private-method-via-for-of/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...orators/test/fixtures/2023-05-misc/setting-private-method-via-object-pattern/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...oposal-decorators/test/fixtures/2023-05-misc/setting-private-method-via-rest/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...osal-decorators/test/fixtures/2023-05-misc/setting-private-method-via-update/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
2 changes: 1 addition & 1 deletion
2
...plugin-proposal-decorators/test/fixtures/2023-05-misc/setting-private-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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." | ||
"throws": "Decorated private methods are read-only, but \"#x\" is updated via this expression." | ||
} |
11 changes: 11 additions & 0 deletions
11
...osal-decorators/test/fixtures/2023-05-misc/setting-shadowed-private-method-valid/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,11 @@ | ||
const dec = () => {}; | ||
class Foo { | ||
@dec #x() { | ||
class Nested { | ||
static #x; | ||
static set x(v) { | ||
this.#x = v; | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...sal-decorators/test/fixtures/2023-05-misc/setting-shadowed-private-method-valid/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 @@ | ||
var _call_x, _initProto; | ||
const dec = () => {}; | ||
class Foo { | ||
static { | ||
[_call_x, _initProto] = babelHelpers.applyDecs2305(this, [[dec, 2, "x", function () { | ||
class Nested { | ||
static #x; | ||
static set x(v) { | ||
this.#x = v; | ||
} | ||
} | ||
}]], [], 0, _ => #x in _).e; | ||
} | ||
constructor() { | ||
_initProto(this); | ||
} | ||
#x = _call_x; | ||
} |