Files
test-repo/tests/format/js/babel-plugins/private-fields-in-in.js
T
09222ed6e8 Build(deps): Bump espree from 7.3.1 to 8.0.0 (#11162)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: fisker <lionkay@gmail.com>
Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
2021-07-07 18:53:09 +08:00

56 lines
847 B
JavaScript

// https://github.com/tc39/proposal-private-fields-in-in
class C {
#brand;
static isC(obj) {
try {
obj.#brand;
return true;
} catch {
return false;
}
}
}
class C2 {
#data = null; // populated later
get #getter() {
if (!this.#data) {
throw new Error('no data yet!');
}
return this.#data;
}
static isC(obj) {
try {
obj.#getter;
return true;
} catch {
return false; // oops! might have gotten here because `#getter` threw :-(
}
}
}
class C3 {
#brand;
#method() {}
get #getter() {}
static isC(obj) {
return #brand in obj && #method in obj && #getter in obj;
}
}
// Invalid https://github.com/tc39/proposal-private-fields-in-in#try-statement
// class C {
// #brand;
// static isC(obj) {
// return try obj.#brand;
// }
// }