From 5422e56d4805af8518480cce7fc6c5714258f6c7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 4 Sep 2014 14:23:57 -0700 Subject: [PATCH 01/17] Do not show noImplictAny errors when widening for a cast expression --- src/compiler/checker.ts | 22 +++++++------- .../noImplicitAnyInCastExpression.js | 20 +++++++++++++ .../noImplicitAnyInCastExpression.types | 30 +++++++++++++++++++ .../compiler/noImplicitAnyInCastExpression.ts | 12 ++++++++ 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/noImplicitAnyInCastExpression.js create mode 100644 tests/baselines/reference/noImplicitAnyInCastExpression.types create mode 100644 tests/cases/compiler/noImplicitAnyInCastExpression.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6ca1e1e81a5..a55dbb6e345 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3132,7 +3132,7 @@ module ts { return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; } - function getWidenedTypeOfObjectLiteral(type: Type): Type { + function getWidenedTypeOfObjectLiteral(type: Type, supressNoImplictAnyErrors?: boolean): Type { var properties = getPropertiesOfType(type); if (properties.length) { var widenedTypes: Type[] = []; @@ -3143,7 +3143,7 @@ module ts { if (propType !== widenedType) { propTypeWasWidened = true; - if (program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!supressNoImplictAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -3183,9 +3183,9 @@ module ts { return type; } - function getWidenedTypeOfArrayLiteral(type: Type): Type { + function getWidenedTypeOfArrayLiteral(type: Type, supressNoImplictAnyErrors?: boolean): Type { var elementType = (type).typeArguments[0]; - var widenedType = getWidenedType(elementType); + var widenedType = getWidenedType(elementType, supressNoImplictAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; @@ -3193,15 +3193,15 @@ module ts { } /* If we are widening on a literal, then we may need to the 'node' parameter for reporting purposes */ - function getWidenedType(type: Type): Type { + function getWidenedType(type: Type, supressNoImplictAnyErrors?: boolean): Type { if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) { return anyType; } if (isTypeOfObjectLiteral(type)) { - return getWidenedTypeOfObjectLiteral(type); + return getWidenedTypeOfObjectLiteral(type, supressNoImplictAnyErrors); } if (isArrayType(type)) { - return getWidenedTypeOfArrayLiteral(type); + return getWidenedTypeOfArrayLiteral(type, supressNoImplictAnyErrors); } return type; } @@ -4329,9 +4329,11 @@ module ts { var exprType = checkExpression(node.operand); var targetType = getTypeFromTypeNode(node.type); if (fullTypeCheck && targetType !== unknownType) { - var widenedType = getWidenedType(exprType); - if (!(isTypeAssignableTo(exprType, targetType) || isTypeAssignableTo(targetType, widenedType))) { - checkTypeAssignableTo(targetType, widenedType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + if (!isTypeAssignableTo(exprType, targetType)) { + var widenedType = getWidenedType(exprType, /*supressNoImplictAnyErrors*/ true); + if (!isTypeAssignableTo(targetType, widenedType)) { + checkTypeAssignableTo(targetType, widenedType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + } } } return targetType; diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.js b/tests/baselines/reference/noImplicitAnyInCastExpression.js new file mode 100644 index 00000000000..eef614450b4 --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.js @@ -0,0 +1,20 @@ +//// [noImplicitAnyInCastExpression.ts] +interface IBar { + b: number; +} +interface IFoo { + p: IBar[]; +} + +function foo(a: any) { } + +foo( { + p: null, +}); + +//// [noImplicitAnyInCastExpression.js] +function foo(a) { +} +foo({ + p: null +}); diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.types b/tests/baselines/reference/noImplicitAnyInCastExpression.types new file mode 100644 index 00000000000..cdc0a550081 --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/noImplicitAnyInCastExpression.ts === +interface IBar { +>IBar : IBar + + b: number; +>b : number +} +interface IFoo { +>IFoo : IFoo + + p: IBar[]; +>p : IBar[] +>IBar : IBar +} + +function foo(a: any) { } +>foo : (a: any) => void +>a : any + +foo( { +>foo( { p: null,}) : void +>foo : (a: any) => void +> { p: null,} : IFoo +>IFoo : IFoo +>{ p: null,} : { p: null; } + + p: null, +>p : any + +}); diff --git a/tests/cases/compiler/noImplicitAnyInCastExpression.ts b/tests/cases/compiler/noImplicitAnyInCastExpression.ts new file mode 100644 index 00000000000..9838e5e9432 --- /dev/null +++ b/tests/cases/compiler/noImplicitAnyInCastExpression.ts @@ -0,0 +1,12 @@ +interface IBar { + b: number; +} +interface IFoo { + p: IBar[]; +} + +function foo(a: any) { } + +foo( { + p: null, +}); \ No newline at end of file From 3b6afb84994d7408a28caba58fc046b29a0a6753 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 5 Sep 2014 16:41:37 -0700 Subject: [PATCH 02/17] respond to code review remarks --- src/compiler/checker.ts | 19 +++++------ .../baselines/reference/arrayCast.errors.txt | 3 +- .../reference/contextualTyping39.errors.txt | 3 +- .../reference/contextualTyping41.errors.txt | 3 +- tests/baselines/reference/fuzzy.errors.txt | 5 ++- .../genericTypeAssertions2.errors.txt | 3 +- .../genericTypeAssertions4.errors.txt | 6 ++-- .../genericTypeAssertions5.errors.txt | 6 ++-- .../reference/intTypeCheck.errors.txt | 3 +- .../noImplicitAnyInCastExpression.errors.txt | 20 ++++++++++++ .../noImplicitAnyInCastExpression.js | 32 +++++++++++-------- .../noImplicitAnyInCastExpression.types | 30 ----------------- .../reference/typeAssertions.errors.txt | 6 ++-- .../compiler/noImplicitAnyInCastExpression.ts | 21 +++++++----- 14 files changed, 86 insertions(+), 74 deletions(-) create mode 100644 tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt delete mode 100644 tests/baselines/reference/noImplicitAnyInCastExpression.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a55dbb6e345..932c8496694 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3132,7 +3132,7 @@ module ts { return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; } - function getWidenedTypeOfObjectLiteral(type: Type, supressNoImplictAnyErrors?: boolean): Type { + function getWidenedTypeOfObjectLiteral(type: Type, supressNoImplicitAnyErrors?: boolean): Type { var properties = getPropertiesOfType(type); if (properties.length) { var widenedTypes: Type[] = []; @@ -3143,7 +3143,7 @@ module ts { if (propType !== widenedType) { propTypeWasWidened = true; - if (!supressNoImplictAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -3183,9 +3183,9 @@ module ts { return type; } - function getWidenedTypeOfArrayLiteral(type: Type, supressNoImplictAnyErrors?: boolean): Type { + function getWidenedTypeOfArrayLiteral(type: Type, supressNoImplicitAnyErrors?: boolean): Type { var elementType = (type).typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplictAnyErrors); + var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; @@ -3193,15 +3193,15 @@ module ts { } /* If we are widening on a literal, then we may need to the 'node' parameter for reporting purposes */ - function getWidenedType(type: Type, supressNoImplictAnyErrors?: boolean): Type { + function getWidenedType(type: Type, supressNoImplicitAnyErrors?: boolean): Type { if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) { return anyType; } if (isTypeOfObjectLiteral(type)) { - return getWidenedTypeOfObjectLiteral(type, supressNoImplictAnyErrors); + return getWidenedTypeOfObjectLiteral(type, supressNoImplicitAnyErrors); } if (isArrayType(type)) { - return getWidenedTypeOfArrayLiteral(type, supressNoImplictAnyErrors); + return getWidenedTypeOfArrayLiteral(type, supressNoImplicitAnyErrors); } return type; } @@ -4330,10 +4330,7 @@ module ts { var targetType = getTypeFromTypeNode(node.type); if (fullTypeCheck && targetType !== unknownType) { if (!isTypeAssignableTo(exprType, targetType)) { - var widenedType = getWidenedType(exprType, /*supressNoImplictAnyErrors*/ true); - if (!isTypeAssignableTo(targetType, widenedType)) { - checkTypeAssignableTo(targetType, widenedType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); - } + checkTypeAssignableTo(targetType, getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true), node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index f081e0008d9..5ca2bc4b2b2 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -4,7 +4,8 @@ <{ id: number; }[]>[{ foo: "s" }]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! Neither type '{ id: number; }[]' nor type '{ foo: string; }[]' is assignable to the other: -!!! Type '{ id: number; }' is not assignable to type '{ foo: string; }'. +!!! Type '{ id: number; }' is not assignable to type '{ foo: string; }': +!!! Property 'foo' is missing in type '{ id: number; }'. // Should succeed, as the {} element causes the type of the array to be {}[] <{ id: number; }[]>[{ foo: "s" }, {}]; \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping39.errors.txt b/tests/baselines/reference/contextualTyping39.errors.txt index c0907b8fe7b..85ecf5e35b0 100644 --- a/tests/baselines/reference/contextualTyping39.errors.txt +++ b/tests/baselines/reference/contextualTyping39.errors.txt @@ -1,4 +1,5 @@ ==== tests/cases/compiler/contextualTyping39.ts (1 errors) ==== var foo = <{ (): number; }> function() { return "err"; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Neither type '() => number' nor type '() => string' is assignable to the other. \ No newline at end of file +!!! Neither type '() => number' nor type '() => string' is assignable to the other: +!!! Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping41.errors.txt b/tests/baselines/reference/contextualTyping41.errors.txt index d74e45f8a08..7f760b09b80 100644 --- a/tests/baselines/reference/contextualTyping41.errors.txt +++ b/tests/baselines/reference/contextualTyping41.errors.txt @@ -1,4 +1,5 @@ ==== tests/cases/compiler/contextualTyping41.ts (1 errors) ==== var foo = <{():number; (i:number):number; }> (function(){return "err";}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Neither type '{ (): number; (i: number): number; }' nor type '() => string' is assignable to the other. \ No newline at end of file +!!! Neither type '{ (): number; (i: number): number; }' nor type '() => string' is assignable to the other: +!!! Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/fuzzy.errors.txt b/tests/baselines/reference/fuzzy.errors.txt index dfe667b5be9..12060d90c98 100644 --- a/tests/baselines/reference/fuzzy.errors.txt +++ b/tests/baselines/reference/fuzzy.errors.txt @@ -32,7 +32,10 @@ worksToo():R { return ({ oneI: this }); ~~~~~~~~~~~~~~~~~~~ -!!! Neither type 'R' nor type '{ oneI: C; }' is assignable to the other. +!!! Neither type 'R' nor type '{ oneI: C; }' is assignable to the other: +!!! Types of property 'oneI' are incompatible: +!!! Type 'I' is not assignable to type 'C': +!!! Property 'x' is missing in type 'I'. } } } diff --git a/tests/baselines/reference/genericTypeAssertions2.errors.txt b/tests/baselines/reference/genericTypeAssertions2.errors.txt index e2f874b5983..cc49ef77810 100644 --- a/tests/baselines/reference/genericTypeAssertions2.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions2.errors.txt @@ -22,4 +22,5 @@ var r4: A = >new A(); var r5: A = >[]; // error ~~~~~~~~~~~~~ -!!! Neither type 'A' nor type 'any[]' is assignable to the other. \ No newline at end of file +!!! Neither type 'A' nor type 'any[]' is assignable to the other: +!!! Property 'length' is missing in type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions4.errors.txt b/tests/baselines/reference/genericTypeAssertions4.errors.txt index 13a4e2929b3..222b14c0850 100644 --- a/tests/baselines/reference/genericTypeAssertions4.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions4.errors.txt @@ -29,8 +29,10 @@ y = a; y = b; // error: cannot convert B to T ~~~~ -!!! Neither type 'T' nor type 'B' is assignable to the other. +!!! Neither type 'T' nor type 'B' is assignable to the other: +!!! Property 'bar' is missing in type 'A'. y = c; // error: cannot convert C to T ~~~~ -!!! Neither type 'T' nor type 'C' is assignable to the other. +!!! Neither type 'T' nor type 'C' is assignable to the other: +!!! Property 'baz' is missing in type 'A'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions5.errors.txt b/tests/baselines/reference/genericTypeAssertions5.errors.txt index 7b25b898213..97b4b7555c7 100644 --- a/tests/baselines/reference/genericTypeAssertions5.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions5.errors.txt @@ -29,8 +29,10 @@ y = a; y = b; // error: cannot convert B to T ~~~~ -!!! Neither type 'T' nor type 'B' is assignable to the other. +!!! Neither type 'T' nor type 'B' is assignable to the other: +!!! Property 'bar' is missing in type 'A'. y = c; // error: cannot convert C to T ~~~~ -!!! Neither type 'T' nor type 'C' is assignable to the other. +!!! Neither type 'T' nor type 'C' is assignable to the other: +!!! Property 'baz' is missing in type 'A'. } \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index cb2075efbdc..60c834dd0ea 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -315,7 +315,8 @@ var obj69: i7 = new obj66; var obj70: i7 = new Base; ~~~~~~~~~~~~ -!!! Neither type 'i7' nor type 'Base' is assignable to the other. +!!! Neither type 'i7' nor type 'Base' is assignable to the other: +!!! Property 'foo' is missing in type 'i7'. var obj71: i7 = null; var obj72: i7 = function () { }; ~~~~~ diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt new file mode 100644 index 00000000000..2784467da94 --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt @@ -0,0 +1,20 @@ +==== tests/cases/compiler/noImplicitAnyInCastExpression.ts (1 errors) ==== + + // verify no noImplictAny errors reported with cast expression + + interface IFoo { + a: number; + b: string; + } + + // Expr type not assignable to target type + ({ a: null }); + + // Expr type assignanle to target type + ({ a: 2, b: undefined }); + + // Niether types is assignable to each other + ({ c: null }); + ~~~~~~~~~~~~~~~~~ +!!! Neither type 'IFoo' nor type '{ c: any; }' is assignable to the other: +!!! Property 'c' is missing in type 'IFoo'. \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.js b/tests/baselines/reference/noImplicitAnyInCastExpression.js index eef614450b4..6501d17a5fe 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.js +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.js @@ -1,20 +1,26 @@ //// [noImplicitAnyInCastExpression.ts] -interface IBar { - b: number; -} + +// verify no noImplictAny errors reported with cast expression + interface IFoo { - p: IBar[]; + a: number; + b: string; } -function foo(a: any) { } +// Expr type not assignable to target type +({ a: null }); -foo( { - p: null, -}); +// Expr type assignanle to target type +({ a: 2, b: undefined }); + +// Niether types is assignable to each other +({ c: null }); //// [noImplicitAnyInCastExpression.js] -function foo(a) { -} -foo({ - p: null -}); +// verify no noImplictAny errors reported with cast expression +// Expr type not assignable to target type +{ a: null }; +// Expr type assignanle to target type +{ a: 2, b: undefined }; +// Niether types is assignable to each other +{ c: null }; diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.types b/tests/baselines/reference/noImplicitAnyInCastExpression.types deleted file mode 100644 index cdc0a550081..00000000000 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.types +++ /dev/null @@ -1,30 +0,0 @@ -=== tests/cases/compiler/noImplicitAnyInCastExpression.ts === -interface IBar { ->IBar : IBar - - b: number; ->b : number -} -interface IFoo { ->IFoo : IFoo - - p: IBar[]; ->p : IBar[] ->IBar : IBar -} - -function foo(a: any) { } ->foo : (a: any) => void ->a : any - -foo( { ->foo( { p: null,}) : void ->foo : (a: any) => void -> { p: null,} : IFoo ->IFoo : IFoo ->{ p: null,} : { p: null; } - - p: null, ->p : any - -}); diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index 47f3a3c930c..6a82f17a0db 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -33,13 +33,15 @@ someBase = someBase; someBase = someOther; // Error ~~~~~~~~~~~~~~~~~~~ -!!! Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other. +!!! Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other: +!!! Property 'q' is missing in type 'SomeBase'. someDerived = someDerived; someDerived = someBase; someDerived = someOther; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other. +!!! Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other: +!!! Property 'q' is missing in type 'SomeDerived'. someOther = someDerived; // Error ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/cases/compiler/noImplicitAnyInCastExpression.ts b/tests/cases/compiler/noImplicitAnyInCastExpression.ts index 9838e5e9432..afbdfa1ec1e 100644 --- a/tests/cases/compiler/noImplicitAnyInCastExpression.ts +++ b/tests/cases/compiler/noImplicitAnyInCastExpression.ts @@ -1,12 +1,17 @@ -interface IBar { - b: number; -} +//@noImplicitAny: true + +// verify no noImplictAny errors reported with cast expression + interface IFoo { - p: IBar[]; + a: number; + b: string; } -function foo(a: any) { } +// Expr type not assignable to target type +({ a: null }); -foo( { - p: null, -}); \ No newline at end of file +// Expr type assignanle to target type +({ a: 2, b: undefined }); + +// Niether types is assignable to each other +({ c: null }); \ No newline at end of file From b3260653cefa140c3482b6c6464369d4b838b468 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 5 Sep 2014 16:45:30 -0700 Subject: [PATCH 03/17] move getWidenedType* functions inside the getWidenedType function scope --- src/compiler/checker.ts | 100 ++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 932c8496694..289ff68bc40 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3132,45 +3132,6 @@ module ts { return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; } - function getWidenedTypeOfObjectLiteral(type: Type, supressNoImplicitAnyErrors?: boolean): Type { - var properties = getPropertiesOfType(type); - if (properties.length) { - var widenedTypes: Type[] = []; - var propTypeWasWidened: boolean = false; - forEach(properties, p => { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - propTypeWasWidened = true; - - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { - error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); - } - } - widenedTypes.push(widenedType); - }); - if (propTypeWasWidened) { - var members: SymbolTable = {}; - var index = 0; - forEach(properties, p => { - var symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedTypes[index++]; - symbol.target = p; - if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration; - members[symbol.name] = symbol; - }); - var stringIndexType = getIndexTypeOfType(type, IndexKind.String); - var numberIndexType = getIndexTypeOfType(type, IndexKind.Number); - if (stringIndexType) stringIndexType = getWidenedType(stringIndexType); - if (numberIndexType) numberIndexType = getWidenedType(numberIndexType); - type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); - } - } - return type; - } - function isArrayType(type: Type): boolean { return type.flags & TypeFlags.Reference && (type).target === globalArrayType; } @@ -3183,27 +3144,66 @@ module ts { return type; } - function getWidenedTypeOfArrayLiteral(type: Type, supressNoImplicitAnyErrors?: boolean): Type { - var elementType = (type).typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); - - type = elementType !== widenedType ? createArrayType(widenedType) : type; - - return type; - } - /* If we are widening on a literal, then we may need to the 'node' parameter for reporting purposes */ function getWidenedType(type: Type, supressNoImplicitAnyErrors?: boolean): Type { if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) { return anyType; } if (isTypeOfObjectLiteral(type)) { - return getWidenedTypeOfObjectLiteral(type, supressNoImplicitAnyErrors); + return getWidenedTypeOfObjectLiteral(type); } if (isArrayType(type)) { - return getWidenedTypeOfArrayLiteral(type, supressNoImplicitAnyErrors); + return getWidenedTypeOfArrayLiteral(type); } return type; + + function getWidenedTypeOfObjectLiteral(type: Type): Type { + var properties = getPropertiesOfType(type); + if (properties.length) { + var widenedTypes: Type[] = []; + var propTypeWasWidened: boolean = false; + forEach(properties, p => { + var propType = getTypeOfSymbol(p); + var widenedType = getWidenedType(propType); + if (propType !== widenedType) { + propTypeWasWidened = true; + + if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); + } + } + widenedTypes.push(widenedType); + }); + if (propTypeWasWidened) { + var members: SymbolTable = {}; + var index = 0; + forEach(properties, p => { + var symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, p.name); + symbol.declarations = p.declarations; + symbol.parent = p.parent; + symbol.type = widenedTypes[index++]; + symbol.target = p; + if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration; + members[symbol.name] = symbol; + }); + var stringIndexType = getIndexTypeOfType(type, IndexKind.String); + var numberIndexType = getIndexTypeOfType(type, IndexKind.Number); + if (stringIndexType) stringIndexType = getWidenedType(stringIndexType); + if (numberIndexType) numberIndexType = getWidenedType(numberIndexType); + type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); + } + } + return type; + } + + function getWidenedTypeOfArrayLiteral(type: Type): Type { + var elementType = (type).typeArguments[0]; + var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + + type = elementType !== widenedType ? createArrayType(widenedType) : type; + + return type; + } } function forEachMatchingParameterType(source: Signature, target: Signature, callback: (s: Type, t: Type) => void) { From 4f21fb59a2f45a392ef879f33afed21f27b68c89 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 8 Sep 2014 12:08:15 -0700 Subject: [PATCH 04/17] fix typo --- .../reference/noImplicitAnyInCastExpression.errors.txt | 4 ++-- .../baselines/reference/noImplicitAnyInCastExpression.js | 8 ++++---- tests/cases/compiler/noImplicitAnyInCastExpression.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt index 271f869360f..bc7542df511 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt @@ -10,10 +10,10 @@ // Expr type not assignable to target type ({ a: null }); - // Expr type assignanle to target type + // Expr type assignable to target type ({ a: 2, b: undefined }); - // Niether types is assignable to each other + // Neither types is assignable to each other ({ c: null }); ~~~~~~~~~~~~~~~~~ !!! Neither type '{ c: null; }' nor type 'IFoo' is assignable to the other: diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.js b/tests/baselines/reference/noImplicitAnyInCastExpression.js index 6501d17a5fe..1b7cc59c7c0 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.js +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.js @@ -10,17 +10,17 @@ interface IFoo { // Expr type not assignable to target type ({ a: null }); -// Expr type assignanle to target type +// Expr type assignable to target type ({ a: 2, b: undefined }); -// Niether types is assignable to each other +// Neither types is assignable to each other ({ c: null }); //// [noImplicitAnyInCastExpression.js] // verify no noImplictAny errors reported with cast expression // Expr type not assignable to target type { a: null }; -// Expr type assignanle to target type +// Expr type assignable to target type { a: 2, b: undefined }; -// Niether types is assignable to each other +// Neither types is assignable to each other { c: null }; diff --git a/tests/cases/compiler/noImplicitAnyInCastExpression.ts b/tests/cases/compiler/noImplicitAnyInCastExpression.ts index afbdfa1ec1e..5566b898a07 100644 --- a/tests/cases/compiler/noImplicitAnyInCastExpression.ts +++ b/tests/cases/compiler/noImplicitAnyInCastExpression.ts @@ -10,8 +10,8 @@ interface IFoo { // Expr type not assignable to target type ({ a: null }); -// Expr type assignanle to target type +// Expr type assignable to target type ({ a: 2, b: undefined }); -// Niether types is assignable to each other +// Neither types is assignable to each other ({ c: null }); \ No newline at end of file From 9f3d83adebe5c5700b72aa2581debe2d2f7edc73 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 8 Sep 2014 16:14:43 -0700 Subject: [PATCH 05/17] Truncate long types in error messages --- src/compiler/checker.ts | 28 +++++++++++++++---- src/compiler/types.ts | 10 +++---- src/harness/typeWriter.ts | 2 +- .../reference/arrayTypeOfTypeOf.errors.txt | 4 +-- ...gnmentCompatWithCallSignatures4.errors.txt | 4 +-- ...tCompatWithConstructSignatures4.errors.txt | 12 ++++---- ...tureAssignabilityInInheritance3.errors.txt | 2 +- ...tureAssignabilityInInheritance3.errors.txt | 2 +- ...errorMessageOnObjectLiteralType.errors.txt | 2 +- ...rConstrainsPropertyDeclarations.errors.txt | 2 +- .../reference/propertyAccess.errors.txt | 2 +- .../reference/redefineArray.errors.txt | 2 +- ...rConstrainsPropertyDeclarations.errors.txt | 2 +- .../baselines/reference/typeName1.errors.txt | 4 +-- 14 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ab8e3655541..007a935a4ae 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -943,20 +943,36 @@ module ts { writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); } - function createSingleLineTextWriter() { + function createSingleLineTextWriter(maxLength?: number) { var result = ""; + var overflow = false; + function write(s: string) { + if (!overflow) { + result += s; + if (result.length > maxLength) { + result = result.substr(0, maxLength - 3) + "..."; + overflow = true; + } + } + } return { - write(s: string) { result += s; }, - writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); }, - writeLine() { result += " "; }, + write: write, + writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); + }, + writeLine() { + write(" "); + }, increaseIndent() { }, decreaseIndent() { }, - getText() { return result; } + getText() { + return result; + } }; } function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { - var stringWriter = createSingleLineTextWriter(); + var stringWriter = createSingleLineTextWriter(flags & TypeFormatFlags.NoTruncation ? undefined : 100); // TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); return stringWriter.getText(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 922db40cdec..c156e3181c1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -631,12 +631,10 @@ module ts { } export enum TypeFormatFlags { - None = 0x00000000, - - /** writes Array instead T[] */ - WriteArrayAsGenericType = 0x00000001, // Declarations - - UseTypeOfFunction = 0x00000002, // instead of writing signature type of function use typeof + None = 0x00000000, + WriteArrayAsGenericType = 0x00000001, // Write Array instead T[] + UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal + NoTruncation = 0x00000004, // Don't truncate typeToString result } export enum SymbolAccessibility { diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index a3b23d10f14..8fac5e45dab 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -86,7 +86,7 @@ class TypeWriterWalker { column: lineAndCharacter.character, syntaxKind: ts.SyntaxKind[node.kind], sourceText: sourceText, - type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.None) + type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation) }); } diff --git a/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt b/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt index cb877f5e57b..c0a826e06a0 100644 --- a/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt +++ b/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt @@ -10,7 +10,7 @@ ~ !!! Expression expected. ~~~ -!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arrayLength?: number): any[]; new (arrayLength: number): T[]; new (...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }': +!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arr...': !!! Property 'isArray' is missing in type 'Number'. var xs4: typeof Array; ~ @@ -18,4 +18,4 @@ ~ !!! Expression expected. ~~~ -!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arrayLength?: number): any[]; new (arrayLength: number): T[]; new (...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }'. \ No newline at end of file +!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arr...'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt index 973dfe92ca2..5fc04ea8d90 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt @@ -52,7 +52,7 @@ var b8: (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; a8 = b8; // error, { foo: number } and Base are incompatible ~~ -!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: @@ -61,7 +61,7 @@ !!! Type 'number' is not assignable to type 'string'. b8 = a8; // error, { foo: number } and Base are incompatible ~~ -!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U': +!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any': !!! Types of parameters 'arg2' and 'arg2' are incompatible: diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt index c5055b16e89..9c895e57f08 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt @@ -52,7 +52,7 @@ var b8: new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; a8 = b8; // error, type mismatch ~~ -!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: @@ -61,7 +61,7 @@ !!! Type 'number' is not assignable to type 'string'. b8 = a8; // error ~~ -!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U': +!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any': !!! Types of parameters 'arg2' and 'arg2' are incompatible: @@ -93,24 +93,24 @@ var b16: new (x: (a: T) => T) => T[]; a16 = b16; // error ~~~ -!!! Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }': +!!! Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'. b16 = a16; // error ~~~ -!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }' is not assignable to type 'new (x: (a: T) => T) => T[]': +!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...' is not assignable to type 'new (x: (a: T) => T) => T[]': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '{ new (a: number): number; new (a?: number): number; }' is not assignable to type '(a: any) => any'. var b17: new (x: (a: T) => T) => any[]; a17 = b17; // error ~~~ -!!! Type 'new (x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: { new (a: T): T; new (a: T): T; }): any[]; }': +!!! Type 'new (x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: {...': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '(a: any) => any' is not assignable to type '{ new (a: T): T; new (a: T): T; }'. b17 = a17; // error ~~~ -!!! Type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: { new (a: T): T; new (a: T): T; }): any[]; }' is not assignable to type 'new (x: (a: T) => T) => any[]': +!!! Type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: {...' is not assignable to type 'new (x: (a: T) => T) => any[]': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '{ new (a: T): T; new (a: T): T; }' is not assignable to type '(a: any) => any'. } diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt index 81cd8b924f0..f7798de7d1d 100644 --- a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt @@ -68,7 +68,7 @@ ~~ !!! Interface 'I4' incorrectly extends interface 'A': !!! Types of property 'a8' are incompatible: -!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt index 2d267d5a260..29bc90a6bdf 100644 --- a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt @@ -58,7 +58,7 @@ ~~ !!! Interface 'I4' incorrectly extends interface 'A': !!! Types of property 'a8' are incompatible: -!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: diff --git a/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt b/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt index 9b19634265d..5172fb47ec3 100644 --- a/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt +++ b/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt @@ -8,4 +8,4 @@ !!! Property 'getOwnPropertyNamess' does not exist on type '{ a: string; b: number; }'. Object.getOwnPropertyNamess(null); ~~~~~~~~~~~~~~~~~~~~ -!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }'. \ No newline at end of file +!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any...'. \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 1a74ee37809..ed088598bab 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -98,7 +98,7 @@ // error var b: { [x: number]: string; } = { ~ -!!! Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +!!! Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e...' is not assignable to type '{ [x: number]: string; }': !!! Index signatures are incompatible: !!! Type '{}' is not assignable to type 'string'. a: '', diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index acb32459571..29a62c3fe8c 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -41,7 +41,7 @@ // Dotted property access of property that doesn't exist on value's apparent type var cc = obj.qqq; // error ~~~ -!!! Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'. +!!! Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal prop...'. // Bracket notation property access using string literal value on type with property of that literal name var dd = obj['literal property']; diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 5ac77d01f63..35d118de6ff 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -1,5 +1,5 @@ ==== tests/cases/compiler/redefineArray.ts (1 errors) ==== Array = function (n:number, s:string) {return n;}; ~~~~~ -!!! Type '(n: number, s: string) => number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arrayLength?: number): any[]; new (arrayLength: number): T[]; new (...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }': +!!! Type '(n: number, s: string) => number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arr...': !!! Property 'isArray' is missing in type '(n: number, s: string) => number'. \ No newline at end of file diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index 5ccca110ce8..894a83fc88a 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -128,7 +128,7 @@ // error var b: { [x: string]: string; } = { ~ -!!! Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +!!! Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e...' is not assignable to type '{ [x: string]: string; }': !!! Index signatures are incompatible: !!! Type '{}' is not assignable to type 'string'. a: '', diff --git a/tests/baselines/reference/typeName1.errors.txt b/tests/baselines/reference/typeName1.errors.txt index 92b3279ab81..8deb7dc43d6 100644 --- a/tests/baselines/reference/typeName1.errors.txt +++ b/tests/baselines/reference/typeName1.errors.txt @@ -24,7 +24,7 @@ !!! Property 'x' is missing in type 'Number'. var x5:{ (s:string):number;(n:number):string;x;y;z:number;f(n:number):string;f(s:string):number; }=3; ~~ -!!! Type 'number' is not assignable to type '{ (s: string): number; (n: number): string; x: any; y: any; z: number; f(n: number): string; f(s: string): number; }': +!!! Type 'number' is not assignable to type '{ (s: string): number; (n: number): string; x: any; y: any; z: number; f(n: number): string; f(s:...': !!! Property 'x' is missing in type 'Number'. var x6:{ z:number;f:{(n:number):string;(s:string):number;}; }=3; ~~ @@ -53,7 +53,7 @@ !!! Property 'length' is missing in type 'Number'. var x12:{z:I;x:boolean;y:(s:string)=>boolean;w:{ z:I;[s:string]:{ x; y; };[n:number]:{x; y;};():boolean; };}[][]=3; ~~~ -!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }; [x: number]: { x: any; y: any; }; z: I; }; }[][]': +!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }...': !!! Property 'length' is missing in type 'Number'. var x13:{ new(): number; new(n:number):number; x: string; w: {y: number;}; (): {}; } = 3; ~~~ From f61d07db69487d55ddec411ad0ff98f53f4b5102 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 8 Sep 2014 22:30:01 -0700 Subject: [PATCH 06/17] add constructor paramters to Blob --- src/lib/dom.generated.d.ts | 29 +++++++++++++++++------------ src/lib/webworker.generated.d.ts | 7 ++++++- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 3a093bcfaf4..53f21708b3f 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -1886,6 +1886,23 @@ declare var HTMLCollection: { new(): HTMLCollection; } +interface BlobPropertyBag { + type?: string; + endings?: string; +} + +interface Blob { + type: string; + size: number; + msDetachStream(): any; + slice(start?: number, end?: number, contentType?: string): Blob; + msClose(): void; +} +declare var Blob: { + prototype: Blob; + new (blobParts?: any[], options?: BlobPropertyBag): Blob; +} + interface NavigatorID { appVersion: string; appName: string; @@ -10027,18 +10044,6 @@ declare var FileReader: { new(): FileReader; } -interface Blob { - type: string; - size: number; - msDetachStream(): any; - slice(start?: number, end?: number, contentType?: string): Blob; - msClose(): void; -} -declare var Blob: { - prototype: Blob; - new(): Blob; -} - interface ApplicationCache extends EventTarget { status: number; ondownloading: (ev: Event) => any; diff --git a/src/lib/webworker.generated.d.ts b/src/lib/webworker.generated.d.ts index 5dfaa2f646f..a6119989164 100644 --- a/src/lib/webworker.generated.d.ts +++ b/src/lib/webworker.generated.d.ts @@ -614,6 +614,11 @@ declare var FileReader: { new(): FileReader; } +interface BlobPropertyBag { + type?: string; + endings?: string; +} + interface Blob { type: string; size: number; @@ -623,7 +628,7 @@ interface Blob { } declare var Blob: { prototype: Blob; - new(): Blob; + new (blobParts?: any[], options?: BlobPropertyBag): Blob; } interface MSStream { From aa58dcbee048e7bdc17e6dfad8e20571a8183e61 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Sep 2014 12:25:03 -0700 Subject: [PATCH 07/17] Adding noErrorTruncation compiler option --- src/compiler/checker.ts | 27 ++++++++++--------- src/compiler/types.ts | 2 +- src/harness/harness.ts | 7 ++++- .../reference/arrayTypeOfTypeOf.errors.txt | 4 +-- ...gnmentCompatWithCallSignatures4.errors.txt | 4 +-- ...tCompatWithConstructSignatures4.errors.txt | 12 ++++----- ...tureAssignabilityInInheritance3.errors.txt | 2 +- ...tureAssignabilityInInheritance3.errors.txt | 2 +- ...errorMessageOnObjectLiteralType.errors.txt | 2 +- .../errorWithTruncatedType.errors.txt | 15 +++++++++++ .../reference/errorWithTruncatedType.js | 18 +++++++++++++ ...rConstrainsPropertyDeclarations.errors.txt | 2 +- .../reference/propertyAccess.errors.txt | 2 +- .../reference/redefineArray.errors.txt | 2 +- ...rConstrainsPropertyDeclarations.errors.txt | 2 +- .../baselines/reference/typeName1.errors.txt | 4 +-- .../cases/compiler/errorWithTruncatedType.ts | 12 +++++++++ 17 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 tests/baselines/reference/errorWithTruncatedType.errors.txt create mode 100644 tests/baselines/reference/errorWithTruncatedType.js create mode 100644 tests/cases/compiler/errorWithTruncatedType.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 007a935a4ae..52860bc0209 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37,7 +37,9 @@ module ts { var emptyArray: any[] = []; var emptySymbols: SymbolTable = {}; - + + var compilerOptions = program.getCompilerOptions(); + var checker: TypeChecker = { getProgram: () => program, getDiagnostics: getDiagnostics, @@ -972,7 +974,8 @@ module ts { } function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { - var stringWriter = createSingleLineTextWriter(flags & TypeFormatFlags.NoTruncation ? undefined : 100); + var maxLength = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation ? undefined : 100; + var stringWriter = createSingleLineTextWriter(maxLength); // TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); return stringWriter.getText(); @@ -1364,7 +1367,7 @@ module ts { return type; function checkImplicitAny(type: Type) { - if (!fullTypeCheck || !program.getCompilerOptions().noImplicitAny) { + if (!fullTypeCheck || !compilerOptions.noImplicitAny) { return; } // We need to have ended up with 'any', 'any[]', 'any[][]', etc. @@ -1467,7 +1470,7 @@ module ts { } // Otherwise, fall back to 'any'. else { - if (program.getCompilerOptions().noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbol.name); } @@ -3159,7 +3162,7 @@ module ts { if (propType !== widenedType) { propTypeWasWidened = true; - if (program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -3987,7 +3990,7 @@ module ts { } // Fall back to any. - if (program.getCompilerOptions().noImplicitAny && objectType !== anyType) { + if (compilerOptions.noImplicitAny && objectType !== anyType) { error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } @@ -4332,7 +4335,7 @@ module ts { var declaration = signature.declaration; if (declaration && (declaration.kind !== SyntaxKind.Constructor && declaration.kind !== SyntaxKind.ConstructSignature)) { // When resolved signature is a call signature (and not a construct signature) the result type is any - if (program.getCompilerOptions().noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(node, Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } return anyType; @@ -4378,7 +4381,7 @@ module ts { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } @@ -4400,7 +4403,7 @@ module ts { var widenedType = getWidenedType(commonType); // Check and report for noImplicitAny if the best common type implicitly gets widened to an 'any'/arrays-of-'any' type. - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { @@ -4976,7 +4979,7 @@ module ts { checkCollisionWithCapturedThisVariable(node, node.name); checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); - if (program.getCompilerOptions().noImplicitAny && !node.type) { + if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { case SyntaxKind.ConstructSignature: error(node, Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); @@ -5532,7 +5535,7 @@ module ts { } // If there is no body and no explicit return type, then report an error. - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && !node.body && !node.type) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !node.body && !node.type) { // Ignore privates within ambient contexts; they exist purely for documentative purposes to avoid name clashing. // (e.g. privates within .d.ts files do not expose type information) if (!isPrivateWithinAmbient(node)) { @@ -7177,7 +7180,7 @@ module ts { function shouldEmitDeclarations() { // If the declaration emit and there are no errors being reported in program or by checker // declarations can be emitted - return program.getCompilerOptions().declaration && + return compilerOptions.declaration && !program.getDiagnostics().length && !getDiagnostics().length; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c156e3181c1..c13b47a066c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -955,6 +955,7 @@ module ts { locale?: string; mapRoot?: string; module?: ModuleKind; + noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; noLibCheck?: boolean; @@ -967,7 +968,6 @@ module ts { target?: ScriptTarget; version?: boolean; watch?: boolean; - [option: string]: any; } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 654f240b4b5..5ee3139d8f7 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -622,6 +622,7 @@ module Harness { options = options || { noResolve: false }; options.target = options.target || ts.ScriptTarget.ES3; options.module = options.module || ts.ModuleKind.None; + options.noErrorTruncation = true; if (settingsCallback) { settingsCallback(null); @@ -725,6 +726,10 @@ module Harness { options.emitBOM = !!setting.value; break; + case 'errortruncation': + options.noErrorTruncation = setting.value === 'false'; + break; + default: throw new Error('Unsupported compiler setting ' + setting.flag); } @@ -1030,7 +1035,7 @@ module Harness { var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines // List of allowed metadata names - var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom"]; + var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt b/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt index c0a826e06a0..cb877f5e57b 100644 --- a/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt +++ b/tests/baselines/reference/arrayTypeOfTypeOf.errors.txt @@ -10,7 +10,7 @@ ~ !!! Expression expected. ~~~ -!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arr...': +!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arrayLength?: number): any[]; new (arrayLength: number): T[]; new (...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }': !!! Property 'isArray' is missing in type 'Number'. var xs4: typeof Array; ~ @@ -18,4 +18,4 @@ ~ !!! Expression expected. ~~~ -!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arr...'. \ No newline at end of file +!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arrayLength?: number): any[]; new (arrayLength: number): T[]; new (...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt index 5fc04ea8d90..973dfe92ca2 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt @@ -52,7 +52,7 @@ var b8: (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; a8 = b8; // error, { foo: number } and Base are incompatible ~~ -!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: @@ -61,7 +61,7 @@ !!! Type 'number' is not assignable to type 'string'. b8 = a8; // error, { foo: number } and Base are incompatible ~~ -!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...': +!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any': !!! Types of parameters 'arg2' and 'arg2' are incompatible: diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt index 9c895e57f08..c5055b16e89 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt @@ -52,7 +52,7 @@ var b8: new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; a8 = b8; // error, type mismatch ~~ -!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: @@ -61,7 +61,7 @@ !!! Type 'number' is not assignable to type 'string'. b8 = a8; // error ~~ -!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...': +!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any': !!! Types of parameters 'arg2' and 'arg2' are incompatible: @@ -93,24 +93,24 @@ var b16: new (x: (a: T) => T) => T[]; a16 = b16; // error ~~~ -!!! Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...': +!!! Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'. b16 = a16; // error ~~~ -!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...' is not assignable to type 'new (x: (a: T) => T) => T[]': +!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }' is not assignable to type 'new (x: (a: T) => T) => T[]': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '{ new (a: number): number; new (a?: number): number; }' is not assignable to type '(a: any) => any'. var b17: new (x: (a: T) => T) => any[]; a17 = b17; // error ~~~ -!!! Type 'new (x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: {...': +!!! Type 'new (x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: { new (a: T): T; new (a: T): T; }): any[]; }': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '(a: any) => any' is not assignable to type '{ new (a: T): T; new (a: T): T; }'. b17 = a17; // error ~~~ -!!! Type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: {...' is not assignable to type 'new (x: (a: T) => T) => any[]': +!!! Type '{ new (x: { new (a: T): T; new (a: T): T; }): any[]; new (x: { new (a: T): T; new (a: T): T; }): any[]; }' is not assignable to type 'new (x: (a: T) => T) => any[]': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type '{ new (a: T): T; new (a: T): T; }' is not assignable to type '(a: any) => any'. } diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt index f7798de7d1d..81cd8b924f0 100644 --- a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt @@ -68,7 +68,7 @@ ~~ !!! Interface 'I4' incorrectly extends interface 'A': !!! Types of property 'a8' are incompatible: -!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt index 29bc90a6bdf..2d267d5a260 100644 --- a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt @@ -58,7 +58,7 @@ ~~ !!! Interface 'I4' incorrectly extends interface 'A': !!! Types of property 'a8' are incompatible: -!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': +!!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: diff --git a/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt b/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt index 5172fb47ec3..9b19634265d 100644 --- a/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt +++ b/tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt @@ -8,4 +8,4 @@ !!! Property 'getOwnPropertyNamess' does not exist on type '{ a: string; b: number; }'. Object.getOwnPropertyNamess(null); ~~~~~~~~~~~~~~~~~~~~ -!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any...'. \ No newline at end of file +!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }'. \ No newline at end of file diff --git a/tests/baselines/reference/errorWithTruncatedType.errors.txt b/tests/baselines/reference/errorWithTruncatedType.errors.txt new file mode 100644 index 00000000000..7d3cab5f3c5 --- /dev/null +++ b/tests/baselines/reference/errorWithTruncatedType.errors.txt @@ -0,0 +1,15 @@ +==== tests/cases/compiler/errorWithTruncatedType.ts (1 errors) ==== + + var x: { + propertyWithAnExceedinglyLongName1: string; + propertyWithAnExceedinglyLongName2: string; + propertyWithAnExceedinglyLongName3: string; + propertyWithAnExceedinglyLongName4: string; + propertyWithAnExceedinglyLongName5: string; + }; + + // String representation of type of 'x' should be truncated in error message + var s: string = x; + ~ +!!! Type '{ propertyWithAnExceedinglyLongName1: string; propertyWithAnExceedinglyLongName2: string; propert...' is not assignable to type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/errorWithTruncatedType.js b/tests/baselines/reference/errorWithTruncatedType.js new file mode 100644 index 00000000000..5fd45579a29 --- /dev/null +++ b/tests/baselines/reference/errorWithTruncatedType.js @@ -0,0 +1,18 @@ +//// [errorWithTruncatedType.ts] + +var x: { + propertyWithAnExceedinglyLongName1: string; + propertyWithAnExceedinglyLongName2: string; + propertyWithAnExceedinglyLongName3: string; + propertyWithAnExceedinglyLongName4: string; + propertyWithAnExceedinglyLongName5: string; +}; + +// String representation of type of 'x' should be truncated in error message +var s: string = x; + + +//// [errorWithTruncatedType.js] +var x; +// String representation of type of 'x' should be truncated in error message +var s = x; diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index ed088598bab..1a74ee37809 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -98,7 +98,7 @@ // error var b: { [x: number]: string; } = { ~ -!!! Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e...' is not assignable to type '{ [x: number]: string; }': +!!! Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': !!! Index signatures are incompatible: !!! Type '{}' is not assignable to type 'string'. a: '', diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index 29a62c3fe8c..acb32459571 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -41,7 +41,7 @@ // Dotted property access of property that doesn't exist on value's apparent type var cc = obj.qqq; // error ~~~ -!!! Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal prop...'. +!!! Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'. // Bracket notation property access using string literal value on type with property of that literal name var dd = obj['literal property']; diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 35d118de6ff..5ac77d01f63 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -1,5 +1,5 @@ ==== tests/cases/compiler/redefineArray.ts (1 errors) ==== Array = function (n:number, s:string) {return n;}; ~~~~~ -!!! Type '(n: number, s: string) => number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arr...': +!!! Type '(n: number, s: string) => number' is not assignable to type '{ (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; new (arrayLength?: number): any[]; new (arrayLength: number): T[]; new (...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }': !!! Property 'isArray' is missing in type '(n: number, s: string) => number'. \ No newline at end of file diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index 894a83fc88a..5ccca110ce8 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -128,7 +128,7 @@ // error var b: { [x: string]: string; } = { ~ -!!! Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e...' is not assignable to type '{ [x: string]: string; }': +!!! Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': !!! Index signatures are incompatible: !!! Type '{}' is not assignable to type 'string'. a: '', diff --git a/tests/baselines/reference/typeName1.errors.txt b/tests/baselines/reference/typeName1.errors.txt index 8deb7dc43d6..92b3279ab81 100644 --- a/tests/baselines/reference/typeName1.errors.txt +++ b/tests/baselines/reference/typeName1.errors.txt @@ -24,7 +24,7 @@ !!! Property 'x' is missing in type 'Number'. var x5:{ (s:string):number;(n:number):string;x;y;z:number;f(n:number):string;f(s:string):number; }=3; ~~ -!!! Type 'number' is not assignable to type '{ (s: string): number; (n: number): string; x: any; y: any; z: number; f(n: number): string; f(s:...': +!!! Type 'number' is not assignable to type '{ (s: string): number; (n: number): string; x: any; y: any; z: number; f(n: number): string; f(s: string): number; }': !!! Property 'x' is missing in type 'Number'. var x6:{ z:number;f:{(n:number):string;(s:string):number;}; }=3; ~~ @@ -53,7 +53,7 @@ !!! Property 'length' is missing in type 'Number'. var x12:{z:I;x:boolean;y:(s:string)=>boolean;w:{ z:I;[s:string]:{ x; y; };[n:number]:{x; y;};():boolean; };}[][]=3; ~~~ -!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }...': +!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }; [x: number]: { x: any; y: any; }; z: I; }; }[][]': !!! Property 'length' is missing in type 'Number'. var x13:{ new(): number; new(n:number):number; x: string; w: {y: number;}; (): {}; } = 3; ~~~ diff --git a/tests/cases/compiler/errorWithTruncatedType.ts b/tests/cases/compiler/errorWithTruncatedType.ts new file mode 100644 index 00000000000..307ff642ed9 --- /dev/null +++ b/tests/cases/compiler/errorWithTruncatedType.ts @@ -0,0 +1,12 @@ +// @errortruncation: true + +var x: { + propertyWithAnExceedinglyLongName1: string; + propertyWithAnExceedinglyLongName2: string; + propertyWithAnExceedinglyLongName3: string; + propertyWithAnExceedinglyLongName4: string; + propertyWithAnExceedinglyLongName5: string; +}; + +// String representation of type of 'x' should be truncated in error message +var s: string = x; From a62e7d218d861cba32b2aa8203fd20a55a015c43 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 9 Sep 2014 12:26:49 -0700 Subject: [PATCH 08/17] Update LKG --- bin/lib.d.ts | 109 +-- bin/lib.dom.d.ts | 109 +-- bin/lib.webworker.d.ts | 7 +- bin/tsc.js | 570 ++++++++----- bin/typescriptServices.js | 1683 ++++++++++++++++++++++++------------- 5 files changed, 1552 insertions(+), 926 deletions(-) diff --git a/bin/lib.d.ts b/bin/lib.d.ts index a3081f2c8d7..ebf92241aff 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -3807,30 +3807,42 @@ declare var Window: { new(): Window; } -interface FormData { - append(name: any, value: any, blobName?: string): void; +interface HTMLCollection extends MSHTMLCollectionExtensions { + /** + * Sets or retrieves the number of objects in a collection. + */ + length: number; + /** + * Retrieves an object from various collections. + */ + item(nameOrIndex?: any, optionalIndex?: any): Element; + /** + * Retrieves a select object or an object from an options collection. + */ + namedItem(name: string): Element; + // [name: string]: Element; + [index: number]: Element; } -declare var FormData: { - prototype: FormData; - new (form?: HTMLFormElement): FormData; +declare var HTMLCollection: { + prototype: HTMLCollection; + new(): HTMLCollection; } -interface SourceBuffer extends EventTarget { - updating: boolean; - appendWindowStart: number; - appendWindowEnd: number; - buffered: TimeRanges; - timestampOffset: number; - audioTracks: AudioTrackList; - appendBuffer(data: ArrayBufferView): void; - appendBuffer(data: ArrayBuffer): void; - remove(start: number, end: number): void; - abort(): void; - appendStream(stream: MSStream, maxSize?: number): void; +interface BlobPropertyBag { + type?: string; + endings?: string; } -declare var SourceBuffer: { - prototype: SourceBuffer; - new(): SourceBuffer; + +interface Blob { + type: string; + size: number; + msDetachStream(): any; + slice(start?: number, end?: number, contentType?: string): Blob; + msClose(): void; +} +declare var Blob: { + prototype: Blob; + new (blobParts?: any[], options?: BlobPropertyBag): Blob; } interface NavigatorID { @@ -5739,26 +5751,6 @@ declare var MSCSSProperties: { new(): MSCSSProperties; } -interface HTMLCollection extends MSHTMLCollectionExtensions { - /** - * Sets or retrieves the number of objects in a collection. - */ - length: number; - /** - * Retrieves an object from various collections. - */ - item(nameOrIndex?: any, optionalIndex?: any): Element; - /** - * Retrieves a select object or an object from an options collection. - */ - namedItem(name: string): Element; - // [name: string]: Element; -} -declare var HTMLCollection: { - prototype: HTMLCollection; - new(): HTMLCollection; -} - interface SVGExternalResourcesRequired { externalResourcesRequired: SVGAnimatedBoolean; } @@ -11994,18 +11986,6 @@ declare var FileReader: { new(): FileReader; } -interface Blob { - type: string; - size: number; - msDetachStream(): any; - slice(start?: number, end?: number, contentType?: string): Blob; - msClose(): void; -} -declare var Blob: { - prototype: Blob; - new(): Blob; -} - interface ApplicationCache extends EventTarget { status: number; ondownloading: (ev: Event) => any; @@ -12164,6 +12144,14 @@ declare var MSManipulationEvent: { MS_MANIPULATION_STATE_CANCELLED: number; } +interface FormData { + append(name: any, value: any, blobName?: string): void; +} +declare var FormData: { + prototype: FormData; + new(): FormData; +} + interface HTMLDataListElement extends HTMLElement { options: HTMLCollection; } @@ -12582,6 +12570,23 @@ interface RandomSource { getRandomValues(array: ArrayBufferView): ArrayBufferView; } +interface SourceBuffer extends EventTarget { + updating: boolean; + appendWindowStart: number; + appendWindowEnd: number; + buffered: TimeRanges; + timestampOffset: number; + audioTracks: AudioTrackList; + appendBuffer(data: ArrayBuffer): void; + remove(start: number, end: number): void; + abort(): void; + appendStream(stream: MSStream, maxSize?: number): void; +} +declare var SourceBuffer: { + prototype: SourceBuffer; + new(): SourceBuffer; +} + interface MSInputMethodContext extends EventTarget { oncandidatewindowshow: (ev: any) => any; target: HTMLElement; diff --git a/bin/lib.dom.d.ts b/bin/lib.dom.d.ts index c0aceb3fc11..0fe2922830a 100644 --- a/bin/lib.dom.d.ts +++ b/bin/lib.dom.d.ts @@ -2704,30 +2704,42 @@ declare var Window: { new(): Window; } -interface FormData { - append(name: any, value: any, blobName?: string): void; +interface HTMLCollection extends MSHTMLCollectionExtensions { + /** + * Sets or retrieves the number of objects in a collection. + */ + length: number; + /** + * Retrieves an object from various collections. + */ + item(nameOrIndex?: any, optionalIndex?: any): Element; + /** + * Retrieves a select object or an object from an options collection. + */ + namedItem(name: string): Element; + // [name: string]: Element; + [index: number]: Element; } -declare var FormData: { - prototype: FormData; - new (form?: HTMLFormElement): FormData; +declare var HTMLCollection: { + prototype: HTMLCollection; + new(): HTMLCollection; } -interface SourceBuffer extends EventTarget { - updating: boolean; - appendWindowStart: number; - appendWindowEnd: number; - buffered: TimeRanges; - timestampOffset: number; - audioTracks: AudioTrackList; - appendBuffer(data: ArrayBufferView): void; - appendBuffer(data: ArrayBuffer): void; - remove(start: number, end: number): void; - abort(): void; - appendStream(stream: MSStream, maxSize?: number): void; +interface BlobPropertyBag { + type?: string; + endings?: string; } -declare var SourceBuffer: { - prototype: SourceBuffer; - new(): SourceBuffer; + +interface Blob { + type: string; + size: number; + msDetachStream(): any; + slice(start?: number, end?: number, contentType?: string): Blob; + msClose(): void; +} +declare var Blob: { + prototype: Blob; + new (blobParts?: any[], options?: BlobPropertyBag): Blob; } interface NavigatorID { @@ -4636,26 +4648,6 @@ declare var MSCSSProperties: { new(): MSCSSProperties; } -interface HTMLCollection extends MSHTMLCollectionExtensions { - /** - * Sets or retrieves the number of objects in a collection. - */ - length: number; - /** - * Retrieves an object from various collections. - */ - item(nameOrIndex?: any, optionalIndex?: any): Element; - /** - * Retrieves a select object or an object from an options collection. - */ - namedItem(name: string): Element; - // [name: string]: Element; -} -declare var HTMLCollection: { - prototype: HTMLCollection; - new(): HTMLCollection; -} - interface SVGExternalResourcesRequired { externalResourcesRequired: SVGAnimatedBoolean; } @@ -10891,18 +10883,6 @@ declare var FileReader: { new(): FileReader; } -interface Blob { - type: string; - size: number; - msDetachStream(): any; - slice(start?: number, end?: number, contentType?: string): Blob; - msClose(): void; -} -declare var Blob: { - prototype: Blob; - new(): Blob; -} - interface ApplicationCache extends EventTarget { status: number; ondownloading: (ev: Event) => any; @@ -11061,6 +11041,14 @@ declare var MSManipulationEvent: { MS_MANIPULATION_STATE_CANCELLED: number; } +interface FormData { + append(name: any, value: any, blobName?: string): void; +} +declare var FormData: { + prototype: FormData; + new(): FormData; +} + interface HTMLDataListElement extends HTMLElement { options: HTMLCollection; } @@ -11479,6 +11467,23 @@ interface RandomSource { getRandomValues(array: ArrayBufferView): ArrayBufferView; } +interface SourceBuffer extends EventTarget { + updating: boolean; + appendWindowStart: number; + appendWindowEnd: number; + buffered: TimeRanges; + timestampOffset: number; + audioTracks: AudioTrackList; + appendBuffer(data: ArrayBuffer): void; + remove(start: number, end: number): void; + abort(): void; + appendStream(stream: MSStream, maxSize?: number): void; +} +declare var SourceBuffer: { + prototype: SourceBuffer; + new(): SourceBuffer; +} + interface MSInputMethodContext extends EventTarget { oncandidatewindowshow: (ev: any) => any; target: HTMLElement; diff --git a/bin/lib.webworker.d.ts b/bin/lib.webworker.d.ts index 654d75b0aa9..02485d2602a 100644 --- a/bin/lib.webworker.d.ts +++ b/bin/lib.webworker.d.ts @@ -1453,6 +1453,11 @@ declare var FileReader: { new(): FileReader; } +interface BlobPropertyBag { + type?: string; + endings?: string; +} + interface Blob { type: string; size: number; @@ -1462,7 +1467,7 @@ interface Blob { } declare var Blob: { prototype: Blob; - new(): Blob; + new (blobParts?: any[], options?: BlobPropertyBag): Blob; } interface MSStream { diff --git a/bin/tsc.js b/bin/tsc.js index 5efd7065d8e..98e690a82e0 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -267,6 +267,7 @@ var ts; Import_name_cannot_be_0: { code: 2438, category: 1 /* Error */, key: "Import name cannot be '{0}'" }, Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: 1 /* Error */, key: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name." }, Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: 1 /* Error */, key: "Import declaration conflicts with local declaration of '{0}'" }, + Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: 1 /* Error */, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -566,7 +567,8 @@ var ts; var pos = 0; var lineStart = 0; while (pos < text.length) { - switch (text.charCodeAt(pos++)) { + var ch = text.charCodeAt(pos++); + switch (ch) { case 13 /* carriageReturn */: if (text.charCodeAt(pos) === 10 /* lineFeed */) { pos++; @@ -575,6 +577,12 @@ var ts; result.push(lineStart); lineStart = pos; break; + default: + if (ch > 127 /* maxAsciiCharacter */ && isLineBreak(ch)) { + result.push(lineStart); + lineStart = pos; + } + break; } } result.push(lineStart); @@ -608,7 +616,7 @@ var ts; } ts.isWhiteSpace = isWhiteSpace; function isLineBreak(ch) { - return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */; + return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */ || ch === 133 /* nextLine */; } ts.isLineBreak = isLineBreak; function isDigit(ch) { @@ -748,6 +756,14 @@ var ts; return getCommentRanges(text, pos, true); } ts.getTrailingComments = getTrailingComments; + function isIdentifierStart(ch, languageVersion) { + return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); + } + ts.isIdentifierStart = isIdentifierStart; + function isIdentifierPart(ch, languageVersion) { + return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); + } + ts.isIdentifierPart = isIdentifierPart; function createScanner(languageVersion, text, onError, onComment) { var pos; var len; @@ -2732,6 +2748,42 @@ var ts; return false; } ts.isInAmbientContext = isInAmbientContext; + function isDeclaration(node) { + switch (node.kind) { + case 113 /* TypeParameter */: + case 114 /* Parameter */: + case 166 /* VariableDeclaration */: + case 115 /* Property */: + case 129 /* PropertyAssignment */: + case 176 /* EnumMember */: + case 116 /* Method */: + case 167 /* FunctionDeclaration */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 169 /* ClassDeclaration */: + case 170 /* InterfaceDeclaration */: + case 171 /* EnumDeclaration */: + case 172 /* ModuleDeclaration */: + case 174 /* ImportDeclaration */: + return true; + } + return false; + } + ts.isDeclaration = isDeclaration; + function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { + if (name.kind !== 55 /* Identifier */ && name.kind !== 3 /* StringLiteral */ && name.kind !== 2 /* NumericLiteral */) { + return false; + } + var parent = name.parent; + if (isDeclaration(parent) || parent.kind === 136 /* FunctionExpression */) { + return parent.name === name; + } + if (parent.kind === 163 /* CatchBlock */) { + return parent.variable === name; + } + return false; + } + ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; var ParsingContext; (function (ParsingContext) { ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements"; @@ -2820,6 +2872,22 @@ var ts; ControlBlockContext[ControlBlockContext["Nested"] = 1] = "Nested"; ControlBlockContext[ControlBlockContext["CrossingFunctionBoundary"] = 2] = "CrossingFunctionBoundary"; })(ControlBlockContext || (ControlBlockContext = {})); + function isKeyword(token) { + return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; + } + ts.isKeyword = isKeyword; + function isModifier(token) { + switch (token) { + case 98 /* PublicKeyword */: + case 96 /* PrivateKeyword */: + case 99 /* StaticKeyword */: + case 68 /* ExportKeyword */: + case 104 /* DeclareKeyword */: + return true; + } + return false; + } + ts.isModifier = isModifier; function createSourceFile(filename, sourceText, languageVersion, version, isOpen) { if (isOpen === void 0) { isOpen = false; } var file; @@ -3054,12 +3122,15 @@ var ts; function createMissingNode() { return createNode(111 /* Missing */); } + function internIdentifier(text) { + return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); + } function createIdentifier(isIdentifier) { identifierCount++; if (isIdentifier) { var node = createNode(55 /* Identifier */); var text = escapeIdentifier(scanner.getTokenValue()); - node.text = ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); + node.text = internIdentifier(text); nextToken(); return finishNode(node); } @@ -3077,24 +3148,10 @@ var ts; } function parsePropertyName() { if (token === 3 /* StringLiteral */ || token === 2 /* NumericLiteral */) { - return parsePrimaryExpression(); + return parseLiteralNode(true); } return parseIdentifierName(); } - function isKeyword(token) { - return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; - } - function isModifier(token) { - switch (token) { - case 98 /* PublicKeyword */: - case 96 /* PrivateKeyword */: - case 99 /* StaticKeyword */: - case 68 /* ExportKeyword */: - case 104 /* DeclareKeyword */: - return true; - } - return false; - } function parseContextualModifier(t) { return token === t && tryParse(function () { nextToken(); @@ -3309,9 +3366,10 @@ var ts; nextToken(); return finishNode(node); } - function parseLiteralNode() { + function parseLiteralNode(internName) { var node = createNode(token); - node.text = scanner.getTokenValue(); + var text = scanner.getTokenValue(); + node.text = internName ? internIdentifier(text) : text; var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); @@ -3327,7 +3385,7 @@ var ts; } function parseStringLiteral() { if (token === 3 /* StringLiteral */) - return parseLiteralNode(); + return parseLiteralNode(true); error(ts.Diagnostics.String_literal_expected); return createMissingNode(); } @@ -3999,6 +4057,10 @@ var ts; } else { indexedAccess.index = parseExpression(); + if (indexedAccess.index.kind === 3 /* StringLiteral */ || indexedAccess.index.kind === 2 /* NumericLiteral */) { + var literal = indexedAccess.index; + literal.text = internIdentifier(literal.text); + } parseExpected(10 /* CloseBracketToken */); } expr = finishNode(indexedAccess); @@ -5304,6 +5366,7 @@ var ts; file.version = version; file.isOpen = isOpen; file.languageVersion = languageVersion; + file.identifiers = identifiers; return file; } ts.createSourceFile = createSourceFile; @@ -5368,18 +5431,17 @@ var ts; } function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) { var canonicalName = host.getCanonicalFileName(filename); - var file = getSourceFile(filename); - if (file) { - if (host.useCaseSensitiveFileNames() && canonicalName !== file.filename) { + if (ts.hasProperty(filesByName, canonicalName)) { + var file = filesByName[canonicalName]; + if (file && host.useCaseSensitiveFileNames() && canonicalName !== file.filename) { errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, file.filename)); } } else { - file = host.getSourceFile(filename, options.target, function (hostErrorMessage) { + var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); }); if (file) { - filesByName[host.getCanonicalFileName(filename)] = file; seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; if (!options.noResolve) { var basePath = ts.getDirectoryPath(filename); @@ -5904,18 +5966,10 @@ var ts; function writeLiteral(s) { if (s && s.length) { write(s); - var pos = 0; - while (pos < s.length) { - switch (s.charCodeAt(pos++)) { - case 13 /* carriageReturn */: - if (pos < s.length && s.charCodeAt(pos) === 10 /* lineFeed */) { - pos++; - } - case 10 /* lineFeed */: - lineCount++; - linePos = output.length - s.length + pos; - break; - } + var lineStartsOfS = ts.getLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; } } } @@ -6026,10 +6080,9 @@ var ts; } function calculateIndent(pos, end) { var currentLineIndent = 0; - while (pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos))) { - pos++; + for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) { - currentLineIndent += getIndentSize(); + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); } else { currentLineIndent++; @@ -7275,14 +7328,12 @@ var ts; return emitPinnedOrTripleSlashComments(node); } emitLeadingComments(node); - if (!(node.flags & 1 /* Export */)) { - emitStart(node); - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - } + emitStart(node); + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); emitStart(node); write("(function ("); emitStart(node.name); @@ -7306,21 +7357,15 @@ var ts; scopeEmitEnd(); } write(")("); + if (node.flags & 1 /* Export */) { + emit(node.name); + write(" = "); + } emitModuleMemberName(node); write(" || ("); emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } emitTrailingComments(node); } function emitImportDeclaration(node) { @@ -8327,39 +8372,43 @@ var ts; } } function resolveScriptReference(sourceFile, reference) { - var referenceFileName = compilerOptions.noResolve ? reference.filename : ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); + var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); return program.getSourceFile(referenceFileName); } var referencePathsOutput = ""; function writeReferencePath(referencedFile) { var declFileName = referencedFile.flags & 512 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts"; declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false); - referencePathsOutput += "/// " + newLine; + referencePathsOutput += "/// " + newLine; } if (root) { - var addedGlobalFileReference = false; - ts.forEach(root.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(root, fileReference); - if ((referencedFile.flags & 512 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile) || !addedGlobalFileReference) { - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; + if (!compilerOptions.noResolve) { + var addedGlobalFileReference = false; + ts.forEach(root.referencedFiles, function (fileReference) { + var referencedFile = resolveScriptReference(root, fileReference); + if ((referencedFile.flags & 512 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile) || !addedGlobalFileReference) { + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } } - } - }); + }); + } emitNode(root); } else { var emittedReferencedFiles = []; ts.forEach(program.getSourceFiles(), function (sourceFile) { if (!isExternalModuleOrDeclarationFile(sourceFile)) { - ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(sourceFile, fileReference); - if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); + if (!compilerOptions.noResolve) { + ts.forEach(sourceFile.referencedFiles, function (fileReference) { + var referencedFile = resolveScriptReference(sourceFile, fileReference); + if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } emitNode(sourceFile); } }); @@ -8409,6 +8458,17 @@ var ts; var nextSymbolId = 1; var nextNodeId = 1; var nextMergeId = 1; + function getDeclarationOfKind(symbol, kind) { + var declarations = symbol.declarations; + for (var i = 0; i < declarations.length; i++) { + var declaration = declarations[i]; + if (declaration.kind === kind) { + return declaration; + } + } + return undefined; + } + ts.getDeclarationOfKind = getDeclarationOfKind; function createTypeChecker(program, fullTypeCheck) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); @@ -8439,7 +8499,9 @@ var ts; getApparentType: getApparentType, typeToString: typeToString, symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType + getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, + getRootSymbol: getRootSymbol, + getContextualType: getContextualType }; var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments"); @@ -8887,16 +8949,6 @@ var ts; } return false; } - function getDeclarationOfKind(symbol, kind) { - var declarations = symbol.declarations; - for (var i = 0; i < declarations.length; i++) { - var declaration = declarations[i]; - if (declaration.kind === kind) { - return declaration; - } - } - return undefined; - } function findConstructorDeclaration(node) { var members = node.members; for (var i = 0; i < members.length; i++) { @@ -9917,27 +9969,38 @@ var ts; } function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; - var members = emptySymbols; - var callSignatures = emptyArray; - var constructSignatures = emptyArray; - if (symbol.flags & ts.SymbolFlags.HasExports) { - members = symbol.exports; + if (symbol.flags & 512 /* TypeLiteral */) { + var members = symbol.members; + var callSignatures = getSignaturesOfSymbol(members["__call"]); + var constructSignatures = getSignaturesOfSymbol(members["__new"]); + var stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */); + var numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */); } - if (symbol.flags & (8 /* Function */ | 2048 /* Method */)) { - callSignatures = getSignaturesOfSymbol(symbol); - } - if (symbol.flags & 16 /* Class */) { - var classType = getDeclaredTypeOfClass(symbol); - constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); - if (!constructSignatures.length) - constructSignatures = getDefaultConstructSignatures(classType); - if (classType.baseTypes.length) { - var members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + else { + var members = emptySymbols; + var callSignatures = emptyArray; + var constructSignatures = emptyArray; + if (symbol.flags & ts.SymbolFlags.HasExports) { + members = symbol.exports; } + if (symbol.flags & (8 /* Function */ | 2048 /* Method */)) { + callSignatures = getSignaturesOfSymbol(symbol); + } + if (symbol.flags & 16 /* Class */) { + var classType = getDeclaredTypeOfClass(symbol); + constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); + if (!constructSignatures.length) { + constructSignatures = getDefaultConstructSignatures(classType); + } + if (classType.baseTypes.length) { + members = createSymbolTable(getNamedMembers(members)); + addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + } + } + var stringIndexType = undefined; + var numberIndexType = (symbol.flags & 64 /* Enum */) ? stringType : undefined; } - var numberIndexType = (symbol.flags & 64 /* Enum */) ? stringType : undefined; - setObjectTypeMembers(type, members, callSignatures, constructSignatures, undefined, numberIndexType); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function resolveObjectTypeMembers(type) { if (!type.members) { @@ -10319,13 +10382,7 @@ var ts; function getTypeFromTypeLiteralNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var symbol = node.symbol; - var members = symbol.members; - var callSignatures = getSignaturesOfSymbol(members["__call"]); - var constructSignatures = getSignaturesOfSymbol(members["__new"]); - var stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */); - var numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */); - links.resolvedType = createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + links.resolvedType = createObjectType(8192 /* Anonymous */, node.symbol); } return links.resolvedType; } @@ -11054,45 +11111,6 @@ var ts; function isTypeOfObjectLiteral(type) { return (type.flags & 8192 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; } - function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfType(type); - if (properties.length) { - var widenedTypes = []; - var propTypeWasWidened = false; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - propTypeWasWidened = true; - if (program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { - error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); - } - } - widenedTypes.push(widenedType); - }); - if (propTypeWasWidened) { - var members = {}; - var index = 0; - ts.forEach(properties, function (p) { - var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedTypes[index++]; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - members[symbol.name] = symbol; - }); - var stringIndexType = getIndexTypeOfType(type, 0 /* String */); - var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); - if (stringIndexType) - stringIndexType = getWidenedType(stringIndexType); - if (numberIndexType) - numberIndexType = getWidenedType(numberIndexType); - type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); - } - } - return type; - } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; } @@ -11102,13 +11120,7 @@ var ts; } return type; } - function getWidenedTypeOfArrayLiteral(type) { - var elementType = type.typeArguments[0]; - var widenedType = getWidenedType(elementType); - type = elementType !== widenedType ? createArrayType(widenedType) : type; - return type; - } - function getWidenedType(type) { + function getWidenedType(type, supressNoImplicitAnyErrors) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } @@ -11119,6 +11131,52 @@ var ts; return getWidenedTypeOfArrayLiteral(type); } return type; + function getWidenedTypeOfObjectLiteral(type) { + var properties = getPropertiesOfType(type); + if (properties.length) { + var widenedTypes = []; + var propTypeWasWidened = false; + ts.forEach(properties, function (p) { + var propType = getTypeOfSymbol(p); + var widenedType = getWidenedType(propType); + if (propType !== widenedType) { + propTypeWasWidened = true; + if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); + } + } + widenedTypes.push(widenedType); + }); + if (propTypeWasWidened) { + var members = {}; + var index = 0; + ts.forEach(properties, function (p) { + var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); + symbol.declarations = p.declarations; + symbol.parent = p.parent; + symbol.type = widenedTypes[index++]; + symbol.target = p; + if (p.valueDeclaration) + symbol.valueDeclaration = p.valueDeclaration; + members[symbol.name] = symbol; + }); + var stringIndexType = getIndexTypeOfType(type, 0 /* String */); + var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); + if (stringIndexType) + stringIndexType = getWidenedType(stringIndexType); + if (numberIndexType) + numberIndexType = getWidenedType(numberIndexType); + type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); + } + } + return type; + } + function getWidenedTypeOfArrayLiteral(type) { + var elementType = type.typeArguments[0]; + var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + type = elementType !== widenedType ? createArrayType(widenedType) : type; + return type; + } } function forEachMatchingParameterType(source, target, callback) { var sourceMax = source.parameters.length; @@ -11652,6 +11710,7 @@ var ts; if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration; prop.type = type; + prop.target = member; member = prop; } else { @@ -12020,9 +12079,9 @@ var ts; var exprType = checkExpression(node.operand); var targetType = getTypeFromTypeNode(node.type); if (fullTypeCheck && targetType !== unknownType) { - var widenedType = getWidenedType(exprType); - if (!(isTypeAssignableTo(exprType, targetType) || isTypeAssignableTo(targetType, widenedType))) { - checkTypeAssignableTo(targetType, widenedType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + var widenedType = getWidenedType(exprType, true); + if (!(isTypeAssignableTo(targetType, widenedType))) { + checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; @@ -12162,26 +12221,26 @@ var ts; } } } + checkSignatureDeclaration(node); } } - if (fullTypeCheck && !(links.flags & 1 /* TypeChecked */)) { - checkSignatureDeclaration(node); - if (node.type) { - checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); - } - if (node.body.kind === 168 /* FunctionBlock */) { - checkSourceElement(node.body); - } - else { - var exprType = checkExpression(node.body); - if (node.type) { - checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined, undefined); - } - } - links.flags |= 1 /* TypeChecked */; - } return type; } + function checkFunctionExpressionBody(node) { + if (node.type) { + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + } + if (node.body.kind === 168 /* FunctionBlock */) { + checkSourceElement(node.body); + } + else { + var exprType = checkExpression(node.body); + if (node.type) { + checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined, undefined); + } + checkFunctionExpressionBodies(node.body); + } + } function checkArithmeticOperandType(operand, type, diagnostic) { if (!(type.flags & (1 /* Any */ | ts.TypeFlags.NumberLike))) { error(operand, diagnostic); @@ -12504,6 +12563,7 @@ var ts; if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (program.getCompilerOptions().noImplicitAny && !node.type) { switch (node.kind) { @@ -13031,6 +13091,18 @@ var ts; } } } + function checkCollistionWithRequireExportsInGeneratedCode(node, name) { + if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { + return; + } + if (node.kind === 172 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { + return; + } + var parent = node.kind === 166 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (parent.kind === 177 /* SourceFile */ && ts.isExternalModule(parent)) { + error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text); + } + } function checkVariableDeclaration(node) { checkSourceElement(node.type); checkExportsOnMergedDeclarations(node); @@ -13052,6 +13124,7 @@ var ts; } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); if (!useTypeFromValueDeclaration) { if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type)); @@ -13250,6 +13323,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13417,6 +13491,7 @@ var ts; } checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var enumSymbol = getSymbolOfNode(node); var enumType = getDeclaredTypeOfSymbol(enumSymbol); @@ -13473,6 +13548,7 @@ var ts; function checkModuleDeclaration(node) { if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { @@ -13505,6 +13581,7 @@ var ts; } function checkImportDeclaration(node) { checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (node.entityName) { @@ -13587,9 +13664,10 @@ var ts; case 167 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 143 /* Block */: + return checkBlock(node); case 168 /* FunctionBlock */: case 173 /* ModuleBlock */: - return checkBlock(node); + return checkBody(node); case 144 /* VariableStatement */: return checkVariableStatement(node); case 146 /* ExpressionStatement */: @@ -13635,12 +13713,79 @@ var ts; return checkExportAssignment(node); } } + function checkFunctionExpressionBodies(node) { + switch (node.kind) { + case 136 /* FunctionExpression */: + case 137 /* ArrowFunction */: + ts.forEach(node.parameters, checkFunctionExpressionBodies); + checkFunctionExpressionBody(node); + break; + case 116 /* Method */: + case 117 /* Constructor */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 167 /* FunctionDeclaration */: + ts.forEach(node.parameters, checkFunctionExpressionBodies); + break; + case 155 /* WithStatement */: + checkFunctionExpressionBodies(node.expression); + break; + case 114 /* Parameter */: + case 115 /* Property */: + case 127 /* ArrayLiteral */: + case 128 /* ObjectLiteral */: + case 129 /* PropertyAssignment */: + case 130 /* PropertyAccess */: + case 131 /* IndexedAccess */: + case 132 /* CallExpression */: + case 133 /* NewExpression */: + case 134 /* TypeAssertion */: + case 135 /* ParenExpression */: + case 138 /* PrefixOperator */: + case 139 /* PostfixOperator */: + case 140 /* BinaryExpression */: + case 141 /* ConditionalExpression */: + case 143 /* Block */: + case 168 /* FunctionBlock */: + case 173 /* ModuleBlock */: + case 144 /* VariableStatement */: + case 146 /* ExpressionStatement */: + case 147 /* IfStatement */: + case 148 /* DoStatement */: + case 149 /* WhileStatement */: + case 150 /* ForStatement */: + case 151 /* ForInStatement */: + case 152 /* ContinueStatement */: + case 153 /* BreakStatement */: + case 154 /* ReturnStatement */: + case 156 /* SwitchStatement */: + case 157 /* CaseClause */: + case 158 /* DefaultClause */: + case 159 /* LabelledStatement */: + case 160 /* ThrowStatement */: + case 161 /* TryStatement */: + case 162 /* TryBlock */: + case 163 /* CatchBlock */: + case 164 /* FinallyBlock */: + case 166 /* VariableDeclaration */: + case 169 /* ClassDeclaration */: + case 171 /* EnumDeclaration */: + case 176 /* EnumMember */: + case 177 /* SourceFile */: + ts.forEachChild(node, checkFunctionExpressionBodies); + break; + } + } + function checkBody(node) { + checkBlock(node); + checkFunctionExpressionBodies(node); + } function checkSourceFile(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { emitExtends = false; potentialThisCollisions.length = 0; - ts.forEach(node.statements, checkSourceElement); + checkBody(node); if (ts.isExternalModule(node)) { var symbol = getExportAssignmentSymbol(node.symbol); if (symbol && symbol.flags & 4194304 /* Import */) { @@ -13754,19 +13899,6 @@ var ts; function isTypeDeclarationName(name) { return name.kind == 55 /* Identifier */ && isTypeDeclaration(name.parent) && name.parent.name === name; } - function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { - if (name.kind !== 55 /* Identifier */ && name.kind !== 3 /* StringLiteral */ && name.kind !== 2 /* NumericLiteral */) { - return false; - } - var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 136 /* FunctionExpression */) { - return parent.name === name; - } - if (parent.kind === 163 /* CatchBlock */) { - return parent.variable === name; - } - return false; - } function isTypeDeclaration(node) { switch (node.kind) { case 113 /* TypeParameter */: @@ -13776,27 +13908,6 @@ var ts; return true; } } - function isDeclaration(node) { - switch (node.kind) { - case 113 /* TypeParameter */: - case 114 /* Parameter */: - case 166 /* VariableDeclaration */: - case 115 /* Property */: - case 129 /* PropertyAssignment */: - case 176 /* EnumMember */: - case 116 /* Method */: - case 167 /* FunctionDeclaration */: - case 118 /* GetAccessor */: - case 119 /* SetAccessor */: - case 169 /* ClassDeclaration */: - case 170 /* InterfaceDeclaration */: - case 171 /* EnumDeclaration */: - case 172 /* ModuleDeclaration */: - case 174 /* ImportDeclaration */: - return true; - } - return false; - } function isTypeReferenceIdentifier(entityName) { var node = entityName; while (node.parent && node.parent.kind === 112 /* QualifiedName */) @@ -13940,7 +14051,7 @@ var ts; return (node.parent.kind === 112 /* QualifiedName */ || node.parent.kind === 130 /* PropertyAccess */) && node.parent.right === node; } function getSymbolOfEntityName(entityName) { - if (isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { + if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } if (entityName.parent.kind === 175 /* ExportAssignment */) { @@ -13976,6 +14087,12 @@ var ts; return undefined; } function getSymbolInfo(node) { + if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + return getSymbolOfNode(node.parent); + } + if (node.kind === 55 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) { + return node.parent.kind === 175 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); + } switch (node.kind) { case 55 /* Identifier */: case 130 /* PropertyAccess */: @@ -13992,7 +14109,13 @@ var ts; } return undefined; case 3 /* StringLiteral */: - if (node.parent.kind === 131 /* IndexedAccess */ && node.parent.index === node) { + if (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node) { + var importSymbol = getSymbolOfNode(node.parent); + var moduleType = getTypeOfSymbol(importSymbol); + return moduleType ? moduleType.symbol : undefined; + } + case 2 /* NumericLiteral */: + if (node.parent.kind == 131 /* IndexedAccess */ && node.parent.index === node) { var objectType = checkExpression(node.parent.object); if (objectType === unknownType) return undefined; @@ -14001,14 +14124,6 @@ var ts; return undefined; return getPropertyOfApparentType(apparentType, node.text); } - else if (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node) { - var importSymbol = getSymbolOfNode(node.parent); - var moduleType = getTypeOfSymbol(importSymbol); - return moduleType ? moduleType.symbol : undefined; - } - else if (node.parent.kind === 172 /* ModuleDeclaration */) { - return getSymbolOfNode(node.parent); - } break; } return undefined; @@ -14028,11 +14143,11 @@ var ts; var symbol = getSymbolInfo(node); return getDeclaredTypeOfSymbol(symbol); } - if (isDeclaration(node)) { + if (ts.isDeclaration(node)) { var symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } - if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { var symbol = getSymbolInfo(node); return getTypeOfSymbol(symbol); } @@ -14079,6 +14194,9 @@ var ts; return getPropertiesOfType(apparentType); } } + function getRootSymbol(symbol) { + return (symbol.flags & 33554432 /* Transient */) ? getSymbolLinks(symbol).target : symbol; + } function isExternalModuleSymbol(symbol) { return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 177 /* SourceFile */; } diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index d9b53be63cf..0e520a2b447 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -267,6 +267,7 @@ var ts; Import_name_cannot_be_0: { code: 2438, category: 1 /* Error */, key: "Import name cannot be '{0}'" }, Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: 1 /* Error */, key: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name." }, Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: 1 /* Error */, key: "Import declaration conflicts with local declaration of '{0}'" }, + Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: 1 /* Error */, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -566,7 +567,8 @@ var ts; var pos = 0; var lineStart = 0; while (pos < text.length) { - switch (text.charCodeAt(pos++)) { + var ch = text.charCodeAt(pos++); + switch (ch) { case 13 /* carriageReturn */: if (text.charCodeAt(pos) === 10 /* lineFeed */) { pos++; @@ -575,6 +577,12 @@ var ts; result.push(lineStart); lineStart = pos; break; + default: + if (ch > 127 /* maxAsciiCharacter */ && isLineBreak(ch)) { + result.push(lineStart); + lineStart = pos; + } + break; } } result.push(lineStart); @@ -608,7 +616,7 @@ var ts; } ts.isWhiteSpace = isWhiteSpace; function isLineBreak(ch) { - return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */; + return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */ || ch === 133 /* nextLine */; } ts.isLineBreak = isLineBreak; function isDigit(ch) { @@ -748,6 +756,14 @@ var ts; return getCommentRanges(text, pos, true); } ts.getTrailingComments = getTrailingComments; + function isIdentifierStart(ch, languageVersion) { + return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); + } + ts.isIdentifierStart = isIdentifierStart; + function isIdentifierPart(ch, languageVersion) { + return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); + } + ts.isIdentifierPart = isIdentifierPart; function createScanner(languageVersion, text, onError, onComment) { var pos; var len; @@ -2241,6 +2257,7 @@ var ts; AssertionLevel[AssertionLevel["VeryAggressive"] = 3] = "VeryAggressive"; })(ts.AssertionLevel || (ts.AssertionLevel = {})); var AssertionLevel = ts.AssertionLevel; + var Debug; (function (Debug) { var currentAssertionLevel = 0 /* None */; function shouldAssert(level) { @@ -2261,8 +2278,7 @@ var ts; Debug.assert(false, message); } Debug.fail = fail; - })(ts.Debug || (ts.Debug = {})); - var Debug = ts.Debug; + })(Debug = ts.Debug || (ts.Debug = {})); })(ts || (ts = {})); var ts; (function (ts) { @@ -2537,6 +2553,42 @@ var ts; return false; } ts.isInAmbientContext = isInAmbientContext; + function isDeclaration(node) { + switch (node.kind) { + case 113 /* TypeParameter */: + case 114 /* Parameter */: + case 166 /* VariableDeclaration */: + case 115 /* Property */: + case 129 /* PropertyAssignment */: + case 176 /* EnumMember */: + case 116 /* Method */: + case 167 /* FunctionDeclaration */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 169 /* ClassDeclaration */: + case 170 /* InterfaceDeclaration */: + case 171 /* EnumDeclaration */: + case 172 /* ModuleDeclaration */: + case 174 /* ImportDeclaration */: + return true; + } + return false; + } + ts.isDeclaration = isDeclaration; + function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { + if (name.kind !== 55 /* Identifier */ && name.kind !== 3 /* StringLiteral */ && name.kind !== 2 /* NumericLiteral */) { + return false; + } + var parent = name.parent; + if (isDeclaration(parent) || parent.kind === 136 /* FunctionExpression */) { + return parent.name === name; + } + if (parent.kind === 163 /* CatchBlock */) { + return parent.variable === name; + } + return false; + } + ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; var ParsingContext; (function (ParsingContext) { ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements"; @@ -2625,6 +2677,22 @@ var ts; ControlBlockContext[ControlBlockContext["Nested"] = 1] = "Nested"; ControlBlockContext[ControlBlockContext["CrossingFunctionBoundary"] = 2] = "CrossingFunctionBoundary"; })(ControlBlockContext || (ControlBlockContext = {})); + function isKeyword(token) { + return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; + } + ts.isKeyword = isKeyword; + function isModifier(token) { + switch (token) { + case 98 /* PublicKeyword */: + case 96 /* PrivateKeyword */: + case 99 /* StaticKeyword */: + case 68 /* ExportKeyword */: + case 104 /* DeclareKeyword */: + return true; + } + return false; + } + ts.isModifier = isModifier; function createSourceFile(filename, sourceText, languageVersion, version, isOpen) { if (isOpen === void 0) { isOpen = false; } var file; @@ -2859,12 +2927,15 @@ var ts; function createMissingNode() { return createNode(111 /* Missing */); } + function internIdentifier(text) { + return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); + } function createIdentifier(isIdentifier) { identifierCount++; if (isIdentifier) { var node = createNode(55 /* Identifier */); var text = escapeIdentifier(scanner.getTokenValue()); - node.text = ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); + node.text = internIdentifier(text); nextToken(); return finishNode(node); } @@ -2882,24 +2953,10 @@ var ts; } function parsePropertyName() { if (token === 3 /* StringLiteral */ || token === 2 /* NumericLiteral */) { - return parsePrimaryExpression(); + return parseLiteralNode(true); } return parseIdentifierName(); } - function isKeyword(token) { - return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; - } - function isModifier(token) { - switch (token) { - case 98 /* PublicKeyword */: - case 96 /* PrivateKeyword */: - case 99 /* StaticKeyword */: - case 68 /* ExportKeyword */: - case 104 /* DeclareKeyword */: - return true; - } - return false; - } function parseContextualModifier(t) { return token === t && tryParse(function () { nextToken(); @@ -3114,9 +3171,10 @@ var ts; nextToken(); return finishNode(node); } - function parseLiteralNode() { + function parseLiteralNode(internName) { var node = createNode(token); - node.text = scanner.getTokenValue(); + var text = scanner.getTokenValue(); + node.text = internName ? internIdentifier(text) : text; var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); @@ -3132,7 +3190,7 @@ var ts; } function parseStringLiteral() { if (token === 3 /* StringLiteral */) - return parseLiteralNode(); + return parseLiteralNode(true); error(ts.Diagnostics.String_literal_expected); return createMissingNode(); } @@ -3804,6 +3862,10 @@ var ts; } else { indexedAccess.index = parseExpression(); + if (indexedAccess.index.kind === 3 /* StringLiteral */ || indexedAccess.index.kind === 2 /* NumericLiteral */) { + var literal = indexedAccess.index; + literal.text = internIdentifier(literal.text); + } parseExpected(10 /* CloseBracketToken */); } expr = finishNode(indexedAccess); @@ -5109,6 +5171,7 @@ var ts; file.version = version; file.isOpen = isOpen; file.languageVersion = languageVersion; + file.identifiers = identifiers; return file; } ts.createSourceFile = createSourceFile; @@ -5173,18 +5236,17 @@ var ts; } function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) { var canonicalName = host.getCanonicalFileName(filename); - var file = getSourceFile(filename); - if (file) { - if (host.useCaseSensitiveFileNames() && canonicalName !== file.filename) { + if (ts.hasProperty(filesByName, canonicalName)) { + var file = filesByName[canonicalName]; + if (file && host.useCaseSensitiveFileNames() && canonicalName !== file.filename) { errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, file.filename)); } } else { - file = host.getSourceFile(filename, options.target, function (hostErrorMessage) { + var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); }); if (file) { - filesByName[host.getCanonicalFileName(filename)] = file; seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; if (!options.noResolve) { var basePath = ts.getDirectoryPath(filename); @@ -5709,18 +5771,10 @@ var ts; function writeLiteral(s) { if (s && s.length) { write(s); - var pos = 0; - while (pos < s.length) { - switch (s.charCodeAt(pos++)) { - case 13 /* carriageReturn */: - if (pos < s.length && s.charCodeAt(pos) === 10 /* lineFeed */) { - pos++; - } - case 10 /* lineFeed */: - lineCount++; - linePos = output.length - s.length + pos; - break; - } + var lineStartsOfS = ts.getLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; } } } @@ -5831,10 +5885,9 @@ var ts; } function calculateIndent(pos, end) { var currentLineIndent = 0; - while (pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos))) { - pos++; + for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) { - currentLineIndent += getIndentSize(); + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); } else { currentLineIndent++; @@ -7080,14 +7133,12 @@ var ts; return emitPinnedOrTripleSlashComments(node); } emitLeadingComments(node); - if (!(node.flags & 1 /* Export */)) { - emitStart(node); - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - } + emitStart(node); + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); emitStart(node); write("(function ("); emitStart(node.name); @@ -7111,21 +7162,15 @@ var ts; scopeEmitEnd(); } write(")("); + if (node.flags & 1 /* Export */) { + emit(node.name); + write(" = "); + } emitModuleMemberName(node); write(" || ("); emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } emitTrailingComments(node); } function emitImportDeclaration(node) { @@ -8132,39 +8177,43 @@ var ts; } } function resolveScriptReference(sourceFile, reference) { - var referenceFileName = compilerOptions.noResolve ? reference.filename : ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); + var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); return program.getSourceFile(referenceFileName); } var referencePathsOutput = ""; function writeReferencePath(referencedFile) { var declFileName = referencedFile.flags & 512 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts"; declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false); - referencePathsOutput += "/// " + newLine; + referencePathsOutput += "/// " + newLine; } if (root) { - var addedGlobalFileReference = false; - ts.forEach(root.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(root, fileReference); - if ((referencedFile.flags & 512 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile) || !addedGlobalFileReference) { - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; + if (!compilerOptions.noResolve) { + var addedGlobalFileReference = false; + ts.forEach(root.referencedFiles, function (fileReference) { + var referencedFile = resolveScriptReference(root, fileReference); + if ((referencedFile.flags & 512 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile) || !addedGlobalFileReference) { + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } } - } - }); + }); + } emitNode(root); } else { var emittedReferencedFiles = []; ts.forEach(program.getSourceFiles(), function (sourceFile) { if (!isExternalModuleOrDeclarationFile(sourceFile)) { - ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(sourceFile, fileReference); - if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); + if (!compilerOptions.noResolve) { + ts.forEach(sourceFile.referencedFiles, function (fileReference) { + var referencedFile = resolveScriptReference(sourceFile, fileReference); + if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } emitNode(sourceFile); } }); @@ -8214,6 +8263,17 @@ var ts; var nextSymbolId = 1; var nextNodeId = 1; var nextMergeId = 1; + function getDeclarationOfKind(symbol, kind) { + var declarations = symbol.declarations; + for (var i = 0; i < declarations.length; i++) { + var declaration = declarations[i]; + if (declaration.kind === kind) { + return declaration; + } + } + return undefined; + } + ts.getDeclarationOfKind = getDeclarationOfKind; function createTypeChecker(program, fullTypeCheck) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); @@ -8244,7 +8304,9 @@ var ts; getApparentType: getApparentType, typeToString: typeToString, symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType + getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, + getRootSymbol: getRootSymbol, + getContextualType: getContextualType }; var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments"); @@ -8692,16 +8754,6 @@ var ts; } return false; } - function getDeclarationOfKind(symbol, kind) { - var declarations = symbol.declarations; - for (var i = 0; i < declarations.length; i++) { - var declaration = declarations[i]; - if (declaration.kind === kind) { - return declaration; - } - } - return undefined; - } function findConstructorDeclaration(node) { var members = node.members; for (var i = 0; i < members.length; i++) { @@ -9722,27 +9774,38 @@ var ts; } function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; - var members = emptySymbols; - var callSignatures = emptyArray; - var constructSignatures = emptyArray; - if (symbol.flags & ts.SymbolFlags.HasExports) { - members = symbol.exports; + if (symbol.flags & 512 /* TypeLiteral */) { + var members = symbol.members; + var callSignatures = getSignaturesOfSymbol(members["__call"]); + var constructSignatures = getSignaturesOfSymbol(members["__new"]); + var stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */); + var numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */); } - if (symbol.flags & (8 /* Function */ | 2048 /* Method */)) { - callSignatures = getSignaturesOfSymbol(symbol); - } - if (symbol.flags & 16 /* Class */) { - var classType = getDeclaredTypeOfClass(symbol); - constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); - if (!constructSignatures.length) - constructSignatures = getDefaultConstructSignatures(classType); - if (classType.baseTypes.length) { - var members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + else { + var members = emptySymbols; + var callSignatures = emptyArray; + var constructSignatures = emptyArray; + if (symbol.flags & ts.SymbolFlags.HasExports) { + members = symbol.exports; } + if (symbol.flags & (8 /* Function */ | 2048 /* Method */)) { + callSignatures = getSignaturesOfSymbol(symbol); + } + if (symbol.flags & 16 /* Class */) { + var classType = getDeclaredTypeOfClass(symbol); + constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); + if (!constructSignatures.length) { + constructSignatures = getDefaultConstructSignatures(classType); + } + if (classType.baseTypes.length) { + members = createSymbolTable(getNamedMembers(members)); + addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + } + } + var stringIndexType = undefined; + var numberIndexType = (symbol.flags & 64 /* Enum */) ? stringType : undefined; } - var numberIndexType = (symbol.flags & 64 /* Enum */) ? stringType : undefined; - setObjectTypeMembers(type, members, callSignatures, constructSignatures, undefined, numberIndexType); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function resolveObjectTypeMembers(type) { if (!type.members) { @@ -10124,13 +10187,7 @@ var ts; function getTypeFromTypeLiteralNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var symbol = node.symbol; - var members = symbol.members; - var callSignatures = getSignaturesOfSymbol(members["__call"]); - var constructSignatures = getSignaturesOfSymbol(members["__new"]); - var stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */); - var numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */); - links.resolvedType = createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + links.resolvedType = createObjectType(8192 /* Anonymous */, node.symbol); } return links.resolvedType; } @@ -10859,45 +10916,6 @@ var ts; function isTypeOfObjectLiteral(type) { return (type.flags & 8192 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; } - function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfType(type); - if (properties.length) { - var widenedTypes = []; - var propTypeWasWidened = false; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - propTypeWasWidened = true; - if (program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { - error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); - } - } - widenedTypes.push(widenedType); - }); - if (propTypeWasWidened) { - var members = {}; - var index = 0; - ts.forEach(properties, function (p) { - var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedTypes[index++]; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - members[symbol.name] = symbol; - }); - var stringIndexType = getIndexTypeOfType(type, 0 /* String */); - var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); - if (stringIndexType) - stringIndexType = getWidenedType(stringIndexType); - if (numberIndexType) - numberIndexType = getWidenedType(numberIndexType); - type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); - } - } - return type; - } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; } @@ -10907,13 +10925,7 @@ var ts; } return type; } - function getWidenedTypeOfArrayLiteral(type) { - var elementType = type.typeArguments[0]; - var widenedType = getWidenedType(elementType); - type = elementType !== widenedType ? createArrayType(widenedType) : type; - return type; - } - function getWidenedType(type) { + function getWidenedType(type, supressNoImplicitAnyErrors) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } @@ -10924,6 +10936,52 @@ var ts; return getWidenedTypeOfArrayLiteral(type); } return type; + function getWidenedTypeOfObjectLiteral(type) { + var properties = getPropertiesOfType(type); + if (properties.length) { + var widenedTypes = []; + var propTypeWasWidened = false; + ts.forEach(properties, function (p) { + var propType = getTypeOfSymbol(p); + var widenedType = getWidenedType(propType); + if (propType !== widenedType) { + propTypeWasWidened = true; + if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); + } + } + widenedTypes.push(widenedType); + }); + if (propTypeWasWidened) { + var members = {}; + var index = 0; + ts.forEach(properties, function (p) { + var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); + symbol.declarations = p.declarations; + symbol.parent = p.parent; + symbol.type = widenedTypes[index++]; + symbol.target = p; + if (p.valueDeclaration) + symbol.valueDeclaration = p.valueDeclaration; + members[symbol.name] = symbol; + }); + var stringIndexType = getIndexTypeOfType(type, 0 /* String */); + var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); + if (stringIndexType) + stringIndexType = getWidenedType(stringIndexType); + if (numberIndexType) + numberIndexType = getWidenedType(numberIndexType); + type = createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); + } + } + return type; + } + function getWidenedTypeOfArrayLiteral(type) { + var elementType = type.typeArguments[0]; + var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + type = elementType !== widenedType ? createArrayType(widenedType) : type; + return type; + } } function forEachMatchingParameterType(source, target, callback) { var sourceMax = source.parameters.length; @@ -11457,6 +11515,7 @@ var ts; if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration; prop.type = type; + prop.target = member; member = prop; } else { @@ -11825,9 +11884,9 @@ var ts; var exprType = checkExpression(node.operand); var targetType = getTypeFromTypeNode(node.type); if (fullTypeCheck && targetType !== unknownType) { - var widenedType = getWidenedType(exprType); - if (!(isTypeAssignableTo(exprType, targetType) || isTypeAssignableTo(targetType, widenedType))) { - checkTypeAssignableTo(targetType, widenedType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + var widenedType = getWidenedType(exprType, true); + if (!(isTypeAssignableTo(targetType, widenedType))) { + checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; @@ -11967,26 +12026,26 @@ var ts; } } } + checkSignatureDeclaration(node); } } - if (fullTypeCheck && !(links.flags & 1 /* TypeChecked */)) { - checkSignatureDeclaration(node); - if (node.type) { - checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); - } - if (node.body.kind === 168 /* FunctionBlock */) { - checkSourceElement(node.body); - } - else { - var exprType = checkExpression(node.body); - if (node.type) { - checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined, undefined); - } - } - links.flags |= 1 /* TypeChecked */; - } return type; } + function checkFunctionExpressionBody(node) { + if (node.type) { + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + } + if (node.body.kind === 168 /* FunctionBlock */) { + checkSourceElement(node.body); + } + else { + var exprType = checkExpression(node.body); + if (node.type) { + checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined, undefined); + } + checkFunctionExpressionBodies(node.body); + } + } function checkArithmeticOperandType(operand, type, diagnostic) { if (!(type.flags & (1 /* Any */ | ts.TypeFlags.NumberLike))) { error(operand, diagnostic); @@ -12309,6 +12368,7 @@ var ts; if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (program.getCompilerOptions().noImplicitAny && !node.type) { switch (node.kind) { @@ -12836,6 +12896,18 @@ var ts; } } } + function checkCollistionWithRequireExportsInGeneratedCode(node, name) { + if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { + return; + } + if (node.kind === 172 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { + return; + } + var parent = node.kind === 166 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (parent.kind === 177 /* SourceFile */ && ts.isExternalModule(parent)) { + error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text); + } + } function checkVariableDeclaration(node) { checkSourceElement(node.type); checkExportsOnMergedDeclarations(node); @@ -12857,6 +12929,7 @@ var ts; } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); if (!useTypeFromValueDeclaration) { if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type)); @@ -13055,6 +13128,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13222,6 +13296,7 @@ var ts; } checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var enumSymbol = getSymbolOfNode(node); var enumType = getDeclaredTypeOfSymbol(enumSymbol); @@ -13278,6 +13353,7 @@ var ts; function checkModuleDeclaration(node) { if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { @@ -13310,6 +13386,7 @@ var ts; } function checkImportDeclaration(node) { checkCollisionWithCapturedThisVariable(node, node.name); + checkCollistionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (node.entityName) { @@ -13392,9 +13469,10 @@ var ts; case 167 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 143 /* Block */: + return checkBlock(node); case 168 /* FunctionBlock */: case 173 /* ModuleBlock */: - return checkBlock(node); + return checkBody(node); case 144 /* VariableStatement */: return checkVariableStatement(node); case 146 /* ExpressionStatement */: @@ -13440,12 +13518,79 @@ var ts; return checkExportAssignment(node); } } + function checkFunctionExpressionBodies(node) { + switch (node.kind) { + case 136 /* FunctionExpression */: + case 137 /* ArrowFunction */: + ts.forEach(node.parameters, checkFunctionExpressionBodies); + checkFunctionExpressionBody(node); + break; + case 116 /* Method */: + case 117 /* Constructor */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 167 /* FunctionDeclaration */: + ts.forEach(node.parameters, checkFunctionExpressionBodies); + break; + case 155 /* WithStatement */: + checkFunctionExpressionBodies(node.expression); + break; + case 114 /* Parameter */: + case 115 /* Property */: + case 127 /* ArrayLiteral */: + case 128 /* ObjectLiteral */: + case 129 /* PropertyAssignment */: + case 130 /* PropertyAccess */: + case 131 /* IndexedAccess */: + case 132 /* CallExpression */: + case 133 /* NewExpression */: + case 134 /* TypeAssertion */: + case 135 /* ParenExpression */: + case 138 /* PrefixOperator */: + case 139 /* PostfixOperator */: + case 140 /* BinaryExpression */: + case 141 /* ConditionalExpression */: + case 143 /* Block */: + case 168 /* FunctionBlock */: + case 173 /* ModuleBlock */: + case 144 /* VariableStatement */: + case 146 /* ExpressionStatement */: + case 147 /* IfStatement */: + case 148 /* DoStatement */: + case 149 /* WhileStatement */: + case 150 /* ForStatement */: + case 151 /* ForInStatement */: + case 152 /* ContinueStatement */: + case 153 /* BreakStatement */: + case 154 /* ReturnStatement */: + case 156 /* SwitchStatement */: + case 157 /* CaseClause */: + case 158 /* DefaultClause */: + case 159 /* LabelledStatement */: + case 160 /* ThrowStatement */: + case 161 /* TryStatement */: + case 162 /* TryBlock */: + case 163 /* CatchBlock */: + case 164 /* FinallyBlock */: + case 166 /* VariableDeclaration */: + case 169 /* ClassDeclaration */: + case 171 /* EnumDeclaration */: + case 176 /* EnumMember */: + case 177 /* SourceFile */: + ts.forEachChild(node, checkFunctionExpressionBodies); + break; + } + } + function checkBody(node) { + checkBlock(node); + checkFunctionExpressionBodies(node); + } function checkSourceFile(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { emitExtends = false; potentialThisCollisions.length = 0; - ts.forEach(node.statements, checkSourceElement); + checkBody(node); if (ts.isExternalModule(node)) { var symbol = getExportAssignmentSymbol(node.symbol); if (symbol && symbol.flags & 4194304 /* Import */) { @@ -13559,19 +13704,6 @@ var ts; function isTypeDeclarationName(name) { return name.kind == 55 /* Identifier */ && isTypeDeclaration(name.parent) && name.parent.name === name; } - function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { - if (name.kind !== 55 /* Identifier */ && name.kind !== 3 /* StringLiteral */ && name.kind !== 2 /* NumericLiteral */) { - return false; - } - var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 136 /* FunctionExpression */) { - return parent.name === name; - } - if (parent.kind === 163 /* CatchBlock */) { - return parent.variable === name; - } - return false; - } function isTypeDeclaration(node) { switch (node.kind) { case 113 /* TypeParameter */: @@ -13581,27 +13713,6 @@ var ts; return true; } } - function isDeclaration(node) { - switch (node.kind) { - case 113 /* TypeParameter */: - case 114 /* Parameter */: - case 166 /* VariableDeclaration */: - case 115 /* Property */: - case 129 /* PropertyAssignment */: - case 176 /* EnumMember */: - case 116 /* Method */: - case 167 /* FunctionDeclaration */: - case 118 /* GetAccessor */: - case 119 /* SetAccessor */: - case 169 /* ClassDeclaration */: - case 170 /* InterfaceDeclaration */: - case 171 /* EnumDeclaration */: - case 172 /* ModuleDeclaration */: - case 174 /* ImportDeclaration */: - return true; - } - return false; - } function isTypeReferenceIdentifier(entityName) { var node = entityName; while (node.parent && node.parent.kind === 112 /* QualifiedName */) @@ -13745,7 +13856,7 @@ var ts; return (node.parent.kind === 112 /* QualifiedName */ || node.parent.kind === 130 /* PropertyAccess */) && node.parent.right === node; } function getSymbolOfEntityName(entityName) { - if (isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { + if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } if (entityName.parent.kind === 175 /* ExportAssignment */) { @@ -13781,6 +13892,12 @@ var ts; return undefined; } function getSymbolInfo(node) { + if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + return getSymbolOfNode(node.parent); + } + if (node.kind === 55 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) { + return node.parent.kind === 175 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); + } switch (node.kind) { case 55 /* Identifier */: case 130 /* PropertyAccess */: @@ -13797,7 +13914,13 @@ var ts; } return undefined; case 3 /* StringLiteral */: - if (node.parent.kind === 131 /* IndexedAccess */ && node.parent.index === node) { + if (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node) { + var importSymbol = getSymbolOfNode(node.parent); + var moduleType = getTypeOfSymbol(importSymbol); + return moduleType ? moduleType.symbol : undefined; + } + case 2 /* NumericLiteral */: + if (node.parent.kind == 131 /* IndexedAccess */ && node.parent.index === node) { var objectType = checkExpression(node.parent.object); if (objectType === unknownType) return undefined; @@ -13806,14 +13929,6 @@ var ts; return undefined; return getPropertyOfApparentType(apparentType, node.text); } - else if (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node) { - var importSymbol = getSymbolOfNode(node.parent); - var moduleType = getTypeOfSymbol(importSymbol); - return moduleType ? moduleType.symbol : undefined; - } - else if (node.parent.kind === 172 /* ModuleDeclaration */) { - return getSymbolOfNode(node.parent); - } break; } return undefined; @@ -13833,11 +13948,11 @@ var ts; var symbol = getSymbolInfo(node); return getDeclaredTypeOfSymbol(symbol); } - if (isDeclaration(node)) { + if (ts.isDeclaration(node)) { var symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } - if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { var symbol = getSymbolInfo(node); return getTypeOfSymbol(symbol); } @@ -13884,6 +13999,9 @@ var ts; return getPropertiesOfType(apparentType); } } + function getRootSymbol(symbol) { + return (symbol.flags & 33554432 /* Transient */) ? getSymbolLinks(symbol).target : symbol; + } function isExternalModuleSymbol(symbol) { return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 177 /* SourceFile */; } @@ -15321,73 +15439,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { - var Hash = (function () { - function Hash() { - } - Hash.computeFnv1aCharArrayHashCode = function (text, start, len) { - var hashCode = Hash.FNV_BASE; - var end = start + len; - for (var i = start; i < end; i++) { - hashCode = TypeScript.IntegerUtilities.integerMultiplyLow32Bits(hashCode ^ text[i], Hash.FNV_PRIME); - } - return hashCode; - }; - Hash.computeSimple31BitCharArrayHashCode = function (key, start, len) { - var hash = 0; - for (var i = 0; i < len; i++) { - var ch = key[start + i]; - hash = ((((hash << 5) - hash) | 0) + ch) | 0; - } - return hash & 0x7FFFFFFF; - }; - Hash.computeSimple31BitStringHashCode = function (key) { - var hash = 0; - var start = 0; - var len = key.length; - for (var i = 0; i < len; i++) { - var ch = key.charCodeAt(start + i); - hash = ((((hash << 5) - hash) | 0) + ch) | 0; - } - return hash & 0x7FFFFFFF; - }; - Hash.computeMurmur2StringHashCode = function (key, seed) { - var m = 0x5bd1e995; - var r = 24; - var numberOfCharsLeft = key.length; - var h = Math.abs(seed ^ numberOfCharsLeft); - var index = 0; - while (numberOfCharsLeft >= 2) { - var c1 = key.charCodeAt(index); - var c2 = key.charCodeAt(index + 1); - var k = Math.abs(c1 | (c2 << 16)); - k = TypeScript.IntegerUtilities.integerMultiplyLow32Bits(k, m); - k ^= k >> r; - k = TypeScript.IntegerUtilities.integerMultiplyLow32Bits(k, m); - h = TypeScript.IntegerUtilities.integerMultiplyLow32Bits(h, m); - h ^= k; - index += 2; - numberOfCharsLeft -= 2; - } - if (numberOfCharsLeft === 1) { - h ^= key.charCodeAt(index); - h = TypeScript.IntegerUtilities.integerMultiplyLow32Bits(h, m); - } - h ^= h >> 13; - h = TypeScript.IntegerUtilities.integerMultiplyLow32Bits(h, m); - h ^= h >> 15; - return h; - }; - Hash.combine = function (value, currentHash) { - return (((currentHash << 5) + currentHash) + value) & 0x7FFFFFFF; - }; - Hash.FNV_BASE = 2166136261; - Hash.FNV_PRIME = 16777619; - return Hash; - })(); - TypeScript.Hash = Hash; -})(TypeScript || (TypeScript = {})); -var TypeScript; -(function (TypeScript) { + var IntegerUtilities; (function (IntegerUtilities) { function integerDivide(numerator, denominator) { return (numerator / denominator) >> 0; @@ -15410,8 +15462,7 @@ var TypeScript; return /^0(x|X)[0-9a-fA-F]+$/.test(text); } IntegerUtilities.isHexInteger = isHexInteger; - })(TypeScript.IntegerUtilities || (TypeScript.IntegerUtilities = {})); - var IntegerUtilities = TypeScript.IntegerUtilities; + })(IntegerUtilities = TypeScript.IntegerUtilities || (TypeScript.IntegerUtilities = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -15649,6 +15700,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var ScriptSnapshot; (function (ScriptSnapshot) { var StringScriptSnapshot = (function () { function StringScriptSnapshot(text) { @@ -15676,11 +15728,11 @@ var TypeScript; return new StringScriptSnapshot(text); } ScriptSnapshot.fromString = fromString; - })(TypeScript.ScriptSnapshot || (TypeScript.ScriptSnapshot = {})); - var ScriptSnapshot = TypeScript.ScriptSnapshot; + })(ScriptSnapshot = TypeScript.ScriptSnapshot || (TypeScript.ScriptSnapshot = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var LineMap1; (function (LineMap1) { function fromSimpleText(text) { return new TypeScript.LineMap(function () { return TypeScript.TextUtilities.parseLineStarts({ charCodeAt: function (index) { return text.charCodeAt(index); }, length: text.length() }); }, text.length()); @@ -15694,11 +15746,11 @@ var TypeScript; return new TypeScript.LineMap(function () { return TypeScript.TextUtilities.parseLineStarts(text); }, text.length); } LineMap1.fromString = fromString; - })(TypeScript.LineMap1 || (TypeScript.LineMap1 = {})); - var LineMap1 = TypeScript.LineMap1; + })(LineMap1 = TypeScript.LineMap1 || (TypeScript.LineMap1 = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var SimpleText; (function (SimpleText) { var SimpleStringText = (function () { function SimpleStringText(value) { @@ -15753,11 +15805,11 @@ var TypeScript; return new SimpleScriptSnapshotText(scriptSnapshot); } SimpleText.fromScriptSnapshot = fromScriptSnapshot; - })(TypeScript.SimpleText || (TypeScript.SimpleText = {})); - var SimpleText = TypeScript.SimpleText; + })(SimpleText = TypeScript.SimpleText || (TypeScript.SimpleText = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var TextUtilities; (function (TextUtilities) { function parseLineStarts(text) { var length = text.length; @@ -15825,8 +15877,7 @@ var TypeScript; return c === 10 /* lineFeed */ || c === 13 /* carriageReturn */ || c === 133 /* nextLine */ || c === 8232 /* lineSeparator */ || c === 8233 /* paragraphSeparator */; } TextUtilities.isAnyLineBreakCharacter = isAnyLineBreakCharacter; - })(TypeScript.TextUtilities || (TypeScript.TextUtilities = {})); - var TextUtilities = TypeScript.TextUtilities; + })(TextUtilities = TypeScript.TextUtilities || (TypeScript.TextUtilities = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -15956,6 +16007,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var CharacterInfo; (function (CharacterInfo) { function isDecimalDigit(c) { return c >= 48 /* _0 */ && c <= 57 /* _9 */; @@ -16011,8 +16063,7 @@ var TypeScript; return false; } CharacterInfo.isLineTerminator = isLineTerminator; - })(TypeScript.CharacterInfo || (TypeScript.CharacterInfo = {})); - var CharacterInfo = TypeScript.CharacterInfo; + })(CharacterInfo = TypeScript.CharacterInfo || (TypeScript.CharacterInfo = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -16314,6 +16365,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var SyntaxFacts; (function (SyntaxFacts) { var textToKeywordKind = { "any": 60 /* AnyKeyword */, @@ -16685,11 +16737,11 @@ var TypeScript; return false; } SyntaxFacts.isType = isType; - })(TypeScript.SyntaxFacts || (TypeScript.SyntaxFacts = {})); - var SyntaxFacts = TypeScript.SyntaxFacts; + })(SyntaxFacts = TypeScript.SyntaxFacts || (TypeScript.SyntaxFacts = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Scanner; (function (Scanner) { TypeScript.Debug.assert(TypeScript.SyntaxKind.LastToken <= 127); var ScannerConstants; @@ -17919,8 +17971,7 @@ var TypeScript; }; } Scanner.createParserSource = createParserSource; - })(TypeScript.Scanner || (TypeScript.Scanner = {})); - var Scanner = TypeScript.Scanner; + })(Scanner = TypeScript.Scanner || (TypeScript.Scanner = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -18239,6 +18290,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Syntax; (function (Syntax) { Syntax._nextSyntaxID = 1; function childIndex(parent, child) { @@ -18462,8 +18514,7 @@ var TypeScript; } return lineMap.getLineNumberFromPosition(TypeScript.end(_previousToken)) !== lineMap.getLineNumberFromPosition(TypeScript.start(token)); } - })(TypeScript.Syntax || (TypeScript.Syntax = {})); - var Syntax = TypeScript.Syntax; + })(Syntax = TypeScript.Syntax || (TypeScript.Syntax = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -18864,6 +18915,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var SyntaxFacts; (function (SyntaxFacts) { function isDirectivePrologueElement(node) { if (node.kind() === 149 /* ExpressionStatement */) { @@ -18888,11 +18940,11 @@ var TypeScript; return tokenKind === 11 /* IdentifierName */ || SyntaxFacts.isAnyKeyword(tokenKind); } SyntaxFacts.isIdentifierNameOrAnyKeyword = isIdentifierNameOrAnyKeyword; - })(TypeScript.SyntaxFacts || (TypeScript.SyntaxFacts = {})); - var SyntaxFacts = TypeScript.SyntaxFacts; + })(SyntaxFacts = TypeScript.SyntaxFacts || (TypeScript.SyntaxFacts = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Syntax; (function (Syntax) { var _emptyList = []; var _emptySeparatedList = []; @@ -18952,8 +19004,7 @@ var TypeScript; return -1; } Syntax.nonSeparatorIndexOf = nonSeparatorIndexOf; - })(TypeScript.Syntax || (TypeScript.Syntax = {})); - var Syntax = TypeScript.Syntax; + })(Syntax = TypeScript.Syntax || (TypeScript.Syntax = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -19123,6 +19174,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Syntax; (function (Syntax) { function realizeToken(token, text) { return new RealizedToken(token.fullStart(), token.kind(), token.isKeywordConvertedToIdentifier(), token.leadingTrivia(text), token.text(), token.trailingTrivia(text)); @@ -19370,11 +19422,11 @@ var TypeScript; }; return ConvertedKeywordToken; })(); - })(TypeScript.Syntax || (TypeScript.Syntax = {})); - var Syntax = TypeScript.Syntax; + })(Syntax = TypeScript.Syntax || (TypeScript.Syntax = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Syntax; (function (Syntax) { var AbstractTrivia = (function () { function AbstractTrivia(_kind) { @@ -19497,11 +19549,11 @@ var TypeScript; return result; } Syntax.splitMultiLineCommentTriviaIntoMultipleLines = splitMultiLineCommentTriviaIntoMultipleLines; - })(TypeScript.Syntax || (TypeScript.Syntax = {})); - var Syntax = TypeScript.Syntax; + })(Syntax = TypeScript.Syntax || (TypeScript.Syntax = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Syntax; (function (Syntax) { var EmptyTriviaList = (function () { function EmptyTriviaList() { @@ -19674,8 +19726,7 @@ var TypeScript; return new NormalSyntaxTriviaList(trivia); } Syntax.triviaList = triviaList; - })(TypeScript.Syntax || (TypeScript.Syntax = {})); - var Syntax = TypeScript.Syntax; + })(Syntax = TypeScript.Syntax || (TypeScript.Syntax = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -20758,6 +20809,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Parser; (function (Parser) { Parser.syntaxFactory; var arrayPool = []; @@ -21014,14 +21066,20 @@ var TypeScript; throw TypeScript.Errors.invalidOperation(); } } - function replaceTokenInParent(oldToken, newToken) { + function replaceTokenInParent(node, oldToken, newToken) { replaceTokenInParentWorker(oldToken, newToken); var parent = oldToken.parent; newToken.parent = parent; - TypeScript.Debug.assert(TypeScript.isNode(parent) || TypeScript.isList(parent) || TypeScript.isSeparatedList(parent)); - var dataElement = parent; - if (dataElement.data) { - dataElement.data &= 4 /* NodeParsedInStrictModeMask */; + while (true) { + TypeScript.Debug.assert(TypeScript.isNode(parent) || TypeScript.isList(parent) || TypeScript.isSeparatedList(parent)); + var dataElement = parent; + if (dataElement.data) { + dataElement.data &= 4 /* NodeParsedInStrictModeMask */; + } + if (parent === node) { + break; + } + parent = parent.parent; } } function replaceTokenInParentWorker(oldToken, newToken) { @@ -21063,14 +21121,14 @@ var TypeScript; function addSkippedTokenAfterNode(node, skippedToken) { var oldToken = TypeScript.lastToken(node); var newToken = addSkippedTokenAfterToken(oldToken, skippedToken); - replaceTokenInParent(oldToken, newToken); + replaceTokenInParent(node, oldToken, newToken); return node; } function addSkippedTokensBeforeNode(node, skippedTokens) { if (skippedTokens.length > 0) { var oldToken = TypeScript.firstToken(node); var newToken = addSkippedTokensBeforeToken(oldToken, skippedTokens); - replaceTokenInParent(oldToken, newToken); + replaceTokenInParent(node, oldToken, newToken); } return node; } @@ -23406,12 +23464,13 @@ var TypeScript; return parseSyntaxTree(source, isDeclaration); } Parser.parseSource = parseSource; - })(TypeScript.Parser || (TypeScript.Parser = {})); - var Parser = TypeScript.Parser; + })(Parser = TypeScript.Parser || (TypeScript.Parser = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Syntax; (function (Syntax) { + var Concrete; (function (Concrete) { TypeScript.Parser.syntaxFactory = Concrete; Concrete.isConcrete = true; @@ -24193,10 +24252,8 @@ var TypeScript; })(TypeScript.SyntaxNode); Concrete.ModuleNameModuleReferenceSyntax = ModuleNameModuleReferenceSyntax; SourceUnitSyntax.prototype.__kind = 120 /* SourceUnit */, QualifiedNameSyntax.prototype.__kind = 121 /* QualifiedName */, ObjectTypeSyntax.prototype.__kind = 122 /* ObjectType */, FunctionTypeSyntax.prototype.__kind = 123 /* FunctionType */, ArrayTypeSyntax.prototype.__kind = 124 /* ArrayType */, ConstructorTypeSyntax.prototype.__kind = 125 /* ConstructorType */, GenericTypeSyntax.prototype.__kind = 126 /* GenericType */, TypeQuerySyntax.prototype.__kind = 127 /* TypeQuery */, InterfaceDeclarationSyntax.prototype.__kind = 128 /* InterfaceDeclaration */, FunctionDeclarationSyntax.prototype.__kind = 129 /* FunctionDeclaration */, ModuleDeclarationSyntax.prototype.__kind = 130 /* ModuleDeclaration */, ClassDeclarationSyntax.prototype.__kind = 131 /* ClassDeclaration */, EnumDeclarationSyntax.prototype.__kind = 132 /* EnumDeclaration */, ImportDeclarationSyntax.prototype.__kind = 133 /* ImportDeclaration */, ExportAssignmentSyntax.prototype.__kind = 134 /* ExportAssignment */, MemberFunctionDeclarationSyntax.prototype.__kind = 135 /* MemberFunctionDeclaration */, MemberVariableDeclarationSyntax.prototype.__kind = 136 /* MemberVariableDeclaration */, ConstructorDeclarationSyntax.prototype.__kind = 137 /* ConstructorDeclaration */, IndexMemberDeclarationSyntax.prototype.__kind = 138 /* IndexMemberDeclaration */, GetAccessorSyntax.prototype.__kind = 139 /* GetAccessor */, SetAccessorSyntax.prototype.__kind = 140 /* SetAccessor */, PropertySignatureSyntax.prototype.__kind = 141 /* PropertySignature */, CallSignatureSyntax.prototype.__kind = 142 /* CallSignature */, ConstructSignatureSyntax.prototype.__kind = 143 /* ConstructSignature */, IndexSignatureSyntax.prototype.__kind = 144 /* IndexSignature */, MethodSignatureSyntax.prototype.__kind = 145 /* MethodSignature */, BlockSyntax.prototype.__kind = 146 /* Block */, IfStatementSyntax.prototype.__kind = 147 /* IfStatement */, VariableStatementSyntax.prototype.__kind = 148 /* VariableStatement */, ExpressionStatementSyntax.prototype.__kind = 149 /* ExpressionStatement */, ReturnStatementSyntax.prototype.__kind = 150 /* ReturnStatement */, SwitchStatementSyntax.prototype.__kind = 151 /* SwitchStatement */, BreakStatementSyntax.prototype.__kind = 152 /* BreakStatement */, ContinueStatementSyntax.prototype.__kind = 153 /* ContinueStatement */, ForStatementSyntax.prototype.__kind = 154 /* ForStatement */, ForInStatementSyntax.prototype.__kind = 155 /* ForInStatement */, EmptyStatementSyntax.prototype.__kind = 156 /* EmptyStatement */, ThrowStatementSyntax.prototype.__kind = 157 /* ThrowStatement */, WhileStatementSyntax.prototype.__kind = 158 /* WhileStatement */, TryStatementSyntax.prototype.__kind = 159 /* TryStatement */, LabeledStatementSyntax.prototype.__kind = 160 /* LabeledStatement */, DoStatementSyntax.prototype.__kind = 161 /* DoStatement */, DebuggerStatementSyntax.prototype.__kind = 162 /* DebuggerStatement */, WithStatementSyntax.prototype.__kind = 163 /* WithStatement */, DeleteExpressionSyntax.prototype.__kind = 170 /* DeleteExpression */, TypeOfExpressionSyntax.prototype.__kind = 171 /* TypeOfExpression */, VoidExpressionSyntax.prototype.__kind = 172 /* VoidExpression */, ConditionalExpressionSyntax.prototype.__kind = 186 /* ConditionalExpression */, MemberAccessExpressionSyntax.prototype.__kind = 212 /* MemberAccessExpression */, InvocationExpressionSyntax.prototype.__kind = 213 /* InvocationExpression */, ArrayLiteralExpressionSyntax.prototype.__kind = 214 /* ArrayLiteralExpression */, ObjectLiteralExpressionSyntax.prototype.__kind = 215 /* ObjectLiteralExpression */, ObjectCreationExpressionSyntax.prototype.__kind = 216 /* ObjectCreationExpression */, ParenthesizedExpressionSyntax.prototype.__kind = 217 /* ParenthesizedExpression */, ParenthesizedArrowFunctionExpressionSyntax.prototype.__kind = 218 /* ParenthesizedArrowFunctionExpression */, SimpleArrowFunctionExpressionSyntax.prototype.__kind = 219 /* SimpleArrowFunctionExpression */, CastExpressionSyntax.prototype.__kind = 220 /* CastExpression */, ElementAccessExpressionSyntax.prototype.__kind = 221 /* ElementAccessExpression */, FunctionExpressionSyntax.prototype.__kind = 222 /* FunctionExpression */, OmittedExpressionSyntax.prototype.__kind = 223 /* OmittedExpression */, VariableDeclarationSyntax.prototype.__kind = 224 /* VariableDeclaration */, VariableDeclaratorSyntax.prototype.__kind = 225 /* VariableDeclarator */, ArgumentListSyntax.prototype.__kind = 226 /* ArgumentList */, ParameterListSyntax.prototype.__kind = 227 /* ParameterList */, TypeArgumentListSyntax.prototype.__kind = 228 /* TypeArgumentList */, TypeParameterListSyntax.prototype.__kind = 229 /* TypeParameterList */, EqualsValueClauseSyntax.prototype.__kind = 232 /* EqualsValueClause */, CaseSwitchClauseSyntax.prototype.__kind = 233 /* CaseSwitchClause */, DefaultSwitchClauseSyntax.prototype.__kind = 234 /* DefaultSwitchClause */, ElseClauseSyntax.prototype.__kind = 235 /* ElseClause */, CatchClauseSyntax.prototype.__kind = 236 /* CatchClause */, FinallyClauseSyntax.prototype.__kind = 237 /* FinallyClause */, TypeParameterSyntax.prototype.__kind = 238 /* TypeParameter */, ConstraintSyntax.prototype.__kind = 239 /* Constraint */, SimplePropertyAssignmentSyntax.prototype.__kind = 240 /* SimplePropertyAssignment */, FunctionPropertyAssignmentSyntax.prototype.__kind = 241 /* FunctionPropertyAssignment */, ParameterSyntax.prototype.__kind = 242 /* Parameter */, EnumElementSyntax.prototype.__kind = 243 /* EnumElement */, TypeAnnotationSyntax.prototype.__kind = 244 /* TypeAnnotation */, ExternalModuleReferenceSyntax.prototype.__kind = 245 /* ExternalModuleReference */, ModuleNameModuleReferenceSyntax.prototype.__kind = 246 /* ModuleNameModuleReference */; - })(Syntax.Concrete || (Syntax.Concrete = {})); - var Concrete = Syntax.Concrete; - })(TypeScript.Syntax || (TypeScript.Syntax = {})); - var Syntax = TypeScript.Syntax; + })(Concrete = Syntax.Concrete || (Syntax.Concrete = {})); + })(Syntax = TypeScript.Syntax || (TypeScript.Syntax = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -25427,6 +25484,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var IncrementalParser; (function (IncrementalParser) { function createParserSource(oldSyntaxTree, textChangeRange, text) { var fileName = oldSyntaxTree.fileName(); @@ -25826,11 +25884,11 @@ var TypeScript; return TypeScript.Parser.parseSource(createParserSource(oldSyntaxTree, textChangeRange, newText), oldSyntaxTree.isDeclaration()); } IncrementalParser.parse = parse; - })(TypeScript.IncrementalParser || (TypeScript.IncrementalParser = {})); - var IncrementalParser = TypeScript.IncrementalParser; + })(IncrementalParser = TypeScript.IncrementalParser || (TypeScript.IncrementalParser = {})); })(TypeScript || (TypeScript = {})); var ts; (function (ts) { + var OutliningElementsCollector; (function (OutliningElementsCollector) { function collectElements(sourceFile) { var elements = []; @@ -25880,11 +25938,11 @@ var ts; return elements; } OutliningElementsCollector.collectElements = collectElements; - })(ts.OutliningElementsCollector || (ts.OutliningElementsCollector = {})); - var OutliningElementsCollector = ts.OutliningElementsCollector; + })(OutliningElementsCollector = ts.OutliningElementsCollector || (ts.OutliningElementsCollector = {})); })(ts || (ts = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { var NavigationBarItemGetter = (function () { function NavigationBarItemGetter() { @@ -26131,11 +26189,11 @@ var TypeScript; return NavigationBarItemGetter; })(); Services.NavigationBarItemGetter = NavigationBarItemGetter; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { var BraceMatcher = (function () { function BraceMatcher() { @@ -26191,12 +26249,13 @@ var TypeScript; return BraceMatcher; })(); Services.BraceMatcher = BraceMatcher; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Breakpoints; (function (Breakpoints) { function createBreakpointSpanInfo(parentElement) { var childElements = []; @@ -27078,13 +27137,12 @@ var TypeScript; return breakpointResolver.breakpointSpanOf(positionedToken); } Breakpoints.getBreakpointLocation = getBreakpointLocation; - })(Services.Breakpoints || (Services.Breakpoints = {})); - var Breakpoints = Services.Breakpoints; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Breakpoints = Services.Breakpoints || (Services.Breakpoints = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Indentation; (function (Indentation) { function columnForEndOfTokenAtPosition(syntaxTree, position, options) { var token = TypeScript.findToken(syntaxTree.sourceUnit(), position); @@ -27180,12 +27238,13 @@ var TypeScript; return value.length; } Indentation.firstNonWhitespacePosition = firstNonWhitespacePosition; - })(TypeScript.Indentation || (TypeScript.Indentation = {})); - var Indentation = TypeScript.Indentation; + })(Indentation = TypeScript.Indentation || (TypeScript.Indentation = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var TextSnapshot = (function () { function TextSnapshot(snapshot) { @@ -27242,14 +27301,14 @@ var TypeScript; return TextSnapshot; })(); Formatting.TextSnapshot = TextSnapshot; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var TextSnapshotLine = (function () { function TextSnapshotLine(_snapshot, _lineNumber, _start, _end, _lineBreak) { @@ -27292,14 +27351,14 @@ var TypeScript; return TextSnapshotLine; })(); Formatting.TextSnapshotLine = TextSnapshotLine; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var SnapshotPoint = (function () { function SnapshotPoint(snapshot, position) { @@ -27315,14 +27374,14 @@ var TypeScript; return SnapshotPoint; })(); Formatting.SnapshotPoint = SnapshotPoint; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var FormattingContext = (function () { function FormattingContext(snapshot, formattingRequestKind) { @@ -27401,14 +27460,14 @@ var TypeScript; return FormattingContext; })(); Formatting.FormattingContext = FormattingContext; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var FormattingManager = (function () { function FormattingManager(syntaxTree, snapshot, rulesProvider, editorOptions) { @@ -27475,14 +27534,14 @@ var TypeScript; return FormattingManager; })(); Formatting.FormattingManager = FormattingManager; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { (function (FormattingRequestKind) { FormattingRequestKind[FormattingRequestKind["FormatDocument"] = 0] = "FormatDocument"; @@ -27493,14 +27552,14 @@ var TypeScript; FormattingRequestKind[FormattingRequestKind["FormatOnPaste"] = 5] = "FormatOnPaste"; })(Formatting.FormattingRequestKind || (Formatting.FormattingRequestKind = {})); var FormattingRequestKind = Formatting.FormattingRequestKind; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var Rule = (function () { function Rule(Descriptor, Operation, Flag) { @@ -27515,14 +27574,14 @@ var TypeScript; return Rule; })(); Formatting.Rule = Rule; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { (function (RuleAction) { RuleAction[RuleAction["Ignore"] = 0] = "Ignore"; @@ -27531,14 +27590,14 @@ var TypeScript; RuleAction[RuleAction["Delete"] = 3] = "Delete"; })(Formatting.RuleAction || (Formatting.RuleAction = {})); var RuleAction = Formatting.RuleAction; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var RuleDescriptor = (function () { function RuleDescriptor(LeftTokenRange, RightTokenRange) { @@ -27563,28 +27622,28 @@ var TypeScript; return RuleDescriptor; })(); Formatting.RuleDescriptor = RuleDescriptor; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { (function (RuleFlags) { RuleFlags[RuleFlags["None"] = 0] = "None"; RuleFlags[RuleFlags["CanDeleteNewLines"] = 1] = "CanDeleteNewLines"; })(Formatting.RuleFlags || (Formatting.RuleFlags = {})); var RuleFlags = Formatting.RuleFlags; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var RuleOperation = (function () { function RuleOperation() { @@ -27606,14 +27665,14 @@ var TypeScript; return RuleOperation; })(); Formatting.RuleOperation = RuleOperation; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var RuleOperationContext = (function () { function RuleOperationContext() { @@ -27641,14 +27700,14 @@ var TypeScript; return RuleOperationContext; })(); Formatting.RuleOperationContext = RuleOperationContext; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var Rules = (function () { function Rules() { @@ -27997,14 +28056,14 @@ var TypeScript; return Rules; })(); Formatting.Rules = Rules; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var RulesMap = (function () { function RulesMap() { @@ -28128,14 +28187,14 @@ var TypeScript; return RulesBucket; })(); Formatting.RulesBucket = RulesBucket; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var RulesProvider = (function () { function RulesProvider(logger) { @@ -28217,14 +28276,14 @@ var TypeScript; return RulesProvider; })(); Formatting.RulesProvider = RulesProvider; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var TextEditInfo = (function () { function TextEditInfo(position, length, replaceWith) { @@ -28238,15 +28297,16 @@ var TypeScript; return TextEditInfo; })(); Formatting.TextEditInfo = TextEditInfo; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { + var Shared; (function (Shared) { var TokenRangeAccess = (function () { function TokenRangeAccess(from, to, except) { @@ -28361,16 +28421,15 @@ var TypeScript; return TokenRange; })(); Shared.TokenRange = TokenRange; - })(Formatting.Shared || (Formatting.Shared = {})); - var Shared = Formatting.Shared; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Shared = Formatting.Shared || (Formatting.Shared = {})); + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var TokenSpan = (function (_super) { __extends(TokenSpan, _super); @@ -28381,14 +28440,14 @@ var TypeScript; return TokenSpan; })(TypeScript.TextSpan); Formatting.TokenSpan = TokenSpan; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var IndentationNodeContext = (function () { function IndentationNodeContext(parent, node, fullStart, indentationAmount, childIndentationAmountDelta) { @@ -28454,14 +28513,14 @@ var TypeScript; return IndentationNodeContext; })(); Formatting.IndentationNodeContext = IndentationNodeContext; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var IndentationNodeContextPool = (function () { function IndentationNodeContextPool() { @@ -28488,14 +28547,14 @@ var TypeScript; return IndentationNodeContextPool; })(); Formatting.IndentationNodeContextPool = IndentationNodeContextPool; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var IndentationTrackingWalker = (function (_super) { __extends(IndentationTrackingWalker, _super); @@ -28702,14 +28761,14 @@ var TypeScript; return IndentationTrackingWalker; })(TypeScript.SyntaxWalker); Formatting.IndentationTrackingWalker = IndentationTrackingWalker; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var MultipleTokenIndenter = (function (_super) { __extends(MultipleTokenIndenter, _super); @@ -28842,14 +28901,14 @@ var TypeScript; return MultipleTokenIndenter; })(Formatting.IndentationTrackingWalker); Formatting.MultipleTokenIndenter = MultipleTokenIndenter; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var SingleTokenIndenter = (function (_super) { __extends(SingleTokenIndenter, _super); @@ -28874,14 +28933,14 @@ var TypeScript; return SingleTokenIndenter; })(Formatting.IndentationTrackingWalker); Formatting.SingleTokenIndenter = SingleTokenIndenter; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { + var Formatting; (function (Formatting) { var Formatter = (function (_super) { __extends(Formatter, _super); @@ -29091,83 +29150,8 @@ var TypeScript; return Formatter; })(Formatting.MultipleTokenIndenter); Formatting.Formatter = Formatter; - })(Services.Formatting || (Services.Formatting = {})); - var Formatting = Services.Formatting; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; -})(TypeScript || (TypeScript = {})); -var TypeScript; -(function (TypeScript) { - var BloomFilter = (function () { - function BloomFilter(expectedCount) { - var m = Math.max(1, BloomFilter.computeM(expectedCount)); - var k = Math.max(1, BloomFilter.computeK(expectedCount)); - ; - var sizeInEvenBytes = (m + 7) & ~7; - this.bitArray = []; - for (var i = 0, len = sizeInEvenBytes; i < len; i++) { - this.bitArray[i] = false; - } - this.hashFunctionCount = k; - } - BloomFilter.computeM = function (expectedCount) { - var p = BloomFilter.falsePositiveProbability; - var n = expectedCount; - var numerator = n * Math.log(p); - var denominator = Math.log(1.0 / Math.pow(2.0, Math.log(2.0))); - return Math.ceil(numerator / denominator); - }; - BloomFilter.computeK = function (expectedCount) { - var n = expectedCount; - var m = BloomFilter.computeM(expectedCount); - var temp = Math.log(2.0) * m / n; - return Math.round(temp); - }; - BloomFilter.prototype.computeHash = function (key, seed) { - return TypeScript.Hash.computeMurmur2StringHashCode(key, seed); - }; - BloomFilter.prototype.addKeys = function (keys) { - for (var name in keys) { - if (ts.lookUp(keys, name)) { - this.add(name); - } - } - }; - BloomFilter.prototype.add = function (value) { - for (var i = 0; i < this.hashFunctionCount; i++) { - var hash = this.computeHash(value, i); - hash = hash % this.bitArray.length; - this.bitArray[Math.abs(hash)] = true; - } - }; - BloomFilter.prototype.probablyContains = function (value) { - for (var i = 0; i < this.hashFunctionCount; i++) { - var hash = this.computeHash(value, i); - hash = hash % this.bitArray.length; - if (!this.bitArray[Math.abs(hash)]) { - return false; - } - } - return true; - }; - BloomFilter.prototype.isEquivalent = function (filter) { - return BloomFilter.isEquivalent(this.bitArray, filter.bitArray) && this.hashFunctionCount === filter.hashFunctionCount; - }; - BloomFilter.isEquivalent = function (array1, array2) { - if (array1.length !== array2.length) { - return false; - } - for (var i = 0; i < array1.length; i++) { - if (array1[i] !== array2[i]) { - return false; - } - } - return true; - }; - BloomFilter.falsePositiveProbability = 0.0001; - return BloomFilter; - })(); - TypeScript.BloomFilter = BloomFilter; + })(Formatting = Services.Formatting || (Services.Formatting = {})); + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -29822,6 +29806,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { + var ASTHelpers; (function (ASTHelpers) { var sentinelEmptyArray = []; function isValidAstNode(ast) { @@ -30393,8 +30378,7 @@ var TypeScript; return result; } ASTHelpers.getModuleNames = getModuleNames; - })(TypeScript.ASTHelpers || (TypeScript.ASTHelpers = {})); - var ASTHelpers = TypeScript.ASTHelpers; + })(ASTHelpers = TypeScript.ASTHelpers || (TypeScript.ASTHelpers = {})); })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -30885,29 +30869,6 @@ var ts; SourceFileObject.prototype.isDeclareFile = function () { return TypeScript.isDTSFile(this.filename); }; - SourceFileObject.prototype.getBloomFilter = function () { - if (!this.bloomFilter) { - var identifiers = TypeScript.createIntrinsicsObject(); - var pre = function (cur) { - if (TypeScript.ASTHelpers.isValidAstNode(cur)) { - if (cur.kind() === 11 /* IdentifierName */) { - var nodeText = TypeScript.tokenValueText(cur); - identifiers[nodeText] = true; - } - } - }; - TypeScript.getAstWalkerFactory().simpleWalk(this.getSourceUnit(), pre, null, identifiers); - var identifierCount = 0; - for (var name in identifiers) { - if (identifiers[name]) { - identifierCount++; - } - } - this.bloomFilter = new TypeScript.BloomFilter(identifierCount); - this.bloomFilter.addKeys(identifiers); - } - return this.bloomFilter; - }; SourceFileObject.prototype.update = function (scriptSnapshot, version, isOpen, textChangeRange) { var oldSyntaxTree = this.syntaxTree; if (textChangeRange && ts.Debug.shouldAssert(1 /* Normal */)) { @@ -31466,6 +31427,79 @@ var ts; }; } ts.createDocumentRegistry = createDocumentRegistry; + function getTargetLabel(referenceNode, labelName) { + while (referenceNode) { + if (referenceNode.kind === 159 /* LabelledStatement */ && referenceNode.label.text === labelName) { + return referenceNode.label; + } + referenceNode = referenceNode.parent; + } + return undefined; + } + function isJumpStatementTarget(node) { + return node.kind === 55 /* Identifier */ && (node.parent.kind === 153 /* BreakStatement */ || node.parent.kind === 152 /* ContinueStatement */) && node.parent.label === node; + } + function isLabelOfLabeledStatement(node) { + return node.kind === 55 /* Identifier */ && node.parent.kind === 159 /* LabelledStatement */ && node.parent.label === node; + } + function isLabelName(node) { + return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); + } + function isCallExpressionTarget(node) { + if (node.parent.kind === 130 /* PropertyAccess */ && node.parent.right === node) + node = node.parent; + return node.parent.kind === 132 /* CallExpression */ && node.parent.func === node; + } + function isNewExpressionTarget(node) { + if (node.parent.kind === 130 /* PropertyAccess */ && node.parent.right === node) + node = node.parent; + return node.parent.kind === 133 /* NewExpression */ && node.parent.func === node; + } + function isAnyFunction(node) { + switch (node.kind) { + case 136 /* FunctionExpression */: + case 167 /* FunctionDeclaration */: + case 137 /* ArrowFunction */: + case 116 /* Method */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 117 /* Constructor */: + return true; + } + return false; + } + function isNameOfFunctionDeclaration(node) { + return node.kind === 55 /* Identifier */ && isAnyFunction(node.parent) && node.parent.name === node; + } + function isNameOfPropertyAssignment(node) { + return (node.kind === 55 /* Identifier */ || node.kind === 3 /* StringLiteral */ || node.kind === 2 /* NumericLiteral */) && node.parent.kind === 129 /* PropertyAssignment */ && node.parent.name === node; + } + function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { + if (node.kind === 3 /* StringLiteral */ || node.kind === 2 /* NumericLiteral */) { + switch (node.parent.kind) { + case 115 /* Property */: + case 129 /* PropertyAssignment */: + case 176 /* EnumMember */: + case 116 /* Method */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 172 /* ModuleDeclaration */: + return node.parent.name === node; + case 131 /* IndexedAccess */: + return node.parent.index === node; + } + } + return false; + } + function isNameOfExternalModuleImportOrDeclaration(node) { + return node.kind === 3 /* StringLiteral */ && ((node.parent.kind === 172 /* ModuleDeclaration */ && node.parent.name === node) || (node.parent.kind === 174 /* ImportDeclaration */ && node.parent.externalModuleName === node)); + } + var SearchMeaning; + (function (SearchMeaning) { + SearchMeaning[SearchMeaning["Value"] = 0x1] = "Value"; + SearchMeaning[SearchMeaning["Type"] = 0x2] = "Type"; + SearchMeaning[SearchMeaning["Namespace"] = 0x4] = "Namespace"; + })(SearchMeaning || (SearchMeaning = {})); var keywordCompletions = []; for (var i = ts.SyntaxKind.FirstKeyword; i <= ts.SyntaxKind.LastKeyword; i++) { keywordCompletions.push({ @@ -31499,8 +31533,7 @@ var ts; return { getSourceFile: function (filename, languageVersion) { var sourceFile = getSourceFile(filename); - ts.Debug.assert(!!sourceFile, "sourceFile can not be undefined"); - return sourceFile.getSourceFile(); + return sourceFile && sourceFile.getSourceFile(); }, getCancellationToken: function () { return cancellationToken; }, getCanonicalFileName: function (filename) { return useCaseSensitivefilenames ? filename : filename.toLowerCase(); }, @@ -31757,7 +31790,7 @@ var ts; isRightOfDot = true; node = node.parent.left; } - var mappedNode = getNodeAtPosition(sourceFile.getSourceFile(), TypeScript.end(node) - 1); + var mappedNode = getNodeAtPosition(sourceFile, TypeScript.end(node) - 1); ts.Debug.assert(mappedNode, "Could not map a Fidelity node to an AST node"); activeCompletionSession = { filename: filename, @@ -31844,8 +31877,9 @@ var ts; current = child; continue outer; } - if (child.end > position) + if (child.end > position) { break; + } } return current; } @@ -31857,6 +31891,7 @@ var ts; return node; } switch (node.kind) { + case 177 /* SourceFile */: case 116 /* Method */: case 167 /* FunctionDeclaration */: case 136 /* FunctionExpression */: @@ -31941,9 +31976,10 @@ var ts; synchronizeHostData(); fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); - var node = getNodeAtPosition(sourceFile.getSourceFile(), position); - if (!node) + var node = getNodeAtPosition(sourceFile, position); + if (!node) { return undefined; + } var symbol = typeInfoResolver.getSymbolInfo(node); var type = symbol && typeInfoResolver.getTypeOfSymbol(symbol); if (type) { @@ -31952,43 +31988,6 @@ var ts; return undefined; } function getDefinitionAtPosition(filename, position) { - function getTargetLabel(node, labelName) { - while (node) { - if (node.kind === 159 /* LabelledStatement */ && node.label.text === labelName) { - return node.label; - } - node = node.parent; - } - return undefined; - } - function isJumpStatementTarget(node) { - return node.kind === 55 /* Identifier */ && (node.parent.kind === 153 /* BreakStatement */ || node.parent.kind === 152 /* ContinueStatement */) && node.parent.label === node; - } - function isCallExpressionTarget(node) { - if (node.parent.kind === 130 /* PropertyAccess */ && node.parent.right === node) - node = node.parent; - return node.parent.kind === 132 /* CallExpression */ && node.parent.func === node; - } - function isNewExpressionTarget(node) { - if (node.parent.kind === 130 /* PropertyAccess */ && node.parent.right === node) - node = node.parent; - return node.parent.kind === 133 /* NewExpression */ && node.parent.func === node; - } - function isFunctionDeclaration(node) { - switch (node.kind) { - case 167 /* FunctionDeclaration */: - case 116 /* Method */: - case 136 /* FunctionExpression */: - case 118 /* GetAccessor */: - case 119 /* SetAccessor */: - case 137 /* ArrowFunction */: - return true; - } - return false; - } - function isNameOfFunctionDeclaration(node) { - return node.kind === 55 /* Identifier */ && isFunctionDeclaration(node.parent) && node.parent.name === node; - } function getDefinitionInfo(node, symbolKind, symbolName, containerName) { return new DefinitionInfo(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()), symbolKind, symbolName, undefined, containerName); } @@ -32031,7 +32030,7 @@ var ts; synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile.getSourceFile(), position); + var node = getNodeAtPosition(sourceFile, position); if (!node) { return undefined; } @@ -32040,7 +32039,7 @@ var ts; var label = getTargetLabel(node.parent, node.text); return label ? [getDefinitionInfo(label, ScriptElementKind.label, labelName, undefined)] : undefined; } - var comment = ts.forEach(sourceFile.getSourceFile().referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; }); + var comment = ts.forEach(sourceFile.referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; }); if (comment) { var targetFilename = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(filename), comment.filename)); if (program.getSourceFile(targetFilename)) { @@ -32066,6 +32065,500 @@ var ts; } return result; } + function getOccurrencesAtPosition(filename, position) { + synchronizeHostData(); + filename = TypeScript.switchToForwardSlashes(filename); + var sourceFile = getSourceFile(filename); + var node = getNodeAtPosition(sourceFile, position); + if (!node) { + return undefined; + } + if (node.kind === 55 /* Identifier */ || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { + return getReferencesForNode(node, [sourceFile]); + } + switch (node.kind) { + case 86 /* TryKeyword */: + case 58 /* CatchKeyword */: + case 71 /* FinallyKeyword */: + if (hasKind(parent(parent(node)), 161 /* TryStatement */)) { + return getTryCatchFinallyOccurrences(node.parent.parent); + } + break; + case 82 /* SwitchKeyword */: + if (hasKind(node.parent, 156 /* SwitchStatement */)) { + return getSwitchCaseDefaultOccurrences(node.parent); + } + break; + case 57 /* CaseKeyword */: + case 63 /* DefaultKeyword */: + if (hasKind(parent(parent(node)), 156 /* SwitchStatement */)) { + return getSwitchCaseDefaultOccurrences(node.parent.parent); + } + break; + case 56 /* BreakKeyword */: + if (hasKind(node.parent, 153 /* BreakStatement */)) { + return getBreakStatementOccurences(node.parent); + } + break; + } + return undefined; + function getTryCatchFinallyOccurrences(tryStatement) { + var keywords = []; + pushKeywordIf(keywords, tryStatement.getFirstToken(), 86 /* TryKeyword */); + if (tryStatement.catchBlock) { + pushKeywordIf(keywords, tryStatement.catchBlock.getFirstToken(), 58 /* CatchKeyword */); + } + if (tryStatement.finallyBlock) { + pushKeywordIf(keywords, tryStatement.finallyBlock.getFirstToken(), 71 /* FinallyKeyword */); + } + return keywordsToReferenceEntries(keywords); + } + function getSwitchCaseDefaultOccurrences(switchStatement) { + var keywords = []; + pushKeywordIf(keywords, switchStatement.getFirstToken(), 82 /* SwitchKeyword */); + ts.forEach(switchStatement.clauses, function (clause) { + pushKeywordIf(keywords, clause.getFirstToken(), 57 /* CaseKeyword */, 63 /* DefaultKeyword */); + ts.forEachChild(clause, function aggregateBreakKeywords(node) { + switch (node.kind) { + case 153 /* BreakStatement */: + if (!node.label) { + pushKeywordIf(keywords, node.getFirstToken(), 56 /* BreakKeyword */); + } + case 150 /* ForStatement */: + case 151 /* ForInStatement */: + case 148 /* DoStatement */: + case 149 /* WhileStatement */: + case 156 /* SwitchStatement */: + return; + } + if (!isAnyFunction(node)) { + ts.forEachChild(node, aggregateBreakKeywords); + } + }); + }); + return keywordsToReferenceEntries(keywords); + } + function getBreakStatementOccurences(breakStatement) { + if (breakStatement.label) { + return undefined; + } + for (var owner = node.parent; owner; owner = owner.parent) { + switch (owner.kind) { + case 150 /* ForStatement */: + case 151 /* ForInStatement */: + case 148 /* DoStatement */: + case 149 /* WhileStatement */: + return undefined; + case 156 /* SwitchStatement */: + return getSwitchCaseDefaultOccurrences(owner); + default: + if (isAnyFunction(owner)) { + return undefined; + } + } + } + return undefined; + } + function hasKind(node, kind) { + return !!(node && node.kind === kind); + } + function parent(node) { + return node && node.parent; + } + function pushKeywordIf(keywordList, token) { + var expected = []; + for (var _i = 2; _i < arguments.length; _i++) { + expected[_i - 2] = arguments[_i]; + } + if (!token) { + return; + } + if (ts.contains(expected, token.kind)) { + keywordList.push(token); + } + } + function keywordsToReferenceEntries(keywords) { + return ts.map(keywords, function (keyword) { return new ReferenceEntry(filename, TypeScript.TextSpan.fromBounds(keyword.getStart(), keyword.end), false); }); + } + } + function getReferencesAtPosition(filename, position) { + synchronizeHostData(); + filename = TypeScript.switchToForwardSlashes(filename); + var sourceFile = getSourceFile(filename); + var node = getNodeAtPosition(sourceFile, position); + if (!node) { + return undefined; + } + if (node.kind !== 55 /* Identifier */ && !isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && !isNameOfExternalModuleImportOrDeclaration(node)) { + return undefined; + } + return getReferencesForNode(node, program.getSourceFiles()); + } + function getReferencesForNode(node, sourceFiles) { + if (isLabelName(node)) { + if (isJumpStatementTarget(node)) { + var labelDefinition = getTargetLabel(node.parent, node.text); + return labelDefinition ? getLabelReferencesInNode(labelDefinition.parent, labelDefinition) : [getReferenceEntry(node)]; + } + else { + return getLabelReferencesInNode(node.parent, node); + } + } + var symbol = typeInfoResolver.getSymbolInfo(node); + if (!symbol) { + return [getReferenceEntry(node)]; + } + if (!symbol.getDeclarations()) { + return undefined; + } + var result; + var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations()); + var symbolName = getNormalizedSymbolName(symbol); + var scope = getSymbolScope(symbol); + if (scope) { + result = []; + getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, result); + } + else { + ts.forEach(sourceFiles, function (sourceFile) { + cancellationToken.throwIfCancellationRequested(); + if (ts.lookUp(sourceFile.identifiers, symbolName)) { + result = result || []; + getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, result); + } + }); + } + return result; + function getNormalizedSymbolName(symbol) { + var functionExpression = ts.getDeclarationOfKind(symbol, 136 /* FunctionExpression */); + if (functionExpression && functionExpression.name) { + var name = functionExpression.name.text; + } + else { + var name = symbol.name; + } + var length = name.length; + if (length >= 2 && name.charCodeAt(0) === 34 /* doubleQuote */ && name.charCodeAt(length - 1) === 34 /* doubleQuote */) { + return name.substring(1, length - 1); + } + ; + return name; + } + function getSymbolScope(symbol) { + if (symbol.getFlags() && (2 /* Property */ | 2048 /* Method */)) { + var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32 /* Private */) ? d : undefined; }); + if (privateDeclaration) { + return privateDeclaration.parent; + } + } + if (symbol.parent) { + return undefined; + } + var scope = undefined; + var declarations = symbol.getDeclarations(); + for (var i = 0, n = declarations.length; i < n; i++) { + var container = getContainerNode(declarations[i]); + if (scope && scope !== container) { + return undefined; + } + if (container.kind === 177 /* SourceFile */ && !ts.isExternalModule(container)) { + return undefined; + } + scope = container; + } + return scope; + } + function getPossibleSymbolReferencePositions(sourceFile, symbolName, start, end) { + var positions = []; + if (!symbolName || !symbolName.length) { + return positions; + } + var text = sourceFile.text; + var sourceLength = text.length; + var symbolNameLength = symbolName.length; + var position = text.indexOf(symbolName, start); + while (position >= 0) { + cancellationToken.throwIfCancellationRequested(); + if (position > end) + break; + var endPosition = position + symbolNameLength; + if ((position === 0 || !ts.isIdentifierPart(text.charCodeAt(position - 1), 1 /* ES5 */)) && (endPosition === sourceLength || !ts.isIdentifierPart(text.charCodeAt(endPosition), 1 /* ES5 */))) { + positions.push(position); + } + position = text.indexOf(symbolName, position + symbolNameLength + 1); + } + return positions; + } + function getLabelReferencesInNode(container, targetLabel) { + var result = []; + var sourceFile = container.getSourceFile(); + var labelName = targetLabel.text; + var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); + ts.forEach(possiblePositions, function (position) { + cancellationToken.throwIfCancellationRequested(); + var node = getNodeAtPosition(sourceFile, position); + if (!node || node.getWidth() !== labelName.length) { + return; + } + if (node === targetLabel || (isJumpStatementTarget(node) && getTargetLabel(node, labelName) === targetLabel)) { + result.push(getReferenceEntry(node)); + } + }); + return result; + } + function isValidReferencePosition(node, searchSymbolName) { + if (node) { + switch (node.kind) { + case 55 /* Identifier */: + return node.getWidth() === searchSymbolName.length; + case 3 /* StringLiteral */: + if (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { + return node.getWidth() === searchSymbolName.length + 2; + } + break; + case 2 /* NumericLiteral */: + if (isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + return node.getWidth() === searchSymbolName.length; + } + break; + } + } + return false; + } + function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, result) { + var sourceFile = container.getSourceFile(); + var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, searchText, container.getStart(), container.getEnd()); + if (possiblePositions.length) { + var searchSymbols = populateSearchSymbolSet(searchSymbol, searchLocation); + ts.forEach(possiblePositions, function (position) { + cancellationToken.throwIfCancellationRequested(); + var referenceLocation = getNodeAtPosition(sourceFile, position); + if (!isValidReferencePosition(referenceLocation, searchText)) { + return; + } + if (!(getMeaningFromLocation(referenceLocation) & searchMeaning)) { + return; + } + var referenceSymbol = typeInfoResolver.getSymbolInfo(referenceLocation); + if (!referenceSymbol || !(referenceSymbol.getDeclarations())) { + return; + } + if (isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) { + result.push(getReferenceEntry(referenceLocation)); + } + }); + } + } + function populateSearchSymbolSet(symbol, location) { + var result = [symbol]; + var rootSymbol = typeInfoResolver.getRootSymbol(symbol); + if (rootSymbol && rootSymbol !== symbol) { + result.push(rootSymbol); + } + if (isNameOfPropertyAssignment(location)) { + var symbolFromContextualType = getPropertySymbolFromContextualType(location); + if (symbolFromContextualType) + result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType)); + } + if (symbol.parent && symbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { + getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result); + } + return result; + } + function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { + if (symbol.flags & (16 /* Class */ | 32 /* Interface */)) { + ts.forEach(symbol.getDeclarations(), function (declaration) { + if (declaration.kind === 169 /* ClassDeclaration */) { + getPropertySymbolFromTypeReference(declaration.baseType); + ts.forEach(declaration.implementedTypes, getPropertySymbolFromTypeReference); + } + else if (declaration.kind === 170 /* InterfaceDeclaration */) { + ts.forEach(declaration.baseTypes, getPropertySymbolFromTypeReference); + } + }); + } + return; + function getPropertySymbolFromTypeReference(typeReference) { + if (typeReference) { + var typeReferenceSymbol = typeInfoResolver.getSymbolInfo(typeReference.typeName); + if (typeReferenceSymbol) { + var propertySymbol = typeReferenceSymbol.members[propertyName]; + if (propertySymbol) + result.push(typeReferenceSymbol.members[propertyName]); + getPropertySymbolsFromBaseTypes(typeReferenceSymbol, propertyName, result); + } + } + } + } + function isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation) { + var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol); + if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) { + return true; + } + if (isNameOfPropertyAssignment(referenceLocation)) { + var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation); + if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) { + return true; + } + } + if (referenceSymbol.parent && referenceSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { + var result = []; + getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result); + return ts.forEach(result, function (s) { return searchSymbols.indexOf(s) >= 0; }); + } + return false; + } + function getPropertySymbolFromContextualType(node) { + if (isNameOfPropertyAssignment(node)) { + var objectLiteral = node.parent.parent; + var contextualType = typeInfoResolver.getContextualType(objectLiteral); + if (contextualType) { + return typeInfoResolver.getPropertyOfType(contextualType, node.text); + } + } + return undefined; + } + function getReferenceEntry(node) { + var start = node.getStart(); + var end = node.getEnd(); + if (node.kind === 3 /* StringLiteral */) { + start += 1; + end -= 1; + } + return new ReferenceEntry(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(start, end), isWriteAccess(node)); + } + function getMeaningFromDeclaration(node) { + switch (node.kind) { + case 114 /* Parameter */: + case 166 /* VariableDeclaration */: + case 115 /* Property */: + case 129 /* PropertyAssignment */: + case 176 /* EnumMember */: + case 116 /* Method */: + case 117 /* Constructor */: + case 118 /* GetAccessor */: + case 119 /* SetAccessor */: + case 167 /* FunctionDeclaration */: + case 136 /* FunctionExpression */: + case 137 /* ArrowFunction */: + case 163 /* CatchBlock */: + return 1 /* Value */; + case 113 /* TypeParameter */: + case 170 /* InterfaceDeclaration */: + case 125 /* TypeLiteral */: + return 2 /* Type */; + case 169 /* ClassDeclaration */: + case 171 /* EnumDeclaration */: + return 1 /* Value */ | 2 /* Type */; + case 172 /* ModuleDeclaration */: + if (node.name.kind === 3 /* StringLiteral */) { + return 4 /* Namespace */ | 1 /* Value */; + } + else if (ts.isInstantiated(node)) { + return 4 /* Namespace */ | 1 /* Value */; + } + else { + return 4 /* Namespace */; + } + break; + case 174 /* ImportDeclaration */: + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + ts.Debug.fail("Unkown declaration type"); + } + function isTypeReference(node) { + if (node.parent.kind === 112 /* QualifiedName */ && node.parent.right === node) + node = node.parent; + return node.parent.kind === 123 /* TypeReference */; + } + function isNamespaceReference(node) { + var root = node; + var isLastClause = true; + if (root.parent.kind === 112 /* QualifiedName */) { + while (root.parent && root.parent.kind === 112 /* QualifiedName */) + root = root.parent; + isLastClause = root.right === node; + } + return root.parent.kind === 123 /* TypeReference */ && !isLastClause; + } + function isInRightSideOfImport(node) { + while (node.parent.kind === 112 /* QualifiedName */) { + node = node.parent; + } + return node.parent.kind === 174 /* ImportDeclaration */ && node.parent.entityName === node; + } + function getMeaningFromRightHandSideOfImport(node) { + ts.Debug.assert(node.kind === 55 /* Identifier */); + if (node.parent.kind === 112 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 174 /* ImportDeclaration */) { + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + return 4 /* Namespace */; + } + function getMeaningFromLocation(node) { + if (node.parent.kind === 175 /* ExportAssignment */) { + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + else if (isInRightSideOfImport(node)) { + return getMeaningFromRightHandSideOfImport(node); + } + else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + return getMeaningFromDeclaration(node.parent); + } + else if (isTypeReference(node)) { + return 2 /* Type */; + } + else if (isNamespaceReference(node)) { + return 4 /* Namespace */; + } + else { + return 1 /* Value */; + } + } + function getIntersectingMeaningFromDeclarations(meaning, declarations) { + if (declarations) { + do { + var lastIterationMeaning = meaning; + for (var i = 0, n = declarations.length; i < n; i++) { + var declarationMeaning = getMeaningFromDeclaration(declarations[i]); + if (declarationMeaning & meaning) { + meaning |= declarationMeaning; + } + } + } while (meaning !== lastIterationMeaning); + } + return meaning; + } + function isWriteAccess(node) { + if (node.kind === 55 /* Identifier */ && ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + return true; + } + var parent = node.parent; + if (parent) { + if (parent.kind === 139 /* PostfixOperator */ || parent.kind === 138 /* PrefixOperator */) { + return true; + } + else if (parent.kind === 140 /* BinaryExpression */ && parent.left === node) { + var operator = parent.operator; + switch (operator) { + case 46 /* AsteriskEqualsToken */: + case 47 /* SlashEqualsToken */: + case 48 /* PercentEqualsToken */: + case 45 /* MinusEqualsToken */: + case 49 /* LessThanLessThanEqualsToken */: + case 50 /* GreaterThanGreaterThanEqualsToken */: + case 51 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 53 /* BarEqualsToken */: + case 54 /* CaretEqualsToken */: + case 52 /* AmpersandEqualsToken */: + case 44 /* PlusEqualsToken */: + case 43 /* EqualsToken */: + return true; + } + } + return false; + } + } + } function getSyntaxTree(filename) { filename = TypeScript.switchToForwardSlashes(filename); return syntaxTreeCache.getCurrentFileSyntaxTree(filename); @@ -32269,8 +32762,8 @@ var ts; getSignatureHelpItems: function (filename, position) { return null; }, getSignatureHelpCurrentArgumentState: function (fileName, position, applicableSpanStart) { return null; }, getDefinitionAtPosition: getDefinitionAtPosition, - getReferencesAtPosition: function (filename, position) { return []; }, - getOccurrencesAtPosition: function (filename, position) { return []; }, + getReferencesAtPosition: getReferencesAtPosition, + getOccurrencesAtPosition: getOccurrencesAtPosition, getImplementorsAtPosition: function (filename, position) { return []; }, getNameOrDottedNameSpan: getNameOrDottedNameSpan, getBreakpointStatementAtPosition: getBreakpointStatementAtPosition, @@ -33165,8 +33658,8 @@ var ts; })(ts || (ts = {})); var TypeScript; (function (TypeScript) { + var Services; (function (Services) { Services.TypeScriptServicesFactory = ts.TypeScriptServicesFactory; - })(TypeScript.Services || (TypeScript.Services = {})); - var Services = TypeScript.Services; + })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); From 3e4c5d5b2f836e6128728ce3caf3763a130c400a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 9 Sep 2014 12:28:25 -0700 Subject: [PATCH 09/17] remove unused file --- scripts/importDefinitllyTypedTests.ts | 124 -------------------------- 1 file changed, 124 deletions(-) delete mode 100644 scripts/importDefinitllyTypedTests.ts diff --git a/scripts/importDefinitllyTypedTests.ts b/scripts/importDefinitllyTypedTests.ts deleted file mode 100644 index caa6be0063a..00000000000 --- a/scripts/importDefinitllyTypedTests.ts +++ /dev/null @@ -1,124 +0,0 @@ -declare var require: any, process: any; -declare var __dirname: any; - -var fs = require("fs"); -var path = require("path"); -var child_process = require('child_process'); - -var tscRoot = path.join(__dirname, "..\\"); -var tscPath = path.join(tscRoot, "built", "instrumented", "tsc.js"); -var rwcTestPath = path.join(tscRoot, "tests", "cases", "rwc", "dt"); -var definitelyTypedRoot = process.argv[2]; - -function fileExtensionIs(path: string, extension: string): boolean { - var pathLen = path.length; - var extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen).toLocaleLowerCase() === extension.toLocaleLowerCase(); -} - -function copyFileSync(source, destination) { - var text = fs.readFileSync(source); - fs.writeFileSync(destination, text); -} - -function importDefinitelyTypedTest(testCaseName: string, testFiles: string[], responseFile: string ) { - var cmd = "node " + tscPath + " --module commonjs " + testFiles.join(" "); - if (responseFile) cmd += " @" + responseFile; - - var testDirectoryName = testCaseName + "_" + Math.floor((Math.random() * 10000) + 1); - var testDirectoryPath = path.join(process.env["temp"], testDirectoryName); - if (fs.existsSync(testDirectoryPath)) { - throw new Error("Could not create test directory"); - } - fs.mkdirSync(testDirectoryPath); - - child_process.exec(cmd, { - maxBuffer: 1 * 1024 * 1024, - cwd: testDirectoryPath - }, (error, stdout, stderr) => { - //console.log("importing " + testCaseName + " ..."); - //console.log(cmd); - - if (error) { - console.log("importing " + testCaseName + " ..."); - console.log(cmd); - console.log("==> error " + JSON.stringify(error)); - console.log("==> stdout " + String(stdout)); - console.log("==> stderr " + String(stderr)); - console.log("\r\n"); - return; - } - - // copy generated file to output location - var outputFilePath = path.join(testDirectoryPath, "iocapture0.json"); - var testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json"); - copyFileSync(outputFilePath, testCasePath); - - //console.log("output generated at: " + outputFilePath); - - if (!fs.existsSync(testCasePath)) { - throw new Error("could not find test case at: " + testCasePath); - } - else { - fs.unlinkSync(outputFilePath); - fs.rmdirSync(testDirectoryPath); - //console.log("testcase generated at: " + testCasePath); - //console.log("Done."); - } - //console.log("\r\n"); - - }) - .on('error', function (error) { - console.log("==> error " + JSON.stringify(error)); - console.log("\r\n"); - }); -} - -function importDefinitelyTypedTests(definitelyTypedRoot: string): void { - fs.readdir(definitelyTypedRoot, (err, subDirectorys) => { - if (err) throw err; - - subDirectorys - .filter(d => ["_infrastructure", "node_modules", ".git"].indexOf(d) >= 0) - .filter(i => fs.statSync(path.join(definitelyTypedRoot, i)).isDirectory()) - .forEach(d => { - var directoryPath = path.join(definitelyTypedRoot, d); - fs.readdir(directoryPath, function (err, files) { - if (err) throw err; - - var tsFiles = []; - var testFiles = []; - var paramFile; - - files - .map(f => path.join(directoryPath, f)) - .forEach(f => { - if (fileExtensionIs(f, ".ts")) tsFiles.push(f); - else if (fileExtensionIs(f, ".tscparams")) paramFile = f; - - if (fileExtensionIs(f, "-tests.ts")) testFiles.push(f); - }); - - if (testFiles.length === 0) { - // no test files but multiple d.ts's, e.g. winjs - var regexp = new RegExp(d + "(([-][0-9])|([\.]d[\.]ts))"); - if (tsFiles.length > 1 && tsFiles.every(t => fileExtensionIs(t, ".d.ts") && regexp.test(t))) { - tsFiles.forEach(filename => { - importDefinitelyTypedTest(path.basename(filename, ".d.ts"), [filename], paramFile); - }); - } - else { - importDefinitelyTypedTest(d, tsFiles, paramFile); - } - } - else { - testFiles.forEach(filename => { - importDefinitelyTypedTest(path.basename(filename, "-tests.ts"), [filename], paramFile); - }); - } - }); - }) - }); -} - -importDefinitelyTypedTests(definitelyTypedRoot); \ No newline at end of file From 840481da3ba92ebff0c63d0a5d64a9396e6fd03a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 9 Sep 2014 12:45:10 -0700 Subject: [PATCH 10/17] Fix the condition for qualifying the symbol of methods and functions in the enclosing declaration Fixes #604 --- src/compiler/checker.ts | 4 +- .../reference/commentsClassMembers.js | 112 +----------------- .../reference/recursiveFunctionTypes1.types | 6 +- 3 files changed, 7 insertions(+), 115 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a4f690137d5..949453ca001 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -907,8 +907,8 @@ module ts { // Get qualified name if (enclosingDeclaration && - // Properties/methods/Signatures/Constructors/TypeParameters do not need qualification - !(symbol.flags & (SymbolFlags.PropertyOrAccessor | SymbolFlags.Signature | SymbolFlags.Constructor | SymbolFlags.Method | SymbolFlags.TypeParameter))) { + // TypeParameters do not need qualification + !(symbol.flags & SymbolFlags.TypeParameter)) { var symbolName: string; while (symbol) { var isFirstName = !symbolName; diff --git a/tests/baselines/reference/commentsClassMembers.js b/tests/baselines/reference/commentsClassMembers.js index a0cf8f2b631..298991c2eef 100644 --- a/tests/baselines/reference/commentsClassMembers.js +++ b/tests/baselines/reference/commentsClassMembers.js @@ -557,11 +557,11 @@ declare var i1_ncf: (b: number) => number; declare var i1_ncr: number; declare var i1_ncprop: number; declare var i1_s_p: number; -declare var i1_s_f: typeof s2; +declare var i1_s_f: typeof c1.s2; declare var i1_s_r: number; declare var i1_s_prop: number; declare var i1_s_nc_p: number; -declare var i1_s_ncf: typeof nc_s2; +declare var i1_s_ncf: typeof c1.nc_s2; declare var i1_s_ncr: number; declare var i1_s_ncprop: number; declare var i1_c: typeof c1; @@ -577,111 +577,3 @@ declare class cProperties { private y; } declare var cProperties_i: cProperties; - - -//// [DtsFileErrors] - - -==== tests/cases/compiler/commentsClassMembers.d.ts (2 errors) ==== - /** This is comment for c1*/ - declare class c1 { - /** p1 is property of c1*/ - p1: number; - /** sum with property*/ - p2(/** number to add*/ b: number): number; - /** getter property*/ - /** setter property*/ - p3: number; - /** pp1 is property of c1*/ - private pp1; - /** sum with property*/ - private pp2(/** number to add*/ b); - /** getter property*/ - /** setter property*/ - private pp3; - /** Constructor method*/ - constructor(); - /** s1 is static property of c1*/ - static s1: number; - /** static sum with property*/ - static s2(/** number to add*/ b: number): number; - /** static getter property*/ - /** setter property*/ - static s3: number; - nc_p1: number; - nc_p2(b: number): number; - nc_p3: number; - private nc_pp1; - private nc_pp2(b); - private nc_pp3; - static nc_s1: number; - static nc_s2(b: number): number; - static nc_s3: number; - a_p1: number; - a_p2(b: number): number; - a_p3: number; - private a_pp1; - private a_pp2(b); - private a_pp3; - static a_s1: number; - static a_s2(b: number): number; - static a_s3: number; - /** p1 is property of c1 */ - b_p1: number; - /** sum with property */ - b_p2(b: number): number; - /** getter property */ - /** setter property */ - b_p3: number; - /** pp1 is property of c1 */ - private b_pp1; - /** sum with property */ - private b_pp2(b); - /** getter property */ - /** setter property */ - private b_pp3; - /** s1 is static property of c1 */ - static b_s1: number; - /** static sum with property */ - static b_s2(b: number): number; - /** static getter property - */ - /** setter property - */ - static b_s3: number; - } - declare var i1: c1; - declare var i1_p: number; - declare var i1_f: (b: number) => number; - declare var i1_r: number; - declare var i1_prop: number; - declare var i1_nc_p: number; - declare var i1_ncf: (b: number) => number; - declare var i1_ncr: number; - declare var i1_ncprop: number; - declare var i1_s_p: number; - declare var i1_s_f: typeof s2; - ~~ -!!! Cannot find name 's2'. - declare var i1_s_r: number; - declare var i1_s_prop: number; - declare var i1_s_nc_p: number; - declare var i1_s_ncf: typeof nc_s2; - ~~~~~ -!!! Cannot find name 'nc_s2'. - declare var i1_s_ncr: number; - declare var i1_s_ncprop: number; - declare var i1_c: typeof c1; - declare class cProperties { - private val; - /** getter only property*/ - p1: number; - nc_p1: number; - /**setter only property*/ - p2: number; - nc_p2: number; - x: number; - private y; - } - declare var cProperties_i: cProperties; - \ No newline at end of file diff --git a/tests/baselines/reference/recursiveFunctionTypes1.types b/tests/baselines/reference/recursiveFunctionTypes1.types index 535555ef13d..b78494ba24c 100644 --- a/tests/baselines/reference/recursiveFunctionTypes1.types +++ b/tests/baselines/reference/recursiveFunctionTypes1.types @@ -3,8 +3,8 @@ class C { >C : C static g(t: typeof C.g){ } ->g : (t: typeof g) => void ->t : (t: typeof g) => void +>g : (t: typeof C.g) => void +>t : (t: typeof C.g) => void >C : typeof C ->g : (t: typeof g) => void +>g : (t: typeof C.g) => void } From 34c4b312f9ff70946de10598261011382d2b48ae Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Sep 2014 15:17:33 -0700 Subject: [PATCH 11/17] Fix contextual signature instantiation during type inference --- src/compiler/checker.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ec681318806..a29b3614da1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4088,19 +4088,6 @@ module ts { return getSignatureInstantiation(signature, getInferredTypes(context)); } - // Inferentially type an expression by a contextual parameter type (section 4.12.2 in TypeScript spec) - function inferentiallyTypeExpession(expr: Expression, contextualType: Type, contextualMapper: TypeMapper): Type { - var type = checkExpressionWithContextualType(expr, contextualType, contextualMapper); - var signature = getSingleCallSignature(type); - if (signature && signature.typeParameters) { - var contextualSignature = getSingleCallSignature(contextualType); - if (contextualSignature && !contextualSignature.typeParameters) { - type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); - } - } - return type; - } - function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument?: boolean[]): Type[] { var typeParameters = signature.typeParameters; var context = createInferenceContext(typeParameters); @@ -4109,7 +4096,7 @@ module ts { for (var i = 0; i < args.length; i++) { if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); - inferTypes(context, inferentiallyTypeExpession(args[i], parameterType, mapper), parameterType); + inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } // Next, infer from those context sensitive arguments that are no longer excluded @@ -4117,7 +4104,7 @@ module ts { for (var i = 0; i < args.length; i++) { if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); - inferTypes(context, inferentiallyTypeExpession(args[i], parameterType, mapper), parameterType); + inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } @@ -4852,6 +4839,23 @@ module ts { // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { + var type = checkExpressionNode(node, contextualMapper); + if (contextualMapper && contextualMapper !== identityMapper) { + var signature = getSingleCallSignature(type); + if (signature && signature.typeParameters) { + var contextualType = getContextualType(node); + if (contextualType) { + var contextualSignature = getSingleCallSignature(contextualType); + if (contextualSignature && !contextualSignature.typeParameters) { + type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); + } + } + } + } + return type; + } + + function checkExpressionNode(node: Expression, contextualMapper: TypeMapper): Type { switch (node.kind) { case SyntaxKind.Identifier: return checkIdentifier(node); From 2b58a239d179fc246ad1fa9555d338c9fa622bfa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Sep 2014 15:23:24 -0700 Subject: [PATCH 12/17] Accepting new baselines --- .../genericCallWithFunctionTypedArguments5.errors.txt | 4 ++-- .../reference/inferentialTypingWithFunctionTypeNested.types | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments5.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments5.errors.txt index c185756667a..8de5453e2af 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments5.errors.txt +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments5.errors.txt @@ -10,9 +10,9 @@ // more args not allowed var r2 = foo({ cb: (x: T, y: T) => '' }); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! Argument of type '{ cb: (x: T, y: T) => string; }' is not assignable to parameter of type '{ cb: (t: any) => string; }'. +!!! Argument of type '{ cb: (x: T, y: T) => string; }' is not assignable to parameter of type '{ cb: (t: {}) => string; }'. !!! Types of property 'cb' are incompatible: -!!! Type '(x: T, y: T) => string' is not assignable to type '(t: any) => string'. +!!! Type '(x: T, y: T) => string' is not assignable to type '(t: {}) => string'. var r3 = foo({ cb: (x: string, y: number) => '' }); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! Argument of type '{ cb: (x: string, y: number) => string; }' is not assignable to parameter of type '{ cb: (t: string) => string; }'. diff --git a/tests/baselines/reference/inferentialTypingWithFunctionTypeNested.types b/tests/baselines/reference/inferentialTypingWithFunctionTypeNested.types index 0596081ade3..c411dd00514 100644 --- a/tests/baselines/reference/inferentialTypingWithFunctionTypeNested.types +++ b/tests/baselines/reference/inferentialTypingWithFunctionTypeNested.types @@ -20,10 +20,10 @@ declare function identity(y: V): V; >V : V var s = map("", () => { return { x: identity }; }); ->s : any ->map("", () => { return { x: identity }; }) : any +>s : string +>map("", () => { return { x: identity }; }) : string >map : (x: T, f: () => { x: (s: T) => U; }) => U ->() => { return { x: identity }; } : () => { x: (y: V) => V; } +>() => { return { x: identity }; } : () => { x: (y: string) => string; } >{ x: identity } : { x: (y: V) => V; } >x : (y: V) => V >identity : (y: V) => V From c27379827ba1105e1d0682bae891fe35e5e1c4b1 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 10 Sep 2014 16:44:57 -0700 Subject: [PATCH 13/17] Add asserts for bounds on diagnostics --- src/compiler/core.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fbf767b91a9..c549231eacc 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -198,6 +198,9 @@ module ts { export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic; export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage): Diagnostic { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); + var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { @@ -252,6 +255,9 @@ module ts { } export function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); + var code = diagnosticChain.code; var category = diagnosticChain.category; var messageText = ""; From fad5650be6583c3d68b97e8e02777fc8f0053129 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 10 Sep 2014 17:57:51 -0700 Subject: [PATCH 14/17] Fix the error spans issue --- src/compiler/parser.ts | 5 +++-- .../parserEqualsGreaterThanAfterFunction1.errors.txt | 2 +- .../parserEqualsGreaterThanAfterFunction2.errors.txt | 2 +- .../reference/parserVariableDeclaration6.errors.txt | 2 +- .../reference/parserVariableDeclaration8.errors.txt | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 68c076367d4..cfe27e7e7c3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -81,7 +81,7 @@ module ts { export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic { node = getErrorSpanForNode(node); var file = getSourceFileOfNode(node); - var start = skipTrivia(file.text, node.pos); + var start = node.kind === SyntaxKind.Missing ? node.pos : skipTrivia(file.text, node.pos); var length = node.end - start; return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); @@ -2876,10 +2876,11 @@ module ts { parseExpected(SyntaxKind.VarKeyword); node.declarations = parseVariableDeclarationList(flags, /*noIn*/false); parseSemicolon(); + finishNode(node); if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); } - return finishNode(node); + return node; } function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionDeclaration { diff --git a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt index e3ff187a00e..9f428d7fea7 100644 --- a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt +++ b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt @@ -2,5 +2,5 @@ function => ~~ !!! Identifier expected. - + !!! Function implementation is missing or not immediately following the declaration. \ No newline at end of file diff --git a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt index 24866e9e424..4e9b5fbaa86 100644 --- a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt +++ b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt @@ -8,5 +8,5 @@ !!! ',' expected. !!! ')' expected. - + !!! Function implementation is missing or not immediately following the declaration. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableDeclaration6.errors.txt b/tests/baselines/reference/parserVariableDeclaration6.errors.txt index 01f3935495d..466384c7e0c 100644 --- a/tests/baselines/reference/parserVariableDeclaration6.errors.txt +++ b/tests/baselines/reference/parserVariableDeclaration6.errors.txt @@ -1,4 +1,4 @@ ==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts (1 errors) ==== var - + ~~~ !!! Variable declaration list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableDeclaration8.errors.txt b/tests/baselines/reference/parserVariableDeclaration8.errors.txt index 5e7f335a920..9e2f8edfd25 100644 --- a/tests/baselines/reference/parserVariableDeclaration8.errors.txt +++ b/tests/baselines/reference/parserVariableDeclaration8.errors.txt @@ -1,4 +1,4 @@ ==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts (1 errors) ==== var ; - + ~~~~~ !!! Variable declaration list cannot be empty. \ No newline at end of file From 1f2a2d2ae354b6e5ed59681537aa214f7a155fe0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 11 Sep 2014 09:22:27 -0700 Subject: [PATCH 15/17] Simple fixes for the tests --- scripts/importDefinitelyTypedTests.ts | 79 ++++++++++++++------------- tests/webTestServer.ts | 8 ++- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/scripts/importDefinitelyTypedTests.ts b/scripts/importDefinitelyTypedTests.ts index caa6be0063a..f33ba1dd525 100644 --- a/scripts/importDefinitelyTypedTests.ts +++ b/scripts/importDefinitelyTypedTests.ts @@ -33,44 +33,44 @@ function importDefinitelyTypedTest(testCaseName: string, testFiles: string[], re fs.mkdirSync(testDirectoryPath); child_process.exec(cmd, { - maxBuffer: 1 * 1024 * 1024, - cwd: testDirectoryPath - }, (error, stdout, stderr) => { - //console.log("importing " + testCaseName + " ..."); - //console.log(cmd); - - if (error) { - console.log("importing " + testCaseName + " ..."); - console.log(cmd); - console.log("==> error " + JSON.stringify(error)); - console.log("==> stdout " + String(stdout)); - console.log("==> stderr " + String(stderr)); - console.log("\r\n"); - return; - } - - // copy generated file to output location - var outputFilePath = path.join(testDirectoryPath, "iocapture0.json"); - var testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json"); - copyFileSync(outputFilePath, testCasePath); - - //console.log("output generated at: " + outputFilePath); - - if (!fs.existsSync(testCasePath)) { - throw new Error("could not find test case at: " + testCasePath); - } - else { - fs.unlinkSync(outputFilePath); - fs.rmdirSync(testDirectoryPath); - //console.log("testcase generated at: " + testCasePath); - //console.log("Done."); - } - //console.log("\r\n"); - - }) - .on('error', function (error) { - console.log("==> error " + JSON.stringify(error)); - console.log("\r\n"); + maxBuffer: 1 * 1024 * 1024, + cwd: testDirectoryPath + }, (error, stdout, stderr) => { + console.log("importing " + testCaseName + " ..."); + console.log(cmd); + + if (error) { + console.log("importing " + testCaseName + " ..."); + console.log(cmd); + console.log("==> error " + JSON.stringify(error)); + console.log("==> stdout " + String(stdout)); + console.log("==> stderr " + String(stderr)); + console.log("\r\n"); + return; + } + + // copy generated file to output location + var outputFilePath = path.join(testDirectoryPath, "iocapture0.json"); + var testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json"); + copyFileSync(outputFilePath, testCasePath); + + //console.log("output generated at: " + outputFilePath); + + if (!fs.existsSync(testCasePath)) { + throw new Error("could not find test case at: " + testCasePath); + } + else { + fs.unlinkSync(outputFilePath); + fs.rmdirSync(testDirectoryPath); + //console.log("testcase generated at: " + testCasePath); + //console.log("Done."); + } + //console.log("\r\n"); + + }) + .on('error', function (error) { + console.log("==> error " + JSON.stringify(error)); + console.log("\r\n"); }); } @@ -79,7 +79,8 @@ function importDefinitelyTypedTests(definitelyTypedRoot: string): void { if (err) throw err; subDirectorys - .filter(d => ["_infrastructure", "node_modules", ".git"].indexOf(d) >= 0) + .filter(d => ["_infrastructure", "node_modules", ".git"].indexOf(d) < 0) + .filter(i => i.indexOf("sipml") >=0 ) .filter(i => fs.statSync(path.join(definitelyTypedRoot, i)).isDirectory()) .forEach(d => { var directoryPath = path.join(definitelyTypedRoot, d); diff --git a/tests/webTestServer.ts b/tests/webTestServer.ts index 05cf7a10f20..40e347fed50 100644 --- a/tests/webTestServer.ts +++ b/tests/webTestServer.ts @@ -227,11 +227,15 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons send('success', res, null); break; case RequestType.DeleteFile: - fs.unlinkSync(reqPath); + if (fs.existsSync(reqPath)) { + fs.unlinkSync(reqPath); + } send('success', res, null); break; case RequestType.DeleteDir: - fs.rmdirSync(reqPath); + if (fs.existsSync(reqPath)) { + fs.rmdirSync(reqPath); + } send('success', res, null); break; case RequestType.AppendFile: From 9093bac9deee5227ebbd41526a035f443689d2f6 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 11 Sep 2014 10:29:43 -0700 Subject: [PATCH 16/17] Update LKG --- bin/tsc.js | 87 ++++++++++++++++++++++++--------------- bin/typescriptServices.js | 83 +++++++++++++++++++++++-------------- 2 files changed, 106 insertions(+), 64 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 98e690a82e0..af5f939a80d 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -1532,6 +1532,7 @@ var ts; TypeFormatFlags[TypeFormatFlags["None"] = 0x00000000] = "None"; TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 0x00000001] = "WriteArrayAsGenericType"; TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 0x00000002] = "UseTypeOfFunction"; + TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 0x00000004] = "NoTruncation"; })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); var TypeFormatFlags = ts.TypeFormatFlags; (function (SymbolAccessibility) { @@ -1959,6 +1960,8 @@ var ts; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); @@ -2002,6 +2005,8 @@ var ts; } ts.chainDiagnosticMessages = chainDiagnosticMessages; function flattenDiagnosticChain(file, start, length, diagnosticChain, newLine) { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); var code = diagnosticChain.code; var category = diagnosticChain.category; var messageText = ""; @@ -2257,6 +2262,7 @@ var ts; AssertionLevel[AssertionLevel["VeryAggressive"] = 3] = "VeryAggressive"; })(ts.AssertionLevel || (ts.AssertionLevel = {})); var AssertionLevel = ts.AssertionLevel; + var Debug; (function (Debug) { var currentAssertionLevel = 0 /* None */; function shouldAssert(level) { @@ -2277,8 +2283,7 @@ var ts; Debug.assert(false, message); } Debug.fail = fail; - })(ts.Debug || (ts.Debug = {})); - var Debug = ts.Debug; + })(Debug = ts.Debug || (ts.Debug = {})); })(ts || (ts = {})); var sys = (function () { function getWScriptSystem() { @@ -2544,7 +2549,7 @@ var ts; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { node = getErrorSpanForNode(node); var file = getSourceFileOfNode(node); - var start = ts.skipTrivia(file.text, node.pos); + var start = node.kind === 111 /* Missing */ ? node.pos : ts.skipTrivia(file.text, node.pos); var length = node.end - start; return ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); } @@ -4735,10 +4740,11 @@ var ts; parseExpected(88 /* VarKeyword */); node.declarations = parseVariableDeclarationList(flags, false); parseSemicolon(); + finishNode(node); if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); } - return finishNode(node); + return node; } function parseFunctionDeclaration(pos, flags) { var node = createNode(167 /* FunctionDeclaration */, pos); @@ -8476,6 +8482,7 @@ var ts; var typeCount = 0; var emptyArray = []; var emptySymbols = {}; + var compilerOptions = program.getCompilerOptions(); var checker = { getProgram: function () { return program; }, getDiagnostics: getDiagnostics, @@ -9186,7 +9193,7 @@ var ts; } return symbol.name; } - if (enclosingDeclaration && !(symbol.flags & (ts.SymbolFlags.PropertyOrAccessor | ts.SymbolFlags.Signature | 4096 /* Constructor */ | 2048 /* Method */ | 262144 /* TypeParameter */))) { + if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { var symbolName; while (symbol) { var isFirstName = !symbolName; @@ -9215,17 +9222,25 @@ var ts; function writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, writer) { writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); } - function createSingleLineTextWriter() { + function createSingleLineTextWriter(maxLength) { var result = ""; - return { - write: function (s) { + var overflow = false; + function write(s) { + if (!overflow) { result += s; - }, + if (result.length > maxLength) { + result = result.substr(0, maxLength - 3) + "..."; + overflow = true; + } + } + } + return { + write: write, writeSymbol: function (symbol, enclosingDeclaration, meaning) { writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); }, writeLine: function () { - result += " "; + write(" "); }, increaseIndent: function () { }, @@ -9237,7 +9252,8 @@ var ts; }; } function typeToString(type, enclosingDeclaration, flags) { - var stringWriter = createSingleLineTextWriter(); + var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; + var stringWriter = createSingleLineTextWriter(maxLength); writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); return stringWriter.getText(); } @@ -9567,7 +9583,7 @@ var ts; checkImplicitAny(type); return type; function checkImplicitAny(type) { - if (!fullTypeCheck || !program.getCompilerOptions().noImplicitAny) { + if (!fullTypeCheck || !compilerOptions.noImplicitAny) { return; } if (getInnermostTypeOfNestedArrayTypes(type) !== anyType) { @@ -9651,7 +9667,7 @@ var ts; type = getReturnTypeFromBody(getter); } else { - if (program.getCompilerOptions().noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(setter, ts.Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbol.name); } type = anyType; @@ -11813,7 +11829,7 @@ var ts; if (stringIndexType) { return stringIndexType; } - if (program.getCompilerOptions().noImplicitAny && objectType !== anyType) { + if (compilerOptions.noImplicitAny && objectType !== anyType) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -11884,17 +11900,6 @@ var ts; }); return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferentiallyTypeExpession(expr, contextualType, contextualMapper) { - var type = checkExpressionWithContextualType(expr, contextualType, contextualMapper); - var signature = getSingleCallSignature(type); - if (signature && signature.typeParameters) { - var contextualSignature = getSingleCallSignature(contextualType); - if (contextualSignature && !contextualSignature.typeParameters) { - type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); - } - } - return type; - } function inferTypeArguments(signature, args, excludeArgument) { var typeParameters = signature.typeParameters; var context = createInferenceContext(typeParameters); @@ -11902,14 +11907,14 @@ var ts; for (var i = 0; i < args.length; i++) { if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); - inferTypes(context, inferentiallyTypeExpession(args[i], parameterType, mapper), parameterType); + inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } if (excludeArgument) { for (var i = 0; i < args.length; i++) { if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); - inferTypes(context, inferentiallyTypeExpession(args[i], parameterType, mapper), parameterType); + inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } @@ -12067,7 +12072,7 @@ var ts; if (node.kind === 133 /* NewExpression */) { var declaration = signature.declaration; if (declaration && (declaration.kind !== 117 /* Constructor */ && declaration.kind !== 121 /* ConstructSignature */)) { - if (program.getCompilerOptions().noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } return anyType; @@ -12106,7 +12111,7 @@ var ts; if (func.body.kind !== 168 /* FunctionBlock */) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } return widenedType; @@ -12119,7 +12124,7 @@ var ts; return unknownType; } var widenedType = getWidenedType(commonType); - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { error(func, ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type, ts.identifierToString(func.name), typeName); @@ -12455,6 +12460,22 @@ var ts; return result; } function checkExpression(node, contextualMapper) { + var type = checkExpressionNode(node, contextualMapper); + if (contextualMapper && contextualMapper !== identityMapper) { + var signature = getSingleCallSignature(type); + if (signature && signature.typeParameters) { + var contextualType = getContextualType(node); + if (contextualType) { + var contextualSignature = getSingleCallSignature(contextualType); + if (contextualSignature && !contextualSignature.typeParameters) { + type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); + } + } + } + } + return type; + } + function checkExpressionNode(node, contextualMapper) { switch (node.kind) { case 55 /* Identifier */: return checkIdentifier(node); @@ -12565,7 +12586,7 @@ var ts; checkCollisionWithCapturedThisVariable(node, node.name); checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); - if (program.getCompilerOptions().noImplicitAny && !node.type) { + if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { case 121 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); @@ -12976,7 +12997,7 @@ var ts; if (node.type && !isAccessor(node.kind)) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && !node.body && !node.type) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !node.body && !node.type) { if (!isPrivateWithinAmbient(node)) { var typeName = typeToString(anyType); if (node.name) { @@ -14273,7 +14294,7 @@ var ts; return target !== unknownSymbol && ((target.flags & ts.SymbolFlags.Value) !== 0); } function shouldEmitDeclarations() { - return program.getCompilerOptions().declaration && !program.getDiagnostics().length && !getDiagnostics().length; + return compilerOptions.declaration && !program.getDiagnostics().length && !getDiagnostics().length; } function isReferencedImportDeclaration(node) { var symbol = getSymbolOfNode(node); diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 0e520a2b447..1efb6d232e3 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -1532,6 +1532,7 @@ var ts; TypeFormatFlags[TypeFormatFlags["None"] = 0x00000000] = "None"; TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 0x00000001] = "WriteArrayAsGenericType"; TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 0x00000002] = "UseTypeOfFunction"; + TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 0x00000004] = "NoTruncation"; })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); var TypeFormatFlags = ts.TypeFormatFlags; (function (SymbolAccessibility) { @@ -1959,6 +1960,8 @@ var ts; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); @@ -2002,6 +2005,8 @@ var ts; } ts.chainDiagnosticMessages = chainDiagnosticMessages; function flattenDiagnosticChain(file, start, length, diagnosticChain, newLine) { + Debug.assert(start >= 0, "start must be non-negative, is " + start); + Debug.assert(length >= 0, "length must be non-negative, is " + length); var code = diagnosticChain.code; var category = diagnosticChain.category; var messageText = ""; @@ -2349,7 +2354,7 @@ var ts; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { node = getErrorSpanForNode(node); var file = getSourceFileOfNode(node); - var start = ts.skipTrivia(file.text, node.pos); + var start = node.kind === 111 /* Missing */ ? node.pos : ts.skipTrivia(file.text, node.pos); var length = node.end - start; return ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); } @@ -4540,10 +4545,11 @@ var ts; parseExpected(88 /* VarKeyword */); node.declarations = parseVariableDeclarationList(flags, false); parseSemicolon(); + finishNode(node); if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); } - return finishNode(node); + return node; } function parseFunctionDeclaration(pos, flags) { var node = createNode(167 /* FunctionDeclaration */, pos); @@ -8281,6 +8287,7 @@ var ts; var typeCount = 0; var emptyArray = []; var emptySymbols = {}; + var compilerOptions = program.getCompilerOptions(); var checker = { getProgram: function () { return program; }, getDiagnostics: getDiagnostics, @@ -8991,7 +8998,7 @@ var ts; } return symbol.name; } - if (enclosingDeclaration && !(symbol.flags & (ts.SymbolFlags.PropertyOrAccessor | ts.SymbolFlags.Signature | 4096 /* Constructor */ | 2048 /* Method */ | 262144 /* TypeParameter */))) { + if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { var symbolName; while (symbol) { var isFirstName = !symbolName; @@ -9020,17 +9027,25 @@ var ts; function writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, writer) { writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); } - function createSingleLineTextWriter() { + function createSingleLineTextWriter(maxLength) { var result = ""; - return { - write: function (s) { + var overflow = false; + function write(s) { + if (!overflow) { result += s; - }, + if (result.length > maxLength) { + result = result.substr(0, maxLength - 3) + "..."; + overflow = true; + } + } + } + return { + write: write, writeSymbol: function (symbol, enclosingDeclaration, meaning) { writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); }, writeLine: function () { - result += " "; + write(" "); }, increaseIndent: function () { }, @@ -9042,7 +9057,8 @@ var ts; }; } function typeToString(type, enclosingDeclaration, flags) { - var stringWriter = createSingleLineTextWriter(); + var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; + var stringWriter = createSingleLineTextWriter(maxLength); writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); return stringWriter.getText(); } @@ -9372,7 +9388,7 @@ var ts; checkImplicitAny(type); return type; function checkImplicitAny(type) { - if (!fullTypeCheck || !program.getCompilerOptions().noImplicitAny) { + if (!fullTypeCheck || !compilerOptions.noImplicitAny) { return; } if (getInnermostTypeOfNestedArrayTypes(type) !== anyType) { @@ -9456,7 +9472,7 @@ var ts; type = getReturnTypeFromBody(getter); } else { - if (program.getCompilerOptions().noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(setter, ts.Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbol.name); } type = anyType; @@ -11618,7 +11634,7 @@ var ts; if (stringIndexType) { return stringIndexType; } - if (program.getCompilerOptions().noImplicitAny && objectType !== anyType) { + if (compilerOptions.noImplicitAny && objectType !== anyType) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -11689,17 +11705,6 @@ var ts; }); return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferentiallyTypeExpession(expr, contextualType, contextualMapper) { - var type = checkExpressionWithContextualType(expr, contextualType, contextualMapper); - var signature = getSingleCallSignature(type); - if (signature && signature.typeParameters) { - var contextualSignature = getSingleCallSignature(contextualType); - if (contextualSignature && !contextualSignature.typeParameters) { - type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); - } - } - return type; - } function inferTypeArguments(signature, args, excludeArgument) { var typeParameters = signature.typeParameters; var context = createInferenceContext(typeParameters); @@ -11707,14 +11712,14 @@ var ts; for (var i = 0; i < args.length; i++) { if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); - inferTypes(context, inferentiallyTypeExpession(args[i], parameterType, mapper), parameterType); + inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } if (excludeArgument) { for (var i = 0; i < args.length; i++) { if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); - inferTypes(context, inferentiallyTypeExpession(args[i], parameterType, mapper), parameterType); + inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } @@ -11872,7 +11877,7 @@ var ts; if (node.kind === 133 /* NewExpression */) { var declaration = signature.declaration; if (declaration && (declaration.kind !== 117 /* Constructor */ && declaration.kind !== 121 /* ConstructSignature */)) { - if (program.getCompilerOptions().noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } return anyType; @@ -11911,7 +11916,7 @@ var ts; if (func.body.kind !== 168 /* FunctionBlock */) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } return widenedType; @@ -11924,7 +11929,7 @@ var ts; return unknownType; } var widenedType = getWidenedType(commonType); - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { error(func, ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type, ts.identifierToString(func.name), typeName); @@ -12260,6 +12265,22 @@ var ts; return result; } function checkExpression(node, contextualMapper) { + var type = checkExpressionNode(node, contextualMapper); + if (contextualMapper && contextualMapper !== identityMapper) { + var signature = getSingleCallSignature(type); + if (signature && signature.typeParameters) { + var contextualType = getContextualType(node); + if (contextualType) { + var contextualSignature = getSingleCallSignature(contextualType); + if (contextualSignature && !contextualSignature.typeParameters) { + type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); + } + } + } + } + return type; + } + function checkExpressionNode(node, contextualMapper) { switch (node.kind) { case 55 /* Identifier */: return checkIdentifier(node); @@ -12370,7 +12391,7 @@ var ts; checkCollisionWithCapturedThisVariable(node, node.name); checkCollistionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); - if (program.getCompilerOptions().noImplicitAny && !node.type) { + if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { case 121 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); @@ -12781,7 +12802,7 @@ var ts; if (node.type && !isAccessor(node.kind)) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && !node.body && !node.type) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !node.body && !node.type) { if (!isPrivateWithinAmbient(node)) { var typeName = typeToString(anyType); if (node.name) { @@ -14078,7 +14099,7 @@ var ts; return target !== unknownSymbol && ((target.flags & ts.SymbolFlags.Value) !== 0); } function shouldEmitDeclarations() { - return program.getCompilerOptions().declaration && !program.getDiagnostics().length && !getDiagnostics().length; + return compilerOptions.declaration && !program.getDiagnostics().length && !getDiagnostics().length; } function isReferencedImportDeclaration(node) { var symbol = getSymbolOfNode(node); From 2ba3ae92255a8ce9b66c53c6fafc3233cb5d7fce Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 11 Sep 2014 10:39:57 -0700 Subject: [PATCH 17/17] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd1c6276a2b..6b1d991cca6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.0.1", + "version": "1.1.0", "licenses": [ { "type": "Apache License 2.0",