-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
3 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
60 changes: 40 additions & 20 deletions
60
...plugin-proposal-optional-chaining/test/fixtures/general/parenthesized-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 |
---|---|---|
@@ -1,25 +1,45 @@ | ||
let count = 0; | ||
|
||
const foo = { | ||
get a() { | ||
count++; | ||
return { | ||
b() { | ||
return "b" in this && !("a" in this); | ||
} | ||
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; | ||
} | ||
}, | ||
b() { | ||
return "b" in this && "a" in this; | ||
|
||
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); | ||
} | ||
} | ||
|
||
expect((foo?.b)()).toBe(true); | ||
expect((foo?.b)?.()).toBe(true); | ||
expect(() => (undefined?.b)()).toThrow(); | ||
testNull() { | ||
const o = null; | ||
|
||
expect(() => { (o?.Foo.m)() }).toThrow(); | ||
expect(() => { (o?.Foo.m)().toString }).toThrow(); | ||
expect(() => { (o?.Foo.m)().toString() }).toThrow(); | ||
|
||
expect((foo?.a.b)()).toBe(true); | ||
expect(count).toBe(1); | ||
expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow(); | ||
expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow(); | ||
} | ||
} | ||
|
||
expect((foo?.a.b)?.()).toBe(true); | ||
expect(count).toBe(2); | ||
(new Foo).test(); | ||
(new Foo).testNull(); |
27 changes: 23 additions & 4 deletions
27
...lugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/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 |
---|---|---|
@@ -1,7 +1,26 @@ | ||
(foo?.bar)(); | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
m() { return this.x; }; | ||
getSelf() { return this } | ||
|
||
(foo?.bar)?.(); | ||
test() { | ||
const Foo = this; | ||
const o = { Foo: Foo }; | ||
|
||
(foo?.bar.baz)(); | ||
(Foo?.["m"])(); | ||
(Foo?.["m"])().toString; | ||
(Foo?.["m"])().toString(); | ||
|
||
(foo?.bar.baz)?.(); | ||
(o?.Foo.m)(); | ||
(o?.Foo.m)().toString; | ||
(o?.Foo.m)().toString(); | ||
|
||
(((o.Foo?.self.getSelf)())?.m)(); | ||
(((o.Foo.self?.getSelf)())?.m)(); | ||
} | ||
} | ||
|
||
(new Foo).test(); |
38 changes: 33 additions & 5 deletions
38
...ugin-proposal-optional-chaining/test/fixtures/general/parenthesized-member-call/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 |
---|---|---|
@@ -1,6 +1,34 @@ | ||
var _foo, _foo2, _foo2$bar, _foo3, _foo3$bar, _foo4, _foo4$bar$baz, _foo4$bar; | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.self = this; | ||
} | ||
|
||
((_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar.bind(_foo))(); | ||
(_foo2 = foo) === null || _foo2 === void 0 ? void 0 : (_foo2$bar = _foo2.bar) === null || _foo2$bar === void 0 ? void 0 : _foo2$bar.call(_foo2); | ||
((_foo3 = foo) === null || _foo3 === void 0 ? void 0 : (_foo3$bar = _foo3.bar).baz.bind(_foo3$bar))(); | ||
(_foo4 = foo) === null || _foo4 === void 0 ? void 0 : (_foo4$bar$baz = (_foo4$bar = _foo4.bar).baz) === null || _foo4$bar$baz === void 0 ? void 0 : _foo4$bar$baz.call(_foo4$bar); | ||
m() { | ||
return this.x; | ||
} | ||
|
||
getSelf() { | ||
return this; | ||
} | ||
|
||
test() { | ||
var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo4, _o$Foo4$self, _o$Foo$self$getSelf2, _o$Foo$self; | ||
|
||
const Foo = this; | ||
const o = { | ||
Foo: Foo | ||
}; | ||
(Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))(); | ||
(Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString; | ||
(Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString(); | ||
(o === null || o === void 0 ? void 0 : (_o$Foo = o.Foo).m.bind(_o$Foo))(); | ||
(o === null || o === void 0 ? void 0 : (_o$Foo2 = o.Foo).m.bind(_o$Foo2))().toString; | ||
(o === null || o === void 0 ? void 0 : (_o$Foo3 = o.Foo).m.bind(_o$Foo3))().toString(); | ||
((_o$Foo$self$getSelf = ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 ? void 0 : (_o$Foo4$self = _o$Foo4.self).getSelf.bind(_o$Foo4$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); | ||
((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); | ||
} | ||
|
||
} | ||
|
||
new Foo().test(); |