From f9123cf6ec4b27c76831afed0f3864a3920e55c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 25 Feb 2021 16:41:01 -0500 Subject: [PATCH] add test cases --- .../access-before-declaration/exec.js | 29 +++++++++++++++++++ .../private/access-before-declaration/exec.js | 29 +++++++++++++++++++ .../access-before-declaration/exec.js | 29 +++++++++++++++++++ .../access-before-declaration/exec.js | 29 +++++++++++++++++++ .../access-before-declaration/exec.js | 29 +++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/access-before-declaration/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/access-before-declaration/exec.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/access-before-declaration/exec.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/access-before-declaration/exec.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/access-before-declaration/exec.js diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/access-before-declaration/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/access-before-declaration/exec.js new file mode 100644 index 000000000000..dc329788a1fa --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/access-before-declaration/exec.js @@ -0,0 +1,29 @@ +expect(() => { + class C { + static #_ = new C; + static #p; + constructor() { + C.#p; + } + } +}).toThrow(/attempted to use private field on non-instance/); + +expect(() => { + class C { + static #_ = new C; + static #p; + constructor() { + C.#p = 0; + } + } +}).toThrow(/attempted to use private field on non-instance/); + +expect(() => { + class C { + static #_ = new C; + static #p; + constructor() { + for (C.#p of [0]); + } + } +}).toThrow(/attempted to use private field on non-instance/); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/access-before-declaration/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/access-before-declaration/exec.js new file mode 100644 index 000000000000..e5c4a2f5a119 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/access-before-declaration/exec.js @@ -0,0 +1,29 @@ +expect(() => { + class C { + static #_ = new C; + static #p; + constructor() { + C.#p; + } + } +}).toThrow(/attempted to get private static field before its declaration/); + +expect(() => { + class C { + static #_ = new C; + static #p; + constructor() { + C.#p = 0; + } + } +}).toThrow(/attempted to set private static field before its declaration/); + +expect(() => { + class C { + static #_ = new C; + static #p; + constructor() { + for (C.#p of [0]); + } + } +}).toThrow(/attempted to set private static field before its declaration/); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/access-before-declaration/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/access-before-declaration/exec.js new file mode 100644 index 000000000000..792eaa32fe41 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/access-before-declaration/exec.js @@ -0,0 +1,29 @@ +expect(() => { + class C { + static #_ = new C; + static get #p() { return C }; + constructor() { + C.#p; + } + } +}).toThrow(/attempted to use private field on non-instance/); + +expect(() => { + class C { + static #_ = new C; + static set #p(v) {}; + constructor() { + C.#p = 0; + } + } +}).toThrow(/attempted to use private field on non-instance/); + +expect(() => { + class C { + static #_ = new C; + static set #p(v) {}; + constructor() { + for (C.#p of [0]); + } + } +}).toThrow(/attempted to use private field on non-instance/); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/access-before-declaration/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/access-before-declaration/exec.js new file mode 100644 index 000000000000..792eaa32fe41 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/access-before-declaration/exec.js @@ -0,0 +1,29 @@ +expect(() => { + class C { + static #_ = new C; + static get #p() { return C }; + constructor() { + C.#p; + } + } +}).toThrow(/attempted to use private field on non-instance/); + +expect(() => { + class C { + static #_ = new C; + static set #p(v) {}; + constructor() { + C.#p = 0; + } + } +}).toThrow(/attempted to use private field on non-instance/); + +expect(() => { + class C { + static #_ = new C; + static set #p(v) {}; + constructor() { + for (C.#p of [0]); + } + } +}).toThrow(/attempted to use private field on non-instance/); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/access-before-declaration/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/access-before-declaration/exec.js new file mode 100644 index 000000000000..6555875117e7 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/access-before-declaration/exec.js @@ -0,0 +1,29 @@ +expect(() => { + class C { + static #_ = new C; + static get #p() { return C }; + constructor() { + C.#p; + } + } +}).toThrow(/attempted to get private static field before its declaration/); + +expect(() => { + class C { + static #_ = new C; + static set #p(v) {}; + constructor() { + C.#p = 0; + } + } +}).toThrow(/attempted to set private static field before its declaration/); + +expect(() => { + class C { + static #_ = new C; + static set #p(v) {}; + constructor() { + for (C.#p of [0]); + } + } +}).toThrow(/attempted to set private static field before its declaration/);