Align the multiline comments in the generated outputs by retaining its position relative to the first line in the comment

This commit is contained in:
Sheetal Nandi 2014-08-14 14:43:28 -07:00
parent 0caa1f6dc7
commit e76d8f36b6
37 changed files with 650 additions and 209 deletions

View File

@ -10,12 +10,18 @@ module ts {
getLine(): number;
getColumn(): number;
getIndent(): number;
isLineStart(): boolean;
}
var indentStrings: string[] = [];
var indentStrings: string[] = ["", " "];
function getIndentString(level: number) {
return indentStrings[level] || (indentStrings[level] = level === 0 ? "" : getIndentString(level - 1) + " ");
if (indentStrings[level] === undefined) {
indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
}
return indentStrings[level];
}
function getIndentSize() {
return indentStrings[1].length;
}
export function emitFiles(resolver: EmitResolver): EmitResult {
@ -148,7 +154,6 @@ module ts {
getLine: () => lineCount + 1,
getColumn: () => lineStart ? indent * 4 + 1 : output.length - linePos + 1,
getText: () => output,
isLineStart: () => lineStart
};
}
@ -179,7 +184,137 @@ module ts {
}
function writeCommentRange(comment: Comment, writer: EmitTextWriter) {
writer.writeLiteral(currentSourceFile.text.substring(comment.pos, comment.end));
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
var firstCommentLineIndent: number;
var writeNewLine: boolean;
for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1);
if (pos !== comment.pos) {
// If we are not emitting first line, we need to adjust the indent
if (writeNewLine) {
writer.writeLine();
}
if (firstCommentLineIndent === undefined) {
firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, /*character*/1),
comment.pos);
}
var deltaIndent = calculateIndent(pos, nextLineStart) - firstCommentLineIndent;
if (deltaIndent < 0) {
// we need to decrease indent to get the desired effect
// Comment is left indented to first line
// eg
// module m {
// /* this is line 1
// * line
// More left indented comment */
// class c { }
// }
// Spaces to emit = indentSize - (numberof spaces in lastDeltaIndent) (in above eg (4 - 5%4) = 3)
var spacesToEmit = (deltaIndent % getIndentSize()); // This is negative of spaces to emit = -1 in above case
if (spacesToEmit) {
spacesToEmit += getIndentSize(); // Adjust the delta with the indentSize (4 - 1) = 3
}
// Change in delta indent = deltaIndent / indentSize, we will change the delta to upper integer value
// In above eg. 5/4 = 1.75 so change the indent two times
var changeInIndent = (-deltaIndent / getIndentSize());
// If we cant go back as much as we want to, go to left most position
if (changeInIndent > writer.getIndent()) {
changeInIndent = writer.getIndent();
spacesToEmit = 0;
}
// Decrease the chaneInIndent number of times
for (var i = 0; i < changeInIndent; i++) {
writer.decreaseIndent();
}
// Emit either delta spaces or indentSizeSpaces
emitSpaces(spacesToEmit, writeNewLine);
// Write the comment line text
writeNewLine = writeTrimmedCurrentLine(pos, nextLineStart);
// Revert the indent
for (var i = 0; i < changeInIndent; i++) {
writer.increaseIndent();
}
} else {
// Comment is right indented to first line
// eg
// module m {
// /* this is line 1
// * line
// More right indented comment */
// class c { }
// }
// In above eg for line 2 in the comment, the delta is single space and hence emit that and emit the trimmed line
// but the third line has delta of 7 spaces and hence emit those spaces before emitting the trimmed line
emitSpaces(deltaIndent, writeNewLine);
writeNewLine = writeTrimmedCurrentLine(pos, nextLineStart);
}
}
else {
// First comment line, emit as it is
writeNewLine = writeTrimmedCurrentLine(pos, nextLineStart);
}
pos = nextLineStart;
}
}
else {
// Single line comment of styly //....
writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
}
function emitSpaces(count: number, writeNewLine: boolean) {
if (!writeNewLine) {
// If we didnot use WriteLine but instead used writeLiteral to writeNewLine, then we need to make sure we emit indent correctly
writer.write(getIndentString(writer.getIndent()));
}
// Write spaces
while (count) {
writer.write(" ");
count--;
}
}
// Returns true if writer should write new line before emitting next line of comment
function writeTrimmedCurrentLine(pos: number, nextLineStart: number) {
var currentLineText = currentSourceFile.text.substring(pos, Math.min(comment.end, nextLineStart - 1)).replace(/^\s+|\s+$/g, '');
if (currentLineText) {
// trimmed forward and ending spaces text
writer.write(currentLineText);
return true;
}
else {
// Empty string - make sure we write empty line
writer.writeLiteral(sys.newLine);
}
}
function calculateIndent(pos: number, end: number) {
var currentLineIndent = 0;
while (pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos))) {
pos++;
if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) {
// Tabs = size of the indent
currentLineIndent += getIndentSize();
}
else {
// Single space
currentLineIndent++;
}
}
return currentLineIndent;
}
}
function emitJavaScript(jsFilePath: string, root?: SourceFile) {

View File

@ -575,6 +575,13 @@ module ts {
return getLineAndCharacterOfPosition(lineStarts, position);
}
function getPositionFromSourceLineAndCharacter(line: number, character: number): number {
if (!lineStarts) {
lineStarts = getLineStarts(sourceText);
}
return getPositionFromLineAndCharacter(lineStarts, line, character);
}
function error(message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var start = scanner.getTokenPos();
var length = scanner.getTextPos() - start;
@ -3575,6 +3582,7 @@ module ts {
file.filename = normalizePath(filename);
file.text = sourceText;
file.getLineAndCharacterFromPosition = getLineAndCharacterlFromSourcePosition;
file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
file.syntacticErrors = [];
file.semanticErrors = [];
var referenceComments = processReferenceComments();

View File

@ -264,6 +264,10 @@ module ts {
return result;
}
export function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number {
return lineStarts[line - 1] + character - 1;
}
export function getLineAndCharacterOfPosition(lineStarts: number[], position: number) {
var lineNumber = binarySearch(lineStarts, position);
if (lineNumber < 0) {
@ -286,13 +290,13 @@ module ts {
var hasOwnProperty = Object.prototype.hasOwnProperty;
function isWhiteSpace(ch: number): boolean {
export function isWhiteSpace(ch: number): boolean {
return ch === CharacterCodes.space || ch === CharacterCodes.tab || ch === CharacterCodes.verticalTab || ch === CharacterCodes.formFeed ||
ch === CharacterCodes.nonBreakingSpace || ch === CharacterCodes.ogham || ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace ||
ch === CharacterCodes.narrowNoBreakSpace || ch === CharacterCodes.mathematicalSpace || ch === CharacterCodes.ideographicSpace || ch === CharacterCodes.byteOrderMark;
}
function isLineBreak(ch: number): boolean {
export function isLineBreak(ch: number): boolean {
return ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn || ch === CharacterCodes.lineSeparator || ch === CharacterCodes.paragraphSeparator;
}

View File

@ -520,6 +520,7 @@ module ts {
filename: string;
text: string;
getLineAndCharacterFromPosition(position: number): { line: number; character: number };
getPositionFromLineAndCharacter(line: number, character: number): number;
amdDependencies: string[];
referencedFiles: FileReference[];
syntacticErrors: Diagnostic[];

View File

@ -310,6 +310,7 @@ module ts {
public filename: string;
public text: string;
public getLineAndCharacterFromPosition(position: number): { line: number; character: number } { return null; }
public getPositionFromLineAndCharacter(line: number, character: number): number { return -1; }
public amdDependencies: string[];
public referencedFiles: FileReference[];
public syntacticErrors: Diagnostic[];

View File

@ -121,16 +121,16 @@ var C3 = (function () {
};
return C3;
})();
/*
This behaves unexpectedly with the following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
/*
This behaves unexpectedly with the following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
*/
var a1 = null;
var c1 = new C1();

View File

@ -95,16 +95,16 @@ var C3 = (function () {
};
return C3;
})();
/*
This behaves unexpectedly with the following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
/*
This behaves unexpectedly with the following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
*/
var a1 = null;
var c1 = new C1();

View File

@ -35,16 +35,16 @@ var C3 = (function () {
};
return C3;
})();
/*
This behaves unexpectedly with teh following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
/*
This behaves unexpectedly with teh following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
*/
var c3 = new C3();
var o1 = { one: 1 };

View File

@ -12,9 +12,9 @@ class C {
var C = (function () {
function C() {
}
/**
* Returns bar
*/
/**
* Returns bar
*/
C.foo = function () {
return "bar";
};

View File

@ -11,8 +11,8 @@ class WebControls {
var WebControls = (function () {
function WebControls() {
}
/**
* Render a control
/**
* Render a control
*/
WebControls.prototype.createControl = function () {
};

View File

@ -117,10 +117,10 @@ var c7 = (function () {
})();
var i7 = new c7();
var i7_c = c7;
/** class with statics and constructor
/** class with statics and constructor
*/
var c8 = (function () {
/** constructor comment
/** constructor comment
*/
function c8() {
}
@ -167,12 +167,12 @@ declare class c7 {
}
declare var i7: c7;
declare var i7_c: typeof c7;
/** class with statics and constructor
/** class with statics and constructor
*/
declare class c8 {
/** s1 comment */
static s1: number;
/** constructor comment
/** constructor comment
*/
constructor();
}

View File

@ -393,13 +393,13 @@ var c1 = (function () {
return c1.b_s1 + b;
};
Object.defineProperty(c1, "b_s3", {
/** static getter property
*/
/** static getter property
*/
get: function () {
return c1.s2(c1.s1);
},
/** setter property
*/
/** setter property
*/
set: function (value) {
c1.b_s1 = c1.b_s2(value);
},
@ -532,9 +532,9 @@ declare class c1 {
static b_s1: number;
/** static sum with property */
static b_s2(b: number): number;
/** static getter property
/** static getter property
*/
/** setter property
/** setter property
*/
static b_s3: number;
}

View File

@ -169,16 +169,16 @@ multiLine();
function jsDocSingleLine() {
}
jsDocSingleLine();
/** this is multiple line jsdoc stule comment
*New line1
/** this is multiple line jsdoc stule comment
*New line1
*New Line2*/
function jsDocMultiLine() {
}
jsDocMultiLine();
/** this is multiple line jsdoc stule comment
*New line1
/** this is multiple line jsdoc stule comment
*New line1
*New Line2*/
/** Shoul mege this line as well
/** Shoul mege this line as well
* and this too*/ /** Another this one too*/
function jsDocMultiLineMerge() {
}
@ -230,9 +230,9 @@ noHelpComment2();
function noHelpComment3() {
}
noHelpComment3();
/** Adds two integers and returns the result
* @param {number} a first number
* @param b second number
/** Adds two integers and returns the result
* @param {number} a first number
* @param b second number
*/
function sum(a, b) {
return a + b;
@ -242,7 +242,7 @@ sum(10, 20);
/** @param */
/** @param a first number*/
/** @param b */
/** @param c {
/** @param c {
@param d @anotherTag*/
/** @param e LastParam @anotherTag*/
function multiply(a, b, c, d, e) {
@ -251,34 +251,34 @@ function multiply(a, b, c, d, e) {
function f1(aOrb, opt) {
return aOrb;
}
/** This is subtract function
@param { a
*@param { number | } b this is about b
@param { { () => string; } } c this is optional param c
@param { { () => string; } d this is optional param d
@param { { () => string; } } e this is optional param e
@param { { { () => string; } } f this is optional param f
/** This is subtract function
@param { a
*@param { number | } b this is about b
@param { { () => string; } } c this is optional param c
@param { { () => string; } d this is optional param d
@param { { () => string; } } e this is optional param e
@param { { { () => string; } } f this is optional param f
*/
function subtract(a, b, c, d, e, f) {
}
/** this is square function
@paramTag { number } a this is input number of paramTag
@param { number } a this is input number
@returnType { number } it is return type
/** this is square function
@paramTag { number } a this is input number of paramTag
@param { number } a this is input number
@returnType { number } it is return type
*/
function square(a) {
return a * a;
}
/** this is divide function
@param { number} a this is a
@paramTag { number } g this is optional param g
@param { number} b this is b
/** this is divide function
@param { number} a this is a
@paramTag { number } g this is optional param g
@param { number} b this is b
*/
function divide(a, b) {
}
/** this is jsdoc style function with param tag as well as inline parameter help
*@param a it is first parameter
*@param c it is third parameter
/** this is jsdoc style function with param tag as well as inline parameter help
*@param a it is first parameter
*@param c it is third parameter
*/
function jsDocParamTest(a, b, c, d) {
return a + b + c + d;
@ -296,14 +296,14 @@ declare function simple(): void;
declare function multiLine(): void;
/** this is eg of single line jsdoc style comment */
declare function jsDocSingleLine(): void;
/** this is multiple line jsdoc stule comment
*New line1
/** this is multiple line jsdoc stule comment
*New line1
*New Line2*/
declare function jsDocMultiLine(): void;
/** this is multiple line jsdoc stule comment
*New line1
/** this is multiple line jsdoc stule comment
*New line1
*New Line2*/
/** Shoul mege this line as well
/** Shoul mege this line as well
* and this too*/ /** Another this one too*/
declare function jsDocMultiLineMerge(): void;
/** jsdoc comment */
@ -322,48 +322,48 @@ declare function jsDocMixedComments6(): void;
declare function noHelpComment1(): void;
declare function noHelpComment2(): void;
declare function noHelpComment3(): void;
/** Adds two integers and returns the result
* @param {number} a first number
* @param b second number
/** Adds two integers and returns the result
* @param {number} a first number
* @param b second number
*/
declare function sum(a: number, b: number): number;
/** This is multiplication function*/
/** @param */
/** @param a first number*/
/** @param b */
/** @param c {
/** @param c {
@param d @anotherTag*/
/** @param e LastParam @anotherTag*/
declare function multiply(a: number, b: number, c?: number, d?: any, e?: any): void;
/** fn f1 with number
* @param { string} b about b
/** fn f1 with number
* @param { string} b about b
*/
declare function f1(a: number): any;
declare function f1(b: string): any;
/** This is subtract function
@param { a
*@param { number | } b this is about b
@param { { () => string; } } c this is optional param c
@param { { () => string; } d this is optional param d
@param { { () => string; } } e this is optional param e
@param { { { () => string; } } f this is optional param f
/** This is subtract function
@param { a
*@param { number | } b this is about b
@param { { () => string; } } c this is optional param c
@param { { () => string; } d this is optional param d
@param { { () => string; } } e this is optional param e
@param { { { () => string; } } f this is optional param f
*/
declare function subtract(a: number, b: number, c?: () => string, d?: () => string, e?: () => string, f?: () => string): void;
/** this is square function
@paramTag { number } a this is input number of paramTag
@param { number } a this is input number
@returnType { number } it is return type
/** this is square function
@paramTag { number } a this is input number of paramTag
@param { number } a this is input number
@returnType { number } it is return type
*/
declare function square(a: number): number;
/** this is divide function
@param { number} a this is a
@paramTag { number } g this is optional param g
@param { number} b this is b
/** this is divide function
@param { number} a this is a
@paramTag { number } g this is optional param g
@param { number} b this is b
*/
declare function divide(a: number, b: number): void;
/** this is jsdoc style function with param tag as well as inline parameter help
*@param a it is first parameter
*@param c it is third parameter
/** this is jsdoc style function with param tag as well as inline parameter help
*@param a it is first parameter
*@param c it is third parameter
*/
declare function jsDocParamTest(/** this is inline comment for a */ a: number, /** this is inline comment for b*/ b: number, c: number, d: number): number;
declare class NoQuickInfoClass {

View File

@ -98,13 +98,13 @@ define(["require", "exports"], function (require, exports) {
(function (m4) {
/** b's comment */
m4.b;
/** foo's comment
*/
/** foo's comment
*/
function foo() {
return m4.b;
}
/** m2 comments
*/
/** m2 comments
*/
(function (m2) {
/** class comment; */
var c = (function () {
@ -157,7 +157,7 @@ export declare module m1 {
export declare module m4 {
/** b's comment */
var b: number;
/** m2 comments
/** m2 comments
*/
module m2 {
/** class comment; */

View File

@ -98,13 +98,13 @@ define(["require", "exports"], function (require, exports) {
(function (m4) {
/** b's comment */
m4.b;
/** foo's comment
*/
/** foo's comment
*/
function foo() {
return m4.b;
}
/** m2 comments
*/
/** m2 comments
*/
(function (m2) {
/** class comment; */
var c = (function () {
@ -157,7 +157,7 @@ export declare module m1 {
export declare module m4 {
/** b's comment */
var b: number;
/** m2 comments
/** m2 comments
*/
module m2 {
/** class comment; */

View File

@ -0,0 +1,220 @@
//// [commentsFormatting.ts]
module m {
/** this is first line - aligned to class declaration
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
export class c {
}
/** this is first line - 4 spaces right aligned to class but in js file should be aligned to class declaration
* this is 8 spaces left aligned
* this is 7 spaces left aligned
* this is 6 spaces left aligned
* this is 5 spaces left aligned
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
export class c2 {
}
/** this is comment with new lines in between
this is 4 spaces left aligned but above line is empty
this is 3 spaces left aligned but above line is empty
this is 2 spaces left aligned but above line is empty
this is 1 spaces left aligned but above line is empty
this is at same level as first line but above line is empty
this is 1 spaces right aligned but above line is empty
this is 2 spaces right aligned but above line is empty
this is 3 spaces right aligned but above line is empty
this is 4 spaces right aligned but above line is empty
Above 2 lines are empty
above 3 lines are empty*/
export class c3 {
}
}
//// [commentsFormatting.js]
var m;
(function (m) {
/** this is first line - aligned to class declaration
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
var c = (function () {
function c() {
}
return c;
})();
m.c = c;
/** this is first line - 4 spaces right aligned to class but in js file should be aligned to class declaration
* this is 8 spaces left aligned
* this is 7 spaces left aligned
* this is 6 spaces left aligned
* this is 5 spaces left aligned
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
var c2 = (function () {
function c2() {
}
return c2;
})();
m.c2 = c2;
/** this is comment with new lines in between
this is 4 spaces left aligned but above line is empty
this is 3 spaces left aligned but above line is empty
this is 2 spaces left aligned but above line is empty
this is 1 spaces left aligned but above line is empty
this is at same level as first line but above line is empty
this is 1 spaces right aligned but above line is empty
this is 2 spaces right aligned but above line is empty
this is 3 spaces right aligned but above line is empty
this is 4 spaces right aligned but above line is empty
Above 2 lines are empty
above 3 lines are empty*/
var c3 = (function () {
function c3() {
}
return c3;
})();
m.c3 = c3;
})(m || (m = {}));
//// [commentsFormatting.d.ts]
declare module m {
/** this is first line - aligned to class declaration
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
class c {
}
/** this is first line - 4 spaces right aligned to class but in js file should be aligned to class declaration
* this is 8 spaces left aligned
* this is 7 spaces left aligned
* this is 6 spaces left aligned
* this is 5 spaces left aligned
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
class c2 {
}
/** this is comment with new lines in between
this is 4 spaces left aligned but above line is empty
this is 3 spaces left aligned but above line is empty
this is 2 spaces left aligned but above line is empty
this is 1 spaces left aligned but above line is empty
this is at same level as first line but above line is empty
this is 1 spaces right aligned but above line is empty
this is 2 spaces right aligned but above line is empty
this is 3 spaces right aligned but above line is empty
this is 4 spaces right aligned but above line is empty
Above 2 lines are empty
above 3 lines are empty*/
class c3 {
}
}

View File

@ -35,8 +35,8 @@ function fooWithParameters(a, /** this is comment for b*/
var d = a;
}
fooWithParameters("a", 10);
/** fooFunc
* comment
/** fooFunc
* comment
*/
var fooFunc = function FooFunctionValue(b) {
return b;
@ -54,8 +54,8 @@ declare function foo(): void;
/** This is comment for function signature*/
declare function fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/
b: number): void;
/** fooFunc
* comment
/** fooFunc
* comment
*/
declare var fooFunc: (b: string) => string;
declare var lambdaFoo: (a: number, b: number) => number;

View File

@ -370,8 +370,8 @@ interface i2 {
interface i3 extends i2 {
/** i3 p1 */
p1: number;
/**
* i3 f1
/**
* i3 f1
*/
f1(): void;
/** i3 l1*/

View File

@ -130,14 +130,14 @@ var m1;
function foo2Export(a) {
}
m1.foo2Export = foo2Export;
/** foo3Export
* comment
/** foo3Export
* comment
*/
function foo3Export() {
}
m1.foo3Export = foo3Export;
/** foo4Export
* comment
/** foo4Export
* comment
*/
function foo4Export() {
}
@ -286,8 +286,8 @@ declare module m1 {
/** exported function*/
function fooExport(): number;
function foo2Export(/**hm*/ a: string): void;
/** foo3Export
* comment
/** foo3Export
* comment
*/
function foo3Export(): void;
}

View File

@ -14,11 +14,11 @@ var Person = makeClass(
//// [commentsOnObjectLiteral2.js]
var Person = makeClass({
/**
This is just another way to define a constructor.
@constructs
@param {string} name The name of the person.
*/
/**
This is just another way to define a constructor.
@constructs
@param {string} name The name of the person.
*/
initialize: function (name) {
this.name = name;
}

View File

@ -24,12 +24,12 @@ class test {
var test = (function () {
function test() {
}
/**
* p1 comment appears in output
/**
* p1 comment appears in output
*/
test.p1 = "";
/**
* p3 comment appears in output
/**
* p3 comment appears in output
*/
test.p3 = "";
return test;

View File

@ -50,7 +50,7 @@ var myVariable = 10;
var anotherVariable = 30;
// shouldn't appear
var aVar = "";
/** this is multiline comment
/** this is multiline comment
* All these variables are of number type */
var anotherAnotherVariable = 70;
/** Triple slash multiline comment*/
@ -79,7 +79,7 @@ declare var myVariable: number;
/** This is another variable comment*/
declare var anotherVariable: number;
declare var aVar: string;
/** this is multiline comment
/** this is multiline comment
* All these variables are of number type */
declare var anotherAnotherVariable: number;
/** Triple slash multiline comment*/

View File

@ -34,11 +34,11 @@ c = c.m(cc);
//// [concatError.js]
var n1;
/*
interface Array<T> {
concat(...items: T[][]): T[]; // Note: This overload needs to be picked for arrays of arrays, even though both are applicable
concat(...items: T[]): T[];
}
/*
interface Array<T> {
concat(...items: T[][]): T[]; // Note: This overload needs to be picked for arrays of arrays, even though both are applicable
concat(...items: T[]): T[];
}
*/
var fa;
fa = fa.concat([0]);

View File

@ -120,15 +120,15 @@ l\u0061bel4:
}
//// [escapedIdentifiers.js]
/*
0 .. \u0030
9 .. \u0039
A .. \u0041
Z .. \u005a
a .. \u0061
z .. \u00za
/*
0 .. \u0030
9 .. \u0039
A .. \u0041
Z .. \u005a
a .. \u0061
z .. \u00za
*/
// var decl
var \u0061 = 1;

View File

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

View File

@ -64,8 +64,8 @@ var a = function () {
return new C2();
};
new a();
/*var b:I4 = C2;
new b();
/*var b:I4 = C2;
new b();
*/
var c;
c[5];

View File

@ -45,11 +45,11 @@ var IceCreamMonster = (function () {
this.soundsWhenEating = soundsWhenEating;
this.name = name;
}
/**
* Tells the IceCreamMonster to eat their ice cre am!
*
* @param {number} amount The amount of ice cream to e at.
* @return {boolean} True if ice cream remains, false if there is no more ice cream le ft.
/**
* Tells the IceCreamMonster to eat their ice cre am!
*
* @param {number} amount The amount of ice cream to e at.
* @return {boolean} True if ice cream remains, false if there is no more ice cream le ft.
*/
IceCreamMonster.prototype.eatIceCream = function (amount) {
this.iceCreamRemaining -= amount;

View File

@ -32,9 +32,9 @@ runTestCase(testcase);
/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the
/// "Use Terms"). Any redistribution of this code must retain the above
/// copyright and this notice and otherwise comply with the Use Terms.
/**
* @path ch15/15.4/15.4.4/15.4.4.14/15.4.4.14-9-2.js
* @description Array.prototype.indexOf must return correct index (Number)
/**
* @path ch15/15.4/15.4.4/15.4.4.14/15.4.4.14-9-2.js
* @description Array.prototype.indexOf must return correct index (Number)
*/
function testcase() {
var obj = { toString: function () {

View File

@ -23,11 +23,11 @@ if (x !== 1) {
//// [parserS7.3_A1.1_T2.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* LINE FEED (U+000A) may occur between any two tokens
*
* @path ch07/7.3/S7.3_A1.1_T2.js
* @description Insert real LINE FEED between tokens of var x=1
/**
* LINE FEED (U+000A) may occur between any two tokens
*
* @path ch07/7.3/S7.3_A1.1_T2.js
* @description Insert real LINE FEED between tokens of var x=1
*/
//CHECK#1
var x = 1;

View File

@ -148,11 +148,11 @@ if (Ё !== 1) {
//// [parserS7.6_A4.2_T1.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* Correct interpretation of RUSSIAN ALPHABET
*
* @path ch07/7.6/S7.6_A4.2_T1.js
* @description Check RUSSIAN CAPITAL ALPHABET
/**
* Correct interpretation of RUSSIAN ALPHABET
*
* @path ch07/7.6/S7.6_A4.2_T1.js
* @description Check RUSSIAN CAPITAL ALPHABET
*/
//CHECK#А
var \u0410 = 1;

View File

@ -23,13 +23,13 @@ y
//// [parserS7.9_A5.7_T1.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* Since LineTerminator(LT) between Postfix Increment/Decrement Operator(I/DO) and operand is not allowed, two IO(just as two DO and their combination)
* between two references separated by [LT] after automatic semicolon insertion lead to syntax error
*
* @path ch07/7.9/S7.9_A5.7_T1.js
* @description Try use Variable1 \n ++ \n ++ \n Variable2 construction
* @negative
/**
* Since LineTerminator(LT) between Postfix Increment/Decrement Operator(I/DO) and operand is not allowed, two IO(just as two DO and their combination)
* between two references separated by [LT] after automatic semicolon insertion lead to syntax error
*
* @path ch07/7.9/S7.9_A5.7_T1.js
* @description Try use Variable1 \n ++ \n ++ \n Variable2 construction
* @negative
*/
var x = 0, y = 0;
var z = x;

View File

@ -23,11 +23,11 @@ if (x !== 1) {
//// [scannerS7.3_A1.1_T2.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* LINE FEED (U+000A) may occur between any two tokens
*
* @path ch07/7.3/S7.3_A1.1_T2.js
* @description Insert real LINE FEED between tokens of var x=1
/**
* LINE FEED (U+000A) may occur between any two tokens
*
* @path ch07/7.3/S7.3_A1.1_T2.js
* @description Insert real LINE FEED between tokens of var x=1
*/
//CHECK#1
var x = 1;

View File

@ -148,11 +148,11 @@ if (Ё !== 1) {
//// [scannerS7.6_A4.2_T1.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* Correct interpretation of RUSSIAN ALPHABET
*
* @path ch07/7.6/S7.6_A4.2_T1.js
* @description Check RUSSIAN CAPITAL ALPHABET
/**
* Correct interpretation of RUSSIAN ALPHABET
*
* @path ch07/7.6/S7.6_A4.2_T1.js
* @description Check RUSSIAN CAPITAL ALPHABET
*/
//CHECK#А
var \u0410 = 1;

View File

@ -61,8 +61,8 @@ var Shapes;
function foo() {
}
Shapes.foo = foo;
/** comment after function
* this is another comment
/** comment after function
* this is another comment
*/
var b = 10;
})(Shapes || (Shapes = {}));

View File

@ -465,7 +465,7 @@ sourceFile:sourceMap-FileWithComments.ts
3 > ^^^
4 > ^^^
5 > ^
6 > ^^^^^^^^^^->
6 > ^^^^^^^^^^^->
1->
2 > foo
3 >
@ -478,7 +478,7 @@ sourceFile:sourceMap-FileWithComments.ts
4 >Emitted(24, 21) Source(26, 6) + SourceIndex(0) name (Shapes)
5 >Emitted(24, 22) Source(26, 6) + SourceIndex(0) name (Shapes)
---
>>> /** comment after function
>>> /** comment after function
1->^^^^
2 >
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^->
@ -492,7 +492,7 @@ sourceFile:sourceMap-FileWithComments.ts
1->Emitted(25, 5) Source(31, 5) + SourceIndex(0) name (Shapes)
2 >Emitted(25, 5) Source(28, 5) + SourceIndex(0) name (Shapes)
---
>>> * this is another comment
>>> * this is another comment
>>> */
1->^^^^^^
2 > ^^^^^^^^^^->

View File

@ -15,8 +15,8 @@ function foo() {
//// [stradac.js]
var x = 10;
// C++-style comment
/*
C-Style comment
/*
C-Style comment
*/
function foo() {
x++;

View File

@ -0,0 +1,72 @@
// @target: ES5
// @declaration: true
// @comments: true
module m {
/** this is first line - aligned to class declaration
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
export class c {
}
/** this is first line - 4 spaces right aligned to class but in js file should be aligned to class declaration
* this is 8 spaces left aligned
* this is 7 spaces left aligned
* this is 6 spaces left aligned
* this is 5 spaces left aligned
* this is 4 spaces left aligned
* this is 3 spaces left aligned
* this is 2 spaces left aligned
* this is 1 spaces left aligned
* this is at same level as first line
* this is 1 spaces right aligned
* this is 2 spaces right aligned
* this is 3 spaces right aligned
* this is 4 spaces right aligned
* this is 5 spaces right aligned
* this is 6 spaces right aligned
* this is 7 spaces right aligned
* this is 8 spaces right aligned */
export class c2 {
}
/** this is comment with new lines in between
this is 4 spaces left aligned but above line is empty
this is 3 spaces left aligned but above line is empty
this is 2 spaces left aligned but above line is empty
this is 1 spaces left aligned but above line is empty
this is at same level as first line but above line is empty
this is 1 spaces right aligned but above line is empty
this is 2 spaces right aligned but above line is empty
this is 3 spaces right aligned but above line is empty
this is 4 spaces right aligned but above line is empty
Above 2 lines are empty
above 3 lines are empty*/
export class c3 {
}
}