Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unwrap parthenthesizedExpression
- Loading branch information
Showing
3 changed files
with
67 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
45 changes: 45 additions & 0 deletions
45
...osal-optional-chaining/test/fixtures/general/parenthesized-expression-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,45 @@ | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
m() { return this.x; }; | ||
getSelf() { return this } | ||
|
||
test() { | ||
const Foo = this; | ||
const o = { Foo: Foo }; | ||
const deep = { very: { o } }; | ||
function fn() { | ||
return o; | ||
} | ||
function fnDeep() { | ||
return deep; | ||
} | ||
|
||
expect((Foo?.["m"])()).toEqual(1); | ||
expect((Foo?.["m"])().toString).toEqual(1..toString); | ||
expect((Foo?.["m"])().toString()).toEqual('1'); | ||
|
||
expect((o?.Foo.m)()).toEqual(1); | ||
expect((o?.Foo.m)().toString).toEqual(1..toString); | ||
expect((o?.Foo.m)().toString()).toEqual('1'); | ||
|
||
expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1); | ||
expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1); | ||
} | ||
|
||
testNull() { | ||
const o = null; | ||
|
||
expect(() => { (o?.Foo.m)() }).toThrow(); | ||
expect(() => { (o?.Foo.m)().toString }).toThrow(); | ||
expect(() => { (o?.Foo.m)().toString() }).toThrow(); | ||
|
||
expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); | ||
expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); | ||
} | ||
} | ||
|
||
(new Foo).test(); | ||
(new Foo).testNull(); |
6 changes: 6 additions & 0 deletions
6
...optional-chaining/test/fixtures/general/parenthesized-expression-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,6 @@ | ||
{ | ||
"plugins": ["proposal-optional-chaining"], | ||
"parserOpts": { | ||
"createParenthesizedExpressions": true | ||
} | ||
} |