From 5422e56d4805af8518480cce7fc6c5714258f6c7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 4 Sep 2014 14:23:57 -0700 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 6fb3c34681654b850568f62c6593c67f52f9017a Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 5 Sep 2014 18:42:05 -0700 Subject: [PATCH 4/8] Conformance coverage for spec change #589 --- ...tExternalModuleInsideNonAmbient.errors.txt | 6 + .../ambientExternalModuleInsideNonAmbient.js | 6 + ...eInsideNonAmbientExternalModule.errors.txt | 4 + ...nalModuleInsideNonAmbientExternalModule.js | 6 + .../reference/ambientExternalModuleMerging.js | 25 +++ .../ambientExternalModuleMerging.types | 28 +++ .../reference/ambientInsideNonAmbient.js | 24 +++ .../reference/ambientInsideNonAmbient.types | 38 ++++ .../ambientInsideNonAmbientExternalModule.js | 10 + ...mbientInsideNonAmbientExternalModule.types | 16 ++ ...eAssignmentCompatIndexSignature.errors.txt | 2 +- ...entedTypeBracketAccessIndexSignature.types | 2 +- .../classDoesNotDependOnPrivateMember.js | 26 +++ .../classDoesNotDependOnPrivateMember.types | 15 ++ ...FunctionExpressionsAndReturnAnnotations.js | 28 +++ ...ctionExpressionsAndReturnAnnotations.types | 45 ++++ ...rivedInterfaceDoesNotHideBaseSignatures.js | 13 ++ ...edInterfaceDoesNotHideBaseSignatures.types | 18 ++ .../reference/enumConstantMembers.errors.txt | 24 +++ .../reference/forgottenNew.errors.txt | 2 +- .../indexSignatureTypeInference.errors.txt | 2 +- .../reference/recursiveTypesWithTypeof.js | 99 +++++++++ .../reference/recursiveTypesWithTypeof.types | 196 ++++++++++++++++++ .../specializedSignatureWithOptional.js | 5 + .../specializedSignatureWithOptional.types | 9 + .../ambientExternalModuleInsideNonAmbient.ts | 3 + ...nalModuleInsideNonAmbientExternalModule.ts | 2 + .../ambient/ambientExternalModuleMerging.ts | 16 ++ .../ambient/ambientInsideNonAmbient.ts | 15 ++ .../ambientInsideNonAmbientExternalModule.ts | 6 + .../classDoesNotDependOnPrivateMember.ts | 7 + .../conformance/enums/enumConstantMembers.ts | 19 ++ .../functionCalls}/forgottenNew.ts | 0 ...FunctionExpressionsAndReturnAnnotations.ts | 14 ++ ...rivedInterfaceDoesNotHideBaseSignatures.ts | 10 + ...entedTypeAssignmentCompatIndexSignature.ts | 0 ...ugmentedTypeBracketAccessIndexSignature.ts | 0 .../specializedSignatureWithOptional.ts | 2 + .../typeQueries/recursiveTypesWithTypeof.ts | 53 +++++ .../indexSignatureTypeInference.ts | 0 40 files changed, 792 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt create mode 100644 tests/baselines/reference/ambientExternalModuleInsideNonAmbient.js create mode 100644 tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt create mode 100644 tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.js create mode 100644 tests/baselines/reference/ambientExternalModuleMerging.js create mode 100644 tests/baselines/reference/ambientExternalModuleMerging.types create mode 100644 tests/baselines/reference/ambientInsideNonAmbient.js create mode 100644 tests/baselines/reference/ambientInsideNonAmbient.types create mode 100644 tests/baselines/reference/ambientInsideNonAmbientExternalModule.js create mode 100644 tests/baselines/reference/ambientInsideNonAmbientExternalModule.types create mode 100644 tests/baselines/reference/classDoesNotDependOnPrivateMember.js create mode 100644 tests/baselines/reference/classDoesNotDependOnPrivateMember.types create mode 100644 tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.js create mode 100644 tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.types create mode 100644 tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.js create mode 100644 tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.types create mode 100644 tests/baselines/reference/enumConstantMembers.errors.txt create mode 100644 tests/baselines/reference/recursiveTypesWithTypeof.js create mode 100644 tests/baselines/reference/recursiveTypesWithTypeof.types create mode 100644 tests/baselines/reference/specializedSignatureWithOptional.js create mode 100644 tests/baselines/reference/specializedSignatureWithOptional.types create mode 100644 tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts create mode 100644 tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts create mode 100644 tests/cases/conformance/ambient/ambientExternalModuleMerging.ts create mode 100644 tests/cases/conformance/ambient/ambientInsideNonAmbient.ts create mode 100644 tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts create mode 100644 tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts create mode 100644 tests/cases/conformance/enums/enumConstantMembers.ts rename tests/cases/{compiler => conformance/expressions/functionCalls}/forgottenNew.ts (100%) create mode 100644 tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts rename tests/cases/{compiler => conformance/types/members}/augmentedTypeAssignmentCompatIndexSignature.ts (100%) rename tests/cases/{compiler => conformance/types/members}/augmentedTypeBracketAccessIndexSignature.ts (100%) create mode 100644 tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts create mode 100644 tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts rename tests/cases/{compiler => conformance/types/typeRelationships/typeInference}/indexSignatureTypeInference.ts (100%) diff --git a/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt b/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt new file mode 100644 index 00000000000..ca8ceb6d3ec --- /dev/null +++ b/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt @@ -0,0 +1,6 @@ +==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts (1 errors) ==== + module M { + export declare module "M" { } + ~~~ +!!! Ambient external modules cannot be nested in other modules. + } \ No newline at end of file diff --git a/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.js b/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.js new file mode 100644 index 00000000000..0d06147e802 --- /dev/null +++ b/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.js @@ -0,0 +1,6 @@ +//// [ambientExternalModuleInsideNonAmbient.ts] +module M { + export declare module "M" { } +} + +//// [ambientExternalModuleInsideNonAmbient.js] diff --git a/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt b/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt new file mode 100644 index 00000000000..44731cf6250 --- /dev/null +++ b/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt @@ -0,0 +1,4 @@ +==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts (1 errors) ==== + export declare module "M" { } + ~~~ +!!! Ambient external modules cannot be nested in other modules. \ No newline at end of file diff --git a/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.js b/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.js new file mode 100644 index 00000000000..8a3e15e7c7f --- /dev/null +++ b/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.js @@ -0,0 +1,6 @@ +//// [ambientExternalModuleInsideNonAmbientExternalModule.ts] +export declare module "M" { } + +//// [ambientExternalModuleInsideNonAmbientExternalModule.js] +define(["require", "exports"], function (require, exports) { +}); diff --git a/tests/baselines/reference/ambientExternalModuleMerging.js b/tests/baselines/reference/ambientExternalModuleMerging.js new file mode 100644 index 00000000000..1549b725d67 --- /dev/null +++ b/tests/baselines/reference/ambientExternalModuleMerging.js @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/ambient/ambientExternalModuleMerging.ts] //// + +//// [ambientExternalModuleMerging_use.ts] +import M = require("M"); +// Should be strings +var x = M.x; +var y = M.y; + +//// [ambientExternalModuleMerging_declare.ts] +declare module "M" { + export var x: string; +} + +// Merge +declare module "M" { + export var y: string; +} + +//// [ambientExternalModuleMerging_use.js] +define(["require", "exports", "M"], function (require, exports, M) { + // Should be strings + var x = M.x; + var y = M.y; +}); +//// [ambientExternalModuleMerging_declare.js] diff --git a/tests/baselines/reference/ambientExternalModuleMerging.types b/tests/baselines/reference/ambientExternalModuleMerging.types new file mode 100644 index 00000000000..1c1be0fd256 --- /dev/null +++ b/tests/baselines/reference/ambientExternalModuleMerging.types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/ambient/ambientExternalModuleMerging_use.ts === +import M = require("M"); +>M : typeof M + +// Should be strings +var x = M.x; +>x : string +>M.x : string +>M : typeof M +>x : string + +var y = M.y; +>y : string +>M.y : string +>M : typeof M +>y : string + +=== tests/cases/conformance/ambient/ambientExternalModuleMerging_declare.ts === +declare module "M" { + export var x: string; +>x : string +} + +// Merge +declare module "M" { + export var y: string; +>y : string +} diff --git a/tests/baselines/reference/ambientInsideNonAmbient.js b/tests/baselines/reference/ambientInsideNonAmbient.js new file mode 100644 index 00000000000..9a3c5558e07 --- /dev/null +++ b/tests/baselines/reference/ambientInsideNonAmbient.js @@ -0,0 +1,24 @@ +//// [ambientInsideNonAmbient.ts] +module M { + export declare var x; + export declare function f(); + export declare class C { } + export declare enum E { } + export declare module M { } +} + +module M2 { + declare var x; + declare function f(); + declare class C { } + declare enum E { } + declare module M { } +} + +//// [ambientInsideNonAmbient.js] +var M; +(function (M) { +})(M || (M = {})); +var M2; +(function (M2) { +})(M2 || (M2 = {})); diff --git a/tests/baselines/reference/ambientInsideNonAmbient.types b/tests/baselines/reference/ambientInsideNonAmbient.types new file mode 100644 index 00000000000..ee654aee333 --- /dev/null +++ b/tests/baselines/reference/ambientInsideNonAmbient.types @@ -0,0 +1,38 @@ +=== tests/cases/conformance/ambient/ambientInsideNonAmbient.ts === +module M { +>M : typeof M + + export declare var x; +>x : any + + export declare function f(); +>f : () => any + + export declare class C { } +>C : C + + export declare enum E { } +>E : E + + export declare module M { } +>M : unknown +} + +module M2 { +>M2 : typeof M2 + + declare var x; +>x : any + + declare function f(); +>f : () => any + + declare class C { } +>C : C + + declare enum E { } +>E : E + + declare module M { } +>M : unknown +} diff --git a/tests/baselines/reference/ambientInsideNonAmbientExternalModule.js b/tests/baselines/reference/ambientInsideNonAmbientExternalModule.js new file mode 100644 index 00000000000..5db44bb1ce1 --- /dev/null +++ b/tests/baselines/reference/ambientInsideNonAmbientExternalModule.js @@ -0,0 +1,10 @@ +//// [ambientInsideNonAmbientExternalModule.ts] +export declare var x; +export declare function f(); +export declare class C { } +export declare enum E { } +export declare module M { } + +//// [ambientInsideNonAmbientExternalModule.js] +define(["require", "exports"], function (require, exports) { +}); diff --git a/tests/baselines/reference/ambientInsideNonAmbientExternalModule.types b/tests/baselines/reference/ambientInsideNonAmbientExternalModule.types new file mode 100644 index 00000000000..bda7a61a7f3 --- /dev/null +++ b/tests/baselines/reference/ambientInsideNonAmbientExternalModule.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts === +export declare var x; +>x : any + +export declare function f(); +>f : () => any + +export declare class C { } +>C : C + +export declare enum E { } +>E : E + +export declare module M { } +>M : unknown + diff --git a/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt b/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt index 19824374ebd..4222ab54b15 100644 --- a/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt +++ b/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/compiler/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ==== +==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ==== interface Foo { a } interface Bar { b } diff --git a/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types b/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types index d02a36409a7..4e6b51730da 100644 --- a/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types +++ b/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/augmentedTypeBracketAccessIndexSignature.ts === +=== tests/cases/conformance/types/members/augmentedTypeBracketAccessIndexSignature.ts === interface Foo { a } >Foo : Foo >a : any diff --git a/tests/baselines/reference/classDoesNotDependOnPrivateMember.js b/tests/baselines/reference/classDoesNotDependOnPrivateMember.js new file mode 100644 index 00000000000..548c94b0ea7 --- /dev/null +++ b/tests/baselines/reference/classDoesNotDependOnPrivateMember.js @@ -0,0 +1,26 @@ +//// [classDoesNotDependOnPrivateMember.ts] +module M { + interface I { } + export class C { + private x: I; + } +} + +//// [classDoesNotDependOnPrivateMember.js] +var M; +(function (M) { + var C = (function () { + function C() { + } + return C; + })(); + M.C = C; +})(M || (M = {})); + + +//// [classDoesNotDependOnPrivateMember.d.ts] +declare module M { + class C { + private x; + } +} diff --git a/tests/baselines/reference/classDoesNotDependOnPrivateMember.types b/tests/baselines/reference/classDoesNotDependOnPrivateMember.types new file mode 100644 index 00000000000..213c46ca1d5 --- /dev/null +++ b/tests/baselines/reference/classDoesNotDependOnPrivateMember.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts === +module M { +>M : typeof M + + interface I { } +>I : I + + export class C { +>C : C + + private x: I; +>x : I +>I : I + } +} diff --git a/tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.js b/tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.js new file mode 100644 index 00000000000..05bf5937039 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.js @@ -0,0 +1,28 @@ +//// [contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts] +declare function foo(x: (y: string) => (y2: number) => void); + +// Contextually type the parameter even if there is a return annotation +foo((y): (y2: number) => void => { + var z = y.charAt(0); // Should be string + return null; +}); + +foo((y: string) => { + return y2 => { + var z = y2.toFixed(); // Should be string + return 0; + }; +}); + +//// [contextuallyTypedFunctionExpressionsAndReturnAnnotations.js] +// Contextually type the parameter even if there is a return annotation +foo(function (y) { + var z = y.charAt(0); // Should be string + return null; +}); +foo(function (y) { + return function (y2) { + var z = y2.toFixed(); // Should be string + return 0; + }; +}); diff --git a/tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.types b/tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.types new file mode 100644 index 00000000000..09c317c64a0 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedFunctionExpressionsAndReturnAnnotations.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts === +declare function foo(x: (y: string) => (y2: number) => void); +>foo : (x: (y: string) => (y2: number) => void) => any +>x : (y: string) => (y2: number) => void +>y : string +>y2 : number + +// Contextually type the parameter even if there is a return annotation +foo((y): (y2: number) => void => { +>foo((y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;}) : any +>foo : (x: (y: string) => (y2: number) => void) => any +>(y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;} : (y: string) => (y2: number) => void +>y : string +>y2 : number + + var z = y.charAt(0); // Should be string +>z : string +>y.charAt(0) : string +>y.charAt : (pos: number) => string +>y : string +>charAt : (pos: number) => string + + return null; +}); + +foo((y: string) => { +>foo((y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };}) : any +>foo : (x: (y: string) => (y2: number) => void) => any +>(y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };} : (y: string) => (y2: number) => number +>y : string + + return y2 => { +>y2 => { var z = y2.toFixed(); // Should be string return 0; } : (y2: number) => number +>y2 : number + + var z = y2.toFixed(); // Should be string +>z : string +>y2.toFixed() : string +>y2.toFixed : (fractionDigits?: number) => string +>y2 : number +>toFixed : (fractionDigits?: number) => string + + return 0; + }; +}); diff --git a/tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.js b/tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.js new file mode 100644 index 00000000000..2cce6e72209 --- /dev/null +++ b/tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.js @@ -0,0 +1,13 @@ +//// [derivedInterfaceDoesNotHideBaseSignatures.ts] +// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible. +interface Base { + (): string; + new (x: string): number; +} + +interface Derived extends Base { + (): number; + new (x: string): string; +} + +//// [derivedInterfaceDoesNotHideBaseSignatures.js] diff --git a/tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.types b/tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.types new file mode 100644 index 00000000000..7ee090b7de3 --- /dev/null +++ b/tests/baselines/reference/derivedInterfaceDoesNotHideBaseSignatures.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts === +// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible. +interface Base { +>Base : Base + + (): string; + new (x: string): number; +>x : string +} + +interface Derived extends Base { +>Derived : Derived +>Base : Base + + (): number; + new (x: string): string; +>x : string +} diff --git a/tests/baselines/reference/enumConstantMembers.errors.txt b/tests/baselines/reference/enumConstantMembers.errors.txt new file mode 100644 index 00000000000..ac77e2b7b4e --- /dev/null +++ b/tests/baselines/reference/enumConstantMembers.errors.txt @@ -0,0 +1,24 @@ +==== tests/cases/conformance/enums/enumConstantMembers.ts (2 errors) ==== + // Constant members allow negatives, but not decimals. Also hex literals are allowed + enum E1 { + a = 1, + b + } + enum E2 { + a = - 1, + b + } + enum E3 { + a = 0.1, + b // Error because 0.1 is not a constant + ~ +!!! Enum member must have initializer. + } + + declare enum E4 { + a = 1, + b = -1, + c = 0.1 // Not a constant + ~ +!!! Ambient enum elements can only have integer literal initializers. + } \ No newline at end of file diff --git a/tests/baselines/reference/forgottenNew.errors.txt b/tests/baselines/reference/forgottenNew.errors.txt index 3a6d490a0e9..ba44223819c 100644 --- a/tests/baselines/reference/forgottenNew.errors.txt +++ b/tests/baselines/reference/forgottenNew.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/compiler/forgottenNew.ts (1 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/forgottenNew.ts (1 errors) ==== module Tools { export class NullLogger { } } diff --git a/tests/baselines/reference/indexSignatureTypeInference.errors.txt b/tests/baselines/reference/indexSignatureTypeInference.errors.txt index a37e4458543..ee42069a4ec 100644 --- a/tests/baselines/reference/indexSignatureTypeInference.errors.txt +++ b/tests/baselines/reference/indexSignatureTypeInference.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/compiler/indexSignatureTypeInference.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts (1 errors) ==== interface NumberMap { [index: number]: T; } diff --git a/tests/baselines/reference/recursiveTypesWithTypeof.js b/tests/baselines/reference/recursiveTypesWithTypeof.js new file mode 100644 index 00000000000..36c13405b0b --- /dev/null +++ b/tests/baselines/reference/recursiveTypesWithTypeof.js @@ -0,0 +1,99 @@ +//// [recursiveTypesWithTypeof.ts] +// None of these declarations should have any errors! +// Using typeof directly, these should be any +var c: typeof c; +var c: any; +var d: typeof e; +var d: any; +var e: typeof d; +var e: any; + +// In type arguments, these should be any +interface Foo { } +var f: Array; +var f: any; +var f2: Foo; +var f2: any; +var f3: Foo[]; +var f3: any; + +// Truly recursive types +var g: { x: typeof g; }; +var g: typeof g.x; +var h: () => typeof h; +var h = h(); +var i: (x: typeof i) => typeof x; +var i = i(i); +var j: (x: T) => T; +var j = j(j); + +// Same as h, i, j with construct signatures +var h2: new () => typeof h2; +var h2 = new h2(); +var i2: new (x: typeof i2) => typeof x; +var i2 = new i2(i2); +var j2: new (x: T) => T; +var j2 = new j2(j2); + +// Indexers +var k: { [n: number]: typeof k;[s: string]: typeof k }; +var k = k[0]; +var k = k['']; + +// Hybrid - contains type literals as well as type arguments +// These two are recursive +var hy1: { x: typeof hy1 }[]; +var hy1 = hy1[0].x; +var hy2: { x: Array }; +var hy2 = hy2.x[0]; + +interface Foo2 { } + +// This one should be any because the first type argument is not contained inside a type literal +var hy3: Foo2; +var hy3: any; + +//// [recursiveTypesWithTypeof.js] +// None of these declarations should have any errors! +// Using typeof directly, these should be any +var c; +var c; +var d; +var d; +var e; +var e; +var f; +var f; +var f2; +var f2; +var f3; +var f3; +// Truly recursive types +var g; +var g; +var h; +var h = h(); +var i; +var i = i(i); +var j; +var j = j(j); +// Same as h, i, j with construct signatures +var h2; +var h2 = new h2(); +var i2; +var i2 = new i2(i2); +var j2; +var j2 = new j2(j2); +// Indexers +var k; +var k = k[0]; +var k = k['']; +// Hybrid - contains type literals as well as type arguments +// These two are recursive +var hy1; +var hy1 = hy1[0].x; +var hy2; +var hy2 = hy2.x[0]; +// This one should be any because the first type argument is not contained inside a type literal +var hy3; +var hy3; diff --git a/tests/baselines/reference/recursiveTypesWithTypeof.types b/tests/baselines/reference/recursiveTypesWithTypeof.types new file mode 100644 index 00000000000..f75bae79c5b --- /dev/null +++ b/tests/baselines/reference/recursiveTypesWithTypeof.types @@ -0,0 +1,196 @@ +=== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts === +// None of these declarations should have any errors! +// Using typeof directly, these should be any +var c: typeof c; +>c : any +>c : any + +var c: any; +>c : any + +var d: typeof e; +>d : any +>e : any + +var d: any; +>d : any + +var e: typeof d; +>e : any +>d : any + +var e: any; +>e : any + +// In type arguments, these should be any +interface Foo { } +>Foo : Foo +>T : T + +var f: Array; +>f : any +>Array : T[] +>f : any + +var f: any; +>f : any + +var f2: Foo; +>f2 : any +>Foo : Foo +>f2 : any + +var f2: any; +>f2 : any + +var f3: Foo[]; +>f3 : any +>Foo : Foo +>f3 : any + +var f3: any; +>f3 : any + +// Truly recursive types +var g: { x: typeof g; }; +>g : { x: any; } +>x : { x: any; } +>g : { x: any; } + +var g: typeof g.x; +>g : { x: any; } +>g : { x: any; } +>x : { x: any; } + +var h: () => typeof h; +>h : () => any +>h : () => any + +var h = h(); +>h : () => any +>h() : () => any +>h : () => any + +var i: (x: typeof i) => typeof x; +>i : (x: any) => any +>x : (x: any) => any +>i : (x: any) => any +>x : (x: any) => any + +var i = i(i); +>i : (x: any) => any +>i(i) : (x: any) => any +>i : (x: any) => any +>i : (x: any) => any + +var j: (x: T) => T; +>j : (x: T) => T +>T : T +>j : (x: T) => T +>x : T +>T : T +>T : T + +var j = j(j); +>j : (x: T) => T +>j(j) : (x: T) => T +>j : (x: T) => T +>j : (x: T) => T + +// Same as h, i, j with construct signatures +var h2: new () => typeof h2; +>h2 : new () => any +>h2 : new () => any + +var h2 = new h2(); +>h2 : new () => any +>new h2() : new () => any +>h2 : new () => any + +var i2: new (x: typeof i2) => typeof x; +>i2 : new (x: any) => any +>x : new (x: any) => any +>i2 : new (x: any) => any +>x : new (x: any) => any + +var i2 = new i2(i2); +>i2 : new (x: any) => any +>new i2(i2) : new (x: any) => any +>i2 : new (x: any) => any +>i2 : new (x: any) => any + +var j2: new (x: T) => T; +>j2 : new (x: T) => T +>T : T +>j2 : new (x: T) => T +>x : T +>T : T +>T : T + +var j2 = new j2(j2); +>j2 : new (x: T) => T +>new j2(j2) : new (x: T) => T +>j2 : new (x: T) => T +>j2 : new (x: T) => T + +// Indexers +var k: { [n: number]: typeof k;[s: string]: typeof k }; +>k : { [x: string]: any; [x: number]: any; } +>n : number +>k : { [x: string]: any; [x: number]: any; } +>s : string +>k : { [x: string]: any; [x: number]: any; } + +var k = k[0]; +>k : { [x: string]: any; [x: number]: any; } +>k[0] : { [x: string]: any; [x: number]: any; } +>k : { [x: string]: any; [x: number]: any; } + +var k = k['']; +>k : { [x: string]: any; [x: number]: any; } +>k[''] : { [x: string]: any; [x: number]: any; } +>k : { [x: string]: any; [x: number]: any; } + +// Hybrid - contains type literals as well as type arguments +// These two are recursive +var hy1: { x: typeof hy1 }[]; +>hy1 : { x: any[]; }[] +>x : { x: any[]; }[] +>hy1 : { x: any[]; }[] + +var hy1 = hy1[0].x; +>hy1 : { x: any[]; }[] +>hy1[0].x : { x: any[]; }[] +>hy1[0] : { x: any[]; } +>hy1 : { x: any[]; }[] +>x : { x: any[]; }[] + +var hy2: { x: Array }; +>hy2 : { x: any[]; } +>x : { x: any[]; }[] +>Array : T[] +>hy2 : { x: any[]; } + +var hy2 = hy2.x[0]; +>hy2 : { x: any[]; } +>hy2.x[0] : { x: any[]; } +>hy2.x : { x: any[]; }[] +>hy2 : { x: any[]; } +>x : { x: any[]; }[] + +interface Foo2 { } +>Foo2 : Foo2 +>T : T +>U : U + +// This one should be any because the first type argument is not contained inside a type literal +var hy3: Foo2; +>hy3 : any +>Foo2 : Foo2 +>hy3 : any +>x : any +>hy3 : any + +var hy3: any; +>hy3 : any + diff --git a/tests/baselines/reference/specializedSignatureWithOptional.js b/tests/baselines/reference/specializedSignatureWithOptional.js new file mode 100644 index 00000000000..aea08090b55 --- /dev/null +++ b/tests/baselines/reference/specializedSignatureWithOptional.js @@ -0,0 +1,5 @@ +//// [specializedSignatureWithOptional.ts] +declare function f(x?: "hi"): void; +declare function f(x?: string): void; + +//// [specializedSignatureWithOptional.js] diff --git a/tests/baselines/reference/specializedSignatureWithOptional.types b/tests/baselines/reference/specializedSignatureWithOptional.types new file mode 100644 index 00000000000..73cd89edb30 --- /dev/null +++ b/tests/baselines/reference/specializedSignatureWithOptional.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts === +declare function f(x?: "hi"): void; +>f : { (x?: "hi"): void; (x?: string): void; } +>x : "hi" + +declare function f(x?: string): void; +>f : { (x?: "hi"): void; (x?: string): void; } +>x : string + diff --git a/tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts b/tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts new file mode 100644 index 00000000000..9a726443729 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts @@ -0,0 +1,3 @@ +module M { + export declare module "M" { } +} \ No newline at end of file diff --git a/tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts b/tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts new file mode 100644 index 00000000000..027dc4d3008 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts @@ -0,0 +1,2 @@ +//@module: amd +export declare module "M" { } \ No newline at end of file diff --git a/tests/cases/conformance/ambient/ambientExternalModuleMerging.ts b/tests/cases/conformance/ambient/ambientExternalModuleMerging.ts new file mode 100644 index 00000000000..432ac693821 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientExternalModuleMerging.ts @@ -0,0 +1,16 @@ +//@filename: ambientExternalModuleMerging_use.ts +//@module: amd +import M = require("M"); +// Should be strings +var x = M.x; +var y = M.y; + +//@filename: ambientExternalModuleMerging_declare.ts +declare module "M" { + export var x: string; +} + +// Merge +declare module "M" { + export var y: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/ambient/ambientInsideNonAmbient.ts b/tests/cases/conformance/ambient/ambientInsideNonAmbient.ts new file mode 100644 index 00000000000..e2f24113c94 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientInsideNonAmbient.ts @@ -0,0 +1,15 @@ +module M { + export declare var x; + export declare function f(); + export declare class C { } + export declare enum E { } + export declare module M { } +} + +module M2 { + declare var x; + declare function f(); + declare class C { } + declare enum E { } + declare module M { } +} \ No newline at end of file diff --git a/tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts b/tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts new file mode 100644 index 00000000000..dbdc315c743 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts @@ -0,0 +1,6 @@ +// @module: amd +export declare var x; +export declare function f(); +export declare class C { } +export declare enum E { } +export declare module M { } \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts b/tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts new file mode 100644 index 00000000000..4f0e9f7f4e5 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts @@ -0,0 +1,7 @@ +//@declaration: true +module M { + interface I { } + export class C { + private x: I; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/enums/enumConstantMembers.ts b/tests/cases/conformance/enums/enumConstantMembers.ts new file mode 100644 index 00000000000..e56828db064 --- /dev/null +++ b/tests/cases/conformance/enums/enumConstantMembers.ts @@ -0,0 +1,19 @@ +// Constant members allow negatives, but not decimals. Also hex literals are allowed +enum E1 { + a = 1, + b +} +enum E2 { + a = - 1, + b +} +enum E3 { + a = 0.1, + b // Error because 0.1 is not a constant +} + +declare enum E4 { + a = 1, + b = -1, + c = 0.1 // Not a constant +} \ No newline at end of file diff --git a/tests/cases/compiler/forgottenNew.ts b/tests/cases/conformance/expressions/functionCalls/forgottenNew.ts similarity index 100% rename from tests/cases/compiler/forgottenNew.ts rename to tests/cases/conformance/expressions/functionCalls/forgottenNew.ts diff --git a/tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts b/tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts new file mode 100644 index 00000000000..0a1aceaf376 --- /dev/null +++ b/tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts @@ -0,0 +1,14 @@ +declare function foo(x: (y: string) => (y2: number) => void); + +// Contextually type the parameter even if there is a return annotation +foo((y): (y2: number) => void => { + var z = y.charAt(0); // Should be string + return null; +}); + +foo((y: string) => { + return y2 => { + var z = y2.toFixed(); // Should be string + return 0; + }; +}); \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts new file mode 100644 index 00000000000..49f67862ef0 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts @@ -0,0 +1,10 @@ +// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible. +interface Base { + (): string; + new (x: string): number; +} + +interface Derived extends Base { + (): number; + new (x: string): string; +} \ No newline at end of file diff --git a/tests/cases/compiler/augmentedTypeAssignmentCompatIndexSignature.ts b/tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts similarity index 100% rename from tests/cases/compiler/augmentedTypeAssignmentCompatIndexSignature.ts rename to tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts diff --git a/tests/cases/compiler/augmentedTypeBracketAccessIndexSignature.ts b/tests/cases/conformance/types/members/augmentedTypeBracketAccessIndexSignature.ts similarity index 100% rename from tests/cases/compiler/augmentedTypeBracketAccessIndexSignature.ts rename to tests/cases/conformance/types/members/augmentedTypeBracketAccessIndexSignature.ts diff --git a/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts b/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts new file mode 100644 index 00000000000..a601f6b483b --- /dev/null +++ b/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts @@ -0,0 +1,2 @@ +declare function f(x?: "hi"): void; +declare function f(x?: string): void; \ No newline at end of file diff --git a/tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts b/tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts new file mode 100644 index 00000000000..7852f99dd9b --- /dev/null +++ b/tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts @@ -0,0 +1,53 @@ +// None of these declarations should have any errors! +// Using typeof directly, these should be any +var c: typeof c; +var c: any; +var d: typeof e; +var d: any; +var e: typeof d; +var e: any; + +// In type arguments, these should be any +interface Foo { } +var f: Array; +var f: any; +var f2: Foo; +var f2: any; +var f3: Foo[]; +var f3: any; + +// Truly recursive types +var g: { x: typeof g; }; +var g: typeof g.x; +var h: () => typeof h; +var h = h(); +var i: (x: typeof i) => typeof x; +var i = i(i); +var j: (x: T) => T; +var j = j(j); + +// Same as h, i, j with construct signatures +var h2: new () => typeof h2; +var h2 = new h2(); +var i2: new (x: typeof i2) => typeof x; +var i2 = new i2(i2); +var j2: new (x: T) => T; +var j2 = new j2(j2); + +// Indexers +var k: { [n: number]: typeof k;[s: string]: typeof k }; +var k = k[0]; +var k = k['']; + +// Hybrid - contains type literals as well as type arguments +// These two are recursive +var hy1: { x: typeof hy1 }[]; +var hy1 = hy1[0].x; +var hy2: { x: Array }; +var hy2 = hy2.x[0]; + +interface Foo2 { } + +// This one should be any because the first type argument is not contained inside a type literal +var hy3: Foo2; +var hy3: any; \ No newline at end of file diff --git a/tests/cases/compiler/indexSignatureTypeInference.ts b/tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts similarity index 100% rename from tests/cases/compiler/indexSignatureTypeInference.ts rename to tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts From 4f21fb59a2f45a392ef879f33afed21f27b68c89 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 8 Sep 2014 12:08:15 -0700 Subject: [PATCH 5/8] 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 f61d07db69487d55ddec411ad0ff98f53f4b5102 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 8 Sep 2014 22:30:01 -0700 Subject: [PATCH 6/8] 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 a62e7d218d861cba32b2aa8203fd20a55a015c43 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 9 Sep 2014 12:26:49 -0700 Subject: [PATCH 7/8] 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 8/8] 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