Skip to content

do not clone the receiver #57

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ namespace ts {
}

function createPrivateIdentifierAccess(info: PrivateIdentifierInfo, receiver: Expression): Expression {
receiver = visitNode(receiver, visitor, isExpression);
const synthesizedReceiver = nodeIsSynthesized(receiver) ? receiver : factory.cloneNode(receiver);
return createPrivateIdentifierAccessHelper(info, synthesizedReceiver);
return createPrivateIdentifierAccessHelper(info, visitNode(receiver, visitor, isExpression));
}

function createPrivateIdentifierAccessHelper(info: PrivateIdentifierInfo, receiver: Expression): Expression {
Expand Down
6 changes: 4 additions & 2 deletions tests/baselines/reference/privateNameAndAny.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class A {
}
method(thing) {
__classPrivateFieldGet(thing, _A_foo, "f"); // OK
__classPrivateFieldGet(thing, _a, "m", _A_m).call(// OK
__classPrivateFieldGet(// OK
thing, _a, "m", _A_m).call(// OK
thing);
__classPrivateFieldGet(thing, _a, "f", _A_baz);
thing.; // Error
__classPrivateFieldGet(thing, _A_foo, "f").call(// Error
__classPrivateFieldGet(// Error
thing, _A_foo, "f").call(// Error
thing);
}
methodU(thing) {
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateNameMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class A1 {
_A1_instances.add(this);
__classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(this, "");
__classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(this, 1); // Error
__classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(// Error
__classPrivateFieldGet(// Error
this, _A1_instances, "m", _A1_method).call(// Error
this); // Error
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateNameNestedMethodAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class C {
_D_instances.add(this);
__classPrivateFieldGet(new C(), _C_foo, "f");
__classPrivateFieldGet(new C(), _D_instances, "m", _D_bar); // Error
__classPrivateFieldGet(new C(), _C_instances, "a", _C_baz_get);
__classPrivateFieldGet(// Error
new C(), _C_instances, "a", _C_baz_get);
__classPrivateFieldGet(new D(), _D_instances, "m", _D_bar);
}
n(x) {
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateNameStaticMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class A1 {
constructor() {
__classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1, "");
__classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1, 1); // Error
__classPrivateFieldGet(A1, _a, "m", _A1_method).call(// Error
__classPrivateFieldGet(// Error
A1, _a, "m", _A1_method).call(// Error
A1); // Error
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateNamesAndStaticFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class A {
constructor() {
__classPrivateFieldSet(A, _a, 3, "f", _A_foo);
__classPrivateFieldGet(B, _a, "f", _A_foo); // Error
__classPrivateFieldGet(B, _a, "f", _A_bar); // Error
__classPrivateFieldGet(// Error
B, _a, "f", _A_bar); // Error
}
}
_a = A;
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateNamesConstructorChain-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Parent {
}
accessChildProps() {
__classPrivateFieldGet(new Child(), _Parent_foo, "f"); // OK (`#foo` was added when `Parent`'s constructor was called on `child`)
__classPrivateFieldGet(Child, _a, "f", _Parent_bar); // Error: not found
__classPrivateFieldGet(// OK (`#foo` was added when `Parent`'s constructor was called on `child`)
Child, _a, "f", _Parent_bar); // Error: not found
}
}
_a = Parent, _Parent_foo = new WeakMap();
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateNamesConstructorChain-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Parent {
}
accessChildProps() {
__classPrivateFieldGet(new Child(), _Parent_foo, "f"); // OK (`#foo` was added when `Parent`'s constructor was called on `child`)
__classPrivateFieldGet(Child, _a, "f", _Parent_bar); // Error: not found
__classPrivateFieldGet(// OK (`#foo` was added when `Parent`'s constructor was called on `child`)
Child, _a, "f", _Parent_bar); // Error: not found
}
}
_a = Parent, _Parent_foo = new WeakMap();
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/privateStaticNameShadowing.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class X {
_b = X, _X_m = function _X_m() {
const X = {}; // shadow the class
const _a = {}; // shadow the first generated var
__classPrivateFieldGet(X, _b, "m", _X_m).call(// shadow the first generated var
__classPrivateFieldGet(// shadow the first generated var
X, _b, "m", _X_m).call(// shadow the first generated var
X); // Should check with X as the receiver with _b as the class constructor
return 1;
};
Expand Down