Add a leading space on binary operator token trailing comments (#17691)

* Add a leading space on token trailing comments

* Demystify comment
This commit is contained in:
Wesley Wigham 2017-08-09 14:27:37 -07:00 committed by GitHub
parent f28f5fd041
commit a6f37f55e4
10 changed files with 22 additions and 22 deletions

View File

@ -1348,7 +1348,7 @@ namespace ts {
increaseIndentIf(indentBeforeOperator, isCommaOperator ? " " : undefined);
emitLeadingCommentsOfPosition(node.operatorToken.pos);
writeTokenNode(node.operatorToken);
emitTrailingCommentsOfPosition(node.operatorToken.end);
emitTrailingCommentsOfPosition(node.operatorToken.end, /*prefixSpace*/ true); // Binary operators should have a space before the comment starts
increaseIndentIf(indentAfterOperator, " ");
emitExpression(node.right);
decreaseIndentIf(indentBeforeOperator, indentAfterOperator);

View File

@ -21,5 +21,5 @@ var b = 'some'
+ 'text';
var c = 'some'
/* comment */
+/*comment1*/
+ /*comment1*/
'text';

View File

@ -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 +/*e3*/ b);
foo(/*c3*/ function () { }, /*d2*/ function () { }, /*e2*/ a + /*e3*/ b);
foo(/*c3*/ function () { }, /*d3*/ function () { }, /*e3*/ (a + b));
foo(
/*c4*/ function () { },

View File

@ -97,7 +97,7 @@ var a;
/** @type {string} */
var s;
var a = ("" + 4);
var s = "" +/** @type {*} */ (4);
var s = "" + /** @type {*} */ (4);
var SomeBase = (function () {
function SomeBase() {
this.p = 42;
@ -128,19 +128,19 @@ var someBase = new SomeBase();
var someDerived = new SomeDerived();
var someOther = new SomeOther();
var someFakeClass = new SomeFakeClass();
someBase =/** @type {SomeBase} */ (someDerived);
someBase =/** @type {SomeBase} */ (someBase);
someBase =/** @type {SomeBase} */ (someOther); // Error
someDerived =/** @type {SomeDerived} */ (someDerived);
someDerived =/** @type {SomeDerived} */ (someBase);
someDerived =/** @type {SomeDerived} */ (someOther); // Error
someOther =/** @type {SomeOther} */ (someDerived); // Error
someOther =/** @type {SomeOther} */ (someBase); // Error
someOther =/** @type {SomeOther} */ (someOther);
someBase = /** @type {SomeBase} */ (someDerived);
someBase = /** @type {SomeBase} */ (someBase);
someBase = /** @type {SomeBase} */ (someOther); // Error
someDerived = /** @type {SomeDerived} */ (someDerived);
someDerived = /** @type {SomeDerived} */ (someBase);
someDerived = /** @type {SomeDerived} */ (someOther); // Error
someOther = /** @type {SomeOther} */ (someDerived); // Error
someOther = /** @type {SomeOther} */ (someBase); // Error
someOther = /** @type {SomeOther} */ (someOther);
someFakeClass = someBase;
someFakeClass = someDerived;
someBase = someFakeClass; // Error
someBase =/** @type {SomeBase} */ (someFakeClass);
someBase = /** @type {SomeBase} */ (someFakeClass);
// Type assertion cannot be a type-predicate type
/** @type {number | string} */
var numOrStr;

View File

@ -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[14]=_float===-(4/3)
a.indexOf(0) === 7 &&// a[7] = +0, 0===+0
a.indexOf(-0) === 7 &&// a[7] = +0, -0===+0
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;
}

View File

@ -7,5 +7,5 @@
//// [parserGreaterThanTokenAmbiguity10.js]
1
// before
>>>// after
>>> // after
2;

View File

@ -7,5 +7,5 @@
//// [parserGreaterThanTokenAmbiguity15.js]
1
// before
>>=// after
>>= // after
2;

View File

@ -7,5 +7,5 @@
//// [parserGreaterThanTokenAmbiguity20.js]
1
// Before
>>>=// after
>>>= // after
2;

View File

@ -7,5 +7,5 @@
//// [parserGreaterThanTokenAmbiguity5.js]
1
// before
>>// after
>> // after
2;

View File

@ -138,7 +138,7 @@ function foo8(x) {
var b;
return typeof x === "string"
? x === "hello"
: ((b = x) &&// number | boolean
: ((b = x) && // number | boolean
(typeof x === "boolean"
? x // boolean
: x == 10)); // boolean