Fixes the emit of comment when comment ends on last line

This fixes regression from 5a7500ca5e with addition of eof token
Handles #1714
This commit is contained in:
Sheetal Nandi
2015-01-20 21:16:14 -08:00
parent 7f749909da
commit e8e2356afa
7 changed files with 27 additions and 85 deletions
+2 -1
View File
@@ -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
@@ -55,27 +55,4 @@ interface B<TBase extends Base> extends A {
}
var b: B<Derived> = 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<TBase extends Base> extends Foo {
[i: number]: TBase;
}
var x: FooOf<Derived> = null;
var y: Derived = x[0];
/*
// Note - the equivalent for normal interface methods works fine:
interface A {
foo(): Base;
}
interface B<TBase extends Base> extends A {
foo(): TBase;
}
var b: B<Derived> = null;
var z: Derived = b.foo();
*/
@@ -0,0 +1,11 @@
//// [commentEmitWithCommentOnLastLine.ts]
var x: any;
/*
var bar;
*/
//// [commentEmitWithCommentOnLastLine.js]
var x;
/*
var bar;
*/
@@ -0,0 +1,7 @@
=== tests/cases/compiler/commentEmitWithCommentOnLastLine.ts ===
var x: any;
>x : any
/*
var bar;
*/
+1 -31
View File
@@ -57,34 +57,4 @@ var c: C<number>;
var cc: C<C<number>>;
c = c.m(cc);
var n1: number[];
/*
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: number[];
fa = fa.concat([0]);
fa = fa.concat(0);
/*
declare class C<T> {
public m(p1: C<C<T>>): C<T>;
//public p: T;
}
var c: C<number>;
var cc: C<C<number>>;
c = c.m(cc);
*/
@@ -74,32 +74,4 @@ declare module MsPortal.Controls.Base.ItemList {
class ViewModel<TValue> extends ItemValue<TValue> {
}
}
module MsPortal.Controls.Base.ItemList {
export interface Interface<TValue> {
// Removing this line fixes the constructor of ItemValue
options: ViewModel<TValue>;
}
export class ItemValue<T> {
constructor(value: T) {
}
}
export class ViewModel<TValue> extends ItemValue<TValue> {
}
}
// Generates:
/*
declare module MsPortal.Controls.Base.ItemList {
interface Interface<TValue> {
options: ViewModel<TValue>;
}
class ItemValue<T> {
constructor(value: T);
}
class ViewModel<TValue> extends ItemValue<TValue> {
}
}
*/
@@ -0,0 +1,4 @@
var x: any;
/*
var bar;
*/