fix: tagged template incorrect receiver (#13395)
* fix: tagged template incorrect receiver * review changes * func exp instead of arrow * review comments * update tests output * swap arrow funcs to regular funcs Co-authored-by: sagiv.bengiat <sagiv.bengiat@appsflyer.com>
This commit is contained in:
10
packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js
vendored
Normal file
10
packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/exec.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
class Foo {
|
||||
get #tag() {
|
||||
return function() { return this; };
|
||||
}
|
||||
|
||||
constructor() {
|
||||
const receiver = this.#tag``;
|
||||
expect(receiver).toBe(this);
|
||||
}
|
||||
}
|
||||
11
packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js
vendored
Normal file
11
packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/input.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
get #tag() {
|
||||
return () => this;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.#tag``;
|
||||
}
|
||||
}
|
||||
|
||||
new Foo();
|
||||
19
packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js
vendored
Normal file
19
packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var _tag = /*#__PURE__*/new WeakMap();
|
||||
|
||||
class Foo {
|
||||
constructor() {
|
||||
_tag.set(this, {
|
||||
get: _get_tag,
|
||||
set: void 0
|
||||
});
|
||||
|
||||
babelHelpers.classPrivateFieldGet(this, _tag).bind(this)``;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function _get_tag() {
|
||||
return () => this;
|
||||
}
|
||||
|
||||
new Foo();
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
#tag() {
|
||||
return this;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
const receiver = this.#tag`tagged template`;
|
||||
expect(receiver).toBe(this);
|
||||
}
|
||||
}
|
||||
new Foo();
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
#tag() {
|
||||
this.#tag``;
|
||||
}
|
||||
}
|
||||
new Foo();
|
||||
@@ -0,0 +1,14 @@
|
||||
var _tag = /*#__PURE__*/new WeakSet();
|
||||
|
||||
class Foo {
|
||||
constructor() {
|
||||
_tag.add(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function _tag2() {
|
||||
babelHelpers.classPrivateMethodGet(this, _tag, _tag2).bind(this)``;
|
||||
}
|
||||
|
||||
new Foo();
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
static #tag() {
|
||||
return this;
|
||||
}
|
||||
|
||||
static getReceiver() {
|
||||
return this.#tag``;
|
||||
}
|
||||
}
|
||||
|
||||
expect(Foo.getReceiver()).toBe(Foo);
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
static #tag() {
|
||||
this.#tag``;
|
||||
}
|
||||
}
|
||||
new Foo();
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {}
|
||||
|
||||
function _tag() {
|
||||
babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``;
|
||||
}
|
||||
|
||||
new Foo();
|
||||
@@ -0,0 +1,10 @@
|
||||
class Foo {
|
||||
static get #tag() {
|
||||
return function() { return this; };
|
||||
}
|
||||
|
||||
static test() {
|
||||
const receiver = this.#tag``;
|
||||
expect(receiver).toBe(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
class Foo {
|
||||
static test() {
|
||||
var receiver = babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag).bind(this)``;
|
||||
expect(receiver).toBe(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function _get_tag() {
|
||||
return function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
var _tag = {
|
||||
get: _get_tag,
|
||||
set: void 0
|
||||
};
|
||||
Reference in New Issue
Block a user