Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow reinitializing private elements (#13601)
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
- Loading branch information
1 parent
cb3ebde
commit fdfe978
Showing
92 changed files
with
451 additions
and
229 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
19 changes: 19 additions & 0 deletions
19
...eate-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/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,19 @@ | ||
class Base { | ||
constructor(obj) { | ||
return obj; | ||
} | ||
} | ||
|
||
class Derived extends Base { | ||
get #foo() { | ||
return 'bar'; | ||
} | ||
|
||
set #foo(value) { | ||
this.#foo = value; | ||
} | ||
|
||
static get(obj) { | ||
return obj.#foo(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/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,6 @@ | ||
{ | ||
"presets": [["env", { "shippedProposals": true }]], | ||
"targets": { | ||
"chrome": "75" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ate-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/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,31 @@ | ||
class Base { | ||
constructor(obj) { | ||
return obj; | ||
} | ||
|
||
} | ||
|
||
var _foo = /*#__PURE__*/new WeakMap(); | ||
|
||
class Derived extends Base { | ||
constructor(...args) { | ||
super(...args); | ||
babelHelpers.classPrivateFieldInitSpec(this, _foo, { | ||
get: _get_foo, | ||
set: _set_foo | ||
}); | ||
} | ||
|
||
static get(obj) { | ||
return babelHelpers.classPrivateFieldGet(obj, _foo).call(obj); | ||
} | ||
|
||
} | ||
|
||
function _get_foo() { | ||
return 'bar'; | ||
} | ||
|
||
function _set_foo(value) { | ||
babelHelpers.classPrivateFieldSet(this, _foo, value); | ||
} |
13 changes: 13 additions & 0 deletions
13
...-create-class-features-plugin/test/fixtures/field-reinitialization/private-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,13 @@ | ||
class Base { | ||
constructor(obj) { | ||
return obj; | ||
} | ||
} | ||
|
||
let counter = 0; | ||
class Derived extends Base { | ||
#foo = ++counter; | ||
static get(obj) { | ||
return obj.#foo; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ate-class-features-plugin/test/fixtures/field-reinitialization/private-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,6 @@ | ||
{ | ||
"presets": [["env", { "shippedProposals": true }]], | ||
"targets": { | ||
"chrome": "75" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...create-class-features-plugin/test/fixtures/field-reinitialization/private-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,25 @@ | ||
class Base { | ||
constructor(obj) { | ||
return obj; | ||
} | ||
|
||
} | ||
|
||
let counter = 0; | ||
|
||
var _foo = /*#__PURE__*/new WeakMap(); | ||
|
||
class Derived extends Base { | ||
constructor(...args) { | ||
super(...args); | ||
babelHelpers.classPrivateFieldInitSpec(this, _foo, { | ||
writable: true, | ||
value: ++counter | ||
}); | ||
} | ||
|
||
static get(obj) { | ||
return babelHelpers.classPrivateFieldGet(obj, _foo); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...create-class-features-plugin/test/fixtures/field-reinitialization/private-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,15 @@ | ||
class Base { | ||
constructor(obj) { | ||
return obj; | ||
} | ||
} | ||
|
||
class Derived extends Base { | ||
#foo() { | ||
return 'bar'; | ||
} | ||
|
||
static get(obj) { | ||
return obj.#foo(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...te-class-features-plugin/test/fixtures/field-reinitialization/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [["env", { "shippedProposals": true }]], | ||
"targets": { | ||
"chrome": "75" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...reate-class-features-plugin/test/fixtures/field-reinitialization/private-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,24 @@ | ||
class Base { | ||
constructor(obj) { | ||
return obj; | ||
} | ||
|
||
} | ||
|
||
var _foo = /*#__PURE__*/new WeakSet(); | ||
|
||
class Derived extends Base { | ||
constructor(...args) { | ||
super(...args); | ||
babelHelpers.classPrivateMethodInitSpec(this, _foo); | ||
} | ||
|
||
static get(obj) { | ||
return babelHelpers.classPrivateMethodGet(obj, _foo, _foo2).call(obj); | ||
} | ||
|
||
} | ||
|
||
function _foo2() { | ||
return 'bar'; | ||
} |
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
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
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
Oops, something went wrong.