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 5 commits
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 (parentPath.isTaggedTemplateExpression()) {
// MEMBER -> _get(MEMBER).bind(this)
member.replaceWith(this.boundGet(member));
} else {
// MEMBER -> _get(MEMBER)
member.replaceWith(this.get(member));
}
},
};

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

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

expect(Foo.getReceiver()).toBe(Foo);
@@ -0,0 +1,8 @@
class Foo {
static #tag = function () { return this };

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

@@ -0,0 +1,6 @@
{
"plugins": [
"proposal-class-properties",
"proposal-private-methods"
]
}
@@ -0,0 +1,13 @@
class Foo {
static getReceiver() {
return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag).bind(this)``;
}

}

var _tag = {
writable: true,
value: function () {
return this;
}
};
@@ -0,0 +1,17 @@
class Foo {
#tag() {
return this;
}

#tag2 = function() { return this; };

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

const receiver2 = this.#tag2`tagged template`;
expect(receiver2).toBe(this);
}
}

new Foo();
@@ -0,0 +1,9 @@
class Foo {
#tag;

test() {
this.#tag``;
}
}

new Foo();
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"shippedProposals": true,
"targets": {
"chrome": "75"
}
}
]
]
}
@@ -0,0 +1,24 @@
var _tag = /*#__PURE__*/new WeakMap();

var Foo = /*#__PURE__*/function () {
"use strict";

function Foo() {
babelHelpers.classCallCheck(this, Foo);

_tag.set(this, {
writable: true,
value: void 0
});
}

babelHelpers.createClass(Foo, [{
key: "test",
value: function test() {
babelHelpers.classPrivateFieldGet(this, _tag).bind(this)``;
}
}]);
return Foo;
}();

new Foo();
@@ -0,0 +1,10 @@
class Foo {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
get #tag() {
return () => this;
existentialism marked this conversation as resolved.
Show resolved Hide resolved
}

constructor() {
const receiver = this.#tag``;
expect(receiver).toBe(this);
}
}
@@ -0,0 +1,7 @@
class Foo {
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
get #tag() {
return () => this;
}
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
}

new Foo();
@@ -0,0 +1,17 @@
var _tag = /*#__PURE__*/new WeakMap();

class Foo {
constructor() {
_tag.set(this, {
get: _get_tag,
set: void 0
});
}

}

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 () => this;
existentialism marked this conversation as resolved.
Show resolved Hide resolved
}

static test() {
const receiver = this.#tag``;
expect(receiver).toBe(this);
}
}
@@ -0,0 +1,16 @@
class Foo {
static test() {
var receiver = babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _tag).bind(this)``;
expect(receiver).toBe(this);
}

}

function _get_tag() {
return () => this;
}

var _tag = {
get: _get_tag,
set: void 0
};