Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Private static accessors strict
- Loading branch information
Showing
16 changed files
with
379 additions
and
18 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
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
23 changes: 23 additions & 0 deletions
23
packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/basic/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,23 @@ | ||
class Cl { | ||
static #PRIVATE_STATIC_FIELD = "top secret string"; | ||
|
||
static get #privateStaticFieldValue() { | ||
return Cl.#PRIVATE_STATIC_FIELD; | ||
} | ||
|
||
static set #privateStaticFieldValue(newValue) { | ||
Cl.#PRIVATE_STATIC_FIELD = `Updated: ${newValue}`; | ||
} | ||
|
||
static getValue() { | ||
return Cl.#privateStaticFieldValue; | ||
} | ||
|
||
static setValue() { | ||
Cl.#privateStaticFieldValue = "dank"; | ||
} | ||
} | ||
|
||
expect(Cl.getValue()).toEqual("top secret string"); | ||
Cl.setValue(); | ||
expect(Cl.getValue()).toEqual("Updated: dank"); |
19 changes: 19 additions & 0 deletions
19
packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/basic/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 Cl { | ||
static #PRIVATE_STATIC_FIELD = "top secret string"; | ||
|
||
static get #privateStaticFieldValue() { | ||
return Cl.#PRIVATE_STATIC_FIELD; | ||
} | ||
|
||
static set #privateStaticFieldValue(newValue) { | ||
Cl.#PRIVATE_STATIC_FIELD = `Updated: ${newValue}`; | ||
} | ||
|
||
static getValue() { | ||
return Cl.#privateStaticFieldValue; | ||
} | ||
|
||
static setValue() { | ||
Cl.#privateStaticFieldValue = "dank"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/basic/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,27 @@ | ||
class Cl { | ||
static getValue() { | ||
return babelHelpers.classStaticPrivateFieldSpecGet(Cl, Cl, _privateStaticFieldValue); | ||
} | ||
|
||
static setValue() { | ||
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _privateStaticFieldValue, "dank"); | ||
} | ||
|
||
} | ||
|
||
var _set_privateStaticFieldValue = function (newValue) { | ||
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _PRIVATE_STATIC_FIELD, `Updated: ${newValue}`); | ||
}; | ||
|
||
var _get_privateStaticFieldValue = function () { | ||
return babelHelpers.classStaticPrivateFieldSpecGet(Cl, Cl, _PRIVATE_STATIC_FIELD); | ||
}; | ||
|
||
var _PRIVATE_STATIC_FIELD = { | ||
writable: true, | ||
value: "top secret string" | ||
}; | ||
var _privateStaticFieldValue = { | ||
get: _get_privateStaticFieldValue, | ||
set: _set_privateStaticFieldValue | ||
}; |
13 changes: 13 additions & 0 deletions
13
...el-plugin-proposal-private-methods/test/fixtures/static-accessors/get-only-setter/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,13 @@ | ||
class Cl { | ||
static #PRIVATE_STATIC_FIELD = 0; | ||
|
||
static set #privateStaticFieldValue(newValue) { | ||
Cl.#PRIVATE_STATIC_FIELD = newValue; | ||
} | ||
|
||
static getPrivateStaticFieldValue() { | ||
return Cl.#privateStaticFieldValue; | ||
} | ||
} | ||
|
||
expect(Cl.getPrivateStaticFieldValue()).toBeUndefined(); |
11 changes: 11 additions & 0 deletions
11
...l-plugin-proposal-private-methods/test/fixtures/static-accessors/get-only-setter/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 @@ | ||
class Cl { | ||
static #PRIVATE_STATIC_FIELD = 0; | ||
|
||
static set #privateStaticFieldValue(newValue) { | ||
Cl.#PRIVATE_STATIC_FIELD = newValue; | ||
} | ||
|
||
static getPrivateStaticFieldValue() { | ||
return Cl.#privateStaticFieldValue; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...-plugin-proposal-private-methods/test/fixtures/static-accessors/get-only-setter/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 Cl { | ||
static getPrivateStaticFieldValue() { | ||
return babelHelpers.classStaticPrivateFieldSpecGet(Cl, Cl, _privateStaticFieldValue); | ||
} | ||
|
||
} | ||
|
||
var _set_privateStaticFieldValue = function (newValue) { | ||
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _PRIVATE_STATIC_FIELD, newValue); | ||
}; | ||
|
||
var _PRIVATE_STATIC_FIELD = { | ||
writable: true, | ||
value: 0 | ||
}; | ||
var _privateStaticFieldValue = { | ||
set: _set_privateStaticFieldValue | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/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,14 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"external-helpers", | ||
{ | ||
"helperVersion": "7.1000.0" | ||
} | ||
], | ||
"proposal-private-methods", | ||
"proposal-class-properties", | ||
"transform-block-scoping", | ||
"syntax-class-properties" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
...el-plugin-proposal-private-methods/test/fixtures/static-accessors/set-only-getter/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,13 @@ | ||
class Cl { | ||
static #PRIVATE_STATIC_FIELD = 0; | ||
|
||
static get #privateStaticFieldValue() { | ||
return Cl.#PRIVATE_STATIC_FIELD; | ||
} | ||
|
||
static setPrivateStaticFieldValue() { | ||
Cl.#privateStaticFieldValue = 1; | ||
} | ||
} | ||
|
||
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError); |
11 changes: 11 additions & 0 deletions
11
...l-plugin-proposal-private-methods/test/fixtures/static-accessors/set-only-getter/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 @@ | ||
class Cl { | ||
static #PRIVATE_STATIC_FIELD = 0; | ||
|
||
static get #privateStaticFieldValue() { | ||
return Cl.#PRIVATE_STATIC_FIELD; | ||
} | ||
|
||
static setPrivateStaticFieldValue() { | ||
Cl.#privateStaticFieldValue = 1; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...-plugin-proposal-private-methods/test/fixtures/static-accessors/set-only-getter/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 Cl { | ||
static setPrivateStaticFieldValue() { | ||
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _privateStaticFieldValue, 1); | ||
} | ||
|
||
} | ||
|
||
var _get_privateStaticFieldValue = function () { | ||
return babelHelpers.classStaticPrivateFieldSpecGet(Cl, Cl, _PRIVATE_STATIC_FIELD); | ||
}; | ||
|
||
var _PRIVATE_STATIC_FIELD = { | ||
writable: true, | ||
value: 0 | ||
}; | ||
var _privateStaticFieldValue = { | ||
get: _get_privateStaticFieldValue | ||
}; |
46 changes: 46 additions & 0 deletions
46
...ages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/updates/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,46 @@ | ||
class Cl { | ||
static #privateField = "top secret string"; | ||
static publicField = "not secret string"; | ||
|
||
static get #privateFieldValue() { | ||
return Cl.#privateField; | ||
} | ||
|
||
static set #privateFieldValue(newValue) { | ||
Cl.#privateField = newValue; | ||
} | ||
|
||
static publicGetPrivateField() { | ||
return Cl.#privateFieldValue; | ||
} | ||
|
||
static publicSetPrivateField(newValue) { | ||
Cl.#privateFieldValue = newValue; | ||
} | ||
|
||
static get publicFieldValue() { | ||
return Cl.publicField; | ||
} | ||
|
||
static set publicFieldValue(newValue) { | ||
Cl.publicField = newValue; | ||
} | ||
|
||
static testUpdates() { | ||
Cl.#privateField = 0; | ||
Cl.publicField = 0; | ||
Cl.#privateFieldValue = Cl.#privateFieldValue++; | ||
Cl.publicFieldValue = Cl.publicFieldValue++; | ||
expect(Cl.#privateField).toEqual(Cl.publicField); | ||
|
||
++Cl.#privateFieldValue; | ||
++Cl.publicFieldValue; | ||
expect(Cl.#privateField).toEqual(Cl.publicField); | ||
|
||
Cl.#privateFieldValue += 1; | ||
Cl.publicFieldValue += 1; | ||
expect(Cl.#privateField).toEqual(Cl.publicField); | ||
} | ||
} | ||
|
||
Cl.testUpdates(); |
Oops, something went wrong.