From 3f7644823dd11a334f21e65b77a9a3098f89fd51 Mon Sep 17 00:00:00 2001 From: Chris Hewell Garrett Date: Sat, 27 Nov 2021 16:20:25 -0500 Subject: [PATCH 01/24] Adds the 2021-12 transform for decorators Implements the 2021-12 transform for the decorators proposal, with support for the `accessor` keyword. --- .../src/decorators.ts | 5 +- .../src/fields.ts | 7 +- .../src/index.ts | 4 +- .../babel-helpers/src/helpers-generated.ts | 4 + .../babel-helpers/src/helpers/applyDecs.js | 728 +++++++++++++ .../CONTRIB.md | 374 +++++++ .../package.json | 4 +- .../src/index.ts | 13 +- .../src/transformer-2021-12.ts | 987 ++++++++++++++++++ .../fixtures/2021-12-accessors/options.json | 11 + .../2021-12-accessors/private/exec.js | 54 + .../2021-12-accessors/private/input.js | 7 + .../2021-12-accessors/private/output.js | 59 ++ .../fixtures/2021-12-accessors/public/exec.js | 75 ++ .../2021-12-accessors/public/input.js | 10 + .../2021-12-accessors/public/output.js | 58 + .../2021-12-accessors/static-private/exec.js | 52 + .../2021-12-accessors/static-private/input.js | 7 + .../static-private/output.js | 58 + .../2021-12-accessors/static-public/exec.js | 70 ++ .../2021-12-accessors/static-public/input.js | 10 + .../2021-12-accessors/static-public/output.js | 52 + .../undecorated-private/exec.js | 31 + .../undecorated-private/input.js | 5 + .../undecorated-private/output.js | 45 + .../undecorated-public/exec.js | 27 + .../undecorated-public/input.js | 7 + .../undecorated-public/output.js | 47 + .../undecorated-static-private/exec.js | 29 + .../undecorated-static-private/input.js | 5 + .../undecorated-static-private/output.js | 34 + .../undecorated-static-public/exec.js | 22 + .../undecorated-static-public/input.js | 7 + .../undecorated-static-public/output.js | 39 + .../2021-12-classes/expressions/input.js | 11 + .../2021-12-classes/expressions/output.js | 51 + .../2021-12-classes/inheritance/exec.js | 18 + .../2021-12-classes/inheritance/input.js | 5 + .../2021-12-classes/inheritance/output.js | 25 + .../2021-12-classes/initializers/exec.js | 41 + .../2021-12-classes/initializers/input.js | 13 + .../2021-12-classes/initializers/output.js | 33 + .../fixtures/2021-12-classes/options.json | 11 + .../replacement-with-expr/exec.js | 17 + .../replacement-with-expr/input.js | 6 + .../replacement-with-expr/output.js | 13 + .../2021-12-classes/replacement/exec.js | 19 + .../2021-12-classes/replacement/input.js | 6 + .../2021-12-classes/replacement/output.js | 17 + .../computed-keys-same-ast/exec.js | 33 + .../computed-keys-same-ast/input.js | 11 + .../computed-keys-same-ast/output.js | 25 + .../computed-keys-same-value/exec.js | 29 + .../computed-keys-same-value/input.js | 11 + .../computed-keys-same-value/output.js | 25 + .../method-and-field/exec.js | 23 + .../method-and-field/input.js | 9 + .../method-and-field/output.js | 16 + .../methods-with-same-key/exec.js | 19 + .../methods-with-same-key/input.js | 11 + .../methods-with-same-key/output.js | 20 + .../2021-12-duplicated-keys/options.json | 11 + .../test/fixtures/2021-12-fields/options.json | 11 + .../fixtures/2021-12-fields/private/exec.js | 41 + .../fixtures/2021-12-fields/private/input.js | 7 + .../fixtures/2021-12-fields/private/output.js | 31 + .../fixtures/2021-12-fields/public/exec.js | 62 ++ .../fixtures/2021-12-fields/public/input.js | 10 + .../fixtures/2021-12-fields/public/output.js | 19 + .../2021-12-fields/static-private/exec.js | 39 + .../2021-12-fields/static-private/input.js | 7 + .../2021-12-fields/static-private/output.js | 24 + .../2021-12-fields/static-public/exec.js | 57 + .../2021-12-fields/static-public/input.js | 10 + .../2021-12-fields/static-public/output.js | 16 + .../2021-12-getters-and-setters/options.json | 11 + .../private/exec.js | 67 ++ .../private/input.js | 21 + .../private/output.js | 40 + .../public/exec.js | 88 ++ .../public/input.js | 23 + .../public/output.js | 37 + .../static-private/exec.js | 65 ++ .../static-private/input.js | 21 + .../static-private/output.js | 37 + .../static-public/exec.js | 87 ++ .../static-public/input.js | 23 + .../static-public/output.js | 35 + .../fixtures/2021-12-getters/options.json | 11 + .../fixtures/2021-12-getters/private/exec.js | 39 + .../fixtures/2021-12-getters/private/input.js | 12 + .../2021-12-getters/private/output.js | 30 + .../fixtures/2021-12-getters/public/exec.js | 50 + .../fixtures/2021-12-getters/public/input.js | 13 + .../fixtures/2021-12-getters/public/output.js | 26 + .../2021-12-getters/static-private/exec.js | 38 + .../2021-12-getters/static-private/input.js | 12 + .../2021-12-getters/static-private/output.js | 27 + .../2021-12-getters/static-public/exec.js | 48 + .../2021-12-getters/static-public/input.js | 13 + .../2021-12-getters/static-public/output.js | 24 + .../fixtures/2021-12-metadata/class/exec.js | 10 + .../getting-previously-set-metadata/exec.js | 30 + .../inheritance-private/exec.js | 16 + .../inheritance-public/exec.js | 18 + .../2021-12-metadata/non-symbol-keys/exec.js | 10 + .../fixtures/2021-12-metadata/options.json | 11 + .../2021-12-metadata/proto-private/exec.js | 11 + .../2021-12-metadata/proto-public/exec.js | 11 + .../2021-12-metadata/static-private/exec.js | 11 + .../2021-12-metadata/static-public/exec.js | 11 + .../fixtures/2021-12-methods/options.json | 11 + .../fixtures/2021-12-methods/private/exec.js | 41 + .../fixtures/2021-12-methods/private/input.js | 12 + .../2021-12-methods/private/output.js | 26 + .../fixtures/2021-12-methods/public/exec.js | 50 + .../fixtures/2021-12-methods/public/input.js | 13 + .../fixtures/2021-12-methods/public/output.js | 26 + .../2021-12-methods/static-private/exec.js | 39 + .../2021-12-methods/static-private/input.js | 12 + .../2021-12-methods/static-private/output.js | 22 + .../2021-12-methods/static-public/exec.js | 48 + .../2021-12-methods/static-public/input.js | 13 + .../2021-12-methods/static-public/output.js | 24 + .../2021-12-misc/initializer-timing/exec.js | 34 + .../test/fixtures/2021-12-misc/options.json | 11 + .../valid-expression-formats/input.js | 22 + .../valid-expression-formats/output.js | 40 + .../fixtures/2021-12-setters/options.json | 11 + .../fixtures/2021-12-setters/private/exec.js | 40 + .../fixtures/2021-12-setters/private/input.js | 12 + .../2021-12-setters/private/output.js | 30 + .../fixtures/2021-12-setters/public/exec.js | 50 + .../fixtures/2021-12-setters/public/input.js | 13 + .../fixtures/2021-12-setters/public/output.js | 26 + .../2021-12-setters/static-private/exec.js | 38 + .../2021-12-setters/static-private/input.js | 12 + .../2021-12-setters/static-private/output.js | 27 + .../2021-12-setters/static-public/exec.js | 49 + .../2021-12-setters/static-public/input.js | 13 + .../2021-12-setters/static-public/output.js | 24 + .../options.json | 8 + .../private/input.js | 7 + .../private/output.js | 35 + .../public/input.js | 10 + .../public/output.js | 42 + .../static-private/input.js | 7 + .../static-private/output.js | 38 + .../static-public/input.js | 10 + .../static-public/output.js | 45 + .../undecorated-private/input.js | 5 + .../undecorated-private/output.js | 22 + .../undecorated-public/input.js | 7 + .../undecorated-public/output.js | 32 + .../undecorated-static-private/input.js | 5 + .../undecorated-static-private/output.js | 22 + .../undecorated-static-public/input.js | 7 + .../undecorated-static-public/output.js | 32 + .../expressions/input.js | 11 + .../expressions/output.js | 87 ++ .../inheritance/input.js | 5 + .../inheritance/output.js | 25 + .../initializers/input.js | 13 + .../initializers/output.js | 30 + .../options.json | 8 + .../replacement-with-expr/input.js | 6 + .../replacement-with-expr/output.js | 13 + .../replacement/input.js | 6 + .../replacement/output.js | 16 + .../computed-keys-same-ast/input.js | 11 + .../computed-keys-same-ast/output.js | 25 + .../computed-keys-same-value/input.js | 11 + .../computed-keys-same-value/output.js | 25 + .../method-and-field/input.js | 9 + .../method-and-field/output.js | 13 + .../methods-with-same-key/input.js | 11 + .../methods-with-same-key/output.js | 20 + .../options.json | 8 + .../options.json | 8 + .../private/input.js | 7 + .../private/output.js | 17 + .../public/input.js | 10 + .../public/output.js | 15 + .../static-private/input.js | 7 + .../static-private/output.js | 17 + .../static-public/input.js | 10 + .../static-public/output.js | 15 + .../options.json | 8 + .../private/input.js | 21 + .../private/output.js | 34 + .../public/input.js | 23 + .../public/output.js | 37 + .../static-private/input.js | 21 + .../static-private/output.js | 32 + .../static-public/input.js | 23 + .../static-public/output.js | 35 + .../options.json | 8 + .../private/input.js | 12 + .../private/output.js | 24 + .../public/input.js | 13 + .../public/output.js | 26 + .../static-private/input.js | 12 + .../static-private/output.js | 22 + .../static-public/input.js | 13 + .../static-public/output.js | 24 + .../2021-12-transform-only-loose/options.json | 11 + .../input.js | 6 + .../output.js | 18 + .../super-in-private-accessor/input.js | 6 + .../super-in-private-accessor/output.js | 20 + .../super-in-private-method/input.js | 6 + .../super-in-private-method/output.js | 17 + .../options.json | 8 + .../private/input.js | 12 + .../private/output.js | 21 + .../public/input.js | 13 + .../public/output.js | 26 + .../static-private/input.js | 12 + .../static-private/output.js | 19 + .../static-public/input.js | 13 + .../static-public/output.js | 24 + .../2021-12-transform-only-misc/options.json | 8 + .../input.js | 7 + .../options.json | 3 + .../input.js | 7 + .../options.json | 3 + .../input.js | 7 + .../options.json | 3 + .../setting-private-method-via-rest/input.js | 7 + .../options.json | 3 + .../input.js | 7 + .../options.json | 3 + .../setting-private-method/input.js | 7 + .../setting-private-method/options.json | 3 + .../input.js | 6 + .../output.js | 18 + .../super-in-private-accessor/input.js | 6 + .../super-in-private-accessor/output.js | 20 + .../super-in-private-method/input.js | 6 + .../super-in-private-method/output.js | 17 + .../valid-expression-formats/input.js | 22 + .../valid-expression-formats/output.js | 33 + .../options.json | 8 + .../private/input.js | 12 + .../private/output.js | 24 + .../public/input.js | 13 + .../public/output.js | 26 + .../static-private/input.js | 12 + .../static-private/output.js | 22 + .../static-public/input.js | 13 + .../static-public/output.js | 24 + .../src/index.ts | 13 +- packages/babel-runtime-corejs2/package.json | 9 + packages/babel-runtime-corejs3/package.json | 9 + packages/babel-runtime/package.json | 9 + .../src/ast-types/generated/index.ts | 2 + .../src/builders/generated/index.ts | 2 + packages/babel-types/src/definitions/core.ts | 2 + yarn.lock | 2 + 259 files changed, 7438 insertions(+), 9 deletions(-) create mode 100644 packages/babel-helpers/src/helpers/applyDecs.js create mode 100644 packages/babel-plugin-proposal-decorators/CONTRIB.md create mode 100644 packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/class/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/getting-previously-set-metadata/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/non-symbol-keys/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initializer-timing/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index d4175e68a395..432439aed912 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -80,7 +80,10 @@ function extractElementDescriptor( const properties: t.ObjectExpression["properties"] = [ prop("kind", t.stringLiteral(t.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node as Decorable)), - prop("static", node.static && t.booleanLiteral(true)), + prop( + "static", + !t.isStaticBlock(node) && node.static && t.booleanLiteral(true), + ), prop("key", getKey(node)), ].filter(Boolean); diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index cbaee3f1ca2d..bebb6a107cc9 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -911,7 +911,7 @@ function replaceThisContext( getSuperRef, getObjectRef() { state.needsClassRef = true; - return isStaticBlock || path.node.static + return t.isStaticBlock(path.node) || path.node.static ? ref : t.memberExpression(ref, t.identifier("prototype")); }, @@ -931,7 +931,8 @@ function replaceThisContext( export type PropNode = | t.ClassProperty | t.ClassPrivateMethod - | t.ClassPrivateProperty; + | t.ClassPrivateProperty + | t.StaticBlock; export type PropPath = NodePath; export function buildFieldsInitNodes( @@ -963,7 +964,7 @@ export function buildFieldsInitNodes( for (const prop of props) { prop.isClassProperty() && ts.assertFieldTransformed(prop); - const isStatic = prop.node.static; + const isStatic = !t.isStaticBlock(prop.node) && prop.node.static; const isInstance = !isStatic; const isPrivate = prop.isPrivate(); const isPublic = !isPrivate; diff --git a/packages/babel-helper-create-class-features-plugin/src/index.ts b/packages/babel-helper-create-class-features-plugin/src/index.ts index 6e242a58c7c4..70da4597d09b 100644 --- a/packages/babel-helper-create-class-features-plugin/src/index.ts +++ b/packages/babel-helper-create-class-features-plugin/src/index.ts @@ -170,7 +170,7 @@ export function createClassFeaturePlugin({ path.isPrivate() || path.isStaticBlock?.() ) { - props.push(path); + props.push(path as PropPath); } } } @@ -246,7 +246,7 @@ export function createClassFeaturePlugin({ (referenceVisitor, state) => { if (isDecorated) return; for (const prop of props) { - if (prop.node.static) continue; + if (t.isStaticBlock(prop.node) || prop.node.static) continue; prop.traverse(referenceVisitor, state); } }, diff --git a/packages/babel-helpers/src/helpers-generated.ts b/packages/babel-helpers/src/helpers-generated.ts index 1f148f411cae..76bcc74b10f3 100644 --- a/packages/babel-helpers/src/helpers-generated.ts +++ b/packages/babel-helpers/src/helpers-generated.ts @@ -13,6 +13,10 @@ function helper(minVersion, source) { } export default Object.freeze({ + applyDecs: helper( + "7.16.6", + 'function createMetadataMethodsForProperty(metadataMap,kind,property){return{getMetadata(key){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0!==metadataForKey)if(1===kind){var pub=metadataForKey.public;if(void 0!==pub)return pub[property]}else if(2===kind){var priv=metadataForKey.private;if(void 0!==priv)return priv.get(property)}else if(Object.hasOwnProperty.call(metadataForKey,"constructor"))return metadataForKey.constructor},setMetadata(key,value){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0===metadataForKey&&(metadataForKey=metadataMap[key]={}),1===kind){var pub=metadataForKey.public;void 0===pub&&(pub=metadataForKey.public=Object.create(null)),pub[property]=value}else if(2===kind){var priv=metadataForKey.priv;void 0===priv&&(priv=metadataForKey.private=new Map),priv.set(property,value)}else metadataForKey.constructor=value}}}function convertMetadataMapToFinal(obj,metadataMap){var parentMetadataMap=obj[Symbol.metadata],metadataKeys=Object.getOwnPropertySymbols(metadataMap);if(0!==metadataKeys.length){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i 3; + + var isStatic = kind >= 5; /* STATIC */ + var base; + var metadataMap; + var initializers; + + if (isStatic) { + base = Class; + metadataMap = staticMetadataMap; + kind = kind - 5 /* STATIC */; + + if (!staticInitializers) { + staticInitializers = []; + } + + initializers = staticInitializers; + } else { + base = Class.prototype; + metadataMap = protoMetadataMap; + + if (!protoInitializers) { + protoInitializers = []; + } + + initializers = protoInitializers; + } + + if (kind !== 0 /* FIELD */ && !isPrivate) { + var existingNonFields = isStatic + ? existingStaticNonFields + : existingProtoNonFields; + + var existingKind = existingNonFields.get(name) || 0; + + if ( + existingKind === true || + (existingKind === 3 /* GETTER */ && kind !== 4) /* SETTER */ || + (existingKind === 4 /* SETTER */ && kind !== 3) /* GETTER */ + ) { + throw new Error( + "Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + + name + ); + } else if (!existingKind && kind > 2 /* METHOD */) { + existingNonFields.set(name, kind); + } else { + existingNonFields.set(name, true); + } + } + + applyMemberDec( + ret, + base, + decInfo, + name, + kind, + isStatic, + isPrivate, + metadataMap, + initializers + ); + } + + if (protoInitializers) { + pushInitializers(ret, protoInitializers); + } + + if (staticInitializers) { + pushInitializers(ret, staticInitializers); + } +} + +function pushInitializers(ret, initializers) { + if (initializers.length > 0) { + // Slice the array, which means that `addInitializer` can no longer add + // additional initializers to the array + initializers = initializers.slice(); + + ret.push(function (instance) { + for (var i = 0; i < initializers.length; i++) { + initializers[i].call(instance, instance); + } + }); + } else { + ret.push(function () {}); + } +} + +function applyClassDecs(ret, targetClass, metadataMap, classDecs) { + var initializers = []; + var newClass = targetClass; + + var name = targetClass.name; + var ctx = Object.assign( + { + kind: "class", + name: name, + addInitializer: createAddInitializerMethod(initializers), + }, + createMetadataMethodsForProperty(metadataMap, 0 /* CONSTRUCTOR */, name) + ); + + for (var i = 0; i < classDecs.length; i++) { + newClass = classDecs[i](newClass, ctx) || newClass; + } + + ret.push(newClass); + + if (initializers.length > 0) { + ret.push(function () { + for (var i = 0; i < initializers.length; i++) { + initializers[i].call(newClass, newClass); + } + }); + } else { + ret.push(function () {}); + } +} + +/** + Basic usage: + + applyDecs( + Class, + [ + // member decorators + [ + dec, // dec or array of decs + 0, // kind of value being decorated + 'prop', // name of public prop on class containing the value being decorated, + '#p', // the name of the private property (if is private, undefined otherwise), + ] + ], + [ + // class decorators + dec1, dec2 + ] + ) + ``` + + Fully transpiled example: + + ```js + @dec + class Class { + @dec + a = 123; + + @dec + #a = 123; + + @dec + @dec2 + accessor b = 123; + + @dec + accessor #b = 123; + + @dec + c() { console.log('c'); } + + @dec + #c() { console.log('privC'); } + + @dec + get d() { console.log('d'); } + + @dec + get #d() { console.log('privD'); } + + @dec + set e(v) { console.log('e'); } + + @dec + set #e(v) { console.log('privE'); } + } + + + // becomes + let initializeInstance; + let initializeClass; + + let initA; + let initPrivA; + + let initB; + let initPrivB, getPrivB, setPrivB; + + let privC; + let privD; + let privE; + + let Class; + class _Class { + static { + let ret = applyDecs( + this, + [ + [dec, 0, 'a'], + [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v], + [[dec, dec2], 1, 'b'], + [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v], + [dec, 2, 'c'], + [dec, 2, 'c', () => console.log('privC')], + [dec, 3, 'd'], + [dec, 3, 'd', () => console.log('privD')], + [dec, 4, 'e'], + [dec, 4, 'e', () => console.log('privE')], + ], + [ + dec + ] + ) + + initA = ret[0]; + + initPrivA = ret[1]; + + initB = ret[2]; + + initPrivB = ret[3]; + getPrivB = ret[4]; + setPrivB = ret[5]; + + privC = ret[6]; + + privD = ret[7]; + + privE = ret[8]; + + initializeInstance = ret[9]; + + Class = ret[10] + + initializeClass = ret[11]; + } + + a = (initializeInstance(this), initA(this, 123)); + + #a = initPrivA(this, 123); + + #bData = initB(this, 123); + get b() { return this.#bData } + set b(v) { this.#bData = v } + + #privBData = initPrivB(this, 123); + get #b() { return getPrivB(this); } + set #b(v) { setPrivB(this, v); } + + c() { console.log('c'); } + + #c(...args) { return privC(this, ...args) } + + get d() { console.log('d'); } + + get #d() { return privD(this); } + + set e(v) { console.log('e'); } + + set #e(v) { privE(this, v); } + } + + initializeClass(Class); + */ +export default function applyDecs(targetClass, memberDecs, classDecs) { + var ret = []; + var staticMetadataMap = {}; + + if (memberDecs) { + var protoMetadataMap = {}; + + applyMemberDecs( + ret, + targetClass, + protoMetadataMap, + staticMetadataMap, + memberDecs + ); + + convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap); + } + + if (classDecs) { + applyClassDecs(ret, targetClass, staticMetadataMap, classDecs); + } + + convertMetadataMapToFinal(targetClass, staticMetadataMap); + + return ret; +} diff --git a/packages/babel-plugin-proposal-decorators/CONTRIB.md b/packages/babel-plugin-proposal-decorators/CONTRIB.md new file mode 100644 index 000000000000..30c36983e1ce --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/CONTRIB.md @@ -0,0 +1,374 @@ +These are notes about the implementation of the 2021-12 decorators transform. +The implementation's goals are (in descending order): + +1. Being accurate to the actual proposal (e.g. not defining additional + properties unless required, matching semantics exactly, etc.). This includes + being able to work properly with private fields and methods. +2. Transpiling to a very minimal and minifiable output. This transform will + affect each and every decorated class, so ensuring that the output is not 10x + the size of the original is important. +3. Having good runtime performance. Decoration output has the potential to + drastically impact startup performance, since it runs whenever a decorated + class is defined. In addition, every instance of a decorated class may be + impacted for certain types of decorators. + +All of these goals come somewhat at the expense of readability and can make the +implementation difficult to understand, so these notes are meant to document the +motivations behind the design. + +## Overview + +Given a simple decorated class like this one: + +```js +@dec +class Class { + @dec a = 123; + + @dec static #b() { + console.log('foo'); + } + + [someVal]() {} + + @dec + @dec2 + accessor #c = 456; +} +``` + +It's output would be something like the following: + +```js +import { applyDecs } from '@babel/helpers'; + +let initInstance, initClass, initA, callB, computedKey, initC, getC, setC; + +const elementDecs = [ + [dec, 0, 'a'], + [dec, 7, 'x', '#b'] + (computedKey = someVal, null) + [[dec, dec2], 1, 'y', '#c'] +]; + +const classDecs = [dec]; + +let Class; +class _Class { + static { + let ret = applyDecs( + this, + elementDecs, + [dec] + ); + + initA = ret[0]; + callB = ret[1]; + initC = ret[2]; + getC = ret[3]; + setC = ret[4]; + initInstance = ret[5]; + Class = ret[6]; + initClass = ret[7]; + } + + a = (initInstance(this), initA(this, 123)); + + static #b(...args) { + callB(this, args); + } + static x() { + console.log('foo'); + } + + [computedKey]() {} + + #y = initC(this, 123); + get y() { + return this.#y; + } + set y(v) { + this.#y = v; + } + get #c() { + return getC(this); + } + set #c(v) { + setC(this, v); + } + + static { + initClass(C); + } +} +``` + +Let's break this output down a bit: + +```js +let initInstance, initClass, initA, callB, initC, getC, setC; +``` + +First, we need to setup some local variables outside of the class. These are +for: + +- Decorated class field/accessor initializers +- Extra initializer functions added by `addInitializers` +- Private class methods + +These are essentially all values that cannot be defined on the class itself via +`Object.defineProperty`, so we have to insert them into the class manually, +ahead of time and populate them when we run our decorators. + +```js +const elementDecs = [ + [dec, 0, 'a'], + [dec, 7, 'x', '#b'] + (computedKey = someVal, null) + [[dec, dec2], 1, 'y', '#c'] +]; + +const classDecs = [dec]; +``` + +Next up, we define and evaluate the decorator member expressions. The reason we +do this _before_ defining the class is because we must interleave decorator +expressions with computed property key expressions, since computed properties +and decorators can run arbitrary code which can modify the runtime of subsequent +decorators or computed property keys. + +```js +let Class; +class _Class { +``` + +This class is being decorated directly, which means that the decorator may +replace the class itself. Class bindings are not mutable, so we need to create a +new `let` variable for the decorated class. + + +```js + static { + let ret = applyDecs( + this, + elementDecs, + classDecs + ); + + initA = ret[0]; + callB = ret[1]; + initC = ret[2]; + getC = ret[3]; + setC = ret[4]; + initInstance = ret[5]; + Class = ret[6]; + initClass = ret[7]; + } +``` + +Next, we immediately define a `static` block which actually applies the +decorators. This is important because we must apply the decorators _after_ the +class prototype has been fully setup, but _before_ static fields are run, since +static fields should only see the decorated version of the class. + +We apply the decorators to class elements and the class itself, and the +application returns an array of values that are used to populate all of the +local variables we defined earlier. The array's order is fully deterministic, so +we can assign the values based on an index we can calculate ahead of time. + +We'll come back to `applyDecs` in a bit to dig into what its format is exactly, +but now let's dig into the new definitions of our class elements. + +```js + a = (initInstance(this), initA(this, 123)); +``` + +Alright, so previously this was a simple class field. Since it's the first field +on the class, we've updated it to immediately call `initInstance` in its +initializer. This calls any initializers added with `addInitializer` for all of +the per-class values (methods and accessors), which should all be setup on the +instance before class fields are assigned. Then, it calls `initA` to get the +initial value of the field, which allows initializers returned from the +decorator to intercept and decorate it. It's important that the initial value +is used/defined _within_ the class body, because initializers can now refer to +private class fields, e.g. `a = this.#b` is a valid field initializer and would +become `a = initA(this, this.#b)`, which would also be valid. We cannot +extract initializer code, or any other code, from the class body because of +this. + +Overall, this decoration is pretty straightforward other than the fact that we +have to reference `initA` externally. + +```js + static #b(...args) { + callB(this, args); + } + static x() { + console.log('foo'); + } +``` + +Next up, we have a private static class method `#b`. This one is a bit more +complex, as our definition has been broken out into 2 parts: + +1. `static #b`: This is the method itself, which being a private method we + cannot overwrite with `defineProperty`. We also can't convert it into a + private field because that would change its semantics (would make it + writable). So, we instead have it proxy to the locally scoped `callB` + variable, which will be populated with the fully decorated method. +2. `static x`: This contains the _code_ of the original method. Once again, this + code cannot be removed from the class body because it may reference private + identifiers. However, we have moved the code to a _public_ method, which means + we can now read its value using `Object.getOwnPropertyDescriptor`. Decorators + use this to get the initial implementation of the method, which can then be + wrapped with decorator code/logic. They then `delete` this temporary property, + which is necessary because no additional elements should be added to a class + definition. + + The name for this method is unimportant, but because public method names + cannot be minified and we also need to pass the name into `applyDecs`, we + generate as small of a unique identifier as possible here, starting with 1 + char names which are not taken and growing until we find one that is free. + +```js + [computedKey]() {} +``` + +Next is the undecorated method with a computed key. This uses the previously +calculated and stored computed key. + +```js + #y = initC(this, 123); + get y() { + return this.#y; + } + set y(v) { + this.#y = v; + } + get #c() { + return getC(this); + } + set #c(v) { + setC(this, v); + } +``` + +Next up, we have the output for `accessor #c`. This is the most complicated +case, since we have to transpile the decorators, the `accessor` keyword, and +target a private field. Breaking it down piece by piece: + +```js + #y = initC(this, 123); +``` + +`accessor #c` desugars to a getter and setter which are backed by a new private +field, `#y`. Like before, the name of this field doesn't really matter, we'll +just generate a short, unique name. We call the decorated initializer for `#c` +and return that value to assign to the field. + +```js + get y() { + return this.#y; + } + set y(v) { + this.#y = v; + } +``` + +Next we have a getter and setter named `y` which provide access to the backing +storage for the accessor. These are the base getter/setter for the accessor, +which the decorator will get via `Object.getOwnPropertyDescriptor`. They will be +deleted from the class fully, so again the name is not important here, just +needs to be short. + +```js + get #c() { + return getC(this); + } + set #c(v) { + setC(this, v); + } +``` + +Next, we have the getter and setter for `#c` itself. These methods defer to +the `getC` and `setC` local variables, which will be the decorated versions of +the `get y` and `set y` methods from the previous step. + +```js + static { + initClass(C); + } +``` + +Finally, we call `initClass` in another static block, running any class and +static method initializers on the final class. This is done in a static block +for convenience with class expressions, but it could run immediately after the +class is defined. + +Ok, so now that we understand the general output, let's go back to `applyDecs`: + +```js +const elementDecs = [ + [dec, 0, 'a'], + [dec, 7, 'x', '#b'] + (computedKey = someVal, null) + [[dec, dec2], 1, 'y', '#c'] +]; + +const classDecs = [dec]; + +// ... + +let ret = applyDecs( + this, + elementDecs, + classDecs +); +``` + +`applyDecs` takes all of the decorators for the class and applies them. It +receives the following arguments: + +1. The class itself +2. Decorators to apply to class elements +3. Decorators to apply to the class itself + +The format of the data is designed to be as minimal as possible. Here's an +annotated version of the member descriptors: + +```js +[ + // List of decorators to apply to the field. Array if multiple decorators, + // otherwise just the single decorator itself. + dec, + + // The type of the decorator, represented as an enum. Static-ness is also + // encoded by adding 5 to the values + // 0 === FIELD + // 1 === ACCESSOR + // 2 === METHOD + // 3 === GETTER + // 4 === SETTER + // 5 === FIELD + STATIC + // 6 === ACCESSOR + STATIC + // 7 === METHOD + STATIC + // 8 === GETTER + STATIC + // 9 === SETTER + STATIC + 1, + + // The name of the public property that can be used to access the value. + // For public members this is the actual name, for private members this is + // the name of the public property which can be used to access the value + // (see descriptions of #b and #c above) + 'y', + + // Optional fourth value, this is the spelling of the private element's name, + // which signals that the element is private to `applyDecs` and is used in the + // decorator's context object + '#c' +], +``` + +Static and prototype decorators are all described like this. For class +decorators, it's just the list of decorators since no other context +is necessary. diff --git a/packages/babel-plugin-proposal-decorators/package.json b/packages/babel-plugin-proposal-decorators/package.json index 6e5f4128b1b4..565234dd6fa8 100644 --- a/packages/babel-plugin-proposal-decorators/package.json +++ b/packages/babel-plugin-proposal-decorators/package.json @@ -22,7 +22,9 @@ "dependencies": { "@babel/helper-create-class-features-plugin": "workspace:^", "@babel/helper-plugin-utils": "workspace:^", - "@babel/plugin-syntax-decorators": "workspace:^" + "@babel/helper-replace-supers": "workspace:^", + "@babel/plugin-syntax-decorators": "workspace:^", + "charcodes": "^0.2.0" }, "peerDependencies": { "@babel/core": "^7.0.0-0" diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index a7e142769038..ddf98ea99e76 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -7,6 +7,7 @@ import { FEATURES, } from "@babel/helper-create-class-features-plugin"; import legacyVisitor from "./transformer-legacy"; +import transformer2021_12 from "./transformer-2021-12"; export default declare((api, options) => { api.assertVersion(7); @@ -16,7 +17,7 @@ export default declare((api, options) => { throw new Error("'legacy' must be a boolean."); } - const { decoratorsBeforeExport } = options; + const { decoratorsBeforeExport, version } = options; if (decoratorsBeforeExport === undefined) { if (!legacy) { throw new Error( @@ -37,6 +38,10 @@ export default declare((api, options) => { } if (legacy) { + if (version !== undefined) { + throw new Error("'version' can't be used with legacy decorators"); + } + return { name: "proposal-decorators", inherits: syntaxDecorators, @@ -47,6 +52,12 @@ export default declare((api, options) => { }; } + if (version === "2021-12") { + return transformer2021_12(api, options); + } else if (!(version === "2018-09" || version === undefined)) { + throw new Error("Unsupported decorators version: " + version); + } + return createClassFeaturePlugin({ name: "proposal-decorators", diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts new file mode 100644 index 000000000000..e962011267d7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -0,0 +1,987 @@ +import type { NodePath } from "@babel/traverse"; +import { types as t } from "@babel/core"; +import syntaxDecorators from "@babel/plugin-syntax-decorators"; +import ReplaceSupers from "@babel/helper-replace-supers"; +import * as charCodes from "charcodes"; + +type ClassDecoratableElement = + | t.ClassMethod + | t.ClassPrivateMethod + | t.ClassProperty + | t.ClassPrivateProperty + | t.ClassAccessorProperty; + +type ClassElement = + | ClassDecoratableElement + | t.TSDeclareMethod + | t.TSIndexSignature + | t.StaticBlock; + +type classUidGenerator = ( + isPrivate: B, +) => B extends true ? t.PrivateName : t.Identifier; + +function incrementId(id: number[], idx = id.length - 1): void { + // If index is -1, id needs an additional character, unshift A + if (idx === -1) { + id.unshift(charCodes.uppercaseA); + return; + } + + const current = id[idx]; + + if (current === charCodes.uppercaseZ) { + // if current is Z, skip to a + id[idx] = charCodes.lowercaseA; + } else if (current === charCodes.lowercaseZ) { + // if current is z, reset to A and carry the 1 + id[idx] = charCodes.uppercaseA; + incrementId(id, idx - 1); + } else { + // else, increment by one + id[idx] = current + 1; + } +} + +/** + * Generates a new element name that is unique to the given class. This can be + * used to create extra class fields and methods for the implementation, while + * keeping the length of those names as small as possible. This is important for + * minification purposes, since public names cannot be safely renamed/minified. + * + * Names are split into two namespaces, public and private. Static and non-static + * names are shared in the same namespace, because this is true for private names + * (you cannot have #x and static #x in the same class) and it's not worth the + * extra complexity for public names. + */ +function createUidGeneratorForClass( + body: NodePath[], +): (isPrivate: boolean) => t.Identifier | t.PrivateName { + let currentPublicId: number[], currentPrivateId: number[]; + + const publicNames = new Set(); + const privateNames = new Set(); + + for (const element of body) { + if ( + element.node.type === "TSIndexSignature" || + element.node.type === "StaticBlock" + ) { + continue; + } + + const { key } = element.node; + + if (key.type === "PrivateName") { + privateNames.add(key.id.name); + } else if (key.type === "Identifier") { + publicNames.add(key.name); + } + } + + return (isPrivate: boolean): t.Identifier | t.PrivateName => { + let currentId: number[], names: Set; + + if (isPrivate) { + if (!currentPrivateId) { + currentPrivateId = [charCodes.uppercaseA]; + } + + currentId = currentPrivateId; + names = privateNames; + } else { + if (!currentPublicId) { + currentPublicId = [charCodes.uppercaseA]; + } + + currentId = currentPublicId; + names = publicNames; + } + + let reifiedId = String.fromCharCode(...currentId); + + while (names.has(reifiedId)) { + incrementId(currentId); + reifiedId = String.fromCharCode(...currentId); + } + + incrementId(currentId); + + if (isPrivate) { + return t.privateName(t.identifier(reifiedId)); + } else { + return t.identifier(reifiedId); + } + }; +} + +/** + * Wraps the above generator function so that it's run lazily the first time + * it's actually required. Several types of decoration do not require this, so it + * saves iterating the class elements an additional time and allocating the space + * for the Sets of element names. + */ +function createLazyUidGeneratorForClass( + body: NodePath[], +): classUidGenerator { + let generator: (isPrivate: boolean) => t.Identifier | t.PrivateName; + + const lazyGenerator = (isPrivate: boolean): t.Identifier | t.PrivateName => { + if (!generator) { + generator = createUidGeneratorForClass(body); + } + + return generator(isPrivate); + }; + + return lazyGenerator as unknown as classUidGenerator; +} + +/** + * Takes a class definition and replaces it with an equivalent class declaration + * which is then assigned to a local variable. This allows us to reassign the + * local variable with the decorated version of the class. The class definition + * retains its original name so that `toString` is not affected, other + * references to the class are renamed instead. + */ +function replaceClassWithVar( + path: NodePath, +): [t.Identifier, NodePath] { + if (path.type === "ClassDeclaration") { + const varId = path.scope.generateUidIdentifierBasedOnNode(path.node.id); + const classId = t.identifier(path.node.id.name); + + path.scope.rename(classId.name, varId.name); + + path.insertBefore( + t.variableDeclaration("let", [t.variableDeclarator(varId)]), + ); + path.get("id").replaceWith(classId); + + return [t.cloneNode(varId), path]; + } else { + let className: string; + let varId: t.Identifier; + + if (path.node.id) { + className = path.node.id.name; + varId = generateLocalVarId(path, className); + path.scope.rename(className, varId.name); + } else if ( + path.parentPath.node.type === "VariableDeclarator" && + path.parentPath.node.id.type === "Identifier" + ) { + className = path.parentPath.node.id.name; + varId = generateLocalVarId(path, className); + } else { + varId = generateLocalVarId(path, "decorated_class"); + } + + const newClassExpr = t.classExpression( + className && t.identifier(className), + path.node.superClass, + path.node.body, + ); + + const [newPath] = path.replaceWith( + t.sequenceExpression([newClassExpr, varId]), + ); + + return [t.cloneNode(varId), newPath.get("expressions.0")]; + } +} + +function generateClassProperty( + key: t.PrivateName | t.Identifier, + value: t.Expression | undefined, + isStatic: boolean, +): t.ClassPrivateProperty | t.ClassProperty { + if (key.type === "PrivateName") { + return t.classPrivateProperty(key, value, undefined, isStatic); + } else { + return t.classProperty(key, value, undefined, undefined, isStatic); + } +} + +function addProxyAccessorsFor( + element: NodePath, + originalKey: t.PrivateName | t.Expression, + targetKey: t.PrivateName, + isComputed = false, +): void { + const { static: isStatic } = element.node; + + const getterBody = t.blockStatement([ + t.returnStatement( + t.memberExpression(t.thisExpression(), t.cloneNode(targetKey)), + ), + ]); + + const setterBody = t.blockStatement([ + t.expressionStatement( + t.assignmentExpression( + "=", + t.memberExpression(t.thisExpression(), t.cloneNode(targetKey)), + t.identifier("v"), + ), + ), + ]); + + let getter: t.ClassMethod | t.ClassPrivateMethod, + setter: t.ClassMethod | t.ClassPrivateMethod; + + if (originalKey.type === "PrivateName") { + getter = t.classPrivateMethod( + "get", + t.cloneNode(originalKey), + [], + getterBody, + isStatic, + ); + setter = t.classPrivateMethod( + "set", + t.cloneNode(originalKey), + [t.identifier("v")], + setterBody, + isStatic, + ); + } else { + getter = t.classMethod( + "get", + t.cloneNode(originalKey), + [], + getterBody, + isComputed, + isStatic, + ); + setter = t.classMethod( + "set", + t.cloneNode(originalKey), + [t.identifier("v")], + setterBody, + isComputed, + isStatic, + ); + } + + element.insertAfter(setter); + element.insertAfter(getter); +} + +function extractProxyAccessorsFor( + targetKey: t.PrivateName, +): t.FunctionExpression[] { + return [ + t.functionExpression( + undefined, + [], + t.blockStatement([ + t.returnStatement( + t.memberExpression(t.thisExpression(), t.cloneNode(targetKey)), + ), + ]), + ), + t.functionExpression( + undefined, + [t.identifier("value")], + t.blockStatement([ + t.expressionStatement( + t.assignmentExpression( + "=", + t.memberExpression(t.thisExpression(), t.cloneNode(targetKey)), + t.identifier("value"), + ), + ), + ]), + ), + ]; +} + +const FIELD = 0; +const ACCESSOR = 1; +const METHOD = 2; +const GETTER = 3; +const SETTER = 4; + +const STATIC = 5; + +function getElementKind(element: NodePath): number { + switch (element.node.type) { + case "ClassProperty": + case "ClassPrivateProperty": + return FIELD; + case "ClassAccessorProperty": + return ACCESSOR; + case "ClassMethod": + case "ClassPrivateMethod": + if (element.node.kind === "get") { + return GETTER; + } else if (element.node.kind === "set") { + return SETTER; + } else { + return METHOD; + } + } +} + +function generateLocalVarId(path: NodePath, name: string): t.Identifier { + const varId = path.scope.generateUidIdentifier(name); + path.scope.parent.push({ id: varId }); + return t.cloneNode(varId); +} + +// Information about the decorators applied to an element +interface DecoratorInfo { + // The expressions of the decorators themselves + decorators: t.Expression[]; + + // The kind of the decorated value, matches the kind value passed to applyDecs + kind: number; + + // whether or not the field is static + isStatic: boolean; + + // The name of the decorator + name: t.StringLiteral | t.Expression; + + privateMethods: t.FunctionExpression | t.FunctionExpression[] | undefined; + + // The names of local variables that will be used/returned from the decoration + locals: t.Identifier | t.Identifier[] | undefined; +} + +// Information about a computed property key. These must be evaluated +// interspersed with decorator expressions, which is why they get added to the +// array of DecoratorInfos later on. +interface ComputedPropInfo { + localComputedNameId: t.Identifier; + keyNode: t.Expression; +} + +function isDecoratorInfo( + info: DecoratorInfo | ComputedPropInfo, +): info is DecoratorInfo { + return "decorators" in info; +} + +function generateDecorationExprs( + info: (DecoratorInfo | ComputedPropInfo)[], +): t.ArrayExpression { + return t.arrayExpression( + info.filter(isDecoratorInfo).map(el => { + const decs = + el.decorators.length > 1 + ? t.arrayExpression(el.decorators) + : el.decorators[0]; + + const kind = el.isStatic ? el.kind + STATIC : el.kind; + + const decInfo = [decs, t.numericLiteral(kind), el.name]; + + const { privateMethods } = el; + + if (Array.isArray(privateMethods)) { + decInfo.push(...privateMethods); + } else if (privateMethods) { + decInfo.push(privateMethods); + } + + return t.arrayExpression(decInfo); + }), + ); +} + +function extractElementLocalAssignments( + decorationInfo: (DecoratorInfo | ComputedPropInfo)[], +) { + const locals: t.Identifier[] = []; + + for (const el of decorationInfo) { + if ("locals" in el && el.locals) { + if (Array.isArray(el.locals)) { + locals.push(...el.locals); + } else { + locals.push(el.locals); + } + } + } + + return locals; +} + +function addCallAccessorsFor( + element: NodePath, + key: t.PrivateName, + getId: t.Identifier, + setId: t.Identifier, +) { + element.insertAfter( + t.classPrivateMethod( + "get", + t.cloneNode(key), + [], + t.blockStatement([ + t.expressionStatement( + t.callExpression(t.cloneNode(getId), [t.thisExpression()]), + ), + ]), + ), + ); + + element.insertAfter( + t.classPrivateMethod( + "set", + t.cloneNode(key), + [t.identifier("v")], + t.blockStatement([ + t.expressionStatement( + t.callExpression(t.cloneNode(setId), [ + t.thisExpression(), + t.identifier("v"), + ]), + ), + ]), + ), + ); +} + +function isNotTsParameter( + node: t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty, +): node is t.Identifier | t.Pattern | t.RestElement { + return node.type !== "TSParameterProperty"; +} + +function movePrivateAccessor( + element: NodePath, + key: t.PrivateName, + methodLocalVar: t.Identifier, + isStatic: boolean, +) { + let params: (t.Identifier | t.RestElement)[]; + let block: t.Statement[]; + + if (element.node.kind === "set") { + params = [t.identifier("v")]; + block = [ + t.expressionStatement( + t.callExpression(methodLocalVar, [ + t.thisExpression(), + t.identifier("v"), + ]), + ), + ]; + } else { + params = []; + block = [ + t.returnStatement(t.callExpression(methodLocalVar, [t.thisExpression()])), + ]; + } + + element.replaceWith( + t.classPrivateMethod( + element.node.kind, + t.cloneNode(key), + params, + t.blockStatement(block), + isStatic, + ), + ); +} + +function isClassDecoratableElementPath( + path: NodePath, +): path is NodePath { + const { type } = path; + + return ( + type !== "TSDeclareMethod" && + type !== "TSIndexSignature" && + type !== "StaticBlock" + ); +} + +function transformClass( + path: NodePath, + state: any, + constantSuper: boolean, +): NodePath { + const body = path.get("body.body"); + + const classDecorators = path.node.decorators; + let hasElementDecorators = false; + + const generateClassUid = createLazyUidGeneratorForClass(body); + + // Iterate over the class to see if we need to decorate it, and also to + // transform simple auto accessors which are not decorated + for (const element of body) { + if (!isClassDecoratableElementPath(element)) { + continue; + } + + if (element.node.decorators) { + hasElementDecorators = true; + } else if (element.node.type === "ClassAccessorProperty") { + const { key, value, static: isStatic } = element.node; + + const newId = generateClassUid(true); + + const valueNode = value ? t.cloneNode(value) : undefined; + + const newField = generateClassProperty(newId, valueNode, isStatic); + + const [newPath] = element.replaceWith(newField); + addProxyAccessorsFor(newPath, key, newId, element.node.computed); + } + } + + // If nothing is decorated, return + if (!classDecorators && !hasElementDecorators) return; + + const elementDecoratorInfo: (DecoratorInfo | ComputedPropInfo)[] = []; + + let firstFieldPath: + | NodePath + | undefined; + let constructorPath: NodePath | undefined; + let requiresProtoInit = false; + let requiresStaticInit = false; + let hasComputedProps = false; + const decoratedPrivateMethods = new Set(); + + let protoInitLocal: t.Identifier, + staticInitLocal: t.Identifier, + classInitLocal: t.Identifier, + classLocal: t.Identifier; + + if (classDecorators) { + classInitLocal = generateLocalVarId(path, "initClass"); + + const [localId, classPath] = replaceClassWithVar(path); + path = classPath; + classLocal = localId; + + path.node.decorators = null; + } else { + if (!path.node.id) { + path.node.id = path.scope.generateUidIdentifier("Class"); + } + classLocal = t.cloneNode(path.node.id); + } + + if (hasElementDecorators) { + for (const element of body) { + if (!isClassDecoratableElementPath(element)) { + continue; + } + + let { key } = element.node; + const kind = getElementKind(element); + const decorators = element.get("decorators"); + + const isPrivate = key.type === "PrivateName"; + const isComputed = + "computed" in element.node && element.node.computed === true; + const isStatic = !!element.node.static; + + let name = "computedKey"; + + if (isPrivate) { + name = (key as t.PrivateName).id.name; + } else if (key.type === "Identifier") { + name = key.name; + } + + if ( + element.node.type === "ClassMethod" && + element.node.kind === "constructor" + ) { + constructorPath = element as NodePath; + } + + if (isComputed) { + const keyPath = element.get("key"); + const localComputedNameId = generateLocalVarId(keyPath, name); + keyPath.replaceWith(localComputedNameId); + + elementDecoratorInfo.push({ + localComputedNameId: t.cloneNode(localComputedNameId), + keyNode: t.cloneNode(key as t.Expression), + }); + + key = localComputedNameId; + hasComputedProps = true; + } + + if (Array.isArray(decorators)) { + let locals: t.Identifier | t.Identifier[]; + let privateMethods: t.FunctionExpression | t.FunctionExpression[]; + + if (kind === ACCESSOR) { + const { value } = element.node as t.ClassAccessorProperty; + + const params: t.Expression[] = [t.thisExpression()]; + + if (value) { + params.push(t.cloneNode(value)); + } + + const newId = generateClassUid(true); + const newFieldInitId = generateLocalVarId(element, `init_${name}`); + const newValue = t.callExpression( + t.cloneNode(newFieldInitId), + params, + ); + + const newField = generateClassProperty(newId, newValue, isStatic); + const [newPath] = element.replaceWith(newField); + + if (isPrivate) { + privateMethods = extractProxyAccessorsFor(newId); + + const getId = generateLocalVarId(newPath, `get_${name}`); + const setId = generateLocalVarId(newPath, `set_${name}`); + + addCallAccessorsFor(newPath, key as t.PrivateName, getId, setId); + + locals = [newFieldInitId, getId, setId]; + } else { + addProxyAccessorsFor(newPath, key, newId, isComputed); + locals = newFieldInitId; + } + } else if (kind === FIELD) { + const initId = generateLocalVarId(element, `init_${name}`); + const valuePath = ( + element as NodePath + ).get("value"); + + valuePath.replaceWith( + t.callExpression( + t.cloneNode(initId), + [t.thisExpression(), valuePath.node].filter(v => v), + ), + ); + + locals = initId; + + if (isPrivate) { + privateMethods = extractProxyAccessorsFor(key as t.PrivateName); + } + } else if (isPrivate) { + locals = generateLocalVarId(element, `call_${name}`); + + const replaceSupers = new ReplaceSupers({ + constantSuper, + methodPath: element, + objectRef: classLocal, + superRef: path.node.superClass, + file: state, + refToPreserve: classLocal, + }); + + replaceSupers.replace(); + + const { + params, + body, + async: isAsync, + } = element.node as t.ClassPrivateMethod; + + privateMethods = t.functionExpression( + undefined, + params.filter(isNotTsParameter), + body, + isAsync, + ); + + if (kind === GETTER || kind === SETTER) { + movePrivateAccessor( + element as NodePath, + t.cloneNode(key as t.PrivateName), + t.cloneNode(locals), + isStatic, + ); + } else { + const node = element.node as t.ClassPrivateMethod; + + // Unshift + path.node.body.body.unshift( + t.classPrivateProperty( + key as t.PrivateName, + t.cloneNode(locals), + [], + node.static, + ), + ); + + decoratedPrivateMethods.add((key as t.PrivateName).id.name); + + element.remove(); + } + } + + let nameExpr: t.Expression; + + if (isComputed) { + nameExpr = t.cloneNode(key as t.Expression); + } else if (key.type === "PrivateName") { + nameExpr = t.stringLiteral(key.id.name); + } else if (key.type === "Identifier") { + nameExpr = t.stringLiteral(key.name); + } else { + nameExpr = t.cloneNode(key as t.Expression); + } + + elementDecoratorInfo.push({ + kind, + decorators: decorators.map(d => d.node.expression), + name: nameExpr, + isStatic, + privateMethods, + locals, + }); + + if (kind !== FIELD) { + if (isStatic) { + requiresStaticInit = true; + } else { + requiresProtoInit = true; + } + } + + if (element.node) { + element.node.decorators = null; + } + + if (!firstFieldPath && (kind === FIELD || kind === ACCESSOR)) { + firstFieldPath = element as NodePath< + t.ClassProperty | t.ClassPrivateProperty + >; + } + } + } + } + + if (hasComputedProps) { + const assignments: t.AssignmentExpression[] = []; + + for (const info of elementDecoratorInfo) { + if (isDecoratorInfo(info)) { + const { decorators } = info; + const newDecorators: t.Identifier[] = []; + + for (const decorator of decorators) { + const localComputedNameId = generateLocalVarId(path, "dec"); + assignments.push( + t.assignmentExpression("=", localComputedNameId, decorator), + ); + newDecorators.push(t.cloneNode(localComputedNameId)); + } + + info.decorators = newDecorators; + } else { + assignments.push( + t.assignmentExpression("=", info.localComputedNameId, info.keyNode), + ); + } + } + + path.insertBefore(assignments); + } + + const elementDecorations = generateDecorationExprs(elementDecoratorInfo); + const classDecorations = t.arrayExpression( + (classDecorators || []).map(d => d.expression), + ); + + const locals: t.Identifier[] = + extractElementLocalAssignments(elementDecoratorInfo); + + if (classDecorators) { + locals.push(classLocal, classInitLocal); + } + + if (requiresProtoInit) { + protoInitLocal = generateLocalVarId(path, "initProto"); + locals.push(protoInitLocal); + + const protoInitCall = t.callExpression(t.cloneNode(protoInitLocal), [ + t.thisExpression(), + ]); + + if (firstFieldPath) { + const value = firstFieldPath.get("value"); + const body: t.Expression[] = [protoInitCall]; + + if (value.node) { + body.push(value.node); + } + + value.replaceWith(t.sequenceExpression(body)); + } else if (constructorPath) { + if (path.node.superClass) { + let found = false; + + path.traverse({ + Super(path) { + const { parentPath } = path; + + if (found || parentPath.node.type !== "CallExpression") return; + + found = true; + + const prop = generateLocalVarId(path, "super"); + parentPath.replaceWith( + t.sequenceExpression([ + t.assignmentExpression("=", t.cloneNode(prop), parentPath.node), + protoInitCall, + t.cloneNode(prop), + ]), + ); + }, + }); + } else { + constructorPath.node.body.body.unshift( + t.expressionStatement(protoInitCall), + ); + } + } else { + const body: t.Statement[] = [t.expressionStatement(protoInitCall)]; + + if (path.node.superClass) { + body.unshift( + t.expressionStatement( + t.callExpression(t.super(), [ + t.spreadElement(t.identifier("args")), + ]), + ), + ); + } + + path.node.body.body.unshift( + t.classMethod( + "constructor", + t.identifier("constructor"), + [t.restElement(t.identifier("args"))], + t.blockStatement(body), + ), + ); + } + } + + if (requiresStaticInit) { + staticInitLocal = generateLocalVarId(path, "initStatic"); + locals.push(staticInitLocal); + } + + const staticBlock = t.staticBlock( + [ + t.expressionStatement( + t.assignmentExpression( + "=", + t.arrayPattern(locals), + t.callExpression(state.addHelper("applyDecs"), [ + t.thisExpression(), + elementDecorations, + classDecorations, + ]), + ), + ), + requiresStaticInit && + t.expressionStatement( + t.callExpression(t.cloneNode(staticInitLocal), [t.thisExpression()]), + ), + ].filter(v => v), + ); + + path.node.body.body.unshift(staticBlock as unknown as ClassElement); + + if (classInitLocal) { + path.node.body.body.push( + t.staticBlock([ + t.expressionStatement( + t.callExpression(t.cloneNode(classInitLocal), []), + ), + ]), + ); + } + + if (decoratedPrivateMethods.size > 0) { + path.traverse({ + PrivateName(path) { + if (!decoratedPrivateMethods.has(path.node.id.name)) return; + + const parentPath = path.parentPath; + const parentParentPath = parentPath.parentPath; + + if ( + // this.bar().#x = 123; + (parentParentPath.node.type === "AssignmentExpression" && + parentParentPath.node.left === parentPath.node) || + // this.#x++; + parentParentPath.node.type === "UpdateExpression" || + // ([...this.#x] = foo); + parentParentPath.node.type === "RestElement" || + // ([this.#x] = foo); + parentParentPath.node.type === "ArrayPattern" || + // ({ a: this.#x } = bar); + (parentParentPath.node.type === "ObjectProperty" && + parentParentPath.node.value === parentPath.node && + parentParentPath.parentPath.type === "ObjectPattern") || + // for (this.#x of []); + (parentParentPath.node.type === "ForOfStatement" && + parentParentPath.node.left === parentPath.node) + ) { + throw path.buildCodeFrameError( + `Decorated private methods are not updatable, but "#${path.node.id.name}" is updated via this expression.`, + ); + } + }, + }); + } + + // Recrawl the scope to make sure new identifiers are properly synced + path.scope.crawl(); + + return path; +} + +export default function ( + { assertVersion, assumption }, + { decoratorsBeforeExport, loose }, +) { + assertVersion("^7.16.0"); + + const VISITED = new WeakSet(); + const constantSuper = assumption("constantSuper") ?? loose; + + return { + name: "proposal-decorators", + inherits: syntaxDecorators, + manipulateOptions({ generatorOpts }) { + generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport; + }, + + visitor: { + ClassDeclaration(path: NodePath, state: any) { + if (VISITED.has(path)) return; + + const newPath = transformClass(path, state, constantSuper); + + if (newPath) { + VISITED.add(newPath); + } + }, + + ClassExpression(path: NodePath, state: any) { + if (VISITED.has(path)) return; + + const newPath = transformClass(path, state, constantSuper); + + if (newPath) { + VISITED.add(newPath); + } + }, + }, + }; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/exec.js new file mode 100644 index 000000000000..d3161fa6ab3d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/exec.js @@ -0,0 +1,54 @@ +function dec({ get, set }, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return { + get() { + return get.call(this) + 1; + }, + + set(v) { + set.call(this, v + 1); + }, + + initializer(v) { + return v ? v : 1; + } + } +} + +class Foo { + @dec + accessor #a; + + @dec + accessor #b = 123; +} + +let foo = new Foo(); + +const aContext = foo['#aContext']; +const bContext = foo['#bContext']; + +expect(aContext.access.get.call(foo)).toBe(2); +aContext.access.set.call(foo, 123); +expect(aContext.access.get.call(foo)).toBe(125); +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('accessor'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.access.get.call(foo)).toBe(124); +bContext.access.set.call(foo, 123); +expect(bContext.access.get.call(foo)).toBe(125); +expect(bContext.name).toBe('#b'); +expect(bContext.kind).toBe('accessor'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(true); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/input.js new file mode 100644 index 000000000000..be4f348923bc --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + accessor #a; + + @dec + accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js new file mode 100644 index 000000000000..69673b7af6d2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js @@ -0,0 +1,59 @@ +var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto; + +var _A = /*#__PURE__*/new WeakMap(); + +var _a = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _b, { + get: _get_b2, + set: _set_b2 + }); + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a2, + set: _set_a2 + }); + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: (_initProto(this), _init_a(this)) + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: _init_b(this, 123) + }); + } + +} + +function _set_a2(v) { + _set_a(this, v); +} + +function _get_a2() { + _get_a(this); +} + +function _set_b2(v) { + _set_b(this, v); +} + +function _get_b2() { + _get_b(this); +} + +(() => { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 1, "a", function () { + return babelHelpers.classPrivateFieldGet(this, _A); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _A, value); + }], [dec, 1, "b", function () { + return babelHelpers.classPrivateFieldGet(this, _B); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _B, value); + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/exec.js new file mode 100644 index 000000000000..7951130866a2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/exec.js @@ -0,0 +1,75 @@ +function dec({ get, set }, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return { + get() { + return get.call(this) + 1; + }, + + set(v) { + set.call(this, v + 1); + }, + + initializer(v) { + return v ? v : 1; + } + } +} + +class Foo { + @dec + accessor a; + + @dec + accessor b = 123; + + @dec + accessor ['c'] = 456; +} + +let foo = new Foo(); + +const aContext = foo['aContext']; +const bContext = foo['bContext']; +const cContext = foo['cContext']; + +expect(foo.a).toBe(2); +foo.a = 123; +expect(foo.a).toBe(125); +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('accessor'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); +expect(foo.hasOwnProperty('a')).toBe(false); +expect(Foo.prototype.hasOwnProperty('a')).toBe(true); + +expect(foo.b).toBe(124); +foo.b = 123; +expect(foo.b).toBe(125); +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('accessor'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); +expect(foo.hasOwnProperty('b')).toBe(false); +expect(Foo.prototype.hasOwnProperty('b')).toBe(true); + +expect(foo.c).toBe(457); +foo.c = 456; +expect(foo.c).toBe(458); +expect(cContext.name).toBe('c'); +expect(cContext.kind).toBe('accessor'); +expect(cContext.isStatic).toBe(false); +expect(cContext.isPrivate).toBe(false); +expect(typeof cContext.addInitializer).toBe('function'); +expect(typeof cContext.setMetadata).toBe('function'); +expect(typeof cContext.getMetadata).toBe('function'); +expect(foo.hasOwnProperty('c')).toBe(false); +expect(Foo.prototype.hasOwnProperty('c')).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/input.js new file mode 100644 index 000000000000..5945d3196f1d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + accessor a; + + @dec + accessor b = 123; + + @dec + accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js new file mode 100644 index 000000000000..2a6057e84caa --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js @@ -0,0 +1,58 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initProto; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +var _A = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _C = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: (_initProto(this), _init_a(this)) + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: _init_b(this, 123) + }); + babelHelpers.classPrivateFieldInitSpec(this, _C, { + writable: true, + value: _init_computedKey(this, 456) + }); + } + + get a() { + return babelHelpers.classPrivateFieldGet(this, _A); + } + + set a(v) { + babelHelpers.classPrivateFieldSet(this, _A, v); + } + + get b() { + return babelHelpers.classPrivateFieldGet(this, _B); + } + + set b(v) { + babelHelpers.classPrivateFieldSet(this, _B, v); + } + + get [_computedKey]() { + return babelHelpers.classPrivateFieldGet(this, _C); + } + + set [_computedKey](v) { + babelHelpers.classPrivateFieldSet(this, _C, v); + } + +} + +(() => { + [_init_a, _init_b, _init_computedKey, _initProto] = babelHelpers.applyDecs(Foo, [[_dec, 1, "a"], [_dec2, 1, "b"], [_dec3, 1, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/exec.js new file mode 100644 index 000000000000..06946cc2f26d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/exec.js @@ -0,0 +1,52 @@ +function dec({ get, set }, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return { + get() { + return get.call(this) + 1; + }, + + set(v) { + set.call(this, v + 1); + }, + + initializer(v) { + return v ? v : 1; + } + } +} + +class Foo { + @dec + static accessor #a; + + @dec + static accessor #b = 123; +} + +const aContext = Foo['#aContext']; +const bContext = Foo['#bContext']; + +expect(aContext.access.get.call(Foo)).toBe(2); +aContext.access.set.call(Foo, 123); +expect(aContext.access.get.call(Foo)).toBe(125); +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('accessor'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.access.get.call(Foo)).toBe(124); +bContext.access.set.call(Foo, 123); +expect(bContext.access.get.call(Foo)).toBe(125); +expect(bContext.name).toBe('#b'); +expect(bContext.kind).toBe('accessor'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(true); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/input.js new file mode 100644 index 000000000000..ebb88a741572 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + static accessor #a; + + @dec + static accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js new file mode 100644 index 000000000000..b0ec49e5726f --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js @@ -0,0 +1,58 @@ +var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic; + +var _a = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _b, { + get: _get_b2, + set: _set_b2 + }); + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a2, + set: _set_a2 + }); + } + +} + +function _set_a2(v) { + _set_a(this, v); +} + +function _get_a2() { + _get_a(this); +} + +function _set_b2(v) { + _set_b(this, v); +} + +function _get_b2() { + _get_b(this); +} + +(() => { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 6, "a", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, value); + }], [dec, 6, "b", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, value); + }]], []); + + _initStatic(Foo); +})(); + +var _A = { + writable: true, + value: _init_a(Foo) +}; +var _B = { + writable: true, + value: _init_b(Foo, 123) +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/exec.js new file mode 100644 index 000000000000..21973ce25629 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/exec.js @@ -0,0 +1,70 @@ +function dec({ get, set }, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return { + get() { + return get.call(this) + 1; + }, + + set(v) { + set.call(this, v + 1); + }, + + initializer(v) { + return v ? v : 1; + } + } +} + +class Foo { + @dec + static accessor a; + + @dec + static accessor b = 123; + + @dec + static accessor ['c'] = 456; +} + +const aContext = Foo['aContext']; +const bContext = Foo['bContext']; +const cContext = Foo['cContext']; + +expect(Foo.a).toBe(2); +Foo.a = 123; +expect(Foo.a).toBe(125); +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('accessor'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); +expect(Foo.hasOwnProperty('a')).toBe(true); + +expect(Foo.b).toBe(124); +Foo.b = 123; +expect(Foo.b).toBe(125); +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('accessor'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); +expect(Foo.hasOwnProperty('b')).toBe(true); + +expect(Foo.c).toBe(457); +Foo.c = 456; +expect(Foo.c).toBe(458); +expect(cContext.name).toBe('c'); +expect(cContext.kind).toBe('accessor'); +expect(cContext.isStatic).toBe(true); +expect(cContext.isPrivate).toBe(false); +expect(typeof cContext.addInitializer).toBe('function'); +expect(typeof cContext.setMetadata).toBe('function'); +expect(typeof cContext.getMetadata).toBe('function'); +expect(Foo.hasOwnProperty('c')).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/input.js new file mode 100644 index 000000000000..edf06478601f --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + static accessor a; + + @dec + static accessor b = 123; + + @dec + static accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js new file mode 100644 index 000000000000..c5a6ac47eba2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js @@ -0,0 +1,52 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initStatic; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + static get a() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + } + + static set a(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); + } + + static get b() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + } + + static set b(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); + } + + static get [_computedKey]() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _C); + } + + static set [_computedKey](v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _C, v); + } + +} + +(() => { + [_init_a, _init_b, _init_computedKey, _initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 6, "a"], [_dec2, 6, "b"], [_dec3, 6, _computedKey]], []); + + _initStatic(Foo); +})(); + +var _A = { + writable: true, + value: _init_a(Foo) +}; +var _B = { + writable: true, + value: _init_b(Foo, 123) +}; +var _C = { + writable: true, + value: _init_computedKey(Foo, 456) +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/exec.js new file mode 100644 index 000000000000..51715be9f173 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/exec.js @@ -0,0 +1,31 @@ +class Foo { + accessor #a; + + accessor #b = 123; + + getA() { + return this.#a; + } + + setA(v) { + this.#a = v; + } + + getB() { + return this.#b; + } + + setB(v) { + this.#b = v; + } +} + +let foo = new Foo(); + +expect(foo.getA()).toBe(undefined); +foo.setA(123) +expect(foo.getA()).toBe(123); + +expect(foo.getB()).toBe(123); +foo.setB(456) +expect(foo.getB()).toBe(456); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/input.js new file mode 100644 index 000000000000..4afc45261337 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/input.js @@ -0,0 +1,5 @@ +class Foo { + accessor #a; + + accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js new file mode 100644 index 000000000000..29d3fbd66965 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js @@ -0,0 +1,45 @@ +var _A = /*#__PURE__*/new WeakMap(); + +var _a = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _b, { + get: _get_b, + set: _set_b + }); + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a, + set: _set_a + }); + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: void 0 + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: 123 + }); + } + +} + +function _get_a() { + return babelHelpers.classPrivateFieldGet(this, _A); +} + +function _set_a(v) { + babelHelpers.classPrivateFieldSet(this, _A, v); +} + +function _get_b() { + return babelHelpers.classPrivateFieldGet(this, _B); +} + +function _set_b(v) { + babelHelpers.classPrivateFieldSet(this, _B, v); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/exec.js new file mode 100644 index 000000000000..5ccd5dcce44d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/exec.js @@ -0,0 +1,27 @@ +class Foo { + accessor a; + + accessor b = 123; + + accessor ['c'] = 456; +} + +let foo = new Foo(); + +expect(foo.a).toBe(undefined); +foo.a = 123; +expect(foo.a).toBe(123); +expect(foo.hasOwnProperty('a')).toBe(false); +expect(Foo.prototype.hasOwnProperty('a')).toBe(true); + +expect(foo.b).toBe(123); +foo.b = 456 +expect(foo.b).toBe(456); +expect(foo.hasOwnProperty('b')).toBe(false); +expect(Foo.prototype.hasOwnProperty('b')).toBe(true); + +expect(foo.c).toBe(456); +foo.c = 789 +expect(foo.c).toBe(789); +expect(foo.hasOwnProperty('c')).toBe(false); +expect(Foo.prototype.hasOwnProperty('c')).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/input.js new file mode 100644 index 000000000000..ad27f18d5ed3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/input.js @@ -0,0 +1,7 @@ +class Foo { + accessor a; + + accessor b = 123; + + accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js new file mode 100644 index 000000000000..6ec6f9255a06 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js @@ -0,0 +1,47 @@ +var _A = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _C = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: void 0 + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: 123 + }); + babelHelpers.classPrivateFieldInitSpec(this, _C, { + writable: true, + value: 456 + }); + } + + get a() { + return babelHelpers.classPrivateFieldGet(this, _A); + } + + set a(v) { + babelHelpers.classPrivateFieldSet(this, _A, v); + } + + get b() { + return babelHelpers.classPrivateFieldGet(this, _B); + } + + set b(v) { + babelHelpers.classPrivateFieldSet(this, _B, v); + } + + get 'c'() { + return babelHelpers.classPrivateFieldGet(this, _C); + } + + set 'c'(v) { + babelHelpers.classPrivateFieldSet(this, _C, v); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/exec.js new file mode 100644 index 000000000000..21defb3f24d8 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/exec.js @@ -0,0 +1,29 @@ +class Foo { + static accessor #a; + + static accessor #b = 123; + + static getA() { + return this.#a; + } + + static setA(v) { + this.#a = v; + } + + static getB() { + return this.#b; + } + + static setB(v) { + this.#b = v; + } +} + +expect(Foo.getA()).toBe(undefined); +Foo.setA(123) +expect(Foo.getA()).toBe(123); + +expect(Foo.getB()).toBe(123); +Foo.setB(456) +expect(Foo.getB()).toBe(456); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/input.js new file mode 100644 index 000000000000..2e516a961de9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/input.js @@ -0,0 +1,5 @@ +class Foo { + static accessor #a; + + static accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js new file mode 100644 index 000000000000..51de21b149b2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js @@ -0,0 +1,34 @@ +class Foo {} + +function _get_a() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); +} + +function _set_a(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); +} + +function _get_b() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); +} + +function _set_b(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); +} + +var _b = { + get: _get_b, + set: _set_b +}; +var _a = { + get: _get_a, + set: _set_a +}; +var _A = { + writable: true, + value: void 0 +}; +var _B = { + writable: true, + value: 123 +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/exec.js new file mode 100644 index 000000000000..d22a4e710dd8 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/exec.js @@ -0,0 +1,22 @@ +class Foo { + static accessor a; + + static accessor b = 123; + + static accessor ['c'] = 456; +} + +expect(Foo.a).toBe(undefined); +Foo.a = 123; +expect(Foo.a).toBe(123); +expect(Foo.hasOwnProperty('a')).toBe(true); + +expect(Foo.b).toBe(123); +Foo.b = 456 +expect(Foo.b).toBe(456); +expect(Foo.hasOwnProperty('b')).toBe(true); + +expect(Foo.c).toBe(456); +Foo.c = 789 +expect(Foo.c).toBe(789); +expect(Foo.hasOwnProperty('c')).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/input.js new file mode 100644 index 000000000000..160e72cd531c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/input.js @@ -0,0 +1,7 @@ +class Foo { + static accessor a; + + static accessor b = 123; + + static accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js new file mode 100644 index 000000000000..4fe37de40ebf --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js @@ -0,0 +1,39 @@ +class Foo { + static get a() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + } + + static set a(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); + } + + static get b() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + } + + static set b(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); + } + + static get 'c'() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _C); + } + + static set 'c'(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _C, v); + } + +} + +var _A = { + writable: true, + value: void 0 +}; +var _B = { + writable: true, + value: 123 +}; +var _C = { + writable: true, + value: 456 +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/input.js new file mode 100644 index 000000000000..542bf870c079 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/input.js @@ -0,0 +1,11 @@ +const A = @dec class A {} +const B = @dec class C {} +const D = @dec class {} +const E = (@dec class {}, 123); +const F = [@dec class G {}, @dec class {}]; +const H = @dec class extends I {}; +const J = @dec class K extends L {}; + +function classFactory() { + return @dec class {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js new file mode 100644 index 000000000000..b0cce043afbe --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js @@ -0,0 +1,51 @@ +var _initClass, _A, _class, _temp, _initClass2, _C, _class2, _temp2, _initClass3, _D, _class3, _temp3, _initClass4, _decorated_class, _class4, _temp4, _initClass5, _G, _class5, _temp5, _initClass6, _decorated_class2, _class6, _temp6, _initClass7, _H, _class7, _temp7, _initClass8, _K, _class8, _temp8; + +const A = ((_temp = _class = class A {}, (() => { + [_A, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); +})(), (() => { + _initClass(); +})(), _temp), _A); +const B = ((_temp2 = _class2 = class C {}, (() => { + [_C, _initClass2] = babelHelpers.applyDecs(_class2, [], [dec]); +})(), (() => { + _initClass2(); +})(), _temp2), _C); +const D = ((_temp3 = _class3 = class D {}, (() => { + [_D, _initClass3] = babelHelpers.applyDecs(_class3, [], [dec]); +})(), (() => { + _initClass3(); +})(), _temp3), _D); +const E = (((_temp4 = _class4 = class {}, (() => { + [_decorated_class, _initClass4] = babelHelpers.applyDecs(_class4, [], [dec]); +})(), (() => { + _initClass4(); +})(), _temp4), _decorated_class), 123); +const F = [((_temp5 = _class5 = class G {}, (() => { + [_G, _initClass5] = babelHelpers.applyDecs(_class5, [], [dec]); +})(), (() => { + _initClass5(); +})(), _temp5), _G), ((_temp6 = _class6 = class {}, (() => { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_class6, [], [dec]); +})(), (() => { + _initClass6(); +})(), _temp6), _decorated_class2)]; +const H = ((_temp7 = _class7 = class H extends I {}, (() => { + [_H, _initClass7] = babelHelpers.applyDecs(_class7, [], [dec]); +})(), (() => { + _initClass7(); +})(), _temp7), _H); +const J = ((_temp8 = _class8 = class K extends L {}, (() => { + [_K, _initClass8] = babelHelpers.applyDecs(_class8, [], [dec]); +})(), (() => { + _initClass8(); +})(), _temp8), _K); + +function classFactory() { + var _initClass9, _decorated_class3, _class9, _temp9; + + return (_temp9 = _class9 = class {}, (() => { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_class9, [], [dec]); + })(), (() => { + _initClass9(); + })(), _temp9), _decorated_class3; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/exec.js new file mode 100644 index 000000000000..889e8c102cf4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/exec.js @@ -0,0 +1,18 @@ +let count = 0; + +function dec1(Klass) { + expect(++count).toBe(1); + expect(Klass.name).toBe('Bar'); +} + +@dec1 +class Bar {} + +function dec2(Klass) { + expect(++count).toBe(2); + expect(Klass.name).toBe('Foo'); + expect(Object.getPrototypeOf(Klass)).toBe(Bar); +} + +@dec2 +class Foo extends Bar {} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/input.js new file mode 100644 index 000000000000..7a4a6684555a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/input.js @@ -0,0 +1,5 @@ +@dec1 +class Bar {} + +@dec2 +class Foo extends Bar {} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js new file mode 100644 index 000000000000..605270eadeca --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js @@ -0,0 +1,25 @@ +var _initClass, _initClass2; + +let _Bar; + +class Bar {} + +(() => { + [_Bar, _initClass] = babelHelpers.applyDecs(Bar, [], [dec1]); +})(); + +(() => { + _initClass(); +})(); + +let _Foo; + +class Foo extends _Bar {} + +(() => { + [_Foo, _initClass2] = babelHelpers.applyDecs(Foo, [], [dec2]); +})(); + +(() => { + _initClass2(); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/exec.js new file mode 100644 index 000000000000..aefc3ba5b88c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/exec.js @@ -0,0 +1,41 @@ +function dec1(Foo, { addInitializer }) { + expect(Foo.field).toBe(undefined); + addInitializer(() => { + Foo.initField = 123; + }); +} + +@dec1 +class Foo { + static { + expect(this.initField).toBe(undefined); + } + + static field = 123; +} + +expect(Foo.initField).toBe(123); +expect(Foo.field).toBe(123); + +function dec2(Bar, { addInitializer }) { + expect(Bar.field).toBe(123); + expect(Bar.otherField).toBe(undefined); + expect(Bar.initField).toBe(123); + addInitializer(() => { + Bar.initField = 456; + }); +} + +@dec2 +class Bar extends Foo { + static { + expect(this.initField).toBe(123); + this.otherField = 456; + } + + static field = 456; +} + +expect(Bar.initField).toBe(456); +expect(Bar.field).toBe(456); +expect(Bar.otherField).toBe(456); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/input.js new file mode 100644 index 000000000000..deeb483448f7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/input.js @@ -0,0 +1,13 @@ +@dec +class Foo { + static field = 123; +} + +@dec +class Bar extends Foo { + static { + this.otherField = 456; + } + + static field = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js new file mode 100644 index 000000000000..a197b92f57e6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js @@ -0,0 +1,33 @@ +var _initClass, _initClass2; + +let _Foo; + +class Foo {} + +(() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); +})(); + +babelHelpers.defineProperty(Foo, "field", 123); + +(() => { + _initClass(); +})(); + +let _Bar; + +class Bar extends _Foo {} + +(() => { + [_Bar, _initClass2] = babelHelpers.applyDecs(Bar, [], [dec]); +})(); + +(() => { + Bar.otherField = 456; +})(); + +babelHelpers.defineProperty(Bar, "field", 123); + +(() => { + _initClass2(); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/exec.js new file mode 100644 index 000000000000..739e33a05be5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/exec.js @@ -0,0 +1,17 @@ +let replaced; + +function dec(Klass) { + replaced = class extends Klass {}; + + return replaced; +} + +const Foo = @dec class Bar { + static bar = new Bar(); +}; + +const foo = new Foo(); + +expect(Foo).toBe(replaced); +expect(Foo.bar).toBeInstanceOf(replaced); +expect(foo).toBeInstanceOf(replaced); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/input.js new file mode 100644 index 000000000000..fde7feb1abd7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/input.js @@ -0,0 +1,6 @@ +const Foo = @dec class Bar { + bar = new Bar(); +}; + +const foo = new Foo(); + diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js new file mode 100644 index 000000000000..f1f8cd9df38d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js @@ -0,0 +1,13 @@ +var _initClass, _Bar, _class, _temp; + +const Foo = ((_temp = _class = class Bar { + constructor() { + babelHelpers.defineProperty(this, "bar", new _Bar()); + } + +}, (() => { + [_Bar, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); +})(), (() => { + _initClass(); +})(), _temp), _Bar); +const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/exec.js new file mode 100644 index 000000000000..c8dc49c0d85e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/exec.js @@ -0,0 +1,19 @@ + +let replaced; + +function dec(Klass) { + replaced = class extends Klass {}; + + return replaced; +} + +@dec +class Foo { + static foo = new Foo(); +} + +const foo = new Foo(); + +expect(Foo).toBe(replaced); +expect(Foo.foo).toBeInstanceOf(replaced); +expect(foo).toBeInstanceOf(replaced); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/input.js new file mode 100644 index 000000000000..e6da5000db62 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/input.js @@ -0,0 +1,6 @@ +@dec +class Foo { + static foo = new Foo(); +} + +const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js new file mode 100644 index 000000000000..4a26f8ccd8bf --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js @@ -0,0 +1,17 @@ +var _initClass; + +let _Foo; + +class Foo {} + +(() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); +})(); + +babelHelpers.defineProperty(Foo, "foo", new _Foo()); + +(() => { + _initClass(); +})(); + +const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/exec.js new file mode 100644 index 000000000000..49fad189f4e2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/exec.js @@ -0,0 +1,33 @@ +var i = 0; + +function getKey() { + return (i++).toString(); +} + +let elements = []; + +function dec(fn, context) { + elements.push({ fn, context }); +} + +class Foo { + @dec + [getKey()]() { + return 1; + } + + @dec + [getKey()]() { + return 2; + } +} + +expect(elements).toHaveLength(2); + +expect(elements[0].context.name).toBe("0"); +expect(elements[0].fn()).toBe(1); + +expect(elements[1].context.name).toBe("1"); +expect(elements[1].fn()).toBe(2); + +expect(i).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/input.js new file mode 100644 index 000000000000..2ca438188867 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/input.js @@ -0,0 +1,11 @@ +class Foo { + @dec + [getKey()]() { + return 1; + } + + @dec + [getKey()]() { + return 2; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js new file mode 100644 index 000000000000..a70d24de54c9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js @@ -0,0 +1,25 @@ +var _computedKey, _computedKey2, _dec, _dec2, _initProto; + +_computedKey = getKey() +_dec = dec +_computedKey2 = getKey() +_dec2 = dec + +class Foo { + constructor(...args) { + _initProto(this); + } + + [_computedKey]() { + return 1; + } + + [_computedKey2]() { + return 2; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/exec.js new file mode 100644 index 000000000000..c97e2293ac96 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/exec.js @@ -0,0 +1,29 @@ +expect(() => { + var i = 0; + var j = 0; + + function getKeyI() { + return (i++).toString(); + } + function getKeyJ() { + return (j++).toString(); + } + + let elements = []; + + function dec(fn, context) { + elements.push({ fn, context }); + } + + class Foo { + @dec + [getKeyI()]() { + return 1; + } + + @dec + [getKeyJ()]() { + return 2; + } + } +}).toThrow("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: 0") diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/input.js new file mode 100644 index 000000000000..8aeb57759b76 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/input.js @@ -0,0 +1,11 @@ +class Foo { + @dec + [getKeyI()]() { + return 1; + } + + @dec + [getKeyJ()]() { + return 2; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js new file mode 100644 index 000000000000..66e2ac318d83 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js @@ -0,0 +1,25 @@ +var _computedKey, _computedKey2, _dec, _dec2, _initProto; + +_computedKey = getKeyI() +_dec = dec +_computedKey2 = getKeyJ() +_dec2 = dec + +class Foo { + constructor(...args) { + _initProto(this); + } + + [_computedKey]() { + return 1; + } + + [_computedKey2]() { + return 2; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/exec.js new file mode 100644 index 000000000000..8ac906f1823a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/exec.js @@ -0,0 +1,23 @@ +let elements = []; + +function dec(val, context) { + elements.push({ val, context }); +} + +class Foo { + @dec + a = 123; + + @dec + a() { + return 1; + } +} + +expect(elements).toHaveLength(2); + +expect(elements[0].context.name).toBe("a"); +expect(elements[0].val).toBe(undefined); + +expect(elements[1].context.name).toBe("a"); +expect(elements[1].val()).toBe(1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/input.js new file mode 100644 index 000000000000..522da0061204 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/input.js @@ -0,0 +1,9 @@ +class Foo { + @dec + a = 123; + + @dec + a() { + return 1; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js new file mode 100644 index 000000000000..fe79aa632006 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js @@ -0,0 +1,16 @@ +var _init_a, _initProto; + +class Foo { + constructor() { + babelHelpers.defineProperty(this, "a", (_initProto(this), _init_a(this, 123))); + } + + a() { + return 1; + } + +} + +(() => { + [_init_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 0, "a"], [dec, 2, "a"]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/exec.js new file mode 100644 index 000000000000..9e270b2a7488 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/exec.js @@ -0,0 +1,19 @@ +expect(() => { + let elements = []; + + function dec(val, context) { + elements.push({ val, context }); + } + + class Foo { + @dec + a() { + return 1; + } + + @dec + a() { + return 2; + } + } +}).toThrow("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: a") diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/input.js new file mode 100644 index 000000000000..db90a40aa67b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/input.js @@ -0,0 +1,11 @@ +class Foo { + @dec + a() { + return 1; + } + + @dec + a() { + return 2; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js new file mode 100644 index 000000000000..6402e1341ff0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js @@ -0,0 +1,20 @@ +var _initProto; + +class Foo { + constructor(...args) { + _initProto(this); + } + + a() { + return 1; + } + + a() { + return 2; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[dec, 2, "a"], [dec, 2, "a"]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/exec.js new file mode 100644 index 000000000000..9d368edd0f8b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/exec.js @@ -0,0 +1,41 @@ +function dec(_v, context) { + return function (v) { + this[context.name + 'Context'] = context; + return (v || 1) + 1; + } +} + +class Foo { + @dec + #a; + + @dec + #b = 123; +} + +let foo = new Foo(); + +const aContext = foo['#aContext']; +const bContext = foo['#bContext']; + +expect(aContext.access.get.call(foo)).toBe(2); +aContext.access.set.call(foo, 123); +expect(aContext.access.get.call(foo)).toBe(123); +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('field'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('undefined'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.access.get.call(foo)).toBe(124); +bContext.access.set.call(foo, 123); +expect(bContext.access.get.call(foo)).toBe(123); +expect(bContext.name).toBe('#b'); +expect(bContext.kind).toBe('field'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('undefined'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/input.js new file mode 100644 index 000000000000..222ec09fc95e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + #a; + + @dec + #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js new file mode 100644 index 000000000000..af27fce2d289 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js @@ -0,0 +1,31 @@ +var _init_a, _init_b; + +var _a = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + writable: true, + value: _init_a(this) + }); + babelHelpers.classPrivateFieldInitSpec(this, _b, { + writable: true, + value: _init_b(this, 123) + }); + } + +} + +(() => { + [_init_a, _init_b] = babelHelpers.applyDecs(Foo, [[dec, 0, "a", function () { + return babelHelpers.classPrivateFieldGet(this, _a); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _a, value); + }], [dec, 0, "b", function () { + return babelHelpers.classPrivateFieldGet(this, _b); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _b, value); + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/exec.js new file mode 100644 index 000000000000..0d5ed78cf745 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/exec.js @@ -0,0 +1,62 @@ +function dec(_v, context) { + return function (v) { + this[context.name + 'Context'] = context; + return (v || 1) + 1; + } +} + +class Foo { + @dec + a; + + @dec + b = 123; + + @dec + ['c'] = 456; +} + +let foo = new Foo(); + +const aContext = foo['aContext']; +const bContext = foo['bContext']; +const cContext = foo['cContext']; + +expect(foo.a).toBe(2); +foo.a = 123; +expect(foo.a).toBe(123); +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('field'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('undefined'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); +expect(foo.hasOwnProperty('a')).toBe(true); +expect(Foo.prototype.hasOwnProperty('a')).toBe(false); + +expect(foo.b).toBe(124); +foo.b = 123; +expect(foo.b).toBe(123); +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('field'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('undefined'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); +expect(foo.hasOwnProperty('b')).toBe(true); +expect(Foo.prototype.hasOwnProperty('b')).toBe(false); + +expect(foo.c).toBe(457); +foo.c = 456; +expect(foo.c).toBe(456); +expect(cContext.name).toBe('c'); +expect(cContext.kind).toBe('field'); +expect(cContext.isStatic).toBe(false); +expect(cContext.isPrivate).toBe(false); +expect(typeof cContext.addInitializer).toBe('undefined'); +expect(typeof cContext.setMetadata).toBe('function'); +expect(typeof cContext.getMetadata).toBe('function'); +expect(foo.hasOwnProperty('c')).toBe(true); +expect(Foo.prototype.hasOwnProperty('c')).toBe(false); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/input.js new file mode 100644 index 000000000000..8dff95c99a3a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + a; + + @dec + b = 123; + + @dec + ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js new file mode 100644 index 000000000000..481926ddfe5a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js @@ -0,0 +1,19 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + constructor() { + babelHelpers.defineProperty(this, "a", _init_a(this)); + babelHelpers.defineProperty(this, "b", _init_b(this, 123)); + babelHelpers.defineProperty(this, _computedKey, _init_computedKey(this, 456)); + } + +} + +(() => { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(Foo, [[_dec, 0, "a"], [_dec2, 0, "b"], [_dec3, 0, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/exec.js new file mode 100644 index 000000000000..51fba146164c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/exec.js @@ -0,0 +1,39 @@ +function dec(_v, context) { + return function (v) { + this[context.name + 'Context'] = context; + return (v || 1) + 1; + } +} + +class Foo { + @dec + static #a; + + @dec + static #b = 123; +} + +const aContext = Foo['#aContext']; +const bContext = Foo['#bContext']; + +expect(aContext.access.get.call(Foo)).toBe(2); +aContext.access.set.call(Foo, 123); +expect(aContext.access.get.call(Foo)).toBe(123); +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('field'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('undefined'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.access.get.call(Foo)).toBe(124); +bContext.access.set.call(Foo, 123); +expect(bContext.access.get.call(Foo)).toBe(123); +expect(bContext.name).toBe('#b'); +expect(bContext.kind).toBe('field'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('undefined'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/input.js new file mode 100644 index 000000000000..830d82321863 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + static #a; + + @dec + static #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js new file mode 100644 index 000000000000..ad619ac7d598 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js @@ -0,0 +1,24 @@ +var _init_a, _init_b; + +class Foo {} + +(() => { + [_init_a, _init_b] = babelHelpers.applyDecs(Foo, [[dec, 5, "a", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, value); + }], [dec, 5, "b", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _b); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _b, value); + }]], []); +})(); + +var _a = { + writable: true, + value: _init_a(Foo) +}; +var _b = { + writable: true, + value: _init_b(Foo, 123) +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/exec.js new file mode 100644 index 000000000000..48af3023539c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/exec.js @@ -0,0 +1,57 @@ +function dec(_v, context) { + return function (v) { + this[context.name + 'Context'] = context; + return (v || 1) + 1; + } +} + +class Foo { + @dec + static a; + + @dec + static b = 123; + + @dec + static ['c'] = 456; +} + +const aContext = Foo['aContext']; +const bContext = Foo['bContext']; +const cContext = Foo['cContext']; + +expect(Foo.a).toBe(2); +Foo.a = 123; +expect(Foo.a).toBe(123); +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('field'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('undefined'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); +expect(Foo.hasOwnProperty('a')).toBe(true); + +expect(Foo.b).toBe(124); +Foo.b = 123; +expect(Foo.b).toBe(123); +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('field'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('undefined'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); +expect(Foo.hasOwnProperty('b')).toBe(true); + +expect(Foo.c).toBe(457); +Foo.c = 456; +expect(Foo.c).toBe(456); +expect(cContext.name).toBe('c'); +expect(cContext.kind).toBe('field'); +expect(cContext.isStatic).toBe(true); +expect(cContext.isPrivate).toBe(false); +expect(typeof cContext.addInitializer).toBe('undefined'); +expect(typeof cContext.setMetadata).toBe('function'); +expect(typeof cContext.getMetadata).toBe('function'); +expect(Foo.hasOwnProperty('c')).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/input.js new file mode 100644 index 000000000000..9b9dae98314a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + static a; + + @dec + static b = 123; + + @dec + static ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js new file mode 100644 index 000000000000..c5df8314385b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js @@ -0,0 +1,16 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo {} + +(() => { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(Foo, [[_dec, 5, "a"], [_dec2, 5, "b"], [_dec3, 5, _computedKey]], []); +})(); + +babelHelpers.defineProperty(Foo, "a", _init_a(Foo)); +babelHelpers.defineProperty(Foo, "b", _init_b(Foo, 123)); +babelHelpers.defineProperty(Foo, _computedKey, _init_computedKey(Foo, 456)); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/exec.js new file mode 100644 index 000000000000..a4f9a31d2589 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/exec.js @@ -0,0 +1,67 @@ +function dec(value, context) { + context.addInitializer((instance) => { + instance[context.name + '_' + context.kind + 'Context'] = context; + }); + + if (context.kind === 'getter') { + return function () { + return value.call(this) + 1; + } + } else { + return function (v) { + return value.call(this, v + 1); + } + } +} + +class Foo { + value = 1; + + @dec + get #a() { + return this.value; + } + + @dec + set #a(v) { + this.value = v; + } + + getA() { + return this.#a; + } + + setA(v) { + this.#a = v; + } +} + +let foo = new Foo(); + +const a_getterContext = foo['#a_getterContext']; +const a_setterContext = foo['#a_setterContext']; + +expect(a_getterContext.access.get.call(foo)).toBe(2); +expect(foo.getA()).toBe(2); +a_setterContext.access.set.call(foo, 123); +expect(a_getterContext.access.get.call(foo)).toBe(125); +expect(foo.getA()).toBe(125); +foo.setA(456); +expect(a_getterContext.access.get.call(foo)).toBe(458); +expect(foo.getA()).toBe(458); + +expect(a_getterContext.name).toBe('#a'); +expect(a_getterContext.kind).toBe('getter'); +expect(a_getterContext.isStatic).toBe(false); +expect(a_getterContext.isPrivate).toBe(true); +expect(typeof a_getterContext.addInitializer).toBe('function'); +expect(typeof a_getterContext.setMetadata).toBe('function'); +expect(typeof a_getterContext.getMetadata).toBe('function'); + +expect(a_setterContext.name).toBe('#a'); +expect(a_setterContext.kind).toBe('setter'); +expect(a_setterContext.isStatic).toBe(false); +expect(a_setterContext.isPrivate).toBe(true); +expect(typeof a_setterContext.addInitializer).toBe('function'); +expect(typeof a_setterContext.setMetadata).toBe('function'); +expect(typeof a_setterContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/input.js new file mode 100644 index 000000000000..060ae225a21e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/input.js @@ -0,0 +1,21 @@ +class Foo { + value = 1; + + @dec + get #a() { + return this.value; + } + + @dec + set #a(v) { + this.value = v; + } + + getA() { + return this.#a; + } + + setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js new file mode 100644 index 000000000000..71e95a6ee2a2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js @@ -0,0 +1,40 @@ +var _call_a, _call_a2, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a, + set: _set_a + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + getA() { + return babelHelpers.classPrivateFieldGet(this, _a); + } + + setA(v) { + babelHelpers.classPrivateFieldSet(this, _a, v); + } + +} + +function _get_a() { + return _call_a(this); +} + +function _set_a(v) { + _call_a2(this, v); +} + +(() => { + [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 3, "a", function () { + return this.value; + }], [dec, 4, "a", function (v) { + this.value = v; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/exec.js new file mode 100644 index 000000000000..0420e538875b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/exec.js @@ -0,0 +1,88 @@ +function dec(value, context) { + context.addInitializer((instance) => { + instance[context.name + '_' + context.kind + 'Context'] = context; + }); + + if (context.kind === 'getter') { + return function () { + return value.call(this) + 1; + } + } else { + return function (v) { + return value.call(this, v + 1); + } + } +} + +class Foo { + value = 1; + + @dec + get a() { + return this.value; + } + + @dec + set a(v) { + this.value = v; + } + + @dec + get ['b']() { + return this.value; + } + + @dec + set ['b'](v) { + this.value = v; + } +} + +let foo = new Foo(); + +const a_getterContext = foo['a_getterContext']; +const a_setterContext = foo['a_setterContext']; + +const b_getterContext = foo['b_getterContext']; +const b_setterContext = foo['b_setterContext']; + +expect(foo.a).toBe(2); +expect(foo.b).toBe(2); +foo.a = 123; +expect(foo.a).toBe(125); +expect(foo.b).toBe(125); +foo.b = 456; +expect(foo.a).toBe(458); +expect(foo.b).toBe(458); + +expect(a_getterContext.name).toBe('a'); +expect(a_getterContext.kind).toBe('getter'); +expect(a_getterContext.isStatic).toBe(false); +expect(a_getterContext.isPrivate).toBe(false); +expect(typeof a_getterContext.addInitializer).toBe('function'); +expect(typeof a_getterContext.setMetadata).toBe('function'); +expect(typeof a_getterContext.getMetadata).toBe('function'); + +expect(a_setterContext.name).toBe('a'); +expect(a_setterContext.kind).toBe('setter'); +expect(a_setterContext.isStatic).toBe(false); +expect(a_setterContext.isPrivate).toBe(false); +expect(typeof a_setterContext.addInitializer).toBe('function'); +expect(typeof a_setterContext.setMetadata).toBe('function'); +expect(typeof a_setterContext.getMetadata).toBe('function'); + +expect(b_getterContext.name).toBe('b'); +expect(b_getterContext.kind).toBe('getter'); +expect(b_getterContext.isStatic).toBe(false); +expect(b_getterContext.isPrivate).toBe(false); +expect(typeof b_getterContext.addInitializer).toBe('function'); +expect(typeof b_getterContext.setMetadata).toBe('function'); +expect(typeof b_getterContext.getMetadata).toBe('function'); + +expect(b_setterContext.name).toBe('b'); +expect(b_setterContext.kind).toBe('setter'); +expect(b_setterContext.isStatic).toBe(false); +expect(b_setterContext.isPrivate).toBe(false); +expect(typeof b_setterContext.addInitializer).toBe('function'); +expect(typeof b_setterContext.setMetadata).toBe('function'); +expect(typeof b_setterContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/input.js new file mode 100644 index 000000000000..ef384166d689 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/input.js @@ -0,0 +1,23 @@ +class Foo { + value = 1; + + @dec + get a() { + return this.value; + } + + @dec + set a(v) { + this.value = v; + } + + @dec + get ['b']() { + return this.value; + } + + @dec + set ['b'](v) { + this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js new file mode 100644 index 000000000000..a05760c5cfe9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js @@ -0,0 +1,37 @@ +var _computedKey, _computedKey2, _dec, _dec2, _dec3, _dec4, _initProto; + +_dec = dec +_dec2 = dec +_computedKey = 'b' +_dec3 = dec +_computedKey2 = 'b' +_dec4 = dec + +class Foo { + constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + get a() { + return this.value; + } + + set a(v) { + this.value = v; + } + + get [_computedKey]() { + return this.value; + } + + set [_computedKey2](v) { + this.value = v; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 3, "a"], [_dec2, 4, "a"], [_dec3, 3, _computedKey], [_dec4, 4, _computedKey2]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/exec.js new file mode 100644 index 000000000000..90bdd12c47ec --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/exec.js @@ -0,0 +1,65 @@ +function dec(value, context) { + context.addInitializer((instance) => { + instance[context.name + '_' + context.kind + 'Context'] = context; + }); + + if (context.kind === 'getter') { + return function () { + return value.call(this) + 1; + } + } else { + return function (v) { + return value.call(this, v + 1); + } + } +} + +class Foo { + static value = 1; + + @dec + static get #a() { + return this.value; + } + + @dec + static set #a(v) { + this.value = v; + } + + static getA() { + return this.#a; + } + + static setA(v) { + this.#a = v; + } +} + +const a_getterContext = Foo['#a_getterContext']; +const a_setterContext = Foo['#a_setterContext']; + +expect(a_getterContext.access.get.call(Foo)).toBe(2); +expect(Foo.getA()).toBe(2); +a_setterContext.access.set.call(Foo, 123); +expect(a_getterContext.access.get.call(Foo)).toBe(125); +expect(Foo.getA()).toBe(125); +Foo.setA(456); +expect(a_getterContext.access.get.call(Foo)).toBe(458); +expect(Foo.getA()).toBe(458); + +expect(a_getterContext.name).toBe('#a'); +expect(a_getterContext.kind).toBe('getter'); +expect(a_getterContext.isStatic).toBe(true); +expect(a_getterContext.isPrivate).toBe(true); +expect(typeof a_getterContext.addInitializer).toBe('function'); +expect(typeof a_getterContext.setMetadata).toBe('function'); +expect(typeof a_getterContext.getMetadata).toBe('function'); + +expect(a_setterContext.name).toBe('#a'); +expect(a_setterContext.kind).toBe('setter'); +expect(a_setterContext.isStatic).toBe(true); +expect(a_setterContext.isPrivate).toBe(true); +expect(typeof a_setterContext.addInitializer).toBe('function'); +expect(typeof a_setterContext.setMetadata).toBe('function'); +expect(typeof a_setterContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/input.js new file mode 100644 index 000000000000..f439a9152528 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/input.js @@ -0,0 +1,21 @@ +class Foo { + static value = 1; + + @dec + static get #a() { + return this.value; + } + + @dec + static set #a(v) { + this.value = v; + } + + static getA() { + return this.#a; + } + + static setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js new file mode 100644 index 000000000000..e9ac78c2c966 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js @@ -0,0 +1,37 @@ +var _call_a, _call_a2, _initStatic; + +class Foo { + static getA() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); + } + + static setA(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, v); + } + +} + +function _get_a() { + return _call_a(this); +} + +function _set_a(v) { + _call_a2(this, v); +} + +var _a = { + get: _get_a, + set: _set_a +}; + +(() => { + [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 8, "a", function () { + return this.value; + }], [dec, 9, "a", function (v) { + this.value = v; + }]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/exec.js new file mode 100644 index 000000000000..23ea7b2f54cd --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/exec.js @@ -0,0 +1,87 @@ +function dec(value, context) { + context.addInitializer((instance) => { + instance[context.name + '_' + context.kind + 'Context'] = context; + }); + + if (context.kind === 'getter') { + return function () { + return value.call(this) + 1; + } + } else { + return function (v) { + return value.call(this, v + 1); + } + } +} + +class Foo { + static value = 1; + + @dec + static get a() { + return this.value; + } + + @dec + static set a(v) { + this.value = v; + } + + @dec + static get ['b']() { + return this.value; + } + + @dec + static set ['b'](v) { + this.value = v; + } +} + +const a_getterContext = Foo['a_getterContext']; +const a_setterContext = Foo['a_setterContext']; + +const b_getterContext = Foo['b_getterContext']; +const b_setterContext = Foo['b_setterContext']; + +expect(Foo.a).toBe(2); +expect(Foo.b).toBe(2); +Foo.a = 123; +expect(Foo.a).toBe(125); +expect(Foo.b).toBe(125); +Foo.b = 456; +expect(Foo.a).toBe(458); +expect(Foo.b).toBe(458); + +expect(a_getterContext.name).toBe('a'); +expect(a_getterContext.kind).toBe('getter'); +expect(a_getterContext.isStatic).toBe(true); +expect(a_getterContext.isPrivate).toBe(false); +expect(typeof a_getterContext.addInitializer).toBe('function'); +expect(typeof a_getterContext.setMetadata).toBe('function'); +expect(typeof a_getterContext.getMetadata).toBe('function'); + +expect(a_setterContext.name).toBe('a'); +expect(a_setterContext.kind).toBe('setter'); +expect(a_setterContext.isStatic).toBe(true); +expect(a_setterContext.isPrivate).toBe(false); +expect(typeof a_setterContext.addInitializer).toBe('function'); +expect(typeof a_setterContext.setMetadata).toBe('function'); +expect(typeof a_setterContext.getMetadata).toBe('function'); + +expect(b_getterContext.name).toBe('b'); +expect(b_getterContext.kind).toBe('getter'); +expect(b_getterContext.isStatic).toBe(true); +expect(b_getterContext.isPrivate).toBe(false); +expect(typeof b_getterContext.addInitializer).toBe('function'); +expect(typeof b_getterContext.setMetadata).toBe('function'); +expect(typeof b_getterContext.getMetadata).toBe('function'); + +expect(b_setterContext.name).toBe('b'); +expect(b_setterContext.kind).toBe('setter'); +expect(b_setterContext.isStatic).toBe(true); +expect(b_setterContext.isPrivate).toBe(false); +expect(typeof b_setterContext.addInitializer).toBe('function'); +expect(typeof b_setterContext.setMetadata).toBe('function'); +expect(typeof b_setterContext.getMetadata).toBe('function'); + diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/input.js new file mode 100644 index 000000000000..193bf7b836a2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/input.js @@ -0,0 +1,23 @@ +class Foo { + static value = 1; + + @dec + static get a() { + return this.value; + } + + @dec + static set a(v) { + this.value = v; + } + + @dec + static get ['b']() { + return this.value; + } + + @dec + static set ['b'](v) { + this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js new file mode 100644 index 000000000000..edcb11764a7a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js @@ -0,0 +1,35 @@ +var _computedKey, _computedKey2, _dec, _dec2, _dec3, _dec4, _initStatic; + +_dec = dec +_dec2 = dec +_computedKey = 'b' +_dec3 = dec +_computedKey2 = 'b' +_dec4 = dec + +class Foo { + static get a() { + return this.value; + } + + static set a(v) { + this.value = v; + } + + static get [_computedKey]() { + return this.value; + } + + static set [_computedKey2](v) { + this.value = v; + } + +} + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 8, "a"], [_dec2, 9, "a"], [_dec3, 8, _computedKey], [_dec4, 9, _computedKey2]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/exec.js new file mode 100644 index 000000000000..70c0965c67e9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/exec.js @@ -0,0 +1,39 @@ +function dec(get, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return get.call(this) + 1; + } +} + +class Foo { + value = 1; + + @dec + get #a() { + return this.value; + } + + getA() { + return this.#a; + } +} + +let foo = new Foo(); + +const aContext = foo['#aContext']; + +expect(aContext.access.get.call(foo)).toBe(2); +expect(foo.getA()).toBe(2); +foo.value = 123; +expect(aContext.access.get.call(foo)).toBe(124); +expect(foo.getA()).toBe(124); +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('getter'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/input.js new file mode 100644 index 000000000000..49c601a1dd5b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/input.js @@ -0,0 +1,12 @@ +class Foo { + value = 1; + + @dec + get #a() { + return this.value; + } + + getA() { + return this.#a; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js new file mode 100644 index 000000000000..32971ca073e9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js @@ -0,0 +1,30 @@ +var _call_a, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a, + set: void 0 + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + getA() { + return babelHelpers.classPrivateFieldGet(this, _a); + } + +} + +function _get_a() { + return _call_a(this); +} + +(() => { + [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 3, "a", function () { + return this.value; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/exec.js new file mode 100644 index 000000000000..22f52e96d4f2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/exec.js @@ -0,0 +1,50 @@ +function dec(get, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return get.call(this) + 1; + } +} + +class Foo { + value = 1; + + @dec + get a() { + return this.value; + } + + @dec + get ['b']() { + return this.value; + } +} + +let foo = new Foo(); + +const aContext = foo['aContext']; +const bContext = foo['bContext']; + +expect(foo.a).toBe(2); +expect(foo.b).toBe(2); +foo.value = 123; +expect(foo.a).toBe(124); +expect(foo.b).toBe(124); + +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('getter'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('getter'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/input.js new file mode 100644 index 000000000000..9d1cbae52f1d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/input.js @@ -0,0 +1,13 @@ +class Foo { + value = 1; + + @dec + get a() { + return this.value; + } + + @dec + get ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js new file mode 100644 index 000000000000..0152dbf977de --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js @@ -0,0 +1,26 @@ +var _computedKey, _dec, _dec2, _initProto; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + get a() { + return this.value; + } + + get [_computedKey]() { + return this.value; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 3, "a"], [_dec2, 3, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/exec.js new file mode 100644 index 000000000000..7d1c8027d545 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/exec.js @@ -0,0 +1,38 @@ +function dec(get, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return get.call(this) + 1; + } +} + +class Foo { + static value = 1; + + @dec + static get #a() { + return this.value; + } + + static getA() { + return this.#a; + } +} + +const aContext = Foo['#aContext']; + +expect(aContext.access.get.call(Foo)).toBe(2); +expect(Foo.getA()).toBe(2); +Foo.value = 123; +expect(aContext.access.get.call(Foo)).toBe(124); +expect(Foo.getA()).toBe(124); + +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('getter'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/input.js new file mode 100644 index 000000000000..90edd26364d8 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/input.js @@ -0,0 +1,12 @@ +class Foo { + static value = 1; + + @dec + static get #a() { + return this.value; + } + + static getA() { + return this.#a; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js new file mode 100644 index 000000000000..e0262570f9e3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js @@ -0,0 +1,27 @@ +var _call_a, _initStatic; + +class Foo { + static getA() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); + } + +} + +function _get_a() { + return _call_a(this); +} + +var _a = { + get: _get_a, + set: void 0 +}; + +(() => { + [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 8, "a", function () { + return this.value; + }]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/exec.js new file mode 100644 index 000000000000..94c7b9d5dab5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/exec.js @@ -0,0 +1,48 @@ +function dec(get, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return get.call(this) + 1; + } +} + +class Foo { + static value = 1; + + @dec + static get a() { + return this.value; + } + + @dec + static get ['b']() { + return this.value; + } +} + +const aContext = Foo['aContext']; +const bContext = Foo['bContext']; + +expect(Foo.a).toBe(2); +expect(Foo.b).toBe(2); +Foo.value = 123; +expect(Foo.a).toBe(124); +expect(Foo.b).toBe(124); + +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('getter'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('getter'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/input.js new file mode 100644 index 000000000000..1383fa58abf4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/input.js @@ -0,0 +1,13 @@ +class Foo { + static value = 1; + + @dec + static get a() { + return this.value; + } + + @dec + static get ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js new file mode 100644 index 000000000000..68787d432777 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js @@ -0,0 +1,24 @@ +var _computedKey, _dec, _dec2, _initStatic; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static get a() { + return this.value; + } + + static get [_computedKey]() { + return this.value; + } + +} + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 8, "a"], [_dec2, 8, _computedKey]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/class/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/class/exec.js new file mode 100644 index 000000000000..2eaa3d1263b0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/class/exec.js @@ -0,0 +1,10 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +@dec +class Foo {} + +expect(Foo[Symbol.metadata][key].constructor).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/getting-previously-set-metadata/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/getting-previously-set-metadata/exec.js new file mode 100644 index 000000000000..73eeed66ac57 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/getting-previously-set-metadata/exec.js @@ -0,0 +1,30 @@ +const key = Symbol(); + +function dec1(_, { setMetadata, getMetadata }) { + expect(getMetadata(key)).toBe(undefined); + setMetadata(key, 123); + expect(getMetadata(key)).toBe(123); +} + +function dec2(_, { setMetadata, getMetadata }) { + expect(getMetadata(key)).toBe(123); + setMetadata(key, 456); + expect(getMetadata(key)).toBe(456); +} + +class Foo { + @dec1 @dec2 a; +} + +function dec3(_, { setMetadata, getMetadata }) { + expect(getMetadata(key)).toBe(undefined); + setMetadata(key, 789); + expect(getMetadata(key)).toBe(789); +} + +class Bar extends Foo { + @dec3 a; +} + +expect(Foo.prototype[Symbol.metadata][key].public.a).toBe(456); +expect(Bar.prototype[Symbol.metadata][key].public.a).toBe(789); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-private/exec.js new file mode 100644 index 000000000000..d36a857a1e77 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-private/exec.js @@ -0,0 +1,16 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +class Foo { + @dec #a; +} + +class Bar extends Foo { + @dec #b; +} + +expect(Foo.prototype[Symbol.metadata][key].private).toEqual([123]); +expect(Bar.prototype[Symbol.metadata][key].private).toEqual([123, 123]); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-public/exec.js new file mode 100644 index 000000000000..666bc9601116 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-public/exec.js @@ -0,0 +1,18 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +class Foo { + @dec a; +} + +class Bar extends Foo { + @dec b; +} + +expect(Foo.prototype[Symbol.metadata][key].public.a).toEqual(123); +expect(Foo.prototype[Symbol.metadata][key].public.b).toEqual(undefined); +expect(Bar.prototype[Symbol.metadata][key].public.a).toEqual(123); +expect(Bar.prototype[Symbol.metadata][key].public.b).toEqual(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/non-symbol-keys/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/non-symbol-keys/exec.js new file mode 100644 index 000000000000..a6c8ae1af6f8 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/non-symbol-keys/exec.js @@ -0,0 +1,10 @@ +expect(() => { + const key = 'test'; + + function dec(_, { setMetadata }) { + setMetadata(key, 123); + } + + @dec + class Foo {} +}).toThrow('Metadata keys must be symbols, received: test') diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-private/exec.js new file mode 100644 index 000000000000..a10baeb36f72 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-private/exec.js @@ -0,0 +1,11 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +class Foo { + @dec #a; +} + +expect(Foo.prototype[Symbol.metadata][key].private[0]).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-public/exec.js new file mode 100644 index 000000000000..021bdaf9a5e0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-public/exec.js @@ -0,0 +1,11 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +class Foo { + @dec a; +} + +expect(Foo.prototype[Symbol.metadata][key].public.a).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-private/exec.js new file mode 100644 index 000000000000..c8453c1559ce --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-private/exec.js @@ -0,0 +1,11 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +class Foo { + @dec static #a; +} + +expect(Foo[Symbol.metadata][key].private[0]).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-public/exec.js new file mode 100644 index 000000000000..1635eab50b54 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-public/exec.js @@ -0,0 +1,11 @@ +const key = Symbol(); + +function dec(_, { setMetadata }) { + setMetadata(key, 123); +} + +class Foo { + @dec static a; +} + +expect(Foo[Symbol.metadata][key].public.a).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/exec.js new file mode 100644 index 000000000000..5a3ce1785ff0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/exec.js @@ -0,0 +1,41 @@ +function dec(fn, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return fn.call(this) + 1; + } +} + +class Foo { + value = 1; + + @dec + #a() { + return this.value; + } + + callA() { + return this.#a(); + } +} + +let foo = new Foo(); + +const aContext = foo['#aContext']; + +// First call gets the method, second call calls the method with correct `this` +expect(aContext.access.get.call(foo).call(foo)).toBe(2); +expect(foo.callA()).toBe(2); +foo.value = 123; +expect(aContext.access.get.call(foo).call(foo)).toBe(124); +expect(foo.callA()).toBe(124); + +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('method'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/input.js new file mode 100644 index 000000000000..fc7ace8128ee --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/input.js @@ -0,0 +1,12 @@ +class Foo { + value = 1; + + @dec + #a() { + return this.value; + } + + callA() { + return this.#a(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js new file mode 100644 index 000000000000..4e18191445f1 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js @@ -0,0 +1,26 @@ +var _call_a, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + writable: true, + value: _call_a + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + callA() { + return babelHelpers.classPrivateFieldGet(this, _a).call(this); + } + +} + +(() => { + [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 2, "a", function () { + return this.value; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/exec.js new file mode 100644 index 000000000000..0f27b61caa4d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/exec.js @@ -0,0 +1,50 @@ +function dec(fn, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return fn.call(this) + 1; + } +} + +class Foo { + value = 1; + + @dec + a() { + return this.value; + } + + @dec + ['b']() { + return this.value; + } +} + +let foo = new Foo(); + +const aContext = foo['aContext']; +const bContext = foo['bContext']; + +expect(foo.a()).toBe(2); +expect(foo.b()).toBe(2); +foo.value = 123; +expect(foo.a()).toBe(124); +expect(foo.b()).toBe(124); + +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('method'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('method'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/input.js new file mode 100644 index 000000000000..f364442146ea --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/input.js @@ -0,0 +1,13 @@ +class Foo { + value = 1; + + @dec + a() { + return this.value; + } + + @dec + ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js new file mode 100644 index 000000000000..1835a9fa3548 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js @@ -0,0 +1,26 @@ +var _computedKey, _dec, _dec2, _initProto; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + a() { + return this.value; + } + + [_computedKey]() { + return this.value; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, "a"], [_dec2, 2, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/exec.js new file mode 100644 index 000000000000..bab58275b48a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/exec.js @@ -0,0 +1,39 @@ +function dec(fn, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return fn.call(this) + 1; + } +} + +class Foo { + static value = 1; + + @dec + static #a() { + return this.value; + } + + static callA() { + return this.#a(); + } +} + +const aContext = Foo['#aContext']; + +// First call gets the method, second call calls the method with correct `this` +expect(aContext.access.get.call(Foo).call(Foo)).toBe(2); +expect(Foo.callA()).toBe(2); +Foo.value = 123; +expect(aContext.access.get.call(Foo).call(Foo)).toBe(124); +expect(Foo.callA()).toBe(124); + +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('method'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/input.js new file mode 100644 index 000000000000..e68191455f14 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/input.js @@ -0,0 +1,12 @@ +class Foo { + static value = 1; + + @dec + static #a() { + return this.value; + } + + static callA() { + return this.#a(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js new file mode 100644 index 000000000000..3c147c920d64 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js @@ -0,0 +1,22 @@ +var _call_a, _initStatic; + +class Foo { + static callA() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a).call(this); + } + +} + +(() => { + [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 7, "a", function () { + return this.value; + }]], []); + + _initStatic(Foo); +})(); + +var _a = { + writable: true, + value: _call_a +}; +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/exec.js new file mode 100644 index 000000000000..e68458db59d9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/exec.js @@ -0,0 +1,48 @@ +function dec(fn, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function () { + return fn.call(this) + 1; + } +} + +class Foo { + static value = 1; + + @dec + static a() { + return this.value; + } + + @dec + static ['b']() { + return this.value; + } +} + +const aContext = Foo['aContext']; +const bContext = Foo['bContext']; + +expect(Foo.a()).toBe(2); +expect(Foo.b()).toBe(2); +Foo.value = 123; +expect(Foo.a()).toBe(124); +expect(Foo.b()).toBe(124); + +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('method'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('method'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/input.js new file mode 100644 index 000000000000..77dae8711cd3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/input.js @@ -0,0 +1,13 @@ +class Foo { + static value = 1; + + @dec + static a() { + return this.value; + } + + @dec + static ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js new file mode 100644 index 000000000000..d1c334def59e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js @@ -0,0 +1,24 @@ +var _computedKey, _dec, _dec2, _initStatic; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static a() { + return this.value; + } + + static [_computedKey]() { + return this.value; + } + +} + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 7, "a"], [_dec2, 7, _computedKey]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initializer-timing/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initializer-timing/exec.js new file mode 100644 index 000000000000..ac5920dcd16a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initializer-timing/exec.js @@ -0,0 +1,34 @@ +function dec1(fn, context) { + context.addInitializer((instance) => { + expect(instance.value).toBe(undefined); + }); + + return fn; +} + +class Foo { + value = 1; + + @dec1 + foo() {} +} + +function dec2(fn, context) { + context.addInitializer((instance) => { + expect(instance.value).toBe(1); + }); + + return fn; +} + + +class Bar extends Foo { + constructor() { + super(); + + this.value = 2; + } + + @dec2 + bar() {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/input.js new file mode 100644 index 000000000000..844a924e3e80 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/input.js @@ -0,0 +1,22 @@ +@dec +@call() +@chain.expr() +@(arbitrary + expr) +@(array[expr]) +class Foo { + #a; + + @dec + @call() + @chain.expr() + @(arbitrary + expr) + @(array[expr]) + method() {} + + makeClass() { + return class Nested { + @(this.#a) + bar; + } + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js new file mode 100644 index 000000000000..79b845170bc7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js @@ -0,0 +1,40 @@ +var _initClass, _initProto; + +let _Foo; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + writable: true, + value: void 0 + }); + + _initProto(this); + } + + method() {} + + makeClass() { + var _init_bar, _class, _temp; + + return _temp = _class = class Nested { + constructor() { + babelHelpers.defineProperty(this, "bar", _init_bar(this)); + } + + }, (() => { + [_init_bar] = babelHelpers.applyDecs(_class, [[babelHelpers.classPrivateFieldGet(_class, _a), 0, "bar"]], []); + })(), _temp; + } + +} + +(() => { + [_Foo, _initClass, _initProto] = babelHelpers.applyDecs(Foo, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]); +})(); + +(() => { + _initClass(); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/exec.js new file mode 100644 index 000000000000..c2768a0a2c67 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/exec.js @@ -0,0 +1,40 @@ +function dec(set, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function (v) { + return set.call(this, v + 1); + } +} + +class Foo { + value = 1; + + @dec + set #a(v) { + return this.value = v; + } + + setA(v) { + this.#a = v; + } +} + +let foo = new Foo(); + +const aContext = foo['#aContext']; + +expect(foo.value).toBe(1); +aContext.access.set.call(foo, 123); +expect(foo.value).toBe(124); +foo.setA(456); +expect(foo.value).toBe(457); + +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('setter'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/input.js new file mode 100644 index 000000000000..254f2f102f9a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/input.js @@ -0,0 +1,12 @@ +class Foo { + value = 1; + + @dec + set #a(v) { + return this.value = v; + } + + setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js new file mode 100644 index 000000000000..5d0ad516b80b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js @@ -0,0 +1,30 @@ +var _call_a, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: void 0, + set: _set_a + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + setA(v) { + babelHelpers.classPrivateFieldSet(this, _a, v); + } + +} + +function _set_a(v) { + _call_a(this, v); +} + +(() => { + [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 4, "a", function (v) { + return this.value = v; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/exec.js new file mode 100644 index 000000000000..ab2f98534b95 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/exec.js @@ -0,0 +1,50 @@ +function dec(set, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function (v) { + return set.call(this, v + 1); + } +} + +class Foo { + value = 1; + + @dec + set a(v) { + return this.value = v; + } + + @dec + set ['b'](v) { + return this.value = v; + } +} + +let foo = new Foo(); + +const aContext = foo['aContext']; +const bContext = foo['bContext']; + +expect(foo.value).toBe(1); +foo.a = 123; +expect(foo.value).toBe(124); +foo.a = 456; +expect(foo.value).toBe(457); + +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('setter'); +expect(aContext.isStatic).toBe(false); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('setter'); +expect(bContext.isStatic).toBe(false); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/input.js new file mode 100644 index 000000000000..b8b837257ff0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/input.js @@ -0,0 +1,13 @@ +class Foo { + value = 1; + + @dec + set a(v) { + return this.value = v; + } + + @dec + set ['b'](v) { + return this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js new file mode 100644 index 000000000000..256297632372 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js @@ -0,0 +1,26 @@ +var _computedKey, _dec, _dec2, _initProto; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + set a(v) { + return this.value = v; + } + + set [_computedKey](v) { + return this.value = v; + } + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 4, "a"], [_dec2, 4, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/exec.js new file mode 100644 index 000000000000..55ecade3ac96 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/exec.js @@ -0,0 +1,38 @@ +function dec(set, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function (v) { + return set.call(this, v + 1); + } +} + +class Foo { + static value = 1; + + @dec + static set #a(v) { + return this.value = v; + } + + static setA(v) { + this.#a = v; + } +} + +const aContext = Foo['#aContext']; + +expect(Foo.value).toBe(1); +aContext.access.set.call(Foo, 123); +expect(Foo.value).toBe(124); +Foo.setA(456); +expect(Foo.value).toBe(457); + +expect(aContext.name).toBe('#a'); +expect(aContext.kind).toBe('setter'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(true); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/input.js new file mode 100644 index 000000000000..0038d6b6bd30 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/input.js @@ -0,0 +1,12 @@ +class Foo { + static value = 1; + + @dec + static set #a(v) { + return this.value = v; + } + + static setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js new file mode 100644 index 000000000000..45e47a57177c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js @@ -0,0 +1,27 @@ +var _call_a, _initStatic; + +class Foo { + static setA(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, v); + } + +} + +function _set_a(v) { + _call_a(this, v); +} + +var _a = { + get: void 0, + set: _set_a +}; + +(() => { + [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 9, "a", function (v) { + return this.value = v; + }]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/exec.js new file mode 100644 index 000000000000..2e7eb639048c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/exec.js @@ -0,0 +1,49 @@ +function dec(set, context) { + context.addInitializer((instance) => { + instance[context.name + 'Context'] = context; + }); + + return function (v) { + return set.call(this, v + 1); + } +} + +class Foo { + static value = 1; + + @dec + static set a(v) { + return this.value = v; + } + + @dec + static set ['b'](v) { + return this.value = v; + } +} + +const aContext = Foo['aContext']; +const bContext = Foo['bContext']; + + +expect(Foo.value).toBe(1); +Foo.a = 123; +expect(Foo.value).toBe(124); +Foo.a = 456; +expect(Foo.value).toBe(457); + +expect(aContext.name).toBe('a'); +expect(aContext.kind).toBe('setter'); +expect(aContext.isStatic).toBe(true); +expect(aContext.isPrivate).toBe(false); +expect(typeof aContext.addInitializer).toBe('function'); +expect(typeof aContext.setMetadata).toBe('function'); +expect(typeof aContext.getMetadata).toBe('function'); + +expect(bContext.name).toBe('b'); +expect(bContext.kind).toBe('setter'); +expect(bContext.isStatic).toBe(true); +expect(bContext.isPrivate).toBe(false); +expect(typeof bContext.addInitializer).toBe('function'); +expect(typeof bContext.setMetadata).toBe('function'); +expect(typeof bContext.getMetadata).toBe('function'); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/input.js new file mode 100644 index 000000000000..0cca65be7fa3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/input.js @@ -0,0 +1,13 @@ +class Foo { + static value = 1; + + @dec + static set a(v) { + return this.value = v; + } + + @dec + static set ['b'](v) { + return this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js new file mode 100644 index 000000000000..e890b8fb8d4a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js @@ -0,0 +1,24 @@ +var _computedKey, _dec, _dec2, _initStatic; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static set a(v) { + return this.value = v; + } + + static set [_computedKey](v) { + return this.value = v; + } + +} + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 9, "a"], [_dec2, 9, _computedKey]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/input.js new file mode 100644 index 000000000000..be4f348923bc --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + accessor #a; + + @dec + accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js new file mode 100644 index 000000000000..c054a288032a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js @@ -0,0 +1,35 @@ +var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto; + +class Foo { + static { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = babelHelpers.applyDecs(this, [[dec, 1, "a", function () { + return this.#A; + }, function (value) { + this.#A = value; + }], [dec, 1, "b", function () { + return this.#B; + }, function (value) { + this.#B = value; + }]], []); + } + #A = (_initProto(this), _init_a(this)); + + set #a(v) { + _set_a(this, v); + } + + get #a() { + _get_a(this); + } + + #B = _init_b(this, 123); + + set #b(v) { + _set_b(this, v); + } + + get #b() { + _get_b(this); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/input.js new file mode 100644 index 000000000000..5945d3196f1d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + accessor a; + + @dec + accessor b = 123; + + @dec + accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js new file mode 100644 index 000000000000..0fb94194b1db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js @@ -0,0 +1,42 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initProto; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + static { + [_init_a, _init_b, _init_computedKey, _initProto] = babelHelpers.applyDecs(this, [[_dec, 1, "a"], [_dec2, 1, "b"], [_dec3, 1, _computedKey]], []); + } + #A = (_initProto(this), _init_a(this)); + + get a() { + return this.#A; + } + + set a(v) { + this.#A = v; + } + + #B = _init_b(this, 123); + + get b() { + return this.#B; + } + + set b(v) { + this.#B = v; + } + + #C = _init_computedKey(this, 456); + + get [_computedKey]() { + return this.#C; + } + + set [_computedKey](v) { + this.#C = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/input.js new file mode 100644 index 000000000000..ebb88a741572 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + static accessor #a; + + @dec + static accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js new file mode 100644 index 000000000000..ad30531a425e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js @@ -0,0 +1,38 @@ +var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic; + +class Foo { + static { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(this, [[dec, 6, "a", function () { + return this.#A; + }, function (value) { + this.#A = value; + }], [dec, 6, "b", function () { + return this.#B; + }, function (value) { + this.#B = value; + }]], []); + + _initStatic(this); + + } + static #A = _init_a(this); + + set #a(v) { + _set_a(this, v); + } + + get #a() { + _get_a(this); + } + + static #B = _init_b(this, 123); + + set #b(v) { + _set_b(this, v); + } + + get #b() { + _get_b(this); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/input.js new file mode 100644 index 000000000000..edf06478601f --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + static accessor a; + + @dec + static accessor b = 123; + + @dec + static accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js new file mode 100644 index 000000000000..471adf36f9c9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js @@ -0,0 +1,45 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initStatic; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + static { + [_init_a, _init_b, _init_computedKey, _initStatic] = babelHelpers.applyDecs(this, [[_dec, 6, "a"], [_dec2, 6, "b"], [_dec3, 6, _computedKey]], []); + + _initStatic(this); + + } + static #A = _init_a(this); + + static get a() { + return this.#A; + } + + static set a(v) { + this.#A = v; + } + + static #B = _init_b(this, 123); + + static get b() { + return this.#B; + } + + static set b(v) { + this.#B = v; + } + + static #C = _init_computedKey(this, 456); + + static get [_computedKey]() { + return this.#C; + } + + static set [_computedKey](v) { + this.#C = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/input.js new file mode 100644 index 000000000000..4afc45261337 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/input.js @@ -0,0 +1,5 @@ +class Foo { + accessor #a; + + accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js new file mode 100644 index 000000000000..9eb7268e4131 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js @@ -0,0 +1,22 @@ +class Foo { + #A; + + get #a() { + return this.#A; + } + + set #a(v) { + this.#A = v; + } + + #B = 123; + + get #b() { + return this.#B; + } + + set #b(v) { + this.#B = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/input.js new file mode 100644 index 000000000000..ad27f18d5ed3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/input.js @@ -0,0 +1,7 @@ +class Foo { + accessor a; + + accessor b = 123; + + accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js new file mode 100644 index 000000000000..f6269be736f1 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js @@ -0,0 +1,32 @@ +class Foo { + #A; + + get a() { + return this.#A; + } + + set a(v) { + this.#A = v; + } + + #B = 123; + + get b() { + return this.#B; + } + + set b(v) { + this.#B = v; + } + + #C = 456; + + get 'c'() { + return this.#C; + } + + set 'c'(v) { + this.#C = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/input.js new file mode 100644 index 000000000000..2e516a961de9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/input.js @@ -0,0 +1,5 @@ +class Foo { + static accessor #a; + + static accessor #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js new file mode 100644 index 000000000000..04cc0ef030d0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js @@ -0,0 +1,22 @@ +class Foo { + static #A; + + static get #a() { + return this.#A; + } + + static set #a(v) { + this.#A = v; + } + + static #B = 123; + + static get #b() { + return this.#B; + } + + static set #b(v) { + this.#B = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/input.js new file mode 100644 index 000000000000..160e72cd531c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/input.js @@ -0,0 +1,7 @@ +class Foo { + static accessor a; + + static accessor b = 123; + + static accessor ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js new file mode 100644 index 000000000000..187ad5214a67 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js @@ -0,0 +1,32 @@ +class Foo { + static #A; + + static get a() { + return this.#A; + } + + static set a(v) { + this.#A = v; + } + + static #B = 123; + + static get b() { + return this.#B; + } + + static set b(v) { + this.#B = v; + } + + static #C = 456; + + static get 'c'() { + return this.#C; + } + + static set 'c'(v) { + this.#C = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/input.js new file mode 100644 index 000000000000..542bf870c079 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/input.js @@ -0,0 +1,11 @@ +const A = @dec class A {} +const B = @dec class C {} +const D = @dec class {} +const E = (@dec class {}, 123); +const F = [@dec class G {}, @dec class {}]; +const H = @dec class extends I {}; +const J = @dec class K extends L {}; + +function classFactory() { + return @dec class {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js new file mode 100644 index 000000000000..146cdb17ca70 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js @@ -0,0 +1,87 @@ +var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _initClass8, _K; + +const A = (class A { + static { + [_A, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass(); + + } +}, _A); +const B = (class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass2(); + + } +}, _C); +const D = (class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass3(); + + } +}, _D); +const E = ((class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass4(); + + } +}, _decorated_class), 123); +const F = [(class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass5(); + + } +}, _G), (class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass6(); + + } +}, _decorated_class2)]; +const H = (class H extends I { + static { + [_H, _initClass7] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass7(); + + } +}, _H); +const J = (class K extends L { + static { + [_K, _initClass8] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass8(); + + } +}, _K); + +function classFactory() { + var _initClass9, _decorated_class3; + + return class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass9(); + + } + }, _decorated_class3; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/input.js new file mode 100644 index 000000000000..7a4a6684555a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/input.js @@ -0,0 +1,5 @@ +@dec1 +class Bar {} + +@dec2 +class Foo extends Bar {} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js new file mode 100644 index 000000000000..d7ea9b35166e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js @@ -0,0 +1,25 @@ +var _initClass, _initClass2; + +let _Bar; + +class Bar { + static { + [_Bar, _initClass] = babelHelpers.applyDecs(this, [], [dec1]); + } + static { + _initClass(); + + } +} + +let _Foo; + +class Foo extends _Bar { + static { + [_Foo, _initClass2] = babelHelpers.applyDecs(this, [], [dec2]); + } + static { + _initClass2(); + + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/input.js new file mode 100644 index 000000000000..deeb483448f7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/input.js @@ -0,0 +1,13 @@ +@dec +class Foo { + static field = 123; +} + +@dec +class Bar extends Foo { + static { + this.otherField = 456; + } + + static field = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js new file mode 100644 index 000000000000..c4b21cf992e6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js @@ -0,0 +1,30 @@ +var _initClass, _initClass2; + +let _Foo; + +class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + static field = 123; + static { + _initClass(); + + } +} + +let _Bar; + +class Bar extends _Foo { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + this.otherField = 456; + } + static field = 123; + static { + _initClass2(); + + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/input.js new file mode 100644 index 000000000000..fde7feb1abd7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/input.js @@ -0,0 +1,6 @@ +const Foo = @dec class Bar { + bar = new Bar(); +}; + +const foo = new Foo(); + diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js new file mode 100644 index 000000000000..4c37edebb1dd --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js @@ -0,0 +1,13 @@ +var _initClass, _Bar; + +const Foo = (class Bar { + static { + [_Bar, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + bar = new _Bar(); + static { + _initClass(); + + } +}, _Bar); +const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/input.js new file mode 100644 index 000000000000..e6da5000db62 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/input.js @@ -0,0 +1,6 @@ +@dec +class Foo { + static foo = new Foo(); +} + +const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js new file mode 100644 index 000000000000..046ba5f9a759 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js @@ -0,0 +1,16 @@ +var _initClass; + +let _Foo; + +class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + static foo = new _Foo(); + static { + _initClass(); + + } +} + +const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/input.js new file mode 100644 index 000000000000..2ca438188867 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/input.js @@ -0,0 +1,11 @@ +class Foo { + @dec + [getKey()]() { + return 1; + } + + @dec + [getKey()]() { + return 2; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js new file mode 100644 index 000000000000..9663aebaf7b3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js @@ -0,0 +1,25 @@ +var _computedKey, _computedKey2, _dec, _dec2, _initProto; + +_computedKey = getKey() +_dec = dec +_computedKey2 = getKey() +_dec2 = dec + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); + } + + constructor(...args) { + _initProto(this); + } + + [_computedKey]() { + return 1; + } + + [_computedKey2]() { + return 2; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/input.js new file mode 100644 index 000000000000..8aeb57759b76 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/input.js @@ -0,0 +1,11 @@ +class Foo { + @dec + [getKeyI()]() { + return 1; + } + + @dec + [getKeyJ()]() { + return 2; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js new file mode 100644 index 000000000000..76d9f05cad75 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js @@ -0,0 +1,25 @@ +var _computedKey, _computedKey2, _dec, _dec2, _initProto; + +_computedKey = getKeyI() +_dec = dec +_computedKey2 = getKeyJ() +_dec2 = dec + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); + } + + constructor(...args) { + _initProto(this); + } + + [_computedKey]() { + return 1; + } + + [_computedKey2]() { + return 2; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/input.js new file mode 100644 index 000000000000..522da0061204 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/input.js @@ -0,0 +1,9 @@ +class Foo { + @dec + a = 123; + + @dec + a() { + return 1; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js new file mode 100644 index 000000000000..cb04e3cc2e5d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js @@ -0,0 +1,13 @@ +var _init_a, _initProto; + +class Foo { + static { + [_init_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 0, "a"], [dec, 2, "a"]], []); + } + a = (_initProto(this), _init_a(this, 123)); + + a() { + return 1; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/input.js new file mode 100644 index 000000000000..db90a40aa67b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/input.js @@ -0,0 +1,11 @@ +class Foo { + @dec + a() { + return 1; + } + + @dec + a() { + return 2; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js new file mode 100644 index 000000000000..c4befb4def4d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js @@ -0,0 +1,20 @@ +var _initProto; + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a"], [dec, 2, "a"]], []); + } + + constructor(...args) { + _initProto(this); + } + + a() { + return 1; + } + + a() { + return 2; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/input.js new file mode 100644 index 000000000000..222ec09fc95e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + #a; + + @dec + #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js new file mode 100644 index 000000000000..b72a6d971df6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js @@ -0,0 +1,17 @@ +var _init_a, _init_b; + +class Foo { + static { + [_init_a, _init_b] = babelHelpers.applyDecs(this, [[dec, 0, "a", function () { + return this.#a; + }, function (value) { + this.#a = value; + }], [dec, 0, "b", function () { + return this.#b; + }, function (value) { + this.#b = value; + }]], []); + } + #a = _init_a(this); + #b = _init_b(this, 123); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/input.js new file mode 100644 index 000000000000..8dff95c99a3a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + a; + + @dec + b = 123; + + @dec + ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js new file mode 100644 index 000000000000..06c0434d04a6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js @@ -0,0 +1,15 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + static { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(this, [[_dec, 0, "a"], [_dec2, 0, "b"], [_dec3, 0, _computedKey]], []); + } + a = _init_a(this); + b = _init_b(this, 123); + [_computedKey] = _init_computedKey(this, 456); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/input.js new file mode 100644 index 000000000000..830d82321863 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec + static #a; + + @dec + static #b = 123; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js new file mode 100644 index 000000000000..cb167ff192fd --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js @@ -0,0 +1,17 @@ +var _init_a, _init_b; + +class Foo { + static { + [_init_a, _init_b] = babelHelpers.applyDecs(this, [[dec, 5, "a", function () { + return this.#a; + }, function (value) { + this.#a = value; + }], [dec, 5, "b", function () { + return this.#b; + }, function (value) { + this.#b = value; + }]], []); + } + static #a = _init_a(this); + static #b = _init_b(this, 123); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/input.js new file mode 100644 index 000000000000..9b9dae98314a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/input.js @@ -0,0 +1,10 @@ +class Foo { + @dec + static a; + + @dec + static b = 123; + + @dec + static ['c'] = 456; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js new file mode 100644 index 000000000000..64af25745500 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js @@ -0,0 +1,15 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + static { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(this, [[_dec, 5, "a"], [_dec2, 5, "b"], [_dec3, 5, _computedKey]], []); + } + static a = _init_a(this); + static b = _init_b(this, 123); + static [_computedKey] = _init_computedKey(this, 456); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/input.js new file mode 100644 index 000000000000..060ae225a21e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/input.js @@ -0,0 +1,21 @@ +class Foo { + value = 1; + + @dec + get #a() { + return this.value; + } + + @dec + set #a(v) { + this.value = v; + } + + getA() { + return this.#a; + } + + setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js new file mode 100644 index 000000000000..bcf3cae9176e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js @@ -0,0 +1,34 @@ +var _call_a, _call_a2, _initProto; + +class Foo { + static { + [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a", function () { + return this.value; + }], [dec, 4, "a", function (v) { + this.value = v; + }]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + get #a() { + return _call_a(this); + } + + set #a(v) { + _call_a2(this, v); + } + + getA() { + return this.#a; + } + + setA(v) { + this.#a = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/input.js new file mode 100644 index 000000000000..ef384166d689 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/input.js @@ -0,0 +1,23 @@ +class Foo { + value = 1; + + @dec + get a() { + return this.value; + } + + @dec + set a(v) { + this.value = v; + } + + @dec + get ['b']() { + return this.value; + } + + @dec + set ['b'](v) { + this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js new file mode 100644 index 000000000000..1a7c8951454d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js @@ -0,0 +1,37 @@ +var _computedKey, _computedKey2, _dec, _dec2, _dec3, _dec4, _initProto; + +_dec = dec +_dec2 = dec +_computedKey = 'b' +_dec3 = dec +_computedKey2 = 'b' +_dec4 = dec + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 3, "a"], [_dec2, 4, "a"], [_dec3, 3, _computedKey], [_dec4, 4, _computedKey2]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + get a() { + return this.value; + } + + set a(v) { + this.value = v; + } + + get [_computedKey]() { + return this.value; + } + + set [_computedKey2](v) { + this.value = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/input.js new file mode 100644 index 000000000000..f439a9152528 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/input.js @@ -0,0 +1,21 @@ +class Foo { + static value = 1; + + @dec + static get #a() { + return this.value; + } + + @dec + static set #a(v) { + this.value = v; + } + + static getA() { + return this.#a; + } + + static setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js new file mode 100644 index 000000000000..e897ea3cd18e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js @@ -0,0 +1,32 @@ +var _call_a, _call_a2, _initStatic; + +class Foo { + static { + [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a", function () { + return this.value; + }], [dec, 9, "a", function (v) { + this.value = v; + }]], []); + + _initStatic(this); + + } + static value = 1; + + static get #a() { + return _call_a(this); + } + + static set #a(v) { + _call_a2(this, v); + } + + static getA() { + return this.#a; + } + + static setA(v) { + this.#a = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/input.js new file mode 100644 index 000000000000..193bf7b836a2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/input.js @@ -0,0 +1,23 @@ +class Foo { + static value = 1; + + @dec + static get a() { + return this.value; + } + + @dec + static set a(v) { + this.value = v; + } + + @dec + static get ['b']() { + return this.value; + } + + @dec + static set ['b'](v) { + this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js new file mode 100644 index 000000000000..367b9d127fd7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js @@ -0,0 +1,35 @@ +var _computedKey, _computedKey2, _dec, _dec2, _dec3, _dec4, _initStatic; + +_dec = dec +_dec2 = dec +_computedKey = 'b' +_dec3 = dec +_computedKey2 = 'b' +_dec4 = dec + +class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 8, "a"], [_dec2, 9, "a"], [_dec3, 8, _computedKey], [_dec4, 9, _computedKey2]], []); + + _initStatic(this); + + } + static value = 1; + + static get a() { + return this.value; + } + + static set a(v) { + this.value = v; + } + + static get [_computedKey]() { + return this.value; + } + + static set [_computedKey2](v) { + this.value = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/input.js new file mode 100644 index 000000000000..49c601a1dd5b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/input.js @@ -0,0 +1,12 @@ +class Foo { + value = 1; + + @dec + get #a() { + return this.value; + } + + getA() { + return this.#a; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js new file mode 100644 index 000000000000..06ba2926bfa4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js @@ -0,0 +1,24 @@ +var _call_a, _initProto; + +class Foo { + static { + [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a", function () { + return this.value; + }]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + get #a() { + return _call_a(this); + } + + getA() { + return this.#a; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/input.js new file mode 100644 index 000000000000..9d1cbae52f1d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/input.js @@ -0,0 +1,13 @@ +class Foo { + value = 1; + + @dec + get a() { + return this.value; + } + + @dec + get ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js new file mode 100644 index 000000000000..756adf797e3b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js @@ -0,0 +1,26 @@ +var _computedKey, _dec, _dec2, _initProto; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 3, "a"], [_dec2, 3, _computedKey]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + get a() { + return this.value; + } + + get [_computedKey]() { + return this.value; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/input.js new file mode 100644 index 000000000000..90edd26364d8 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/input.js @@ -0,0 +1,12 @@ +class Foo { + static value = 1; + + @dec + static get #a() { + return this.value; + } + + static getA() { + return this.#a; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js new file mode 100644 index 000000000000..dc93a5313712 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js @@ -0,0 +1,22 @@ +var _call_a, _initStatic; + +class Foo { + static { + [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a", function () { + return this.value; + }]], []); + + _initStatic(this); + + } + static value = 1; + + static get #a() { + return _call_a(this); + } + + static getA() { + return this.#a; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/input.js new file mode 100644 index 000000000000..1383fa58abf4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/input.js @@ -0,0 +1,13 @@ +class Foo { + static value = 1; + + @dec + static get a() { + return this.value; + } + + @dec + static get ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js new file mode 100644 index 000000000000..2ec6f560dc4b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js @@ -0,0 +1,24 @@ +var _computedKey, _dec, _dec2, _initStatic; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 8, "a"], [_dec2, 8, _computedKey]], []); + + _initStatic(this); + + } + static value = 1; + + static get a() { + return this.value; + } + + static get [_computedKey]() { + return this.value; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/options.json new file mode 100644 index 000000000000..9629f07e45ec --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ], + "assumptions": { + "constantSuper": true + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/input.js new file mode 100644 index 000000000000..ebd79d22da06 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/input.js @@ -0,0 +1,6 @@ +@dec +class Foo extends Bar { + constructor() { + let foo = super(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/output.js new file mode 100644 index 000000000000..dcf5a0fae917 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/output.js @@ -0,0 +1,18 @@ +var _initClass; + +let _Foo; + +class Foo extends Bar { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + + constructor() { + let foo = super(); + } + + static { + _initClass(); + + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/input.js new file mode 100644 index 000000000000..4be504d54e70 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/input.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + @dec + get #x() { + return super.foo(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/output.js new file mode 100644 index 000000000000..17cd5aa63e11 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/output.js @@ -0,0 +1,20 @@ +var _call_x, _initProto; + +class Foo extends Bar { + static { + [_call_x, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "x", function () { + return Bar.prototype.foo.call(this); + }]], []); + } + + constructor(...args) { + super(...args); + + _initProto(this); + } + + get #x() { + return _call_x(this); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/input.js new file mode 100644 index 000000000000..73200f5f673d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/input.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + @dec + #x() { + return super.foo(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/output.js new file mode 100644 index 000000000000..91246a1f387a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/output.js @@ -0,0 +1,17 @@ +var _call_x, _initProto; + +class Foo extends Bar { + static { + [_call_x, _initProto] = babelHelpers.applyDecs(this, [[dec, 2, "x", function () { + return Bar.prototype.foo.call(this); + }]], []); + } + + constructor(...args) { + super(...args); + + _initProto(this); + } + + #x = _call_x; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/input.js new file mode 100644 index 000000000000..fc7ace8128ee --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/input.js @@ -0,0 +1,12 @@ +class Foo { + value = 1; + + @dec + #a() { + return this.value; + } + + callA() { + return this.#a(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js new file mode 100644 index 000000000000..6f76b6021b6c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js @@ -0,0 +1,21 @@ +var _call_a, _initProto; + +class Foo { + static { + [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a", function () { + return this.value; + }]], []); + } + + constructor(...args) { + _initProto(this); + } + + #a = _call_a; + value = 1; + + callA() { + return this.#a(); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/input.js new file mode 100644 index 000000000000..f364442146ea --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/input.js @@ -0,0 +1,13 @@ +class Foo { + value = 1; + + @dec + a() { + return this.value; + } + + @dec + ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js new file mode 100644 index 000000000000..efac40c1c35e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js @@ -0,0 +1,26 @@ +var _computedKey, _dec, _dec2, _initProto; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, "a"], [_dec2, 2, _computedKey]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + a() { + return this.value; + } + + [_computedKey]() { + return this.value; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/input.js new file mode 100644 index 000000000000..e68191455f14 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/input.js @@ -0,0 +1,12 @@ +class Foo { + static value = 1; + + @dec + static #a() { + return this.value; + } + + static callA() { + return this.#a(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js new file mode 100644 index 000000000000..6b807803efa6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js @@ -0,0 +1,19 @@ +var _call_a, _initStatic; + +class Foo { + static { + [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 7, "a", function () { + return this.value; + }]], []); + + _initStatic(this); + + } + static #a = _call_a; + static value = 1; + + static callA() { + return this.#a(); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/input.js new file mode 100644 index 000000000000..77dae8711cd3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/input.js @@ -0,0 +1,13 @@ +class Foo { + static value = 1; + + @dec + static a() { + return this.value; + } + + @dec + static ['b']() { + return this.value; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js new file mode 100644 index 000000000000..1ad76b111fb4 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js @@ -0,0 +1,24 @@ +var _computedKey, _dec, _dec2, _initStatic; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 7, "a"], [_dec2, 7, _computedKey]], []); + + _initStatic(this); + + } + static value = 1; + + static a() { + return this.value; + } + + static [_computedKey]() { + return this.value; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/input.js new file mode 100644 index 000000000000..ff2a3c43e415 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec #x() {} + + bar() { + ([this.#x] = this.baz); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/options.json new file mode 100644 index 000000000000..188eae592ec5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/input.js new file mode 100644 index 000000000000..34df0b29ed8b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec #x() {} + + bar() { + for (this.#x of this.baz); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/options.json new file mode 100644 index 000000000000..188eae592ec5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/input.js new file mode 100644 index 000000000000..56e2501e42e1 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec #x() {} + + bar() { + ({ x: this.#x } = this.baz); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/options.json new file mode 100644 index 000000000000..188eae592ec5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/input.js new file mode 100644 index 000000000000..c24cac0560ad --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec #x() {} + + bar() { + ([...this.#x] = this.baz); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/options.json new file mode 100644 index 000000000000..188eae592ec5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/input.js new file mode 100644 index 000000000000..f3b235ffe0df --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec #x() {} + + bar() { + this.#x++; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/options.json new file mode 100644 index 000000000000..188eae592ec5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/input.js new file mode 100644 index 000000000000..46f4ecf6453b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/input.js @@ -0,0 +1,7 @@ +class Foo { + @dec #x() {} + + bar() { + this.#x = 123; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/options.json new file mode 100644 index 000000000000..188eae592ec5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorated private methods are not updatable, but \"#x\" is updated via this expression." +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/input.js new file mode 100644 index 000000000000..ebd79d22da06 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/input.js @@ -0,0 +1,6 @@ +@dec +class Foo extends Bar { + constructor() { + let foo = super(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/output.js new file mode 100644 index 000000000000..dcf5a0fae917 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/output.js @@ -0,0 +1,18 @@ +var _initClass; + +let _Foo; + +class Foo extends Bar { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + + constructor() { + let foo = super(); + } + + static { + _initClass(); + + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/input.js new file mode 100644 index 000000000000..4be504d54e70 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/input.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + @dec + get #x() { + return super.foo(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/output.js new file mode 100644 index 000000000000..dea033cc9d65 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/output.js @@ -0,0 +1,20 @@ +var _call_x, _initProto; + +class Foo extends Bar { + static { + [_call_x, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "x", function () { + return babelHelpers.get(babelHelpers.getPrototypeOf(Foo), "foo", this).call(this); + }]], []); + } + + constructor(...args) { + super(...args); + + _initProto(this); + } + + get #x() { + return _call_x(this); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/input.js new file mode 100644 index 000000000000..73200f5f673d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/input.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + @dec + #x() { + return super.foo(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/output.js new file mode 100644 index 000000000000..b77541b7c254 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/output.js @@ -0,0 +1,17 @@ +var _call_x, _initProto; + +class Foo extends Bar { + static { + [_call_x, _initProto] = babelHelpers.applyDecs(this, [[dec, 2, "x", function () { + return babelHelpers.get(babelHelpers.getPrototypeOf(Foo), "foo", this).call(this); + }]], []); + } + + constructor(...args) { + super(...args); + + _initProto(this); + } + + #x = _call_x; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/input.js new file mode 100644 index 000000000000..844a924e3e80 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/input.js @@ -0,0 +1,22 @@ +@dec +@call() +@chain.expr() +@(arbitrary + expr) +@(array[expr]) +class Foo { + #a; + + @dec + @call() + @chain.expr() + @(arbitrary + expr) + @(array[expr]) + method() {} + + makeClass() { + return class Nested { + @(this.#a) + bar; + } + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js new file mode 100644 index 000000000000..5490137a9009 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js @@ -0,0 +1,33 @@ +var _initClass, _initProto; + +let _Foo; + +class Foo { + static { + [_Foo, _initClass, _initProto] = babelHelpers.applyDecs(this, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]); + } + + constructor(...args) { + _initProto(this); + } + + #a; + + method() {} + + makeClass() { + var _init_bar; + + return class Nested { + static { + [_init_bar] = babelHelpers.applyDecs(this, [[this.#a, 0, "bar"]], []); + } + bar = _init_bar(this); + }; + } + + static { + _initClass(); + + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json new file mode 100644 index 000000000000..18aa205580db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/input.js new file mode 100644 index 000000000000..254f2f102f9a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/input.js @@ -0,0 +1,12 @@ +class Foo { + value = 1; + + @dec + set #a(v) { + return this.value = v; + } + + setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js new file mode 100644 index 000000000000..a1b2e04ab8f1 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js @@ -0,0 +1,24 @@ +var _call_a, _initProto; + +class Foo { + static { + [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 4, "a", function (v) { + return this.value = v; + }]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + set #a(v) { + _call_a(this, v); + } + + setA(v) { + this.#a = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/input.js new file mode 100644 index 000000000000..b8b837257ff0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/input.js @@ -0,0 +1,13 @@ +class Foo { + value = 1; + + @dec + set a(v) { + return this.value = v; + } + + @dec + set ['b'](v) { + return this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js new file mode 100644 index 000000000000..ad6f2edce743 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js @@ -0,0 +1,26 @@ +var _computedKey, _dec, _dec2, _initProto; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 4, "a"], [_dec2, 4, _computedKey]], []); + } + + constructor(...args) { + _initProto(this); + } + + value = 1; + + set a(v) { + return this.value = v; + } + + set [_computedKey](v) { + return this.value = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/input.js new file mode 100644 index 000000000000..0038d6b6bd30 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/input.js @@ -0,0 +1,12 @@ +class Foo { + static value = 1; + + @dec + static set #a(v) { + return this.value = v; + } + + static setA(v) { + this.#a = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js new file mode 100644 index 000000000000..6bcadc0cc528 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js @@ -0,0 +1,22 @@ +var _call_a, _initStatic; + +class Foo { + static { + [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 9, "a", function (v) { + return this.value = v; + }]], []); + + _initStatic(this); + + } + static value = 1; + + static set #a(v) { + _call_a(this, v); + } + + static setA(v) { + this.#a = v; + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/input.js new file mode 100644 index 000000000000..0cca65be7fa3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/input.js @@ -0,0 +1,13 @@ +class Foo { + static value = 1; + + @dec + static set a(v) { + return this.value = v; + } + + @dec + static set ['b'](v) { + return this.value = v; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js new file mode 100644 index 000000000000..230ee2bc8aff --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js @@ -0,0 +1,24 @@ +var _computedKey, _dec, _dec2, _initStatic; + +_dec = dec +_computedKey = 'b' +_dec2 = dec + +class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 9, "a"], [_dec2, 9, _computedKey]], []); + + _initStatic(this); + + } + static value = 1; + + static set a(v) { + return this.value = v; + } + + static set [_computedKey](v) { + return this.value = v; + } + +} diff --git a/packages/babel-plugin-syntax-decorators/src/index.ts b/packages/babel-plugin-syntax-decorators/src/index.ts index a825adfd77a5..5f43d029b7af 100644 --- a/packages/babel-plugin-syntax-decorators/src/index.ts +++ b/packages/babel-plugin-syntax-decorators/src/index.ts @@ -3,7 +3,7 @@ import { declare } from "@babel/helper-plugin-utils"; export default declare((api, options) => { api.assertVersion(7); - const { legacy = false } = options; + const { legacy = false, version } = options; if (typeof legacy !== "boolean") { throw new Error("'legacy' must be a boolean."); } @@ -29,6 +29,12 @@ export default declare((api, options) => { } } + if ( + !(version === "2021-12" || version === "2018-09" || version === undefined) + ) { + throw new Error("Unsupported decorators version: " + version); + } + return { name: "syntax-decorators", @@ -38,6 +44,11 @@ export default declare((api, options) => { ? "decorators-legacy" : ["decorators", { decoratorsBeforeExport }], ); + + if (version === "2021-12") { + parserOpts.plugins.push("decoratorAutoAccessors"); + parserOpts.plugins.push("classStaticBlock"); + } }, }; }); diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index 217b7b8fa822..89e1bfa3e572 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -18,6 +18,15 @@ "regenerator-runtime": "^0.13.4" }, "exports": { + "./helpers/applyDecs": [ + { + "node": "./helpers/applyDecs.js", + "import": "./helpers/esm/applyDecs.js", + "default": "./helpers/applyDecs.js" + }, + "./helpers/applyDecs.js" + ], + "./helpers/esm/applyDecs": "./helpers/esm/applyDecs.js", "./helpers/asyncIterator": [ { "node": "./helpers/asyncIterator.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index 254c7a2c3518..17f1ca246f3e 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -17,6 +17,15 @@ "regenerator-runtime": "^0.13.4" }, "exports": { + "./helpers/applyDecs": [ + { + "node": "./helpers/applyDecs.js", + "import": "./helpers/esm/applyDecs.js", + "default": "./helpers/applyDecs.js" + }, + "./helpers/applyDecs.js" + ], + "./helpers/esm/applyDecs": "./helpers/esm/applyDecs.js", "./helpers/asyncIterator": [ { "node": "./helpers/asyncIterator.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index 9f58421f4e17..0178026eca7f 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -17,6 +17,15 @@ "regenerator-runtime": "^0.13.4" }, "exports": { + "./helpers/applyDecs": [ + { + "node": "./helpers/applyDecs.js", + "import": "./helpers/esm/applyDecs.js", + "default": "./helpers/applyDecs.js" + }, + "./helpers/applyDecs.js" + ], + "./helpers/esm/applyDecs": "./helpers/esm/applyDecs.js", "./helpers/asyncIterator": [ { "node": "./helpers/asyncIterator.js", diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index 5e6547f5e991..f750429c735d 100644 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -736,8 +736,10 @@ export interface ClassBody extends BaseNode { | ClassPrivateMethod | ClassProperty | ClassPrivateProperty + | ClassAccessorProperty | TSDeclareMethod | TSIndexSignature + | StaticBlock >; } diff --git a/packages/babel-types/src/builders/generated/index.ts b/packages/babel-types/src/builders/generated/index.ts index 5ba1190e4145..130814020c40 100644 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -344,8 +344,10 @@ export function classBody( | t.ClassPrivateMethod | t.ClassProperty | t.ClassPrivateProperty + | t.ClassAccessorProperty | t.TSDeclareMethod | t.TSIndexSignature + | t.StaticBlock >, ): t.ClassBody { return builder.apply("ClassBody", arguments); diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 5c38150c6a46..df9783987d60 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -1262,8 +1262,10 @@ defineType("ClassBody", { "ClassPrivateMethod", "ClassProperty", "ClassPrivateProperty", + "ClassAccessorProperty", "TSDeclareMethod", "TSIndexSignature", + "StaticBlock", ), ), ), diff --git a/yarn.lock b/yarn.lock index 4495d77b7ccd..162df8780152 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1295,9 +1295,11 @@ __metadata: "@babel/helper-create-class-features-plugin": "workspace:^" "@babel/helper-plugin-test-runner": "workspace:^" "@babel/helper-plugin-utils": "workspace:^" + "@babel/helper-replace-supers": "workspace:^" "@babel/plugin-syntax-decorators": "workspace:^" "@babel/traverse": "workspace:^" babel-plugin-polyfill-es-shims: ^0.6.0 + charcodes: ^0.2.0 object.getownpropertydescriptors: ^2.1.1 peerDependencies: "@babel/core": ^7.0.0-0 From ab6d74a9cc5b252128e2da8b4a8d8f555db4669e Mon Sep 17 00:00:00 2001 From: Chris Hewell Garrett Date: Fri, 31 Dec 2021 10:02:20 -0500 Subject: [PATCH 02/24] Ensure private UID generation takes into account all referenced private names --- .../src/transformer-2021-12.ts | 93 ++++++------------- .../private-keys-in-enclosing-class/input.js | 10 ++ .../private-keys-in-enclosing-class/output.js | 19 ++++ 3 files changed, 55 insertions(+), 67 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/output.js diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index e962011267d7..510dbd4d869a 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -17,10 +17,6 @@ type ClassElement = | t.TSIndexSignature | t.StaticBlock; -type classUidGenerator = ( - isPrivate: B, -) => B extends true ? t.PrivateName : t.Identifier; - function incrementId(id: number[], idx = id.length - 1): void { // If index is -1, id needs an additional character, unshift A if (idx === -1) { @@ -54,64 +50,29 @@ function incrementId(id: number[], idx = id.length - 1): void { * (you cannot have #x and static #x in the same class) and it's not worth the * extra complexity for public names. */ -function createUidGeneratorForClass( - body: NodePath[], -): (isPrivate: boolean) => t.Identifier | t.PrivateName { - let currentPublicId: number[], currentPrivateId: number[]; - - const publicNames = new Set(); +function createPrivateUidGeneratorForClass( + classPath: NodePath, +): () => t.PrivateName { + const currentPrivateId = [charCodes.uppercaseA]; const privateNames = new Set(); - for (const element of body) { - if ( - element.node.type === "TSIndexSignature" || - element.node.type === "StaticBlock" - ) { - continue; - } - - const { key } = element.node; - - if (key.type === "PrivateName") { - privateNames.add(key.id.name); - } else if (key.type === "Identifier") { - publicNames.add(key.name); - } - } - - return (isPrivate: boolean): t.Identifier | t.PrivateName => { - let currentId: number[], names: Set; - - if (isPrivate) { - if (!currentPrivateId) { - currentPrivateId = [charCodes.uppercaseA]; - } - - currentId = currentPrivateId; - names = privateNames; - } else { - if (!currentPublicId) { - currentPublicId = [charCodes.uppercaseA]; - } - - currentId = currentPublicId; - names = publicNames; - } + classPath.traverse({ + PrivateName(path) { + privateNames.add(path.node.id.name); + }, + }); - let reifiedId = String.fromCharCode(...currentId); + return (): t.PrivateName => { + let reifiedId = String.fromCharCode(...currentPrivateId); - while (names.has(reifiedId)) { - incrementId(currentId); - reifiedId = String.fromCharCode(...currentId); + while (privateNames.has(reifiedId)) { + incrementId(currentPrivateId); + reifiedId = String.fromCharCode(...currentPrivateId); } - incrementId(currentId); + incrementId(currentPrivateId); - if (isPrivate) { - return t.privateName(t.identifier(reifiedId)); - } else { - return t.identifier(reifiedId); - } + return t.privateName(t.identifier(reifiedId)); }; } @@ -121,20 +82,18 @@ function createUidGeneratorForClass( * saves iterating the class elements an additional time and allocating the space * for the Sets of element names. */ -function createLazyUidGeneratorForClass( - body: NodePath[], -): classUidGenerator { - let generator: (isPrivate: boolean) => t.Identifier | t.PrivateName; +function createLazyPrivateUidGeneratorForClass( + classPath: NodePath, +): () => t.PrivateName { + let generator: () => t.PrivateName; - const lazyGenerator = (isPrivate: boolean): t.Identifier | t.PrivateName => { + return (): t.PrivateName => { if (!generator) { - generator = createUidGeneratorForClass(body); + generator = createPrivateUidGeneratorForClass(classPath); } - return generator(isPrivate); + return generator(); }; - - return lazyGenerator as unknown as classUidGenerator; } /** @@ -510,7 +469,7 @@ function transformClass( const classDecorators = path.node.decorators; let hasElementDecorators = false; - const generateClassUid = createLazyUidGeneratorForClass(body); + const generateClassPrivateUid = createLazyPrivateUidGeneratorForClass(path); // Iterate over the class to see if we need to decorate it, and also to // transform simple auto accessors which are not decorated @@ -524,7 +483,7 @@ function transformClass( } else if (element.node.type === "ClassAccessorProperty") { const { key, value, static: isStatic } = element.node; - const newId = generateClassUid(true); + const newId = generateClassPrivateUid(); const valueNode = value ? t.cloneNode(value) : undefined; @@ -626,7 +585,7 @@ function transformClass( params.push(t.cloneNode(value)); } - const newId = generateClassUid(true); + const newId = generateClassPrivateUid(); const newFieldInitId = generateLocalVarId(element, `init_${name}`); const newValue = t.callExpression( t.cloneNode(newFieldInitId), diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/input.js new file mode 100644 index 000000000000..586fb0adef1e --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/input.js @@ -0,0 +1,10 @@ +class A { + #A = 1; + static B = class B extends A { + accessor a = 2; + + getA() { + return this.#A; + } + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/output.js new file mode 100644 index 000000000000..102e9e463973 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/output.js @@ -0,0 +1,19 @@ +class A { + #A = 1; + static B = class B extends A { + #B = 2; + + get a() { + return this.#B; + } + + set a(v) { + this.#B = v; + } + + getA() { + return this.#A; + } + + }; +} From 46c54fbbf6b5e81cb64b73f5c862fbe03f396a9c Mon Sep 17 00:00:00 2001 From: Chris Hewell Garrett Date: Sat, 1 Jan 2022 13:49:22 -0500 Subject: [PATCH 03/24] Allow version: "legacy", use built-in Identifier generation, simplify private UID code --- babel.config.js | 5 +- .../src/index.ts | 8 ++- .../src/transformer-2021-12.ts | 71 ++++++++++--------- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/babel.config.js b/babel.config.js index f595e3a4e5e2..c66b077a8a32 100644 --- a/babel.config.js +++ b/babel.config.js @@ -194,7 +194,10 @@ module.exports = function (api) { assumptions: parserAssumptions, }, { - test: ["packages/babel-generator"].map(normalize), + test: [ + "packages/babel-generator", + "packages/babel-plugin-proposal-decorators", + ].map(normalize), plugins: ["babel-plugin-transform-charcodes"], }, convertESM && { diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index ddf98ea99e76..1a3b6c4a3d7b 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -37,9 +37,11 @@ export default declare((api, options) => { } } - if (legacy) { - if (version !== undefined) { - throw new Error("'version' can't be used with legacy decorators"); + if (version === "legacy" || legacy) { + if (version !== undefined && legacy) { + throw new Error( + 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', + ); } return { diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index 510dbd4d869a..95872e23a98c 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -40,20 +40,16 @@ function incrementId(id: number[], idx = id.length - 1): void { } /** - * Generates a new element name that is unique to the given class. This can be + * Generates a new private name that is unique to the given class. This can be * used to create extra class fields and methods for the implementation, while * keeping the length of those names as small as possible. This is important for - * minification purposes, since public names cannot be safely renamed/minified. - * - * Names are split into two namespaces, public and private. Static and non-static - * names are shared in the same namespace, because this is true for private names - * (you cannot have #x and static #x in the same class) and it's not worth the - * extra complexity for public names. + * minification purposes (though private names can generally be minified, + * transpilations and polyfills cannot yet). */ function createPrivateUidGeneratorForClass( classPath: NodePath, ): () => t.PrivateName { - const currentPrivateId = [charCodes.uppercaseA]; + const currentPrivateId = []; const privateNames = new Set(); classPath.traverse({ @@ -63,14 +59,11 @@ function createPrivateUidGeneratorForClass( }); return (): t.PrivateName => { - let reifiedId = String.fromCharCode(...currentPrivateId); - - while (privateNames.has(reifiedId)) { + let reifiedId; + do { incrementId(currentPrivateId); reifiedId = String.fromCharCode(...currentPrivateId); - } - - incrementId(currentPrivateId); + } while (privateNames.has(reifiedId)); return t.privateName(t.identifier(reifiedId)); }; @@ -124,16 +117,17 @@ function replaceClassWithVar( if (path.node.id) { className = path.node.id.name; - varId = generateLocalVarId(path, className); + varId = path.scope.parent.generateDeclaredUidIdentifier(className); path.scope.rename(className, varId.name); } else if ( path.parentPath.node.type === "VariableDeclarator" && path.parentPath.node.id.type === "Identifier" ) { className = path.parentPath.node.id.name; - varId = generateLocalVarId(path, className); + varId = path.scope.parent.generateDeclaredUidIdentifier(className); } else { - varId = generateLocalVarId(path, "decorated_class"); + varId = + path.scope.parent.generateDeclaredUidIdentifier("decorated_class"); } const newClassExpr = t.classExpression( @@ -283,12 +277,6 @@ function getElementKind(element: NodePath): number { } } -function generateLocalVarId(path: NodePath, name: string): t.Identifier { - const varId = path.scope.generateUidIdentifier(name); - path.scope.parent.push({ id: varId }); - return t.cloneNode(varId); -} - // Information about the decorators applied to an element interface DecoratorInfo { // The expressions of the decorators themselves @@ -514,7 +502,8 @@ function transformClass( classLocal: t.Identifier; if (classDecorators) { - classInitLocal = generateLocalVarId(path, "initClass"); + classInitLocal = + path.scope.parent.generateDeclaredUidIdentifier("initClass"); const [localId, classPath] = replaceClassWithVar(path); path = classPath; @@ -560,7 +549,8 @@ function transformClass( if (isComputed) { const keyPath = element.get("key"); - const localComputedNameId = generateLocalVarId(keyPath, name); + const localComputedNameId = + keyPath.scope.parent.generateDeclaredUidIdentifier(name); keyPath.replaceWith(localComputedNameId); elementDecoratorInfo.push({ @@ -586,7 +576,8 @@ function transformClass( } const newId = generateClassPrivateUid(); - const newFieldInitId = generateLocalVarId(element, `init_${name}`); + const newFieldInitId = + element.scope.parent.generateDeclaredUidIdentifier(`init_${name}`); const newValue = t.callExpression( t.cloneNode(newFieldInitId), params, @@ -598,8 +589,12 @@ function transformClass( if (isPrivate) { privateMethods = extractProxyAccessorsFor(newId); - const getId = generateLocalVarId(newPath, `get_${name}`); - const setId = generateLocalVarId(newPath, `set_${name}`); + const getId = newPath.scope.parent.generateDeclaredUidIdentifier( + `get_${name}`, + ); + const setId = newPath.scope.parent.generateDeclaredUidIdentifier( + `set_${name}`, + ); addCallAccessorsFor(newPath, key as t.PrivateName, getId, setId); @@ -609,7 +604,9 @@ function transformClass( locals = newFieldInitId; } } else if (kind === FIELD) { - const initId = generateLocalVarId(element, `init_${name}`); + const initId = element.scope.parent.generateDeclaredUidIdentifier( + `init_${name}`, + ); const valuePath = ( element as NodePath ).get("value"); @@ -627,7 +624,9 @@ function transformClass( privateMethods = extractProxyAccessorsFor(key as t.PrivateName); } } else if (isPrivate) { - locals = generateLocalVarId(element, `call_${name}`); + locals = element.scope.parent.generateDeclaredUidIdentifier( + `call_${name}`, + ) as t.Identifier; const replaceSupers = new ReplaceSupers({ constantSuper, @@ -730,7 +729,8 @@ function transformClass( const newDecorators: t.Identifier[] = []; for (const decorator of decorators) { - const localComputedNameId = generateLocalVarId(path, "dec"); + const localComputedNameId = + path.scope.parent.generateDeclaredUidIdentifier("dec"); assignments.push( t.assignmentExpression("=", localComputedNameId, decorator), ); @@ -761,7 +761,8 @@ function transformClass( } if (requiresProtoInit) { - protoInitLocal = generateLocalVarId(path, "initProto"); + protoInitLocal = + path.scope.parent.generateDeclaredUidIdentifier("initProto"); locals.push(protoInitLocal); const protoInitCall = t.callExpression(t.cloneNode(protoInitLocal), [ @@ -789,7 +790,8 @@ function transformClass( found = true; - const prop = generateLocalVarId(path, "super"); + const prop = + path.scope.parent.generateDeclaredUidIdentifier("super"); parentPath.replaceWith( t.sequenceExpression([ t.assignmentExpression("=", t.cloneNode(prop), parentPath.node), @@ -829,7 +831,8 @@ function transformClass( } if (requiresStaticInit) { - staticInitLocal = generateLocalVarId(path, "initStatic"); + staticInitLocal = + path.scope.parent.generateDeclaredUidIdentifier("initStatic"); locals.push(staticInitLocal); } From 910e1a782ad378e76d749b81158b79a1b1b31529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 6 Jan 2022 17:05:13 +0100 Subject: [PATCH 04/24] Rename tests --- .../options.json | 0 .../private/exec.js | 0 .../private/input.js | 0 .../private/output.js | 59 ++++++++ .../public/exec.js | 0 .../public/input.js | 0 .../public/output.js | 58 ++++++++ .../static-private/exec.js | 0 .../static-private/input.js | 0 .../static-private/output.js | 58 ++++++++ .../static-public/exec.js | 0 .../static-public/input.js | 0 .../static-public/output.js | 52 +++++++ .../undecorated-private/exec.js | 0 .../undecorated-private/input.js | 0 .../undecorated-private/output.js | 45 ++++++ .../undecorated-public/exec.js | 0 .../undecorated-public/input.js | 0 .../undecorated-public/output.js | 47 +++++++ .../undecorated-static-private/exec.js | 0 .../undecorated-static-private/input.js | 0 .../undecorated-static-private/output.js | 34 +++++ .../undecorated-static-public/exec.js | 0 .../undecorated-static-public/input.js | 0 .../undecorated-static-public/output.js | 39 ++++++ .../fixtures/2021-12-accessors/options.json | 5 +- .../2021-12-accessors/private/output.js | 74 ++++------ .../2021-12-accessors/public/output.js | 42 ++---- .../static-private/output.js | 74 ++++------ .../2021-12-accessors/static-public/output.js | 43 +++--- .../undecorated-private/output.js | 51 ++----- .../undecorated-public/output.js | 37 ++--- .../undecorated-static-private/output.js | 46 +++---- .../undecorated-static-public/output.js | 31 ++--- .../options.json | 0 .../input.js | 0 .../output.js | 0 .../super-in-private-accessor/input.js | 0 .../super-in-private-accessor/output.js | 0 .../super-in-private-method/input.js | 0 .../super-in-private-method/output.js | 0 .../expressions/input.js | 0 .../expressions/output.js | 51 +++++++ .../inheritance/exec.js | 0 .../inheritance/input.js | 0 .../inheritance/output.js | 25 ++++ .../initializers/exec.js | 0 .../initializers/input.js | 0 .../initializers/output.js | 33 +++++ .../options.json | 5 +- .../replacement-with-expr/exec.js | 0 .../replacement-with-expr/input.js | 0 .../replacement-with-expr/output.js | 13 ++ .../replacement/exec.js | 0 .../replacement/input.js | 0 .../replacement/output.js | 17 +++ .../2021-12-classes/expressions/output.js | 130 +++++++++++------- .../2021-12-classes/inheritance/output.js | 32 ++--- .../2021-12-classes/initializers/output.js | 47 +++---- .../fixtures/2021-12-classes/options.json | 5 +- .../replacement-with-expr/output.js | 18 +-- .../2021-12-classes/replacement/output.js | 19 ++- .../computed-keys-same-ast/exec.js | 0 .../computed-keys-same-ast/input.js | 0 .../computed-keys-same-ast/output.js | 8 +- .../computed-keys-same-value/exec.js | 0 .../computed-keys-same-value/input.js | 0 .../computed-keys-same-value/output.js | 8 +- .../method-and-field/exec.js | 0 .../method-and-field/input.js | 0 .../method-and-field/output.js | 16 +++ .../methods-with-same-key/exec.js | 0 .../methods-with-same-key/input.js | 0 .../methods-with-same-key/output.js | 8 +- .../options.json | 5 +- .../computed-keys-same-ast/output.js | 8 +- .../computed-keys-same-value/output.js | 8 +- .../method-and-field/output.js | 9 +- .../methods-with-same-key/output.js | 8 +- .../2021-12-duplicated-keys/options.json | 5 +- .../options.json | 5 +- .../private/exec.js | 0 .../private/input.js | 0 .../private/output.js | 31 +++++ .../public/exec.js | 0 .../public/input.js | 0 .../public/output.js | 19 +++ .../static-private/exec.js | 0 .../static-private/input.js | 0 .../static-private/output.js | 24 ++++ .../static-public/exec.js | 0 .../static-public/input.js | 0 .../static-public/output.js | 16 +++ .../test/fixtures/2021-12-fields/options.json | 5 +- .../fixtures/2021-12-fields/private/output.js | 38 ++--- .../fixtures/2021-12-fields/public/output.js | 14 +- .../2021-12-fields/static-private/output.js | 37 ++--- .../2021-12-fields/static-public/output.js | 17 ++- .../options.json | 5 +- .../private/exec.js | 0 .../private/input.js | 0 .../private/output.js | 30 ++++ .../public/exec.js | 0 .../public/input.js | 0 .../public/output.js | 12 +- .../static-private/exec.js | 0 .../static-private/input.js | 0 .../static-private/output.js | 27 ++++ .../static-public/exec.js | 0 .../static-public/input.js | 0 .../static-public/output.js | 16 +-- .../options.json | 11 ++ .../private/exec.js | 0 .../private/input.js | 0 .../private/output.js | 40 ++++++ .../public/exec.js | 0 .../public/input.js | 0 .../public/output.js | 12 +- .../static-private/exec.js | 0 .../static-private/input.js | 0 .../static-private/output.js | 37 +++++ .../static-public/exec.js | 0 .../static-public/input.js | 0 .../static-public/output.js | 16 +-- .../2021-12-getters-and-setters/options.json | 5 +- .../private/output.js | 46 +++---- .../public/output.js | 12 +- .../static-private/output.js | 49 +++---- .../static-public/output.js | 16 +-- .../fixtures/2021-12-getters/options.json | 5 +- .../2021-12-getters/private/output.js | 32 ++--- .../fixtures/2021-12-getters/public/output.js | 12 +- .../2021-12-getters/static-private/output.js | 33 ++--- .../2021-12-getters/static-public/output.js | 16 +-- .../class/exec.js | 0 .../getting-previously-set-metadata/exec.js | 0 .../inheritance-private/exec.js | 0 .../inheritance-public/exec.js | 0 .../non-symbol-keys/exec.js | 0 .../2021-12-metadata--to-es2015/options.json | 11 ++ .../proto-private/exec.js | 0 .../proto-public/exec.js | 0 .../static-private/exec.js | 0 .../static-public/exec.js | 0 .../2021-12-methods--to-es2015/options.json | 11 ++ .../private/exec.js | 0 .../private/input.js | 0 .../private/output.js | 26 ++++ .../public/exec.js | 0 .../public/input.js | 0 .../public/output.js | 12 +- .../static-private/exec.js | 0 .../static-private/input.js | 0 .../static-private/output.js | 22 +++ .../static-public/exec.js | 0 .../static-public/input.js | 0 .../static-public/output.js | 16 +-- .../fixtures/2021-12-methods/options.json | 5 +- .../2021-12-methods/private/output.js | 25 ++-- .../fixtures/2021-12-methods/public/output.js | 12 +- .../2021-12-methods/static-private/output.js | 27 ++-- .../2021-12-methods/static-public/output.js | 16 +-- .../initializer-timing/exec.js | 0 .../2021-12-misc--to-es2015/options.json | 11 ++ .../valid-expression-formats/input.js | 0 .../valid-expression-formats/output.js | 40 ++++++ .../test/fixtures/2021-12-misc/options.json | 5 +- .../private-keys-in-enclosing-class/input.js | 0 .../private-keys-in-enclosing-class/output.js | 0 .../input.js | 0 .../options.json | 0 .../input.js | 0 .../options.json | 0 .../input.js | 0 .../options.json | 0 .../setting-private-method-via-rest/input.js | 0 .../options.json | 0 .../input.js | 0 .../options.json | 0 .../setting-private-method/input.js | 0 .../setting-private-method/options.json | 0 .../input.js | 0 .../output.js | 0 .../super-in-private-accessor/input.js | 0 .../super-in-private-accessor/output.js | 0 .../super-in-private-method/input.js | 0 .../super-in-private-method/output.js | 0 .../valid-expression-formats/output.js | 39 +++--- .../2021-12-setters--to-es2015/options.json | 11 ++ .../private/exec.js | 0 .../private/input.js | 0 .../private/output.js | 30 ++++ .../public/exec.js | 0 .../public/input.js | 0 .../public/output.js | 12 +- .../static-private/exec.js | 0 .../static-private/input.js | 0 .../static-private/output.js | 27 ++++ .../static-public/exec.js | 0 .../static-public/input.js | 0 .../static-public/output.js | 16 +-- .../fixtures/2021-12-setters/options.json | 5 +- .../2021-12-setters/private/output.js | 32 ++--- .../fixtures/2021-12-setters/public/output.js | 12 +- .../2021-12-setters/static-private/output.js | 33 ++--- .../2021-12-setters/static-public/output.js | 16 +-- .../private/output.js | 35 ----- .../public/output.js | 42 ------ .../static-private/output.js | 38 ----- .../static-public/output.js | 45 ------ .../undecorated-private/output.js | 22 --- .../undecorated-public/output.js | 32 ----- .../undecorated-static-private/output.js | 22 --- .../undecorated-static-public/output.js | 32 ----- .../expressions/output.js | 87 ------------ .../inheritance/output.js | 25 ---- .../initializers/output.js | 30 ---- .../replacement-with-expr/output.js | 13 -- .../replacement/output.js | 16 --- .../method-and-field/output.js | 13 -- .../private/output.js | 17 --- .../public/output.js | 15 -- .../static-private/output.js | 17 --- .../static-public/output.js | 15 -- .../options.json | 8 -- .../private/output.js | 34 ----- .../static-private/output.js | 32 ----- .../options.json | 8 -- .../private/output.js | 24 ---- .../static-private/output.js | 22 --- .../options.json | 8 -- .../private/output.js | 21 --- .../static-private/output.js | 19 --- .../2021-12-transform-only-misc/options.json | 8 -- .../valid-expression-formats/output.js | 33 ----- .../options.json | 8 -- .../private/output.js | 24 ---- .../static-private/output.js | 22 --- 238 files changed, 1585 insertions(+), 1585 deletions(-) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-accessors--to-es2015}/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/public/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/static-public/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/undecorated-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/undecorated-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/undecorated-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/undecorated-public/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/undecorated-static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/undecorated-static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-accessors => 2021-12-accessors--to-es2015}/undecorated-static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-accessors--to-es2015}/undecorated-static-public/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/super-in-nested-constructor-expression/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/super-in-nested-constructor-expression/output.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/super-in-private-accessor/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/super-in-private-accessor/output.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/super-in-private-method/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-loose => 2021-12-assumption-constantSuper}/super-in-private-method/output.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-classes => 2021-12-classes--to-es2015}/expressions/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-classes => 2021-12-classes--to-es2015}/inheritance/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-classes => 2021-12-classes--to-es2015}/inheritance/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-classes => 2021-12-classes--to-es2015}/initializers/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-classes => 2021-12-classes--to-es2015}/initializers/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-accessors => 2021-12-classes--to-es2015}/options.json (53%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-classes => 2021-12-classes--to-es2015}/replacement-with-expr/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-classes => 2021-12-classes--to-es2015}/replacement-with-expr/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-classes => 2021-12-classes--to-es2015}/replacement/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-classes => 2021-12-classes--to-es2015}/replacement/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/computed-keys-same-ast/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/computed-keys-same-ast/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/computed-keys-same-ast/output.js (69%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/computed-keys-same-value/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/computed-keys-same-value/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/computed-keys-same-value/output.js (69%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/method-and-field/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/method-and-field/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/methods-with-same-key/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/methods-with-same-key/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/methods-with-same-key/output.js (57%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-duplicated-keys => 2021-12-duplicated-keys--to-es2015}/options.json (53%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-classes => 2021-12-fields--to-es2015}/options.json (53%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-fields => 2021-12-fields--to-es2015}/private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-fields => 2021-12-fields--to-es2015}/private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-fields => 2021-12-fields--to-es2015}/public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-fields => 2021-12-fields--to-es2015}/public/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-fields => 2021-12-fields--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-fields => 2021-12-fields--to-es2015}/static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-fields => 2021-12-fields--to-es2015}/static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-fields => 2021-12-fields--to-es2015}/static-public/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-fields => 2021-12-getters--to-es2015}/options.json (53%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters => 2021-12-getters--to-es2015}/private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters => 2021-12-getters--to-es2015}/private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters => 2021-12-getters--to-es2015}/public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters => 2021-12-getters--to-es2015}/public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters => 2021-12-getters--to-es2015}/public/output.js (60%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters => 2021-12-getters--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters => 2021-12-getters--to-es2015}/static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters => 2021-12-getters--to-es2015}/static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters => 2021-12-getters--to-es2015}/static-public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters => 2021-12-getters--to-es2015}/static-public/output.js (54%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/options.json rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/public/output.js (66%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/static-public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-getters-and-setters => 2021-12-getters-and-setters--to-es2015}/static-public/output.js (63%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/class/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/getting-previously-set-metadata/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/inheritance-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/inheritance-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/non-symbol-keys/exec.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/options.json rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/proto-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/proto-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-metadata => 2021-12-metadata--to-es2015}/static-public/exec.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/options.json rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-methods => 2021-12-methods--to-es2015}/private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-methods => 2021-12-methods--to-es2015}/private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-methods => 2021-12-methods--to-es2015}/public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-methods => 2021-12-methods--to-es2015}/public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-methods => 2021-12-methods--to-es2015}/public/output.js (60%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-methods => 2021-12-methods--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-methods => 2021-12-methods--to-es2015}/static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-methods => 2021-12-methods--to-es2015}/static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-methods => 2021-12-methods--to-es2015}/static-public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-methods => 2021-12-methods--to-es2015}/static-public/output.js (53%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-misc => 2021-12-misc--to-es2015}/initializer-timing/exec.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/options.json rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc--to-es2015}/valid-expression-formats/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/private-keys-in-enclosing-class/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/private-keys-in-enclosing-class/output.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-array-pattern/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-array-pattern/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-for-of/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-for-of/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-object-pattern/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-object-pattern/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-rest/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-rest/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-update/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method-via-update/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/setting-private-method/options.json (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/super-in-nested-constructor-expression/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/super-in-nested-constructor-expression/output.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/super-in-private-accessor/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/super-in-private-accessor/output.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/super-in-private-method/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-misc => 2021-12-misc}/super-in-private-method/output.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/options.json rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-setters => 2021-12-setters--to-es2015}/private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-setters => 2021-12-setters--to-es2015}/private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-setters => 2021-12-setters--to-es2015}/public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-setters => 2021-12-setters--to-es2015}/public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-setters => 2021-12-setters--to-es2015}/public/output.js (61%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-setters => 2021-12-setters--to-es2015}/static-private/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-setters => 2021-12-setters--to-es2015}/static-private/input.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/output.js rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-setters => 2021-12-setters--to-es2015}/static-public/exec.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-setters => 2021-12-setters--to-es2015}/static-public/input.js (100%) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-transform-only-setters => 2021-12-setters--to-es2015}/static-public/output.js (55%) delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js delete mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/output.js new file mode 100644 index 000000000000..69673b7af6d2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/private/output.js @@ -0,0 +1,59 @@ +var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto; + +var _A = /*#__PURE__*/new WeakMap(); + +var _a = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _b, { + get: _get_b2, + set: _set_b2 + }); + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a2, + set: _set_a2 + }); + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: (_initProto(this), _init_a(this)) + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: _init_b(this, 123) + }); + } + +} + +function _set_a2(v) { + _set_a(this, v); +} + +function _get_a2() { + _get_a(this); +} + +function _set_b2(v) { + _set_b(this, v); +} + +function _get_b2() { + _get_b(this); +} + +(() => { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 1, "a", function () { + return babelHelpers.classPrivateFieldGet(this, _A); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _A, value); + }], [dec, 1, "b", function () { + return babelHelpers.classPrivateFieldGet(this, _B); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _B, value); + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/output.js new file mode 100644 index 000000000000..2a6057e84caa --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/public/output.js @@ -0,0 +1,58 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initProto; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +var _A = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _C = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: (_initProto(this), _init_a(this)) + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: _init_b(this, 123) + }); + babelHelpers.classPrivateFieldInitSpec(this, _C, { + writable: true, + value: _init_computedKey(this, 456) + }); + } + + get a() { + return babelHelpers.classPrivateFieldGet(this, _A); + } + + set a(v) { + babelHelpers.classPrivateFieldSet(this, _A, v); + } + + get b() { + return babelHelpers.classPrivateFieldGet(this, _B); + } + + set b(v) { + babelHelpers.classPrivateFieldSet(this, _B, v); + } + + get [_computedKey]() { + return babelHelpers.classPrivateFieldGet(this, _C); + } + + set [_computedKey](v) { + babelHelpers.classPrivateFieldSet(this, _C, v); + } + +} + +(() => { + [_init_a, _init_b, _init_computedKey, _initProto] = babelHelpers.applyDecs(Foo, [[_dec, 1, "a"], [_dec2, 1, "b"], [_dec3, 1, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/output.js new file mode 100644 index 000000000000..b0ec49e5726f --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-private/output.js @@ -0,0 +1,58 @@ +var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic; + +var _a = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _b, { + get: _get_b2, + set: _set_b2 + }); + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a2, + set: _set_a2 + }); + } + +} + +function _set_a2(v) { + _set_a(this, v); +} + +function _get_a2() { + _get_a(this); +} + +function _set_b2(v) { + _set_b(this, v); +} + +function _get_b2() { + _get_b(this); +} + +(() => { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 6, "a", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, value); + }], [dec, 6, "b", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, value); + }]], []); + + _initStatic(Foo); +})(); + +var _A = { + writable: true, + value: _init_a(Foo) +}; +var _B = { + writable: true, + value: _init_b(Foo, 123) +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/output.js new file mode 100644 index 000000000000..c5a6ac47eba2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/static-public/output.js @@ -0,0 +1,52 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initStatic; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + static get a() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + } + + static set a(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); + } + + static get b() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + } + + static set b(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); + } + + static get [_computedKey]() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _C); + } + + static set [_computedKey](v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _C, v); + } + +} + +(() => { + [_init_a, _init_b, _init_computedKey, _initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 6, "a"], [_dec2, 6, "b"], [_dec3, 6, _computedKey]], []); + + _initStatic(Foo); +})(); + +var _A = { + writable: true, + value: _init_a(Foo) +}; +var _B = { + writable: true, + value: _init_b(Foo, 123) +}; +var _C = { + writable: true, + value: _init_computedKey(Foo, 456) +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/output.js new file mode 100644 index 000000000000..29d3fbd66965 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-private/output.js @@ -0,0 +1,45 @@ +var _A = /*#__PURE__*/new WeakMap(); + +var _a = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _b, { + get: _get_b, + set: _set_b + }); + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a, + set: _set_a + }); + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: void 0 + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: 123 + }); + } + +} + +function _get_a() { + return babelHelpers.classPrivateFieldGet(this, _A); +} + +function _set_a(v) { + babelHelpers.classPrivateFieldSet(this, _A, v); +} + +function _get_b() { + return babelHelpers.classPrivateFieldGet(this, _B); +} + +function _set_b(v) { + babelHelpers.classPrivateFieldSet(this, _B, v); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/output.js new file mode 100644 index 000000000000..6ec6f9255a06 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-public/output.js @@ -0,0 +1,47 @@ +var _A = /*#__PURE__*/new WeakMap(); + +var _B = /*#__PURE__*/new WeakMap(); + +var _C = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _A, { + writable: true, + value: void 0 + }); + babelHelpers.classPrivateFieldInitSpec(this, _B, { + writable: true, + value: 123 + }); + babelHelpers.classPrivateFieldInitSpec(this, _C, { + writable: true, + value: 456 + }); + } + + get a() { + return babelHelpers.classPrivateFieldGet(this, _A); + } + + set a(v) { + babelHelpers.classPrivateFieldSet(this, _A, v); + } + + get b() { + return babelHelpers.classPrivateFieldGet(this, _B); + } + + set b(v) { + babelHelpers.classPrivateFieldSet(this, _B, v); + } + + get 'c'() { + return babelHelpers.classPrivateFieldGet(this, _C); + } + + set 'c'(v) { + babelHelpers.classPrivateFieldSet(this, _C, v); + } + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/output.js new file mode 100644 index 000000000000..51de21b149b2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-private/output.js @@ -0,0 +1,34 @@ +class Foo {} + +function _get_a() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); +} + +function _set_a(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); +} + +function _get_b() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); +} + +function _set_b(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); +} + +var _b = { + get: _get_b, + set: _set_b +}; +var _a = { + get: _get_a, + set: _set_a +}; +var _A = { + writable: true, + value: void 0 +}; +var _B = { + writable: true, + value: 123 +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/output.js new file mode 100644 index 000000000000..4fe37de40ebf --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors--to-es2015/undecorated-static-public/output.js @@ -0,0 +1,39 @@ +class Foo { + static get a() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + } + + static set a(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); + } + + static get b() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + } + + static set b(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); + } + + static get 'c'() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _C); + } + + static set 'c'(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _C, v); + } + +} + +var _A = { + writable: true, + value: void 0 +}; +var _B = { + writable: true, + value: 123 +}; +var _C = { + writable: true, + value: 456 +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js index 69673b7af6d2..c054a288032a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/private/output.js @@ -1,59 +1,35 @@ var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto; -var _A = /*#__PURE__*/new WeakMap(); - -var _a = /*#__PURE__*/new WeakMap(); - -var _B = /*#__PURE__*/new WeakMap(); - -var _b = /*#__PURE__*/new WeakMap(); - class Foo { - constructor() { - babelHelpers.classPrivateFieldInitSpec(this, _b, { - get: _get_b2, - set: _set_b2 - }); - babelHelpers.classPrivateFieldInitSpec(this, _a, { - get: _get_a2, - set: _set_a2 - }); - babelHelpers.classPrivateFieldInitSpec(this, _A, { - writable: true, - value: (_initProto(this), _init_a(this)) - }); - babelHelpers.classPrivateFieldInitSpec(this, _B, { - writable: true, - value: _init_b(this, 123) - }); + static { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = babelHelpers.applyDecs(this, [[dec, 1, "a", function () { + return this.#A; + }, function (value) { + this.#A = value; + }], [dec, 1, "b", function () { + return this.#B; + }, function (value) { + this.#B = value; + }]], []); } + #A = (_initProto(this), _init_a(this)); -} + set #a(v) { + _set_a(this, v); + } -function _set_a2(v) { - _set_a(this, v); -} + get #a() { + _get_a(this); + } -function _get_a2() { - _get_a(this); -} + #B = _init_b(this, 123); -function _set_b2(v) { - _set_b(this, v); -} + set #b(v) { + _set_b(this, v); + } -function _get_b2() { - _get_b(this); -} + get #b() { + _get_b(this); + } -(() => { - [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 1, "a", function () { - return babelHelpers.classPrivateFieldGet(this, _A); - }, function (value) { - babelHelpers.classPrivateFieldSet(this, _A, value); - }], [dec, 1, "b", function () { - return babelHelpers.classPrivateFieldGet(this, _B); - }, function (value) { - babelHelpers.classPrivateFieldSet(this, _B, value); - }]], []); -})(); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js index 2a6057e84caa..0fb94194b1db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/public/output.js @@ -5,54 +5,38 @@ _dec2 = dec _computedKey = 'c' _dec3 = dec -var _A = /*#__PURE__*/new WeakMap(); - -var _B = /*#__PURE__*/new WeakMap(); - -var _C = /*#__PURE__*/new WeakMap(); - class Foo { - constructor() { - babelHelpers.classPrivateFieldInitSpec(this, _A, { - writable: true, - value: (_initProto(this), _init_a(this)) - }); - babelHelpers.classPrivateFieldInitSpec(this, _B, { - writable: true, - value: _init_b(this, 123) - }); - babelHelpers.classPrivateFieldInitSpec(this, _C, { - writable: true, - value: _init_computedKey(this, 456) - }); + static { + [_init_a, _init_b, _init_computedKey, _initProto] = babelHelpers.applyDecs(this, [[_dec, 1, "a"], [_dec2, 1, "b"], [_dec3, 1, _computedKey]], []); } + #A = (_initProto(this), _init_a(this)); get a() { - return babelHelpers.classPrivateFieldGet(this, _A); + return this.#A; } set a(v) { - babelHelpers.classPrivateFieldSet(this, _A, v); + this.#A = v; } + #B = _init_b(this, 123); + get b() { - return babelHelpers.classPrivateFieldGet(this, _B); + return this.#B; } set b(v) { - babelHelpers.classPrivateFieldSet(this, _B, v); + this.#B = v; } + #C = _init_computedKey(this, 456); + get [_computedKey]() { - return babelHelpers.classPrivateFieldGet(this, _C); + return this.#C; } set [_computedKey](v) { - babelHelpers.classPrivateFieldSet(this, _C, v); + this.#C = v; } } - -(() => { - [_init_a, _init_b, _init_computedKey, _initProto] = babelHelpers.applyDecs(Foo, [[_dec, 1, "a"], [_dec2, 1, "b"], [_dec3, 1, _computedKey]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js index b0ec49e5726f..ad30531a425e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-private/output.js @@ -1,58 +1,38 @@ var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic; -var _a = /*#__PURE__*/new WeakMap(); +class Foo { + static { + [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(this, [[dec, 6, "a", function () { + return this.#A; + }, function (value) { + this.#A = value; + }], [dec, 6, "b", function () { + return this.#B; + }, function (value) { + this.#B = value; + }]], []); + + _initStatic(this); -var _b = /*#__PURE__*/new WeakMap(); + } + static #A = _init_a(this); -class Foo { - constructor() { - babelHelpers.classPrivateFieldInitSpec(this, _b, { - get: _get_b2, - set: _set_b2 - }); - babelHelpers.classPrivateFieldInitSpec(this, _a, { - get: _get_a2, - set: _set_a2 - }); + set #a(v) { + _set_a(this, v); } -} + get #a() { + _get_a(this); + } -function _set_a2(v) { - _set_a(this, v); -} + static #B = _init_b(this, 123); -function _get_a2() { - _get_a(this); -} + set #b(v) { + _set_b(this, v); + } -function _set_b2(v) { - _set_b(this, v); -} + get #b() { + _get_b(this); + } -function _get_b2() { - _get_b(this); } - -(() => { - [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 6, "a", function () { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); - }, function (value) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, value); - }], [dec, 6, "b", function () { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); - }, function (value) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, value); - }]], []); - - _initStatic(Foo); -})(); - -var _A = { - writable: true, - value: _init_a(Foo) -}; -var _B = { - writable: true, - value: _init_b(Foo, 123) -}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js index c5a6ac47eba2..471adf36f9c9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/static-public/output.js @@ -6,47 +6,40 @@ _computedKey = 'c' _dec3 = dec class Foo { + static { + [_init_a, _init_b, _init_computedKey, _initStatic] = babelHelpers.applyDecs(this, [[_dec, 6, "a"], [_dec2, 6, "b"], [_dec3, 6, _computedKey]], []); + + _initStatic(this); + + } + static #A = _init_a(this); + static get a() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + return this.#A; } static set a(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); + this.#A = v; } + static #B = _init_b(this, 123); + static get b() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + return this.#B; } static set b(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); + this.#B = v; } + static #C = _init_computedKey(this, 456); + static get [_computedKey]() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _C); + return this.#C; } static set [_computedKey](v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _C, v); + this.#C = v; } } - -(() => { - [_init_a, _init_b, _init_computedKey, _initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 6, "a"], [_dec2, 6, "b"], [_dec3, 6, _computedKey]], []); - - _initStatic(Foo); -})(); - -var _A = { - writable: true, - value: _init_a(Foo) -}; -var _B = { - writable: true, - value: _init_b(Foo, 123) -}; -var _C = { - writable: true, - value: _init_computedKey(Foo, 456) -}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js index 29d3fbd66965..9eb7268e4131 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-private/output.js @@ -1,45 +1,22 @@ -var _A = /*#__PURE__*/new WeakMap(); - -var _a = /*#__PURE__*/new WeakMap(); - -var _B = /*#__PURE__*/new WeakMap(); - -var _b = /*#__PURE__*/new WeakMap(); - class Foo { - constructor() { - babelHelpers.classPrivateFieldInitSpec(this, _b, { - get: _get_b, - set: _set_b - }); - babelHelpers.classPrivateFieldInitSpec(this, _a, { - get: _get_a, - set: _set_a - }); - babelHelpers.classPrivateFieldInitSpec(this, _A, { - writable: true, - value: void 0 - }); - babelHelpers.classPrivateFieldInitSpec(this, _B, { - writable: true, - value: 123 - }); + #A; + + get #a() { + return this.#A; } -} + set #a(v) { + this.#A = v; + } -function _get_a() { - return babelHelpers.classPrivateFieldGet(this, _A); -} + #B = 123; -function _set_a(v) { - babelHelpers.classPrivateFieldSet(this, _A, v); -} + get #b() { + return this.#B; + } -function _get_b() { - return babelHelpers.classPrivateFieldGet(this, _B); -} + set #b(v) { + this.#B = v; + } -function _set_b(v) { - babelHelpers.classPrivateFieldSet(this, _B, v); } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js index 6ec6f9255a06..f6269be736f1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-public/output.js @@ -1,47 +1,32 @@ -var _A = /*#__PURE__*/new WeakMap(); - -var _B = /*#__PURE__*/new WeakMap(); - -var _C = /*#__PURE__*/new WeakMap(); - class Foo { - constructor() { - babelHelpers.classPrivateFieldInitSpec(this, _A, { - writable: true, - value: void 0 - }); - babelHelpers.classPrivateFieldInitSpec(this, _B, { - writable: true, - value: 123 - }); - babelHelpers.classPrivateFieldInitSpec(this, _C, { - writable: true, - value: 456 - }); - } + #A; get a() { - return babelHelpers.classPrivateFieldGet(this, _A); + return this.#A; } set a(v) { - babelHelpers.classPrivateFieldSet(this, _A, v); + this.#A = v; } + #B = 123; + get b() { - return babelHelpers.classPrivateFieldGet(this, _B); + return this.#B; } set b(v) { - babelHelpers.classPrivateFieldSet(this, _B, v); + this.#B = v; } + #C = 456; + get 'c'() { - return babelHelpers.classPrivateFieldGet(this, _C); + return this.#C; } set 'c'(v) { - babelHelpers.classPrivateFieldSet(this, _C, v); + this.#C = v; } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js index 51de21b149b2..04cc0ef030d0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-private/output.js @@ -1,34 +1,22 @@ -class Foo {} +class Foo { + static #A; -function _get_a() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); -} + static get #a() { + return this.#A; + } -function _set_a(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); -} + static set #a(v) { + this.#A = v; + } -function _get_b() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); -} + static #B = 123; -function _set_b(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); -} + static get #b() { + return this.#B; + } + + static set #b(v) { + this.#B = v; + } -var _b = { - get: _get_b, - set: _set_b -}; -var _a = { - get: _get_a, - set: _set_a -}; -var _A = { - writable: true, - value: void 0 -}; -var _B = { - writable: true, - value: 123 -}; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js index 4fe37de40ebf..187ad5214a67 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-accessors/undecorated-static-public/output.js @@ -1,39 +1,32 @@ class Foo { + static #A; + static get a() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); + return this.#A; } static set a(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, v); + this.#A = v; } + static #B = 123; + static get b() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); + return this.#B; } static set b(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, v); + this.#B = v; } + static #C = 456; + static get 'c'() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _C); + return this.#C; } static set 'c'(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _C, v); + this.#C = v; } } - -var _A = { - writable: true, - value: void 0 -}; -var _B = { - writable: true, - value: 123 -}; -var _C = { - writable: true, - value: 456 -}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-nested-constructor-expression/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-nested-constructor-expression/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-nested-constructor-expression/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-nested-constructor-expression/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-nested-constructor-expression/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-accessor/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-accessor/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-accessor/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-accessor/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-accessor/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-method/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-method/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-method/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-loose/super-in-private-method/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-assumption-constantSuper/super-in-private-method/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js new file mode 100644 index 000000000000..b0cce043afbe --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js @@ -0,0 +1,51 @@ +var _initClass, _A, _class, _temp, _initClass2, _C, _class2, _temp2, _initClass3, _D, _class3, _temp3, _initClass4, _decorated_class, _class4, _temp4, _initClass5, _G, _class5, _temp5, _initClass6, _decorated_class2, _class6, _temp6, _initClass7, _H, _class7, _temp7, _initClass8, _K, _class8, _temp8; + +const A = ((_temp = _class = class A {}, (() => { + [_A, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); +})(), (() => { + _initClass(); +})(), _temp), _A); +const B = ((_temp2 = _class2 = class C {}, (() => { + [_C, _initClass2] = babelHelpers.applyDecs(_class2, [], [dec]); +})(), (() => { + _initClass2(); +})(), _temp2), _C); +const D = ((_temp3 = _class3 = class D {}, (() => { + [_D, _initClass3] = babelHelpers.applyDecs(_class3, [], [dec]); +})(), (() => { + _initClass3(); +})(), _temp3), _D); +const E = (((_temp4 = _class4 = class {}, (() => { + [_decorated_class, _initClass4] = babelHelpers.applyDecs(_class4, [], [dec]); +})(), (() => { + _initClass4(); +})(), _temp4), _decorated_class), 123); +const F = [((_temp5 = _class5 = class G {}, (() => { + [_G, _initClass5] = babelHelpers.applyDecs(_class5, [], [dec]); +})(), (() => { + _initClass5(); +})(), _temp5), _G), ((_temp6 = _class6 = class {}, (() => { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_class6, [], [dec]); +})(), (() => { + _initClass6(); +})(), _temp6), _decorated_class2)]; +const H = ((_temp7 = _class7 = class H extends I {}, (() => { + [_H, _initClass7] = babelHelpers.applyDecs(_class7, [], [dec]); +})(), (() => { + _initClass7(); +})(), _temp7), _H); +const J = ((_temp8 = _class8 = class K extends L {}, (() => { + [_K, _initClass8] = babelHelpers.applyDecs(_class8, [], [dec]); +})(), (() => { + _initClass8(); +})(), _temp8), _K); + +function classFactory() { + var _initClass9, _decorated_class3, _class9, _temp9; + + return (_temp9 = _class9 = class {}, (() => { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_class9, [], [dec]); + })(), (() => { + _initClass9(); + })(), _temp9), _decorated_class3; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/output.js new file mode 100644 index 000000000000..605270eadeca --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/inheritance/output.js @@ -0,0 +1,25 @@ +var _initClass, _initClass2; + +let _Bar; + +class Bar {} + +(() => { + [_Bar, _initClass] = babelHelpers.applyDecs(Bar, [], [dec1]); +})(); + +(() => { + _initClass(); +})(); + +let _Foo; + +class Foo extends _Bar {} + +(() => { + [_Foo, _initClass2] = babelHelpers.applyDecs(Foo, [], [dec2]); +})(); + +(() => { + _initClass2(); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js new file mode 100644 index 000000000000..a197b92f57e6 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js @@ -0,0 +1,33 @@ +var _initClass, _initClass2; + +let _Foo; + +class Foo {} + +(() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); +})(); + +babelHelpers.defineProperty(Foo, "field", 123); + +(() => { + _initClass(); +})(); + +let _Bar; + +class Bar extends _Foo {} + +(() => { + [_Bar, _initClass2] = babelHelpers.applyDecs(Bar, [], [dec]); +})(); + +(() => { + Bar.otherField = 456; +})(); + +babelHelpers.defineProperty(Bar, "field", 123); + +(() => { + _initClass2(); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/options.json similarity index 53% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/options.json index 18aa205580db..69f3e599cf2d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/options.json @@ -3,6 +3,9 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ] + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js new file mode 100644 index 000000000000..f1f8cd9df38d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js @@ -0,0 +1,13 @@ +var _initClass, _Bar, _class, _temp; + +const Foo = ((_temp = _class = class Bar { + constructor() { + babelHelpers.defineProperty(this, "bar", new _Bar()); + } + +}, (() => { + [_Bar, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); +})(), (() => { + _initClass(); +})(), _temp), _Bar); +const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js new file mode 100644 index 000000000000..4a26f8ccd8bf --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js @@ -0,0 +1,17 @@ +var _initClass; + +let _Foo; + +class Foo {} + +(() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); +})(); + +babelHelpers.defineProperty(Foo, "foo", new _Foo()); + +(() => { + _initClass(); +})(); + +const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js index b0cce043afbe..146cdb17ca70 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/expressions/output.js @@ -1,51 +1,87 @@ -var _initClass, _A, _class, _temp, _initClass2, _C, _class2, _temp2, _initClass3, _D, _class3, _temp3, _initClass4, _decorated_class, _class4, _temp4, _initClass5, _G, _class5, _temp5, _initClass6, _decorated_class2, _class6, _temp6, _initClass7, _H, _class7, _temp7, _initClass8, _K, _class8, _temp8; - -const A = ((_temp = _class = class A {}, (() => { - [_A, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); -})(), (() => { - _initClass(); -})(), _temp), _A); -const B = ((_temp2 = _class2 = class C {}, (() => { - [_C, _initClass2] = babelHelpers.applyDecs(_class2, [], [dec]); -})(), (() => { - _initClass2(); -})(), _temp2), _C); -const D = ((_temp3 = _class3 = class D {}, (() => { - [_D, _initClass3] = babelHelpers.applyDecs(_class3, [], [dec]); -})(), (() => { - _initClass3(); -})(), _temp3), _D); -const E = (((_temp4 = _class4 = class {}, (() => { - [_decorated_class, _initClass4] = babelHelpers.applyDecs(_class4, [], [dec]); -})(), (() => { - _initClass4(); -})(), _temp4), _decorated_class), 123); -const F = [((_temp5 = _class5 = class G {}, (() => { - [_G, _initClass5] = babelHelpers.applyDecs(_class5, [], [dec]); -})(), (() => { - _initClass5(); -})(), _temp5), _G), ((_temp6 = _class6 = class {}, (() => { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_class6, [], [dec]); -})(), (() => { - _initClass6(); -})(), _temp6), _decorated_class2)]; -const H = ((_temp7 = _class7 = class H extends I {}, (() => { - [_H, _initClass7] = babelHelpers.applyDecs(_class7, [], [dec]); -})(), (() => { - _initClass7(); -})(), _temp7), _H); -const J = ((_temp8 = _class8 = class K extends L {}, (() => { - [_K, _initClass8] = babelHelpers.applyDecs(_class8, [], [dec]); -})(), (() => { - _initClass8(); -})(), _temp8), _K); +var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _initClass8, _K; + +const A = (class A { + static { + [_A, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass(); + + } +}, _A); +const B = (class C { + static { + [_C, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass2(); + + } +}, _C); +const D = (class D { + static { + [_D, _initClass3] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass3(); + + } +}, _D); +const E = ((class { + static { + [_decorated_class, _initClass4] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass4(); + + } +}, _decorated_class), 123); +const F = [(class G { + static { + [_G, _initClass5] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass5(); + + } +}, _G), (class { + static { + [_decorated_class2, _initClass6] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass6(); + + } +}, _decorated_class2)]; +const H = (class H extends I { + static { + [_H, _initClass7] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass7(); + + } +}, _H); +const J = (class K extends L { + static { + [_K, _initClass8] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass8(); + + } +}, _K); function classFactory() { - var _initClass9, _decorated_class3, _class9, _temp9; + var _initClass9, _decorated_class3; + + return class { + static { + [_decorated_class3, _initClass9] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + _initClass9(); - return (_temp9 = _class9 = class {}, (() => { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_class9, [], [dec]); - })(), (() => { - _initClass9(); - })(), _temp9), _decorated_class3; + } + }, _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js index 605270eadeca..d7ea9b35166e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/inheritance/output.js @@ -2,24 +2,24 @@ var _initClass, _initClass2; let _Bar; -class Bar {} +class Bar { + static { + [_Bar, _initClass] = babelHelpers.applyDecs(this, [], [dec1]); + } + static { + _initClass(); -(() => { - [_Bar, _initClass] = babelHelpers.applyDecs(Bar, [], [dec1]); -})(); - -(() => { - _initClass(); -})(); + } +} let _Foo; -class Foo extends _Bar {} - -(() => { - [_Foo, _initClass2] = babelHelpers.applyDecs(Foo, [], [dec2]); -})(); +class Foo extends _Bar { + static { + [_Foo, _initClass2] = babelHelpers.applyDecs(this, [], [dec2]); + } + static { + _initClass2(); -(() => { - _initClass2(); -})(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js index a197b92f57e6..c4b21cf992e6 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js @@ -2,32 +2,29 @@ var _initClass, _initClass2; let _Foo; -class Foo {} +class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + static field = 123; + static { + _initClass(); -(() => { - [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); -})(); - -babelHelpers.defineProperty(Foo, "field", 123); - -(() => { - _initClass(); -})(); + } +} let _Bar; -class Bar extends _Foo {} - -(() => { - [_Bar, _initClass2] = babelHelpers.applyDecs(Bar, [], [dec]); -})(); - -(() => { - Bar.otherField = 456; -})(); - -babelHelpers.defineProperty(Bar, "field", 123); - -(() => { - _initClass2(); -})(); +class Bar extends _Foo { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); + } + static { + this.otherField = 456; + } + static field = 123; + static { + _initClass2(); + + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js index f1f8cd9df38d..4c37edebb1dd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-with-expr/output.js @@ -1,13 +1,13 @@ -var _initClass, _Bar, _class, _temp; +var _initClass, _Bar; -const Foo = ((_temp = _class = class Bar { - constructor() { - babelHelpers.defineProperty(this, "bar", new _Bar()); +const Foo = (class Bar { + static { + [_Bar, _initClass] = babelHelpers.applyDecs(this, [], [dec]); } + bar = new _Bar(); + static { + _initClass(); -}, (() => { - [_Bar, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); -})(), (() => { - _initClass(); -})(), _temp), _Bar); + } +}, _Bar); const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js index 4a26f8ccd8bf..046ba5f9a759 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js @@ -2,16 +2,15 @@ var _initClass; let _Foo; -class Foo {} +class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + static foo = new _Foo(); + static { + _initClass(); -(() => { - [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); -})(); - -babelHelpers.defineProperty(Foo, "foo", new _Foo()); - -(() => { - _initClass(); -})(); + } +} const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js similarity index 69% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 9663aebaf7b3..a70d24de54c9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -6,10 +6,6 @@ _computedKey2 = getKey() _dec2 = dec class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); - } - constructor(...args) { _initProto(this); } @@ -23,3 +19,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js similarity index 69% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js index 76d9f05cad75..66e2ac318d83 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -6,10 +6,6 @@ _computedKey2 = getKeyJ() _dec2 = dec class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); - } - constructor(...args) { _initProto(this); } @@ -23,3 +19,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/output.js new file mode 100644 index 000000000000..fe79aa632006 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/method-and-field/output.js @@ -0,0 +1,16 @@ +var _init_a, _initProto; + +class Foo { + constructor() { + babelHelpers.defineProperty(this, "a", (_initProto(this), _init_a(this, 123))); + } + + a() { + return 1; + } + +} + +(() => { + [_init_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 0, "a"], [dec, 2, "a"]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/output.js similarity index 57% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/output.js index c4befb4def4d..6402e1341ff0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/methods-with-same-key/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/methods-with-same-key/output.js @@ -1,10 +1,6 @@ var _initProto; class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a"], [dec, 2, "a"]], []); - } - constructor(...args) { _initProto(this); } @@ -18,3 +14,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[dec, 2, "a"], [dec, 2, "a"]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/options.json similarity index 53% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/options.json index 18aa205580db..69f3e599cf2d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys--to-es2015/options.json @@ -3,6 +3,9 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ] + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js index a70d24de54c9..9663aebaf7b3 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-ast/output.js @@ -6,6 +6,10 @@ _computedKey2 = getKey() _dec2 = dec class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); + } + constructor(...args) { _initProto(this); } @@ -19,7 +23,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js index 66e2ac318d83..76d9f05cad75 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/computed-keys-same-value/output.js @@ -6,6 +6,10 @@ _computedKey2 = getKeyJ() _dec2 = dec class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); + } + constructor(...args) { _initProto(this); } @@ -19,7 +23,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, _computedKey], [_dec2, 2, _computedKey2]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js index fe79aa632006..cb04e3cc2e5d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/method-and-field/output.js @@ -1,16 +1,13 @@ var _init_a, _initProto; class Foo { - constructor() { - babelHelpers.defineProperty(this, "a", (_initProto(this), _init_a(this, 123))); + static { + [_init_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 0, "a"], [dec, 2, "a"]], []); } + a = (_initProto(this), _init_a(this, 123)); a() { return 1; } } - -(() => { - [_init_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 0, "a"], [dec, 2, "a"]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js index 6402e1341ff0..c4befb4def4d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/methods-with-same-key/output.js @@ -1,6 +1,10 @@ var _initProto; class Foo { + static { + [_initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a"], [dec, 2, "a"]], []); + } + constructor(...args) { _initProto(this); } @@ -14,7 +18,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[dec, 2, "a"], [dec, 2, "a"]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-duplicated-keys/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/options.json similarity index 53% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/options.json index 18aa205580db..69f3e599cf2d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/options.json @@ -3,6 +3,9 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ] + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/output.js new file mode 100644 index 000000000000..af27fce2d289 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/private/output.js @@ -0,0 +1,31 @@ +var _init_a, _init_b; + +var _a = /*#__PURE__*/new WeakMap(); + +var _b = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + writable: true, + value: _init_a(this) + }); + babelHelpers.classPrivateFieldInitSpec(this, _b, { + writable: true, + value: _init_b(this, 123) + }); + } + +} + +(() => { + [_init_a, _init_b] = babelHelpers.applyDecs(Foo, [[dec, 0, "a", function () { + return babelHelpers.classPrivateFieldGet(this, _a); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _a, value); + }], [dec, 0, "b", function () { + return babelHelpers.classPrivateFieldGet(this, _b); + }, function (value) { + babelHelpers.classPrivateFieldSet(this, _b, value); + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/output.js new file mode 100644 index 000000000000..481926ddfe5a --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/public/output.js @@ -0,0 +1,19 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo { + constructor() { + babelHelpers.defineProperty(this, "a", _init_a(this)); + babelHelpers.defineProperty(this, "b", _init_b(this, 123)); + babelHelpers.defineProperty(this, _computedKey, _init_computedKey(this, 456)); + } + +} + +(() => { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(Foo, [[_dec, 0, "a"], [_dec2, 0, "b"], [_dec3, 0, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/output.js new file mode 100644 index 000000000000..ad619ac7d598 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-private/output.js @@ -0,0 +1,24 @@ +var _init_a, _init_b; + +class Foo {} + +(() => { + [_init_a, _init_b] = babelHelpers.applyDecs(Foo, [[dec, 5, "a", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, value); + }], [dec, 5, "b", function () { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _b); + }, function (value) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _b, value); + }]], []); +})(); + +var _a = { + writable: true, + value: _init_a(Foo) +}; +var _b = { + writable: true, + value: _init_b(Foo, 123) +}; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/output.js new file mode 100644 index 000000000000..c5df8314385b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields--to-es2015/static-public/output.js @@ -0,0 +1,16 @@ +var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; + +_dec = dec +_dec2 = dec +_computedKey = 'c' +_dec3 = dec + +class Foo {} + +(() => { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(Foo, [[_dec, 5, "a"], [_dec2, 5, "b"], [_dec3, 5, _computedKey]], []); +})(); + +babelHelpers.defineProperty(Foo, "a", _init_a(Foo)); +babelHelpers.defineProperty(Foo, "b", _init_b(Foo, 123)); +babelHelpers.defineProperty(Foo, _computedKey, _init_computedKey(Foo, 456)); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js index af27fce2d289..b72a6d971df6 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/private/output.js @@ -1,31 +1,17 @@ var _init_a, _init_b; -var _a = /*#__PURE__*/new WeakMap(); - -var _b = /*#__PURE__*/new WeakMap(); - class Foo { - constructor() { - babelHelpers.classPrivateFieldInitSpec(this, _a, { - writable: true, - value: _init_a(this) - }); - babelHelpers.classPrivateFieldInitSpec(this, _b, { - writable: true, - value: _init_b(this, 123) - }); + static { + [_init_a, _init_b] = babelHelpers.applyDecs(this, [[dec, 0, "a", function () { + return this.#a; + }, function (value) { + this.#a = value; + }], [dec, 0, "b", function () { + return this.#b; + }, function (value) { + this.#b = value; + }]], []); } - + #a = _init_a(this); + #b = _init_b(this, 123); } - -(() => { - [_init_a, _init_b] = babelHelpers.applyDecs(Foo, [[dec, 0, "a", function () { - return babelHelpers.classPrivateFieldGet(this, _a); - }, function (value) { - babelHelpers.classPrivateFieldSet(this, _a, value); - }], [dec, 0, "b", function () { - return babelHelpers.classPrivateFieldGet(this, _b); - }, function (value) { - babelHelpers.classPrivateFieldSet(this, _b, value); - }]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js index 481926ddfe5a..06c0434d04a6 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/public/output.js @@ -6,14 +6,10 @@ _computedKey = 'c' _dec3 = dec class Foo { - constructor() { - babelHelpers.defineProperty(this, "a", _init_a(this)); - babelHelpers.defineProperty(this, "b", _init_b(this, 123)); - babelHelpers.defineProperty(this, _computedKey, _init_computedKey(this, 456)); + static { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(this, [[_dec, 0, "a"], [_dec2, 0, "b"], [_dec3, 0, _computedKey]], []); } - + a = _init_a(this); + b = _init_b(this, 123); + [_computedKey] = _init_computedKey(this, 456); } - -(() => { - [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(Foo, [[_dec, 0, "a"], [_dec2, 0, "b"], [_dec3, 0, _computedKey]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js index ad619ac7d598..cb167ff192fd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-private/output.js @@ -1,24 +1,17 @@ var _init_a, _init_b; -class Foo {} - -(() => { - [_init_a, _init_b] = babelHelpers.applyDecs(Foo, [[dec, 5, "a", function () { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); - }, function (value) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, value); - }], [dec, 5, "b", function () { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _b); - }, function (value) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _b, value); - }]], []); -})(); - -var _a = { - writable: true, - value: _init_a(Foo) -}; -var _b = { - writable: true, - value: _init_b(Foo, 123) -}; +class Foo { + static { + [_init_a, _init_b] = babelHelpers.applyDecs(this, [[dec, 5, "a", function () { + return this.#a; + }, function (value) { + this.#a = value; + }], [dec, 5, "b", function () { + return this.#b; + }, function (value) { + this.#b = value; + }]], []); + } + static #a = _init_a(this); + static #b = _init_b(this, 123); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js index c5df8314385b..64af25745500 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-fields/static-public/output.js @@ -5,12 +5,11 @@ _dec2 = dec _computedKey = 'c' _dec3 = dec -class Foo {} - -(() => { - [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(Foo, [[_dec, 5, "a"], [_dec2, 5, "b"], [_dec3, 5, _computedKey]], []); -})(); - -babelHelpers.defineProperty(Foo, "a", _init_a(Foo)); -babelHelpers.defineProperty(Foo, "b", _init_b(Foo, 123)); -babelHelpers.defineProperty(Foo, _computedKey, _init_computedKey(Foo, 456)); +class Foo { + static { + [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(this, [[_dec, 5, "a"], [_dec2, 5, "b"], [_dec3, 5, _computedKey]], []); + } + static a = _init_a(this); + static b = _init_b(this, 123); + static [_computedKey] = _init_computedKey(this, 456); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/options.json similarity index 53% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/options.json index 18aa205580db..69f3e599cf2d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/options.json @@ -3,6 +3,9 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ] + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/output.js new file mode 100644 index 000000000000..32971ca073e9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/private/output.js @@ -0,0 +1,30 @@ +var _call_a, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a, + set: void 0 + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + getA() { + return babelHelpers.classPrivateFieldGet(this, _a); + } + +} + +function _get_a() { + return _call_a(this); +} + +(() => { + [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 3, "a", function () { + return this.value; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/output.js similarity index 60% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/output.js index 756adf797e3b..0152dbf977de 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/public/output.js @@ -5,16 +5,12 @@ _computedKey = 'b' _dec2 = dec class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[_dec, 3, "a"], [_dec2, 3, _computedKey]], []); - } - constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + _initProto(this); } - value = 1; - get a() { return this.value; } @@ -24,3 +20,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 3, "a"], [_dec2, 3, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/output.js new file mode 100644 index 000000000000..e0262570f9e3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-private/output.js @@ -0,0 +1,27 @@ +var _call_a, _initStatic; + +class Foo { + static getA() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); + } + +} + +function _get_a() { + return _call_a(this); +} + +var _a = { + get: _get_a, + set: void 0 +}; + +(() => { + [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 8, "a", function () { + return this.value; + }]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/output.js similarity index 54% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/output.js index 2ec6f560dc4b..68787d432777 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters--to-es2015/static-public/output.js @@ -5,14 +5,6 @@ _computedKey = 'b' _dec2 = dec class Foo { - static { - [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 8, "a"], [_dec2, 8, _computedKey]], []); - - _initStatic(this); - - } - static value = 1; - static get a() { return this.value; } @@ -22,3 +14,11 @@ class Foo { } } + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 8, "a"], [_dec2, 8, _computedKey]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/output.js new file mode 100644 index 000000000000..71e95a6ee2a2 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/private/output.js @@ -0,0 +1,40 @@ +var _call_a, _call_a2, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: _get_a, + set: _set_a + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + getA() { + return babelHelpers.classPrivateFieldGet(this, _a); + } + + setA(v) { + babelHelpers.classPrivateFieldSet(this, _a, v); + } + +} + +function _get_a() { + return _call_a(this); +} + +function _set_a(v) { + _call_a2(this, v); +} + +(() => { + [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 3, "a", function () { + return this.value; + }], [dec, 4, "a", function (v) { + this.value = v; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/output.js similarity index 66% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/output.js index 1a7c8951454d..a05760c5cfe9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/public/output.js @@ -8,16 +8,12 @@ _computedKey2 = 'b' _dec4 = dec class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[_dec, 3, "a"], [_dec2, 4, "a"], [_dec3, 3, _computedKey], [_dec4, 4, _computedKey2]], []); - } - constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + _initProto(this); } - value = 1; - get a() { return this.value; } @@ -35,3 +31,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 3, "a"], [_dec2, 4, "a"], [_dec3, 3, _computedKey], [_dec4, 4, _computedKey2]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/output.js new file mode 100644 index 000000000000..e9ac78c2c966 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-private/output.js @@ -0,0 +1,37 @@ +var _call_a, _call_a2, _initStatic; + +class Foo { + static getA() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); + } + + static setA(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, v); + } + +} + +function _get_a() { + return _call_a(this); +} + +function _set_a(v) { + _call_a2(this, v); +} + +var _a = { + get: _get_a, + set: _set_a +}; + +(() => { + [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 8, "a", function () { + return this.value; + }], [dec, 9, "a", function (v) { + this.value = v; + }]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/output.js similarity index 63% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/output.js index 367b9d127fd7..edcb11764a7a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters--to-es2015/static-public/output.js @@ -8,14 +8,6 @@ _computedKey2 = 'b' _dec4 = dec class Foo { - static { - [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 8, "a"], [_dec2, 9, "a"], [_dec3, 8, _computedKey], [_dec4, 9, _computedKey2]], []); - - _initStatic(this); - - } - static value = 1; - static get a() { return this.value; } @@ -33,3 +25,11 @@ class Foo { } } + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 8, "a"], [_dec2, 9, "a"], [_dec3, 8, _computedKey], [_dec4, 9, _computedKey2]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js index 71e95a6ee2a2..bcf3cae9176e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/private/output.js @@ -1,40 +1,34 @@ var _call_a, _call_a2, _initProto; -var _a = /*#__PURE__*/new WeakMap(); - class Foo { - constructor(...args) { - babelHelpers.classPrivateFieldInitSpec(this, _a, { - get: _get_a, - set: _set_a - }); - babelHelpers.defineProperty(this, "value", 1); + static { + [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a", function () { + return this.value; + }], [dec, 4, "a", function (v) { + this.value = v; + }]], []); + } + constructor(...args) { _initProto(this); } - getA() { - return babelHelpers.classPrivateFieldGet(this, _a); + value = 1; + + get #a() { + return _call_a(this); } - setA(v) { - babelHelpers.classPrivateFieldSet(this, _a, v); + set #a(v) { + _call_a2(this, v); } -} + getA() { + return this.#a; + } -function _get_a() { - return _call_a(this); -} + setA(v) { + this.#a = v; + } -function _set_a(v) { - _call_a2(this, v); } - -(() => { - [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 3, "a", function () { - return this.value; - }], [dec, 4, "a", function (v) { - this.value = v; - }]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js index a05760c5cfe9..1a7c8951454d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/public/output.js @@ -8,12 +8,16 @@ _computedKey2 = 'b' _dec4 = dec class Foo { - constructor(...args) { - babelHelpers.defineProperty(this, "value", 1); + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 3, "a"], [_dec2, 4, "a"], [_dec3, 3, _computedKey], [_dec4, 4, _computedKey2]], []); + } + constructor(...args) { _initProto(this); } + value = 1; + get a() { return this.value; } @@ -31,7 +35,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 3, "a"], [_dec2, 4, "a"], [_dec3, 3, _computedKey], [_dec4, 4, _computedKey2]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js index e9ac78c2c966..e897ea3cd18e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-private/output.js @@ -1,37 +1,32 @@ var _call_a, _call_a2, _initStatic; class Foo { - static getA() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); - } - - static setA(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, v); - } + static { + [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a", function () { + return this.value; + }], [dec, 9, "a", function (v) { + this.value = v; + }]], []); -} + _initStatic(this); -function _get_a() { - return _call_a(this); -} + } + static value = 1; -function _set_a(v) { - _call_a2(this, v); -} + static get #a() { + return _call_a(this); + } -var _a = { - get: _get_a, - set: _set_a -}; + static set #a(v) { + _call_a2(this, v); + } -(() => { - [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 8, "a", function () { - return this.value; - }], [dec, 9, "a", function (v) { - this.value = v; - }]], []); + static getA() { + return this.#a; + } - _initStatic(Foo); -})(); + static setA(v) { + this.#a = v; + } -babelHelpers.defineProperty(Foo, "value", 1); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js index edcb11764a7a..367b9d127fd7 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters-and-setters/static-public/output.js @@ -8,6 +8,14 @@ _computedKey2 = 'b' _dec4 = dec class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 8, "a"], [_dec2, 9, "a"], [_dec3, 8, _computedKey], [_dec4, 9, _computedKey2]], []); + + _initStatic(this); + + } + static value = 1; + static get a() { return this.value; } @@ -25,11 +33,3 @@ class Foo { } } - -(() => { - [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 8, "a"], [_dec2, 9, "a"], [_dec3, 8, _computedKey], [_dec4, 9, _computedKey2]], []); - - _initStatic(Foo); -})(); - -babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js index 32971ca073e9..06ba2926bfa4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/private/output.js @@ -1,30 +1,24 @@ var _call_a, _initProto; -var _a = /*#__PURE__*/new WeakMap(); - class Foo { - constructor(...args) { - babelHelpers.classPrivateFieldInitSpec(this, _a, { - get: _get_a, - set: void 0 - }); - babelHelpers.defineProperty(this, "value", 1); + static { + [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a", function () { + return this.value; + }]], []); + } + constructor(...args) { _initProto(this); } - getA() { - return babelHelpers.classPrivateFieldGet(this, _a); + value = 1; + + get #a() { + return _call_a(this); } -} + getA() { + return this.#a; + } -function _get_a() { - return _call_a(this); } - -(() => { - [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 3, "a", function () { - return this.value; - }]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js index 0152dbf977de..756adf797e3b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/public/output.js @@ -5,12 +5,16 @@ _computedKey = 'b' _dec2 = dec class Foo { - constructor(...args) { - babelHelpers.defineProperty(this, "value", 1); + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 3, "a"], [_dec2, 3, _computedKey]], []); + } + constructor(...args) { _initProto(this); } + value = 1; + get a() { return this.value; } @@ -20,7 +24,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 3, "a"], [_dec2, 3, _computedKey]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js index e0262570f9e3..dc93a5313712 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-private/output.js @@ -1,27 +1,22 @@ var _call_a, _initStatic; class Foo { - static getA() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); - } + static { + [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a", function () { + return this.value; + }]], []); -} - -function _get_a() { - return _call_a(this); -} + _initStatic(this); -var _a = { - get: _get_a, - set: void 0 -}; + } + static value = 1; -(() => { - [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 8, "a", function () { - return this.value; - }]], []); + static get #a() { + return _call_a(this); + } - _initStatic(Foo); -})(); + static getA() { + return this.#a; + } -babelHelpers.defineProperty(Foo, "value", 1); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js index 68787d432777..2ec6f560dc4b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-getters/static-public/output.js @@ -5,6 +5,14 @@ _computedKey = 'b' _dec2 = dec class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 8, "a"], [_dec2, 8, _computedKey]], []); + + _initStatic(this); + + } + static value = 1; + static get a() { return this.value; } @@ -14,11 +22,3 @@ class Foo { } } - -(() => { - [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 8, "a"], [_dec2, 8, _computedKey]], []); - - _initStatic(Foo); -})(); - -babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/class/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/class/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/class/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/class/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/getting-previously-set-metadata/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/getting-previously-set-metadata/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/getting-previously-set-metadata/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/getting-previously-set-metadata/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/inheritance-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/inheritance-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/inheritance-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/inheritance-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/inheritance-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/non-symbol-keys/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/non-symbol-keys/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/non-symbol-keys/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/non-symbol-keys/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/proto-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/proto-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/proto-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/proto-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/proto-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-metadata--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/output.js new file mode 100644 index 000000000000..4e18191445f1 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/private/output.js @@ -0,0 +1,26 @@ +var _call_a, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + writable: true, + value: _call_a + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + callA() { + return babelHelpers.classPrivateFieldGet(this, _a).call(this); + } + +} + +(() => { + [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 2, "a", function () { + return this.value; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/output.js similarity index 60% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/output.js index efac40c1c35e..1835a9fa3548 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/public/output.js @@ -5,16 +5,12 @@ _computedKey = 'b' _dec2 = dec class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, "a"], [_dec2, 2, _computedKey]], []); - } - constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + _initProto(this); } - value = 1; - a() { return this.value; } @@ -24,3 +20,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, "a"], [_dec2, 2, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/output.js new file mode 100644 index 000000000000..3c147c920d64 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-private/output.js @@ -0,0 +1,22 @@ +var _call_a, _initStatic; + +class Foo { + static callA() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a).call(this); + } + +} + +(() => { + [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 7, "a", function () { + return this.value; + }]], []); + + _initStatic(Foo); +})(); + +var _a = { + writable: true, + value: _call_a +}; +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/output.js similarity index 53% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/output.js index 1ad76b111fb4..d1c334def59e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods--to-es2015/static-public/output.js @@ -5,14 +5,6 @@ _computedKey = 'b' _dec2 = dec class Foo { - static { - [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 7, "a"], [_dec2, 7, _computedKey]], []); - - _initStatic(this); - - } - static value = 1; - static a() { return this.value; } @@ -22,3 +14,11 @@ class Foo { } } + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 7, "a"], [_dec2, 7, _computedKey]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js index 4e18191445f1..6f76b6021b6c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/private/output.js @@ -1,26 +1,21 @@ var _call_a, _initProto; -var _a = /*#__PURE__*/new WeakMap(); - class Foo { - constructor(...args) { - babelHelpers.classPrivateFieldInitSpec(this, _a, { - writable: true, - value: _call_a - }); - babelHelpers.defineProperty(this, "value", 1); + static { + [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a", function () { + return this.value; + }]], []); + } + constructor(...args) { _initProto(this); } + #a = _call_a; + value = 1; + callA() { - return babelHelpers.classPrivateFieldGet(this, _a).call(this); + return this.#a(); } } - -(() => { - [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 2, "a", function () { - return this.value; - }]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js index 1835a9fa3548..efac40c1c35e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/public/output.js @@ -5,12 +5,16 @@ _computedKey = 'b' _dec2 = dec class Foo { - constructor(...args) { - babelHelpers.defineProperty(this, "value", 1); + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 2, "a"], [_dec2, 2, _computedKey]], []); + } + constructor(...args) { _initProto(this); } + value = 1; + a() { return this.value; } @@ -20,7 +24,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 2, "a"], [_dec2, 2, _computedKey]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js index 3c147c920d64..6b807803efa6 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-private/output.js @@ -1,22 +1,19 @@ var _call_a, _initStatic; class Foo { - static callA() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a).call(this); - } + static { + [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 7, "a", function () { + return this.value; + }]], []); -} + _initStatic(this); -(() => { - [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 7, "a", function () { - return this.value; - }]], []); + } + static #a = _call_a; + static value = 1; - _initStatic(Foo); -})(); + static callA() { + return this.#a(); + } -var _a = { - writable: true, - value: _call_a -}; -babelHelpers.defineProperty(Foo, "value", 1); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js index d1c334def59e..1ad76b111fb4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-methods/static-public/output.js @@ -5,6 +5,14 @@ _computedKey = 'b' _dec2 = dec class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 7, "a"], [_dec2, 7, _computedKey]], []); + + _initStatic(this); + + } + static value = 1; + static a() { return this.value; } @@ -14,11 +22,3 @@ class Foo { } } - -(() => { - [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 7, "a"], [_dec2, 7, _computedKey]], []); - - _initStatic(Foo); -})(); - -babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initializer-timing/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initializer-timing/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initializer-timing/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initializer-timing/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js new file mode 100644 index 000000000000..79b845170bc7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js @@ -0,0 +1,40 @@ +var _initClass, _initProto; + +let _Foo; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + writable: true, + value: void 0 + }); + + _initProto(this); + } + + method() {} + + makeClass() { + var _init_bar, _class, _temp; + + return _temp = _class = class Nested { + constructor() { + babelHelpers.defineProperty(this, "bar", _init_bar(this)); + } + + }, (() => { + [_init_bar] = babelHelpers.applyDecs(_class, [[babelHelpers.classPrivateFieldGet(_class, _a), 0, "bar"]], []); + })(), _temp; + } + +} + +(() => { + [_Foo, _initClass, _initProto] = babelHelpers.applyDecs(Foo, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]); +})(); + +(() => { + _initClass(); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/private-keys-in-enclosing-class/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/private-keys-in-enclosing-class/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/private-keys-in-enclosing-class/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/private-keys-in-enclosing-class/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/private-keys-in-enclosing-class/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-array-pattern/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-array-pattern/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-array-pattern/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-array-pattern/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-array-pattern/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-for-of/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-for-of/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-for-of/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-for-of/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-for-of/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-object-pattern/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-object-pattern/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-object-pattern/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-object-pattern/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-object-pattern/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-rest/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-rest/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-rest/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-rest/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-rest/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-update/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-update/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-update/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method-via-update/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method-via-update/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method/options.json similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/setting-private-method/options.json rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/setting-private-method/options.json diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-nested-constructor-expression/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-nested-constructor-expression/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-nested-constructor-expression/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-nested-constructor-expression/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-nested-constructor-expression/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-accessor/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-accessor/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-accessor/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-accessor/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-accessor/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-method/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-method/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-method/output.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/super-in-private-method/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/super-in-private-method/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js index 79b845170bc7..5490137a9009 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/valid-expression-formats/output.js @@ -2,39 +2,32 @@ var _initClass, _initProto; let _Foo; -var _a = /*#__PURE__*/new WeakMap(); - class Foo { - constructor(...args) { - babelHelpers.classPrivateFieldInitSpec(this, _a, { - writable: true, - value: void 0 - }); + static { + [_Foo, _initClass, _initProto] = babelHelpers.applyDecs(this, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]); + } + constructor(...args) { _initProto(this); } + #a; + method() {} makeClass() { - var _init_bar, _class, _temp; + var _init_bar; - return _temp = _class = class Nested { - constructor() { - babelHelpers.defineProperty(this, "bar", _init_bar(this)); + return class Nested { + static { + [_init_bar] = babelHelpers.applyDecs(this, [[this.#a, 0, "bar"]], []); } - - }, (() => { - [_init_bar] = babelHelpers.applyDecs(_class, [[babelHelpers.classPrivateFieldGet(_class, _a), 0, "bar"]], []); - })(), _temp; + bar = _init_bar(this); + }; } -} - -(() => { - [_Foo, _initClass, _initProto] = babelHelpers.applyDecs(Foo, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]); -})(); + static { + _initClass(); -(() => { - _initClass(); -})(); + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/options.json new file mode 100644 index 000000000000..69f3e599cf2d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "proposal-decorators", + { "version": "2021-12", "decoratorsBeforeExport": false } + ], + "proposal-class-properties", + "proposal-private-methods", + "proposal-class-static-block" + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/output.js new file mode 100644 index 000000000000..5d0ad516b80b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/private/output.js @@ -0,0 +1,30 @@ +var _call_a, _initProto; + +var _a = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor(...args) { + babelHelpers.classPrivateFieldInitSpec(this, _a, { + get: void 0, + set: _set_a + }); + babelHelpers.defineProperty(this, "value", 1); + + _initProto(this); + } + + setA(v) { + babelHelpers.classPrivateFieldSet(this, _a, v); + } + +} + +function _set_a(v) { + _call_a(this, v); +} + +(() => { + [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 4, "a", function (v) { + return this.value = v; + }]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/output.js similarity index 61% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/output.js index ad6f2edce743..256297632372 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/public/output.js @@ -5,16 +5,12 @@ _computedKey = 'b' _dec2 = dec class Foo { - static { - [_initProto] = babelHelpers.applyDecs(this, [[_dec, 4, "a"], [_dec2, 4, _computedKey]], []); - } - constructor(...args) { + babelHelpers.defineProperty(this, "value", 1); + _initProto(this); } - value = 1; - set a(v) { return this.value = v; } @@ -24,3 +20,7 @@ class Foo { } } + +(() => { + [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 4, "a"], [_dec2, 4, _computedKey]], []); +})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/output.js new file mode 100644 index 000000000000..45e47a57177c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-private/output.js @@ -0,0 +1,27 @@ +var _call_a, _initStatic; + +class Foo { + static setA(v) { + babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, v); + } + +} + +function _set_a(v) { + _call_a(this, v); +} + +var _a = { + get: void 0, + set: _set_a +}; + +(() => { + [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 9, "a", function (v) { + return this.value = v; + }]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/input.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/input.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/input.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/output.js similarity index 55% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/output.js index 230ee2bc8aff..e890b8fb8d4a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters--to-es2015/static-public/output.js @@ -5,14 +5,6 @@ _computedKey = 'b' _dec2 = dec class Foo { - static { - [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 9, "a"], [_dec2, 9, _computedKey]], []); - - _initStatic(this); - - } - static value = 1; - static set a(v) { return this.value = v; } @@ -22,3 +14,11 @@ class Foo { } } + +(() => { + [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 9, "a"], [_dec2, 9, _computedKey]], []); + + _initStatic(Foo); +})(); + +babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json index 69f3e599cf2d..18aa205580db 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/options.json @@ -3,9 +3,6 @@ [ "proposal-decorators", { "version": "2021-12", "decoratorsBeforeExport": false } - ], - "proposal-class-properties", - "proposal-private-methods", - "proposal-class-static-block" + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js index 5d0ad516b80b..a1b2e04ab8f1 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/private/output.js @@ -1,30 +1,24 @@ var _call_a, _initProto; -var _a = /*#__PURE__*/new WeakMap(); - class Foo { - constructor(...args) { - babelHelpers.classPrivateFieldInitSpec(this, _a, { - get: void 0, - set: _set_a - }); - babelHelpers.defineProperty(this, "value", 1); + static { + [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 4, "a", function (v) { + return this.value = v; + }]], []); + } + constructor(...args) { _initProto(this); } - setA(v) { - babelHelpers.classPrivateFieldSet(this, _a, v); + value = 1; + + set #a(v) { + _call_a(this, v); } -} + setA(v) { + this.#a = v; + } -function _set_a(v) { - _call_a(this, v); } - -(() => { - [_call_a, _initProto] = babelHelpers.applyDecs(Foo, [[dec, 4, "a", function (v) { - return this.value = v; - }]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js index 256297632372..ad6f2edce743 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/public/output.js @@ -5,12 +5,16 @@ _computedKey = 'b' _dec2 = dec class Foo { - constructor(...args) { - babelHelpers.defineProperty(this, "value", 1); + static { + [_initProto] = babelHelpers.applyDecs(this, [[_dec, 4, "a"], [_dec2, 4, _computedKey]], []); + } + constructor(...args) { _initProto(this); } + value = 1; + set a(v) { return this.value = v; } @@ -20,7 +24,3 @@ class Foo { } } - -(() => { - [_initProto] = babelHelpers.applyDecs(Foo, [[_dec, 4, "a"], [_dec2, 4, _computedKey]], []); -})(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js index 45e47a57177c..6bcadc0cc528 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-private/output.js @@ -1,27 +1,22 @@ var _call_a, _initStatic; class Foo { - static setA(v) { - babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, v); - } + static { + [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 9, "a", function (v) { + return this.value = v; + }]], []); -} - -function _set_a(v) { - _call_a(this, v); -} + _initStatic(this); -var _a = { - get: void 0, - set: _set_a -}; + } + static value = 1; -(() => { - [_call_a, _initStatic] = babelHelpers.applyDecs(Foo, [[dec, 9, "a", function (v) { - return this.value = v; - }]], []); + static set #a(v) { + _call_a(this, v); + } - _initStatic(Foo); -})(); + static setA(v) { + this.#a = v; + } -babelHelpers.defineProperty(Foo, "value", 1); +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js index e890b8fb8d4a..230ee2bc8aff 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-setters/static-public/output.js @@ -5,6 +5,14 @@ _computedKey = 'b' _dec2 = dec class Foo { + static { + [_initStatic] = babelHelpers.applyDecs(this, [[_dec, 9, "a"], [_dec2, 9, _computedKey]], []); + + _initStatic(this); + + } + static value = 1; + static set a(v) { return this.value = v; } @@ -14,11 +22,3 @@ class Foo { } } - -(() => { - [_initStatic] = babelHelpers.applyDecs(Foo, [[_dec, 9, "a"], [_dec2, 9, _computedKey]], []); - - _initStatic(Foo); -})(); - -babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js deleted file mode 100644 index c054a288032a..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/private/output.js +++ /dev/null @@ -1,35 +0,0 @@ -var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto; - -class Foo { - static { - [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = babelHelpers.applyDecs(this, [[dec, 1, "a", function () { - return this.#A; - }, function (value) { - this.#A = value; - }], [dec, 1, "b", function () { - return this.#B; - }, function (value) { - this.#B = value; - }]], []); - } - #A = (_initProto(this), _init_a(this)); - - set #a(v) { - _set_a(this, v); - } - - get #a() { - _get_a(this); - } - - #B = _init_b(this, 123); - - set #b(v) { - _set_b(this, v); - } - - get #b() { - _get_b(this); - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js deleted file mode 100644 index 0fb94194b1db..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/public/output.js +++ /dev/null @@ -1,42 +0,0 @@ -var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initProto; - -_dec = dec -_dec2 = dec -_computedKey = 'c' -_dec3 = dec - -class Foo { - static { - [_init_a, _init_b, _init_computedKey, _initProto] = babelHelpers.applyDecs(this, [[_dec, 1, "a"], [_dec2, 1, "b"], [_dec3, 1, _computedKey]], []); - } - #A = (_initProto(this), _init_a(this)); - - get a() { - return this.#A; - } - - set a(v) { - this.#A = v; - } - - #B = _init_b(this, 123); - - get b() { - return this.#B; - } - - set b(v) { - this.#B = v; - } - - #C = _init_computedKey(this, 456); - - get [_computedKey]() { - return this.#C; - } - - set [_computedKey](v) { - this.#C = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js deleted file mode 100644 index ad30531a425e..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-private/output.js +++ /dev/null @@ -1,38 +0,0 @@ -var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic; - -class Foo { - static { - [_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(this, [[dec, 6, "a", function () { - return this.#A; - }, function (value) { - this.#A = value; - }], [dec, 6, "b", function () { - return this.#B; - }, function (value) { - this.#B = value; - }]], []); - - _initStatic(this); - - } - static #A = _init_a(this); - - set #a(v) { - _set_a(this, v); - } - - get #a() { - _get_a(this); - } - - static #B = _init_b(this, 123); - - set #b(v) { - _set_b(this, v); - } - - get #b() { - _get_b(this); - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js deleted file mode 100644 index 471adf36f9c9..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/static-public/output.js +++ /dev/null @@ -1,45 +0,0 @@ -var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3, _initStatic; - -_dec = dec -_dec2 = dec -_computedKey = 'c' -_dec3 = dec - -class Foo { - static { - [_init_a, _init_b, _init_computedKey, _initStatic] = babelHelpers.applyDecs(this, [[_dec, 6, "a"], [_dec2, 6, "b"], [_dec3, 6, _computedKey]], []); - - _initStatic(this); - - } - static #A = _init_a(this); - - static get a() { - return this.#A; - } - - static set a(v) { - this.#A = v; - } - - static #B = _init_b(this, 123); - - static get b() { - return this.#B; - } - - static set b(v) { - this.#B = v; - } - - static #C = _init_computedKey(this, 456); - - static get [_computedKey]() { - return this.#C; - } - - static set [_computedKey](v) { - this.#C = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js deleted file mode 100644 index 9eb7268e4131..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-private/output.js +++ /dev/null @@ -1,22 +0,0 @@ -class Foo { - #A; - - get #a() { - return this.#A; - } - - set #a(v) { - this.#A = v; - } - - #B = 123; - - get #b() { - return this.#B; - } - - set #b(v) { - this.#B = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js deleted file mode 100644 index f6269be736f1..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-public/output.js +++ /dev/null @@ -1,32 +0,0 @@ -class Foo { - #A; - - get a() { - return this.#A; - } - - set a(v) { - this.#A = v; - } - - #B = 123; - - get b() { - return this.#B; - } - - set b(v) { - this.#B = v; - } - - #C = 456; - - get 'c'() { - return this.#C; - } - - set 'c'(v) { - this.#C = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js deleted file mode 100644 index 04cc0ef030d0..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-private/output.js +++ /dev/null @@ -1,22 +0,0 @@ -class Foo { - static #A; - - static get #a() { - return this.#A; - } - - static set #a(v) { - this.#A = v; - } - - static #B = 123; - - static get #b() { - return this.#B; - } - - static set #b(v) { - this.#B = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js deleted file mode 100644 index 187ad5214a67..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-accessors/undecorated-static-public/output.js +++ /dev/null @@ -1,32 +0,0 @@ -class Foo { - static #A; - - static get a() { - return this.#A; - } - - static set a(v) { - this.#A = v; - } - - static #B = 123; - - static get b() { - return this.#B; - } - - static set b(v) { - this.#B = v; - } - - static #C = 456; - - static get 'c'() { - return this.#C; - } - - static set 'c'(v) { - this.#C = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js deleted file mode 100644 index 146cdb17ca70..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/expressions/output.js +++ /dev/null @@ -1,87 +0,0 @@ -var _initClass, _A, _initClass2, _C, _initClass3, _D, _initClass4, _decorated_class, _initClass5, _G, _initClass6, _decorated_class2, _initClass7, _H, _initClass8, _K; - -const A = (class A { - static { - [_A, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass(); - - } -}, _A); -const B = (class C { - static { - [_C, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass2(); - - } -}, _C); -const D = (class D { - static { - [_D, _initClass3] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass3(); - - } -}, _D); -const E = ((class { - static { - [_decorated_class, _initClass4] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass4(); - - } -}, _decorated_class), 123); -const F = [(class G { - static { - [_G, _initClass5] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass5(); - - } -}, _G), (class { - static { - [_decorated_class2, _initClass6] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass6(); - - } -}, _decorated_class2)]; -const H = (class H extends I { - static { - [_H, _initClass7] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass7(); - - } -}, _H); -const J = (class K extends L { - static { - [_K, _initClass8] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass8(); - - } -}, _K); - -function classFactory() { - var _initClass9, _decorated_class3; - - return class { - static { - [_decorated_class3, _initClass9] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - _initClass9(); - - } - }, _decorated_class3; -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js deleted file mode 100644 index d7ea9b35166e..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/inheritance/output.js +++ /dev/null @@ -1,25 +0,0 @@ -var _initClass, _initClass2; - -let _Bar; - -class Bar { - static { - [_Bar, _initClass] = babelHelpers.applyDecs(this, [], [dec1]); - } - static { - _initClass(); - - } -} - -let _Foo; - -class Foo extends _Bar { - static { - [_Foo, _initClass2] = babelHelpers.applyDecs(this, [], [dec2]); - } - static { - _initClass2(); - - } -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js deleted file mode 100644 index c4b21cf992e6..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/initializers/output.js +++ /dev/null @@ -1,30 +0,0 @@ -var _initClass, _initClass2; - -let _Foo; - -class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } - static field = 123; - static { - _initClass(); - - } -} - -let _Bar; - -class Bar extends _Foo { - static { - [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); - } - static { - this.otherField = 456; - } - static field = 123; - static { - _initClass2(); - - } -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js deleted file mode 100644 index 4c37edebb1dd..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement-with-expr/output.js +++ /dev/null @@ -1,13 +0,0 @@ -var _initClass, _Bar; - -const Foo = (class Bar { - static { - [_Bar, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } - bar = new _Bar(); - static { - _initClass(); - - } -}, _Bar); -const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js deleted file mode 100644 index 046ba5f9a759..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-classes/replacement/output.js +++ /dev/null @@ -1,16 +0,0 @@ -var _initClass; - -let _Foo; - -class Foo { - static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); - } - static foo = new _Foo(); - static { - _initClass(); - - } -} - -const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js deleted file mode 100644 index cb04e3cc2e5d..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-duplicated-keys/method-and-field/output.js +++ /dev/null @@ -1,13 +0,0 @@ -var _init_a, _initProto; - -class Foo { - static { - [_init_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 0, "a"], [dec, 2, "a"]], []); - } - a = (_initProto(this), _init_a(this, 123)); - - a() { - return 1; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js deleted file mode 100644 index b72a6d971df6..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/private/output.js +++ /dev/null @@ -1,17 +0,0 @@ -var _init_a, _init_b; - -class Foo { - static { - [_init_a, _init_b] = babelHelpers.applyDecs(this, [[dec, 0, "a", function () { - return this.#a; - }, function (value) { - this.#a = value; - }], [dec, 0, "b", function () { - return this.#b; - }, function (value) { - this.#b = value; - }]], []); - } - #a = _init_a(this); - #b = _init_b(this, 123); -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js deleted file mode 100644 index 06c0434d04a6..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/public/output.js +++ /dev/null @@ -1,15 +0,0 @@ -var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; - -_dec = dec -_dec2 = dec -_computedKey = 'c' -_dec3 = dec - -class Foo { - static { - [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(this, [[_dec, 0, "a"], [_dec2, 0, "b"], [_dec3, 0, _computedKey]], []); - } - a = _init_a(this); - b = _init_b(this, 123); - [_computedKey] = _init_computedKey(this, 456); -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js deleted file mode 100644 index cb167ff192fd..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-private/output.js +++ /dev/null @@ -1,17 +0,0 @@ -var _init_a, _init_b; - -class Foo { - static { - [_init_a, _init_b] = babelHelpers.applyDecs(this, [[dec, 5, "a", function () { - return this.#a; - }, function (value) { - this.#a = value; - }], [dec, 5, "b", function () { - return this.#b; - }, function (value) { - this.#b = value; - }]], []); - } - static #a = _init_a(this); - static #b = _init_b(this, 123); -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js deleted file mode 100644 index 64af25745500..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-fields/static-public/output.js +++ /dev/null @@ -1,15 +0,0 @@ -var _init_a, _init_b, _computedKey, _init_computedKey, _dec, _dec2, _dec3; - -_dec = dec -_dec2 = dec -_computedKey = 'c' -_dec3 = dec - -class Foo { - static { - [_init_a, _init_b, _init_computedKey] = babelHelpers.applyDecs(this, [[_dec, 5, "a"], [_dec2, 5, "b"], [_dec3, 5, _computedKey]], []); - } - static a = _init_a(this); - static b = _init_b(this, 123); - static [_computedKey] = _init_computedKey(this, 456); -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json deleted file mode 100644 index 18aa205580db..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/options.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - [ - "proposal-decorators", - { "version": "2021-12", "decoratorsBeforeExport": false } - ] - ] -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js deleted file mode 100644 index bcf3cae9176e..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/private/output.js +++ /dev/null @@ -1,34 +0,0 @@ -var _call_a, _call_a2, _initProto; - -class Foo { - static { - [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a", function () { - return this.value; - }], [dec, 4, "a", function (v) { - this.value = v; - }]], []); - } - - constructor(...args) { - _initProto(this); - } - - value = 1; - - get #a() { - return _call_a(this); - } - - set #a(v) { - _call_a2(this, v); - } - - getA() { - return this.#a; - } - - setA(v) { - this.#a = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js deleted file mode 100644 index e897ea3cd18e..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters-and-setters/static-private/output.js +++ /dev/null @@ -1,32 +0,0 @@ -var _call_a, _call_a2, _initStatic; - -class Foo { - static { - [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a", function () { - return this.value; - }], [dec, 9, "a", function (v) { - this.value = v; - }]], []); - - _initStatic(this); - - } - static value = 1; - - static get #a() { - return _call_a(this); - } - - static set #a(v) { - _call_a2(this, v); - } - - static getA() { - return this.#a; - } - - static setA(v) { - this.#a = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json deleted file mode 100644 index 18aa205580db..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/options.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - [ - "proposal-decorators", - { "version": "2021-12", "decoratorsBeforeExport": false } - ] - ] -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js deleted file mode 100644 index 06ba2926bfa4..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/private/output.js +++ /dev/null @@ -1,24 +0,0 @@ -var _call_a, _initProto; - -class Foo { - static { - [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a", function () { - return this.value; - }]], []); - } - - constructor(...args) { - _initProto(this); - } - - value = 1; - - get #a() { - return _call_a(this); - } - - getA() { - return this.#a; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js deleted file mode 100644 index dc93a5313712..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-getters/static-private/output.js +++ /dev/null @@ -1,22 +0,0 @@ -var _call_a, _initStatic; - -class Foo { - static { - [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 8, "a", function () { - return this.value; - }]], []); - - _initStatic(this); - - } - static value = 1; - - static get #a() { - return _call_a(this); - } - - static getA() { - return this.#a; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json deleted file mode 100644 index 18aa205580db..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/options.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - [ - "proposal-decorators", - { "version": "2021-12", "decoratorsBeforeExport": false } - ] - ] -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js deleted file mode 100644 index 6f76b6021b6c..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/private/output.js +++ /dev/null @@ -1,21 +0,0 @@ -var _call_a, _initProto; - -class Foo { - static { - [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a", function () { - return this.value; - }]], []); - } - - constructor(...args) { - _initProto(this); - } - - #a = _call_a; - value = 1; - - callA() { - return this.#a(); - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js deleted file mode 100644 index 6b807803efa6..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-methods/static-private/output.js +++ /dev/null @@ -1,19 +0,0 @@ -var _call_a, _initStatic; - -class Foo { - static { - [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 7, "a", function () { - return this.value; - }]], []); - - _initStatic(this); - - } - static #a = _call_a; - static value = 1; - - static callA() { - return this.#a(); - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json deleted file mode 100644 index 18aa205580db..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/options.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - [ - "proposal-decorators", - { "version": "2021-12", "decoratorsBeforeExport": false } - ] - ] -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js deleted file mode 100644 index 5490137a9009..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-misc/valid-expression-formats/output.js +++ /dev/null @@ -1,33 +0,0 @@ -var _initClass, _initProto; - -let _Foo; - -class Foo { - static { - [_Foo, _initClass, _initProto] = babelHelpers.applyDecs(this, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]); - } - - constructor(...args) { - _initProto(this); - } - - #a; - - method() {} - - makeClass() { - var _init_bar; - - return class Nested { - static { - [_init_bar] = babelHelpers.applyDecs(this, [[this.#a, 0, "bar"]], []); - } - bar = _init_bar(this); - }; - } - - static { - _initClass(); - - } -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json deleted file mode 100644 index 18aa205580db..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/options.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - [ - "proposal-decorators", - { "version": "2021-12", "decoratorsBeforeExport": false } - ] - ] -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js deleted file mode 100644 index a1b2e04ab8f1..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/private/output.js +++ /dev/null @@ -1,24 +0,0 @@ -var _call_a, _initProto; - -class Foo { - static { - [_call_a, _initProto] = babelHelpers.applyDecs(this, [[dec, 4, "a", function (v) { - return this.value = v; - }]], []); - } - - constructor(...args) { - _initProto(this); - } - - value = 1; - - set #a(v) { - _call_a(this, v); - } - - setA(v) { - this.#a = v; - } - -} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js deleted file mode 100644 index 6bcadc0cc528..000000000000 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-transform-only-setters/static-private/output.js +++ /dev/null @@ -1,22 +0,0 @@ -var _call_a, _initStatic; - -class Foo { - static { - [_call_a, _initStatic] = babelHelpers.applyDecs(this, [[dec, 9, "a", function (v) { - return this.value = v; - }]], []); - - _initStatic(this); - - } - static value = 1; - - static set #a(v) { - _call_a(this, v); - } - - static setA(v) { - this.#a = v; - } - -} From e1c0086fe0fbe19e23b8b984ca1e4d3a26e9867c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 6 Jan 2022 18:30:25 +0100 Subject: [PATCH 05/24] Install static fields and private methods on the correct class --- packages/babel-helpers/src/helpers.ts | 6 + .../src/transformer-2021-12.ts | 157 ++++++++++++++---- .../initializers/output.js | 46 ++--- .../exec.js | 33 ++++ .../input.js | 15 ++ .../output.js | 32 ++++ .../replacement-static-this/exec.js | 19 +++ .../replacement-static-this/input.js | 10 ++ .../replacement-static-this/output.js | 22 +++ .../replacement/output.js | 22 +-- .../2021-12-classes/initializers/output.js | 39 +++-- .../input.js | 15 ++ .../output.js | 33 ++++ .../replacement-static-this/input.js | 10 ++ .../replacement-static-this/output.js | 24 +++ .../2021-12-classes/replacement/output.js | 17 +- packages/babel-runtime-corejs2/package.json | 9 + packages/babel-runtime-corejs3/package.json | 9 + packages/babel-runtime/package.json | 9 + 19 files changed, 443 insertions(+), 84 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/exec.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js diff --git a/packages/babel-helpers/src/helpers.ts b/packages/babel-helpers/src/helpers.ts index 80ee32905a72..355aa8fd6e4e 100644 --- a/packages/babel-helpers/src/helpers.ts +++ b/packages/babel-helpers/src/helpers.ts @@ -2052,3 +2052,9 @@ if (!process.env.BABEL_8_BREAKING) { } `; } + +helpers.identity = helper("7.16.7")` + export default function _identity(x) { + return x; + } +`; diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index 95872e23a98c..7519ed552373 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -1,5 +1,5 @@ import type { NodePath } from "@babel/traverse"; -import { types as t } from "@babel/core"; +import { types as t, template } from "@babel/core"; import syntaxDecorators from "@babel/plugin-syntax-decorators"; import ReplaceSupers from "@babel/helper-replace-supers"; import * as charCodes from "charcodes"; @@ -447,6 +447,19 @@ function isClassDecoratableElementPath( ); } +function staticBlockToIIFE(block: t.StaticBlock) { + return t.callExpression( + t.arrowFunctionExpression([], t.blockStatement(block.body)), + [], + ); +} + +function maybeSequenceExpression(exprs: t.Expression[]) { + if (exprs.length === 0) return t.unaryExpression("void", t.numericLiteral(0)); + if (exprs.length === 1) return exprs[0]; + return t.sequenceExpression(exprs); +} + function transformClass( path: NodePath, state: any, @@ -836,38 +849,6 @@ function transformClass( locals.push(staticInitLocal); } - const staticBlock = t.staticBlock( - [ - t.expressionStatement( - t.assignmentExpression( - "=", - t.arrayPattern(locals), - t.callExpression(state.addHelper("applyDecs"), [ - t.thisExpression(), - elementDecorations, - classDecorations, - ]), - ), - ), - requiresStaticInit && - t.expressionStatement( - t.callExpression(t.cloneNode(staticInitLocal), [t.thisExpression()]), - ), - ].filter(v => v), - ); - - path.node.body.body.unshift(staticBlock as unknown as ClassElement); - - if (classInitLocal) { - path.node.body.body.push( - t.staticBlock([ - t.expressionStatement( - t.callExpression(t.cloneNode(classInitLocal), []), - ), - ]), - ); - } - if (decoratedPrivateMethods.size > 0) { path.traverse({ PrivateName(path) { @@ -902,6 +883,116 @@ function transformClass( }); } + let classInitInjected = false; + const classInitCall = + classInitLocal && t.callExpression(t.cloneNode(classInitLocal), []); + + const originalClass = path.node; + + if (classDecorators) { + const statics = []; + let staticBlocks: t.StaticBlock[] = []; + path.get("body.body").forEach(element => { + // Static blocks cannot be compiled to "instance blocks", but we can inline + // them as IIFEs in the next property. + if (element.isStaticBlock()) { + staticBlocks.push(element.node); + element.remove(); + return; + } + + const isProperty = + element.isClassProperty() || element.isClassPrivateProperty(); + + if ( + (isProperty || element.isClassPrivateMethod()) && + element.node.static + ) { + if (isProperty && staticBlocks.length > 0) { + const allValues: t.Expression[] = staticBlocks.map(staticBlockToIIFE); + if (element.node.value) allValues.push(element.node.value); + element.node.value = maybeSequenceExpression(allValues); + staticBlocks = []; + } + + element.node.static = false; + statics.push(element.node); + element.remove(); + } + }); + + if (statics.length > 0 || staticBlocks.length > 0) { + const staticsClass = template.expression.ast` + class extends ${state.addHelper("identity")} {} + ` as t.ClassExpression; + staticsClass.body.body = [ + t.staticBlock([t.toStatement(path.node, false)]), + ...statics, + ]; + + const constructorBody: t.Expression[] = []; + + const newExpr = t.newExpression(staticsClass, []); + + if (staticBlocks.length > 0) { + constructorBody.push(...staticBlocks.map(staticBlockToIIFE)); + } + if (classInitCall) { + classInitInjected = true; + constructorBody.push(classInitCall); + } + if (constructorBody.length > 0) { + constructorBody.unshift( + t.callExpression(t.super(), [t.cloneNode(classLocal)]), + ); + + staticsClass.body.body.push( + t.classMethod( + "constructor", + t.identifier("constructor"), + [], + t.blockStatement([ + t.expressionStatement(t.sequenceExpression(constructorBody)), + ]), + ), + ); + } else { + newExpr.arguments.push(t.cloneNode(classLocal)); + } + + path.replaceWith(newExpr); + } + } + if (!classInitInjected && classInitCall) { + path.node.body.body.push( + t.staticBlock([t.expressionStatement(classInitCall)]), + ); + } + + originalClass.body.body.unshift( + t.staticBlock( + [ + t.expressionStatement( + t.assignmentExpression( + "=", + t.arrayPattern(locals), + t.callExpression(state.addHelper("applyDecs"), [ + t.thisExpression(), + elementDecorations, + classDecorations, + ]), + ), + ), + requiresStaticInit && + t.expressionStatement( + t.callExpression(t.cloneNode(staticInitLocal), [ + t.thisExpression(), + ]), + ), + ].filter(Boolean), + ), + ); + // Recrawl the scope to make sure new identifiers are properly synced path.scope.crawl(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js index a197b92f57e6..3ed28458cab0 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js @@ -1,33 +1,37 @@ -var _initClass, _initClass2; +var _initClass, _temp2, _initClass2, _temp4; let _Foo; -class Foo {} +new (_temp2 = class extends babelHelpers.identity { + constructor() { + var _temp; -(() => { - [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); -})(); + (_temp = super(_Foo), babelHelpers.defineProperty(this, "field", 123), _temp), _initClass(); + } -babelHelpers.defineProperty(Foo, "field", 123); +}, (() => { + class Foo {} -(() => { - _initClass(); -})(); + (() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); + })(); +})(), _temp2)(); let _Bar; -class Bar extends _Foo {} +new (_temp4 = class extends babelHelpers.identity { + constructor() { + var _temp3; -(() => { - [_Bar, _initClass2] = babelHelpers.applyDecs(Bar, [], [dec]); -})(); + (_temp3 = super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { + this.otherField = 456; + })(), 123)), _temp3), _initClass2(); + } -(() => { - Bar.otherField = 456; -})(); +}, (() => { + class Bar extends _Foo {} -babelHelpers.defineProperty(Bar, "field", 123); - -(() => { - _initClass2(); -})(); + (() => { + [_Bar, _initClass2] = babelHelpers.applyDecs(Bar, [], [dec]); + })(); +})(), _temp4)(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/exec.js new file mode 100644 index 000000000000..2f4e342e3eee --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/exec.js @@ -0,0 +1,33 @@ +let hasX, hasM, OriginalFoo; + +class Bar {} + +function dec(Foo) { + OriginalFoo = Foo; + return Bar; +} + +@dec +class Foo { + static #x; + static #m() {} + + static x; + static m() {} + + static { + hasX = o => #x in o; + hasM = o => #m in o; + } +} + +expect(hasX(Bar)).toBe(true); +expect(hasM(Bar)).toBe(true); +expect(hasX(OriginalFoo)).toBe(false); +expect(hasM(OriginalFoo)).toBe(false); + +expect(Bar.hasOwnProperty("x")).toBe(true); +expect(OriginalFoo.hasOwnProperty("x")).toBe(false); + +expect(Bar.hasOwnProperty("m")).toBe(false); +expect(OriginalFoo.hasOwnProperty("m")).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/input.js new file mode 100644 index 000000000000..daf74ddd2d36 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/input.js @@ -0,0 +1,15 @@ +let hasX, hasM; + +@dec +class Foo { + static #x; + static #m() {} + + static x; + static m() {} + + static { + hasX = o => #x in o; + hasM = o => #m in o; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js new file mode 100644 index 000000000000..f11cf07517d3 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -0,0 +1,32 @@ +var _initClass, _x, _m, _temp2; + +let hasX, hasM; + +let _Foo; + +new (_temp2 = (_x = /*#__PURE__*/new WeakMap(), _m = /*#__PURE__*/new WeakSet(), class extends babelHelpers.identity { + constructor() { + var _temp; + + (_temp = super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _m), babelHelpers.classPrivateFieldInitSpec(this, _x, { + writable: true, + value: void 0 + }), babelHelpers.defineProperty(this, "x", void 0), _temp), (() => { + hasX = o => _x.has(o); + + hasM = o => _m.has(o); + })(), _initClass(); + } + +}), (() => { + class Foo { + static m() {} + + } + + (() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); + })(); +})(), _temp2)(); + +function _m2() {} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/exec.js new file mode 100644 index 000000000000..6b55df43edc8 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/exec.js @@ -0,0 +1,19 @@ + +class Bar {} + +let _this, _this2, _this3; + +@(() => Bar) +class Foo { + static { + _this = this; + } + static field = (_this2 = this); + static { + _this3 = this; + } +} + +expect(_this).toBe(Bar); +expect(_this2).toBe(Bar); +expect(_this3).toBe(Bar); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/input.js new file mode 100644 index 000000000000..51bc09c85652 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/input.js @@ -0,0 +1,10 @@ +@dec +class Foo { + static { + this + } + static field = this; + static { + this + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js new file mode 100644 index 000000000000..fe77f96f5af9 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js @@ -0,0 +1,22 @@ +var _initClass, _temp2; + +let _Foo; + +new (_temp2 = class extends babelHelpers.identity { + constructor() { + var _temp; + + (_temp = super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { + this; + })(), this)), _temp), (() => { + this; + })(), _initClass(); + } + +}, (() => { + class Foo {} + + (() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); + })(); +})(), _temp2)(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js index 4a26f8ccd8bf..f302d19a6ecb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js @@ -1,17 +1,19 @@ -var _initClass; +var _initClass, _temp2; let _Foo; -class Foo {} +new (_temp2 = class extends babelHelpers.identity { + constructor() { + var _temp; -(() => { - [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); -})(); + (_temp = super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo()), _temp), _initClass(); + } -babelHelpers.defineProperty(Foo, "foo", new _Foo()); - -(() => { - _initClass(); -})(); +}, (() => { + class Foo {} + (() => { + [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); + })(); +})(), _temp2)(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js index c4b21cf992e6..982a63a72f28 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/initializers/output.js @@ -2,29 +2,40 @@ var _initClass, _initClass2; let _Foo; -class Foo { +new class extends babelHelpers.identity { static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + } + } - static field = 123; - static { - _initClass(); + field = 123; + constructor() { + super(_Foo), _initClass(); } -} + +}(); let _Bar; -class Bar extends _Foo { +new class extends babelHelpers.identity { static { - [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); + class Bar extends _Foo { + static { + [_Bar, _initClass2] = babelHelpers.applyDecs(this, [], [dec]); + } + } + } - static { + field = ((() => { this.otherField = 456; - } - static field = 123; - static { - _initClass2(); + })(), 123); + constructor() { + super(_Bar), _initClass2(); } -} + +}(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/input.js new file mode 100644 index 000000000000..daf74ddd2d36 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/input.js @@ -0,0 +1,15 @@ +let hasX, hasM; + +@dec +class Foo { + static #x; + static #m() {} + + static x; + static m() {} + + static { + hasX = o => #x in o; + hasM = o => #m in o; + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js new file mode 100644 index 000000000000..8f36ec034422 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-installed-on-correct-class/output.js @@ -0,0 +1,33 @@ +var _initClass; + +let hasX, hasM; + +let _Foo; + +new class extends babelHelpers.identity { + static { + class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + + static m() {} + + } + + } + #x; + + #m() {} + + x; + + constructor() { + super(_Foo), (() => { + hasX = o => #x in o; + + hasM = o => #m in o; + })(), _initClass(); + } + +}(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/input.js new file mode 100644 index 000000000000..51bc09c85652 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/input.js @@ -0,0 +1,10 @@ +@dec +class Foo { + static { + this + } + static field = this; + static { + this + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js new file mode 100644 index 000000000000..5ca20ff8d696 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement-static-this/output.js @@ -0,0 +1,24 @@ +var _initClass; + +let _Foo; + +new class extends babelHelpers.identity { + static { + class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + } + + } + field = ((() => { + this; + })(), this); + + constructor() { + super(_Foo), (() => { + this; + })(), _initClass(); + } + +}(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js index 046ba5f9a759..42a115d10f2b 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes/replacement/output.js @@ -2,15 +2,20 @@ var _initClass; let _Foo; -class Foo { +new class extends babelHelpers.identity { static { - [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + class Foo { + static { + [_Foo, _initClass] = babelHelpers.applyDecs(this, [], [dec]); + } + } + } - static foo = new _Foo(); - static { - _initClass(); + foo = new _Foo(); + constructor() { + super(_Foo), _initClass(); } -} +}(); const foo = new _Foo(); diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index 89e1bfa3e572..98577387d20d 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -846,6 +846,15 @@ "./helpers/classPrivateMethodSet.js" ], "./helpers/esm/classPrivateMethodSet": "./helpers/esm/classPrivateMethodSet.js", + "./helpers/identity": [ + { + "node": "./helpers/identity.js", + "import": "./helpers/esm/identity.js", + "default": "./helpers/identity.js" + }, + "./helpers/identity.js" + ], + "./helpers/esm/identity": "./helpers/esm/identity.js", "./package": "./package.json", "./package.json": "./package.json", "./regenerator": "./regenerator/index.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index 17f1ca246f3e..a6ddb186bec3 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -845,6 +845,15 @@ "./helpers/classPrivateMethodSet.js" ], "./helpers/esm/classPrivateMethodSet": "./helpers/esm/classPrivateMethodSet.js", + "./helpers/identity": [ + { + "node": "./helpers/identity.js", + "import": "./helpers/esm/identity.js", + "default": "./helpers/identity.js" + }, + "./helpers/identity.js" + ], + "./helpers/esm/identity": "./helpers/esm/identity.js", "./package": "./package.json", "./package.json": "./package.json", "./regenerator": "./regenerator/index.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index 0178026eca7f..9ac7ec6efccc 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -845,6 +845,15 @@ "./helpers/classPrivateMethodSet.js" ], "./helpers/esm/classPrivateMethodSet": "./helpers/esm/classPrivateMethodSet.js", + "./helpers/identity": [ + { + "node": "./helpers/identity.js", + "import": "./helpers/esm/identity.js", + "default": "./helpers/identity.js" + }, + "./helpers/identity.js" + ], + "./helpers/esm/identity": "./helpers/esm/identity.js", "./package": "./package.json", "./package.json": "./package.json", "./regenerator": "./regenerator/index.js", From 9ce9c7b861d38e9fe1122f511d04b8f09162615d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 7 Jan 2022 16:21:46 +0100 Subject: [PATCH 06/24] Update makefile --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index a314bf79d22b..13380d88033c 100644 --- a/Makefile +++ b/Makefile @@ -187,15 +187,15 @@ prepublish: IS_PUBLISH=true $(MAKE) test new-version-checklist: - # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - # @echo "!!!!!! !!!!!!" - # @echo "!!!!!! Write any message that should !!!!!!" - # @echo "!!!!!! block the release here !!!!!!" - # @echo "!!!!!! !!!!!!" - # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - # @exit 1 + @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + @echo "!!!!!! !!!!!!" + @echo "!!!!!! Update the version of the "identity" !!!!!!" + @echo "!!!!!! and "applyDecs" helpers to 7.17.0 !!!!!!" + @echo "!!!!!! !!!!!!" + @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + @exit 1 new-version: $(MAKE) new-version-checklist From 0e745e50c9f6149465bfd070078e445ed2e575a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 8 Jan 2022 23:52:24 +0100 Subject: [PATCH 07/24] `undefined` -> `void 0` in helper --- .../babel-helpers/src/helpers-generated.ts | 2 +- .../babel-helpers/src/helpers/applyDecs.js | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/babel-helpers/src/helpers-generated.ts b/packages/babel-helpers/src/helpers-generated.ts index 76bcc74b10f3..9b4b3ebd24ba 100644 --- a/packages/babel-helpers/src/helpers-generated.ts +++ b/packages/babel-helpers/src/helpers-generated.ts @@ -15,7 +15,7 @@ function helper(minVersion, source) { export default Object.freeze({ applyDecs: helper( "7.16.6", - 'function createMetadataMethodsForProperty(metadataMap,kind,property){return{getMetadata(key){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0!==metadataForKey)if(1===kind){var pub=metadataForKey.public;if(void 0!==pub)return pub[property]}else if(2===kind){var priv=metadataForKey.private;if(void 0!==priv)return priv.get(property)}else if(Object.hasOwnProperty.call(metadataForKey,"constructor"))return metadataForKey.constructor},setMetadata(key,value){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0===metadataForKey&&(metadataForKey=metadataMap[key]={}),1===kind){var pub=metadataForKey.public;void 0===pub&&(pub=metadataForKey.public=Object.create(null)),pub[property]=value}else if(2===kind){var priv=metadataForKey.priv;void 0===priv&&(priv=metadataForKey.private=new Map),priv.set(property,value)}else metadataForKey.constructor=value}}}function convertMetadataMapToFinal(obj,metadataMap){var parentMetadataMap=obj[Symbol.metadata],metadataKeys=Object.getOwnPropertySymbols(metadataMap);if(0!==metadataKeys.length){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i Date: Sun, 9 Jan 2022 00:15:20 +0100 Subject: [PATCH 08/24] Minor code update --- .../src/transformer-2021-12.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index 7519ed552373..b85890e0af85 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -553,11 +553,8 @@ function transformClass( name = key.name; } - if ( - element.node.type === "ClassMethod" && - element.node.kind === "constructor" - ) { - constructorPath = element as NodePath; + if (element.isClassMethod({ kind: "constructor" })) { + constructorPath = element; } if (isComputed) { From faf44db9d948d6795ad2b4fb5d68dc915efb8fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 9 Jan 2022 00:24:01 +0100 Subject: [PATCH 09/24] Add test for _initProto with existing constructor --- .../input.js | 12 +++++++++++ .../output.js | 20 +++++++++++++++++++ .../input.js | 10 ++++++++++ .../output.js | 16 +++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js new file mode 100644 index 000000000000..4956801b7a7c --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js @@ -0,0 +1,12 @@ +class A extends B { + constructor() { + if (Math.random() > 0.5) { + super(true); + } else { + super(false); + } + } + + @deco + method() {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js new file mode 100644 index 000000000000..6ab0449f864d --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -0,0 +1,20 @@ +var _initProto; + +class A extends B { + static { + [_initProto] = babelHelpers.applyDecs(this, [[deco, 2, "method"]], []); + } + + constructor() { + var _super; + + if (Math.random() > 0.5) { + _super = super(true), _initProto(this), _super; + } else { + super(false); + } + } + + method() {} + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/input.js new file mode 100644 index 000000000000..d72d66fd2a29 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/input.js @@ -0,0 +1,10 @@ +class A extends B { + constructor() { + let a = 2; + super(a); + foo(); + } + + @deco + method() {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js new file mode 100644 index 000000000000..223f54963ba0 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js @@ -0,0 +1,16 @@ +var _initProto, _super; + +class A extends B { + static { + [_initProto] = babelHelpers.applyDecs(this, [[deco, 2, "method"]], []); + } + + constructor() { + let a = 2; + _super = super(a), _initProto(this), _super; + foo(); + } + + method() {} + +} From 5ba1365f9ac21b380b731d776df67345c127ec0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 9 Jan 2022 00:30:41 +0100 Subject: [PATCH 10/24] Fix `_initProto` injection --- .../src/transformer-2021-12.ts | 32 ++++++++----------- .../input.js | 11 +++++++ .../output.js | 23 ++++++++++--- .../output.js | 4 +-- 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index b85890e0af85..b963d8fe4f69 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -790,25 +790,21 @@ function transformClass( value.replaceWith(t.sequenceExpression(body)); } else if (constructorPath) { if (path.node.superClass) { - let found = false; - path.traverse({ - Super(path) { - const { parentPath } = path; - - if (found || parentPath.node.type !== "CallExpression") return; - - found = true; - - const prop = - path.scope.parent.generateDeclaredUidIdentifier("super"); - parentPath.replaceWith( - t.sequenceExpression([ - t.assignmentExpression("=", t.cloneNode(prop), parentPath.node), - protoInitCall, - t.cloneNode(prop), - ]), - ); + CallExpression: { + exit(path) { + if (!path.get("callee").isSuper()) return; + + path.replaceWith( + t.sequenceExpression([ + path.node, + t.cloneNode(protoInitCall), + t.thisExpression(), + ]), + ); + + path.skip(); + }, }, }); } else { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js index 4956801b7a7c..6b0bc3b5a233 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/input.js @@ -10,3 +10,14 @@ class A extends B { @deco method() {} } + +class C extends B { + constructor() { + try { + super(super(), null.x); + } catch {} + } + + @deco + method() {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js index 6ab0449f864d..f29863a7dd24 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor-multiple-super/output.js @@ -1,4 +1,4 @@ -var _initProto; +var _initProto, _initProto2; class A extends B { static { @@ -6,15 +6,28 @@ class A extends B { } constructor() { - var _super; - if (Math.random() > 0.5) { - _super = super(true), _initProto(this), _super; + super(true), _initProto(this), this; } else { - super(false); + super(false), _initProto(this), this; } } method() {} } + +class C extends B { + static { + [_initProto2] = babelHelpers.applyDecs(this, [[deco, 2, "method"]], []); + } + + constructor() { + try { + super((super(), _initProto2(this), this), null.x), _initProto2(this), this; + } catch {} + } + + method() {} + +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js index 223f54963ba0..8cbf561af431 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js @@ -1,4 +1,4 @@ -var _initProto, _super; +var _initProto; class A extends B { static { @@ -7,7 +7,7 @@ class A extends B { constructor() { let a = 2; - _super = super(a), _initProto(this), _super; + super(a), _initProto(this), this; foo(); } From 9a876a2a6458b7b63587646128b63cc431bb34d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 9 Jan 2022 00:46:37 +0100 Subject: [PATCH 11/24] Simplify _initProto injection for existing super() --- .../babel-helpers/src/helpers-generated.ts | 2 +- .../babel-helpers/src/helpers/applyDecs.js | 5 +++- .../src/transformer-2021-12.ts | 6 +--- .../output.js | 6 ++-- .../exec.js | 28 +++++++++++++++++++ .../output.js | 4 ++- 6 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/exec.js diff --git a/packages/babel-helpers/src/helpers-generated.ts b/packages/babel-helpers/src/helpers-generated.ts index 9b4b3ebd24ba..65d723dd40d2 100644 --- a/packages/babel-helpers/src/helpers-generated.ts +++ b/packages/babel-helpers/src/helpers-generated.ts @@ -15,7 +15,7 @@ function helper(minVersion, source) { export default Object.freeze({ applyDecs: helper( "7.16.6", - 'function createMetadataMethodsForProperty(metadataMap,kind,property){return{getMetadata(key){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0!==metadataForKey)if(1===kind){var pub=metadataForKey.public;if(void 0!==pub)return pub[property]}else if(2===kind){var priv=metadataForKey.private;if(void 0!==priv)return priv.get(property)}else if(Object.hasOwnProperty.call(metadataForKey,"constructor"))return metadataForKey.constructor},setMetadata(key,value){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0===metadataForKey&&(metadataForKey=metadataMap[key]={}),1===kind){var pub=metadataForKey.public;void 0===pub&&(pub=metadataForKey.public=Object.create(null)),pub[property]=value}else if(2===kind){var priv=metadataForKey.priv;void 0===priv&&(priv=metadataForKey.private=new Map),priv.set(property,value)}else metadataForKey.constructor=value}}}function convertMetadataMapToFinal(obj,metadataMap){var parentMetadataMap=obj[Symbol.metadata],metadataKeys=Object.getOwnPropertySymbols(metadataMap);if(0!==metadataKeys.length){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i 0.5) { - super(true), _initProto(this), this; + _initProto(super(true)); } else { - super(false), _initProto(this), this; + _initProto(super(false)); } } @@ -24,7 +24,7 @@ class C extends B { constructor() { try { - super((super(), _initProto2(this), this), null.x), _initProto2(this), this; + _initProto2(super(_initProto2(super()), null.x)); } catch {} } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/exec.js new file mode 100644 index 000000000000..3d81b8cdf452 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/exec.js @@ -0,0 +1,28 @@ +let self, a, initCalled; + +function deco(_, context) { + context.addInitializer(() => { + initCalled = true; + }) +} + +class B { + constructor(s) { + a = s; + } +} + +class A extends B { + constructor() { + let a = 2; + self = super(a); + } + + @deco + method() {} +} + +let instance = new A(); +expect(self).toBe(instance); +expect(a).toBe(2); +expect(initCalled).toBe(true); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js index 8cbf561af431..e2fb9d7eb331 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/output.js @@ -7,7 +7,9 @@ class A extends B { constructor() { let a = 2; - super(a), _initProto(this), this; + + _initProto(super(a)); + foo(); } From 9ecadfd8d20d27febb6bab407298791672c6cb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 9 Jan 2022 01:24:27 +0100 Subject: [PATCH 12/24] Fix test --- .../exec.js | 0 .../input.js | 10 ++++++++++ .../output.js | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) rename packages/babel-plugin-proposal-decorators/test/fixtures/{2021-12-misc => 2021-12-misc--to-es2015}/initProto-existing-derived-constructor/exec.js (100%) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/exec.js similarity index 100% rename from packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/exec.js rename to packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/exec.js diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/input.js new file mode 100644 index 000000000000..d72d66fd2a29 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/input.js @@ -0,0 +1,10 @@ +class A extends B { + constructor() { + let a = 2; + super(a); + foo(); + } + + @deco + method() {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js new file mode 100644 index 000000000000..61a1fde840db --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -0,0 +1,18 @@ +var _initProto; + +class A extends B { + constructor() { + let a = 2; + + _initProto(super(a)); + + foo(); + } + + method() {} + +} + +(() => { + [_initProto] = babelHelpers.applyDecs(A, [[deco, 2, "method"]], []); +})(); From 62acebe844fe09de9737b55e454e163173fdc364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 15:43:51 -0500 Subject: [PATCH 13/24] add decoratorsVersion support to babel-standalone --- packages/babel-standalone/src/preset-stage-0.ts | 4 +++- packages/babel-standalone/src/preset-stage-1.ts | 4 +++- packages/babel-standalone/src/preset-stage-2.ts | 6 +++++- .../babel-standalone/test/preset-stage-1.test.js | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/babel-standalone/src/preset-stage-0.ts b/packages/babel-standalone/src/preset-stage-0.ts index 7add5af3e1c1..66a8f8a180f6 100644 --- a/packages/babel-standalone/src/preset-stage-0.ts +++ b/packages/babel-standalone/src/preset-stage-0.ts @@ -5,7 +5,8 @@ export default (_: any, opts: any = {}) => { const { loose = false, useBuiltIns = false, - decoratorsLegacy = false, + decoratorsLegacy, + decoratorsVersion, decoratorsBeforeExport, pipelineProposal, pipelineTopicToken, @@ -20,6 +21,7 @@ export default (_: any, opts: any = {}) => { loose, useBuiltIns, decoratorsLegacy, + decoratorsVersion, decoratorsBeforeExport, pipelineProposal, pipelineTopicToken, diff --git a/packages/babel-standalone/src/preset-stage-1.ts b/packages/babel-standalone/src/preset-stage-1.ts index 6fdf52daec0f..67a3ef331819 100644 --- a/packages/babel-standalone/src/preset-stage-1.ts +++ b/packages/babel-standalone/src/preset-stage-1.ts @@ -5,7 +5,8 @@ export default (_: any, opts: any = {}) => { const { loose = false, useBuiltIns = false, - decoratorsLegacy = false, + decoratorsLegacy, + decoratorsVersion, decoratorsBeforeExport, pipelineProposal, pipelineTopicToken, @@ -20,6 +21,7 @@ export default (_: any, opts: any = {}) => { loose, useBuiltIns, decoratorsLegacy, + decoratorsVersion, decoratorsBeforeExport, pipelineProposal, pipelineTopicToken, diff --git a/packages/babel-standalone/src/preset-stage-2.ts b/packages/babel-standalone/src/preset-stage-2.ts index 4d743659dae5..26f172b49b0f 100644 --- a/packages/babel-standalone/src/preset-stage-2.ts +++ b/packages/babel-standalone/src/preset-stage-2.ts @@ -6,6 +6,7 @@ export default (_: any, opts: any = {}) => { loose = false, useBuiltIns = false, decoratorsLegacy = false, + decoratorsVersion = "2018-09", decoratorsBeforeExport, pipelineProposal = "minimal", pipelineTopicToken = "%", @@ -17,7 +18,10 @@ export default (_: any, opts: any = {}) => { plugins: [ [ babelPlugins.proposalDecorators, - { legacy: decoratorsLegacy, decoratorsBeforeExport }, + { + version: decoratorsLegacy ? "legacy" : decoratorsVersion, + decoratorsBeforeExport, + }, ], [ babelPlugins.proposalPipelineOperator, diff --git a/packages/babel-standalone/test/preset-stage-1.test.js b/packages/babel-standalone/test/preset-stage-1.test.js index cbac8842006e..d8f2e111811c 100644 --- a/packages/babel-standalone/test/preset-stage-1.test.js +++ b/packages/babel-standalone/test/preset-stage-1.test.js @@ -55,5 +55,20 @@ _ref = x, _ref;" _ref = x, _ref;" `); }); + it("should support decorators versioned 2021-12", () => { + const output = Babel.transform("@dec class C {}", { + plugins: [["external-helpers", { helperVersion: "7.100.0" }]], + presets: [ + [ + "stage-1", + { + decoratorsVersion: "2021-12", + decoratorsBeforeExport: false, + }, + ], + ], + }).code; + expect(output).toMatch("babelHelpers.applyDecs"); + }); }, ); From e67b698cbde93866fc5764f33867b7ae26074dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 18:44:58 -0500 Subject: [PATCH 14/24] fix: throw when legacy and version are both specified also fix decoratorsBeforeExport error when version: "legacy" is specified --- .../src/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index 1a3b6c4a3d7b..42e2a097c83f 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -12,10 +12,16 @@ import transformer2021_12 from "./transformer-2021-12"; export default declare((api, options) => { api.assertVersion(7); - const { legacy = false } = options; + let { legacy = false } = options; if (typeof legacy !== "boolean") { throw new Error("'legacy' must be a boolean."); } + if (version !== undefined && options.legacy !== undefined) { + throw new Error( + 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', + ); + } + legacy ||= version === "legacy"; const { decoratorsBeforeExport, version } = options; if (decoratorsBeforeExport === undefined) { @@ -23,7 +29,7 @@ export default declare((api, options) => { throw new Error( "The decorators plugin requires a 'decoratorsBeforeExport' option," + " whose value must be a boolean. If you want to use the legacy" + - " decorators semantics, you can set the 'legacy: true' option.", + " decorators semantics, you can set the `version: 'legacy'` option.", ); } } else { @@ -37,13 +43,7 @@ export default declare((api, options) => { } } - if (version === "legacy" || legacy) { - if (version !== undefined && legacy) { - throw new Error( - 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', - ); - } - + if (legacy) { return { name: "proposal-decorators", inherits: syntaxDecorators, From e52f1dc4b2ec8366f83d7560323d5fe104d5accf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 18:53:29 -0500 Subject: [PATCH 15/24] fix init --- packages/babel-plugin-proposal-decorators/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index 42e2a097c83f..c166dd9e880a 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -16,6 +16,7 @@ export default declare((api, options) => { if (typeof legacy !== "boolean") { throw new Error("'legacy' must be a boolean."); } + const { decoratorsBeforeExport, version } = options; if (version !== undefined && options.legacy !== undefined) { throw new Error( 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', @@ -23,7 +24,6 @@ export default declare((api, options) => { } legacy ||= version === "legacy"; - const { decoratorsBeforeExport, version } = options; if (decoratorsBeforeExport === undefined) { if (!legacy) { throw new Error( From be798df427de74c1cf29ee8d6a69d4e0f3964f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 20:30:11 -0500 Subject: [PATCH 16/24] refactor: centralize option validation in syntax-decorators --- .../src/index.ts | 62 +++++-------------- .../src/index.ts | 28 +++++---- 2 files changed, 31 insertions(+), 59 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index c166dd9e880a..6d9fcf633ba3 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -12,36 +12,7 @@ import transformer2021_12 from "./transformer-2021-12"; export default declare((api, options) => { api.assertVersion(7); - let { legacy = false } = options; - if (typeof legacy !== "boolean") { - throw new Error("'legacy' must be a boolean."); - } - const { decoratorsBeforeExport, version } = options; - if (version !== undefined && options.legacy !== undefined) { - throw new Error( - 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', - ); - } - legacy ||= version === "legacy"; - - if (decoratorsBeforeExport === undefined) { - if (!legacy) { - throw new Error( - "The decorators plugin requires a 'decoratorsBeforeExport' option," + - " whose value must be a boolean. If you want to use the legacy" + - " decorators semantics, you can set the `version: 'legacy'` option.", - ); - } - } else { - if (legacy) { - throw new Error( - "'decoratorsBeforeExport' can't be used with legacy decorators.", - ); - } - if (typeof decoratorsBeforeExport !== "boolean") { - throw new Error("'decoratorsBeforeExport' must be a boolean."); - } - } + const { legacy, decoratorsBeforeExport, version } = options; if (legacy) { return { @@ -52,24 +23,21 @@ export default declare((api, options) => { }, visitor: legacyVisitor, }; - } - - if (version === "2021-12") { + } else if (version === "2021-12") { return transformer2021_12(api, options); - } else if (!(version === "2018-09" || version === undefined)) { - throw new Error("Unsupported decorators version: " + version); - } - - return createClassFeaturePlugin({ - name: "proposal-decorators", + } else { + const plugin = createClassFeaturePlugin({ + name: "proposal-decorators", - api, - feature: FEATURES.decorators, - // loose: options.loose, Not supported + api, + feature: FEATURES.decorators, + // loose: options.loose, Not supported - manipulateOptions({ generatorOpts, parserOpts }) { - parserOpts.plugins.push(["decorators", { decoratorsBeforeExport }]); - generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport; - }, - }); + manipulateOptions({ generatorOpts }) { + generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport; + }, + }); + plugin.inherits = syntaxDecorators; + return plugin; + } }); diff --git a/packages/babel-plugin-syntax-decorators/src/index.ts b/packages/babel-plugin-syntax-decorators/src/index.ts index 5f43d029b7af..1b659a7c044f 100644 --- a/packages/babel-plugin-syntax-decorators/src/index.ts +++ b/packages/babel-plugin-syntax-decorators/src/index.ts @@ -3,19 +3,29 @@ import { declare } from "@babel/helper-plugin-utils"; export default declare((api, options) => { api.assertVersion(7); - const { legacy = false, version } = options; + let { legacy = false } = options; if (typeof legacy !== "boolean") { throw new Error("'legacy' must be a boolean."); } + const { decoratorsBeforeExport, version = "2018-09" } = options; + if ( + !(version === "2021-12" || version === "2018-09" || version === "legacy") + ) { + throw new Error("Unsupported decorators version: " + version); + } + if (version !== undefined && options.legacy !== undefined) { + throw new Error( + 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', + ); + } + legacy ||= version === "legacy"; - const { decoratorsBeforeExport } = options; if (decoratorsBeforeExport === undefined) { if (!legacy) { throw new Error( - "The '@babel/plugin-syntax-decorators' plugin requires a" + - " 'decoratorsBeforeExport' option, whose value must be a boolean." + - " If you want to use the legacy decorators semantics, you can set" + - " the 'legacy: true' option.", + "The decorators plugin requires a 'decoratorsBeforeExport' option," + + " whose value must be a boolean. If you want to use the legacy" + + " decorators semantics, you can set the `version: 'legacy'` option.", ); } } else { @@ -29,12 +39,6 @@ export default declare((api, options) => { } } - if ( - !(version === "2021-12" || version === "2018-09" || version === undefined) - ) { - throw new Error("Unsupported decorators version: " + version); - } - return { name: "syntax-decorators", From e9f56f3c2af5a88160e2a3b183304c2b95c3e9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 20:32:21 -0500 Subject: [PATCH 17/24] remove noop parser plugin babel-parser 7.17 has materalized classStaticBlock --- packages/babel-plugin-syntax-decorators/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/babel-plugin-syntax-decorators/src/index.ts b/packages/babel-plugin-syntax-decorators/src/index.ts index 1b659a7c044f..b0d65e4972c2 100644 --- a/packages/babel-plugin-syntax-decorators/src/index.ts +++ b/packages/babel-plugin-syntax-decorators/src/index.ts @@ -51,7 +51,6 @@ export default declare((api, options) => { if (version === "2021-12") { parserOpts.plugins.push("decoratorAutoAccessors"); - parserOpts.plugins.push("classStaticBlock"); } }, }; From 351f1585b7fbf89bfe3f0ca3e926cf0bb5a05b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 20:41:36 -0500 Subject: [PATCH 18/24] fix test errors --- packages/babel-helper-create-class-features-plugin/src/index.ts | 1 + packages/babel-plugin-syntax-decorators/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/index.ts b/packages/babel-helper-create-class-features-plugin/src/index.ts index 70da4597d09b..25105ca085a0 100644 --- a/packages/babel-helper-create-class-features-plugin/src/index.ts +++ b/packages/babel-helper-create-class-features-plugin/src/index.ts @@ -38,6 +38,7 @@ interface Options { name: string; feature: number; loose?: boolean; + inherits?: () => Options; // same as PluginObject.manipulateOptions manipulateOptions: (options: unknown, parserOpts: ParserOptions) => void; // TODO(flow->ts): change to babel api diff --git a/packages/babel-plugin-syntax-decorators/src/index.ts b/packages/babel-plugin-syntax-decorators/src/index.ts index b0d65e4972c2..ccfbeedaa77b 100644 --- a/packages/babel-plugin-syntax-decorators/src/index.ts +++ b/packages/babel-plugin-syntax-decorators/src/index.ts @@ -13,7 +13,7 @@ export default declare((api, options) => { ) { throw new Error("Unsupported decorators version: " + version); } - if (version !== undefined && options.legacy !== undefined) { + if (options.version !== undefined && options.legacy !== undefined) { throw new Error( 'You can either specify `legacy: true` or `version: "legacy"` with decorators, not both.', ); From 2fc8ad9539bed033123869558ae6a80e921338bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 14 Jan 2022 20:51:34 -0500 Subject: [PATCH 19/24] fix TS errors --- .../babel-helper-create-class-features-plugin/src/index.ts | 4 +++- packages/babel-plugin-proposal-decorators/src/index.ts | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/index.ts b/packages/babel-helper-create-class-features-plugin/src/index.ts index 25105ca085a0..1f874cde0bd2 100644 --- a/packages/babel-helper-create-class-features-plugin/src/index.ts +++ b/packages/babel-helper-create-class-features-plugin/src/index.ts @@ -38,7 +38,7 @@ interface Options { name: string; feature: number; loose?: boolean; - inherits?: () => Options; + inherits?: (api: any, options: any) => any; // same as PluginObject.manipulateOptions manipulateOptions: (options: unknown, parserOpts: ParserOptions) => void; // TODO(flow->ts): change to babel api @@ -52,6 +52,7 @@ export function createClassFeaturePlugin({ manipulateOptions, // TODO(Babel 8): Remove the default value api = { assumption: () => void 0 }, + inherits, }: Options) { const setPublicClassFields = api.assumption("setPublicClassFields"); const privateFieldsAsProperties = api.assumption("privateFieldsAsProperties"); @@ -86,6 +87,7 @@ export function createClassFeaturePlugin({ return { name, manipulateOptions, + inherits, pre() { enableFeature(this.file, feature, loose); diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index 6d9fcf633ba3..f98c07c6f2b7 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -26,18 +26,17 @@ export default declare((api, options) => { } else if (version === "2021-12") { return transformer2021_12(api, options); } else { - const plugin = createClassFeaturePlugin({ + return createClassFeaturePlugin({ name: "proposal-decorators", api, feature: FEATURES.decorators, + inherits: syntaxDecorators, // loose: options.loose, Not supported manipulateOptions({ generatorOpts }) { generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport; }, }); - plugin.inherits = syntaxDecorators; - return plugin; } }); From 0876e7a160f20af93f1cd9ca6203f94230cfc218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 16 Jan 2022 14:18:07 +0100 Subject: [PATCH 20/24] Fallback to `Symbol.for("Symbol.metadata")` --- packages/babel-helpers/src/helpers-generated.ts | 2 +- packages/babel-helpers/src/helpers/applyDecs.js | 4 ++-- .../fixtures/2021-12-metadata--to-es2015/class/exec.js | 2 +- .../getting-previously-set-metadata/exec.js | 4 ++-- .../inheritance-private/exec.js | 4 ++-- .../inheritance-public/exec.js | 8 ++++---- .../2021-12-metadata--to-es2015/proto-private/exec.js | 2 +- .../2021-12-metadata--to-es2015/proto-public/exec.js | 2 +- .../2021-12-metadata--to-es2015/static-private/exec.js | 2 +- .../2021-12-metadata--to-es2015/static-public/exec.js | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/babel-helpers/src/helpers-generated.ts b/packages/babel-helpers/src/helpers-generated.ts index 65d723dd40d2..0ebee43d1889 100644 --- a/packages/babel-helpers/src/helpers-generated.ts +++ b/packages/babel-helpers/src/helpers-generated.ts @@ -15,7 +15,7 @@ function helper(minVersion, source) { export default Object.freeze({ applyDecs: helper( "7.16.6", - 'function createMetadataMethodsForProperty(metadataMap,kind,property){return{getMetadata(key){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0!==metadataForKey)if(1===kind){var pub=metadataForKey.public;if(void 0!==pub)return pub[property]}else if(2===kind){var priv=metadataForKey.private;if(void 0!==priv)return priv.get(property)}else if(Object.hasOwnProperty.call(metadataForKey,"constructor"))return metadataForKey.constructor},setMetadata(key,value){if("symbol"!=typeof key)throw new TypeError("Metadata keys must be symbols, received: "+key);var metadataForKey=metadataMap[key];if(void 0===metadataForKey&&(metadataForKey=metadataMap[key]={}),1===kind){var pub=metadataForKey.public;void 0===pub&&(pub=metadataForKey.public=Object.create(null)),pub[property]=value}else if(2===kind){var priv=metadataForKey.priv;void 0===priv&&(priv=metadataForKey.private=new Map),priv.set(property,value)}else metadataForKey.constructor=value}}}function convertMetadataMapToFinal(obj,metadataMap){var parentMetadataMap=obj[Symbol.metadata],metadataKeys=Object.getOwnPropertySymbols(metadataMap);if(0!==metadataKeys.length){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,metadataMap=staticMetadataMap,kind-=5,staticInitializers||(staticInitializers=[]),initializers=staticInitializers):(base=Class.prototype,metadataMap=protoMetadataMap,protoInitializers||(protoInitializers=[]),initializers=protoInitializers),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,metadataMap,initializers)}}protoInitializers&&pushInitializers(ret,protoInitializers),staticInitializers&&pushInitializers(ret,staticInitializers)}function pushInitializers(ret,initializers){initializers.length>0?(initializers=initializers.slice(),ret.push((function(instance){for(var i=0;i0?ret.push((function(){for(var i=0;i Date: Sun, 16 Jan 2022 09:41:22 -0500 Subject: [PATCH 21/24] Object.create(null) -> standard object --- packages/babel-helpers/src/helpers/applyDecs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-helpers/src/helpers/applyDecs.js b/packages/babel-helpers/src/helpers/applyDecs.js index b18bda185fdd..09c6ec5cd983 100644 --- a/packages/babel-helpers/src/helpers/applyDecs.js +++ b/packages/babel-helpers/src/helpers/applyDecs.js @@ -56,7 +56,7 @@ function createMetadataMethodsForProperty(metadataMap, kind, property) { var pub = metadataForKey.public; if (pub === void 0) { - pub = metadataForKey.public = Object.create(null); + pub = metadataForKey.public = {}; } pub[property] = value; From aa4d6e25253d13ad8792ece3d0d11fdbd1bebc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 16 Jan 2022 10:25:33 -0500 Subject: [PATCH 22/24] use legacy visitor when version is "legacy" --- packages/babel-plugin-proposal-decorators/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-proposal-decorators/src/index.ts b/packages/babel-plugin-proposal-decorators/src/index.ts index f98c07c6f2b7..25acc312ae0c 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.ts +++ b/packages/babel-plugin-proposal-decorators/src/index.ts @@ -14,7 +14,7 @@ export default declare((api, options) => { const { legacy, decoratorsBeforeExport, version } = options; - if (legacy) { + if (legacy || version === "legacy") { return { name: "proposal-decorators", inherits: syntaxDecorators, From 1eb2e68c7b61c16e23957174005a5f4348eb78a8 Mon Sep 17 00:00:00 2001 From: Chris Hewell Garrett Date: Sun, 16 Jan 2022 13:24:27 -0500 Subject: [PATCH 23/24] Fix interop between class and static decorators --- .../src/transformer-2021-12.ts | 4 +- .../2021-12-misc/all-decorators/input.js | 26 ++++ .../2021-12-misc/all-decorators/output.js | 113 ++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/input.js create mode 100644 packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index 1e8cc7a188e5..054d1e253b2b 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -479,7 +479,7 @@ function transformClass( continue; } - if (element.node.decorators) { + if (element.node.decorators && element.node.decorators.length > 0) { hasElementDecorators = true; } else if (element.node.type === "ClassAccessorProperty") { const { key, value, static: isStatic } = element.node; @@ -572,7 +572,7 @@ function transformClass( hasComputedProps = true; } - if (Array.isArray(decorators)) { + if (Array.isArray(decorators) && decorators.length > 0) { let locals: t.Identifier | t.Identifier[]; let privateMethods: t.FunctionExpression | t.FunctionExpression[]; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/input.js new file mode 100644 index 000000000000..e57aa75977ea --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/input.js @@ -0,0 +1,26 @@ +@dec +class Class { + @dec a; + @dec b() {} + @dec get c() {} + @dec set c(v) {} + @dec accessor d; + + @dec #e; + @dec #f() {} + @dec get #g() {} + @dec set #g(v) {} + @dec accessor #h; + + @dec static i; + @dec static j() {} + @dec static get k() {} + @dec static set l(v) {} + @dec static accessor m; + + @dec static #n; + @dec static #o() {} + @dec static get #p() {} + @dec static set #q(v) {} + @dec static accessor #r; +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js new file mode 100644 index 000000000000..d13052811623 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc/all-decorators/output.js @@ -0,0 +1,113 @@ +var _initClass, _init_a, _init_d, _init_e, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_m, _init_n, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _initProto, _initStatic; + +let _Class; + +new class extends babelHelpers.identity { + static { + class Class { + static { + [_init_a, _init_d, _init_e, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_m, _init_n, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _Class, _initClass, _initProto, _initStatic] = babelHelpers.applyDecs(this, [[dec, 0, "a"], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 0, "e", function () { + return this.#e; + }, function (value) { + this.#e = value; + }], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", function () { + return this.#B; + }, function (value) { + this.#B = value; + }], [dec, 5, "i"], [dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 5, "n", function () { + return this.#n; + }, function (value) { + this.#n = value; + }], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", function () { + return this.#D; + }, function (value) { + this.#D = value; + }]], [dec]); + + _initStatic(this); + + } + #f = _call_f; + a = (_initProto(this), _init_a(this)); + + b() {} + + get c() {} + + set c(v) {} + + #A = _init_d(this); + + get d() { + return this.#A; + } + + set d(v) { + this.#A = v; + } + + #e = _init_e(this); + + get #g() { + return _call_g(this); + } + + set #g(v) { + _call_g2(this, v); + } + + #B = _init_h(this); + + set #h(v) { + _set_h(this, v); + } + + get #h() { + _get_h(this); + } + + static j() {} + + static get k() {} + + static set l(v) {} + + static get m() { + return this.#C; + } + + static set m(v) { + this.#C = v; + } + + set #r(v) { + _set_r(this, v); + } + + get #r() { + _get_r(this); + } + + } + + } + #o = _call_o; + i = _init_i(this); + #C = _init_m(this); + #n = _init_n(this); + + get #p() { + return _call_p(this); + } + + set #q(v) { + _call_q(this, v); + } + + #D = _init_r(this); + + constructor() { + super(_Class), _initClass(); + } + +}(); From df637f978248dce36cba41f17274438cfab1b123 Mon Sep 17 00:00:00 2001 From: Chris Hewell Garrett Date: Mon, 24 Jan 2022 14:32:40 -0500 Subject: [PATCH 24/24] Update contrib.md --- .../CONTRIB.md | 300 ++++++++++-------- 1 file changed, 161 insertions(+), 139 deletions(-) diff --git a/packages/babel-plugin-proposal-decorators/CONTRIB.md b/packages/babel-plugin-proposal-decorators/CONTRIB.md index 30c36983e1ce..33b8fb85da17 100644 --- a/packages/babel-plugin-proposal-decorators/CONTRIB.md +++ b/packages/babel-plugin-proposal-decorators/CONTRIB.md @@ -42,59 +42,70 @@ It's output would be something like the following: ```js import { applyDecs } from '@babel/helpers'; -let initInstance, initClass, initA, callB, computedKey, initC, getC, setC; +let _initInstance, _initClass, _initStatic, _init_a, _call_b, _computedKey, _init_c, _get_c, _set_c; -const elementDecs = [ - [dec, 0, 'a'], - [dec, 7, 'x', '#b'] - (computedKey = someVal, null) - [[dec, dec2], 1, 'y', '#c'] -]; +let _dec = dec, + _dec2 = dec, + _computedKey = someVal, + _dec3 = dec, + _dec4 = dec2; -const classDecs = [dec]; - -let Class; -class _Class { +let _Class; +class Class { static { - let ret = applyDecs( - this, - elementDecs, + [ + _init_a, + _call_b, + _init_c, + _get_c, + _set_c, + _Class, + _initClass, + _initProto, + _initStatic, + ] = _applyDecs(Class, + [ + [_dec, 0, "a"], + [ + _dec2, + 7, + "b", + function () { + console.log('foo'); + } + ], + [ + [_dec4, _dec5], + 1, + "c", + function () { + return this.#a; + }, + function (value) { + this.#a = value; + } + ] + ], [dec] ); - initA = ret[0]; - callB = ret[1]; - initC = ret[2]; - getC = ret[3]; - setC = ret[4]; - initInstance = ret[5]; - Class = ret[6]; - initClass = ret[7]; + _initStatic(Class); } - a = (initInstance(this), initA(this, 123)); + a = (initInstance(this), _init_a(this, 123)); static #b(...args) { - callB(this, args); - } - static x() { - console.log('foo'); + _call_b(this, args); } - [computedKey]() {} + [_computedKey]() {} - #y = initC(this, 123); - get y() { - return this.#y; - } - set y(v) { - this.#y = v; - } + #a = _init_c(this, 123); get #c() { - return getC(this); + return _get_c(this); } set #c(v) { - setC(this, v); + _set_c(this, v); } static { @@ -106,7 +117,7 @@ class _Class { Let's break this output down a bit: ```js -let initInstance, initClass, initA, callB, initC, getC, setC; +let initInstance, initClass, _init_a, _call_b, _init_c, _get_c, _set_c; ``` First, we need to setup some local variables outside of the class. These are @@ -121,25 +132,22 @@ These are essentially all values that cannot be defined on the class itself via ahead of time and populate them when we run our decorators. ```js -const elementDecs = [ - [dec, 0, 'a'], - [dec, 7, 'x', '#b'] - (computedKey = someVal, null) - [[dec, dec2], 1, 'y', '#c'] -]; - -const classDecs = [dec]; +let _dec = dec, + _dec2 = dec, + _computedKey = someVal, + _dec3 = dec, + _dec4 = dec2; ``` -Next up, we define and evaluate the decorator member expressions. The reason we +Next up, we define and evaluate the decorator expressions. The reason we do this _before_ defining the class is because we must interleave decorator expressions with computed property key expressions, since computed properties and decorators can run arbitrary code which can modify the runtime of subsequent decorators or computed property keys. ```js -let Class; -class _Class { +let _Class; +class Class { ``` This class is being decorated directly, which means that the decorator may @@ -149,20 +157,43 @@ new `let` variable for the decorated class. ```js static { - let ret = applyDecs( - this, - elementDecs, - classDecs + [ + _init_a, + _call_b, + _init_c, + _get_c, + _set_c, + _Class, + _initClass, + _initProto, + _initStatic, + ] = _applyDecs(Class, + [ + [_dec, 0, "a"], + [ + _dec2, + 7, + "b", + function () { + console.log('foo'); + } + ], + [ + [_dec4, _dec5], + 1, + "c", + function () { + return this.#a; + }, + function (value) { + this.#a = value; + } + ] + ], + [dec] ); - initA = ret[0]; - callB = ret[1]; - initC = ret[2]; - getC = ret[3]; - setC = ret[4]; - initInstance = ret[5]; - Class = ret[6]; - initClass = ret[7]; + _initStatic(Class); } ``` @@ -176,35 +207,39 @@ application returns an array of values that are used to populate all of the local variables we defined earlier. The array's order is fully deterministic, so we can assign the values based on an index we can calculate ahead of time. +Another important thing to note here is that we're passing some functions here. +These are for private methods and accessors, which cannot be replaced directly +so we have to extract their code so it can be decorated. Because we define these +within the static block, they can access any private identifiers which were +defined within the class, so it's not an issue that we're extracting the method +logic here. + We'll come back to `applyDecs` in a bit to dig into what its format is exactly, but now let's dig into the new definitions of our class elements. ```js - a = (initInstance(this), initA(this, 123)); + a = (_initInstance(this), _init_a(this, 123)); ``` Alright, so previously this was a simple class field. Since it's the first field on the class, we've updated it to immediately call `initInstance` in its initializer. This calls any initializers added with `addInitializer` for all of the per-class values (methods and accessors), which should all be setup on the -instance before class fields are assigned. Then, it calls `initA` to get the +instance before class fields are assigned. Then, it calls `_init_a` to get the initial value of the field, which allows initializers returned from the decorator to intercept and decorate it. It's important that the initial value is used/defined _within_ the class body, because initializers can now refer to private class fields, e.g. `a = this.#b` is a valid field initializer and would -become `a = initA(this, this.#b)`, which would also be valid. We cannot +become `a = _init_a(this, this.#b)`, which would also be valid. We cannot extract initializer code, or any other code, from the class body because of this. Overall, this decoration is pretty straightforward other than the fact that we -have to reference `initA` externally. +have to reference `_init_a` externally. ```js static #b(...args) { - callB(this, args); - } - static x() { - console.log('foo'); + _call_b(this, args); } ``` @@ -214,42 +249,27 @@ complex, as our definition has been broken out into 2 parts: 1. `static #b`: This is the method itself, which being a private method we cannot overwrite with `defineProperty`. We also can't convert it into a private field because that would change its semantics (would make it - writable). So, we instead have it proxy to the locally scoped `callB` + writable). So, we instead have it proxy to the locally scoped `_call_b` variable, which will be populated with the fully decorated method. -2. `static x`: This contains the _code_ of the original method. Once again, this - code cannot be removed from the class body because it may reference private - identifiers. However, we have moved the code to a _public_ method, which means - we can now read its value using `Object.getOwnPropertyDescriptor`. Decorators - use this to get the initial implementation of the method, which can then be - wrapped with decorator code/logic. They then `delete` this temporary property, - which is necessary because no additional elements should be added to a class - definition. - - The name for this method is unimportant, but because public method names - cannot be minified and we also need to pass the name into `applyDecs`, we - generate as small of a unique identifier as possible here, starting with 1 - char names which are not taken and growing until we find one that is free. +2. The definition of the method, kept in `_call_b`. As we mentioned above, the + original method's code is moved during the decoration process, and the wrapped + version is populated in `_call_b` and called whenever the private method is + called. ```js - [computedKey]() {} + [_computedKey]() {} ``` Next is the undecorated method with a computed key. This uses the previously calculated and stored computed key. ```js - #y = initC(this, 123); - get y() { - return this.#y; - } - set y(v) { - this.#y = v; - } + #a = _init_c(this, 123); get #c() { - return getC(this); + return _get_c(this); } set #c(v) { - setC(this, v); + _set_c(this, v); } ``` @@ -258,49 +278,36 @@ case, since we have to transpile the decorators, the `accessor` keyword, and target a private field. Breaking it down piece by piece: ```js - #y = initC(this, 123); + #a = _init_c(this, 123); ``` `accessor #c` desugars to a getter and setter which are backed by a new private -field, `#y`. Like before, the name of this field doesn't really matter, we'll +field, `#a`. Like before, the name of this field doesn't really matter, we'll just generate a short, unique name. We call the decorated initializer for `#c` and return that value to assign to the field. -```js - get y() { - return this.#y; - } - set y(v) { - this.#y = v; - } -``` - -Next we have a getter and setter named `y` which provide access to the backing -storage for the accessor. These are the base getter/setter for the accessor, -which the decorator will get via `Object.getOwnPropertyDescriptor`. They will be -deleted from the class fully, so again the name is not important here, just -needs to be short. - ```js get #c() { - return getC(this); + return _get_c(this); } set #c(v) { - setC(this, v); + _set_c(this, v); } ``` Next, we have the getter and setter for `#c` itself. These methods defer to -the `getC` and `setC` local variables, which will be the decorated versions of -the `get y` and `set y` methods from the previous step. +the `_get_c` and `_set_c` local variables, which will be the decorated versions +of the two getter functions that we passed for decoration in the static block +above. Those two functions are essentially just accessors for the private `#a` +field, but the decorator may add additional logic to them. ```js static { - initClass(C); + _initClass(_Class); } ``` -Finally, we call `initClass` in another static block, running any class and +Finally, we call `_initClass` in another static block, running any class and static method initializers on the final class. This is done in a static block for convenience with class expressions, but it could run immediately after the class is defined. @@ -308,21 +315,40 @@ class is defined. Ok, so now that we understand the general output, let's go back to `applyDecs`: ```js -const elementDecs = [ - [dec, 0, 'a'], - [dec, 7, 'x', '#b'] - (computedKey = someVal, null) - [[dec, dec2], 1, 'y', '#c'] -]; - -const classDecs = [dec]; - -// ... - -let ret = applyDecs( - this, - elementDecs, - classDecs +[ + _init_a, + _call_b, + _init_c, + _get_c, + _set_c, + _Class, + _initClass, + _initProto, + _initStatic, +] = _applyDecs(Class, + [ + [_dec, 0, "a"], + [ + _dec2, + 7, + "b", + function () { + console.log('foo'); + } + ], + [ + [_dec4, _dec5], + 1, + "c", + function () { + return this.#a; + }, + function (value) { + this.#a = value; + } + ] + ], + [dec] ); ``` @@ -356,16 +382,12 @@ annotated version of the member descriptors: // 9 === SETTER + STATIC 1, - // The name of the public property that can be used to access the value. - // For public members this is the actual name, for private members this is - // the name of the public property which can be used to access the value - // (see descriptions of #b and #c above) + // The name of the member 'y', - // Optional fourth value, this is the spelling of the private element's name, - // which signals that the element is private to `applyDecs` and is used in the - // decorator's context object - '#c' + // Optional fourth and fifth values, these are functions passed for private + // decorators + function() {} ], ```