[Master] fix 12985 emit leading and trailing comment around binary operator (#16584)
* Emit leading and trailing on binary operator * Add tests and baselines * Update baselines
This commit is contained in:
parent
8f7a582fc5
commit
d7fff8ebe9
|
@ -1346,7 +1346,9 @@ namespace ts {
|
|||
|
||||
emitExpression(node.left);
|
||||
increaseIndentIf(indentBeforeOperator, isCommaOperator ? " " : undefined);
|
||||
emitLeadingCommentsOfPosition(node.operatorToken.pos);
|
||||
writeTokenNode(node.operatorToken);
|
||||
emitTrailingCommentsOfPosition(node.operatorToken.end);
|
||||
increaseIndentIf(indentAfterOperator, " ");
|
||||
emitExpression(node.right);
|
||||
decreaseIndentIf(indentBeforeOperator, indentAfterOperator);
|
||||
|
|
25
tests/baselines/reference/commentOnBinaryOperator1.js
Normal file
25
tests/baselines/reference/commentOnBinaryOperator1.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
//// [commentOnBinaryOperator1.ts]
|
||||
var a = 'some'
|
||||
// comment
|
||||
+ 'text';
|
||||
|
||||
var b = 'some'
|
||||
/* comment */
|
||||
+ 'text';
|
||||
|
||||
var c = 'some'
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
||||
|
||||
//// [commentOnBinaryOperator1.js]
|
||||
var a = 'some'
|
||||
// comment
|
||||
+ 'text';
|
||||
var b = 'some'
|
||||
/* comment */
|
||||
+ 'text';
|
||||
var c = 'some'
|
||||
/* comment */
|
||||
+/*comment1*/
|
||||
'text';
|
19
tests/baselines/reference/commentOnBinaryOperator1.symbols
Normal file
19
tests/baselines/reference/commentOnBinaryOperator1.symbols
Normal file
|
@ -0,0 +1,19 @@
|
|||
=== tests/cases/compiler/commentOnBinaryOperator1.ts ===
|
||||
var a = 'some'
|
||||
>a : Symbol(a, Decl(commentOnBinaryOperator1.ts, 0, 3))
|
||||
|
||||
// comment
|
||||
+ 'text';
|
||||
|
||||
var b = 'some'
|
||||
>b : Symbol(b, Decl(commentOnBinaryOperator1.ts, 4, 3))
|
||||
|
||||
/* comment */
|
||||
+ 'text';
|
||||
|
||||
var c = 'some'
|
||||
>c : Symbol(c, Decl(commentOnBinaryOperator1.ts, 8, 3))
|
||||
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
29
tests/baselines/reference/commentOnBinaryOperator1.types
Normal file
29
tests/baselines/reference/commentOnBinaryOperator1.types
Normal file
|
@ -0,0 +1,29 @@
|
|||
=== tests/cases/compiler/commentOnBinaryOperator1.ts ===
|
||||
var a = 'some'
|
||||
>a : string
|
||||
>'some' // comment + 'text' : string
|
||||
>'some' : "some"
|
||||
|
||||
// comment
|
||||
+ 'text';
|
||||
>'text' : "text"
|
||||
|
||||
var b = 'some'
|
||||
>b : string
|
||||
>'some' /* comment */ + 'text' : string
|
||||
>'some' : "some"
|
||||
|
||||
/* comment */
|
||||
+ 'text';
|
||||
>'text' : "text"
|
||||
|
||||
var c = 'some'
|
||||
>c : string
|
||||
>'some' /* comment */ + /*comment1*/ 'text' : string
|
||||
>'some' : "some"
|
||||
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
||||
>'text' : "text"
|
||||
|
22
tests/baselines/reference/commentOnBinaryOperator2.js
Normal file
22
tests/baselines/reference/commentOnBinaryOperator2.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
//// [commentOnBinaryOperator2.ts]
|
||||
var a = 'some'
|
||||
// comment
|
||||
+ 'text';
|
||||
|
||||
var b = 'some'
|
||||
/* comment */
|
||||
+ 'text';
|
||||
|
||||
var c = 'some'
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
||||
|
||||
//// [commentOnBinaryOperator2.js]
|
||||
var a = 'some'
|
||||
+ 'text';
|
||||
var b = 'some'
|
||||
+ 'text';
|
||||
var c = 'some'
|
||||
+
|
||||
'text';
|
19
tests/baselines/reference/commentOnBinaryOperator2.symbols
Normal file
19
tests/baselines/reference/commentOnBinaryOperator2.symbols
Normal file
|
@ -0,0 +1,19 @@
|
|||
=== tests/cases/compiler/commentOnBinaryOperator2.ts ===
|
||||
var a = 'some'
|
||||
>a : Symbol(a, Decl(commentOnBinaryOperator2.ts, 0, 3))
|
||||
|
||||
// comment
|
||||
+ 'text';
|
||||
|
||||
var b = 'some'
|
||||
>b : Symbol(b, Decl(commentOnBinaryOperator2.ts, 4, 3))
|
||||
|
||||
/* comment */
|
||||
+ 'text';
|
||||
|
||||
var c = 'some'
|
||||
>c : Symbol(c, Decl(commentOnBinaryOperator2.ts, 8, 3))
|
||||
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
29
tests/baselines/reference/commentOnBinaryOperator2.types
Normal file
29
tests/baselines/reference/commentOnBinaryOperator2.types
Normal file
|
@ -0,0 +1,29 @@
|
|||
=== tests/cases/compiler/commentOnBinaryOperator2.ts ===
|
||||
var a = 'some'
|
||||
>a : string
|
||||
>'some' // comment + 'text' : string
|
||||
>'some' : "some"
|
||||
|
||||
// comment
|
||||
+ 'text';
|
||||
>'text' : "text"
|
||||
|
||||
var b = 'some'
|
||||
>b : string
|
||||
>'some' /* comment */ + 'text' : string
|
||||
>'some' : "some"
|
||||
|
||||
/* comment */
|
||||
+ 'text';
|
||||
>'text' : "text"
|
||||
|
||||
var c = 'some'
|
||||
>c : string
|
||||
>'some' /* comment */ + /*comment1*/ 'text' : string
|
||||
>'some' : "some"
|
||||
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
||||
>'text' : "text"
|
||||
|
|
@ -14,7 +14,7 @@ foo(
|
|||
function foo(/*c1*/ x, /*d1*/ y, /*e1*/ w) { }
|
||||
var a, b;
|
||||
foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
|
||||
foo(/*c3*/ function () { }, /*d2*/ function () { }, /*e2*/ a + b);
|
||||
foo(/*c3*/ function () { }, /*d2*/ function () { }, /*e2*/ a +/*e3*/ b);
|
||||
foo(/*c3*/ function () { }, /*d3*/ function () { }, /*e3*/ (a + b));
|
||||
foo(
|
||||
/*c4*/ function () { },
|
||||
|
|
|
@ -41,9 +41,9 @@ function testcase() {
|
|||
var one = 1;
|
||||
var _float = -(4 / 3);
|
||||
var a = new Array(false, undefined, null, "0", obj, -1.3333333333333, "str", -0, true, +0, one, 1, 0, false, _float, -(4 / 3));
|
||||
if (a.indexOf(-(4 / 3)) === 14 &&
|
||||
a.indexOf(0) === 7 &&
|
||||
a.indexOf(-0) === 7 &&
|
||||
if (a.indexOf(-(4 / 3)) === 14 &&// a[14]=_float===-(4/3)
|
||||
a.indexOf(0) === 7 &&// a[7] = +0, 0===+0
|
||||
a.indexOf(-0) === 7 &&// a[7] = +0, -0===+0
|
||||
a.indexOf(1) === 10) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
//// [parserGreaterThanTokenAmbiguity10.js]
|
||||
1
|
||||
>>>
|
||||
// before
|
||||
>>>// after
|
||||
2;
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
//// [parserGreaterThanTokenAmbiguity15.js]
|
||||
1
|
||||
>>=
|
||||
// before
|
||||
>>=// after
|
||||
2;
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
//// [parserGreaterThanTokenAmbiguity20.js]
|
||||
1
|
||||
>>>=
|
||||
// Before
|
||||
>>>=// after
|
||||
2;
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
//// [parserGreaterThanTokenAmbiguity5.js]
|
||||
1
|
||||
>>
|
||||
// before
|
||||
>>// after
|
||||
2;
|
||||
|
|
|
@ -138,7 +138,7 @@ function foo8(x) {
|
|||
var b;
|
||||
return typeof x === "string"
|
||||
? x === "hello"
|
||||
: ((b = x) &&
|
||||
: ((b = x) &&// number | boolean
|
||||
(typeof x === "boolean"
|
||||
? x // boolean
|
||||
: x == 10)); // boolean
|
||||
|
|
12
tests/cases/compiler/commentOnBinaryOperator1.ts
Normal file
12
tests/cases/compiler/commentOnBinaryOperator1.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
var a = 'some'
|
||||
// comment
|
||||
+ 'text';
|
||||
|
||||
var b = 'some'
|
||||
/* comment */
|
||||
+ 'text';
|
||||
|
||||
var c = 'some'
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
13
tests/cases/compiler/commentOnBinaryOperator2.ts
Normal file
13
tests/cases/compiler/commentOnBinaryOperator2.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
// @removeComments: true
|
||||
var a = 'some'
|
||||
// comment
|
||||
+ 'text';
|
||||
|
||||
var b = 'some'
|
||||
/* comment */
|
||||
+ 'text';
|
||||
|
||||
var c = 'some'
|
||||
/* comment */
|
||||
+ /*comment1*/
|
||||
'text';
|
Loading…
Reference in a new issue