Merge pull request #572 from Microsoft/commentFormatting

Fix the tab and indent calculation when formatting comments in the emitted output
This commit is contained in:
Sheetal Nandi 2014-09-02 21:24:34 -07:00
commit 2f7429e887
6 changed files with 94 additions and 7 deletions

View file

@ -296,11 +296,10 @@ module ts {
function calculateIndent(pos: number, end: number) {
var currentLineIndent = 0;
while (pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos))) {
pos++;
for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) {
// Tabs = size of the indent
currentLineIndent += getIndentSize();
// Tabs = TabSize = indent size and go to next tabStop
currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
}
else {
// Single space

View file

@ -67,6 +67,23 @@ this is 4 spaces left aligned but above line is empty
above 3 lines are empty*/
export class c3 {
}
/** this is first line - aligned to class declaration
* this is 0 space + tab
* this is 1 space + tab
* this is 2 spaces + tab
* this is 3 spaces + tab
* this is 4 spaces + tab
* this is 5 spaces + tab
* this is 6 spaces + tab
* this is 7 spaces + tab
* this is 8 spaces + tab
* this is 9 spaces + tab
* this is 10 spaces + tab
* this is 11 spaces + tab
* this is 12 spaces + tab */
export class c4 {
}
}
//// [commentsFormatting.js]
@ -148,6 +165,26 @@ this is 4 spaces left aligned but above line is empty
return c3;
})();
m.c3 = c3;
/** this is first line - aligned to class declaration
* this is 0 space + tab
* this is 1 space + tab
* this is 2 spaces + tab
* this is 3 spaces + tab
* this is 4 spaces + tab
* this is 5 spaces + tab
* this is 6 spaces + tab
* this is 7 spaces + tab
* this is 8 spaces + tab
* this is 9 spaces + tab
* this is 10 spaces + tab
* this is 11 spaces + tab
* this is 12 spaces + tab */
var c4 = (function () {
function c4() {
}
return c4;
})();
m.c4 = c4;
})(m || (m = {}));
@ -217,4 +254,20 @@ this is 4 spaces left aligned but above line is empty
above 3 lines are empty*/
class c3 {
}
/** this is first line - aligned to class declaration
* this is 0 space + tab
* this is 1 space + tab
* this is 2 spaces + tab
* this is 3 spaces + tab
* this is 4 spaces + tab
* this is 5 spaces + tab
* this is 6 spaces + tab
* this is 7 spaces + tab
* this is 8 spaces + tab
* this is 9 spaces + tab
* this is 10 spaces + tab
* this is 11 spaces + tab
* this is 12 spaces + tab */
class c4 {
}
}

View file

@ -72,4 +72,22 @@ this is 4 spaces left aligned but above line is empty
export class c3 {
>c3 : c3
}
/** this is first line - aligned to class declaration
* this is 0 space + tab
* this is 1 space + tab
* this is 2 spaces + tab
* this is 3 spaces + tab
* this is 4 spaces + tab
* this is 5 spaces + tab
* this is 6 spaces + tab
* this is 7 spaces + tab
* this is 8 spaces + tab
* this is 9 spaces + tab
* this is 10 spaces + tab
* this is 11 spaces + tab
* this is 12 spaces + tab */
export class c4 {
>c4 : c4
}
}

View file

@ -55,9 +55,9 @@ foo(a); // shouldn't error
class C {
public e: E;
public e: E;
public m(): E { return this.e; } // shouldn't error
public m(): E { return this.e; } // shouldn't error
}

View file

@ -23,7 +23,7 @@ map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U
}
interface String{
length: number;
length: number;
}
*/
var lengths = ["a", "b", "c"].map(function (x) { return x.length; });

View file

@ -69,4 +69,21 @@ this is 4 spaces left aligned but above line is empty
above 3 lines are empty*/
export class c3 {
}
/** this is first line - aligned to class declaration
* this is 0 space + tab
* this is 1 space + tab
* this is 2 spaces + tab
* this is 3 spaces + tab
* this is 4 spaces + tab
* this is 5 spaces + tab
* this is 6 spaces + tab
* this is 7 spaces + tab
* this is 8 spaces + tab
* this is 9 spaces + tab
* this is 10 spaces + tab
* this is 11 spaces + tab
* this is 12 spaces + tab */
export class c4 {
}
}