Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
149 additions
and
14 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ptional-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/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,42 @@ | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
m() { return this.x; }; | ||
getSelf() { return this } | ||
|
||
test() { | ||
const Foo = this; | ||
const o = { Foo: Foo }; | ||
|
||
expect((Foo?.["m"])()).toEqual(1); | ||
expect((Foo?.["m"])().toString).toEqual(1..toString); | ||
expect((Foo?.["m"])().toString()).toEqual('1'); | ||
|
||
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
...al-chaining/test/fixtures/general/parenthesized-expression-member-call-loose/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", { "loose": true }]], | ||
"parserOpts": { | ||
"createParenthesizedExpressions": 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
38 changes: 38 additions & 0 deletions
38
...-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/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,38 @@ | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
m() { return this.x; }; | ||
getSelf() { return this } | ||
|
||
test() { | ||
const Foo = this; | ||
const o = { Foo: Foo }; | ||
|
||
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(); |
26 changes: 26 additions & 0 deletions
26
...proposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/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,26 @@ | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
m() { return this.x; }; | ||
getSelf() { return this } | ||
|
||
test() { | ||
const Foo = this; | ||
const o = { Foo: Foo }; | ||
|
||
(Foo?.["m"])(); | ||
(Foo?.["m"])().toString; | ||
(Foo?.["m"])().toString(); | ||
|
||
(o?.Foo.m)(); | ||
(o?.Foo.m)().toString; | ||
(o?.Foo.m)().toString(); | ||
|
||
(((o.Foo?.self.getSelf)())?.m)(); | ||
(((o.Foo.self?.getSelf)())?.m)(); | ||
} | ||
} | ||
|
||
(new Foo).test(); |
3 changes: 3 additions & 0 deletions
3
...osal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/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 @@ | ||
{ | ||
"plugins": [["proposal-optional-chaining", { "loose": true }]] | ||
} |
34 changes: 34 additions & 0 deletions
34
...roposal-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/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,34 @@ | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
|
||
m() { | ||
return this.x; | ||
} | ||
|
||
getSelf() { | ||
return this; | ||
} | ||
|
||
test() { | ||
var _o$Foo$self$getSelf, _o$Foo, _o$Foo$self$getSelf2, _o$Foo$self; | ||
|
||
const Foo = this; | ||
const o = { | ||
Foo: Foo | ||
}; | ||
(Foo == null ? void 0 : Foo["m"].bind(Foo))(); | ||
(Foo == null ? void 0 : Foo["m"].bind(Foo))().toString; | ||
(Foo == null ? void 0 : Foo["m"].bind(Foo))().toString(); | ||
(o == null ? void 0 : o.Foo.m.bind(o.Foo))(); | ||
(o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString; | ||
(o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString(); | ||
((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) == null ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); | ||
((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) == null ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); | ||
} | ||
|
||
} | ||
|
||
new Foo().test(); |
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