Skip to content

Commit d33c72c

Browse files
joeywattsmheiber
authored andcommitted
Fix comments with private fields
Fix comments and source maps for comments near comments Add regression test Signed-off-by: Joseph Watts <[email protected]>
1 parent 8bfc540 commit d33c72c

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,8 @@ namespace ts {
952952
member.type,
953953
/*initializer*/ undefined
954954
);
955-
setCommentRange(updated, node);
956-
setSourceMapRange(updated, node);
955+
setCommentRange(updated, member);
956+
setSourceMapRange(updated, member);
957957
return updated;
958958
}
959959
return member;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [classConstructorParametersCommentPlacement.ts]
2+
// some comment
3+
class A {
4+
#a = "private hello";
5+
#b = "another private name";
6+
a = "public property";
7+
constructor(private b = "something") { }
8+
}
9+
10+
11+
//// [classConstructorParametersCommentPlacement.js]
12+
var _classPrivateFieldSet = function (receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; };
13+
var _a, _b;
14+
// some comment
15+
var A = /** @class */ (function () {
16+
function A(b) {
17+
if (b === void 0) { b = "something"; }
18+
_a.set(this, void 0);
19+
_b.set(this, void 0);
20+
this.b = b;
21+
_classPrivateFieldSet(this, _a, "private hello");
22+
_classPrivateFieldSet(this, _b, "another private name");
23+
this.a = "public property";
24+
}
25+
return A;
26+
}());
27+
_a = new WeakMap(), _b = new WeakMap();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersCommentPlacement.ts ===
2+
// some comment
3+
class A {
4+
>A : Symbol(A, Decl(classConstructorParametersCommentPlacement.ts, 0, 0))
5+
6+
#a = "private hello";
7+
>#a : Symbol(A.#a, Decl(classConstructorParametersCommentPlacement.ts, 1, 9))
8+
9+
#b = "another private name";
10+
>#b : Symbol(A.#b, Decl(classConstructorParametersCommentPlacement.ts, 2, 25))
11+
12+
a = "public property";
13+
>a : Symbol(A.a, Decl(classConstructorParametersCommentPlacement.ts, 3, 32))
14+
15+
constructor(private b = "something") { }
16+
>b : Symbol(A.b, Decl(classConstructorParametersCommentPlacement.ts, 5, 16))
17+
}
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersCommentPlacement.ts ===
2+
// some comment
3+
class A {
4+
>A : A
5+
6+
#a = "private hello";
7+
>#a : string
8+
>"private hello" : "private hello"
9+
10+
#b = "another private name";
11+
>#b : string
12+
>"another private name" : "another private name"
13+
14+
a = "public property";
15+
>a : string
16+
>"public property" : "public property"
17+
18+
constructor(private b = "something") { }
19+
>b : string
20+
>"something" : "something"
21+
}
22+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
// some comment
3+
class A {
4+
#a = "private hello";
5+
#b = "another private name";
6+
a = "public property";
7+
constructor(private b = "something") { }
8+
}

0 commit comments

Comments
 (0)