Fix the trailing comments for variable declaration and function/arrow expressions

This commit is contained in:
Sheetal Nandi
2014-08-14 16:32:21 -07:00
parent 895a9e7ac5
commit f428a16680
22 changed files with 38 additions and 34 deletions
+6 -2
View File
@@ -1094,6 +1094,7 @@ module ts {
emitLeadingComments(node);
emitModuleMemberName(node);
emitOptional(" = ", node.initializer);
var variableStatement = <VariableStatement>node.parent;
emitTrailingComments(node);
}
@@ -1935,8 +1936,11 @@ module ts {
}
function emitTrailingDeclarationComments(node: Declaration) {
var trailingComments = getTrailingComments(currentSourceFile.text, node.end);
emitComments(trailingComments, writer, writeComment);
// Emit the trailing declaration comments only if the parent's end doesnt match
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
var trailingComments = getTrailingComments(currentSourceFile.text, node.end);
emitComments(trailingComments, writer, writeComment);
}
}
if (compilerOptions.sourceMap) {
@@ -129,7 +129,7 @@ arr_c3 = arr_i1_2;
arr_any = f1;
arr_any = function () {
return null;
}// should be an error - is ;
};
arr_any = o1;
arr_any = a1;
arr_any = c1;
@@ -51,5 +51,5 @@ var o1 = { one: 1 };
var arr_any = [];
arr_any = function () {
return null;
}// should be an error - is ;
};
arr_any = c3;
@@ -13,4 +13,4 @@ var C = (function () {
})();
var c = new C(function () {
return asdf;
})// should error ;// should error
});// should error
@@ -72,7 +72,7 @@ var a5: (x?: number, y?: number) => number;
//// [assignmentCompatWithCallSignaturesWithOptionalParameters.js]
var b;
var a;
a = function () { return 1; }// ok, same number of required params ;
a = function () { return 1; };
a = function (x) { return 1; };
a = function (x) { return 1; };
a = b.a;
@@ -54,7 +54,7 @@ var e3;
e3[e3["One"] = 0] = "One";
})(e3 || (e3 = {}));
var e3 = function () {
}// error // error ;// error
};// error
// enum then class
var e4;
(function (e4) {
@@ -51,7 +51,7 @@ function y2() {
function y2a() {
}
var y2a = function () {
}// error // error ;// error
};// error
// function then class
function y3() {
}
@@ -46,7 +46,7 @@ function x2() {
}// should be an error
var x3 = 1;
var x3 = function () {
}// should be an error // should be an error ;// should be an error
};// should be an error
// var then class
var x4 = 1;
var x4 = (function () {
@@ -68,7 +68,7 @@ var Derived3 = (function (_super) {
function Derived3() {
var r = function () {
_super.call(this);
}// error // error ;// error
};// error
}
return Derived3;
})(Base2);
@@ -17,5 +17,5 @@ var s3 = s2.func(num => num.toString())
//// [genericChainedCalls.js]
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }).func(function (num) { return num.toString(); });
var s1 = v1.func(function (num) { return num.toString(); });
var s2 = s1.func(function (str) { return str.length; })// should also error ;// should also error
var s2 = s1.func(function (str) { return str.length; });// should also error
var s3 = s2.func(function (num) { return num.toString(); });
@@ -43,4 +43,4 @@ var M;
var g1 = new G();
g1.bar(null).foo();
})(M || (M = {}));
var g2 = new G()// was: error Type reference cannot refer to container 'M.C'. ;// was: error Type reference cannot refer to container 'M.C'.
var g2 = new G();// was: error Type reference cannot refer to container 'M.C'.
@@ -24,13 +24,13 @@ var x;
x.foo(1);
var f = function (x) {
return x.foo(1);
}// error // error ;// error
};// error
var f2 = function (x) {
return x.foo(1);
}// error // error ;// error
};// error
var f3 = function (x) {
return x.foo(1);
}// error // error ;// error
};// error
var f4 = function (x) {
return x.foo(1);
}// no error // no error ;// no error
};// no error
@@ -22,7 +22,7 @@ var lambda10 = function temp1() { return 5; }
var lambda = function (l1) {
};// Error at "l1"
var lambd2 = function (ll1, ll2) {
}// Error at "ll1" // Error at "ll1" ;// Error at "ll1"
};// Error at "ll1"
var lamda3 = function myLambda3(myParam) {
};
var lamda4 = function () {
@@ -24,7 +24,7 @@ var C = (function () {
return C;
})();
// this should be an error
var x// error at "y,z" ;// error at "y,z"
var x;// error at "y,z"
var x1;// error at "z1"
var x11;// error at "new"
var x2;// error at "y2"
@@ -39,7 +39,7 @@ var newC2 = new C(<any>[], null)
// this should be errors
var arg0 = null;// error at "arg0"
var anyArray = [null, undefined];// error at array literal
var objL// error at "y,z" ;// error at "y,z"
var objL;// error at "y,z"
var funcL;
function temp1(arg1) {
}// error at "temp1"
+1 -1
View File
@@ -4,4 +4,4 @@ var r: Date = dateMap["hello"] // result type includes indexer using BCT
//// [indexer3.js]
var dateMap = {};
var r = dateMap["hello"]// result type includes indexer using BCT ;// result type includes indexer using BCT
var r = dateMap["hello"];// result type includes indexer using BCT
@@ -22,7 +22,7 @@ var C = (function () {
};
C.prototype.bar = function (x) {
C.prototype.bar = function () {
}// error ;
};
C.prototype.bar = function (x) { return x; };
C.prototype.bar = function (x) { return 1; };
return 1;
@@ -13,4 +13,4 @@ var b: B<B<any>> = a // Error, any does not satisfy constraint B<B<T>>
//// [recursiveIdenticalAssignment.js]
var a;
var b = a// Error, any does not satisfy constraint B<B<T>> ;// Error, any does not satisfy constraint B<B<T>>
var b = a;// Error, any does not satisfy constraint B<B<T>>
@@ -22,7 +22,7 @@ var C = (function () {
};
C.bar = function (x) {
C.bar = function () {
}// error ;
};
C.bar = function (x) { return x; };
C.bar = function (x) { return 1; };
return 1;
+4 -4
View File
@@ -10,23 +10,23 @@ var fra1 = function () {
return function (v) {
return v;
};
}()// should work ;// should work
}();// should work
var fra2 = function () {
return function () {
return 0;
};
}()// should work ;// should work
}();// should work
var fra3 = function () {
return function () {
return function (v) {
return v;
};
}();
}()// should work ;// should work
}();// should work
var fra4 = function () {
return function () {
return function (v) {
return v;
};
}();
}()// should work ;// should work
}();// should work
@@ -22,4 +22,4 @@ var E;
var x = E;
var x;// Shouldnt error
var y = E;
var y// two errors: the types are not identical and duplicate signatures ;// two errors: the types are not identical and duplicate signatures
var y;// two errors: the types are not identical and duplicate signatures
@@ -24,12 +24,12 @@ var fa = function () {
return 3;
};
fa = function () {
}// should not work ;
};
var fv = function () {
};
fv = function () {
return 0;
}// should work ;
};
function execAny(callback) {
return callback(0);
}
@@ -44,19 +44,19 @@ execVoid(function () {
var fra = function () {
return function () {
};
}// should work // should work ;// should work
};// should work
var frv = function () {
return function () {
return 0;
};
}// should work // should work ;// should work
};// should work
var fra3 = (function () {
return function (v) {
return v;
};
})()// should work ;// should work
})();// should work
var frv3 = (function () {
return function () {
return 0;
};
})()// should work ;// should work
})();// should work