From e8e2356afaa00b3fbd4cd18c18692f46f63bee46 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 20 Jan 2015 12:24:13 -0800 Subject: [PATCH] Fixes the emit of comment when comment ends on last line This fixes regression from 5a7500ca5e62d7e6c7863cf42d156e8bcdc3017c with addition of eof token Handles #1714 --- src/compiler/emitter.ts | 3 +- .../reference/baseIndexSignatureResolution.js | 25 +-------------- .../commentEmitWithCommentOnLastLine.js | 11 +++++++ .../commentEmitWithCommentOnLastLine.types | 7 ++++ tests/baselines/reference/concatError.js | 32 +------------------ ...sivelySpecializedConstructorDeclaration.js | 30 +---------------- .../commentEmitWithCommentOnLastLine.ts | 4 +++ 7 files changed, 27 insertions(+), 85 deletions(-) create mode 100644 tests/baselines/reference/commentEmitWithCommentOnLastLine.js create mode 100644 tests/baselines/reference/commentEmitWithCommentOnLastLine.types create mode 100644 tests/cases/compiler/commentEmitWithCommentOnLastLine.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 25cb7a8b2ee..dafd03717a6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -170,9 +170,10 @@ module ts { function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); + var lastLine = currentSourceFile.getLineStarts().length; var firstCommentLineIndent: number; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1); + var nextLineStart = currentLine === lastLine ? (comment.end + 1) : currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1); if (pos !== comment.pos) { // If we are not emitting first line, we need to write the spaces to adjust the alignment diff --git a/tests/baselines/reference/baseIndexSignatureResolution.js b/tests/baselines/reference/baseIndexSignatureResolution.js index 4c2d63bf2c9..4720e92b969 100644 --- a/tests/baselines/reference/baseIndexSignatureResolution.js +++ b/tests/baselines/reference/baseIndexSignatureResolution.js @@ -55,27 +55,4 @@ interface B extends A { } var b: B = null; var z: Derived = b.foo(); -class Base { private a: string; } -class Derived extends Base { private b: string; } - -// Note - commmenting "extends Foo" prevents the error -interface Foo { - [i: number]: Base; -} -interface FooOf extends Foo { - [i: number]: TBase; -} -var x: FooOf = null; -var y: Derived = x[0]; - -/* -// Note - the equivalent for normal interface methods works fine: -interface A { - foo(): Base; -} -interface B extends A { - foo(): TBase; -} -var b: B = null; -var z: Derived = b.foo(); - +*/ diff --git a/tests/baselines/reference/commentEmitWithCommentOnLastLine.js b/tests/baselines/reference/commentEmitWithCommentOnLastLine.js new file mode 100644 index 00000000000..ffd4addb264 --- /dev/null +++ b/tests/baselines/reference/commentEmitWithCommentOnLastLine.js @@ -0,0 +1,11 @@ +//// [commentEmitWithCommentOnLastLine.ts] +var x: any; +/* +var bar; +*/ + +//// [commentEmitWithCommentOnLastLine.js] +var x; +/* +var bar; +*/ diff --git a/tests/baselines/reference/commentEmitWithCommentOnLastLine.types b/tests/baselines/reference/commentEmitWithCommentOnLastLine.types new file mode 100644 index 00000000000..d59c42d3795 --- /dev/null +++ b/tests/baselines/reference/commentEmitWithCommentOnLastLine.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/commentEmitWithCommentOnLastLine.ts === +var x: any; +>x : any + +/* +var bar; +*/ diff --git a/tests/baselines/reference/concatError.js b/tests/baselines/reference/concatError.js index 04c0a16b836..dee3d8a30e3 100644 --- a/tests/baselines/reference/concatError.js +++ b/tests/baselines/reference/concatError.js @@ -57,34 +57,4 @@ var c: C; var cc: C>; c = c.m(cc); -var n1: number[]; -/* -interface Array { - 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: number[]; - -fa = fa.concat([0]); -fa = fa.concat(0); - - - - - -/* - - - - -declare class C { - public m(p1: C>): C; - //public p: T; -} - -var c: C; -var cc: C>; - -c = c.m(cc); - +*/ diff --git a/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js b/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js index dd8028b086a..c0abe985dbc 100644 --- a/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js +++ b/tests/baselines/reference/recursivelySpecializedConstructorDeclaration.js @@ -74,32 +74,4 @@ declare module MsPortal.Controls.Base.ItemList { class ViewModel extends ItemValue { } } -module MsPortal.Controls.Base.ItemList { - - export interface Interface { - // Removing this line fixes the constructor of ItemValue - options: ViewModel; - } - - export class ItemValue { - constructor(value: T) { - } - } - - export class ViewModel extends ItemValue { - } -} - -// Generates: -/* -declare module MsPortal.Controls.Base.ItemList { - interface Interface { - options: ViewModel; - } - class ItemValue { - constructor(value: T); - } - class ViewModel extends ItemValue { - } -} - +*/ diff --git a/tests/cases/compiler/commentEmitWithCommentOnLastLine.ts b/tests/cases/compiler/commentEmitWithCommentOnLastLine.ts new file mode 100644 index 00000000000..d148fbda6fa --- /dev/null +++ b/tests/cases/compiler/commentEmitWithCommentOnLastLine.ts @@ -0,0 +1,4 @@ +var x: any; +/* +var bar; +*/ \ No newline at end of file