Skip to content

Commit fdd6a2b

Browse files
Closure Teamcopybara-github
Closure Team
authored andcommitted
Fix RewriteClassMembers to move the jsdoc on instance field when it is moved to the constructor.
PiperOrigin-RevId: 620291707
1 parent 739013c commit fdd6a2b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/com/google/javascript/jscomp/RewriteClassMembers.java

+6
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ private Node convNonCompFieldToGetProp(Node receiver, Node noncomputedField) {
341341
(fieldValue != null)
342342
? astFactory.createAssignStatement(getProp, fieldValue.detach())
343343
: astFactory.exprResult(getProp);
344+
// Move any JSDoc from the field declaration to the child of the EXPR_RESULT,
345+
// which represents the new declaration.
346+
// noncomputedField is already detached, so there's no benefit to calling
347+
// NodeUtil.getBestJSDocInfo(noncomputedField). For now at least,
348+
// the JSDocInfo we want will always be directly on noncomputedField in all cases.
349+
result.getFirstChild().setJSDocInfo(noncomputedField.getJSDocInfo());
344350
result.srcrefTreeIfMissing(noncomputedField);
345351
return result;
346352
}

test/com/google/javascript/jscomp/RewriteClassMembersTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,14 @@ public void testThisInNonStaticPublicField() {
283283
test(
284284
lines(
285285
"class A {", //
286+
" /** @suppress {partialAlias} */",
286287
" b = 'word';",
287288
" c = this.b;",
288289
"}"),
289290
lines(
290291
"class A {",
291292
" constructor() {",
293+
" /** @suppress {partialAlias} */",
292294
" this.b = 'word';",
293295
" this.c = this.b;",
294296
" }",

0 commit comments

Comments
 (0)