Skip to content

Commit 1b07a00

Browse files
babakksjakebailey
authored andcommitted
šŸ› Fix not emitting comments between sibling fields of object literals (microsoft#50097)
Co-authored-by: Jake Bailey <[email protected]>
1 parent 1f40fbe commit 1b07a00

26 files changed

+100
-28
lines changed

ā€Žsrc/compiler/emitter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,6 +5120,11 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
51205120
shouldDecreaseIndentAfterEmit = true;
51215121
}
51225122

5123+
if (shouldEmitInterveningComments && format & ListFormat.DelimitersMask && !positionIsSynthesized(child.pos)) {
5124+
const commentRange = getCommentRange(child);
5125+
emitTrailingCommentsOfPosition(commentRange.pos, /*prefixSpace*/ !!(format & ListFormat.SpaceBetweenSiblings), /*forceNoNewline*/ true);
5126+
}
5127+
51235128
writeLine(separatingLineTerminatorCount);
51245129
shouldEmitInterveningComments = false;
51255130
}

ā€Žtests/baselines/reference/arrowFunctionParsingDoesNotConfuseParenthesizedObjectForArrowHead.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const test = () => ({
2020
//// [arrowFunctionParsingDoesNotConfuseParenthesizedObjectForArrowHead.js]
2121
var test = function () { return ({
2222
// "Identifier expected." error on "!" and two "Duplicate identifier '(Missing)'." errors on space.
23-
prop: !value,
23+
prop: !value, // remove ! to see that errors will be gone
2424
run: function () {
2525
// comment next line or remove "()" to see that errors will be gone
2626
if (!a.b()) {

ā€Žtests/baselines/reference/assignmentCompatBug3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ foo(x + y);
3030
//// [assignmentCompatBug3.js]
3131
function makePoint(x, y) {
3232
return {
33-
get x() { return x; },
34-
get y() { return y; },
33+
get x() { return x; }, // shouldn't be "void"
34+
get y() { return y; }, // shouldn't be "void"
3535
//x: "yo",
3636
//y: "boo",
3737
dist: function () {

ā€Žtests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _d = useReduxDispatch1(function (d, f) { return ({
4545
p[_i] = arguments[_i];
4646
}
4747
return d(f.funcA.apply(f, p));
48-
},
48+
}, // p should be inferrable
4949
funcB: function () {
5050
var p = [];
5151
for (var _i = 0; _i < arguments.length; _i++) {

ā€Žtests/baselines/reference/callSignaturesWithParameterInitializers2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ c.foo(1);
4949
var b = {
5050
foo: function (x) {
5151
if (x === void 0) { x = 1; }
52-
},
52+
}, // error
5353
foo: function (x) {
5454
if (x === void 0) { x = 1; }
5555
},

ā€Žtests/baselines/reference/circularResolvedSignature.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
2424
exports.Component = void 0;
2525
function Component() {
2626
var _a = useState(function () { return ({
27-
value: "string",
27+
value: "string", // this should be a number
2828
foo: function (arg) { return setState(arg); },
2929
bar: function (arg) { return setState(arg); },
3030
}); }), state = _a[0], setState = _a[1];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/commentsOnObjectLiteral5.ts] ////
2+
3+
//// [commentsOnObjectLiteral5.ts]
4+
const a = {
5+
p0: 0, // Comment 0
6+
p1: 0, /* Comment 1
7+
A multiline comment. */
8+
p2: 0, // Comment 2
9+
};
10+
11+
12+
//// [commentsOnObjectLiteral5.js]
13+
var a = {
14+
p0: 0, // Comment 0
15+
p1: 0, /* Comment 1
16+
A multiline comment. */
17+
p2: 0, // Comment 2
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/commentsOnObjectLiteral5.ts] ////
2+
3+
=== commentsOnObjectLiteral5.ts ===
4+
const a = {
5+
>a : Symbol(a, Decl(commentsOnObjectLiteral5.ts, 0, 5))
6+
7+
p0: 0, // Comment 0
8+
>p0 : Symbol(p0, Decl(commentsOnObjectLiteral5.ts, 0, 11))
9+
10+
p1: 0, /* Comment 1
11+
>p1 : Symbol(p1, Decl(commentsOnObjectLiteral5.ts, 1, 10))
12+
13+
A multiline comment. */
14+
p2: 0, // Comment 2
15+
>p2 : Symbol(p2, Decl(commentsOnObjectLiteral5.ts, 2, 10))
16+
17+
};
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/commentsOnObjectLiteral5.ts] ////
2+
3+
=== commentsOnObjectLiteral5.ts ===
4+
const a = {
5+
>a : { p0: number; p1: number; p2: number; }
6+
>{ p0: 0, // Comment 0 p1: 0, /* Comment 1 A multiline comment. */ p2: 0, // Comment 2} : { p0: number; p1: number; p2: number; }
7+
8+
p0: 0, // Comment 0
9+
>p0 : number
10+
>0 : 0
11+
12+
p1: 0, /* Comment 1
13+
>p1 : number
14+
>0 : 0
15+
16+
A multiline comment. */
17+
p2: 0, // Comment 2
18+
>p2 : number
19+
>0 : 0
20+
21+
};
22+

ā€Žtests/baselines/reference/divergentAccessorsTypes6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ var o1 = {
4949
};
5050
// A setter annotation still implies the getter return type.
5151
var o2 = {
52-
get p1() { return 0; },
52+
get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation
5353
set p1(value) { },
54-
get p2() { return 0; },
54+
get p2() { return 0; }, // ok - explicit annotation
5555
set p2(value) { },
5656
};
5757

0 commit comments

Comments
Ā (0)