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 duplicated trailing comments #64

Merged
merged 2 commits into from
Mar 24, 2021
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
30 changes: 23 additions & 7 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,31 +352,39 @@ namespace ts {
}

function createPrivateIdentifierAccessHelper(info: PrivateIdentifierInfo, receiver: Expression): Expression {
let getExpression: Expression;

switch(info.kind) {
case PrivateIdentifierKind.Accessor:
return context.getEmitHelperFactory().createClassPrivateFieldGetHelper(
getExpression = context.getEmitHelperFactory().createClassPrivateFieldGetHelper(
receiver,
info.brandCheckIdentifier,
info.kind,
info.getterName
);
break;
case PrivateIdentifierKind.Method:
return context.getEmitHelperFactory().createClassPrivateFieldGetHelper(
getExpression = context.getEmitHelperFactory().createClassPrivateFieldGetHelper(
receiver,
info.brandCheckIdentifier,
info.kind,
info.methodName
);
break;
case PrivateIdentifierKind.Field:
return context.getEmitHelperFactory().createClassPrivateFieldGetHelper(
getExpression = context.getEmitHelperFactory().createClassPrivateFieldGetHelper(
receiver,
info.brandCheckIdentifier,
info.kind,
info.variableName
);
break;
default:
Debug.assertNever(info, "Unknown private element type");
}

setCommentRange(receiver, getExpression);
return getExpression;
}

function visitPropertyAccessExpression(node: PropertyAccessExpression) {
Expand Down Expand Up @@ -555,7 +563,7 @@ namespace ts {
return visitEachChild(node, visitor, context);
}

function createPrivateIdentifierAssignment(info: PrivateIdentifierInfo, receiver: Expression, right: Expression, operator: AssignmentOperator) {
function createPrivateIdentifierAssignment(info: PrivateIdentifierInfo, receiver: Expression, right: Expression, operator: AssignmentOperator): Expression {
receiver = visitNode(receiver, visitor, isExpression);
right = visitNode(right, visitor, isExpression);

Expand All @@ -569,34 +577,42 @@ namespace ts {
);
}

let setExpression: Expression;

switch(info.kind) {
case PrivateIdentifierKind.Accessor:
return context.getEmitHelperFactory().createClassPrivateFieldSetHelper(
setExpression = context.getEmitHelperFactory().createClassPrivateFieldSetHelper(
receiver,
info.brandCheckIdentifier,
right,
info.kind,
info.setterName
);
break;
case PrivateIdentifierKind.Method:
return context.getEmitHelperFactory().createClassPrivateFieldSetHelper(
setExpression = context.getEmitHelperFactory().createClassPrivateFieldSetHelper(
receiver,
info.brandCheckIdentifier,
right,
info.kind,
/* f */ undefined
);
break;
case PrivateIdentifierKind.Field:
return context.getEmitHelperFactory().createClassPrivateFieldSetHelper(
setExpression = context.getEmitHelperFactory().createClassPrivateFieldSetHelper(
receiver,
info.brandCheckIdentifier,
right,
info.kind,
info.variableName
);
break;
default:
Debug.assertNever(info, "Unknown private element type");
}

setCommentRange(receiver, setExpression);
return setExpression;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions tests/baselines/reference/privateNameAndAny.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ class A {
}
method(thing) {
__classPrivateFieldGet(thing, _A_foo, "f"); // OK
__classPrivateFieldGet(// OK
thing, _a, "m", _A_m).call(// OK
thing);
__classPrivateFieldGet(thing, _a, "m", _A_m).call(thing);
__classPrivateFieldGet(thing, _a, "f", _A_baz);
thing.; // Error
__classPrivateFieldGet(// Error
thing, _A_foo, "f").call(// Error
thing);
__classPrivateFieldGet(thing, _A_foo, "f").call(thing);
}
methodU(thing) {
__classPrivateFieldGet(thing, _A_foo, "f");
Expand Down
4 changes: 1 addition & 3 deletions tests/baselines/reference/privateNameMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ 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(// Error
this, _A1_instances, "m", _A1_method).call(// Error
this); // Error
__classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(this); // Error
}
}
_A1_instances = new WeakSet(), _A1_method = function _A1_method(param) {
Expand Down
6 changes: 2 additions & 4 deletions tests/baselines/reference/privateNameMethodAssignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class A3 {
var _a, _b;
_A3_instances.add(this);
__classPrivateFieldSet(this, _A3_instances, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(// Error, not writable
a, _A3_instances, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(// Error, not writable
b, _A3_instances, () => { }, "m"); //Error, not writable
__classPrivateFieldSet(a, _A3_instances, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(b, _A3_instances, () => { }, "m"); //Error, not writable
(_a = this, { x: ({ set value(_b) { __classPrivateFieldSet(_a, _A3_instances, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable
let x = __classPrivateFieldGet(this, _A3_instances, "m", _A3_method);
__classPrivateFieldSet(_b = b, _A3_instances, +__classPrivateFieldGet(_b, _A3_instances, "m", _A3_method) + 1, "m"); //Error, not writable
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/privateNameNestedMethodAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class C {
_D_instances.add(this);
__classPrivateFieldGet(new C(), _C_foo, "f");
__classPrivateFieldGet(new C(), _D_instances, "m", _D_bar); // Error
__classPrivateFieldGet(// Error
new C(), _C_instances, "a", _C_baz_get);
__classPrivateFieldGet(new C(), _C_instances, "a", _C_baz_get);
__classPrivateFieldGet(new D(), _D_instances, "m", _D_bar);
}
n(x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ var _a, _Base_prop, _b, _Derived_derivedProp;
class Base {
static method(x) {
Derived.; // error
__classPrivateFieldSet(// error
Base, _a, 10, "f", _Base_prop);
__classPrivateFieldSet(Base, _a, 10, "f", _Base_prop);
}
}
_a = Base;
Expand Down
4 changes: 1 addition & 3 deletions tests/baselines/reference/privateNameStaticMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class A1 {
constructor() {
__classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1, "");
__classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1, 1); // Error
__classPrivateFieldGet(// Error
A1, _a, "m", _A1_method).call(// Error
A1); // Error
__classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1); // Error
}
}
_a = A1, _A1_method = function _A1_method(param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class A3 {
constructor(a, b) {
var _b;
__classPrivateFieldSet(A3, _a, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(// Error, not writable
a, _a, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(// Error, not writable
b, _a, () => { }, "m"); //Error, not writable
__classPrivateFieldSet(a, _a, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(b, _a, () => { }, "m"); //Error, not writable
({ x: ({ set value(_b) { __classPrivateFieldSet(A3, _a, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable
let x = __classPrivateFieldGet(A3, _a, "m", _A3_method);
__classPrivateFieldSet(_b = b, _a, +__classPrivateFieldGet(_b, _a, "m", _A3_method) + 1, "m"); //Error, not writable
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/privateNamesAndStaticFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class A {
constructor() {
__classPrivateFieldSet(A, _a, 3, "f", _A_foo);
__classPrivateFieldGet(B, _a, "f", _A_foo); // Error
__classPrivateFieldGet(// Error
B, _a, "f", _A_bar); // Error
__classPrivateFieldGet(B, _a, "f", _A_bar); // Error
}
}
_a = A;
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/privateNamesConstructorChain-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class Parent {
}
accessChildProps() {
__classPrivateFieldGet(new Child(), _Parent_foo, "f"); // OK (`#foo` was added when `Parent`'s constructor was called on `child`)
__classPrivateFieldGet(// OK (`#foo` was added when `Parent`'s constructor was called on `child`)
Child, _a, "f", _Parent_bar); // Error: not found
__classPrivateFieldGet(Child, _a, "f", _Parent_bar); // Error: not found
}
}
_a = Parent, _Parent_foo = new WeakMap();
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/privateNamesConstructorChain-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class Parent {
}
accessChildProps() {
__classPrivateFieldGet(new Child(), _Parent_foo, "f"); // OK (`#foo` was added when `Parent`'s constructor was called on `child`)
__classPrivateFieldGet(// OK (`#foo` was added when `Parent`'s constructor was called on `child`)
Child, _a, "f", _Parent_bar); // Error: not found
__classPrivateFieldGet(Child, _a, "f", _Parent_bar); // Error: not found
}
}
_a = Parent, _Parent_foo = new WeakMap();
Expand Down
4 changes: 1 addition & 3 deletions tests/baselines/reference/privateStaticNameShadowing.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class X {
_b = X, _X_m = function _X_m() {
const X = {}; // shadow the class
const _a = {}; // 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
__classPrivateFieldGet(X, _b, "m", _X_m).call(X); // Should check with X as the receiver with _b as the class constructor
return 1;
};
_X_f = { value: __classPrivateFieldGet(X, _b, "m", _X_m).call(X) };
9 changes: 3 additions & 6 deletions tests/baselines/reference/privateWriteOnlyAccessorRead.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ class Test {
var _a, _b, _c;
const foo = { bar: 1 };
console.log(__classPrivateFieldGet(this, _Test_instances, "a")); // error
__classPrivateFieldSet(// error
this, _Test_instances, { foo }, "a", _Test_value_set); // ok
__classPrivateFieldSet(// ok
this, _Test_instances, { foo }, "a", _Test_value_set); // ok
__classPrivateFieldGet(// ok
this, _Test_instances, "a").foo = foo; // error
__classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok
__classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok
__classPrivateFieldGet(this, _Test_instances, "a").foo = foo; // error
(_a = this, { o: ({ set value(_d) { __classPrivateFieldSet(_a, _Test_instances, _d, "a", _Test_value_set); } }).value } = { o: { foo } }); //ok
(__classPrivateFieldGet(this, _Test_instances, "a") = __rest({ foo }, [])); //ok
({ foo: __classPrivateFieldGet(this, _Test_instances, "a").foo } = { foo }); //error
Expand Down