Skip to content

Commit 1c06342

Browse files
committed
Merge pull request microsoft#8095 from Microsoft/transformArrowComments
[Transforms] Fixes the incorrectly assigned arrow expression trailing comments
2 parents cefe39c + 1061656 commit 1c06342

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/compiler/printer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,8 +1505,11 @@ const _super = (function (geti, seti) {
15051505
const endingLine = writer.getLine();
15061506
emitLexicalEnvironment(endLexicalEnvironment(), /*newLine*/ startingLine !== endingLine);
15071507

1508-
const range = collapseRangeToEnd(body.statements);
1509-
emitLeadingComments(range, getLeadingComments(range));
1508+
// Do not emit leading comments if the body belongs to arrow expression
1509+
if (!body.original || isBlock(body.original)) {
1510+
const range = collapseRangeToEnd(body.statements);
1511+
emitLeadingComments(range, getLeadingComments(range));
1512+
}
15101513
decreaseIndent();
15111514
}
15121515

src/compiler/transformers/es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ namespace ts {
12711271
setNodeEmitFlags(block, NodeEmitFlags.SingleLine);
12721272
}
12731273

1274+
setOriginalNode(block, node.body);
12741275
return block;
12751276
}
12761277

tests/baselines/reference/disallowLineTerminatorBeforeArrow.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ var f8 = function (x, y, z) {
110110
var f9 = function (a) { return a; };
111111
var f10 = function (a) { return a; };
112112
var f11 = function (a) { return a; };
113-
var f12 = function (a) {
114-
return a;
115-
};
113+
var f12 = function (a) { return a; };
116114
// Should be valid.
117115
var f11 = function (a) { return a; };
118116
// Should be valid.

0 commit comments

Comments
 (0)