Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tagged template incorrect receiver #13395

Merged
merged 6 commits into from Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -462,8 +462,13 @@ const handle = {
return;
}

// MEMBER -> _get(MEMBER)
member.replaceWith(this.get(member));
if (t.isTaggedTemplateExpression(parent)) {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
// MEMBER -> _get(MEMBER).bind(this)
member.replaceWith(this.boundGet(member));
} else {
// MEMBER -> _get(MEMBER)
member.replaceWith(this.get(member));
}
},
};

Expand Down
@@ -0,0 +1,17 @@
class Foo {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
static #tag() {
return this;
}

static #tag2 = () => this
jridgewell marked this conversation as resolved.
Show resolved Hide resolved

static getReceiver() {
return this.#tag``;
}

static getReceiver2() {
return this.#tag2``;
}
}

expect(Foo.getReceiver()).toBe(Foo.getReceiver2());
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,15 @@
class Foo {
static #tag() {
return this;
}
jridgewell marked this conversation as resolved.
Show resolved Hide resolved

static #tag2 = () => this
jridgewell marked this conversation as resolved.
Show resolved Hide resolved

static getReceiver() {
return this.#tag``;
}

static getReceiver2() {
return this.#tag2``;
}
}
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"shippedProposals": true,
"targets": {
"chrome": "75"
}
}
]
]
}
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
@@ -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
};
@@ -0,0 +1,17 @@
class Foo {
#tag() {
return this;
}

#tag2 = this.#tag;
jridgewell marked this conversation as resolved.
Show resolved Hide resolved

constructor() {
const receiver = this.#tag`tagged template`;
expect(receiver === this).toBe(true);

const receiver2 = this.#tag2`tagged template`;
expect(receiver2 === this).toBe(true);
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
}
}

new Foo();
@@ -0,0 +1,8 @@
class Foo {
#tag() {
return this;
}

#tag2 = this.#tag;
}
new Foo();
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"shippedProposals": true,
"targets": {
"chrome": "75"
}
}
]
]
}
@@ -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();
@@ -0,0 +1,16 @@
class Foo {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
#tag() {
return this;
}

get #privateTagMethod(){
return this.#tag``
}

publicGetPrivateTagMethod(){
return this.#privateTagMethod
}
}
const instance = new Foo();

expect(instance === instance.publicGetPrivateTagMethod()).toEqual(true)
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,14 @@
class Foo {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
#tag() {
return this;
}

get #privateTagMethod(){
return this.#tag``
}

publicGetPrivateTagMethod(){
return this.#privateTagMethod
}
}
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
const instance = new Foo();
@@ -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();
@@ -0,0 +1,11 @@
class Foo {
#tag() {
return this;
}

constructor() {
const receiver = this.#tag`tagged template`;
expect(receiver === this).toBe(true);
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
}
}
new Foo();
@@ -0,0 +1,6 @@
class Foo {
#tag() {
return this;
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
}
}
new Foo();
@@ -0,0 +1,14 @@
var _tag = /*#__PURE__*/new WeakSet();

class Foo {
constructor() {
_tag.add(this);
}

}

function _tag2() {
return 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 {
#tag() {
return this;
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
}
}
new Foo();
@@ -0,0 +1,14 @@
var _tag = /*#__PURE__*/new WeakSet();

class Foo {
constructor() {
_tag.add(this);
}

}

function _tag2() {
return this;
}

new Foo();
@@ -0,0 +1,11 @@
class Foo {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
static #tag() {
return this;
}

static get privateTagMethod() {
return this.#tag``;
}
}

expect(Foo.privateTagMethod).toBe(Foo);
@@ -0,0 +1,9 @@
class Foo {
static #tag() {
return this;
}

static get privateTagMethod() {
return this.#tag``;
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
}
}
@@ -0,0 +1,10 @@
class Foo {
static get privateTagMethod() {
return babelHelpers.classStaticPrivateMethodGet(this, Foo, _tag).bind(this)``;
}

}

function _tag() {
return this;
}