@@ -37,7 +37,9 @@ module ts {
37
37
38
38
var emptyArray : any [ ] = [ ] ;
39
39
var emptySymbols : SymbolTable = { } ;
40
-
40
+
41
+ var compilerOptions = program . getCompilerOptions ( ) ;
42
+
41
43
var checker : TypeChecker = {
42
44
getProgram : ( ) => program ,
43
45
getDiagnostics : getDiagnostics ,
@@ -943,20 +945,37 @@ module ts {
943
945
writer . write ( symbolToString ( symbol , enclosingDeclaration , meaning ) ) ;
944
946
}
945
947
946
- function createSingleLineTextWriter ( ) {
948
+ function createSingleLineTextWriter ( maxLength ?: number ) {
947
949
var result = "" ;
950
+ var overflow = false ;
951
+ function write ( s : string ) {
952
+ if ( ! overflow ) {
953
+ result += s ;
954
+ if ( result . length > maxLength ) {
955
+ result = result . substr ( 0 , maxLength - 3 ) + "..." ;
956
+ overflow = true ;
957
+ }
958
+ }
959
+ }
948
960
return {
949
- write ( s : string ) { result += s ; } ,
950
- writeSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) { writeSymbolToTextWriter ( symbol , enclosingDeclaration , meaning , this ) ; } ,
951
- writeLine ( ) { result += " " ; } ,
961
+ write : write ,
962
+ writeSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) {
963
+ writeSymbolToTextWriter ( symbol , enclosingDeclaration , meaning , this ) ;
964
+ } ,
965
+ writeLine ( ) {
966
+ write ( " " ) ;
967
+ } ,
952
968
increaseIndent ( ) { } ,
953
969
decreaseIndent ( ) { } ,
954
- getText ( ) { return result ; }
970
+ getText ( ) {
971
+ return result ;
972
+ }
955
973
} ;
956
974
}
957
975
958
976
function typeToString ( type : Type , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : string {
959
- var stringWriter = createSingleLineTextWriter ( ) ;
977
+ var maxLength = compilerOptions . noErrorTruncation || flags & TypeFormatFlags . NoTruncation ? undefined : 100 ;
978
+ var stringWriter = createSingleLineTextWriter ( maxLength ) ;
960
979
// TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration
961
980
writeTypeToTextWriter ( type , enclosingDeclaration , flags , stringWriter ) ;
962
981
return stringWriter . getText ( ) ;
@@ -1348,7 +1367,7 @@ module ts {
1348
1367
return type ;
1349
1368
1350
1369
function checkImplicitAny ( type : Type ) {
1351
- if ( ! fullTypeCheck || ! program . getCompilerOptions ( ) . noImplicitAny ) {
1370
+ if ( ! fullTypeCheck || ! compilerOptions . noImplicitAny ) {
1352
1371
return ;
1353
1372
}
1354
1373
// We need to have ended up with 'any', 'any[]', 'any[][]', etc.
@@ -1451,7 +1470,7 @@ module ts {
1451
1470
}
1452
1471
// Otherwise, fall back to 'any'.
1453
1472
else {
1454
- if ( program . getCompilerOptions ( ) . noImplicitAny ) {
1473
+ if ( compilerOptions . noImplicitAny ) {
1455
1474
error ( setter , Diagnostics . Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation , symbol . name ) ;
1456
1475
}
1457
1476
@@ -3971,7 +3990,7 @@ module ts {
3971
3990
}
3972
3991
3973
3992
// Fall back to any.
3974
- if ( program . getCompilerOptions ( ) . noImplicitAny && objectType !== anyType ) {
3993
+ if ( compilerOptions . noImplicitAny && objectType !== anyType ) {
3975
3994
error ( node , Diagnostics . Index_signature_of_object_type_implicitly_has_an_any_type ) ;
3976
3995
}
3977
3996
@@ -4316,7 +4335,7 @@ module ts {
4316
4335
var declaration = signature . declaration ;
4317
4336
if ( declaration && ( declaration . kind !== SyntaxKind . Constructor && declaration . kind !== SyntaxKind . ConstructSignature ) ) {
4318
4337
// When resolved signature is a call signature (and not a construct signature) the result type is any
4319
- if ( program . getCompilerOptions ( ) . noImplicitAny ) {
4338
+ if ( compilerOptions . noImplicitAny ) {
4320
4339
error ( node , Diagnostics . new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type ) ;
4321
4340
}
4322
4341
return anyType ;
@@ -4362,7 +4381,7 @@ module ts {
4362
4381
var unwidenedType = checkAndMarkExpression ( func . body , contextualMapper ) ;
4363
4382
var widenedType = getWidenedType ( unwidenedType ) ;
4364
4383
4365
- if ( fullTypeCheck && program . getCompilerOptions ( ) . noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes ( widenedType ) === anyType ) {
4384
+ if ( fullTypeCheck && compilerOptions . noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes ( widenedType ) === anyType ) {
4366
4385
error ( func , Diagnostics . Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type , typeToString ( widenedType ) ) ;
4367
4386
}
4368
4387
@@ -4384,7 +4403,7 @@ module ts {
4384
4403
var widenedType = getWidenedType ( commonType ) ;
4385
4404
4386
4405
// Check and report for noImplicitAny if the best common type implicitly gets widened to an 'any'/arrays-of-'any' type.
4387
- if ( fullTypeCheck && program . getCompilerOptions ( ) . noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes ( widenedType ) === anyType ) {
4406
+ if ( fullTypeCheck && compilerOptions . noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes ( widenedType ) === anyType ) {
4388
4407
var typeName = typeToString ( widenedType ) ;
4389
4408
4390
4409
if ( func . name ) {
@@ -4960,7 +4979,7 @@ module ts {
4960
4979
checkCollisionWithCapturedThisVariable ( node , node . name ) ;
4961
4980
checkCollistionWithRequireExportsInGeneratedCode ( node , node . name ) ;
4962
4981
checkCollisionWithArgumentsInGeneratedCode ( node ) ;
4963
- if ( program . getCompilerOptions ( ) . noImplicitAny && ! node . type ) {
4982
+ if ( compilerOptions . noImplicitAny && ! node . type ) {
4964
4983
switch ( node . kind ) {
4965
4984
case SyntaxKind . ConstructSignature :
4966
4985
error ( node , Diagnostics . Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type ) ;
@@ -5516,7 +5535,7 @@ module ts {
5516
5535
}
5517
5536
5518
5537
// If there is no body and no explicit return type, then report an error.
5519
- if ( fullTypeCheck && program . getCompilerOptions ( ) . noImplicitAny && ! node . body && ! node . type ) {
5538
+ if ( fullTypeCheck && compilerOptions . noImplicitAny && ! node . body && ! node . type ) {
5520
5539
// Ignore privates within ambient contexts; they exist purely for documentative purposes to avoid name clashing.
5521
5540
// (e.g. privates within .d.ts files do not expose type information)
5522
5541
if ( ! isPrivateWithinAmbient ( node ) ) {
@@ -7161,7 +7180,7 @@ module ts {
7161
7180
function shouldEmitDeclarations ( ) {
7162
7181
// If the declaration emit and there are no errors being reported in program or by checker
7163
7182
// declarations can be emitted
7164
- return program . getCompilerOptions ( ) . declaration &&
7183
+ return compilerOptions . declaration &&
7165
7184
! program . getDiagnostics ( ) . length &&
7166
7185
! getDiagnostics ( ) . length ;
7167
7186
}
0 commit comments