Huáng Jùnliàng 5f83a8c1a2
Handle cases when ?? and ?. is in binding initializers (#12032)
* test: add test for nullish coalescing

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* test: add control group

* test: add tests for optional chaining

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* test: add tests on optional chaining mixed with private class elements

* fix: wrap member chains to IIFE when it is in parameter default

* chore: add more testcases

* chore: update test fixtures

* fix: NodePath.get is always non nullish

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-10-03 10:03:58 -04:00

47 lines
876 B
JavaScript

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;
}
function f(o, r = o?.Foo.#m()) {
return r;
}
function g(o, r = o?.Foo.#self.getSelf().#m()) {
return r;
}
function h(fnDeep, r = fnDeep?.().very.o?.Foo?.#m()) {
return r;
}
function i(fn, r = fn?.().Foo.#self?.getSelf()?.self.#m()) {
return r;
}
function j(fn, r = (fn().Foo.#self.getSelf().self.#m)?.()) {
return r;
}
expect(f(o)).toBe(1);
expect(g(o)).toBe(1);
expect(h(fnDeep)).toBe(1);
expect(i(fn)).toBe(1);
expect(j(fn)).toBe(1);
}
}
Foo.test();