New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle private access chained on an optional chain #11248
Merged
nicolo-ribaudo
merged 20 commits into
babel:feat-7.10.0/private-stuff
from
jridgewell:optional-private
May 26, 2020
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d8a38b8
Handle private access chained on an optional chain
jridgewell 844f4bd
Comments, tests, and fixes
jridgewell 327b046
tmp
jridgewell d77facd
Reduce temporary variables
jridgewell 5ec367f
Add private method tests
jridgewell 827fd8e
Fix bug with traversing detached node tree
jridgewell e2ae2b4
Update memoized names
jridgewell d5b22f6
chore: regenerate test fixtures
JLHwung 381a622
feat: allow ?. PrivateIdentifier in parser
JLHwung de86a3d
fix: rebase error
JLHwung 0742d99
update test262 whitelist
JLHwung 785b6e8
feat: support ?.#x and ?.#m()
JLHwung 1788e52
chore: run test on node 14
JLHwung f08975b
fix: don’t memoise static base ref
JLHwung 55bdc00
test: add test cases for `#m?.()`
JLHwung 12eb77b
add `#m?.()` support
JLHwung aee43de
add loose test cases
JLHwung 970a5a1
nit: .call is always computed: false
JLHwung 08160d8
fix: avoid reuse ast node
JLHwung 6c4486f
fix: throw early error for `delete this?.#x`
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...-private-call-with-transform/options.json → ...e-member-call-with-transform/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,6 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"proposal-optional-chaining", | ||
["proposal-optional-chaining", { "loose": true }], | ||
["proposal-class-properties", { "loose": true }] | ||
] | ||
} |
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
122 changes: 122 additions & 0 deletions
122
...al-class-properties/test/fixtures/private-loose/optional-chain-before-member-call/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,122 @@ | ||
class Foo { | ||
static #x = 1; | ||
static #m = function() { return this.#x; }; | ||
static #self = Foo; | ||
static self = Foo; | ||
static getSelf() { return this } | ||
|
||
static test() { | ||
const o = { Foo: Foo }; | ||
const deep = { very: { o } }; | ||
function fn() { | ||
return o; | ||
} | ||
function fnDeep() { | ||
return deep; | ||
} | ||
|
||
expect(o?.Foo.#m()).toEqual(1); | ||
expect(o?.Foo.#m().toString).toEqual(1..toString); | ||
expect(o?.Foo.#m().toString()).toEqual('1'); | ||
|
||
expect(deep?.very.o?.Foo.#m()).toEqual(1); | ||
expect(deep?.very.o?.Foo.#m().toString).toEqual(1..toString); | ||
expect(deep?.very.o?.Foo.#m().toString()).toEqual('1'); | ||
|
||
expect(o?.Foo.#self.#m()).toEqual(1); | ||
expect(o?.Foo.#self.self.#m()).toEqual(1); | ||
expect(o?.Foo.#self?.self.#m()).toEqual(1); | ||
expect(o?.Foo.#self.self?.self.#m()).toEqual(1); | ||
expect(o?.Foo.#self?.self?.self.#m()).toEqual(1); | ||
|
||
expect(o?.Foo.#self.getSelf().#m()).toEqual(1); | ||
expect(o?.Foo.#self.getSelf?.().#m()).toEqual(1); | ||
expect(o?.Foo.#self?.getSelf().#m()).toEqual(1); | ||
expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(1); | ||
expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(1); | ||
expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(1); | ||
expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(1); | ||
expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); | ||
|
||
expect(fn?.().Foo.#m()).toEqual(1); | ||
expect(fn?.().Foo.#m().toString).toEqual(1..toString); | ||
expect(fn?.().Foo.#m().toString()).toEqual('1'); | ||
|
||
expect(fnDeep?.().very.o?.Foo.#m()).toEqual(1); | ||
expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(1..toString); | ||
expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual('1'); | ||
|
||
expect(fn?.().Foo.#self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self.self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self?.self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self.self?.self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(1); | ||
|
||
expect(fn?.().Foo.#self.getSelf().#m()).toEqual(1); | ||
expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(1); | ||
expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(1); | ||
expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(1); | ||
expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(1); | ||
expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(1); | ||
} | ||
|
||
static testNull() { | ||
const o = null;; | ||
const deep = { very: { o } }; | ||
const fn = null; | ||
function fnDeep() { | ||
return deep; | ||
} | ||
|
||
expect(o?.Foo.#m()).toEqual(undefined); | ||
expect(o?.Foo.#m().toString).toEqual(undefined); | ||
expect(o?.Foo.#m().toString()).toEqual(undefined); | ||
|
||
expect(deep?.very.o?.Foo.#m()).toEqual(undefined); | ||
expect(deep?.very.o?.Foo.#m().toString).toEqual(undefined); | ||
expect(deep?.very.o?.Foo.#m().toString()).toEqual(undefined); | ||
|
||
expect(o?.Foo.#self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self.self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self?.self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self.self?.self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self?.self?.self.#m()).toEqual(undefined); | ||
|
||
expect(o?.Foo.#self.getSelf().#m()).toEqual(undefined); | ||
expect(o?.Foo.#self.getSelf?.().#m()).toEqual(undefined); | ||
expect(o?.Foo.#self?.getSelf().#m()).toEqual(undefined); | ||
expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(undefined); | ||
expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); | ||
expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); | ||
|
||
expect(fn?.().Foo.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#m().toString).toEqual(undefined); | ||
expect(fn?.().Foo.#m().toString()).toEqual(undefined); | ||
|
||
expect(fnDeep?.().very.o?.Foo.#m()).toEqual(undefined); | ||
expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(undefined); | ||
expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual(undefined); | ||
|
||
expect(fn?.().Foo.#self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self.self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self?.self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self.self?.self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(undefined); | ||
|
||
expect(fn?.().Foo.#self.getSelf().#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(undefined); | ||
expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined); | ||
} | ||
} | ||
|
||
Foo.test(); | ||
Foo.testNull(); |
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
...ass-properties/test/fixtures/private-loose/optional-chain-before-member-call/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,4 @@ | ||
{ | ||
"plugins": [["proposal-class-properties", { "loose": true }]], | ||
"minNodeVersion": "14.0.0" | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...private-loose/optional-chain/options.json → ...fore-property-with-transform/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,5 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["proposal-optional-chaining", { "loose": true }], | ||
["proposal-class-properties", { "loose": true }] | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we'll figure out how to use
== null
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add
loose
support tobabel/packages/babel-helper-member-expression-to-functions/src/index.js
Line 143 in b457f52