From 82ce67f26cd9eedcf9d3ed8ca76f103c4b45150c Mon Sep 17 00:00:00 2001 From: "sagiv.bengiat" Date: Sat, 29 May 2021 16:51:38 +0300 Subject: [PATCH 1/6] fix: tagged template incorrect receiver --- .../src/index.ts | 9 ++++-- .../private/tagged-template-static/exec.js | 17 +++++++++++ .../private/tagged-template-static/input.js | 15 ++++++++++ .../tagged-template-static/options.json | 13 +++++++++ .../private/tagged-template-static/output.js | 29 +++++++++++++++++++ .../fixtures/private/tagged-template/exec.js | 17 +++++++++++ .../fixtures/private/tagged-template/input.js | 8 +++++ .../private/tagged-template/options.json | 13 +++++++++ .../private/tagged-template/output.js | 22 ++++++++++++++ .../accessors/tagged-template/exec.js | 16 ++++++++++ .../accessors/tagged-template/input.js | 14 +++++++++ .../accessors/tagged-template/output.js | 29 +++++++++++++++++++ .../private-method/tagged-template/exec.js | 11 +++++++ .../private-method/tagged-template/input.js | 6 ++++ .../private-method/tagged-template/output.js | 14 +++++++++ .../tagged-template/exec.js | 11 +++++++ .../tagged-template/input.js | 6 ++++ .../tagged-template/output.js | 14 +++++++++ .../static-accessors/tagged-template/exe.js | 11 +++++++ .../static-accessors/tagged-template/input.js | 9 ++++++ .../tagged-template/output.js | 10 +++++++ 21 files changed, 292 insertions(+), 2 deletions(-) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/options.json create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/exec.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js create mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js diff --git a/packages/babel-helper-member-expression-to-functions/src/index.ts b/packages/babel-helper-member-expression-to-functions/src/index.ts index 6cdddbefb2f2..2b1c6c051c32 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.ts +++ b/packages/babel-helper-member-expression-to-functions/src/index.ts @@ -462,8 +462,13 @@ const handle = { return; } - // MEMBER -> _get(MEMBER) - member.replaceWith(this.get(member)); + if (t.isTaggedTemplateExpression(parent)) { + // MEMBER -> _get(MEMBER).bind(this) + member.replaceWith(this.boundGet(member)); + } else { + // MEMBER -> _get(MEMBER) + member.replaceWith(this.get(member)); + } }, }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js new file mode 100644 index 000000000000..80a3cb5d2040 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js @@ -0,0 +1,17 @@ +class Foo { + static #tag() { + return this; + } + + static #tag2 = () => this + + static getReceiver() { + return this.#tag``; + } + + static getReceiver2() { + return this.#tag2``; + } +} + +expect(Foo.getReceiver()).toBe(Foo.getReceiver2()); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js new file mode 100644 index 000000000000..d65c1c5da19a --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js @@ -0,0 +1,15 @@ +class Foo { + static #tag() { + return this; + } + + static #tag2 = () => this + + static getReceiver() { + return this.#tag``; + } + + static getReceiver2() { + return this.#tag2``; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json new file mode 100644 index 000000000000..d0c00d1ba3de --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json @@ -0,0 +1,13 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "shippedProposals": true, + "targets": { + "chrome": "75" + } + } + ] + ] + } \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js new file mode 100644 index 000000000000..cdd1a128833f --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js @@ -0,0 +1,29 @@ +var Foo = /*#__PURE__*/function () { + "use strict"; + + function Foo() { + babelHelpers.classCallCheck(this, Foo); + } + + babelHelpers.createClass(Foo, null, [{ + key: "getReceiver", + value: function getReceiver() { + return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; + } + }, { + key: "getReceiver2", + value: function getReceiver2() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag3).bind(this)``; + } + }]); + return Foo; +}(); + +function _tag() { + return this; +} + +var _tag3 = { + writable: true, + value: () => Foo +}; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js new file mode 100644 index 000000000000..19579a2af97e --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js @@ -0,0 +1,17 @@ +class Foo { + #tag() { + return this; + } + + #tag2 = this.#tag; + + constructor() { + const receiver = this.#tag`tagged template`; + expect(receiver === this).toBe(true); + + const receiver2 = this.#tag2`tagged template`; + expect(receiver2 === this).toBe(true); + } +} + + new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js new file mode 100644 index 000000000000..1075a4e072b4 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js @@ -0,0 +1,8 @@ +class Foo { + #tag() { + return this; + } + + #tag2 = this.#tag; + } + new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/options.json new file mode 100644 index 000000000000..d0c00d1ba3de --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/options.json @@ -0,0 +1,13 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "shippedProposals": true, + "targets": { + "chrome": "75" + } + } + ] + ] + } \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js new file mode 100644 index 000000000000..43cede28beb6 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js @@ -0,0 +1,22 @@ +var _tag = /*#__PURE__*/new WeakSet(); + +var _tag3 = /*#__PURE__*/new WeakMap(); + +var Foo = function Foo() { + "use strict"; + + babelHelpers.classCallCheck(this, Foo); + + _tag.add(this); + + _tag3.set(this, { + writable: true, + value: babelHelpers.classPrivateMethodGet(this, _tag, _tag2) + }); +}; + +function _tag2() { + return this; +} + +new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js new file mode 100644 index 000000000000..5312b40df21d --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js @@ -0,0 +1,16 @@ +class Foo { + #tag() { + return this; + } + + get #privateTagMethod(){ + return this.#tag`` + } + + publicGetPrivateTagMethod(){ + return this.#privateTagMethod + } +} +const instance = new Foo(); + +expect(instance === instance.publicGetPrivateTagMethod()).toEqual(true) \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js new file mode 100644 index 000000000000..2b10379b05ec --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js @@ -0,0 +1,14 @@ +class Foo { + #tag() { + return this; + } + + get #privateTagMethod(){ + return this.#tag`` + } + + publicGetPrivateTagMethod(){ + return this.#privateTagMethod + } + } + const instance = new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js new file mode 100644 index 000000000000..bc31ab9e0027 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js @@ -0,0 +1,29 @@ +var _tag = /*#__PURE__*/new WeakSet(); + +var _privateTagMethod = /*#__PURE__*/new WeakMap(); + +class Foo { + constructor() { + _privateTagMethod.set(this, { + get: _get_privateTagMethod, + set: void 0 + }); + + _tag.add(this); + } + + publicGetPrivateTagMethod() { + return babelHelpers.classPrivateFieldGet(this, _privateTagMethod); + } + +} + +function _tag2() { + return this; +} + +function _get_privateTagMethod() { + return babelHelpers.classPrivateMethodGet(this, _tag, _tag2).bind(this)``; +} + +var instance = new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js new file mode 100644 index 000000000000..71520d6621be --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js @@ -0,0 +1,11 @@ +class Foo { + #tag() { + return this; + } + + constructor() { + const receiver = this.#tag`tagged template`; + expect(receiver === this).toBe(true); + } + } + new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js new file mode 100644 index 000000000000..fee469e9341c --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js @@ -0,0 +1,6 @@ +class Foo { + #tag() { + return this; + } +} +new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js new file mode 100644 index 000000000000..797b93d41911 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js @@ -0,0 +1,14 @@ +var _tag = /*#__PURE__*/new WeakSet(); + +class Foo { + constructor() { + _tag.add(this); + } + +} + +function _tag2() { + return this; +} + +new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/exec.js new file mode 100644 index 000000000000..b7b2c9fdc575 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/exec.js @@ -0,0 +1,11 @@ +class Foo { + static #tag() { + return this; + } + + static getReceiver() { + return this.#tag``; + } +} + +expect(Foo.getReceiver()).toBe(Foo); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js new file mode 100644 index 000000000000..fee469e9341c --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js @@ -0,0 +1,6 @@ +class Foo { + #tag() { + return this; + } +} +new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js new file mode 100644 index 000000000000..797b93d41911 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js @@ -0,0 +1,14 @@ +var _tag = /*#__PURE__*/new WeakSet(); + +class Foo { + constructor() { + _tag.add(this); + } + +} + +function _tag2() { + return this; +} + +new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js new file mode 100644 index 000000000000..20b749088e79 --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js @@ -0,0 +1,11 @@ +class Foo { + static #tag() { + return this; + } + + static get privateTagMethod() { + return this.#tag``; + } +} + +expect(Foo.privateTagMethod).toBe(Foo); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js new file mode 100644 index 000000000000..53a2dc4227cf --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js @@ -0,0 +1,9 @@ +class Foo { + static #tag() { + return this; + } + + static get privateTagMethod() { + return this.#tag``; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js new file mode 100644 index 000000000000..6f515898a0df --- /dev/null +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js @@ -0,0 +1,10 @@ +class Foo { + static get privateTagMethod() { + return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; + } + +} + +function _tag() { + return this; +} From 56a4088794f6d70387b403f141e53ff6567c7d07 Mon Sep 17 00:00:00 2001 From: "sagiv.bengiat" Date: Sat, 29 May 2021 20:25:30 +0300 Subject: [PATCH 2/6] review changes --- .../src/index.ts | 2 +- .../private/tagged-template-static/exec.js | 7 +++--- .../tagged-template-static/options.json | 17 ++++--------- .../private/tagged-template-static/output.js | 24 ++++++------------- .../accessors/tagged-template/exec.js | 2 +- .../private-method/tagged-template/input.js | 2 +- .../private-method/tagged-template/output.js | 2 +- .../static-accessors/tagged-template/exe.js | 11 --------- 8 files changed, 20 insertions(+), 47 deletions(-) delete mode 100644 packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js diff --git a/packages/babel-helper-member-expression-to-functions/src/index.ts b/packages/babel-helper-member-expression-to-functions/src/index.ts index 2b1c6c051c32..a6530540f92e 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.ts +++ b/packages/babel-helper-member-expression-to-functions/src/index.ts @@ -462,7 +462,7 @@ const handle = { return; } - if (t.isTaggedTemplateExpression(parent)) { + if (parentPath.isTaggedTemplateExpression()) { // MEMBER -> _get(MEMBER).bind(this) member.replaceWith(this.boundGet(member)); } else { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js index 80a3cb5d2040..e702ee19574d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js @@ -3,7 +3,7 @@ class Foo { return this; } - static #tag2 = () => this + static #tag2 = function () { return this }; static getReceiver() { return this.#tag``; @@ -13,5 +13,6 @@ class Foo { return this.#tag2``; } } - -expect(Foo.getReceiver()).toBe(Foo.getReceiver2()); \ No newline at end of file + +expect(Foo.getReceiver()).toBe(Foo); +expect(Foo.getReceiver2()).toBe(Foo); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json index d0c00d1ba3de..a842b4d9452d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/options.json @@ -1,13 +1,6 @@ { - "presets": [ - [ - "@babel/preset-env", - { - "shippedProposals": true, - "targets": { - "chrome": "75" - } - } - ] - ] - } \ No newline at end of file + "plugins": [ + "proposal-class-properties", + "proposal-private-methods" + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js index cdd1a128833f..4fe3752a6a28 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js @@ -1,23 +1,13 @@ -var Foo = /*#__PURE__*/function () { - "use strict"; +class Foo { + static getReceiver() { + return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; + } - function Foo() { - babelHelpers.classCallCheck(this, Foo); + static getReceiver2() { + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag3).bind(this)``; } - babelHelpers.createClass(Foo, null, [{ - key: "getReceiver", - value: function getReceiver() { - return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; - } - }, { - key: "getReceiver2", - value: function getReceiver2() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag3).bind(this)``; - } - }]); - return Foo; -}(); +} function _tag() { return this; diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js index 5312b40df21d..87ea351859ea 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js @@ -13,4 +13,4 @@ class Foo { } const instance = new Foo(); -expect(instance === instance.publicGetPrivateTagMethod()).toEqual(true) \ No newline at end of file +expect(instance.publicGetPrivateTagMethod()).toEqual(instance) \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js index fee469e9341c..51020020b73e 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/input.js @@ -1,6 +1,6 @@ class Foo { #tag() { - return this; + this.#tag``; } } new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js index 797b93d41911..21029095ae9a 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js @@ -8,7 +8,7 @@ class Foo { } function _tag2() { - return this; + babelHelpers.classPrivateMethodGet(this, _tag, _tag2).bind(this)``; } new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js deleted file mode 100644 index 20b749088e79..000000000000 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/exe.js +++ /dev/null @@ -1,11 +0,0 @@ -class Foo { - static #tag() { - return this; - } - - static get privateTagMethod() { - return this.#tag``; - } -} - -expect(Foo.privateTagMethod).toBe(Foo); From 5360dc9f882f5d45f8c15c3dded020e1de1d361d Mon Sep 17 00:00:00 2001 From: "sagiv.bengiat" Date: Sat, 29 May 2021 20:34:44 +0300 Subject: [PATCH 3/6] func exp instead of arrow --- .../test/fixtures/private/tagged-template-static/input.js | 2 +- .../test/fixtures/private/tagged-template-static/output.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js index d65c1c5da19a..608896d38f08 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js @@ -3,7 +3,7 @@ class Foo { return this; } - static #tag2 = () => this + static #tag2 = function () { return this }; static getReceiver() { return this.#tag``; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js index 4fe3752a6a28..4a4f468bd6d1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js @@ -15,5 +15,7 @@ function _tag() { var _tag3 = { writable: true, - value: () => Foo + value: function () { + return this; + } }; From f091566cdc1910201839a4165af7561347174259 Mon Sep 17 00:00:00 2001 From: "sagiv.bengiat" Date: Sat, 12 Jun 2021 13:53:00 +0300 Subject: [PATCH 4/6] review comments --- .../private/tagged-template-static/exec.js | 15 +++----------- .../private/tagged-template-static/input.js | 13 +++--------- .../fixtures/private/tagged-template/exec.js | 6 +++--- .../fixtures/private/tagged-template/input.js | 13 ++++++------ .../accessors/tagged-template/exec.js | 20 +++++++------------ .../accessors/tagged-template/input.js | 17 +++++----------- .../private-method/tagged-template/exec.js | 16 +++++++-------- .../tagged-template/input.js | 4 ++-- .../static-accessors/tagged-template/input.js | 13 ++++++------ 9 files changed, 45 insertions(+), 72 deletions(-) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js index e702ee19574d..23be68550f2f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/exec.js @@ -1,18 +1,9 @@ class Foo { - static #tag() { - return this; - } - - static #tag2 = function () { return this }; + static #tag = function () { return this }; static getReceiver() { return this.#tag``; } - - static getReceiver2() { - return this.#tag2``; - } } - -expect(Foo.getReceiver()).toBe(Foo); -expect(Foo.getReceiver2()).toBe(Foo); \ No newline at end of file + +expect(Foo.getReceiver()).toBe(Foo); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js index 608896d38f08..e02e5f447d7a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/input.js @@ -1,15 +1,8 @@ class Foo { - static #tag() { - return this; - } - - static #tag2 = function () { return this }; + static #tag = function () { return this }; static getReceiver() { return this.#tag``; } - - static getReceiver2() { - return this.#tag2``; - } -} \ No newline at end of file +} + \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js index 19579a2af97e..e79968dd8d1b 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/exec.js @@ -3,14 +3,14 @@ class Foo { return this; } - #tag2 = this.#tag; + #tag2 = function() { return this; }; constructor() { const receiver = this.#tag`tagged template`; - expect(receiver === this).toBe(true); + expect(receiver).toBe(this); const receiver2 = this.#tag2`tagged template`; - expect(receiver2 === this).toBe(true); + expect(receiver2).toBe(this); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js index 1075a4e072b4..a93e2db67c12 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/input.js @@ -1,8 +1,9 @@ class Foo { - #tag() { - return this; - } - - #tag2 = this.#tag; + #tag; + + test() { + this.#tag``; } - new Foo(); \ No newline at end of file +} + +new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js index 87ea351859ea..c17ac7f87ea3 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js @@ -1,16 +1,10 @@ class Foo { - #tag() { - return this; + get #tag() { + return () => this; } - - get #privateTagMethod(){ - return this.#tag`` + + constructor() { + const receiver = this.#tag``; + expect(receiver).toBe(this); } - - publicGetPrivateTagMethod(){ - return this.#privateTagMethod - } -} -const instance = new Foo(); - -expect(instance.publicGetPrivateTagMethod()).toEqual(instance) \ No newline at end of file +} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js index 2b10379b05ec..815b68ed7118 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js @@ -1,14 +1,7 @@ class Foo { - #tag() { - return this; - } - - get #privateTagMethod(){ - return this.#tag`` - } - - publicGetPrivateTagMethod(){ - return this.#privateTagMethod - } + get #tag() { + return () => this; } - const instance = new Foo(); \ No newline at end of file +} + +new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js index 71520d6621be..85a02b5d72ac 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/exec.js @@ -1,11 +1,11 @@ class Foo { - #tag() { - return this; - } + #tag() { + return this; + } - constructor() { - const receiver = this.#tag`tagged template`; - expect(receiver === this).toBe(true); - } + constructor() { + const receiver = this.#tag`tagged template`; + expect(receiver).toBe(this); } - new Foo(); \ No newline at end of file +} +new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js index fee469e9341c..31dc6eea4747 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/input.js @@ -1,6 +1,6 @@ class Foo { - #tag() { - return this; + static #tag() { + this.#tag``; } } new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js index 53a2dc4227cf..4ea5de71afd3 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js @@ -1,9 +1,10 @@ class Foo { - static #tag() { - return this; - } + static get #tag() { + return () => this; + } - static get privateTagMethod() { - return this.#tag``; - } + static test() { + const receiver = this.#tag``; + expect(receiver).toBe(this); + } } \ No newline at end of file From e85228fa120e5f29477a0091ff36814f4dd6c4b9 Mon Sep 17 00:00:00 2001 From: "sagiv.bengiat" Date: Sat, 12 Jun 2021 14:00:35 +0300 Subject: [PATCH 5/6] update tests output --- .../private/tagged-template-static/output.js | 12 ++----- .../private/tagged-template/output.js | 32 ++++++++++--------- .../accessors/tagged-template/output.js | 24 ++++---------- .../tagged-template/output.js | 13 ++------ .../tagged-template/output.js | 14 +++++--- 5 files changed, 38 insertions(+), 57 deletions(-) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js index 4a4f468bd6d1..0f7a2d29767e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template-static/output.js @@ -1,19 +1,11 @@ class Foo { static getReceiver() { - return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; + return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag).bind(this)``; } - static getReceiver2() { - return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag3).bind(this)``; - } - -} - -function _tag() { - return this; } -var _tag3 = { +var _tag = { writable: true, value: function () { return this; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js index 43cede28beb6..b06497c1fcdc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js @@ -1,22 +1,24 @@ -var _tag = /*#__PURE__*/new WeakSet(); +var _tag = /*#__PURE__*/new WeakMap(); -var _tag3 = /*#__PURE__*/new WeakMap(); - -var Foo = function Foo() { +var Foo = /*#__PURE__*/function () { "use strict"; - babelHelpers.classCallCheck(this, Foo); - - _tag.add(this); + function Foo() { + babelHelpers.classCallCheck(this, Foo); - _tag3.set(this, { - writable: true, - value: babelHelpers.classPrivateMethodGet(this, _tag, _tag2) - }); -}; + _tag.set(this, { + writable: true, + value: void 0 + }); + } -function _tag2() { - return this; -} + babelHelpers.createClass(Foo, [{ + key: "test", + value: function test() { + babelHelpers.classPrivateFieldGet(this, _tag).bind(this)``; + } + }]); + return Foo; +}(); new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js index bc31ab9e0027..bb53819a947e 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js @@ -1,29 +1,17 @@ -var _tag = /*#__PURE__*/new WeakSet(); - -var _privateTagMethod = /*#__PURE__*/new WeakMap(); +var _tag = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _privateTagMethod.set(this, { - get: _get_privateTagMethod, + _tag.set(this, { + get: _get_tag, set: void 0 }); - - _tag.add(this); - } - - publicGetPrivateTagMethod() { - return babelHelpers.classPrivateFieldGet(this, _privateTagMethod); } } -function _tag2() { - return this; -} - -function _get_privateTagMethod() { - return babelHelpers.classPrivateMethodGet(this, _tag, _tag2).bind(this)``; +function _get_tag() { + return () => this; } -var instance = new Foo(); +new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js index 797b93d41911..a2ef9d854ce4 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/tagged-template/output.js @@ -1,14 +1,7 @@ -var _tag = /*#__PURE__*/new WeakSet(); +class Foo {} -class Foo { - constructor() { - _tag.add(this); - } - -} - -function _tag2() { - return this; +function _tag() { + babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; } new Foo(); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js index 6f515898a0df..9059de15c818 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js @@ -1,10 +1,16 @@ class Foo { - static get privateTagMethod() { - return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``; + static test() { + var receiver = babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag).bind(this)``; + expect(receiver).toBe(this); } } -function _tag() { - return this; +function _get_tag() { + return () => this; } + +var _tag = { + get: _get_tag, + set: void 0 +}; From 9a0d7ec9e16d607def87e70847dad197b83d65af Mon Sep 17 00:00:00 2001 From: "sagiv.bengiat" Date: Tue, 15 Jun 2021 09:48:37 +0300 Subject: [PATCH 6/6] swap arrow funcs to regular funcs --- .../test/fixtures/accessors/tagged-template/exec.js | 2 +- .../test/fixtures/accessors/tagged-template/input.js | 4 ++++ .../test/fixtures/accessors/tagged-template/output.js | 2 ++ .../test/fixtures/static-accessors/tagged-template/input.js | 2 +- .../test/fixtures/static-accessors/tagged-template/output.js | 4 +++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js index c17ac7f87ea3..c3c22f83dadb 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js @@ -1,6 +1,6 @@ class Foo { get #tag() { - return () => this; + return function() { return this; }; } constructor() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js index 815b68ed7118..0a8c6fa3bc47 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js @@ -2,6 +2,10 @@ class Foo { get #tag() { return () => this; } + + constructor() { + this.#tag``; + } } new Foo(); \ No newline at end of file diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js index bb53819a947e..90a909b22bbe 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js @@ -6,6 +6,8 @@ class Foo { get: _get_tag, set: void 0 }); + + babelHelpers.classPrivateFieldGet(this, _tag).bind(this)``; } } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js index 4ea5de71afd3..bcae85f476f4 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/input.js @@ -1,6 +1,6 @@ class Foo { static get #tag() { - return () => this; + return function() { return this; }; } static test() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js index 9059de15c818..89ff9d565f65 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/tagged-template/output.js @@ -7,7 +7,9 @@ class Foo { } function _get_tag() { - return () => this; + return function () { + return this; + }; } var _tag = {