From b8082caa8eb5c16020f805ff70ef61454e07175c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 11 Nov 2016 15:58:52 -0800 Subject: [PATCH 01/46] Clean up jsdoc in utilities Fix functions that were unused (getJsDocComments), redundant (append) or badly named (getJSDocCommentsFromText) --- src/compiler/declarationEmitter.ts | 2 +- src/compiler/parser.ts | 2 +- src/compiler/utilities.ts | 46 +++++++++--------------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 0bba375a2cb2e..3b48f45347800 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -371,7 +371,7 @@ namespace ts { function writeJsDocComments(declaration: Node) { if (declaration) { - const jsDocComments = getJsDocCommentsFromText(declaration, currentText); + const jsDocComments = getJSDocCommentRanges(declaration, currentText); emitNewLineBeforeLeadingComments(currentLineMap, writer, declaration, jsDocComments); // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space emitComments(currentText, currentLineMap, writer, jsDocComments, /*leadingSeparator*/ false, /*trailingSeparator*/ true, newLine, writeCommentRange); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 943a677ef5d99..682c22b4fba63 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -676,7 +676,7 @@ namespace ts { function addJSDocComment(node: T): T { - const comments = getJsDocCommentsFromText(node, sourceFile.text); + const comments = getJSDocCommentRanges(node, sourceFile.text); if (comments) { for (const comment of comments) { const jsDoc = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a9f2429d37645..9aa0e4267cf89 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -638,25 +638,18 @@ namespace ts { return getLeadingCommentRanges(text, node.pos); } - export function getJsDocComments(node: Node, sourceFileOfNode: SourceFile) { - return getJsDocCommentsFromText(node, sourceFileOfNode.text); - } - - export function getJsDocCommentsFromText(node: Node, text: string) { + export function getJSDocCommentRanges(node: Node, text: string) { const commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter || node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction) ? concatenate(getTrailingCommentRanges(text, node.pos), getLeadingCommentRanges(text, node.pos)) : getLeadingCommentRangesOfNodeFromText(node, text); - return filter(commentRanges, isJsDocComment); - - function isJsDocComment(comment: CommentRange) { - // True if the comment starts with '/**' but not if it is '/**/' - return text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk && - text.charCodeAt(comment.pos + 2) === CharacterCodes.asterisk && - text.charCodeAt(comment.pos + 3) !== CharacterCodes.slash; - } + // True if the comment starts with '/**' but not if it is '/**/' + return filter(commentRanges, comment => + text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk && + text.charCodeAt(comment.pos + 2) === CharacterCodes.asterisk && + text.charCodeAt(comment.pos + 3) !== CharacterCodes.slash); } export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; @@ -1453,18 +1446,6 @@ namespace ts { } } - function append(previous: T[] | undefined, additional: T[] | undefined): T[] | undefined { - if (additional) { - if (!previous) { - previous = []; - } - for (const x of additional) { - previous.push(x); - } - } - return previous; - } - export function getJSDocComments(node: Node, checkParentVariableStatement: boolean): string[] { return getJSDocs(node, checkParentVariableStatement, docs => map(docs, doc => doc.comment), tags => map(tags, tag => tag.comment)); } @@ -1482,7 +1463,6 @@ namespace ts { } function getJSDocs(node: Node, checkParentVariableStatement: boolean, getDocs: (docs: JSDoc[]) => T[], getTags: (tags: JSDocTag[]) => T[]): T[] { - // TODO: Get rid of getJsDocComments and friends (note the lowercase 's' in Js) // TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now... let result: T[] = undefined; // prepend documentation from parent sources @@ -1505,11 +1485,11 @@ namespace ts { isVariableOfVariableDeclarationStatement ? node.parent.parent : undefined; if (variableStatementNode) { - result = append(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocs, getTags)); } if (node.kind === SyntaxKind.ModuleDeclaration && node.parent && node.parent.kind === SyntaxKind.ModuleDeclaration) { - result = append(result, getJSDocs(node.parent, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(node.parent, checkParentVariableStatement, getDocs, getTags)); } // Also recognize when the node is the RHS of an assignment expression @@ -1520,30 +1500,30 @@ namespace ts { (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - result = append(result, getJSDocs(parent.parent, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(parent.parent, checkParentVariableStatement, getDocs, getTags)); } const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; if (isPropertyAssignmentExpression) { - result = append(result, getJSDocs(parent, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(parent, checkParentVariableStatement, getDocs, getTags)); } // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { const paramTags = getJSDocParameterTag(node as ParameterDeclaration, checkParentVariableStatement); if (paramTags) { - result = append(result, getTags(paramTags)); + result = concatenate(result, getTags(paramTags)); } } } if (isVariableLike(node) && node.initializer) { - result = append(result, getJSDocs(node.initializer, /*checkParentVariableStatement*/ false, getDocs, getTags)); + result = concatenate(result, getJSDocs(node.initializer, /*checkParentVariableStatement*/ false, getDocs, getTags)); } if (node.jsDocComments) { if (result) { - result = append(result, getDocs(node.jsDocComments)); + result = concatenate(result, getDocs(node.jsDocComments)); } else { return getDocs(node.jsDocComments); From 641948fb0cec0c27a3764b34ff947dd0f6d3b3be Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 16 Nov 2016 13:38:25 -0800 Subject: [PATCH 02/46] Test assignability checking of object rests --- .../reference/objectRestNegative.errors.txt | 21 +++++++++++++++---- .../baselines/reference/objectRestNegative.js | 9 ++++++++ .../reference/objectSpreadNoTransform.js | 2 +- .../reference/objectSpreadNoTransform.symbols | 2 +- .../reference/objectSpreadNoTransform.types | 4 ++-- .../types/rest/objectRestNegative.ts | 6 ++++++ .../types/spread/objectSpreadNoTransform.ts | 2 +- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tests/baselines/reference/objectRestNegative.errors.txt b/tests/baselines/reference/objectRestNegative.errors.txt index 793a7d31fc819..345e99723bd66 100644 --- a/tests/baselines/reference/objectRestNegative.errors.txt +++ b/tests/baselines/reference/objectRestNegative.errors.txt @@ -1,14 +1,27 @@ tests/cases/conformance/types/rest/objectRestNegative.ts(2,10): error TS2462: A rest element must be last in a destructuring pattern -tests/cases/conformance/types/rest/objectRestNegative.ts(3,31): error TS2462: A rest element must be last in a destructuring pattern -tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Rest types may only be created from object types. -tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: The target of an object rest assignment must be a variable or a property access. +tests/cases/conformance/types/rest/objectRestNegative.ts(6,10): error TS2322: Type '{ a: number; }' is not assignable to type '{ a: string; }'. + Types of property 'a' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/rest/objectRestNegative.ts(9,31): error TS2462: A rest element must be last in a destructuring pattern +tests/cases/conformance/types/rest/objectRestNegative.ts(12,17): error TS2700: Rest types may only be created from object types. +tests/cases/conformance/types/rest/objectRestNegative.ts(17,9): error TS2701: The target of an object rest assignment must be a variable or a property access. -==== tests/cases/conformance/types/rest/objectRestNegative.ts (4 errors) ==== +==== tests/cases/conformance/types/rest/objectRestNegative.ts (5 errors) ==== let o = { a: 1, b: 'no' }; var { ...mustBeLast, a } = o; ~~~~~~~~~~ !!! error TS2462: A rest element must be last in a destructuring pattern + + var b: string; + let notAssignable: { a: string }; + ({ b, ...notAssignable } = o); + ~~~~~~~~~~~~~ +!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ a: string; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + + function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void { ~~~~~~~~~~ !!! error TS2462: A rest element must be last in a destructuring pattern diff --git a/tests/baselines/reference/objectRestNegative.js b/tests/baselines/reference/objectRestNegative.js index a2da998cf8af6..f8c5b72ada5d0 100644 --- a/tests/baselines/reference/objectRestNegative.js +++ b/tests/baselines/reference/objectRestNegative.js @@ -1,6 +1,12 @@ //// [objectRestNegative.ts] let o = { a: 1, b: 'no' }; var { ...mustBeLast, a } = o; + +var b: string; +let notAssignable: { a: string }; +({ b, ...notAssignable } = o); + + function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void { } function generic(t: T) { @@ -24,6 +30,9 @@ var __rest = (this && this.__rest) || function (s, e) { }; var o = { a: 1, b: 'no' }; var a = o.a; +var b; +var notAssignable; +(b = o.b, o, notAssignable = __rest(o, ["b"])); function stillMustBeLast(_a) { var a = _a.a; } diff --git a/tests/baselines/reference/objectSpreadNoTransform.js b/tests/baselines/reference/objectSpreadNoTransform.js index 3442d0864092d..5ad9c01e59903 100644 --- a/tests/baselines/reference/objectSpreadNoTransform.js +++ b/tests/baselines/reference/objectSpreadNoTransform.js @@ -2,7 +2,7 @@ const y = { a: 'yes', b: 'no' }; const o = { x: 1, ...y }; var b; -var rest; +var rest: any; ({ b, ...rest } = o); diff --git a/tests/baselines/reference/objectSpreadNoTransform.symbols b/tests/baselines/reference/objectSpreadNoTransform.symbols index 78423330dbb14..b2062697cdde3 100644 --- a/tests/baselines/reference/objectSpreadNoTransform.symbols +++ b/tests/baselines/reference/objectSpreadNoTransform.symbols @@ -12,7 +12,7 @@ const o = { x: 1, ...y }; var b; >b : Symbol(b, Decl(objectSpreadNoTransform.ts, 2, 3)) -var rest; +var rest: any; >rest : Symbol(rest, Decl(objectSpreadNoTransform.ts, 3, 3)) ({ b, ...rest } = o); diff --git a/tests/baselines/reference/objectSpreadNoTransform.types b/tests/baselines/reference/objectSpreadNoTransform.types index ae89a3a7993e3..bb09fd418c282 100644 --- a/tests/baselines/reference/objectSpreadNoTransform.types +++ b/tests/baselines/reference/objectSpreadNoTransform.types @@ -17,7 +17,7 @@ const o = { x: 1, ...y }; var b; >b : any -var rest; +var rest: any; >rest : any ({ b, ...rest } = o); @@ -25,6 +25,6 @@ var rest; >{ b, ...rest } = o : { a: string; b: string; x: number; } >{ b, ...rest } : any >b : any ->rest : undefined +>rest : any >o : { a: string; b: string; x: number; } diff --git a/tests/cases/conformance/types/rest/objectRestNegative.ts b/tests/cases/conformance/types/rest/objectRestNegative.ts index 75cbe9a55e4e9..c224c8cd30e34 100644 --- a/tests/cases/conformance/types/rest/objectRestNegative.ts +++ b/tests/cases/conformance/types/rest/objectRestNegative.ts @@ -1,5 +1,11 @@ let o = { a: 1, b: 'no' }; var { ...mustBeLast, a } = o; + +var b: string; +let notAssignable: { a: string }; +({ b, ...notAssignable } = o); + + function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void { } function generic(t: T) { diff --git a/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts b/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts index 36c75e70887bb..86bcb7eeee5c2 100644 --- a/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts +++ b/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts @@ -2,5 +2,5 @@ const y = { a: 'yes', b: 'no' }; const o = { x: 1, ...y }; var b; -var rest; +var rest: any; ({ b, ...rest } = o); From 074014e03989edf37bbf270e26846fca88da1aee Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 16 Nov 2016 13:39:00 -0800 Subject: [PATCH 03/46] Check assignability: rest destructuring assignment --- src/compiler/checker.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7132aedb32499..b2555b7d21dd5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14188,12 +14188,13 @@ namespace ts { function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type { const properties = node.properties; for (const p of properties) { - checkObjectLiteralDestructuringPropertyAssignment(sourceType, p); + checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, properties); } return sourceType; } - function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike) { + /** Note: If property cannot be a SpreadAssignment, then allProperties does not need to be provided */ + function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, allProperties?: ObjectLiteralElementLike[]) { if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) { const name = (property).name; if (name.kind === SyntaxKind.ComputedPropertyName) { @@ -14223,7 +14224,14 @@ namespace ts { } } else if (property.kind === SyntaxKind.SpreadAssignment) { - checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access); + const nonRestNames: PropertyName[] = []; + if (allProperties) { + for (let i = 0; i < allProperties.length - 1; i++) { + nonRestNames.push(allProperties[i].name); + } + } + const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol); + return checkDestructuringAssignment(property.expression, type); } else { error(property, Diagnostics.Property_assignment_expected); @@ -14321,7 +14329,10 @@ namespace ts { function checkReferenceAssignment(target: Expression, sourceType: Type, contextualMapper?: TypeMapper): Type { const targetType = checkExpression(target, contextualMapper); - if (checkReferenceExpression(target, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) { + const error = target.parent.kind === SyntaxKind.SpreadAssignment ? + Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access : + Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access; + if (checkReferenceExpression(target, error)) { checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined); } return sourceType; From 3e52f3dfe9ee5922ef4305b1c39bdbca33d0f5f8 Mon Sep 17 00:00:00 2001 From: Anton Khlynovskiy Date: Thu, 17 Nov 2016 22:06:45 +0300 Subject: [PATCH 04/46] Codegen: Do not subtract 0 in arguments to rest array loop --- src/compiler/transformers/es2015.ts | 4 +++- .../reference/accessorWithRestParam.js | 4 ++-- ...patWithCallSignaturesWithRestParameters.js | 6 +++--- .../reference/baseTypeAfterDerivedType.js | 2 +- .../checkSuperCallBeforeThisAccessing5.js | 2 +- .../checkSuperCallBeforeThisAccessing6.js | 2 +- .../checkSuperCallBeforeThisAccessing8.js | 2 +- .../collisionArgumentsArrowFunctions.js | 2 +- .../collisionArgumentsClassConstructor.js | 2 +- .../collisionArgumentsClassMethod.js | 2 +- .../reference/collisionArgumentsFunction.js | 2 +- .../collisionArgumentsFunctionExpressions.js | 2 +- .../collisionRestParameterArrowFunctions.js | 2 +- .../collisionRestParameterClassConstructor.js | 2 +- .../collisionRestParameterClassMethod.js | 2 +- .../collisionRestParameterFunction.js | 2 +- ...llisionRestParameterFunctionExpressions.js | 2 +- .../collisionRestParameterUnderscoreIUsage.js | 2 +- ...constructorWithIncompleteTypeAnnotation.js | 2 +- .../reference/contextuallyTypedIife.js | 6 +++--- .../contextuallyTypingRestParameters.js | 2 +- ...RestParametersOfFunctionAndFunctionType.js | 2 +- ...ingOptionalBindingParametersInOverloads.js | 4 ++-- .../reference/defaultExportWithOverloads01.js | 2 +- .../destructuringParameterDeclaration4.js | 14 ++++++------- .../destructuringParameterDeclaration6.js | 6 +++--- ...detachedCommentAtStartOfLambdaFunction1.js | 2 +- ...detachedCommentAtStartOfLambdaFunction2.js | 2 +- .../disallowLineTerminatorBeforeArrow.js | 4 ++-- .../emitDecoratorMetadata_restArgs.js | 8 ++++---- .../reference/emitRestParametersFunction.js | 2 +- .../emitRestParametersFunctionExpression.js | 6 +++--- .../emitRestParametersFunctionProperty.js | 2 +- .../reference/emitRestParametersMethod.js | 6 +++--- .../emitSkipsThisWithRestParameter.js | 2 +- tests/baselines/reference/es6ClassTest2.js | 2 +- .../reference/es6modulekindWithES5Target6.js | 2 +- .../reference/fatarrowfunctionsErrors.js | 4 ++-- .../fatarrowfunctionsOptionalArgs.js | 20 +++++++++---------- .../fatarrowfunctionsOptionalArgsErrors1.js | 6 +++--- .../fatarrowfunctionsOptionalArgsErrors3.js | 2 +- .../fatarrowfunctionsOptionalArgsErrors4.js | 2 +- tests/baselines/reference/functionCall10.js | 2 +- ...tionOverloadsRecursiveGenericReturnType.js | 2 +- tests/baselines/reference/genericRestArgs.js | 2 +- ...icitAnyDeclareFunctionWithoutFormalType.js | 2 +- .../inheritedConstructorWithRestParams.js | 2 +- tests/baselines/reference/newWithSpread.js | 2 +- tests/baselines/reference/newWithSpreadES5.js | 2 +- .../noImplicitAnyParametersInBareFunctions.js | 4 ++-- .../noImplicitAnyParametersInClass.js | 8 ++++---- .../noImplicitAnyParametersInModule.js | 4 ++-- tests/baselines/reference/nonArrayRestArgs.js | 2 +- .../optionalBindingParametersInOverloads1.js | 2 +- .../optionalBindingParametersInOverloads2.js | 2 +- .../overloadGenericFunctionWithRestArgs.js | 2 +- .../parenthesizedContexualTyping2.js | 2 +- tests/baselines/reference/parser509668.js | 2 +- .../parserMemberAccessorDeclaration18.js | 2 +- .../reference/parserParameterList10.js | 2 +- .../reference/parserParameterList11.js | 2 +- .../reference/parserParameterList9.js | 2 +- ...tatedFunctionInferenceWithTypeParameter.js | 2 +- .../reference/restArgAssignmentCompat.js | 2 +- .../baselines/reference/restArgMissingName.js | 2 +- .../reference/restParamAsOptional.js | 4 ++-- .../baselines/reference/restParamModifier2.js | 2 +- .../restParameterAssignmentCompatibility.js | 2 +- .../restParameterNoTypeAnnotation.js | 2 +- ...estParameterWithoutAnnotationIsAnyArray.js | 10 +++++----- .../restParametersOfNonArrayTypes.js | 10 +++++----- .../restParametersOfNonArrayTypes2.js | 20 +++++++++---------- .../restParametersWithArrayTypeAnnotations.js | 20 +++++++++---------- .../reference/restParamsWithNonRestParams.js | 2 +- .../stringLiteralTypeIsSubtypeOfString.js | 2 +- .../stringLiteralTypesOverloads03.js | 4 ++-- .../reference/subtypingWithCallSignatures2.js | 4 ++-- .../reference/subtypingWithCallSignatures3.js | 4 ++-- ...taggedTemplateStringsHexadecimalEscapes.js | 2 +- ...sPlainCharactersThatArePartsOfEscapes01.js | 2 +- ...gedTemplateStringsWithMultilineTemplate.js | 2 +- ...dTemplateStringsWithOverloadResolution1.js | 2 +- ...dTemplateStringsWithOverloadResolution2.js | 4 ++-- ...tionExpressionsInSubstitutionExpression.js | 2 +- ...taggedTemplateStringsWithUnicodeEscapes.js | 2 +- ...gedTemplateStringsWithWhitespaceEscapes.js | 2 +- ...gCommasInFunctionParametersAndArguments.js | 2 +- .../typeArgumentsWithStringLiteralTypes01.js | 2 +- .../reference/typeGuardFunctionErrors.js | 2 +- .../reference/undeclaredModuleError.js | 2 +- .../reference/unionTypeCallSignatures3.js | 2 +- .../unusedParametersWithUnderscore.js | 4 ++-- .../varArgConstructorMemberParameter.js | 4 ++-- .../reference/varArgParamTypeCheck.js | 2 +- .../reference/varArgWithNoParamName.js | 2 +- tests/baselines/reference/vararg.js | 2 +- 96 files changed, 170 insertions(+), 168 deletions(-) diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 838e58ae99b5c..bc9341a4b4f71 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1306,7 +1306,9 @@ namespace ts { createAssignment( createElementAccess( expressionName, - createSubtract(temp, createLiteral(restIndex)) + restIndex === 0 + ? temp + : createSubtract(temp, createLiteral(restIndex)) ), createElementAccess(createIdentifier("arguments"), temp) ), diff --git a/tests/baselines/reference/accessorWithRestParam.js b/tests/baselines/reference/accessorWithRestParam.js index a58a7db1c5256..871f3ed00efa0 100644 --- a/tests/baselines/reference/accessorWithRestParam.js +++ b/tests/baselines/reference/accessorWithRestParam.js @@ -13,7 +13,7 @@ var C = (function () { set: function () { var v = []; for (var _i = 0; _i < arguments.length; _i++) { - v[_i - 0] = arguments[_i]; + v[_i] = arguments[_i]; } }, enumerable: true, @@ -23,7 +23,7 @@ var C = (function () { set: function () { var v2 = []; for (var _i = 0; _i < arguments.length; _i++) { - v2[_i - 0] = arguments[_i]; + v2[_i] = arguments[_i]; } }, enumerable: true, diff --git a/tests/baselines/reference/assignmentCompatWithCallSignaturesWithRestParameters.js b/tests/baselines/reference/assignmentCompatWithCallSignaturesWithRestParameters.js index f4cf5cc79e29b..ec86f218ac0f9 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignaturesWithRestParameters.js +++ b/tests/baselines/reference/assignmentCompatWithCallSignaturesWithRestParameters.js @@ -52,14 +52,14 @@ a = function () { return 1; }; // ok, same number of required params a = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return 1; }; // ok, same number of required params a = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return 1; }; // error, type mismatch @@ -72,7 +72,7 @@ a2 = function () { return 1; }; // ok, fewer required params a2 = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return 1; }; // ok, fewer required params diff --git a/tests/baselines/reference/baseTypeAfterDerivedType.js b/tests/baselines/reference/baseTypeAfterDerivedType.js index b80b62712f5f9..c4ca7cf7b33a5 100644 --- a/tests/baselines/reference/baseTypeAfterDerivedType.js +++ b/tests/baselines/reference/baseTypeAfterDerivedType.js @@ -23,7 +23,7 @@ var Derived2 = (function () { Derived2.prototype.method = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } }; return Derived2; diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js index 8c7f18b77f617..4cce975d6d980 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -17,7 +17,7 @@ var Based = (function () { function Based() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } } return Based; diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js index cc8912230ab51..782e32362717e 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -20,7 +20,7 @@ var Base = (function () { function Base() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } } return Base; diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js index 25a480b9b57e8..5dd3708a3bb3d 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -20,7 +20,7 @@ var Base = (function () { function Base() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } } return Base; diff --git a/tests/baselines/reference/collisionArgumentsArrowFunctions.js b/tests/baselines/reference/collisionArgumentsArrowFunctions.js index 0aa939e1a2d7f..3e56b8b2f9cc3 100644 --- a/tests/baselines/reference/collisionArgumentsArrowFunctions.js +++ b/tests/baselines/reference/collisionArgumentsArrowFunctions.js @@ -37,7 +37,7 @@ var f1NoError = function (arguments) { var f2 = function () { var restParameters = []; for (var _i = 0; _i < arguments.length; _i++) { - restParameters[_i - 0] = arguments[_i]; + restParameters[_i] = arguments[_i]; } var arguments = 10; // No Error }; diff --git a/tests/baselines/reference/collisionArgumentsClassConstructor.js b/tests/baselines/reference/collisionArgumentsClassConstructor.js index 570b10d39d379..57ffa88f4e1d6 100644 --- a/tests/baselines/reference/collisionArgumentsClassConstructor.js +++ b/tests/baselines/reference/collisionArgumentsClassConstructor.js @@ -118,7 +118,7 @@ var c2 = (function () { function c2() { var restParameters = []; for (var _i = 0; _i < arguments.length; _i++) { - restParameters[_i - 0] = arguments[_i]; + restParameters[_i] = arguments[_i]; } var arguments = 10; // no error } diff --git a/tests/baselines/reference/collisionArgumentsClassMethod.js b/tests/baselines/reference/collisionArgumentsClassMethod.js index a20e0385e6a1c..85610926e350c 100644 --- a/tests/baselines/reference/collisionArgumentsClassMethod.js +++ b/tests/baselines/reference/collisionArgumentsClassMethod.js @@ -94,7 +94,7 @@ var c3 = (function () { c3.prototype.foo = function () { var restParameters = []; for (var _i = 0; _i < arguments.length; _i++) { - restParameters[_i - 0] = arguments[_i]; + restParameters[_i] = arguments[_i]; } var arguments = 10; // no error }; diff --git a/tests/baselines/reference/collisionArgumentsFunction.js b/tests/baselines/reference/collisionArgumentsFunction.js index 9ce4a5ab0e20b..c6a26baa495f9 100644 --- a/tests/baselines/reference/collisionArgumentsFunction.js +++ b/tests/baselines/reference/collisionArgumentsFunction.js @@ -66,7 +66,7 @@ function f1NoError(arguments) { function f3() { var restParameters = []; for (var _i = 0; _i < arguments.length; _i++) { - restParameters[_i - 0] = arguments[_i]; + restParameters[_i] = arguments[_i]; } var arguments = 10; // no error } diff --git a/tests/baselines/reference/collisionArgumentsFunctionExpressions.js b/tests/baselines/reference/collisionArgumentsFunctionExpressions.js index 405ceb625c3c9..b3389ddbf4a54 100644 --- a/tests/baselines/reference/collisionArgumentsFunctionExpressions.js +++ b/tests/baselines/reference/collisionArgumentsFunctionExpressions.js @@ -56,7 +56,7 @@ function foo() { function f3() { var restParameters = []; for (var _i = 0; _i < arguments.length; _i++) { - restParameters[_i - 0] = arguments[_i]; + restParameters[_i] = arguments[_i]; } var arguments = 10; // no error } diff --git a/tests/baselines/reference/collisionRestParameterArrowFunctions.js b/tests/baselines/reference/collisionRestParameterArrowFunctions.js index 39d449555db1d..3e20f48a4d056 100644 --- a/tests/baselines/reference/collisionRestParameterArrowFunctions.js +++ b/tests/baselines/reference/collisionRestParameterArrowFunctions.js @@ -27,7 +27,7 @@ var f1NoError = function (_i) { var f2 = function () { var restParameters = []; for (var _a = 0; _a < arguments.length; _a++) { - restParameters[_a - 0] = arguments[_a]; + restParameters[_a] = arguments[_a]; } var _i = 10; // No Error }; diff --git a/tests/baselines/reference/collisionRestParameterClassConstructor.js b/tests/baselines/reference/collisionRestParameterClassConstructor.js index 82d2ddc089657..f97e49531f64f 100644 --- a/tests/baselines/reference/collisionRestParameterClassConstructor.js +++ b/tests/baselines/reference/collisionRestParameterClassConstructor.js @@ -88,7 +88,7 @@ var c2 = (function () { function c2() { var restParameters = []; for (var _a = 0; _a < arguments.length; _a++) { - restParameters[_a - 0] = arguments[_a]; + restParameters[_a] = arguments[_a]; } var _i = 10; // no error } diff --git a/tests/baselines/reference/collisionRestParameterClassMethod.js b/tests/baselines/reference/collisionRestParameterClassMethod.js index eb92faa7b2ac8..cda717c79ab03 100644 --- a/tests/baselines/reference/collisionRestParameterClassMethod.js +++ b/tests/baselines/reference/collisionRestParameterClassMethod.js @@ -70,7 +70,7 @@ var c3 = (function () { c3.prototype.foo = function () { var restParameters = []; for (var _a = 0; _a < arguments.length; _a++) { - restParameters[_a - 0] = arguments[_a]; + restParameters[_a] = arguments[_a]; } var _i = 10; // no error }; diff --git a/tests/baselines/reference/collisionRestParameterFunction.js b/tests/baselines/reference/collisionRestParameterFunction.js index 8660e8f5db0ea..651062a696c3b 100644 --- a/tests/baselines/reference/collisionRestParameterFunction.js +++ b/tests/baselines/reference/collisionRestParameterFunction.js @@ -48,7 +48,7 @@ function f1NoError(_i) { function f3() { var restParameters = []; for (var _a = 0; _a < arguments.length; _a++) { - restParameters[_a - 0] = arguments[_a]; + restParameters[_a] = arguments[_a]; } var _i = 10; // no error } diff --git a/tests/baselines/reference/collisionRestParameterFunctionExpressions.js b/tests/baselines/reference/collisionRestParameterFunctionExpressions.js index 22709b087eb7b..87bafea09bd2f 100644 --- a/tests/baselines/reference/collisionRestParameterFunctionExpressions.js +++ b/tests/baselines/reference/collisionRestParameterFunctionExpressions.js @@ -39,7 +39,7 @@ function foo() { function f3() { var restParameters = []; for (var _a = 0; _a < arguments.length; _a++) { - restParameters[_a - 0] = arguments[_a]; + restParameters[_a] = arguments[_a]; } var _i = 10; // no error } diff --git a/tests/baselines/reference/collisionRestParameterUnderscoreIUsage.js b/tests/baselines/reference/collisionRestParameterUnderscoreIUsage.js index 97e82a1523f0e..1d7f9f43f7c11 100644 --- a/tests/baselines/reference/collisionRestParameterUnderscoreIUsage.js +++ b/tests/baselines/reference/collisionRestParameterUnderscoreIUsage.js @@ -14,7 +14,7 @@ var Foo = (function () { function Foo() { var args = []; for (var _a = 0; _a < arguments.length; _a++) { - args[_a - 0] = arguments[_a]; + args[_a] = arguments[_a]; } console.log(_i); // This should result in error } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js index 1ee309b0eb424..d4cd737ab46f5 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js @@ -297,7 +297,7 @@ var TypeScriptAllInOne; Program.Main = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } try { var bfs = new BasicFeatures(); diff --git a/tests/baselines/reference/contextuallyTypedIife.js b/tests/baselines/reference/contextuallyTypedIife.js index 0a84e45e30bb8..d2eaaf9c2d5fe 100644 --- a/tests/baselines/reference/contextuallyTypedIife.js +++ b/tests/baselines/reference/contextuallyTypedIife.js @@ -57,21 +57,21 @@ let eleven = (o => o.a(11))({ a: function(n) { return n; } }); (function () { var numbers = []; for (var _i = 0; _i < arguments.length; _i++) { - numbers[_i - 0] = arguments[_i]; + numbers[_i] = arguments[_i]; } return numbers.every(function (n) { return n > 0; }); })(5, 6, 7); (function () { var mixed = []; for (var _i = 0; _i < arguments.length; _i++) { - mixed[_i - 0] = arguments[_i]; + mixed[_i] = arguments[_i]; } return mixed.every(function (n) { return !!n; }); })(5, 'oops', 'oh no'); (function () { var noNumbers = []; for (var _i = 0; _i < arguments.length; _i++) { - noNumbers[_i - 0] = arguments[_i]; + noNumbers[_i] = arguments[_i]; } return noNumbers.some(function (n) { return n > 0; }); })(); diff --git a/tests/baselines/reference/contextuallyTypingRestParameters.js b/tests/baselines/reference/contextuallyTypingRestParameters.js index 17561f5d7fccb..8a1f2ffbdfbcc 100644 --- a/tests/baselines/reference/contextuallyTypingRestParameters.js +++ b/tests/baselines/reference/contextuallyTypingRestParameters.js @@ -11,7 +11,7 @@ var x: (...y: string[]) => void = function (.../*3*/y) { var x = function () { var y = []; for (var _i = 0; _i < arguments.length; _i++) { - y[_i - 0] = arguments[_i]; + y[_i] = arguments[_i]; } var t = y; var x2 = t; // This should be error diff --git a/tests/baselines/reference/declFileRestParametersOfFunctionAndFunctionType.js b/tests/baselines/reference/declFileRestParametersOfFunctionAndFunctionType.js index 563551d67a8e5..894f50fc5abf0 100644 --- a/tests/baselines/reference/declFileRestParametersOfFunctionAndFunctionType.js +++ b/tests/baselines/reference/declFileRestParametersOfFunctionAndFunctionType.js @@ -14,7 +14,7 @@ var f6 = () => { return [10]; } function f1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } function f2(x) { } diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js index a3cdee312222c..941bb383f8135 100644 --- a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -13,13 +13,13 @@ function foo2(...rest: any[]) { function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } function foo2() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } diff --git a/tests/baselines/reference/defaultExportWithOverloads01.js b/tests/baselines/reference/defaultExportWithOverloads01.js index f88d60182db13..770b685378da6 100644 --- a/tests/baselines/reference/defaultExportWithOverloads01.js +++ b/tests/baselines/reference/defaultExportWithOverloads01.js @@ -10,7 +10,7 @@ export default function f(...args: any[]) { function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js index 44838d600d8f0..52007df17c94b 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.js +++ b/tests/baselines/reference/destructuringParameterDeclaration4.js @@ -43,31 +43,31 @@ foo1(1, 2, "string", E1.a, E.b); // Error function a0() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } // Error, rest parameter must be array type function a1() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } function a2() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } } // Error, rest parameter must be array type function a3() { var b = []; for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; + b[_i] = arguments[_i]; } } // Error, can't be optional function a4() { var b = []; for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; + b[_i] = arguments[_i]; } } // Error, can't have initializer function a5(_a) { @@ -86,7 +86,7 @@ var C = (function () { function C() { var temp = []; for (var _i = 0; _i < arguments.length; _i++) { - temp[_i - 0] = arguments[_i]; + temp[_i] = arguments[_i]; } this.temp = temp; } // Error, rest parameter can't have properties @@ -96,7 +96,7 @@ var C = (function () { function foo1() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } } foo1(1, 2, "string", E1.a, E.b); // Error diff --git a/tests/baselines/reference/destructuringParameterDeclaration6.js b/tests/baselines/reference/destructuringParameterDeclaration6.js index 03307415b6514..a8c7f65211f75 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration6.js +++ b/tests/baselines/reference/destructuringParameterDeclaration6.js @@ -40,20 +40,20 @@ while (, ) function a5() { var = []; for (var _i = 0; _i < arguments.length; _i++) { - [_i - 0] = arguments[_i]; + [_i] = arguments[_i]; } } while () { } function a6() { var public = []; for (var _i = 0; _i < arguments.length; _i++) { - public[_i - 0] = arguments[_i]; + public[_i] = arguments[_i]; } } function a7() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } } a({ "while": 1 }); diff --git a/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction1.js b/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction1.js index 51ae4090ae152..495ac29f26980 100644 --- a/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction1.js +++ b/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction1.js @@ -19,7 +19,7 @@ var TestFile = (function () { return function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } /// Test summary /// diff --git a/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction2.js b/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction2.js index 22dfe4bbc4480..e6ced9a8a420c 100644 --- a/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction2.js +++ b/tests/baselines/reference/detachedCommentAtStartOfLambdaFunction2.js @@ -23,7 +23,7 @@ var TestFile = (function () { /// var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } return message + _this.name; }; diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js index 0c6b98def4fd1..9f0d04d301ce7 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js @@ -92,13 +92,13 @@ var f4 = function (x, y) { var f5 = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } }; var f6 = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } }; var f7 = function (x, y, z) { diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js index ec8240b264224..4bc1f02321296 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js @@ -32,13 +32,13 @@ var A = (function () { function A() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } A.prototype.method = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } }; return A; @@ -57,13 +57,13 @@ var B = (function () { function B() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } B.prototype.method = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } }; return B; diff --git a/tests/baselines/reference/emitRestParametersFunction.js b/tests/baselines/reference/emitRestParametersFunction.js index 01116f2ac9263..dff77ad4b5559 100644 --- a/tests/baselines/reference/emitRestParametersFunction.js +++ b/tests/baselines/reference/emitRestParametersFunction.js @@ -6,7 +6,7 @@ function foo(x: number, y: string, ...rest) { } function bar() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } function foo(x, y) { diff --git a/tests/baselines/reference/emitRestParametersFunctionExpression.js b/tests/baselines/reference/emitRestParametersFunctionExpression.js index da87cc79f2de8..55d4b505808f6 100644 --- a/tests/baselines/reference/emitRestParametersFunctionExpression.js +++ b/tests/baselines/reference/emitRestParametersFunctionExpression.js @@ -9,7 +9,7 @@ var funcExp3 = (function (...rest) { })() var funcExp = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } }; var funcExp1 = function (X) { @@ -21,12 +21,12 @@ var funcExp1 = function (X) { var funcExp2 = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } }; var funcExp3 = (function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } })(); diff --git a/tests/baselines/reference/emitRestParametersFunctionProperty.js b/tests/baselines/reference/emitRestParametersFunctionProperty.js index 4fd60a9269d87..99d004daeb2d0 100644 --- a/tests/baselines/reference/emitRestParametersFunctionProperty.js +++ b/tests/baselines/reference/emitRestParametersFunctionProperty.js @@ -13,7 +13,7 @@ var obj2 = { func: function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } }; diff --git a/tests/baselines/reference/emitRestParametersMethod.js b/tests/baselines/reference/emitRestParametersMethod.js index 1dec771cde8cc..fed2138f36be1 100644 --- a/tests/baselines/reference/emitRestParametersMethod.js +++ b/tests/baselines/reference/emitRestParametersMethod.js @@ -24,7 +24,7 @@ var C = (function () { C.prototype.bar = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } }; C.prototype.foo = function (x) { @@ -39,13 +39,13 @@ var D = (function () { function D() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } D.prototype.bar = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } }; D.prototype.foo = function (x) { diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.js b/tests/baselines/reference/emitSkipsThisWithRestParameter.js index d1e99f9409dc5..5645a7e063693 100644 --- a/tests/baselines/reference/emitSkipsThisWithRestParameter.js +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.js @@ -11,7 +11,7 @@ function rebase(fn) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return fn.apply(this, [this].concat(args)); }; diff --git a/tests/baselines/reference/es6ClassTest2.js b/tests/baselines/reference/es6ClassTest2.js index de5657b087e72..533b332422d72 100644 --- a/tests/baselines/reference/es6ClassTest2.js +++ b/tests/baselines/reference/es6ClassTest2.js @@ -236,7 +236,7 @@ var SplatMonster = (function () { function SplatMonster() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } SplatMonster.prototype.roar = function (name) { diff --git a/tests/baselines/reference/es6modulekindWithES5Target6.js b/tests/baselines/reference/es6modulekindWithES5Target6.js index d305c60e54ec6..cff2327dacba8 100644 --- a/tests/baselines/reference/es6modulekindWithES5Target6.js +++ b/tests/baselines/reference/es6modulekindWithES5Target6.js @@ -17,7 +17,7 @@ export function f1(d) { export function f2() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } } export default function f3(d) { diff --git a/tests/baselines/reference/fatarrowfunctionsErrors.js b/tests/baselines/reference/fatarrowfunctionsErrors.js index ced4660d8d10b..0f318f1aa84ad 100644 --- a/tests/baselines/reference/fatarrowfunctionsErrors.js +++ b/tests/baselines/reference/fatarrowfunctionsErrors.js @@ -16,7 +16,7 @@ var x4= (...a: any[]) { }; foo(function () { var Far = []; for (var _i = 0; _i < arguments.length; _i++) { - Far[_i - 0] = arguments[_i]; + Far[_i] = arguments[_i]; } return 0; }); @@ -36,6 +36,6 @@ var x3 = function (a) { }; var x4 = function () { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } }; diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.js b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.js index e6e43f8bbf453..f7e49680f8a51 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.js +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.js @@ -159,7 +159,7 @@ foo( (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 8; }); @@ -203,7 +203,7 @@ foo( (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 28; }); @@ -226,7 +226,7 @@ false ? function (arg) { false ? function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 48; } : null; @@ -247,7 +247,7 @@ false ? (function (arg) { false ? (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 58; }) : null; @@ -268,7 +268,7 @@ false ? null : function (arg) { false ? null : function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 68; }; @@ -294,7 +294,7 @@ false ? null : function () { (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 96; }) instanceof Function; @@ -326,13 +326,13 @@ false ? null : function () { (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 0; }) + '' + (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 107; }); @@ -354,7 +354,7 @@ false ? null : function () { function foo() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } } foo(function (a) { return 110; }, (function (a) { return 111; }), function (a) { @@ -371,7 +371,7 @@ foo(function (a) { return 110; }, (function (a) { return 111; }), function (a) { }, function () { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } return 119; }, function (a, b) { diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js index 4d27f8230ebfe..edbc897922c1b 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js @@ -12,21 +12,21 @@ (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 102; }); (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 103; }); (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 104; }); diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.js b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.js index 665c52440169e..d5d4b099a06be 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.js +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.js @@ -6,7 +6,7 @@ (function () { var = []; for (var _i = 0; _i < arguments.length; _i++) { - [_i - 0] = arguments[_i]; + [_i] = arguments[_i]; } return 105; }); diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.js b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.js index dfd7e9f74dcb2..0fbf4b7486e7a 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.js +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.js @@ -56,7 +56,7 @@ foo(function (a) { return 110; }, (function (a) { return 111; }), function (a) { }, function () { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } return 119; }, function (a, b) { diff --git a/tests/baselines/reference/functionCall10.js b/tests/baselines/reference/functionCall10.js index 9d5cb33a56a3b..51ed76990b343 100644 --- a/tests/baselines/reference/functionCall10.js +++ b/tests/baselines/reference/functionCall10.js @@ -10,7 +10,7 @@ foo(1, 'bar'); function foo() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } } ; diff --git a/tests/baselines/reference/functionOverloadsRecursiveGenericReturnType.js b/tests/baselines/reference/functionOverloadsRecursiveGenericReturnType.js index 1d38d65ad38b4..b616d18c974eb 100644 --- a/tests/baselines/reference/functionOverloadsRecursiveGenericReturnType.js +++ b/tests/baselines/reference/functionOverloadsRecursiveGenericReturnType.js @@ -28,7 +28,7 @@ var A = (function () { function Choice() { var v_args = []; for (var _i = 0; _i < arguments.length; _i++) { - v_args[_i - 0] = arguments[_i]; + v_args[_i] = arguments[_i]; } return new A(); } diff --git a/tests/baselines/reference/genericRestArgs.js b/tests/baselines/reference/genericRestArgs.js index 75c88d7cbf2cc..1cfeb61e1695c 100644 --- a/tests/baselines/reference/genericRestArgs.js +++ b/tests/baselines/reference/genericRestArgs.js @@ -16,7 +16,7 @@ var a2Gc = makeArrayG(1, ""); // error function makeArrayG() { var items = []; for (var _i = 0; _i < arguments.length; _i++) { - items[_i - 0] = arguments[_i]; + items[_i] = arguments[_i]; } return items; } diff --git a/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js b/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js index c13479daff33f..0b2ba6191ef72 100644 --- a/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js +++ b/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js @@ -22,7 +22,7 @@ function func2(a, b, c) { } function func3() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } ; // error at "args" diff --git a/tests/baselines/reference/inheritedConstructorWithRestParams.js b/tests/baselines/reference/inheritedConstructorWithRestParams.js index c9db175667637..6a30836d72896 100644 --- a/tests/baselines/reference/inheritedConstructorWithRestParams.js +++ b/tests/baselines/reference/inheritedConstructorWithRestParams.js @@ -24,7 +24,7 @@ var Base = (function () { function Base() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } } return Base; diff --git a/tests/baselines/reference/newWithSpread.js b/tests/baselines/reference/newWithSpread.js index 91c502e50b9ec..c6ea3b44c15e8 100644 --- a/tests/baselines/reference/newWithSpread.js +++ b/tests/baselines/reference/newWithSpread.js @@ -107,7 +107,7 @@ function f(x, y) { function f2() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var B = (function () { diff --git a/tests/baselines/reference/newWithSpreadES5.js b/tests/baselines/reference/newWithSpreadES5.js index 92904062d0a30..125ac9f0412dd 100644 --- a/tests/baselines/reference/newWithSpreadES5.js +++ b/tests/baselines/reference/newWithSpreadES5.js @@ -106,7 +106,7 @@ function f(x, y) { function f2() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var B = (function () { diff --git a/tests/baselines/reference/noImplicitAnyParametersInBareFunctions.js b/tests/baselines/reference/noImplicitAnyParametersInBareFunctions.js index 8efe32d3140a9..3b0b630b537c4 100644 --- a/tests/baselines/reference/noImplicitAnyParametersInBareFunctions.js +++ b/tests/baselines/reference/noImplicitAnyParametersInBareFunctions.js @@ -59,7 +59,7 @@ function f5(x, y, z) { } function f6() { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } } // Implicit-'any'/'any[]' errors for x, r. @@ -82,7 +82,7 @@ var f12 = function (x, y, z) { return ""; }; var f13 = function () { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } return ""; }; diff --git a/tests/baselines/reference/noImplicitAnyParametersInClass.js b/tests/baselines/reference/noImplicitAnyParametersInClass.js index 0e24793652907..4ad093f56be8b 100644 --- a/tests/baselines/reference/noImplicitAnyParametersInClass.js +++ b/tests/baselines/reference/noImplicitAnyParametersInClass.js @@ -107,7 +107,7 @@ var C = (function () { this.pub_f13 = function () { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } return ""; }; @@ -131,7 +131,7 @@ var C = (function () { this.priv_f13 = function () { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } return ""; }; @@ -158,7 +158,7 @@ var C = (function () { C.prototype.pub_f6 = function () { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } }; // Implicit-'any'/'any[]' errors for x, r. @@ -184,7 +184,7 @@ var C = (function () { C.prototype.priv_f6 = function () { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } }; // Implicit-'any'/'any[]' errors for x, r. diff --git a/tests/baselines/reference/noImplicitAnyParametersInModule.js b/tests/baselines/reference/noImplicitAnyParametersInModule.js index e7f3020555965..1866696fe34d1 100644 --- a/tests/baselines/reference/noImplicitAnyParametersInModule.js +++ b/tests/baselines/reference/noImplicitAnyParametersInModule.js @@ -63,7 +63,7 @@ var M; function m_f6() { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } } // Implicit-'any'/'any[]' errors for x and r. @@ -86,7 +86,7 @@ var M; var m_f13 = function () { var r = []; for (var _i = 0; _i < arguments.length; _i++) { - r[_i - 0] = arguments[_i]; + r[_i] = arguments[_i]; } return ""; }; diff --git a/tests/baselines/reference/nonArrayRestArgs.js b/tests/baselines/reference/nonArrayRestArgs.js index d16b7dea3466e..813f7141b5ccd 100644 --- a/tests/baselines/reference/nonArrayRestArgs.js +++ b/tests/baselines/reference/nonArrayRestArgs.js @@ -8,7 +8,7 @@ function foo(...rest: number) { // error function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } var x = rest[0]; return x; diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads1.js b/tests/baselines/reference/optionalBindingParametersInOverloads1.js index 3658efa72c6e1..9fd64d0da9e72 100644 --- a/tests/baselines/reference/optionalBindingParametersInOverloads1.js +++ b/tests/baselines/reference/optionalBindingParametersInOverloads1.js @@ -13,7 +13,7 @@ foo([false, 0, ""]); function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } foo(["", 0, false]); diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads2.js b/tests/baselines/reference/optionalBindingParametersInOverloads2.js index 1ddfdae4f07d9..033d81993f5e9 100644 --- a/tests/baselines/reference/optionalBindingParametersInOverloads2.js +++ b/tests/baselines/reference/optionalBindingParametersInOverloads2.js @@ -13,7 +13,7 @@ foo({ x: false, y: 0, z: "" }); function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } foo({ x: "", y: 0, z: false }); diff --git a/tests/baselines/reference/overloadGenericFunctionWithRestArgs.js b/tests/baselines/reference/overloadGenericFunctionWithRestArgs.js index 356cece5ab6e3..e83f33f3ad024 100644 --- a/tests/baselines/reference/overloadGenericFunctionWithRestArgs.js +++ b/tests/baselines/reference/overloadGenericFunctionWithRestArgs.js @@ -24,7 +24,7 @@ var A = (function () { function Choice() { var v_args = []; for (var _i = 0; _i < arguments.length; _i++) { - v_args[_i - 0] = arguments[_i]; + v_args[_i] = arguments[_i]; } return new A(); } diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.js b/tests/baselines/reference/parenthesizedContexualTyping2.js index 993a10ba49cd8..48b9355ca317a 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.js +++ b/tests/baselines/reference/parenthesizedContexualTyping2.js @@ -45,7 +45,7 @@ var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); function fun() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } return undefined; } diff --git a/tests/baselines/reference/parser509668.js b/tests/baselines/reference/parser509668.js index c767aea676af0..5dfdc7d1e3137 100644 --- a/tests/baselines/reference/parser509668.js +++ b/tests/baselines/reference/parser509668.js @@ -10,7 +10,7 @@ var Foo3 = (function () { function Foo3() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } this.args = args; } diff --git a/tests/baselines/reference/parserMemberAccessorDeclaration18.js b/tests/baselines/reference/parserMemberAccessorDeclaration18.js index e25aa69f4654f..c6c902d49157c 100644 --- a/tests/baselines/reference/parserMemberAccessorDeclaration18.js +++ b/tests/baselines/reference/parserMemberAccessorDeclaration18.js @@ -11,7 +11,7 @@ var C = (function () { set: function () { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } }, enumerable: true, diff --git a/tests/baselines/reference/parserParameterList10.js b/tests/baselines/reference/parserParameterList10.js index 93ed8c60e8bee..f899901728c20 100644 --- a/tests/baselines/reference/parserParameterList10.js +++ b/tests/baselines/reference/parserParameterList10.js @@ -10,7 +10,7 @@ var C = (function () { C.prototype.foo = function () { var bar = []; for (var _i = 0; _i < arguments.length; _i++) { - bar[_i - 0] = arguments[_i]; + bar[_i] = arguments[_i]; } }; return C; diff --git a/tests/baselines/reference/parserParameterList11.js b/tests/baselines/reference/parserParameterList11.js index a56e8b58c201a..c736e5fddb6b7 100644 --- a/tests/baselines/reference/parserParameterList11.js +++ b/tests/baselines/reference/parserParameterList11.js @@ -5,7 +5,7 @@ (function () { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } return 102; }); diff --git a/tests/baselines/reference/parserParameterList9.js b/tests/baselines/reference/parserParameterList9.js index ec08b48f5729e..3ccc1d0202569 100644 --- a/tests/baselines/reference/parserParameterList9.js +++ b/tests/baselines/reference/parserParameterList9.js @@ -10,7 +10,7 @@ var C = (function () { C.prototype.foo = function () { var bar = []; for (var _i = 0; _i < arguments.length; _i++) { - bar[_i - 0] = arguments[_i]; + bar[_i] = arguments[_i]; } }; return C; diff --git a/tests/baselines/reference/partiallyAnnotatedFunctionInferenceWithTypeParameter.js b/tests/baselines/reference/partiallyAnnotatedFunctionInferenceWithTypeParameter.js index d485fb11d7fb4..d20b35625e961 100644 --- a/tests/baselines/reference/partiallyAnnotatedFunctionInferenceWithTypeParameter.js +++ b/tests/baselines/reference/partiallyAnnotatedFunctionInferenceWithTypeParameter.js @@ -63,7 +63,7 @@ test(function (t1) { }); test(function () { var ts = []; for (var _i = 0; _i < arguments.length; _i++) { - ts[_i - 0] = arguments[_i]; + ts[_i] = arguments[_i]; } }); // source function has rest arg diff --git a/tests/baselines/reference/restArgAssignmentCompat.js b/tests/baselines/reference/restArgAssignmentCompat.js index 3f8749f332dc4..b679f56a88172 100644 --- a/tests/baselines/reference/restArgAssignmentCompat.js +++ b/tests/baselines/reference/restArgAssignmentCompat.js @@ -13,7 +13,7 @@ n([4], 'foo'); function f() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } x.forEach(function (n, i) { return void ('item ' + i + ' = ' + n); }); } diff --git a/tests/baselines/reference/restArgMissingName.js b/tests/baselines/reference/restArgMissingName.js index b87800c7dacb6..f4ec647f7e4fb 100644 --- a/tests/baselines/reference/restArgMissingName.js +++ b/tests/baselines/reference/restArgMissingName.js @@ -6,6 +6,6 @@ function sum (...) {} function sum() { var = []; for (var _i = 0; _i < arguments.length; _i++) { - [_i - 0] = arguments[_i]; + [_i] = arguments[_i]; } } diff --git a/tests/baselines/reference/restParamAsOptional.js b/tests/baselines/reference/restParamAsOptional.js index eb224b84c33b1..2f6da684c0edd 100644 --- a/tests/baselines/reference/restParamAsOptional.js +++ b/tests/baselines/reference/restParamAsOptional.js @@ -6,12 +6,12 @@ function f2(...x = []) { } function f() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } function f2() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } diff --git a/tests/baselines/reference/restParamModifier2.js b/tests/baselines/reference/restParamModifier2.js index a11b78a2376f8..e98aef3f9ad9a 100644 --- a/tests/baselines/reference/restParamModifier2.js +++ b/tests/baselines/reference/restParamModifier2.js @@ -8,7 +8,7 @@ var C = (function () { function C() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } this.rest = rest; } diff --git a/tests/baselines/reference/restParameterAssignmentCompatibility.js b/tests/baselines/reference/restParameterAssignmentCompatibility.js index 0821cf182771f..01472c78c1ec5 100644 --- a/tests/baselines/reference/restParameterAssignmentCompatibility.js +++ b/tests/baselines/reference/restParameterAssignmentCompatibility.js @@ -33,7 +33,7 @@ var T = (function () { T.prototype.m = function () { var p3 = []; for (var _i = 0; _i < arguments.length; _i++) { - p3[_i - 0] = arguments[_i]; + p3[_i] = arguments[_i]; } }; return T; diff --git a/tests/baselines/reference/restParameterNoTypeAnnotation.js b/tests/baselines/reference/restParameterNoTypeAnnotation.js index 95e092fdd4373..b22b531675daf 100644 --- a/tests/baselines/reference/restParameterNoTypeAnnotation.js +++ b/tests/baselines/reference/restParameterNoTypeAnnotation.js @@ -9,7 +9,7 @@ function foo(...rest) { function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } var x = rest[0]; return x; diff --git a/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js b/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js index c6b5fa2ae413f..5c1db2c62e1b3 100644 --- a/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js +++ b/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js @@ -31,13 +31,13 @@ var b = { function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var f = function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; var f2 = function () { @@ -52,7 +52,7 @@ var C = (function () { C.prototype.foo = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; return C; @@ -62,7 +62,7 @@ var b = { foo: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }, a: function foo() { @@ -74,7 +74,7 @@ var b = { b: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } }; diff --git a/tests/baselines/reference/restParametersOfNonArrayTypes.js b/tests/baselines/reference/restParametersOfNonArrayTypes.js index 5400a8b43cc91..6714516772083 100644 --- a/tests/baselines/reference/restParametersOfNonArrayTypes.js +++ b/tests/baselines/reference/restParametersOfNonArrayTypes.js @@ -30,13 +30,13 @@ var b = { function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var f = function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; var f2 = function () { @@ -51,7 +51,7 @@ var C = (function () { C.prototype.foo = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; return C; @@ -61,7 +61,7 @@ var b = { foo: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }, a: function foo() { @@ -73,7 +73,7 @@ var b = { b: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } }; diff --git a/tests/baselines/reference/restParametersOfNonArrayTypes2.js b/tests/baselines/reference/restParametersOfNonArrayTypes2.js index d405c13db5ae1..7df2458a27b3f 100644 --- a/tests/baselines/reference/restParametersOfNonArrayTypes2.js +++ b/tests/baselines/reference/restParametersOfNonArrayTypes2.js @@ -62,13 +62,13 @@ var b2 = { function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var f = function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; var f2 = function () { @@ -83,7 +83,7 @@ var C = (function () { C.prototype.foo = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; return C; @@ -93,7 +93,7 @@ var b = { foo: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }, a: function foo() { @@ -105,20 +105,20 @@ var b = { b: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } }; function foo2() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var f3 = function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; var f4 = function () { @@ -133,7 +133,7 @@ var C2 = (function () { C2.prototype.foo = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; return C2; @@ -143,7 +143,7 @@ var b2 = { foo: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }, a: function foo() { @@ -155,7 +155,7 @@ var b2 = { b: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } }; diff --git a/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js b/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js index 3f1cf33e7ba18..1004fdfcbcb41 100644 --- a/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js +++ b/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js @@ -57,13 +57,13 @@ var b2 = { function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var f = function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; var f2 = function () { @@ -78,7 +78,7 @@ var C = (function () { C.prototype.foo = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; return C; @@ -88,7 +88,7 @@ var b = { foo: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }, a: function foo() { @@ -100,20 +100,20 @@ var b = { b: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } }; function foo2() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } var f3 = function foo() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; var f4 = function () { @@ -128,7 +128,7 @@ var C2 = (function () { C2.prototype.foo = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }; return C2; @@ -138,7 +138,7 @@ var b2 = { foo: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } }, a: function foo() { @@ -150,7 +150,7 @@ var b2 = { b: function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } }; diff --git a/tests/baselines/reference/restParamsWithNonRestParams.js b/tests/baselines/reference/restParamsWithNonRestParams.js index 6b0caa723940a..7b16959143a45 100644 --- a/tests/baselines/reference/restParamsWithNonRestParams.js +++ b/tests/baselines/reference/restParamsWithNonRestParams.js @@ -10,7 +10,7 @@ foo3(); // error but shouldn't be function foo() { var b = []; for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; + b[_i] = arguments[_i]; } } foo(); // ok diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js index 78417b9a082bc..55ea133577104 100644 --- a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js +++ b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js @@ -120,7 +120,7 @@ var C = (function () { C.prototype.concat = function () { var strings = []; for (var _i = 0; _i < arguments.length; _i++) { - strings[_i - 0] = arguments[_i]; + strings[_i] = arguments[_i]; } return null; }; diff --git a/tests/baselines/reference/stringLiteralTypesOverloads03.js b/tests/baselines/reference/stringLiteralTypesOverloads03.js index c1e7916088095..4fdfd4f85d0bd 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads03.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads03.js @@ -52,7 +52,7 @@ var helloOrWorld; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return undefined; } @@ -62,7 +62,7 @@ var fResult3 = f(helloOrWorld); function g() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return undefined; } diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.js b/tests/baselines/reference/subtypingWithCallSignatures2.js index 843a727c33e6b..3b5fada20121b 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.js +++ b/tests/baselines/reference/subtypingWithCallSignatures2.js @@ -253,14 +253,14 @@ var r9b = [r9arg2, r9arg1]; var r10arg1 = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } return x[0]; }; var r10arg2 = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } return null; }; diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.js b/tests/baselines/reference/subtypingWithCallSignatures3.js index a9e7d01aab661..4ac7d3a7f24a9 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.js +++ b/tests/baselines/reference/subtypingWithCallSignatures3.js @@ -170,14 +170,14 @@ var Errors; var r4arg = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } return null; }; var r4arg2 = function () { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } return null; }; diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js index e4482ded0c2dd..3df09abb2db8d 100644 --- a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js @@ -8,7 +8,7 @@ f `\x0D${ "Interrupted CRLF" }\x0A`; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } (_a = ["\r", "\n"], _a.raw = ["\\x0D", "\\x0A"], f(_a, "Interrupted CRLF")); diff --git a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js index 9450e939f2f69..33c2914e3e824 100644 --- a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js +++ b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js @@ -11,7 +11,7 @@ f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r function f() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; + x[_i] = arguments[_i]; } } (_a = ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], _a.raw = ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], f(_a)); diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js index cee9d1efce431..9ffc0cadfef09 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js @@ -11,7 +11,7 @@ f ` function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } (_a = ["\n\n"], _a.raw = ["\n\\\n\n"], f(_a)); diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js index 4245b0cb0f436..19211c2fa8a3b 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js @@ -26,7 +26,7 @@ var z = foo `${1}${2}${3}`; // any (with error) function foo() { var stuff = []; for (var _i = 0; _i < arguments.length; _i++) { - stuff[_i - 0] = arguments[_i]; + stuff[_i] = arguments[_i]; } return undefined; } diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js index c16bfa5454f77..fdac55da181b5 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js @@ -22,7 +22,7 @@ var d = foo2([], 1); function foo1() { var stuff = []; for (var _i = 0; _i < arguments.length; _i++) { - stuff[_i - 0] = arguments[_i]; + stuff[_i] = arguments[_i]; } return undefined; } @@ -31,7 +31,7 @@ var b = foo1([], 1); function foo2() { var stuff = []; for (var _i = 0; _i < arguments.length; _i++) { - stuff[_i - 0] = arguments[_i]; + stuff[_i] = arguments[_i]; } return undefined; } diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js index f7523eb9870dd..334f61e453d3d 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js @@ -10,7 +10,7 @@ foo `${function (x: number) { x = "bad"; } }`; function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } } (_a = ["", ""], _a.raw = ["", ""], foo(_a, function (x) { x = "bad"; })); diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js index ae73b0b227e58..6a04b082e1f08 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js @@ -8,7 +8,7 @@ f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } (_a = ["'\uD83D\uDCA9'", "'\uD83D\uDCA9'"], _a.raw = ["'\\u{1f4a9}'", "'\\uD83D\\uDCA9'"], f(_a, " should be converted to ")); diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js index 65af8da59f997..e8f219fd12582 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js @@ -8,7 +8,7 @@ f `\t\n\v\f\r\\`; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } (_a = ["\t\n\v\f\r\\"], _a.raw = ["\\t\\n\\v\\f\\r\\\\"], f(_a)); diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js index 6f30140c63ec1..495e9354024e6 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js @@ -35,7 +35,7 @@ f1(1); function f2() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } f2.apply(void 0, []); diff --git a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js index c07dd22539648..74a609694aa29 100644 --- a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js +++ b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js @@ -122,7 +122,7 @@ function fun2(x, y) { function fun3() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } return args[+randBool()]; } diff --git a/tests/baselines/reference/typeGuardFunctionErrors.js b/tests/baselines/reference/typeGuardFunctionErrors.js index 244b0df3333db..99c25faaa88ca 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.js +++ b/tests/baselines/reference/typeGuardFunctionErrors.js @@ -264,7 +264,7 @@ C; function b4() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + a[_i] = arguments[_i]; } return true; } diff --git a/tests/baselines/reference/undeclaredModuleError.js b/tests/baselines/reference/undeclaredModuleError.js index c9a43ab4ce67e..88f5e3ab3522c 100644 --- a/tests/baselines/reference/undeclaredModuleError.js +++ b/tests/baselines/reference/undeclaredModuleError.js @@ -22,7 +22,7 @@ define(["require", "exports", "fs"], function (require, exports, fs) { function join() { var paths = []; for (var _i = 0; _i < arguments.length; _i++) { - paths[_i - 0] = arguments[_i]; + paths[_i] = arguments[_i]; } } function instrumentFile(covFileDir, covFileName, originalFilePath) { diff --git a/tests/baselines/reference/unionTypeCallSignatures3.js b/tests/baselines/reference/unionTypeCallSignatures3.js index 2dae152e47450..b3c24a0e60a60 100644 --- a/tests/baselines/reference/unionTypeCallSignatures3.js +++ b/tests/baselines/reference/unionTypeCallSignatures3.js @@ -18,7 +18,7 @@ function f2(s) { } function f3() { var s = []; for (var _i = 0; _i < arguments.length; _i++) { - s[_i - 0] = arguments[_i]; + s[_i] = arguments[_i]; } } function f4(s, s2) { } diff --git a/tests/baselines/reference/unusedParametersWithUnderscore.js b/tests/baselines/reference/unusedParametersWithUnderscore.js index 2899d347c66f3..02d5da3339543 100644 --- a/tests/baselines/reference/unusedParametersWithUnderscore.js +++ b/tests/baselines/reference/unusedParametersWithUnderscore.js @@ -35,13 +35,13 @@ function f3(_c) { function f4() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { - arg[_i - 0] = arguments[_i]; + arg[_i] = arguments[_i]; } } function f5() { var _arg = []; for (var _i = 0; _i < arguments.length; _i++) { - _arg[_i - 0] = arguments[_i]; + _arg[_i] = arguments[_i]; } } function f6(arg, _arg) { diff --git a/tests/baselines/reference/varArgConstructorMemberParameter.js b/tests/baselines/reference/varArgConstructorMemberParameter.js index 2715ed9e542f3..0d80c2b4dbbd7 100644 --- a/tests/baselines/reference/varArgConstructorMemberParameter.js +++ b/tests/baselines/reference/varArgConstructorMemberParameter.js @@ -17,7 +17,7 @@ var Foo1 = (function () { function Foo1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } } return Foo1; @@ -32,7 +32,7 @@ var Foo3 = (function () { function Foo3() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } this.args = args; } diff --git a/tests/baselines/reference/varArgParamTypeCheck.js b/tests/baselines/reference/varArgParamTypeCheck.js index c2a33416436a0..2807ca970580b 100644 --- a/tests/baselines/reference/varArgParamTypeCheck.js +++ b/tests/baselines/reference/varArgParamTypeCheck.js @@ -25,7 +25,7 @@ sequence( function sequence() { var sequences = []; for (var _i = 0; _i < arguments.length; _i++) { - sequences[_i - 0] = arguments[_i]; + sequences[_i] = arguments[_i]; } } function callback(clb) { diff --git a/tests/baselines/reference/varArgWithNoParamName.js b/tests/baselines/reference/varArgWithNoParamName.js index 05a9695770a3a..3aa9fcbabb0a7 100644 --- a/tests/baselines/reference/varArgWithNoParamName.js +++ b/tests/baselines/reference/varArgWithNoParamName.js @@ -5,6 +5,6 @@ function t1(...) {} function t1() { var = []; for (var _i = 0; _i < arguments.length; _i++) { - [_i - 0] = arguments[_i]; + [_i] = arguments[_i]; } } diff --git a/tests/baselines/reference/vararg.js b/tests/baselines/reference/vararg.js index 015c8c9957a7e..bd4a79b462631 100644 --- a/tests/baselines/reference/vararg.js +++ b/tests/baselines/reference/vararg.js @@ -65,7 +65,7 @@ var M; C.prototype.fonly = function () { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; + rest[_i] = arguments[_i]; } builder = ""; for (var i = 0; i < rest.length; i++) { From ad9ad8f948bf2cb7c03fc152e81cb8c911990a8d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 17 Nov 2016 11:08:11 -0800 Subject: [PATCH 05/46] Clean up getJSDocTypeForVariableLikeDeclarationFromJSDocComment Yeah, that name is way too long. --- src/compiler/checker.ts | 23 ++--------------------- src/compiler/utilities.ts | 37 ++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b466bf7afb66b..26dd39d6b92f8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3156,30 +3156,11 @@ namespace ts { function getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration): JSDocType { // First, see if this node has an @type annotation on it directly. - const typeTag = getJSDocTypeTag(declaration); + const typeTag = getJSDocTypeTag(declaration, true); if (typeTag && typeTag.typeExpression) { return typeTag.typeExpression.type; } - if (declaration.kind === SyntaxKind.VariableDeclaration && - declaration.parent.kind === SyntaxKind.VariableDeclarationList && - declaration.parent.parent.kind === SyntaxKind.VariableStatement) { - - // @type annotation might have been on the variable statement, try that instead. - const annotation = getJSDocTypeTag(declaration.parent.parent); - if (annotation && annotation.typeExpression) { - return annotation.typeExpression.type; - } - } - else if (declaration.kind === SyntaxKind.Parameter) { - // If it's a parameter, see if the parent has a jsdoc comment with an @param - // annotation. - const paramTag = getCorrespondingJSDocParameterTag(declaration); - if (paramTag && paramTag.typeExpression) { - return paramTag.typeExpression.type; - } - } - return undefined; } @@ -13551,7 +13532,7 @@ namespace ts { // the destructured type into the contained binding elements. function assignBindingElementTypes(node: VariableLikeDeclaration) { if (isBindingPattern(node.name)) { - for (const element of (node.name).elements) { + for (const element of node.name.elements) { if (!isOmittedExpression(element)) { if (element.name.kind === SyntaxKind.Identifier) { getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 158da8e8f0b98..16255dfdde74c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1449,10 +1449,16 @@ namespace ts { }, tags => tags); } - function getJSDocs(node: Node, checkParentVariableStatement: boolean, getDocs: (docs: JSDoc[]) => T[], getTags: (tags: JSDocTag[]) => T[]): T[] { + function getJSDocs(node: Node, + checkParentVariableStatement: boolean, + getDocContent: (docs: JSDoc[]) => T[], + getTagContent: (tags: JSDocTag[]) => T[]): T[] { // TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now... + // This will be hard because it may need to cache parentvariable versions and nonparent versions + // maybe I should eliminate checkParent first ... let result: T[] = undefined; // prepend documentation from parent sources + // TODO: Probably always want checkParent=true, right? if (checkParentVariableStatement) { // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. // /** @@ -1472,11 +1478,11 @@ namespace ts { isVariableOfVariableDeclarationStatement ? node.parent.parent : undefined; if (variableStatementNode) { - result = concatenate(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocContent, getTagContent)); } if (node.kind === SyntaxKind.ModuleDeclaration && node.parent && node.parent.kind === SyntaxKind.ModuleDeclaration) { - result = concatenate(result, getJSDocs(node.parent, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(node.parent, checkParentVariableStatement, getDocContent, getTagContent)); } // Also recognize when the node is the RHS of an assignment expression @@ -1487,33 +1493,34 @@ namespace ts { (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - result = concatenate(result, getJSDocs(parent.parent, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(parent.parent, checkParentVariableStatement, getDocContent, getTagContent)); } const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; if (isPropertyAssignmentExpression) { - result = concatenate(result, getJSDocs(parent, checkParentVariableStatement, getDocs, getTags)); + result = concatenate(result, getJSDocs(parent, checkParentVariableStatement, getDocContent, getTagContent)); } // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { const paramTags = getJSDocParameterTag(node as ParameterDeclaration, checkParentVariableStatement); if (paramTags) { - result = concatenate(result, getTags(paramTags)); + result = concatenate(result, getTagContent(paramTags)); } } } if (isVariableLike(node) && node.initializer) { - result = concatenate(result, getJSDocs(node.initializer, /*checkParentVariableStatement*/ false, getDocs, getTags)); + // TODO: Does this really need to be called for everything? + result = concatenate(result, getJSDocs(node.initializer, /*checkParentVariableStatement*/ false, getDocContent, getTagContent)); } if (node.jsDocComments) { if (result) { - result = concatenate(result, getDocs(node.jsDocComments)); + result = concatenate(result, getDocContent(node.jsDocComments)); } else { - return getDocs(node.jsDocComments); + return getDocContent(node.jsDocComments); } } @@ -1521,6 +1528,7 @@ namespace ts { } function getJSDocParameterTag(param: ParameterDeclaration, checkParentVariableStatement: boolean): JSDocTag[] { + // TODO: getCorrespondingJSDocParameterTag is basically the same as this, except worse. (and typed, singleton return) const func = param.parent as FunctionLikeDeclaration; const tags = getJSDocTags(func, checkParentVariableStatement); if (!param.name) { @@ -1545,16 +1553,19 @@ namespace ts { } } - export function getJSDocTypeTag(node: Node): JSDocTypeTag { - return getJSDocTag(node, SyntaxKind.JSDocTypeTag, /*checkParentVariableStatement*/ false); + export function getJSDocTypeTag(node: Node, checkParentVariableStatement?: boolean): JSDocTypeTag | JSDocParameterTag { + // TODO: Get rid of the second parameter again + // TODO: Don't call getJSDocTag twice. Call a version that allows you to retrieve either kind. + return getJSDocTag(node, SyntaxKind.JSDocTypeTag, checkParentVariableStatement) as JSDocTypeTag || + node.kind === SyntaxKind.Parameter && firstOrUndefined(getJSDocParameterTag(node as ParameterDeclaration, checkParentVariableStatement)) as JSDocParameterTag; } export function getJSDocReturnTag(node: Node): JSDocReturnTag { - return getJSDocTag(node, SyntaxKind.JSDocReturnTag, /*checkParentVariableStatement*/ true); + return getJSDocTag(node, SyntaxKind.JSDocReturnTag, /*checkParentVariableStatement*/ true) as JSDocReturnTag; } export function getJSDocTemplateTag(node: Node): JSDocTemplateTag { - return getJSDocTag(node, SyntaxKind.JSDocTemplateTag, /*checkParentVariableStatement*/ false); + return getJSDocTag(node, SyntaxKind.JSDocTemplateTag, /*checkParentVariableStatement*/ false) as JSDocTemplateTag; } export function getCorrespondingJSDocParameterTag(parameter: ParameterDeclaration): JSDocParameterTag { From 5a05b94fb5e03eed15f6b687f6ec490c5d685aa5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 17 Nov 2016 13:27:57 -0800 Subject: [PATCH 06/46] Clean up getJSDocs 1. Get rid of parent check. 2. Use a couple of nested functions, one of them a recursive worker. --- src/compiler/checker.ts | 27 +++------ src/compiler/utilities.ts | 116 ++++++++++++++++++-------------------- src/services/jsDoc.ts | 2 +- 3 files changed, 66 insertions(+), 79 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 26dd39d6b92f8..53571e265eac3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3148,19 +3148,10 @@ namespace ts { } function getTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration) { - const jsDocType = getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration); - if (jsDocType) { - return getTypeFromTypeNode(jsDocType); + const jsdocType = getJSDocType(declaration); + if (jsdocType) { + return getTypeFromTypeNode(jsdocType); } - } - - function getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration): JSDocType { - // First, see if this node has an @type annotation on it directly. - const typeTag = getJSDocTypeTag(declaration, true); - if (typeTag && typeTag.typeExpression) { - return typeTag.typeExpression.type; - } - return undefined; } @@ -3426,9 +3417,9 @@ namespace ts { declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { // Use JS Doc type if present on parent expression statement if (declaration.flags & NodeFlags.JavaScriptFile) { - const typeTag = getJSDocTypeTag(declaration.parent); - if (typeTag && typeTag.typeExpression) { - return links.type = getTypeFromTypeNode(typeTag.typeExpression.type); + const jsdocType = getJSDocType(declaration.parent); + if (jsdocType) { + return links.type = getTypeFromTypeNode(jsdocType); } } const declaredTypes = map(symbol.declarations, @@ -10296,9 +10287,9 @@ namespace ts { } function getTypeForThisExpressionFromJSDoc(node: Node) { - const typeTag = getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && typeTag.typeExpression.type && typeTag.typeExpression.type.kind === SyntaxKind.JSDocFunctionType) { - const jsDocFunctionType = typeTag.typeExpression.type; + const jsdocType = getJSDocType(node); + if (jsdocType && jsdocType.kind === SyntaxKind.JSDocFunctionType) { + const jsDocFunctionType = jsdocType; if (jsDocFunctionType.parameters.length > 0 && jsDocFunctionType.parameters[0].type.kind === SyntaxKind.JSDocThisType) { return getTypeFromTypeNode(jsDocFunctionType.parameters[0].type); } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 16255dfdde74c..a0ac380711c27 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1416,12 +1416,12 @@ namespace ts { (node).parameters[0].type.kind === SyntaxKind.JSDocConstructorType; } - function getJSDocTag(node: Node, kind: SyntaxKind, checkParentVariableStatement: boolean): JSDocTag { + function getJSDocTag(node: Node, kind: SyntaxKind): JSDocTag { if (!node) { return undefined; } - const jsDocTags = getJSDocTags(node, checkParentVariableStatement); + const jsDocTags = getJSDocTags(node); if (!jsDocTags) { return undefined; } @@ -1433,12 +1433,12 @@ namespace ts { } } - export function getJSDocComments(node: Node, checkParentVariableStatement: boolean): string[] { - return getJSDocs(node, checkParentVariableStatement, docs => map(docs, doc => doc.comment), tags => map(tags, tag => tag.comment)); + export function getJSDocComments(node: Node): string[] { + return getJSDocs(node, docs => map(docs, doc => doc.comment), tags => map(tags, tag => tag.comment)); } - function getJSDocTags(node: Node, checkParentVariableStatement: boolean): JSDocTag[] { - return getJSDocs(node, checkParentVariableStatement, docs => { + function getJSDocTags(node: Node): JSDocTag[] { + return getJSDocs(node, docs => { const result: JSDocTag[] = []; for (const doc of docs) { if (doc.tags) { @@ -1449,17 +1449,16 @@ namespace ts { }, tags => tags); } - function getJSDocs(node: Node, - checkParentVariableStatement: boolean, - getDocContent: (docs: JSDoc[]) => T[], - getTagContent: (tags: JSDocTag[]) => T[]): T[] { - // TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now... - // This will be hard because it may need to cache parentvariable versions and nonparent versions - // maybe I should eliminate checkParent first ... - let result: T[] = undefined; - // prepend documentation from parent sources - // TODO: Probably always want checkParent=true, right? - if (checkParentVariableStatement) { + function getJSDocs(node: Node, getContent: (docs: JSDoc[]) => T[], getContentFromParam: (tags: JSDocTag[]) => T[]): T[] { + return getJSDocsWorker(node); + + function getJSDocsWorker(node: Node) { + // TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now... + // This will be hard because it may need to cache parentvariable versions and nonparent versions + // maybe I should eliminate checkParent first ... + const parent = node.parent; + let result: T[] = undefined; + // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. // /** // * @param {number} name @@ -1467,70 +1466,61 @@ namespace ts { // */ // var x = function(name) { return name.length; } const isInitializerOfVariableDeclarationInStatement = - isVariableLike(node.parent) && - (node.parent).initializer === node && - node.parent.parent.parent.kind === SyntaxKind.VariableStatement; + isVariableLike(parent) && + parent.initializer === node && + parent.parent.parent.kind === SyntaxKind.VariableStatement; const isVariableOfVariableDeclarationStatement = isVariableLike(node) && - node.parent.parent.kind === SyntaxKind.VariableStatement; - + parent.parent.kind === SyntaxKind.VariableStatement; const variableStatementNode = - isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : - isVariableOfVariableDeclarationStatement ? node.parent.parent : - undefined; + isInitializerOfVariableDeclarationInStatement ? parent.parent.parent : + isVariableOfVariableDeclarationStatement ? parent.parent : + undefined; if (variableStatementNode) { - result = concatenate(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocContent, getTagContent)); - } - if (node.kind === SyntaxKind.ModuleDeclaration && - node.parent && node.parent.kind === SyntaxKind.ModuleDeclaration) { - result = concatenate(result, getJSDocs(node.parent, checkParentVariableStatement, getDocContent, getTagContent)); + result = concatenate(result, getJSDocsWorker(variableStatementNode)); } // Also recognize when the node is the RHS of an assignment expression - const parent = node.parent; const isSourceOfAssignmentExpressionStatement = parent && parent.parent && parent.kind === SyntaxKind.BinaryExpression && (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - result = concatenate(result, getJSDocs(parent.parent, checkParentVariableStatement, getDocContent, getTagContent)); + result = concatenate(result, getJSDocsWorker(parent.parent)); } + const isModuleDeclaration = node.kind === SyntaxKind.ModuleDeclaration && + parent && parent.kind === SyntaxKind.ModuleDeclaration; const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; - if (isPropertyAssignmentExpression) { - result = concatenate(result, getJSDocs(parent, checkParentVariableStatement, getDocContent, getTagContent)); + if (isModuleDeclaration || isPropertyAssignmentExpression) { + result = concatenate(result, getJSDocsWorker(parent)); } // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { - const paramTags = getJSDocParameterTag(node as ParameterDeclaration, checkParentVariableStatement); - if (paramTags) { - result = concatenate(result, getTagContent(paramTags)); - } + result = concatenate(result, getContentFromParam(getJSDocParameterTag(node as ParameterDeclaration))); + } + + if (isVariableLike(node) && node.initializer) { + result = concatenate(result, getOwnJSDocs(node.initializer)); } - } - if (isVariableLike(node) && node.initializer) { - // TODO: Does this really need to be called for everything? - result = concatenate(result, getJSDocs(node.initializer, /*checkParentVariableStatement*/ false, getDocContent, getTagContent)); + result = concatenate(result, getOwnJSDocs(node)); + + return result; } - if (node.jsDocComments) { - if (result) { - result = concatenate(result, getDocContent(node.jsDocComments)); - } - else { - return getDocContent(node.jsDocComments); + function getOwnJSDocs(node: Node) { + if (node.jsDocComments) { + return getContent(node.jsDocComments); } } - - return result; } - function getJSDocParameterTag(param: ParameterDeclaration, checkParentVariableStatement: boolean): JSDocTag[] { + function getJSDocParameterTag(param: ParameterDeclaration): JSDocTag[] { // TODO: getCorrespondingJSDocParameterTag is basically the same as this, except worse. (and typed, singleton return) const func = param.parent as FunctionLikeDeclaration; - const tags = getJSDocTags(func, checkParentVariableStatement); + const tags = getJSDocTags(func); if (!param.name) { // this is an anonymous jsdoc param from a `function(type1, type2): type3` specification const i = func.parameters.indexOf(param); @@ -1553,19 +1543,25 @@ namespace ts { } } - export function getJSDocTypeTag(node: Node, checkParentVariableStatement?: boolean): JSDocTypeTag | JSDocParameterTag { - // TODO: Get rid of the second parameter again - // TODO: Don't call getJSDocTag twice. Call a version that allows you to retrieve either kind. - return getJSDocTag(node, SyntaxKind.JSDocTypeTag, checkParentVariableStatement) as JSDocTypeTag || - node.kind === SyntaxKind.Parameter && firstOrUndefined(getJSDocParameterTag(node as ParameterDeclaration, checkParentVariableStatement)) as JSDocParameterTag; + export function getJSDocType(node: Node): JSDocType { + // TODO: If you have to call getparamtag, you really want the first with a typeExpression, not the first one. + let tag: JSDocTypeTag | JSDocParameterTag = getJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag; + if (!tag && node.kind === SyntaxKind.Parameter) { + const paramTags = getJSDocParameterTag(node as ParameterDeclaration); + if (paramTags) { + tag = find(paramTags, tag => !!(tag as JSDocParameterTag).typeExpression) as JSDocParameterTag; + } + } + + return tag && tag.typeExpression && tag.typeExpression.type; } export function getJSDocReturnTag(node: Node): JSDocReturnTag { - return getJSDocTag(node, SyntaxKind.JSDocReturnTag, /*checkParentVariableStatement*/ true) as JSDocReturnTag; + return getJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag; } export function getJSDocTemplateTag(node: Node): JSDocTemplateTag { - return getJSDocTag(node, SyntaxKind.JSDocTemplateTag, /*checkParentVariableStatement*/ false) as JSDocTemplateTag; + return getJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag; } export function getCorrespondingJSDocParameterTag(parameter: ParameterDeclaration): JSDocParameterTag { @@ -1574,7 +1570,7 @@ namespace ts { // annotation. const parameterName = (parameter.name).text; - const jsDocTags = getJSDocTags(parameter.parent, /*checkParentVariableStatement*/ true); + const jsDocTags = getJSDocTags(parameter.parent); if (!jsDocTags) { return undefined; } diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 5e2f5e7b4c906..24e99cf5c7754 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -52,7 +52,7 @@ namespace ts.JsDoc { // from Array - Array and Array const documentationComment = []; forEachUnique(declarations, declaration => { - const comments = getJSDocComments(declaration, /*checkParentVariableStatement*/ true); + const comments = getJSDocComments(declaration); if (!comments) { return; } From ddffe209f9ab8ee31cae9088688e34cadf255da3 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 17 Nov 2016 14:26:38 -0800 Subject: [PATCH 07/46] Clean up getJSDocParameterTag And delete its near-duplicate which was much less correct. The callers that had to switch are slightly more complex and more correct now. --- src/compiler/checker.ts | 17 ++++++------ src/compiler/utilities.ts | 56 +++++++++------------------------------ 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 53571e265eac3..0803814bc14a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4854,15 +4854,16 @@ namespace ts { if (node.type && node.type.kind === SyntaxKind.JSDocOptionalType) { return true; } + const paramTags = getJSDocParameterTag(node); + if (paramTags) { + for (const paramTag of paramTags) { + if (paramTag.isBracketed) { + return true; + } - const paramTag = getCorrespondingJSDocParameterTag(node); - if (paramTag) { - if (paramTag.isBracketed) { - return true; - } - - if (paramTag.typeExpression) { - return paramTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType; + if (paramTag.typeExpression) { + return paramTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType; + } } } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a0ac380711c27..243d4f4c519ff 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1498,16 +1498,14 @@ namespace ts { // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { - result = concatenate(result, getContentFromParam(getJSDocParameterTag(node as ParameterDeclaration))); + result = concatenate(result, getContentFromParam(getJSDocParameterTag(node))); } if (isVariableLike(node) && node.initializer) { result = concatenate(result, getOwnJSDocs(node.initializer)); } - result = concatenate(result, getOwnJSDocs(node)); - - return result; + return concatenate(result, getOwnJSDocs(node)); } function getOwnJSDocs(node: Node) { @@ -1517,24 +1515,23 @@ namespace ts { } } - function getJSDocParameterTag(param: ParameterDeclaration): JSDocTag[] { - // TODO: getCorrespondingJSDocParameterTag is basically the same as this, except worse. (and typed, singleton return) + export function getJSDocParameterTag(param: Node): JSDocParameterTag[] { + if (!isParameter(param)) { + return undefined; + } const func = param.parent as FunctionLikeDeclaration; const tags = getJSDocTags(func); if (!param.name) { // this is an anonymous jsdoc param from a `function(type1, type2): type3` specification const i = func.parameters.indexOf(param); - const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag); + const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag) as JSDocParameterTag[]; if (paramTags && 0 <= i && i < paramTags.length) { return [paramTags[i]]; } } else if (param.name.kind === SyntaxKind.Identifier) { const name = (param.name as Identifier).text; - const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && (tag as JSDocParameterTag).parameterName.text === name); - if (paramTags) { - return paramTags; - } + return filter(tags as JSDocParameterTag[], tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name); } else { // TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines @@ -1544,12 +1541,11 @@ namespace ts { } export function getJSDocType(node: Node): JSDocType { - // TODO: If you have to call getparamtag, you really want the first with a typeExpression, not the first one. let tag: JSDocTypeTag | JSDocParameterTag = getJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag; if (!tag && node.kind === SyntaxKind.Parameter) { - const paramTags = getJSDocParameterTag(node as ParameterDeclaration); + const paramTags = getJSDocParameterTag(node); if (paramTags) { - tag = find(paramTags, tag => !!(tag as JSDocParameterTag).typeExpression) as JSDocParameterTag; + tag = find(paramTags, tag => !!tag.typeExpression); } } @@ -1564,29 +1560,6 @@ namespace ts { return getJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag; } - export function getCorrespondingJSDocParameterTag(parameter: ParameterDeclaration): JSDocParameterTag { - if (parameter.name && parameter.name.kind === SyntaxKind.Identifier) { - // If it's a parameter, see if the parent has a jsdoc comment with an @param - // annotation. - const parameterName = (parameter.name).text; - - const jsDocTags = getJSDocTags(parameter.parent); - if (!jsDocTags) { - return undefined; - } - for (const tag of jsDocTags) { - if (tag.kind === SyntaxKind.JSDocParameterTag) { - const parameterTag = tag; - if (parameterTag.parameterName.text === parameterName) { - return parameterTag; - } - } - } - } - - return undefined; - } - export function hasRestParameter(s: SignatureDeclaration): boolean { return isRestParameter(lastOrUndefined(s.parameters)); } @@ -1597,14 +1570,11 @@ namespace ts { export function isRestParameter(node: ParameterDeclaration) { if (node && (node.flags & NodeFlags.JavaScriptFile)) { - if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) { + if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType || + forEach(getJSDocParameterTag(node), + t => t.typeExpression && t.typeExpression.type.kind === SyntaxKind.JSDocVariadicType)) { return true; } - - const paramTag = getCorrespondingJSDocParameterTag(node); - if (paramTag && paramTag.typeExpression) { - return paramTag.typeExpression.type.kind === SyntaxKind.JSDocVariadicType; - } } return isDeclaredRestParam(node); } From a2b13d05f2bb3e6111d9dfe923bfd3329068ef6b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 17 Nov 2016 15:12:32 -0800 Subject: [PATCH 08/46] pass project name as a constructor parameter (#12333) --- .../unittests/tsserverProjectSystem.ts | 2 + src/server/editorServices.ts | 12 ++-- src/server/project.ts | 59 +++++++++---------- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 32a78a07811a7..ce5bec05b56ed 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1614,6 +1614,7 @@ namespace ts.projectSystem { return; } assert.equal(e.eventName, server.ProjectLanguageServiceStateEvent); + assert.equal(e.data.project.getProjectName(), config.path, "project name"); lastEvent = e; }); session.executeCommand({ @@ -1628,6 +1629,7 @@ namespace ts.projectSystem { assert.isFalse(project.languageServiceEnabled, "Language service enabled"); assert.isTrue(!!lastEvent, "should receive event"); assert.equal(lastEvent.data.project, project, "project name"); + assert.equal(lastEvent.data.project.getProjectName(), config.path, "config path"); assert.isFalse(lastEvent.data.languageServiceEnabled, "Language service state"); host.reloadFS([f1, f2, configWithExclude]); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index f69b5c1154795..6a7cb049296c7 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -470,7 +470,7 @@ namespace ts.server { private onTypeRootFileChanged(project: ConfiguredProject, fileName: string) { this.logger.info(`Type root file ${fileName} changed`); - this.throttledOperations.schedule(project.configFileName + " * type root", /*delay*/ 250, () => { + this.throttledOperations.schedule(project.getConfigFilePath() + " * type root", /*delay*/ 250, () => { project.updateTypes(); this.updateConfiguredProject(project); // TODO: Figure out why this is needed (should be redundant?) this.refreshInferredProjects(); @@ -492,13 +492,13 @@ namespace ts.server { this.logger.info(`Detected source file changes: ${fileName}`); this.throttledOperations.schedule( - project.configFileName, + project.getConfigFilePath(), /*delay*/250, () => this.handleChangeInSourceFileForConfiguredProject(project, fileName)); } private handleChangeInSourceFileForConfiguredProject(project: ConfiguredProject, triggerFile: string) { - const { projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.configFileName); + const { projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath()); this.reportConfigFileDiagnostics(project.getProjectName(), configFileErrors, triggerFile); const newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f))); @@ -520,7 +520,7 @@ namespace ts.server { } private onConfigChangedForConfiguredProject(project: ConfiguredProject) { - this.logger.info(`Config file changed: ${project.configFileName}`); + this.logger.info(`Config file changed: ${project.getConfigFilePath()}`); this.updateConfiguredProject(project); this.refreshInferredProjects(); } @@ -1009,13 +1009,13 @@ namespace ts.server { } private updateConfiguredProject(project: ConfiguredProject) { - if (!this.host.fileExists(project.configFileName)) { + if (!this.host.fileExists(project.getConfigFilePath())) { this.logger.info("Config file deleted"); this.removeProject(project); return; } - const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.configFileName); + const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath()); if (!success) { // reset project settings to default this.updateNonInferredProject(project, [], fileNamePropertyReader, {}, {}, /*compileOnSave*/false, configFileErrors); diff --git a/src/server/project.ts b/src/server/project.ts index 3e5c810e805e5..82ecc6f3644a3 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -229,6 +229,7 @@ namespace ts.server { } constructor( + private readonly projectName: string, readonly projectKind: ProjectKind, readonly projectService: ProjectService, private documentRegistry: ts.DocumentRegistry, @@ -307,7 +308,9 @@ namespace ts.server { this.projectService.onUpdateLanguageServiceStateForProject(this, /*languageServiceEnabled*/ false); } - abstract getProjectName(): string; + getProjectName() { + return this.projectName; + } abstract getProjectRootPath(): string | undefined; abstract getTypingOptions(): TypingOptions; @@ -759,31 +762,27 @@ namespace ts.server { export class InferredProject extends Project { - private static NextId = 1; - - /** - * Unique name that identifies this particular inferred project - */ - private readonly inferredProjectName: string; + private static newName = (() => { + let nextId = 1; + return () => { + const id = nextId; + nextId++; + return makeInferredProjectName(id); + } + })(); // Used to keep track of what directories are watched for this project directoriesWatchedForTsconfig: string[] = []; constructor(projectService: ProjectService, documentRegistry: ts.DocumentRegistry, compilerOptions: CompilerOptions) { - super(ProjectKind.Inferred, + super(InferredProject.newName(), + ProjectKind.Inferred, projectService, documentRegistry, /*files*/ undefined, /*languageServiceEnabled*/ true, compilerOptions, /*compileOnSaveEnabled*/ false); - - this.inferredProjectName = makeInferredProjectName(InferredProject.NextId); - InferredProject.NextId++; - } - - getProjectName() { - return this.inferredProjectName; } getProjectRootPath() { @@ -822,7 +821,7 @@ namespace ts.server { /** Used for configured projects which may have multiple open roots */ openRefCount = 0; - constructor(readonly configFileName: NormalizedPath, + constructor(configFileName: NormalizedPath, projectService: ProjectService, documentRegistry: ts.DocumentRegistry, hasExplicitListOfFiles: boolean, @@ -830,11 +829,15 @@ namespace ts.server { private wildcardDirectories: Map, languageServiceEnabled: boolean, public compileOnSaveEnabled: boolean) { - super(ProjectKind.Configured, projectService, documentRegistry, hasExplicitListOfFiles, languageServiceEnabled, compilerOptions, compileOnSaveEnabled); + super(configFileName, ProjectKind.Configured, projectService, documentRegistry, hasExplicitListOfFiles, languageServiceEnabled, compilerOptions, compileOnSaveEnabled); + } + + getConfigFilePath() { + return this.getProjectName(); } getProjectRootPath() { - return getDirectoryPath(this.configFileName); + return getDirectoryPath(this.getConfigFilePath()); } setProjectErrors(projectErrors: Diagnostic[]) { @@ -849,12 +852,8 @@ namespace ts.server { return this.typingOptions; } - getProjectName() { - return this.configFileName; - } - watchConfigFile(callback: (project: ConfiguredProject) => void) { - this.projectFileWatcher = this.projectService.host.watchFile(this.configFileName, _ => callback(this)); + this.projectFileWatcher = this.projectService.host.watchFile(this.getConfigFilePath(), _ => callback(this)); } watchTypeRoots(callback: (project: ConfiguredProject, path: string) => void) { @@ -872,7 +871,7 @@ namespace ts.server { return; } - const directoryToWatch = getDirectoryPath(this.configFileName); + const directoryToWatch = getDirectoryPath(this.getConfigFilePath()); this.projectService.logger.info(`Add recursive watcher for: ${directoryToWatch}`); this.directoryWatcher = this.projectService.host.watchDirectory(directoryToWatch, path => callback(this, path), /*recursive*/ true); } @@ -881,7 +880,7 @@ namespace ts.server { if (!this.wildcardDirectories) { return; } - const configDirectoryPath = getDirectoryPath(this.configFileName); + const configDirectoryPath = getDirectoryPath(this.getConfigFilePath()); this.directoriesWatchedForWildcards = reduceProperties(this.wildcardDirectories, (watchers, flag, directory) => { if (comparePaths(configDirectoryPath, directory, ".", !this.projectService.host.useCaseSensitiveFileNames) !== Comparison.EqualTo) { const recursive = (flag & WatchDirectoryFlags.Recursive) !== 0; @@ -941,14 +940,14 @@ namespace ts.server { export class ExternalProject extends Project { private typingOptions: TypingOptions; - constructor(readonly externalProjectName: string, + constructor(externalProjectName: string, projectService: ProjectService, documentRegistry: ts.DocumentRegistry, compilerOptions: CompilerOptions, languageServiceEnabled: boolean, public compileOnSaveEnabled: boolean, private readonly projectFilePath?: string) { - super(ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, languageServiceEnabled, compilerOptions, compileOnSaveEnabled); + super(externalProjectName, ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, languageServiceEnabled, compilerOptions, compileOnSaveEnabled); } getProjectRootPath() { @@ -958,7 +957,7 @@ namespace ts.server { // if the projectFilePath is not given, we make the assumption that the project name // is the path of the project file. AS the project name is provided by VS, we need to // normalize slashes before using it as a file name. - return getDirectoryPath(normalizeSlashes(this.externalProjectName)); + return getDirectoryPath(normalizeSlashes(this.getProjectName())); } getTypingOptions() { @@ -992,9 +991,5 @@ namespace ts.server { } this.typingOptions = newTypingOptions; } - - getProjectName() { - return this.externalProjectName; - } } } \ No newline at end of file From e81cfa10d6c670381ee0bb9823632df34bf57ab2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 17 Nov 2016 15:32:16 -0800 Subject: [PATCH 09/46] Clean cache code and streamline other code Cache only uses one property now. getJSDocs isn't generic and doesn't take a function parameter any more. The code is overall easier to read. --- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 83 +++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index af46cb2173cb9..8b648000273df 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -498,6 +498,7 @@ namespace ts { /* @internal */ original?: Node; // The original node if this is an updated node. /* @internal */ startsOnNewLine?: boolean; // Whether a synthesized node should start on a new line (used by transforms). /* @internal */ jsDocComments?: JSDoc[]; // JSDoc for the node, if it has any. + /* @internal */ jsDocCache?: (JSDoc | JSDocParameterTag)[]; // JSDoc for the node, plus JSDoc retrieved from its parents /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 243d4f4c519ff..e5fd8b067b0e4 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1416,49 +1416,42 @@ namespace ts { (node).parameters[0].type.kind === SyntaxKind.JSDocConstructorType; } - function getJSDocTag(node: Node, kind: SyntaxKind): JSDocTag { - if (!node) { - return undefined; - } - - const jsDocTags = getJSDocTags(node); - if (!jsDocTags) { - return undefined; - } - - for (const tag of jsDocTags) { - if (tag.kind === kind) { - return tag; - } - } - } - export function getJSDocComments(node: Node): string[] { - return getJSDocs(node, docs => map(docs, doc => doc.comment), tags => map(tags, tag => tag.comment)); + return map(getJSDocs(node), doc => doc.comment); } - function getJSDocTags(node: Node): JSDocTag[] { - return getJSDocs(node, docs => { + function getJSDocTags(node: Node, kind: SyntaxKind): JSDocTag[] { + const docs = getJSDocs(node); + if (docs) { const result: JSDocTag[] = []; for (const doc of docs) { - if (doc.tags) { - result.push(...doc.tags); + if (doc.kind === SyntaxKind.JSDocParameterTag) { + if (doc.kind === kind) { + result.push(doc as JSDocParameterTag); + } + } + else { + result.push(...filter((doc as JSDoc).tags, tag => tag.kind === kind)); } } return result; - }, tags => tags); + } + } + + function getFirstJSDocTag(node: Node, kind: SyntaxKind): JSDocTag { + return node && firstOrUndefined(getJSDocTags(node, kind)); } - function getJSDocs(node: Node, getContent: (docs: JSDoc[]) => T[], getContentFromParam: (tags: JSDocTag[]) => T[]): T[] { - return getJSDocsWorker(node); + function getJSDocs(node: Node): (JSDoc | JSDocParameterTag)[] { + let cache: (JSDoc | JSDocParameterTag)[] = node.jsDocCache; + if (!cache) { + getJSDocsWorker(node); + node.jsDocCache = cache; + } + return cache; function getJSDocsWorker(node: Node) { - // TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now... - // This will be hard because it may need to cache parentvariable versions and nonparent versions - // maybe I should eliminate checkParent first ... const parent = node.parent; - let result: T[] = undefined; - // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. // /** // * @param {number} name @@ -1476,7 +1469,7 @@ namespace ts { isVariableOfVariableDeclarationStatement ? parent.parent : undefined; if (variableStatementNode) { - result = concatenate(result, getJSDocsWorker(variableStatementNode)); + getJSDocsWorker(variableStatementNode); } // Also recognize when the node is the RHS of an assignment expression @@ -1486,32 +1479,26 @@ namespace ts { (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - result = concatenate(result, getJSDocsWorker(parent.parent)); + getJSDocsWorker(parent.parent); } const isModuleDeclaration = node.kind === SyntaxKind.ModuleDeclaration && parent && parent.kind === SyntaxKind.ModuleDeclaration; const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; if (isModuleDeclaration || isPropertyAssignmentExpression) { - result = concatenate(result, getJSDocsWorker(parent)); + getJSDocsWorker(parent); } // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { - result = concatenate(result, getContentFromParam(getJSDocParameterTag(node))); + cache = concatenate(cache, getJSDocParameterTag(node)); } if (isVariableLike(node) && node.initializer) { - result = concatenate(result, getOwnJSDocs(node.initializer)); + cache = concatenate(cache, node.initializer.jsDocComments); } - return concatenate(result, getOwnJSDocs(node)); - } - - function getOwnJSDocs(node: Node) { - if (node.jsDocComments) { - return getContent(node.jsDocComments); - } + cache = concatenate(cache, node.jsDocComments); } } @@ -1520,18 +1507,18 @@ namespace ts { return undefined; } const func = param.parent as FunctionLikeDeclaration; - const tags = getJSDocTags(func); + const tags = getJSDocTags(func, SyntaxKind.JSDocParameterTag) as JSDocParameterTag[]; if (!param.name) { // this is an anonymous jsdoc param from a `function(type1, type2): type3` specification const i = func.parameters.indexOf(param); - const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag) as JSDocParameterTag[]; + const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag); if (paramTags && 0 <= i && i < paramTags.length) { return [paramTags[i]]; } } else if (param.name.kind === SyntaxKind.Identifier) { const name = (param.name as Identifier).text; - return filter(tags as JSDocParameterTag[], tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name); + return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name); } else { // TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines @@ -1541,7 +1528,7 @@ namespace ts { } export function getJSDocType(node: Node): JSDocType { - let tag: JSDocTypeTag | JSDocParameterTag = getJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag; + let tag: JSDocTypeTag | JSDocParameterTag = getFirstJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag; if (!tag && node.kind === SyntaxKind.Parameter) { const paramTags = getJSDocParameterTag(node); if (paramTags) { @@ -1553,11 +1540,11 @@ namespace ts { } export function getJSDocReturnTag(node: Node): JSDocReturnTag { - return getJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag; + return getFirstJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag; } export function getJSDocTemplateTag(node: Node): JSDocTemplateTag { - return getJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag; + return getFirstJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag; } export function hasRestParameter(s: SignatureDeclaration): boolean { From 2646828198fb468eabec12ebc6a9446d4e9a7cce Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 17 Nov 2016 20:18:00 -0800 Subject: [PATCH 10/46] Type relations for generic mapped types --- src/compiler/checker.ts | 112 ++++++++++++++++++++------- src/compiler/diagnosticMessages.json | 2 +- src/compiler/types.ts | 4 +- 3 files changed, 86 insertions(+), 32 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d25fc8bbbb0d..5ea185556f7ba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -120,6 +120,7 @@ namespace ts { const intersectionTypes = createMap(); const stringLiteralTypes = createMap(); const numericLiteralTypes = createMap(); + const indexedAccessTypes = createMap(); const evolvingArrayTypes: EvolvingArrayType[] = []; const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); @@ -5907,6 +5908,7 @@ namespace ts { function getIndexType(type: Type): Type { return type.flags & TypeFlags.TypeParameter ? getIndexTypeForTypeParameter(type) : + getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(type) : type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringOrNumberType : getIndexInfoOfType(type, IndexKind.Number) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type)]) : getLiteralTypeFromPropertyNames(type); @@ -5920,18 +5922,13 @@ namespace ts { return links.resolvedType; } - function createIndexedAccessType(objectType: Type, indexType: TypeParameter) { + function createIndexedAccessType(objectType: Type, indexType: Type) { const type = createType(TypeFlags.IndexedAccess); type.objectType = objectType; type.indexType = indexType; return type; } - function getIndexedAccessTypeForTypeParameter(objectType: Type, indexType: TypeParameter) { - const indexedAccessTypes = indexType.resolvedIndexedAccessTypes || (indexType.resolvedIndexedAccessTypes = []); - return indexedAccessTypes[objectType.id] || (indexedAccessTypes[objectType.id] = createIndexedAccessType(objectType, indexType)); - } - function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode, cacheSymbol: boolean) { const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; const propName = indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral | TypeFlags.EnumLiteral) ? @@ -5995,13 +5992,41 @@ namespace ts { return unknownType; } + function getIndexedAccessForMappedType(type: MappedType, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) { + const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; + if (accessExpression && isAssignmentTarget(accessExpression) && type.declaration.readonlyToken) { + error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(type)); + return unknownType; + } + const mapper = createUnaryTypeMapper(getTypeParameterFromMappedType(type), indexType); + const templateMapper = type.mapper ? combineTypeMappers(type.mapper, mapper) : mapper; + return addOptionality(instantiateType(getTemplateTypeFromMappedType(type), templateMapper), !!type.declaration.questionToken); + } + function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) { - if (indexType.flags & TypeFlags.TypeParameter) { - if (accessNode && !isTypeAssignableTo(getConstraintOfTypeParameter(indexType) || emptyObjectType, getIndexType(objectType))) { - error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType)); - return unknownType; + if (indexType.flags & TypeFlags.TypeParameter || + objectType.flags & TypeFlags.TypeParameter && indexType.flags & TypeFlags.Index || + isGenericMappedType(objectType)) { + // If either the object type or the index type are type parameters, or if the object type is a mapped + // type with a generic constraint, we are performing a higher-order index access where we cannot + // meaningfully access the properties of the object type. In those cases, we first check that the + // index type is assignable to 'keyof T' for the object type. + if (accessNode) { + const keyType = indexType.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(indexType) || emptyObjectType : indexType; + if (!isTypeAssignableTo(keyType, getIndexType(objectType))) { + error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); + return unknownType; + } } - return getIndexedAccessTypeForTypeParameter(objectType, indexType); + // If the object type is a mapped type { [P in K]: E }, we instantiate E using a mapper that substitutes + // the index type for P. For example, for an index access { [P in K]: Box }[X], we construct the + // type Box. + if (isGenericMappedType(objectType)) { + return getIndexedAccessForMappedType(objectType, indexType, accessNode); + } + // Otherwise we defer the operation by creating an indexed access type. + const id = objectType.id + "," + indexType.id; + return indexedAccessTypes[id] || (indexedAccessTypes[id] = createIndexedAccessType(objectType, indexType)); } const apparentType = getApparentType(objectType); if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) { @@ -7153,12 +7178,24 @@ namespace ts { } if (target.flags & TypeFlags.TypeParameter) { - // Given a type parameter K with a constraint keyof T, a type S is - // assignable to K if S is assignable to keyof T. - const constraint = getConstraintOfTypeParameter(target); - if (constraint && constraint.flags & TypeFlags.Index) { - if (result = isRelatedTo(source, constraint, reportErrors)) { - return result; + // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. + if (getObjectFlags(source) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(source) === getIndexType(target)) { + if (!(source).declaration.questionToken) { + const templateType = getTemplateTypeFromMappedType(source); + const indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); + if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { + return result; + } + } + } + else { + // Given a type parameter K with a constraint keyof T, a type S is + // assignable to K if S is assignable to keyof T. + const constraint = getConstraintOfTypeParameter(target); + if (constraint && constraint.flags & TypeFlags.Index) { + if (result = isRelatedTo(source, constraint, reportErrors)) { + return result; + } } } } @@ -7178,22 +7215,41 @@ namespace ts { } } } + else if (target.flags & TypeFlags.IndexedAccess) { + // if we have indexed access types with identical index types, see if relationship holds for + // the two object types. + if (source.flags & TypeFlags.IndexedAccess && (source).indexType === (target).indexType) { + if (result = isRelatedTo((source).objectType, (target).objectType, reportErrors)) { + return result; + } + } + } if (source.flags & TypeFlags.TypeParameter) { - let constraint = getConstraintOfTypeParameter(source); - - if (!constraint || constraint.flags & TypeFlags.Any) { - constraint = emptyObjectType; + // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. + if (getObjectFlags(target) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(target) === getIndexType(source)) { + const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); + const templateType = getTemplateTypeFromMappedType(target); + if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { + return result; + } } + else { + let constraint = getConstraintOfTypeParameter(source); + + if (!constraint || constraint.flags & TypeFlags.Any) { + constraint = emptyObjectType; + } - // The constraint may need to be further instantiated with its 'this' type. - constraint = getTypeWithThisArgument(constraint, source); + // The constraint may need to be further instantiated with its 'this' type. + constraint = getTypeWithThisArgument(constraint, source); - // Report constraint errors only if the constraint is not the empty object type - const reportConstraintErrors = reportErrors && constraint !== emptyObjectType; - if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { - errorInfo = saveErrorInfo; - return result; + // Report constraint errors only if the constraint is not the empty object type + const reportConstraintErrors = reportErrors && constraint !== emptyObjectType; + if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { + errorInfo = saveErrorInfo; + return result; + } } } else { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2dd4e76f8f44b..68e7bb6e9826d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1731,7 +1731,7 @@ "category": "Error", "code": 2535 }, - "Type '{0}' is not constrained to 'keyof {1}'.": { + "Type '{0}' cannot be used to index type '{1}'.": { "category": "Error", "code": 2536 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b5e3eefbb2d6a..2b8b6fe294e55 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2974,8 +2974,6 @@ namespace ts { /* @internal */ resolvedIndexType: IndexType; /* @internal */ - resolvedIndexedAccessTypes: IndexedAccessType[]; - /* @internal */ isThisType?: boolean; } @@ -2985,7 +2983,7 @@ namespace ts { export interface IndexedAccessType extends Type { objectType: Type; - indexType: TypeParameter; + indexType: Type; } export const enum SignatureKind { From 63387bb5e00d14642c6ca52470297dd5b14c8211 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Nov 2016 06:13:04 -0800 Subject: [PATCH 11/46] Error on circular constraints in mapped types --- src/compiler/checker.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5ea185556f7ba..f6689471cd885 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6059,6 +6059,9 @@ namespace ts { type.aliasSymbol = getAliasSymbolForTypeNode(node); type.aliasTypeArguments = getAliasTypeArgumentsForTypeNode(node); links.resolvedType = type; + // Eagerly resolve the constraint type which forces an error if the constraint type circularly + // references itself through one or more type aliases. + getConstraintTypeFromMappedType(type); } return links.resolvedType; } From 79bdc267456fcf2a7f39013c07c84931f595ac79 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Nov 2016 06:27:24 -0800 Subject: [PATCH 12/46] Accept new baselines --- .../reference/recursiveMappedTypes.errors.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/baselines/reference/recursiveMappedTypes.errors.txt diff --git a/tests/baselines/reference/recursiveMappedTypes.errors.txt b/tests/baselines/reference/recursiveMappedTypes.errors.txt new file mode 100644 index 0000000000000..3dd6a55cf8cdb --- /dev/null +++ b/tests/baselines/reference/recursiveMappedTypes.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(4,6): error TS2456: Type alias 'Recurse' circularly references itself. +tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(8,6): error TS2456: Type alias 'Recurse1' circularly references itself. +tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(12,6): error TS2456: Type alias 'Recurse2' circularly references itself. + + +==== tests/cases/conformance/types/mapped/recursiveMappedTypes.ts (3 errors) ==== + + // Recursive mapped types simply appear empty + + type Recurse = { + ~~~~~~~ +!!! error TS2456: Type alias 'Recurse' circularly references itself. + [K in keyof Recurse]: Recurse[K] + } + + type Recurse1 = { + ~~~~~~~~ +!!! error TS2456: Type alias 'Recurse1' circularly references itself. + [K in keyof Recurse2]: Recurse2[K] + } + + type Recurse2 = { + ~~~~~~~~ +!!! error TS2456: Type alias 'Recurse2' circularly references itself. + [K in keyof Recurse1]: Recurse1[K] + } \ No newline at end of file From 075a3eb98fd5d639732bc6d47ee9c287c8cd6c64 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Nov 2016 06:27:45 -0800 Subject: [PATCH 13/46] Add new tests --- .../mappedTypeRelationships.errors.txt | 165 ++++++++++++++++ .../reference/mappedTypeRelationships.js | 182 ++++++++++++++++++ .../types/mapped/mappedTypeRelationships.ts | 90 +++++++++ 3 files changed, 437 insertions(+) create mode 100644 tests/baselines/reference/mappedTypeRelationships.errors.txt create mode 100644 tests/baselines/reference/mappedTypeRelationships.js create mode 100644 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt new file mode 100644 index 0000000000000..adafbc5f3a722 --- /dev/null +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -0,0 +1,165 @@ +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(12,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(17,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2536: Type 'K' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,12): error TS2536: Type 'K' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(31,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. + Type 'undefined' is not assignable to type 'T[keyof T]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(36,5): error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. + Type 'undefined' is not assignable to type 'T[K]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. + Type 'undefined' is not assignable to type 'T[keyof T]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(42,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. + Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. + Type 'undefined' is not assignable to type 'T[K]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(47,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. + Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(52,5): error TS2542: Index signature in type 'Readonly' only permits reading. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(57,5): error TS2542: Index signature in type 'Readonly' only permits reading. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(62,5): error TS2542: Index signature in type 'Readonly' only permits reading. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(67,5): error TS2542: Index signature in type 'Readonly' only permits reading. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(71,5): error TS2322: Type 'Partial' is not assignable to type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2322: Type 'Partial' is not assignable to type 'T'. + + +==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (18 errors) ==== + + function f1(x: T, k: keyof T) { + return x[k]; + } + + function f2(x: T, k: K) { + return x[k]; + } + + function f3(x: T, y: U, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. + } + + function f4(x: T, y: U, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. + } + + function f5(x: T, y: U, k: keyof U) { + x[k] = y[k]; // Error + ~~~~ +!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. + y[k] = x[k]; // Error + ~~~~ +!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. + } + + function f6(x: T, y: U, k: K) { + x[k] = y[k]; // Error + ~~~~ +!!! error TS2536: Type 'K' cannot be used to index type 'T'. + y[k] = x[k]; // Error + ~~~~ +!!! error TS2536: Type 'K' cannot be used to index type 'T'. + } + + function f10(x: T, y: Partial, k: keyof T) { + x[k] = y[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. + y[k] = x[k]; + } + + function f11(x: T, y: Partial, k: K) { + x[k] = y[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. + y[k] = x[k]; + } + + function f12(x: T, y: Partial, k: keyof T) { + x[k] = y[k]; // Error + ~~~~ +!!! error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. + y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. + } + + function f13(x: T, y: Partial, k: K) { + x[k] = y[k]; // Error + ~~~~ +!!! error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. + y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. + } + + function f20(x: T, y: Readonly, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error + ~~~~ +!!! error TS2542: Index signature in type 'Readonly' only permits reading. + } + + function f21(x: T, y: Readonly, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error + ~~~~ +!!! error TS2542: Index signature in type 'Readonly' only permits reading. + } + + function f22(x: T, y: Readonly, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error + ~~~~ +!!! error TS2542: Index signature in type 'Readonly' only permits reading. + } + + function f23(x: T, y: Readonly, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error + ~~~~ +!!! error TS2542: Index signature in type 'Readonly' only permits reading. + } + + function f30(x: T, y: Partial) { + x = y; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'T'. + y = x; + } + + function f31(x: T, y: Partial) { + x = y; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'T'. + y = x; + } + + function f40(x: T, y: Readonly) { + x = y; + y = x; + } + + function f41(x: T, y: Readonly) { + x = y; + y = x; + } \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeRelationships.js b/tests/baselines/reference/mappedTypeRelationships.js new file mode 100644 index 0000000000000..fcad6973ab7c7 --- /dev/null +++ b/tests/baselines/reference/mappedTypeRelationships.js @@ -0,0 +1,182 @@ +//// [mappedTypeRelationships.ts] + +function f1(x: T, k: keyof T) { + return x[k]; +} + +function f2(x: T, k: K) { + return x[k]; +} + +function f3(x: T, y: U, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f4(x: T, y: U, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f5(x: T, y: U, k: keyof U) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f6(x: T, y: U, k: K) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f10(x: T, y: Partial, k: keyof T) { + x[k] = y[k]; // Error + y[k] = x[k]; +} + +function f11(x: T, y: Partial, k: K) { + x[k] = y[k]; // Error + y[k] = x[k]; +} + +function f12(x: T, y: Partial, k: keyof T) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f13(x: T, y: Partial, k: K) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f20(x: T, y: Readonly, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f21(x: T, y: Readonly, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f22(x: T, y: Readonly, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f23(x: T, y: Readonly, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f30(x: T, y: Partial) { + x = y; // Error + y = x; +} + +function f31(x: T, y: Partial) { + x = y; // Error + y = x; +} + +function f40(x: T, y: Readonly) { + x = y; + y = x; +} + +function f41(x: T, y: Readonly) { + x = y; + y = x; +} + +//// [mappedTypeRelationships.js] +function f1(x, k) { + return x[k]; +} +function f2(x, k) { + return x[k]; +} +function f3(x, y, k) { + x[k] = y[k]; + y[k] = x[k]; // Error +} +function f4(x, y, k) { + x[k] = y[k]; + y[k] = x[k]; // Error +} +function f5(x, y, k) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} +function f6(x, y, k) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} +function f10(x, y, k) { + x[k] = y[k]; // Error + y[k] = x[k]; +} +function f11(x, y, k) { + x[k] = y[k]; // Error + y[k] = x[k]; +} +function f12(x, y, k) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} +function f13(x, y, k) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} +function f20(x, y, k) { + x[k] = y[k]; + y[k] = x[k]; // Error +} +function f21(x, y, k) { + x[k] = y[k]; + y[k] = x[k]; // Error +} +function f22(x, y, k) { + x[k] = y[k]; + y[k] = x[k]; // Error +} +function f23(x, y, k) { + x[k] = y[k]; + y[k] = x[k]; // Error +} +function f30(x, y) { + x = y; // Error + y = x; +} +function f31(x, y) { + x = y; // Error + y = x; +} +function f40(x, y) { + x = y; + y = x; +} +function f41(x, y) { + x = y; + y = x; +} + + +//// [mappedTypeRelationships.d.ts] +declare function f1(x: T, k: keyof T): T[keyof T]; +declare function f2(x: T, k: K): T[K]; +declare function f3(x: T, y: U, k: keyof T): void; +declare function f4(x: T, y: U, k: K): void; +declare function f5(x: T, y: U, k: keyof U): void; +declare function f6(x: T, y: U, k: K): void; +declare function f10(x: T, y: Partial, k: keyof T): void; +declare function f11(x: T, y: Partial, k: K): void; +declare function f12(x: T, y: Partial, k: keyof T): void; +declare function f13(x: T, y: Partial, k: K): void; +declare function f20(x: T, y: Readonly, k: keyof T): void; +declare function f21(x: T, y: Readonly, k: K): void; +declare function f22(x: T, y: Readonly, k: keyof T): void; +declare function f23(x: T, y: Readonly, k: K): void; +declare function f30(x: T, y: Partial): void; +declare function f31(x: T, y: Partial): void; +declare function f40(x: T, y: Readonly): void; +declare function f41(x: T, y: Readonly): void; diff --git a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts new file mode 100644 index 0000000000000..7bc1c1a16703e --- /dev/null +++ b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts @@ -0,0 +1,90 @@ +// @strictNullChecks: true +// @declaration: true + +function f1(x: T, k: keyof T) { + return x[k]; +} + +function f2(x: T, k: K) { + return x[k]; +} + +function f3(x: T, y: U, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f4(x: T, y: U, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f5(x: T, y: U, k: keyof U) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f6(x: T, y: U, k: K) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f10(x: T, y: Partial, k: keyof T) { + x[k] = y[k]; // Error + y[k] = x[k]; +} + +function f11(x: T, y: Partial, k: K) { + x[k] = y[k]; // Error + y[k] = x[k]; +} + +function f12(x: T, y: Partial, k: keyof T) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f13(x: T, y: Partial, k: K) { + x[k] = y[k]; // Error + y[k] = x[k]; // Error +} + +function f20(x: T, y: Readonly, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f21(x: T, y: Readonly, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f22(x: T, y: Readonly, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f23(x: T, y: Readonly, k: K) { + x[k] = y[k]; + y[k] = x[k]; // Error +} + +function f30(x: T, y: Partial) { + x = y; // Error + y = x; +} + +function f31(x: T, y: Partial) { + x = y; // Error + y = x; +} + +function f40(x: T, y: Readonly) { + x = y; + y = x; +} + +function f41(x: T, y: Readonly) { + x = y; + y = x; +} \ No newline at end of file From aa0d2ce2eea83ddc67d45af74bb3e7eb55710d16 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 18 Nov 2016 06:55:03 -0800 Subject: [PATCH 14/46] Make "exclude" default to empty if "include" is present. --- src/compiler/commandLineParser.ts | 4 +-- src/harness/unittests/matchFiles.ts | 48 ++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 26877de43c4da..7a6476818f784 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -951,8 +951,8 @@ namespace ts { errors.push(createCompilerDiagnostic(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude)); } else { - // By default, exclude common package folders and the outDir - excludeSpecs = ["node_modules", "bower_components", "jspm_packages"]; + // If no includes were specified, exclude common package folders and the outDir + excludeSpecs = includeSpecs ? [] : ["node_modules", "bower_components", "jspm_packages"]; const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"]; if (outDir) { diff --git a/src/harness/unittests/matchFiles.ts b/src/harness/unittests/matchFiles.ts index b514ac142c50b..c562fcefe914f 100644 --- a/src/harness/unittests/matchFiles.ts +++ b/src/harness/unittests/matchFiles.ts @@ -89,8 +89,6 @@ namespace ts { "c:/dev/g.min.js/.g/g.ts" ]); - const defaultExcludes = ["node_modules", "bower_components", "jspm_packages"]; - function assertParsed(actual: ts.ParsedCommandLine, expected: ts.ParsedCommandLine): void { assert.deepEqual(actual.fileNames, expected.fileNames); assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); @@ -98,6 +96,23 @@ namespace ts { } describe("matchFiles", () => { + it("with defaults", () => { + const json = {}; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [ + "c:/dev/a.ts", + "c:/dev/b.ts" + ], + wildcardDirectories: { + "c:/dev": ts.WatchDirectoryFlags.Recursive + }, + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); + assertParsed(actual, expected); + }); + describe("with literal file list", () => { it("without exclusions", () => { const json = { @@ -192,7 +207,7 @@ namespace ts { options: {}, errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: {}, @@ -211,7 +226,7 @@ namespace ts { options: {}, errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: {}, @@ -330,7 +345,10 @@ namespace ts { errors: [], fileNames: [ "c:/dev/a.ts", - "c:/dev/b.ts" + "c:/dev/b.ts", + "c:/dev/bower_components/a.ts", + "c:/dev/jspm_packages/a.ts", + "c:/dev/node_modules/a.ts" ], wildcardDirectories: {}, }; @@ -372,8 +390,7 @@ namespace ts { "node_modules/a.ts", "bower_components/a.ts", "jspm_packages/a.ts" - ], - exclude: [] + ] }; const expected: ts.ParsedCommandLine = { options: {}, @@ -530,7 +547,7 @@ namespace ts { options: {}, errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: { @@ -600,7 +617,10 @@ namespace ts { options: {}, errors: [], fileNames: [ - "c:/dev/a.ts" + "c:/dev/a.ts", + "c:/dev/bower_components/a.ts", + "c:/dev/jspm_packages/a.ts", + "c:/dev/node_modules/a.ts" ], wildcardDirectories: { "c:/dev": ts.WatchDirectoryFlags.Recursive @@ -671,7 +691,7 @@ namespace ts { }, errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: { @@ -980,7 +1000,7 @@ namespace ts { errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, "**"), ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: {} @@ -1022,7 +1042,7 @@ namespace ts { errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, "**/x/**/*"), ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: {} @@ -1071,7 +1091,7 @@ namespace ts { errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, "**/../*"), ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: {} @@ -1091,7 +1111,7 @@ namespace ts { errors: [ ts.createCompilerDiagnostic(ts.Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, "**/y/../*"), ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2, - caseInsensitiveTsconfigPath, JSON.stringify(json.include), JSON.stringify(defaultExcludes)) + caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]") ], fileNames: [], wildcardDirectories: {} From cbde25f2298d4d3f5c47ea62877bc9017dedddaf Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 18 Nov 2016 11:01:28 -0800 Subject: [PATCH 15/46] Handle the scenario when heritage clause of interface is not entity name expression Fixes #12291 --- src/compiler/declarationEmitter.ts | 5 ++++- ...hNonEntityNameExpressionHeritage.errors.txt | 9 +++++++++ ...rfaceWithNonEntityNameExpressionHeritage.js | 18 ++++++++++++++++++ ...rfaceWithNonEntityNameExpressionHeritage.ts | 4 ++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.js create mode 100644 tests/cases/compiler/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 7d2f61b6d6f00..a7f24dc632161 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1143,7 +1143,10 @@ namespace ts { const prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; emitTypeParameters(node.typeParameters); - emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); + const interfaceExtendsTypes = filter(getInterfaceBaseTypeNodes(node), base => isEntityNameExpression(base.expression)); + if (interfaceExtendsTypes && interfaceExtendsTypes.length) { + emitHeritageClause(interfaceExtendsTypes, /*isImplementsList*/ false); + } write(" {"); writeLine(); increaseIndent(); diff --git a/tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.errors.txt b/tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.errors.txt new file mode 100644 index 0000000000000..7dc3a70fdc77d --- /dev/null +++ b/tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts(3,25): error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments. + + +==== tests/cases/compiler/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts (1 errors) ==== + + class A { } + interface Class extends (typeof A) { } + ~~~~~~~~~~ +!!! error TS2499: An interface can only extend an identifier/qualified-name with optional type arguments. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.js b/tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.js new file mode 100644 index 0000000000000..ef2d2e479b0db --- /dev/null +++ b/tests/baselines/reference/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.js @@ -0,0 +1,18 @@ +//// [declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts] + +class A { } +interface Class extends (typeof A) { } + +//// [declarationEmitInterfaceWithNonEntityNameExpressionHeritage.js] +var A = (function () { + function A() { + } + return A; +}()); + + +//// [declarationEmitInterfaceWithNonEntityNameExpressionHeritage.d.ts] +declare class A { +} +interface Class { +} diff --git a/tests/cases/compiler/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts b/tests/cases/compiler/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts new file mode 100644 index 0000000000000..762adaad65767 --- /dev/null +++ b/tests/cases/compiler/declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts @@ -0,0 +1,4 @@ +// @declaration: true + +class A { } +interface Class extends (typeof A) { } \ No newline at end of file From 2376e30410e112689acbd3268ee94aa113546c56 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Nov 2016 13:30:56 -0800 Subject: [PATCH 16/46] Support apparent types for T[K] indexed access types --- src/compiler/checker.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f6689471cd885..024c3d4a983c3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4666,13 +4666,22 @@ namespace ts { return type.resolvedApparentType; } + /** + * The apparent type of an indexed access T[K] is the type of T's string index signature, if any. + */ + function getApparentTypeOfIndexedAccess(type: IndexedAccessType) { + return getIndexTypeOfType(getApparentType(type.objectType), IndexKind.String) || type; + } + /** * For a type parameter, return the base constraint of the type parameter. For the string, number, * boolean, and symbol primitive types, return the corresponding object types. Otherwise return the * type itself. Note that the apparent type of a union type is the union type itself. */ function getApparentType(type: Type): Type { - const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(type) : type; + const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(type) : + type.flags & TypeFlags.IndexedAccess ? getApparentTypeOfIndexedAccess(type) : + type; return t.flags & TypeFlags.StringLike ? globalStringType : t.flags & TypeFlags.NumberLike ? globalNumberType : t.flags & TypeFlags.BooleanLike ? globalBooleanType : From a78999078173b6ce5243f77493a86091108ae774 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Nov 2016 13:31:10 -0800 Subject: [PATCH 17/46] Add tests --- .../mappedTypeRelationships.errors.txt | 18 ++++++++++ .../reference/mappedTypeRelationships.js | 34 +++++++++++++++++++ .../types/mapped/mappedTypeRelationships.ts | 18 ++++++++++ 3 files changed, 70 insertions(+) diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index adafbc5f3a722..e8e0371ed9ae2 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -162,4 +162,22 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2 function f41(x: T, y: Readonly) { x = y; y = x; + } + + type Item = { + name: string; + } + + type ItemMap = { + [x: string]: Item; + } + + function f50(obj: T, key: keyof T) { + let item: Item = obj[key]; + return obj[key].name; + } + + function f51(obj: T, key: K) { + let item: Item = obj[key]; + return obj[key].name; } \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeRelationships.js b/tests/baselines/reference/mappedTypeRelationships.js index fcad6973ab7c7..a81ff973da874 100644 --- a/tests/baselines/reference/mappedTypeRelationships.js +++ b/tests/baselines/reference/mappedTypeRelationships.js @@ -86,6 +86,24 @@ function f40(x: T, y: Readonly) { function f41(x: T, y: Readonly) { x = y; y = x; +} + +type Item = { + name: string; +} + +type ItemMap = { + [x: string]: Item; +} + +function f50(obj: T, key: keyof T) { + let item: Item = obj[key]; + return obj[key].name; +} + +function f51(obj: T, key: K) { + let item: Item = obj[key]; + return obj[key].name; } //// [mappedTypeRelationships.js] @@ -159,6 +177,14 @@ function f41(x, y) { x = y; y = x; } +function f50(obj, key) { + var item = obj[key]; + return obj[key].name; +} +function f51(obj, key) { + var item = obj[key]; + return obj[key].name; +} //// [mappedTypeRelationships.d.ts] @@ -180,3 +206,11 @@ declare function f30(x: T, y: Partial): void; declare function f31(x: T, y: Partial): void; declare function f40(x: T, y: Readonly): void; declare function f41(x: T, y: Readonly): void; +declare type Item = { + name: string; +}; +declare type ItemMap = { + [x: string]: Item; +}; +declare function f50(obj: T, key: keyof T): string; +declare function f51(obj: T, key: K): string; diff --git a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts index 7bc1c1a16703e..4af71fbea0804 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts @@ -87,4 +87,22 @@ function f40(x: T, y: Readonly) { function f41(x: T, y: Readonly) { x = y; y = x; +} + +type Item = { + name: string; +} + +type ItemMap = { + [x: string]: Item; +} + +function f50(obj: T, key: keyof T) { + let item: Item = obj[key]; + return obj[key].name; +} + +function f51(obj: T, key: K) { + let item: Item = obj[key]; + return obj[key].name; } \ No newline at end of file From 9945529875ec5346686d92ac5b4fca69f04b73ff Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 18 Nov 2016 13:39:11 -0800 Subject: [PATCH 18/46] use location of config file as initial location for automatic type reference inclusion if possible (#12341) --- src/compiler/program.ts | 3 ++- .../unittests/tsserverProjectSystem.ts | 24 +++++++++++++++++++ .../reference/library-reference-13.trace.json | 2 +- ...mMultipleNodeModulesDirectories.trace.json | 6 ++--- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 041923a885766..73976d5d02e73 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -364,7 +364,8 @@ namespace ts { if (typeReferences.length) { // This containingFilename needs to match with the one used in managed-side - const containingFilename = combinePaths(host.getCurrentDirectory(), "__inferred type names__.ts"); + const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(); + const containingFilename = combinePaths(containingDirectory, "__inferred type names__.ts"); const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename); for (let i = 0; i < typeReferences.length; i++) { processTypeReferenceDirective(typeReferences[i], resolutions[i]); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index ce5bec05b56ed..e9b6ccb788401 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2339,6 +2339,30 @@ namespace ts.projectSystem { projectService.openExternalProject({ rootFiles: toExternalFiles([f1.path, config.path]), options: {}, projectFileName: projectName }); projectService.checkNumberOfProjects({ configuredProjects: 1 }); }); + + it("types should load from config file path if config exists", () => { + const f1 = { + path: "/a/b/app.ts", + content: "let x = 1" + }; + const config = { + path: "/a/b/tsconfig.json", + content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } }) + }; + const node = { + path: "/a/b/node_modules/@types/node/index.d.ts", + content: "declare var process: any" + }; + const cwd = { + path: "/a/c" + }; + debugger; + const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path }); + const projectService = createProjectService(host); + projectService.openClientFile(f1.path); + projectService.checkNumberOfProjects({ configuredProjects: 1 }); + checkProjectActualFiles(projectService.configuredProjects[0], [f1.path, node.path]); + }); }); describe("add the missing module file for inferred project", () => { diff --git a/tests/baselines/reference/library-reference-13.trace.json b/tests/baselines/reference/library-reference-13.trace.json index 86f7a5a505d49..338cefbc47e89 100644 --- a/tests/baselines/reference/library-reference-13.trace.json +++ b/tests/baselines/reference/library-reference-13.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/a/types'. ========", + "======== Resolving type reference directive 'jquery', containing file '/a/__inferred type names__.ts', root directory '/a/types'. ========", "Resolving with primary search path '/a/types'", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json index d5d9e86e33bb6..b38bb7c0acd91 100644 --- a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json +++ b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json @@ -149,19 +149,19 @@ "File '/node_modules/abc/index.js' does not exist.", "File '/node_modules/abc/index.jsx' does not exist.", "======== Module name 'abc' was not resolved. ========", - "======== Resolving type reference directive 'grumpy', containing file '/src/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", + "======== Resolving type reference directive 'grumpy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'", "File '/foo/node_modules/@types/grumpy/package.json' does not exist.", "File '/foo/node_modules/@types/grumpy/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/foo/node_modules/@types/grumpy/index.d.ts', result '/foo/node_modules/@types/grumpy/index.d.ts'", "======== Type reference directive 'grumpy' was successfully resolved to '/foo/node_modules/@types/grumpy/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'sneezy', containing file '/src/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", + "======== Resolving type reference directive 'sneezy', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'", "File '/foo/node_modules/@types/sneezy/package.json' does not exist.", "File '/foo/node_modules/@types/sneezy/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/foo/node_modules/@types/sneezy/index.d.ts', result '/foo/node_modules/@types/sneezy/index.d.ts'", "======== Type reference directive 'sneezy' was successfully resolved to '/foo/node_modules/@types/sneezy/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'dopey', containing file '/src/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", + "======== Resolving type reference directive 'dopey', containing file '/foo/bar/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'", "File '/foo/node_modules/@types/dopey/package.json' does not exist.", "File '/foo/node_modules/@types/dopey/index.d.ts' does not exist.", From 8674d92bdbfac3afc1c711de6f0bcff45675cba9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 13:51:44 -0800 Subject: [PATCH 19/46] Disable evolving types with implicit any That is, without --noImplicitAny --- src/compiler/checker.ts | 6 +- .../baselines/reference/controlFlowLetVar.js | 247 -------------- .../reference/controlFlowLetVar.symbols | 263 --------------- .../reference/controlFlowLetVar.types | 306 ------------------ tests/cases/compiler/controlFlowLetVar.ts | 129 -------- 5 files changed, 4 insertions(+), 947 deletions(-) delete mode 100644 tests/baselines/reference/controlFlowLetVar.js delete mode 100644 tests/baselines/reference/controlFlowLetVar.symbols delete mode 100644 tests/baselines/reference/controlFlowLetVar.types delete mode 100644 tests/cases/compiler/controlFlowLetVar.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d25fc8bbbb0d..e1ef19998d0ba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3238,9 +3238,11 @@ namespace ts { return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } - if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) && + if (compilerOptions.noImplicitAny && + declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && !isInAmbientContext(declaration)) { - // Use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no + // If --noImplicitAny is on, + // use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no // initializer or a 'null' or 'undefined' initializer. if (!(getCombinedNodeFlags(declaration) & NodeFlags.Const) && (!declaration.initializer || isNullOrUndefined(declaration.initializer))) { return autoType; diff --git a/tests/baselines/reference/controlFlowLetVar.js b/tests/baselines/reference/controlFlowLetVar.js deleted file mode 100644 index 24ad95259b126..0000000000000 --- a/tests/baselines/reference/controlFlowLetVar.js +++ /dev/null @@ -1,247 +0,0 @@ -//// [controlFlowLetVar.ts] - -declare let cond: boolean; - -// CFA for 'let' with no type annotation and initializer -function f1() { - let x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'let' with no type annotation and 'undefined' initializer -function f2() { - let x = undefined; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'let' with no type annotation and 'null' initializer -function f3() { - let x = null; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | null -} - -// No CFA for 'let' with with type annotation -function f4() { - let x: any; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // any -} - -// CFA for 'var' with no type annotation and initializer -function f5() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'var' with no type annotation and 'undefined' initializer -function f6() { - var x = undefined; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'var' with no type annotation and 'null' initializer -function f7() { - var x = null; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | null -} - -// No CFA for 'var' with with type annotation -function f8() { - var x: any; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // any -} - -// No CFA for captured outer variables -function f9() { - let x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined - function f() { - const z = x; // any - } -} - -// No CFA for captured outer variables -function f10() { - let x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined - const f = () => { - const z = x; // any - }; -} - -//// [controlFlowLetVar.js] -// CFA for 'let' with no type annotation and initializer -function f1() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | undefined -} -// CFA for 'let' with no type annotation and 'undefined' initializer -function f2() { - var x = undefined; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | undefined -} -// CFA for 'let' with no type annotation and 'null' initializer -function f3() { - var x = null; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | null -} -// No CFA for 'let' with with type annotation -function f4() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // any -} -// CFA for 'var' with no type annotation and initializer -function f5() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | undefined -} -// CFA for 'var' with no type annotation and 'undefined' initializer -function f6() { - var x = undefined; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | undefined -} -// CFA for 'var' with no type annotation and 'null' initializer -function f7() { - var x = null; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | null -} -// No CFA for 'var' with with type annotation -function f8() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // any -} -// No CFA for captured outer variables -function f9() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | undefined - function f() { - var z = x; // any - } -} -// No CFA for captured outer variables -function f10() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - var y = x; // string | number | undefined - var f = function () { - var z = x; // any - }; -} diff --git a/tests/baselines/reference/controlFlowLetVar.symbols b/tests/baselines/reference/controlFlowLetVar.symbols deleted file mode 100644 index f58edd781b780..0000000000000 --- a/tests/baselines/reference/controlFlowLetVar.symbols +++ /dev/null @@ -1,263 +0,0 @@ -=== tests/cases/compiler/controlFlowLetVar.ts === - -declare let cond: boolean; ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - -// CFA for 'let' with no type annotation and initializer -function f1() { ->f1 : Symbol(f1, Decl(controlFlowLetVar.ts, 1, 26)) - - let x; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) - } - const y = x; // string | number | undefined ->y : Symbol(y, Decl(controlFlowLetVar.ts, 12, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) -} - -// CFA for 'let' with no type annotation and 'undefined' initializer -function f2() { ->f2 : Symbol(f2, Decl(controlFlowLetVar.ts, 13, 1)) - - let x = undefined; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) ->undefined : Symbol(undefined) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) - } - const y = x; // string | number | undefined ->y : Symbol(y, Decl(controlFlowLetVar.ts, 24, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) -} - -// CFA for 'let' with no type annotation and 'null' initializer -function f3() { ->f3 : Symbol(f3, Decl(controlFlowLetVar.ts, 25, 1)) - - let x = null; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) - } - const y = x; // string | number | null ->y : Symbol(y, Decl(controlFlowLetVar.ts, 36, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) -} - -// No CFA for 'let' with with type annotation -function f4() { ->f4 : Symbol(f4, Decl(controlFlowLetVar.ts, 37, 1)) - - let x: any; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) - } - const y = x; // any ->y : Symbol(y, Decl(controlFlowLetVar.ts, 48, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) -} - -// CFA for 'var' with no type annotation and initializer -function f5() { ->f5 : Symbol(f5, Decl(controlFlowLetVar.ts, 49, 1)) - - var x; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) - } - const y = x; // string | number | undefined ->y : Symbol(y, Decl(controlFlowLetVar.ts, 60, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) -} - -// CFA for 'var' with no type annotation and 'undefined' initializer -function f6() { ->f6 : Symbol(f6, Decl(controlFlowLetVar.ts, 61, 1)) - - var x = undefined; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) ->undefined : Symbol(undefined) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) - } - const y = x; // string | number | undefined ->y : Symbol(y, Decl(controlFlowLetVar.ts, 72, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) -} - -// CFA for 'var' with no type annotation and 'null' initializer -function f7() { ->f7 : Symbol(f7, Decl(controlFlowLetVar.ts, 73, 1)) - - var x = null; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) - } - const y = x; // string | number | null ->y : Symbol(y, Decl(controlFlowLetVar.ts, 84, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) -} - -// No CFA for 'var' with with type annotation -function f8() { ->f8 : Symbol(f8, Decl(controlFlowLetVar.ts, 85, 1)) - - var x: any; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) - } - const y = x; // any ->y : Symbol(y, Decl(controlFlowLetVar.ts, 96, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) -} - -// No CFA for captured outer variables -function f9() { ->f9 : Symbol(f9, Decl(controlFlowLetVar.ts, 97, 1)) - - let x; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) - } - const y = x; // string | number | undefined ->y : Symbol(y, Decl(controlFlowLetVar.ts, 108, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) - - function f() { ->f : Symbol(f, Decl(controlFlowLetVar.ts, 108, 16)) - - const z = x; // any ->z : Symbol(z, Decl(controlFlowLetVar.ts, 110, 13)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) - } -} - -// No CFA for captured outer variables -function f10() { ->f10 : Symbol(f10, Decl(controlFlowLetVar.ts, 112, 1)) - - let x; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) - - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = 1; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) - } - if (cond) { ->cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) - - x = "hello"; ->x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) - } - const y = x; // string | number | undefined ->y : Symbol(y, Decl(controlFlowLetVar.ts, 123, 9)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) - - const f = () => { ->f : Symbol(f, Decl(controlFlowLetVar.ts, 124, 9)) - - const z = x; // any ->z : Symbol(z, Decl(controlFlowLetVar.ts, 125, 13)) ->x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) - - }; -} diff --git a/tests/baselines/reference/controlFlowLetVar.types b/tests/baselines/reference/controlFlowLetVar.types deleted file mode 100644 index 09f0ea8348887..0000000000000 --- a/tests/baselines/reference/controlFlowLetVar.types +++ /dev/null @@ -1,306 +0,0 @@ -=== tests/cases/compiler/controlFlowLetVar.ts === - -declare let cond: boolean; ->cond : boolean - -// CFA for 'let' with no type annotation and initializer -function f1() { ->f1 : () => void - - let x; ->x : any - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | undefined ->y : string | number | undefined ->x : string | number | undefined -} - -// CFA for 'let' with no type annotation and 'undefined' initializer -function f2() { ->f2 : () => void - - let x = undefined; ->x : any ->undefined : undefined - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | undefined ->y : string | number | undefined ->x : string | number | undefined -} - -// CFA for 'let' with no type annotation and 'null' initializer -function f3() { ->f3 : () => void - - let x = null; ->x : any ->null : null - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | null ->y : string | number | null ->x : string | number | null -} - -// No CFA for 'let' with with type annotation -function f4() { ->f4 : () => void - - let x: any; ->x : any - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // any ->y : any ->x : any -} - -// CFA for 'var' with no type annotation and initializer -function f5() { ->f5 : () => void - - var x; ->x : any - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | undefined ->y : string | number | undefined ->x : string | number | undefined -} - -// CFA for 'var' with no type annotation and 'undefined' initializer -function f6() { ->f6 : () => void - - var x = undefined; ->x : any ->undefined : undefined - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | undefined ->y : string | number | undefined ->x : string | number | undefined -} - -// CFA for 'var' with no type annotation and 'null' initializer -function f7() { ->f7 : () => void - - var x = null; ->x : any ->null : null - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | null ->y : string | number | null ->x : string | number | null -} - -// No CFA for 'var' with with type annotation -function f8() { ->f8 : () => void - - var x: any; ->x : any - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // any ->y : any ->x : any -} - -// No CFA for captured outer variables -function f9() { ->f9 : () => void - - let x; ->x : any - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | undefined ->y : string | number | undefined ->x : string | number | undefined - - function f() { ->f : () => void - - const z = x; // any ->z : any ->x : any - } -} - -// No CFA for captured outer variables -function f10() { ->f10 : () => void - - let x; ->x : any - - if (cond) { ->cond : boolean - - x = 1; ->x = 1 : 1 ->x : any ->1 : 1 - } - if (cond) { ->cond : boolean - - x = "hello"; ->x = "hello" : "hello" ->x : any ->"hello" : "hello" - } - const y = x; // string | number | undefined ->y : string | number | undefined ->x : string | number | undefined - - const f = () => { ->f : () => void ->() => { const z = x; // any } : () => void - - const z = x; // any ->z : any ->x : any - - }; -} diff --git a/tests/cases/compiler/controlFlowLetVar.ts b/tests/cases/compiler/controlFlowLetVar.ts deleted file mode 100644 index a56a3382642de..0000000000000 --- a/tests/cases/compiler/controlFlowLetVar.ts +++ /dev/null @@ -1,129 +0,0 @@ -// @strictNullChecks: true - -declare let cond: boolean; - -// CFA for 'let' with no type annotation and initializer -function f1() { - let x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'let' with no type annotation and 'undefined' initializer -function f2() { - let x = undefined; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'let' with no type annotation and 'null' initializer -function f3() { - let x = null; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | null -} - -// No CFA for 'let' with with type annotation -function f4() { - let x: any; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // any -} - -// CFA for 'var' with no type annotation and initializer -function f5() { - var x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'var' with no type annotation and 'undefined' initializer -function f6() { - var x = undefined; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined -} - -// CFA for 'var' with no type annotation and 'null' initializer -function f7() { - var x = null; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | null -} - -// No CFA for 'var' with with type annotation -function f8() { - var x: any; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // any -} - -// No CFA for captured outer variables -function f9() { - let x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined - function f() { - const z = x; // any - } -} - -// No CFA for captured outer variables -function f10() { - let x; - if (cond) { - x = 1; - } - if (cond) { - x = "hello"; - } - const y = x; // string | number | undefined - const f = () => { - const z = x; // any - }; -} \ No newline at end of file From a4d584f14a02f18aacc5cd1cff52ee6aabba33d0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 13:53:18 -0800 Subject: [PATCH 20/46] Update baselines to have no evolving types --- .../asiPreventsParsingAsTypeAlias01.types | 6 +- .../reference/assignEveryTypeToAny.types | 4 +- .../reference/capturedLetConstInLoop3.types | 24 ++-- .../capturedLetConstInLoop3_ES6.types | 24 ++-- .../reference/capturedLetConstInLoop4.types | 32 ++--- .../capturedLetConstInLoop4_ES6.types | 32 ++--- .../reference/capturedLetConstInLoop9.types | 2 +- .../capturedLetConstInLoop9_ES6.types | 2 +- .../commentsArgumentsOfCallExpression2.types | 6 +- .../compoundAssignmentLHSIsReference.types | 36 ++--- .../constraintSatisfactionWithAny.types | 30 ++-- .../reference/controlFlowCaching.errors.txt | 128 ------------------ .../reference/downlevelLetConst14.types | 10 +- .../reference/downlevelLetConst15.types | 10 +- tests/baselines/reference/forIn.errors.txt | 11 +- .../initializePropertiesWithRenamedLet.types | 14 +- .../baselines/reference/json.stringify.types | 2 +- .../reference/localClassesInLoop.types | 12 +- .../reference/localClassesInLoop_ES6.types | 12 +- .../nestedBlockScopedBindings3.types | 40 +++--- .../nestedBlockScopedBindings4.types | 56 ++++---- .../nestedBlockScopedBindings6.types | 24 ++-- tests/baselines/reference/null.types | 6 +- .../objectLiteralShorthandProperties.types | 18 +-- .../objectLiteralShorthandPropertiesES6.types | 18 +-- .../reference/objectSpreadNoTransform.types | 2 +- .../parserAmbiguityWithBinaryOperator1.types | 12 +- .../parserAmbiguityWithBinaryOperator2.types | 12 +- .../parserAmbiguityWithBinaryOperator3.types | 12 +- .../reference/parserForStatement2.errors.txt | 8 +- .../reference/parserharness.errors.txt | 11 +- .../protoAsIndexInIndexExpression.types | 4 +- .../strictNullChecksNoWidening.types | 6 +- tests/baselines/reference/tsxEmit1.types | 16 +-- tests/baselines/reference/tsxEmit2.types | 28 ++-- tests/baselines/reference/tsxReactEmit1.types | 16 +-- tests/baselines/reference/tsxReactEmit2.types | 28 ++-- tests/baselines/reference/tsxReactEmit5.types | 2 +- tests/baselines/reference/tsxReactEmit6.types | 2 +- ...WithUndefinedCallResolutionData.errors.txt | 15 -- tests/baselines/reference/typedArrays.types | 36 ++--- .../reference/unusedSwitchStatment.errors.txt | 5 +- 42 files changed, 302 insertions(+), 472 deletions(-) delete mode 100644 tests/baselines/reference/controlFlowCaching.errors.txt delete mode 100644 tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types index c2d9213ca6045..7492a698e3a26 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -10,10 +10,10 @@ var Foo; >Foo : any type ->type : undefined +>type : any Foo = string; ->Foo = string : undefined +>Foo = string : any >Foo : any ->string : undefined +>string : any diff --git a/tests/baselines/reference/assignEveryTypeToAny.types b/tests/baselines/reference/assignEveryTypeToAny.types index fd1dccefae059..cfc24e1da65b8 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.types +++ b/tests/baselines/reference/assignEveryTypeToAny.types @@ -59,9 +59,9 @@ var e = undefined; >undefined : undefined x = e; ->x = e : undefined +>x = e : any >x : any ->e : undefined +>e : any var e2: typeof undefined; >e2 : any diff --git a/tests/baselines/reference/capturedLetConstInLoop3.types b/tests/baselines/reference/capturedLetConstInLoop3.types index 1fee8db67c4a4..8ce40ab5f1b5e 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3.types +++ b/tests/baselines/reference/capturedLetConstInLoop3.types @@ -179,7 +179,7 @@ function foo3(x) { use(v); >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } function foo4(x) { @@ -283,8 +283,8 @@ function foo6(x) { >y : any var v = x; ->v : undefined ->x : undefined +>v : any +>x : any (function() { return x + y + v }); >(function() { return x + y + v }) : () => any @@ -293,7 +293,7 @@ function foo6(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any (() => x + y + v); >(() => x + y + v) : () => any @@ -302,13 +302,13 @@ function foo6(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any } use(v) >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } function foo7(x) { @@ -321,8 +321,8 @@ function foo7(x) { >y : any var v = x; ->v : undefined ->x : undefined +>v : any +>x : any (function() { return x + y + v }); >(function() { return x + y + v }) : () => any @@ -331,7 +331,7 @@ function foo7(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any (() => x + y + v); >(() => x + y + v) : () => any @@ -340,7 +340,7 @@ function foo7(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any } while (1 === 1); >1 === 1 : boolean @@ -350,7 +350,7 @@ function foo7(x) { use(v); >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } @@ -574,7 +574,7 @@ function foo3_c(x) { use(v); >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } function foo4_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop3_ES6.types b/tests/baselines/reference/capturedLetConstInLoop3_ES6.types index bfd279afdff15..9c11ae625744c 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop3_ES6.types @@ -180,7 +180,7 @@ function foo3(x) { use(v); >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } function foo4(x) { @@ -284,8 +284,8 @@ function foo6(x) { >y : any var v = x; ->v : undefined ->x : undefined +>v : any +>x : any (function() { return x + y + v }); >(function() { return x + y + v }) : () => any @@ -294,7 +294,7 @@ function foo6(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any (() => x + y + v); >(() => x + y + v) : () => any @@ -303,13 +303,13 @@ function foo6(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any } use(v) >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } function foo7(x) { @@ -322,8 +322,8 @@ function foo7(x) { >y : any var v = x; ->v : undefined ->x : undefined +>v : any +>x : any (function() { return x + y + v }); >(function() { return x + y + v }) : () => any @@ -332,7 +332,7 @@ function foo7(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any (() => x + y + v); >(() => x + y + v) : () => any @@ -341,7 +341,7 @@ function foo7(x) { >x + y : any >x : any >y : any ->v : undefined +>v : any } while (1 === 1); >1 === 1 : boolean @@ -351,7 +351,7 @@ function foo7(x) { use(v); >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } @@ -575,7 +575,7 @@ function foo3_c(x) { use(v); >use(v) : any >use : (a: any) => any ->v : undefined +>v : any } function foo4_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop4.types b/tests/baselines/reference/capturedLetConstInLoop4.types index 0feff77f60429..2c48463adec70 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.types +++ b/tests/baselines/reference/capturedLetConstInLoop4.types @@ -17,12 +17,12 @@ export function exportedFoo() { >v0 : any >v00 : string >v1 : number ->v2 : undefined ->v3 : undefined +>v2 : any +>v3 : any >v4 : number >v5 : number ->v6 : undefined ->v7 : undefined +>v6 : any +>v7 : any >v8 : number } @@ -103,15 +103,15 @@ while (1 === 1) { >x : any var v2 = x; ->v2 : undefined ->x : undefined +>v2 : any +>x : any (function() { return x + v2}); >(function() { return x + v2}) : () => any >function() { return x + v2} : () => any >x + v2 : any >x : any ->v2 : undefined +>v2 : any (() => x); >(() => x) : () => any @@ -124,15 +124,15 @@ do { >x : any var v3 = x; ->v3 : undefined ->x : undefined +>v3 : any +>x : any (function() { return x + v3}); >(function() { return x + v3}) : () => any >function() { return x + v3} : () => any >x + v3 : any >x : any ->v3 : undefined +>v3 : any (() => x); >(() => x) : () => any @@ -216,8 +216,8 @@ while (1 === 1) { >y : any var v6 = x; ->v6 : undefined ->x : undefined +>v6 : any +>x : any (function() { return x + y + v6}); >(function() { return x + y + v6}) : () => any @@ -226,7 +226,7 @@ while (1 === 1) { >x + y : any >x : any >y : any ->v6 : undefined +>v6 : any (() => x + y); >(() => x + y) : () => any @@ -242,8 +242,8 @@ do { >y : any var v7 = x; ->v7 : undefined ->x : undefined +>v7 : any +>x : any (function() { return x + y + v7}); >(function() { return x + y + v7}) : () => any @@ -252,7 +252,7 @@ do { >x + y : any >x : any >y : any ->v7 : undefined +>v7 : any (() => x + y); >(() => x + y) : () => any diff --git a/tests/baselines/reference/capturedLetConstInLoop4_ES6.types b/tests/baselines/reference/capturedLetConstInLoop4_ES6.types index 301a6ef90f1c3..32af60f24e4f8 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop4_ES6.types @@ -17,12 +17,12 @@ export function exportedFoo() { >v0 : any >v00 : string >v1 : number ->v2 : undefined ->v3 : undefined +>v2 : any +>v3 : any >v4 : number >v5 : number ->v6 : undefined ->v7 : undefined +>v6 : any +>v7 : any >v8 : number } @@ -103,15 +103,15 @@ while (1 === 1) { >x : any var v2 = x; ->v2 : undefined ->x : undefined +>v2 : any +>x : any (function() { return x + v2}); >(function() { return x + v2}) : () => any >function() { return x + v2} : () => any >x + v2 : any >x : any ->v2 : undefined +>v2 : any (() => x); >(() => x) : () => any @@ -124,15 +124,15 @@ do { >x : any var v3 = x; ->v3 : undefined ->x : undefined +>v3 : any +>x : any (function() { return x + v3}); >(function() { return x + v3}) : () => any >function() { return x + v3} : () => any >x + v3 : any >x : any ->v3 : undefined +>v3 : any (() => x); >(() => x) : () => any @@ -216,8 +216,8 @@ while (1 === 1) { >y : any var v6 = x; ->v6 : undefined ->x : undefined +>v6 : any +>x : any (function() { return x + y + v6}); >(function() { return x + y + v6}) : () => any @@ -226,7 +226,7 @@ while (1 === 1) { >x + y : any >x : any >y : any ->v6 : undefined +>v6 : any (() => x + y); >(() => x + y) : () => any @@ -242,8 +242,8 @@ do { >y : any var v7 = x; ->v7 : undefined ->x : undefined +>v7 : any +>x : any (function() { return x + y + v7}); >(function() { return x + y + v7}) : () => any @@ -252,7 +252,7 @@ do { >x + y : any >x : any >y : any ->v7 : undefined +>v7 : any (() => x + y); >(() => x + y) : () => any diff --git a/tests/baselines/reference/capturedLetConstInLoop9.types b/tests/baselines/reference/capturedLetConstInLoop9.types index 453176a40c92f..486697b8d8409 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.types +++ b/tests/baselines/reference/capturedLetConstInLoop9.types @@ -39,7 +39,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : undefined +>x : any case 1: >1 : 1 diff --git a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types index df118279f3022..be4457315eeeb 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types @@ -40,7 +40,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : undefined +>x : any case 1: >1 : 1 diff --git a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types index bc6bf5baa90ad..7ec29aa912430 100644 --- a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types +++ b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types @@ -17,7 +17,7 @@ foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b); >1 : 1 >2 : 2 >a + b : any ->a : undefined +>a : any >b : any foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); @@ -26,7 +26,7 @@ foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); >function () { } : () => void >() => { } : () => void >a + /*e3*/ b : any ->a : undefined +>a : any >b : any foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); @@ -36,7 +36,7 @@ foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); >() => { } : () => void >(a + b) : any >a + b : any ->a : undefined +>a : any >b : any foo( diff --git a/tests/baselines/reference/compoundAssignmentLHSIsReference.types b/tests/baselines/reference/compoundAssignmentLHSIsReference.types index a82eb17426d5a..4816307f50895 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundAssignmentLHSIsReference.types @@ -9,12 +9,12 @@ var x1: number; x1 *= value; >x1 *= value : number >x1 : number ->value : undefined +>value : any x1 += value; ->x1 += value : number +>x1 += value : any >x1 : number ->value : undefined +>value : any function fn1(x2: number) { >fn1 : (x2: number) => void @@ -41,41 +41,41 @@ x3.a *= value; >x3.a : number >x3 : { a: number; } >a : number ->value : undefined +>value : any x3.a += value; ->x3.a += value : number +>x3.a += value : any >x3.a : number >x3 : { a: number; } >a : number ->value : undefined +>value : any x3['a'] *= value; >x3['a'] *= value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : undefined +>value : any x3['a'] += value; ->x3['a'] += value : number +>x3['a'] += value : any >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : undefined +>value : any // parentheses, the contained expression is reference (x1) *= value; >(x1) *= value : number >(x1) : number >x1 : number ->value : undefined +>value : any (x1) += value; ->(x1) += value : number +>(x1) += value : any >(x1) : number >x1 : number ->value : undefined +>value : any function fn2(x4: number) { >fn2 : (x4: number) => void @@ -100,15 +100,15 @@ function fn2(x4: number) { >x3.a : number >x3 : { a: number; } >a : number ->value : undefined +>value : any (x3.a) += value; ->(x3.a) += value : number +>(x3.a) += value : any >(x3.a) : number >x3.a : number >x3 : { a: number; } >a : number ->value : undefined +>value : any (x3['a']) *= value; >(x3['a']) *= value : number @@ -116,13 +116,13 @@ function fn2(x4: number) { >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : undefined +>value : any (x3['a']) += value; ->(x3['a']) += value : number +>(x3['a']) += value : any >(x3['a']) : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : undefined +>value : any diff --git a/tests/baselines/reference/constraintSatisfactionWithAny.types b/tests/baselines/reference/constraintSatisfactionWithAny.types index 2f9c755328826..f3363fe1a9006 100644 --- a/tests/baselines/reference/constraintSatisfactionWithAny.types +++ b/tests/baselines/reference/constraintSatisfactionWithAny.types @@ -35,20 +35,20 @@ var a; >a : any foo(a); ->foo(a) : undefined +>foo(a) : any >foo : (x: T) => T ->a : undefined +>a : any foo2(a); ->foo2(a) : undefined +>foo2(a) : any >foo2 : (x: T) => T ->a : undefined +>a : any //foo3(a); foo4(a); ->foo4(a) : undefined +>foo4(a) : any >foo4 : (x: T) => void>(x: T) => T ->a : undefined +>a : any var b: number; >b : number @@ -84,10 +84,10 @@ class C { } var c1 = new C(a); ->c1 : C ->new C(a) : C +>c1 : C +>new C(a) : C >C : typeof C ->a : undefined +>a : any var c2 = new C(b); >c2 : C @@ -106,10 +106,10 @@ class C2 { } var c3 = new C2(a); ->c3 : C2 ->new C2(a) : C2 +>c3 : C2 +>new C2(a) : C2 >C2 : typeof C2 ->a : undefined +>a : any var c4 = new C2(b); >c4 : C2 @@ -138,10 +138,10 @@ class C4(x:T) => T> { } var c7 = new C4(a); ->c7 : C4 ->new C4(a) : C4 +>c7 : C4 +>new C4(a) : C4 >C4 : typeof C4 ->a : undefined +>a : any var c8 = new C4(b); >c8 : C4 diff --git a/tests/baselines/reference/controlFlowCaching.errors.txt b/tests/baselines/reference/controlFlowCaching.errors.txt deleted file mode 100644 index 1086695313e84..0000000000000 --- a/tests/baselines/reference/controlFlowCaching.errors.txt +++ /dev/null @@ -1,128 +0,0 @@ -tests/cases/compiler/controlFlowCaching.ts(38,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(38,29): error TS2339: Property 'y' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(40,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(40,29): error TS2339: Property 'x' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(42,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(42,29): error TS2339: Property 'y' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(44,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(44,29): error TS2339: Property 'y' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(46,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(46,29): error TS2339: Property 'y' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(48,17): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(48,29): error TS2339: Property 'y' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(53,5): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(53,14): error TS2339: Property 'y' does not exist on type 'never'. -tests/cases/compiler/controlFlowCaching.ts(55,14): error TS2678: Type '"start"' is not comparable to type 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(58,14): error TS2678: Type '"end"' is not comparable to type 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(61,14): error TS2678: Type '"middle"' is not comparable to type 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(62,13): error TS2532: Object is possibly 'undefined'. -tests/cases/compiler/controlFlowCaching.ts(62,25): error TS2339: Property 'y' does not exist on type 'never'. - - -==== tests/cases/compiler/controlFlowCaching.ts (19 errors) ==== - - // Repro for #8401 - - function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { - var isRtl = this._isRtl(); // chart mirroring - // prepare variable - var o = this.opt, ta = this.chart.theme.axis, position = o.position, - leftBottom = position !== "rightOrTop", rotation = o.rotation % 360, - start, stop, titlePos, titleRotation = 0, titleOffset, axisVector, tickVector, anchorOffset, labelOffset, labelAlign, - labelGap = this.chart.theme.axis.tick.labelGap, - taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font), - taTitleFont = o.titleFont || (ta.title && ta.title.font), - taFontColor = o.fontColor || (ta.majorTick && ta.majorTick.fontColor) || (ta.tick && ta.tick.fontColor) || "black", - taTitleFontColor = o.titleFontColor || (ta.title && ta.title.fontColor) || "black", - taTitleGap = (o.titleGap == 0) ? 0 : o.titleGap || (ta.title && ta.title.gap) || 15, - taTitleOrientation = o.titleOrientation || (ta.title && ta.title.orientation) || "axis", - taMajorTick = this.chart.theme.getTick("major", o), - taMinorTick = this.chart.theme.getTick("minor", o), - taMicroTick = this.chart.theme.getTick("micro", o), - - taStroke = "stroke" in o ? o.stroke : ta.stroke, - size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0, - cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), - sinr = Math.abs(Math.sin(rotation * Math.PI / 180)), - tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0; - if (rotation < 0) { - rotation += 360; - } - var cachedLabelW = this._getMaxLabelSize(); - cachedLabelW = cachedLabelW && cachedLabelW.majLabelW; - titleOffset = size * cosr + (cachedLabelW || 0) * sinr + labelGap + Math.max(taMajorTick.length > 0 ? taMajorTick.length : 0, - taMinorTick.length > 0 ? taMinorTick.length : 0) + - tsize + taTitleGap; - axisVector = { x: isRtl ? -1 : 1, y: 0 }; // chart mirroring - switch (rotation) { - default: - if (rotation < (90 - centerAnchorLimit)) { - labelOffset.y = leftBottom ? size : 0; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - } else if (rotation < (90 + centerAnchorLimit)) { - labelOffset.x = -size * 0.4; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'x' does not exist on type 'never'. - } else if (rotation < 180) { - labelOffset.y = leftBottom ? 0 : -size; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - } else if (rotation < (270 - centerAnchorLimit)) { - labelOffset.y = leftBottom ? 0 : -size; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - } else if (rotation < (270 + centerAnchorLimit)) { - labelOffset.y = leftBottom ? size * 0.4 : 0; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - } else { - labelOffset.y = leftBottom ? size : 0; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - } - } - - titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 180 : 0; - titlePos.y = offsets.t - titleOffset + (titleRotation ? 0 : tsize); - ~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - switch (labelAlign) { - case "start": - ~~~~~~~ -!!! error TS2678: Type '"start"' is not comparable to type 'undefined'. - labelAlign = "end"; - break; - case "end": - ~~~~~ -!!! error TS2678: Type '"end"' is not comparable to type 'undefined'. - labelAlign = "start"; - break; - case "middle": - ~~~~~~~~ -!!! error TS2678: Type '"middle"' is not comparable to type 'undefined'. - labelOffset.y -= size; - ~~~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. - ~ -!!! error TS2339: Property 'y' does not exist on type 'never'. - break; - } - - let _ = rotation; - } - \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst14.types b/tests/baselines/reference/downlevelLetConst14.types index 493c17b97cd01..29c87e76cce5c 100644 --- a/tests/baselines/reference/downlevelLetConst14.types +++ b/tests/baselines/reference/downlevelLetConst14.types @@ -77,22 +77,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : undefined +>z0 : any use(z1); >use(z1) : any >use : (a: any) => any ->z1 : undefined +>z1 : any use(z2); >use(z2) : any >use : (a: any) => any ->z2 : undefined +>z2 : any use(z3); >use(z3) : any >use : (a: any) => any ->z3 : undefined +>z3 : any var z6; >z6 : any @@ -149,7 +149,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : undefined +>z6 : any var z = false; >z : boolean diff --git a/tests/baselines/reference/downlevelLetConst15.types b/tests/baselines/reference/downlevelLetConst15.types index 6d224b6310d66..9e58c6488214a 100644 --- a/tests/baselines/reference/downlevelLetConst15.types +++ b/tests/baselines/reference/downlevelLetConst15.types @@ -83,22 +83,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : undefined +>z0 : any use(z1); >use(z1) : any >use : (a: any) => any ->z1 : undefined +>z1 : any use(z2); >use(z2) : any >use : (a: any) => any ->z2 : undefined +>z2 : any use(z3); >use(z3) : any >use : (a: any) => any ->z3 : undefined +>z3 : any var z6; >z6 : any @@ -155,7 +155,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : undefined +>z6 : any var z = false; >z : boolean diff --git a/tests/baselines/reference/forIn.errors.txt b/tests/baselines/reference/forIn.errors.txt index a7dd629698a02..ccc1423f1aa65 100644 --- a/tests/baselines/reference/forIn.errors.txt +++ b/tests/baselines/reference/forIn.errors.txt @@ -1,24 +1,17 @@ tests/cases/compiler/forIn.ts(2,10): error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. -tests/cases/compiler/forIn.ts(2,22): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. -tests/cases/compiler/forIn.ts(7,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. -tests/cases/compiler/forIn.ts(18,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'. -==== tests/cases/compiler/forIn.ts (5 errors) ==== +==== tests/cases/compiler/forIn.ts (2 errors) ==== var arr = null; for (var i:number in arr) { // error ~ !!! error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. - ~~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. var x1 = arr[i]; var y1 = arr[i]; } for (var j in arr) { // ok - ~~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. var x2 = arr[j]; var y2 = arr[j]; } @@ -30,8 +23,6 @@ tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'. } for (var l in arr) { - ~~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. // error in the body k[l] = 1; ~ diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.types b/tests/baselines/reference/initializePropertiesWithRenamedLet.types index d6937da8983f8..65ea68059a7b9 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.types +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.types @@ -10,15 +10,15 @@ if (true) { >x0 : any var obj1 = { x0: x0 }; ->obj1 : { x0: undefined; } ->{ x0: x0 } : { x0: undefined; } ->x0 : undefined ->x0 : undefined +>obj1 : { x0: any; } +>{ x0: x0 } : { x0: any; } +>x0 : any +>x0 : any var obj2 = { x0 }; ->obj2 : { x0: undefined; } ->{ x0 } : { x0: undefined; } ->x0 : undefined +>obj2 : { x0: any; } +>{ x0 } : { x0: any; } +>x0 : any } var x, y, z; diff --git a/tests/baselines/reference/json.stringify.types b/tests/baselines/reference/json.stringify.types index 8ff84885d9c33..b063b06d8d07c 100644 --- a/tests/baselines/reference/json.stringify.types +++ b/tests/baselines/reference/json.stringify.types @@ -1,7 +1,7 @@ === tests/cases/compiler/json.stringify.ts === var value = null; ->value : any +>value : null >null : null JSON.stringify(value, undefined, 2); diff --git a/tests/baselines/reference/localClassesInLoop.types b/tests/baselines/reference/localClassesInLoop.types index 8805044589807..c88bfc0435d0c 100644 --- a/tests/baselines/reference/localClassesInLoop.types +++ b/tests/baselines/reference/localClassesInLoop.types @@ -35,12 +35,12 @@ use(data[0]() === data[1]()); >use(data[0]() === data[1]()) : any >use : (a: any) => any >data[0]() === data[1]() : boolean ->data[0]() : typeof C ->data[0] : () => typeof C ->data : (() => typeof C)[] +>data[0]() : any +>data[0] : any +>data : any[] >0 : 0 ->data[1]() : typeof C ->data[1] : () => typeof C ->data : (() => typeof C)[] +>data[1]() : any +>data[1] : any +>data : any[] >1 : 1 diff --git a/tests/baselines/reference/localClassesInLoop_ES6.types b/tests/baselines/reference/localClassesInLoop_ES6.types index 390f4b8b1ddb2..9d487f6c60051 100644 --- a/tests/baselines/reference/localClassesInLoop_ES6.types +++ b/tests/baselines/reference/localClassesInLoop_ES6.types @@ -36,12 +36,12 @@ use(data[0]() === data[1]()); >use(data[0]() === data[1]()) : any >use : (a: any) => any >data[0]() === data[1]() : boolean ->data[0]() : typeof C ->data[0] : () => typeof C ->data : (() => typeof C)[] +>data[0]() : any +>data[0] : any +>data : any[] >0 : 0 ->data[1]() : typeof C ->data[1] : () => typeof C ->data : (() => typeof C)[] +>data[1]() : any +>data[1] : any +>data : any[] >1 : 1 diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types index ca13759bac4f2..0de8123861d5b 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.types +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -31,7 +31,7 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : undefined +>x : any >1 : 1 () => x; @@ -53,24 +53,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 } } @@ -82,14 +82,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 } switch (1) { @@ -111,14 +111,14 @@ function a4() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 () => x; @@ -145,14 +145,14 @@ function a5() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.types b/tests/baselines/reference/nestedBlockScopedBindings4.types index 9e0147f25f7fb..65b5d73db9d85 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.types +++ b/tests/baselines/reference/nestedBlockScopedBindings4.types @@ -5,24 +5,24 @@ function a0() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 } } @@ -33,14 +33,14 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 () => x; @@ -51,10 +51,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 } } @@ -65,24 +65,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 () => x; @@ -98,14 +98,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : number +>x : any >1 : 1 x = x + 1; ->x = x + 1 : number +>x = x + 1 : any +>x : any +>x + 1 : any >x : any ->x + 1 : number ->x : number >1 : 1 () => x; @@ -116,10 +116,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types index bf38f46d50804..865dea31e377e 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.types +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -18,10 +18,10 @@ function a0() { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 } } @@ -49,10 +49,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 } } @@ -76,10 +76,10 @@ function a2() { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 () => x; @@ -111,10 +111,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : number +>x = x + 2 : any +>x : any +>x + 2 : any >x : any ->x + 2 : number ->x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/null.types b/tests/baselines/reference/null.types index ab5ae728dea39..35c084c3cbf40 100644 --- a/tests/baselines/reference/null.types +++ b/tests/baselines/reference/null.types @@ -5,10 +5,10 @@ var x=null; >null : null var y=3+x; ->y : number ->3+x : number +>y : any +>3+x : any >3 : 3 ->x : null +>x : any var z=3+null; >z : number diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index 168fcc07af784..4f4482906aa50 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: undefined; } ->{ a} : { a: undefined; } +>x1 : { a: any; } +>{ a} : { a: any; } a ->a : undefined +>a : any }; var x2 = { ->x2 : { a: undefined; } ->{ a,} : { a: undefined; } +>x2 : { a: any; } +>{ a,} : { a: any; } a, ->a : undefined +>a : any } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : undefined +>b : any c, ->c : undefined +>c : any d() { }, >d : () => void diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 80cbe304040b9..1565be04625b3 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: undefined; } ->{ a} : { a: undefined; } +>x1 : { a: any; } +>{ a} : { a: any; } a ->a : undefined +>a : any }; var x2 = { ->x2 : { a: undefined; } ->{ a,} : { a: undefined; } +>x2 : { a: any; } +>{ a,} : { a: any; } a, ->a : undefined +>a : any } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : undefined +>b : any c, ->c : undefined +>c : any d() { }, >d : () => void diff --git a/tests/baselines/reference/objectSpreadNoTransform.types b/tests/baselines/reference/objectSpreadNoTransform.types index ae89a3a7993e3..c7cfdf8f00606 100644 --- a/tests/baselines/reference/objectSpreadNoTransform.types +++ b/tests/baselines/reference/objectSpreadNoTransform.types @@ -25,6 +25,6 @@ var rest; >{ b, ...rest } = o : { a: string; b: string; x: number; } >{ b, ...rest } : any >b : any ->rest : undefined +>rest : any >o : { a: string; b: string; x: number; } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types index ca7d65c9c3495..234375fb46dda 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -10,12 +10,12 @@ function f1() { if (a < b || b > (c + 1)) { } >a < b || b > (c + 1) : boolean >a < b : boolean ->a : undefined ->b : undefined +>a : any +>b : any >b > (c + 1) : boolean ->b : undefined ->(c + 1) : number ->c + 1 : number ->c : undefined +>b : any +>(c + 1) : any +>c + 1 : any +>c : any >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types index f4c1c2ac69080..ed3b4b903bb86 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -10,12 +10,12 @@ function f() { if (a < b && b > (c + 1)) { } >a < b && b > (c + 1) : boolean >a < b : boolean ->a : undefined ->b : undefined +>a : any +>b : any >b > (c + 1) : boolean ->b : undefined ->(c + 1) : number ->c + 1 : number ->c : undefined +>b : any +>(c + 1) : any +>c + 1 : any +>c : any >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types index b112965634236..61601d8bdf653 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -10,13 +10,13 @@ function f() { if (a < b && b < (c + 1)) { } >a < b && b < (c + 1) : boolean >a < b : boolean ->a : undefined ->b : undefined +>a : any +>b : any >b < (c + 1) : boolean ->b : undefined ->(c + 1) : number ->c + 1 : number ->c : undefined +>b : any +>(c + 1) : any +>c + 1 : any +>c : any >1 : 1 } diff --git a/tests/baselines/reference/parserForStatement2.errors.txt b/tests/baselines/reference/parserForStatement2.errors.txt index 68ab999b657a5..59d6dd6dec8f4 100644 --- a/tests/baselines/reference/parserForStatement2.errors.txt +++ b/tests/baselines/reference/parserForStatement2.errors.txt @@ -1,17 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,13): error TS2538: Type 'undefined' cannot be used as an index type. -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,20): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,30): error TS2304: Cannot find name 'd'. -==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts (1 errors) ==== var a; var b = []; var c; for (a in b[c] = b[c] || [], d) { - ~ -!!! error TS2538: Type 'undefined' cannot be used as an index type. - ~ -!!! error TS2538: Type 'undefined' cannot be used as an index type. ~ !!! error TS2304: Cannot find name 'd'. diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index 90ac8e0e76027..d3d0c4056a1d5 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -25,9 +25,6 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(776,42): e tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(781,23): error TS2503: Cannot find namespace 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(794,49): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(795,49): error TS2304: Cannot find name 'TypeScript'. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(820,31): error TS2339: Property 'length' does not exist on type 'null'. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(976,28): error TS2339: Property 'length' does not exist on type 'null'. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(977,82): error TS2339: Property 'join' does not exist on type 'null'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,53): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,89): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,115): error TS2503: Cannot find namespace 'TypeScript'. @@ -113,7 +110,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68): tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'. -==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (113 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ==== // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -988,8 +985,6 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): }) return errors.length === 0; - ~~~~~~ -!!! error TS2339: Property 'length' does not exist on type 'null'. } public isSubtypeOf(other: Type) { @@ -1146,11 +1141,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): }) if (errors.length > 0) - ~~~~~~ -!!! error TS2339: Property 'length' does not exist on type 'null'. throw new Error("Type definition contains errors: " + errors.join(",")); - ~~~~ -!!! error TS2339: Property 'join' does not exist on type 'null'. var matchingIdentifiers: Type[] = []; diff --git a/tests/baselines/reference/protoAsIndexInIndexExpression.types b/tests/baselines/reference/protoAsIndexInIndexExpression.types index 6d1374d1f78f7..b761aa2c7a70a 100644 --- a/tests/baselines/reference/protoAsIndexInIndexExpression.types +++ b/tests/baselines/reference/protoAsIndexInIndexExpression.types @@ -14,11 +14,11 @@ var WorkspacePrototype = { } }; WorkspacePrototype['__proto__'] = EntityPrototype; ->WorkspacePrototype['__proto__'] = EntityPrototype : undefined +>WorkspacePrototype['__proto__'] = EntityPrototype : any >WorkspacePrototype['__proto__'] : any >WorkspacePrototype : { serialize: () => any; } >'__proto__' : "___proto__" ->EntityPrototype : undefined +>EntityPrototype : any var o = { >o : { "__proto__": number; } diff --git a/tests/baselines/reference/strictNullChecksNoWidening.types b/tests/baselines/reference/strictNullChecksNoWidening.types index e24797850ee2b..a544f9cef94a4 100644 --- a/tests/baselines/reference/strictNullChecksNoWidening.types +++ b/tests/baselines/reference/strictNullChecksNoWidening.types @@ -1,11 +1,11 @@ === tests/cases/conformance/types/typeRelationships/widenedTypes/strictNullChecksNoWidening.ts === var a1 = null; ->a1 : any +>a1 : null >null : null var a2 = undefined; ->a2 : any +>a2 : undefined >undefined : undefined var a3 = void 0; @@ -14,7 +14,7 @@ var a3 = void 0; >0 : 0 var b1 = []; ->b1 : any[] +>b1 : never[] >[] : never[] var b2 = [,]; diff --git a/tests/baselines/reference/tsxEmit1.types b/tests/baselines/reference/tsxEmit1.types index c3ca7a2b1b015..84f00b4758ab6 100644 --- a/tests/baselines/reference/tsxEmit1.types +++ b/tests/baselines/reference/tsxEmit1.types @@ -61,7 +61,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : undefined +>p : any >y : any var openClosed1 =
; @@ -82,7 +82,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : undefined +>p : any >div : any var openClosed4 =
{p < p}
; @@ -91,8 +91,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : undefined ->p : undefined +>p : any +>p : any >div : any var openClosed5 =
{p > p}
; @@ -101,8 +101,8 @@ var openClosed5 =
{p > p}
; >div : any >n : any >p > p : boolean ->p : undefined ->p : undefined +>p : any +>p : any >div : any class SomeClass { @@ -180,7 +180,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : undefined +>p : any >div : any var whitespace3 =
@@ -189,7 +189,7 @@ var whitespace3 =
>div : any {p} ->p : undefined +>p : any
; >div : any diff --git a/tests/baselines/reference/tsxEmit2.types b/tests/baselines/reference/tsxEmit2.types index d306dc9ffe057..5b267d8b80262 100644 --- a/tests/baselines/reference/tsxEmit2.types +++ b/tests/baselines/reference/tsxEmit2.types @@ -22,16 +22,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : undefined ->p2 : undefined +>p1 : any +>p2 : any >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : undefined ->p2 : undefined +>p1 : any +>p2 : any >div : any var spreads3 =
{p2}
; @@ -39,19 +39,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : undefined ->p1 : undefined ->p2 : undefined +>p3 : any +>p1 : any +>p2 : any >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : undefined +>p1 : any >x : any ->p3 : undefined ->p2 : undefined +>p3 : any +>p2 : any >div : any var spreads5 =
{p2}
; @@ -59,10 +59,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : undefined ->p1 : undefined +>p2 : any +>p1 : any >y : any ->p3 : undefined ->p2 : undefined +>p3 : any +>p2 : any >div : any diff --git a/tests/baselines/reference/tsxReactEmit1.types b/tests/baselines/reference/tsxReactEmit1.types index b2cb2f73eba05..8eb14e9196365 100644 --- a/tests/baselines/reference/tsxReactEmit1.types +++ b/tests/baselines/reference/tsxReactEmit1.types @@ -63,7 +63,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : undefined +>p : any >y : any >b : any @@ -85,7 +85,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : undefined +>p : any >div : any var openClosed4 =
{p < p}
; @@ -94,8 +94,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : undefined ->p : undefined +>p : any +>p : any >div : any var openClosed5 =
{p > p}
; @@ -105,8 +105,8 @@ var openClosed5 =
{p > p}
; >n : any >b : any >p > p : boolean ->p : undefined ->p : undefined +>p : any +>p : any >div : any class SomeClass { @@ -184,7 +184,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : undefined +>p : any >div : any var whitespace3 =
@@ -193,7 +193,7 @@ var whitespace3 =
>div : any {p} ->p : undefined +>p : any
; >div : any diff --git a/tests/baselines/reference/tsxReactEmit2.types b/tests/baselines/reference/tsxReactEmit2.types index b05764e996fc3..928eeecadfac9 100644 --- a/tests/baselines/reference/tsxReactEmit2.types +++ b/tests/baselines/reference/tsxReactEmit2.types @@ -24,16 +24,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : undefined ->p2 : undefined +>p1 : any +>p2 : any >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : undefined ->p2 : undefined +>p1 : any +>p2 : any >div : any var spreads3 =
{p2}
; @@ -41,19 +41,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : undefined ->p1 : undefined ->p2 : undefined +>p3 : any +>p1 : any +>p2 : any >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : undefined +>p1 : any >x : any ->p3 : undefined ->p2 : undefined +>p3 : any +>p2 : any >div : any var spreads5 =
{p2}
; @@ -61,10 +61,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : undefined ->p1 : undefined +>p2 : any +>p1 : any >y : any ->p3 : undefined ->p2 : undefined +>p3 : any +>p2 : any >div : any diff --git a/tests/baselines/reference/tsxReactEmit5.types b/tests/baselines/reference/tsxReactEmit5.types index 73e7e6ff3913e..fb1c6594f3035 100644 --- a/tests/baselines/reference/tsxReactEmit5.types +++ b/tests/baselines/reference/tsxReactEmit5.types @@ -32,6 +32,6 @@ var spread1 =
; >
: JSX.Element >div : any >x : any ->foo : undefined +>foo : any >y : any diff --git a/tests/baselines/reference/tsxReactEmit6.types b/tests/baselines/reference/tsxReactEmit6.types index ae56de052cc44..b8a307eb9d765 100644 --- a/tests/baselines/reference/tsxReactEmit6.types +++ b/tests/baselines/reference/tsxReactEmit6.types @@ -35,7 +35,7 @@ namespace M { >
: JSX.Element >div : any >x : any ->foo : undefined +>foo : any >y : any // Quotes diff --git a/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt deleted file mode 100644 index 3f8cdf56c3dbc..0000000000000 --- a/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/file1.ts(3,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. - - -==== tests/cases/compiler/file2.ts (0 errors) ==== - import f = require('./file1'); - f.foo(); - -==== tests/cases/compiler/file1.ts (1 errors) ==== - export function foo() { - var classes = undefined; - return new classes(null); - ~~~~~~~~~~~~~~~~~ -!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. - } - \ No newline at end of file diff --git a/tests/baselines/reference/typedArrays.types b/tests/baselines/reference/typedArrays.types index cd2103f646122..444d6a74e4303 100644 --- a/tests/baselines/reference/typedArrays.types +++ b/tests/baselines/reference/typedArrays.types @@ -1,7 +1,7 @@ === tests/cases/compiler/typedArrays.ts === function CreateTypedArrayTypes() { ->CreateTypedArrayTypes : () => (Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | Uint8ClampedArrayConstructor)[] +>CreateTypedArrayTypes : () => any[] var typedArrays = []; >typedArrays : any[] @@ -71,11 +71,11 @@ function CreateTypedArrayTypes() { >Uint8ClampedArray : Uint8ClampedArrayConstructor return typedArrays; ->typedArrays : (Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | Uint8ClampedArrayConstructor)[] +>typedArrays : any[] } function CreateTypedArrayInstancesFromLength(obj: number) { ->CreateTypedArrayInstancesFromLength : (obj: number) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateTypedArrayInstancesFromLength : (obj: number) => any[] >obj : number var typedArrays = []; @@ -164,11 +164,11 @@ function CreateTypedArrayInstancesFromLength(obj: number) { >obj : number return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateTypedArrayInstancesFromArray(obj: number[]) { ->CreateTypedArrayInstancesFromArray : (obj: number[]) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateTypedArrayInstancesFromArray : (obj: number[]) => any[] >obj : number[] var typedArrays = []; @@ -257,11 +257,11 @@ function CreateTypedArrayInstancesFromArray(obj: number[]) { >obj : number[] return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateIntegerTypedArraysFromArray2(obj:number[]) { ->CreateIntegerTypedArraysFromArray2 : (obj: number[]) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateIntegerTypedArraysFromArray2 : (obj: number[]) => any[] >obj : number[] var typedArrays = []; @@ -368,11 +368,11 @@ function CreateIntegerTypedArraysFromArray2(obj:number[]) { >obj : number[] return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateIntegerTypedArraysFromArrayLike(obj:ArrayLike) { ->CreateIntegerTypedArraysFromArrayLike : (obj: ArrayLike) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateIntegerTypedArraysFromArrayLike : (obj: ArrayLike) => any[] >obj : ArrayLike >ArrayLike : ArrayLike @@ -480,11 +480,11 @@ function CreateIntegerTypedArraysFromArrayLike(obj:ArrayLike) { >obj : ArrayLike return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateTypedArraysOf(obj) { ->CreateTypedArraysOf : (obj: any) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateTypedArraysOf : (obj: any) => any[] >obj : any var typedArrays = []; @@ -600,11 +600,11 @@ function CreateTypedArraysOf(obj) { >obj : any return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateTypedArraysOf2() { ->CreateTypedArraysOf2 : () => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateTypedArraysOf2 : () => any[] var typedArrays = []; >typedArrays : any[] @@ -737,11 +737,11 @@ function CreateTypedArraysOf2() { >4 : 4 return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateTypedArraysFromMapFn(obj:ArrayLike, mapFn: (n:number, v:number)=> number) { ->CreateTypedArraysFromMapFn : (obj: ArrayLike, mapFn: (n: number, v: number) => number) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateTypedArraysFromMapFn : (obj: ArrayLike, mapFn: (n: number, v: number) => number) => any[] >obj : ArrayLike >ArrayLike : ArrayLike >mapFn : (n: number, v: number) => number @@ -861,11 +861,11 @@ function CreateTypedArraysFromMapFn(obj:ArrayLike, mapFn: (n:number, v:n >mapFn : (n: number, v: number) => number return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } function CreateTypedArraysFromThisObj(obj:ArrayLike, mapFn: (n:number, v:number)=> number, thisArg: {}) { ->CreateTypedArraysFromThisObj : (obj: ArrayLike, mapFn: (n: number, v: number) => number, thisArg: {}) => (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>CreateTypedArraysFromThisObj : (obj: ArrayLike, mapFn: (n: number, v: number) => number, thisArg: {}) => any[] >obj : ArrayLike >ArrayLike : ArrayLike >mapFn : (n: number, v: number) => number @@ -995,5 +995,5 @@ function CreateTypedArraysFromThisObj(obj:ArrayLike, mapFn: (n:number, v >thisArg : {} return typedArrays; ->typedArrays : (Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array)[] +>typedArrays : any[] } diff --git a/tests/baselines/reference/unusedSwitchStatment.errors.txt b/tests/baselines/reference/unusedSwitchStatment.errors.txt index 591e9deca7a21..a22c252f60d52 100644 --- a/tests/baselines/reference/unusedSwitchStatment.errors.txt +++ b/tests/baselines/reference/unusedSwitchStatment.errors.txt @@ -4,10 +4,9 @@ tests/cases/compiler/unusedSwitchStatment.ts(7,15): error TS6133: 'c' is declare tests/cases/compiler/unusedSwitchStatment.ts(10,13): error TS6133: 'z' is declared but never used. tests/cases/compiler/unusedSwitchStatment.ts(15,10): error TS2678: Type '0' is not comparable to type '2'. tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is not comparable to type '2'. -tests/cases/compiler/unusedSwitchStatment.ts(18,9): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/unusedSwitchStatment.ts (7 errors) ==== +==== tests/cases/compiler/unusedSwitchStatment.ts (6 errors) ==== switch (1) { case 0: @@ -38,6 +37,4 @@ tests/cases/compiler/unusedSwitchStatment.ts(18,9): error TS2356: An arithmetic ~ !!! error TS2678: Type '1' is not comparable to type '2'. x++; - ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. } \ No newline at end of file From aa556502f334d58ceec8d0b8b6abf11c8c83fd8d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 18 Nov 2016 14:01:59 -0800 Subject: [PATCH 21/46] Handle when type alias's type parameter extends type that wont get emitted in .d.ts Fixes #12326 --- src/compiler/declarationEmitter.ts | 4 ++++ src/compiler/diagnosticMessages.json | 4 ++++ ...liasTypeParameterExtendingUnknownSymbol.errors.txt | 11 +++++++++++ ...mitTypeAliasTypeParameterExtendingUnknownSymbol.js | 5 +++++ ...mitTypeAliasTypeParameterExtendingUnknownSymbol.ts | 3 +++ 5 files changed, 27 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.errors.txt create mode 100644 tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.js create mode 100644 tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index a7f24dc632161..99a26a13920e1 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1037,6 +1037,10 @@ namespace ts { diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; + case SyntaxKind.TypeAliasDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_type_alias_has_or_is_using_private_name_1; + break; + default: Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2dd4e76f8f44b..dc3341a5a6f89 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2276,6 +2276,10 @@ "category": "Error", "code": 4082 }, + "Type parameter '{0}' of exported type alias has or is using private name '{1}'.": { + "category": "Error", + "code": 4083 + }, "Conflicting definitions for '{0}' found at '{1}' and '{2}'. Consider installing a specific version of this library to resolve the conflict.": { "category": "Message", "code": 4090 diff --git a/tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.errors.txt b/tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.errors.txt new file mode 100644 index 0000000000000..af0bcad47fa32 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts(2,18): error TS2304: Cannot find name 'Unknown'. +tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts(2,18): error TS4083: Type parameter 'T' of exported type alias has or is using private name 'Unknown'. + + +==== tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts (2 errors) ==== + + type A = {} + ~~~~~~~ +!!! error TS2304: Cannot find name 'Unknown'. + ~~~~~~~ +!!! error TS4083: Type parameter 'T' of exported type alias has or is using private name 'Unknown'. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.js b/tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.js new file mode 100644 index 0000000000000..eedcc6eccb7cc --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.js @@ -0,0 +1,5 @@ +//// [declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts] + +type A = {} + +//// [declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.js] diff --git a/tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts b/tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts new file mode 100644 index 0000000000000..07b3b01e1cfc1 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts @@ -0,0 +1,3 @@ +// @declaration: true + +type A = {} \ No newline at end of file From 7750fe1a7c85b9c278a575fe1e3e491ef6ce239d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 14:13:56 -0800 Subject: [PATCH 22/46] Always enable evolving types in Javascript files --- src/compiler/checker.ts | 4 +- .../reference/controlFlowJavascript.js | 203 ++++++++++++++ .../reference/controlFlowJavascript.symbols | 216 +++++++++++++++ .../reference/controlFlowJavascript.types | 252 ++++++++++++++++++ tests/cases/compiler/controlFlowJavascript.ts | 107 ++++++++ 5 files changed, 780 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/controlFlowJavascript.js create mode 100644 tests/baselines/reference/controlFlowJavascript.symbols create mode 100644 tests/baselines/reference/controlFlowJavascript.types create mode 100644 tests/cases/compiler/controlFlowJavascript.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e1ef19998d0ba..6928ce73d311b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3238,10 +3238,10 @@ namespace ts { return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } - if (compilerOptions.noImplicitAny && + if ((compilerOptions.noImplicitAny || declaration.flags & NodeFlags.JavaScriptFile) && declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && !isInAmbientContext(declaration)) { - // If --noImplicitAny is on, + // If --noImplicitAny is on or the declaration is in a Javascript file, // use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no // initializer or a 'null' or 'undefined' initializer. if (!(getCombinedNodeFlags(declaration) & NodeFlags.Const) && (!declaration.initializer || isNullOrUndefined(declaration.initializer))) { diff --git a/tests/baselines/reference/controlFlowJavascript.js b/tests/baselines/reference/controlFlowJavascript.js new file mode 100644 index 0000000000000..66518a6567a2c --- /dev/null +++ b/tests/baselines/reference/controlFlowJavascript.js @@ -0,0 +1,203 @@ +//// [controlFlowJavascript.js] + +let cond = true; + +// CFA for 'let' and no initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// CFA for 'var' with no initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} + + +//// [out.js] +var cond = true; +// CFA for 'let' and no initializer +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' and 'undefined' initializer +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' and 'null' initializer +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// CFA for 'var' with no initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for captured outer variables +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + function f() { + var z = x; // any + } +} +// No CFA for captured outer variables +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + var f = function () { + var z = x; // any + }; +} diff --git a/tests/baselines/reference/controlFlowJavascript.symbols b/tests/baselines/reference/controlFlowJavascript.symbols new file mode 100644 index 0000000000000..b3316de3b4e81 --- /dev/null +++ b/tests/baselines/reference/controlFlowJavascript.symbols @@ -0,0 +1,216 @@ +=== tests/cases/compiler/controlFlowJavascript.js === + +let cond = true; +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + +// CFA for 'let' and no initializer +function f1() { +>f1 : Symbol(f1, Decl(controlFlowJavascript.js, 1, 16)) + + let x; +>x : Symbol(x, Decl(controlFlowJavascript.js, 5, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 5, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 5, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowJavascript.js, 12, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 5, 7)) +} + +// CFA for 'let' and 'undefined' initializer +function f2() { +>f2 : Symbol(f2, Decl(controlFlowJavascript.js, 13, 1)) + + let x = undefined; +>x : Symbol(x, Decl(controlFlowJavascript.js, 17, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 17, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 17, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowJavascript.js, 24, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 17, 7)) +} + +// CFA for 'let' and 'null' initializer +function f3() { +>f3 : Symbol(f3, Decl(controlFlowJavascript.js, 25, 1)) + + let x = null; +>x : Symbol(x, Decl(controlFlowJavascript.js, 29, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 29, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 29, 7)) + } + const y = x; // string | number | null +>y : Symbol(y, Decl(controlFlowJavascript.js, 36, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 29, 7)) +} + +// CFA for 'var' with no initializer +function f5() { +>f5 : Symbol(f5, Decl(controlFlowJavascript.js, 37, 1)) + + var x; +>x : Symbol(x, Decl(controlFlowJavascript.js, 41, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 41, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 41, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowJavascript.js, 48, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 41, 7)) +} + +// CFA for 'var' with 'undefined' initializer +function f6() { +>f6 : Symbol(f6, Decl(controlFlowJavascript.js, 49, 1)) + + var x = undefined; +>x : Symbol(x, Decl(controlFlowJavascript.js, 53, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 53, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 53, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowJavascript.js, 60, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 53, 7)) +} + +// CFA for 'var' with 'null' initializer +function f7() { +>f7 : Symbol(f7, Decl(controlFlowJavascript.js, 61, 1)) + + var x = null; +>x : Symbol(x, Decl(controlFlowJavascript.js, 65, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 65, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 65, 7)) + } + const y = x; // string | number | null +>y : Symbol(y, Decl(controlFlowJavascript.js, 72, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 65, 7)) +} + +// No CFA for captured outer variables +function f9() { +>f9 : Symbol(f9, Decl(controlFlowJavascript.js, 73, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowJavascript.js, 77, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 77, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 77, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowJavascript.js, 84, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 77, 7)) + + function f() { +>f : Symbol(f, Decl(controlFlowJavascript.js, 84, 16)) + + const z = x; // any +>z : Symbol(z, Decl(controlFlowJavascript.js, 86, 13)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 77, 7)) + } +} + +// No CFA for captured outer variables +function f10() { +>f10 : Symbol(f10, Decl(controlFlowJavascript.js, 88, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowJavascript.js, 92, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = 1; +>x : Symbol(x, Decl(controlFlowJavascript.js, 92, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowJavascript.js, 1, 3)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowJavascript.js, 92, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowJavascript.js, 99, 9)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 92, 7)) + + const f = () => { +>f : Symbol(f, Decl(controlFlowJavascript.js, 100, 9)) + + const z = x; // any +>z : Symbol(z, Decl(controlFlowJavascript.js, 101, 13)) +>x : Symbol(x, Decl(controlFlowJavascript.js, 92, 7)) + + }; +} + diff --git a/tests/baselines/reference/controlFlowJavascript.types b/tests/baselines/reference/controlFlowJavascript.types new file mode 100644 index 0000000000000..0b88c62cb785a --- /dev/null +++ b/tests/baselines/reference/controlFlowJavascript.types @@ -0,0 +1,252 @@ +=== tests/cases/compiler/controlFlowJavascript.js === + +let cond = true; +>cond : boolean +>true : true + +// CFA for 'let' and no initializer +function f1() { +>f1 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number +>x : string | number +} + +// CFA for 'let' and 'undefined' initializer +function f2() { +>f2 : () => void + + let x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number +>x : string | number +} + +// CFA for 'let' and 'null' initializer +function f3() { +>f3 : () => void + + let x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | null +>y : string | number +>x : string | number +} + +// CFA for 'var' with no initializer +function f5() { +>f5 : () => void + + var x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number +>x : string | number +} + +// CFA for 'var' with 'undefined' initializer +function f6() { +>f6 : () => void + + var x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number +>x : string | number +} + +// CFA for 'var' with 'null' initializer +function f7() { +>f7 : () => void + + var x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | null +>y : string | number +>x : string | number +} + +// No CFA for captured outer variables +function f9() { +>f9 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number +>x : string | number + + function f() { +>f : () => void + + const z = x; // any +>z : any +>x : any + } +} + +// No CFA for captured outer variables +function f10() { +>f10 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number +>x : string | number + + const f = () => { +>f : () => void +>() => { const z = x; // any } : () => void + + const z = x; // any +>z : any +>x : any + + }; +} + diff --git a/tests/cases/compiler/controlFlowJavascript.ts b/tests/cases/compiler/controlFlowJavascript.ts new file mode 100644 index 0000000000000..b2886a2233a99 --- /dev/null +++ b/tests/cases/compiler/controlFlowJavascript.ts @@ -0,0 +1,107 @@ +// @allowJs: true +// @Filename: controlFlowJavascript.js +// @out: out.js + +let cond = true; + +// CFA for 'let' and no initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// CFA for 'var' with no initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} From ab84cd0647719a468e4bd6f7b911a094fe7c685d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 15:03:40 -0800 Subject: [PATCH 23/46] Improve readability of types and names --- src/compiler/checker.ts | 2 +- src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0803814bc14a2..94bbd8823e9f0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4854,7 +4854,7 @@ namespace ts { if (node.type && node.type.kind === SyntaxKind.JSDocOptionalType) { return true; } - const paramTags = getJSDocParameterTag(node); + const paramTags = getJSDocParameterTags(node); if (paramTags) { for (const paramTag of paramTags) { if (paramTag.isBracketed) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8b648000273df..51805228e4895 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -498,7 +498,7 @@ namespace ts { /* @internal */ original?: Node; // The original node if this is an updated node. /* @internal */ startsOnNewLine?: boolean; // Whether a synthesized node should start on a new line (used by transforms). /* @internal */ jsDocComments?: JSDoc[]; // JSDoc for the node, if it has any. - /* @internal */ jsDocCache?: (JSDoc | JSDocParameterTag)[]; // JSDoc for the node, plus JSDoc retrieved from its parents + /* @internal */ jsDocCache?: (JSDoc | JSDocTag)[]; // JSDoc for the node, plus JSDoc and tags retrieved from its parents /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e5fd8b067b0e4..08eaa8033aedf 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1427,7 +1427,7 @@ namespace ts { for (const doc of docs) { if (doc.kind === SyntaxKind.JSDocParameterTag) { if (doc.kind === kind) { - result.push(doc as JSDocParameterTag); + result.push(doc as JSDocTag); } } else { @@ -1442,8 +1442,8 @@ namespace ts { return node && firstOrUndefined(getJSDocTags(node, kind)); } - function getJSDocs(node: Node): (JSDoc | JSDocParameterTag)[] { - let cache: (JSDoc | JSDocParameterTag)[] = node.jsDocCache; + function getJSDocs(node: Node): (JSDoc | JSDocTag)[] { + let cache: (JSDoc | JSDocTag)[] = node.jsDocCache; if (!cache) { getJSDocsWorker(node); node.jsDocCache = cache; @@ -1491,7 +1491,7 @@ namespace ts { // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { - cache = concatenate(cache, getJSDocParameterTag(node)); + cache = concatenate(cache, getJSDocParameterTags(node)); } if (isVariableLike(node) && node.initializer) { @@ -1502,7 +1502,7 @@ namespace ts { } } - export function getJSDocParameterTag(param: Node): JSDocParameterTag[] { + export function getJSDocParameterTags(param: Node): JSDocParameterTag[] { if (!isParameter(param)) { return undefined; } @@ -1530,7 +1530,7 @@ namespace ts { export function getJSDocType(node: Node): JSDocType { let tag: JSDocTypeTag | JSDocParameterTag = getFirstJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag; if (!tag && node.kind === SyntaxKind.Parameter) { - const paramTags = getJSDocParameterTag(node); + const paramTags = getJSDocParameterTags(node); if (paramTags) { tag = find(paramTags, tag => !!tag.typeExpression); } @@ -1558,7 +1558,7 @@ namespace ts { export function isRestParameter(node: ParameterDeclaration) { if (node && (node.flags & NodeFlags.JavaScriptFile)) { if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType || - forEach(getJSDocParameterTag(node), + forEach(getJSDocParameterTags(node), t => t.typeExpression && t.typeExpression.type.kind === SyntaxKind.JSDocVariadicType)) { return true; } From 7caee79ce7aa698a84f98f7a88796d56c5e90624 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 15:10:19 -0800 Subject: [PATCH 24/46] Rename getJSDocComments -> getCommentsFromJSDoc --- src/compiler/utilities.ts | 2 +- src/services/jsDoc.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 08eaa8033aedf..5669ac9be8d3e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1416,7 +1416,7 @@ namespace ts { (node).parameters[0].type.kind === SyntaxKind.JSDocConstructorType; } - export function getJSDocComments(node: Node): string[] { + export function getCommentsFromJSDoc(node: Node): string[] { return map(getJSDocs(node), doc => doc.comment); } diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 24e99cf5c7754..3369ac23223c2 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -52,7 +52,7 @@ namespace ts.JsDoc { // from Array - Array and Array const documentationComment = []; forEachUnique(declarations, declaration => { - const comments = getJSDocComments(declaration); + const comments = getCommentsFromJSDoc(declaration); if (!comments) { return; } From 91e6bce34c3a2d771b815cd73c176018186b31b5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 15:44:15 -0800 Subject: [PATCH 25/46] Address PR comments --- src/compiler/binder.ts | 4 ++-- src/compiler/parser.ts | 20 ++++++++++---------- src/compiler/types.ts | 4 ++-- src/compiler/utilities.ts | 12 ++++++------ src/services/navigationBar.ts | 4 ++-- src/services/services.ts | 6 +++--- src/services/utilities.ts | 8 ++++---- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1afe51db0218b..c2bfce10e57d6 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -599,8 +599,8 @@ namespace ts { // Binding of JsDocComment should be done before the current block scope container changes. // because the scope of JsDocComment should not be affected by whether the current node is a // container or not. - if (isInJavaScriptFile(node) && node.jsDocComments) { - forEach(node.jsDocComments, bind); + if (isInJavaScriptFile(node) && node.jsDoc) { + forEach(node.jsDoc, bind); } if (checkUnreachable(node)) { bindEachChild(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a3c21eaf8dca2..d286a9d9dac10 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -689,10 +689,10 @@ namespace ts { continue; } - if (!node.jsDocComments) { - node.jsDocComments = []; + if (!node.jsDoc) { + node.jsDoc = []; } - node.jsDocComments.push(jsDoc); + node.jsDoc.push(jsDoc); } } @@ -719,11 +719,11 @@ namespace ts { const saveParent = parent; parent = n; forEachChild(n, visitNode); - if (n.jsDocComments) { - for (const jsDocComment of n.jsDocComments) { - jsDocComment.parent = n; - parent = jsDocComment; - forEachChild(jsDocComment, visitNode); + if (n.jsDoc) { + for (const jsDoc of n.jsDoc) { + jsDoc.parent = n; + parent = jsDoc; + forEachChild(jsDoc, visitNode); } } parent = saveParent; @@ -6954,8 +6954,8 @@ namespace ts { } forEachChild(node, visitNode, visitArray); - if (node.jsDocComments) { - for (const jsDocComment of node.jsDocComments) { + if (node.jsDoc) { + for (const jsDocComment of node.jsDoc) { forEachChild(jsDocComment, visitNode, visitArray); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 51805228e4895..2a4b9e66d82e9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -497,8 +497,8 @@ namespace ts { parent?: Node; // Parent node (initialized by binding) /* @internal */ original?: Node; // The original node if this is an updated node. /* @internal */ startsOnNewLine?: boolean; // Whether a synthesized node should start on a new line (used by transforms). - /* @internal */ jsDocComments?: JSDoc[]; // JSDoc for the node, if it has any. - /* @internal */ jsDocCache?: (JSDoc | JSDocTag)[]; // JSDoc for the node, plus JSDoc and tags retrieved from its parents + /* @internal */ jsDoc?: JSDoc[]; // JSDoc that directly precedes this node + /* @internal */ jsDocCache?: (JSDoc | JSDocTag)[]; // All JSDoc that applies to the node, including parent docs and @param tags /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5669ac9be8d3e..1d14854cd1f05 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -239,7 +239,7 @@ namespace ts { return !nodeIsMissing(node); } - export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile, includeJsDocComment?: boolean): number { + export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile, includeJsDoc?: boolean): number { // With nodes that have no width (i.e. 'Missing' nodes), we actually *don't* // want to skip trivia because this will launch us forward to the next token. if (nodeIsMissing(node)) { @@ -250,8 +250,8 @@ namespace ts { return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ true); } - if (includeJsDocComment && node.jsDocComments && node.jsDocComments.length > 0) { - return getTokenPosOfNode(node.jsDocComments[0]); + if (includeJsDoc && node.jsDoc && node.jsDoc.length > 0) { + return getTokenPosOfNode(node.jsDoc[0]); } // For a syntax list, it is possible that one of its children has JSDocComment nodes, while @@ -259,7 +259,7 @@ namespace ts { // trivia for the list, we may have skipped the JSDocComment as well. So we should process its // first child to determine the actual position of its first token. if (node.kind === SyntaxKind.SyntaxList && (node)._children.length > 0) { - return getTokenPosOfNode((node)._children[0], sourceFile, includeJsDocComment); + return getTokenPosOfNode((node)._children[0], sourceFile, includeJsDoc); } return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); @@ -1495,10 +1495,10 @@ namespace ts { } if (isVariableLike(node) && node.initializer) { - cache = concatenate(cache, node.initializer.jsDocComments); + cache = concatenate(cache, node.initializer.jsDoc); } - cache = concatenate(cache, node.jsDocComments); + cache = concatenate(cache, node.jsDoc); } } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 51ce9b6001d53..1cbaa3d640faf 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -225,8 +225,8 @@ namespace ts.NavigationBar { break; default: - forEach(node.jsDocComments, jsDocComment => { - forEach(jsDocComment.tags, tag => { + forEach(node.jsDoc, jsDoc => { + forEach(jsDoc.tags, tag => { if (tag.kind === SyntaxKind.JSDocTypedefTag) { addLeafNode(tag); } diff --git a/src/services/services.ts b/src/services/services.ts index 3c0b78383141d..f826a8850fe2d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1956,9 +1956,9 @@ namespace ts { break; default: forEachChild(node, walk); - if (node.jsDocComments) { - for (const jsDocComment of node.jsDocComments) { - forEachChild(jsDocComment, walk); + if (node.jsDoc) { + for (const jsDoc of node.jsDoc) { + forEachChild(jsDoc, walk); } } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 82b13f8232769..e19fdc0a84a49 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -951,10 +951,10 @@ namespace ts { } if (node) { - if (node.jsDocComments) { - for (const jsDocComment of node.jsDocComments) { - if (jsDocComment.tags) { - for (const tag of jsDocComment.tags) { + if (node.jsDoc) { + for (const jsDoc of node.jsDoc) { + if (jsDoc.tags) { + for (const tag of jsDoc.tags) { if (tag.pos <= position && position <= tag.end) { return tag; } From 0c5429d3b704e557c5be8573a6faba4da30f10a2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 18 Nov 2016 15:48:31 -0800 Subject: [PATCH 26/46] Add missed jsDoc rename in services' Node implementation Why would you implement an interface using a *class*? --- src/services/services.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index f826a8850fe2d..847967b2be986 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -45,7 +45,7 @@ namespace ts { public end: number; public flags: NodeFlags; public parent: Node; - public jsDocComments: JSDoc[]; + public jsDoc: JSDoc[]; public original: Node; public transformFlags: TransformFlags; private _children: Node[]; @@ -154,8 +154,8 @@ namespace ts { pos = nodes.end; }; // jsDocComments need to be the first children - if (this.jsDocComments) { - for (const jsDocComment of this.jsDocComments) { + if (this.jsDoc) { + for (const jsDocComment of this.jsDoc) { processNode(jsDocComment); } } From eaf791e32841c815aecc26d98ad31564673a5695 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 18 Nov 2016 22:53:38 -0800 Subject: [PATCH 27/46] update to tslint@next --- scripts/parallel-lint.js | 20 +++++++++++-------- scripts/tslint/booleanTriviaRule.ts | 2 +- scripts/tslint/nextLineRule.ts | 2 +- scripts/tslint/noInOperatorRule.ts | 2 +- scripts/tslint/noIncrementDecrementRule.ts | 2 +- .../tslint/noTypeAssertionWhitespaceRule.ts | 2 +- .../objectLiteralSurroundingSpaceRule.ts | 2 +- scripts/tslint/preferConstRule.ts | 2 +- scripts/tslint/typeOperatorSpacingRule.ts | 2 +- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/scripts/parallel-lint.js b/scripts/parallel-lint.js index a9aec06c2dfa0..aec9960ce4739 100644 --- a/scripts/parallel-lint.js +++ b/scripts/parallel-lint.js @@ -1,26 +1,29 @@ -var Linter = require("tslint"); +var tslint = require("tslint"); var fs = require("fs"); function getLinterOptions() { return { - configuration: require("../tslint.json"), formatter: "prose", formattersDirectory: undefined, rulesDirectory: "built/local/tslint" }; } +function getLinterConfiguration() { + return require("../tslint.json"); +} -function lintFileContents(options, path, contents) { - var ll = new Linter(path, contents, options); - return ll.lint(); +function lintFileContents(options, configuration, path, contents) { + var ll = new tslint.Linter(options); + ll.lint(path, contents, configuration); + return ll.getResult(); } -function lintFileAsync(options, path, cb) { +function lintFileAsync(options, configuration, path, cb) { fs.readFile(path, "utf8", function (err, contents) { if (err) { return cb(err); } - var result = lintFileContents(options, path, contents); + var result = lintFileContents(options, configuration, path, contents); cb(undefined, result); }); } @@ -30,7 +33,8 @@ process.on("message", function (data) { case "file": var target = data.name; var lintOptions = getLinterOptions(); - lintFileAsync(lintOptions, target, function (err, result) { + var lintConfiguration = getLinterConfiguration(); + lintFileAsync(lintOptions, lintConfiguration, target, function (err, result) { if (err) { process.send({ kind: "error", error: err.toString() }); return; diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index b626b7560a61b..db6abcbf17ba4 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/scripts/tslint/nextLineRule.ts b/scripts/tslint/nextLineRule.ts index d25652f7bce6e..2dee393bd84c5 100644 --- a/scripts/tslint/nextLineRule.ts +++ b/scripts/tslint/nextLineRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; const OPTION_CATCH = "check-catch"; diff --git a/scripts/tslint/noInOperatorRule.ts b/scripts/tslint/noInOperatorRule.ts index 527e8c1b895d2..307f0dffd6a32 100644 --- a/scripts/tslint/noInOperatorRule.ts +++ b/scripts/tslint/noInOperatorRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; diff --git a/scripts/tslint/noIncrementDecrementRule.ts b/scripts/tslint/noIncrementDecrementRule.ts index f5c90abe893d0..2a957b36af566 100644 --- a/scripts/tslint/noIncrementDecrementRule.ts +++ b/scripts/tslint/noIncrementDecrementRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; diff --git a/scripts/tslint/noTypeAssertionWhitespaceRule.ts b/scripts/tslint/noTypeAssertionWhitespaceRule.ts index e75964b9e7e99..5368dcf74bade 100644 --- a/scripts/tslint/noTypeAssertionWhitespaceRule.ts +++ b/scripts/tslint/noTypeAssertionWhitespaceRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; diff --git a/scripts/tslint/objectLiteralSurroundingSpaceRule.ts b/scripts/tslint/objectLiteralSurroundingSpaceRule.ts index b527746bf51b2..a705e56c9691a 100644 --- a/scripts/tslint/objectLiteralSurroundingSpaceRule.ts +++ b/scripts/tslint/objectLiteralSurroundingSpaceRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; diff --git a/scripts/tslint/preferConstRule.ts b/scripts/tslint/preferConstRule.ts index 445fbe2e72afd..28d7446b29049 100644 --- a/scripts/tslint/preferConstRule.ts +++ b/scripts/tslint/preferConstRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/scripts/tslint/typeOperatorSpacingRule.ts b/scripts/tslint/typeOperatorSpacingRule.ts index 559d1b3493705..50f2971a0ee94 100644 --- a/scripts/tslint/typeOperatorSpacingRule.ts +++ b/scripts/tslint/typeOperatorSpacingRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint/lib"; import * as ts from "typescript"; From c96bc89982d2d6f98f6d258a90bca66950222978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Parditka?= Date: Sat, 19 Nov 2016 11:13:36 +0100 Subject: [PATCH 28/46] Fix issue #12260. Fixed tsserver crashing on Android (Termux). --- src/server/server.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server/server.ts b/src/server/server.ts index 220b0d90c65e6..afe0382084c06 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -31,6 +31,7 @@ namespace ts.server { os.tmpdir(); break; case "linux": + case "android": basePath = (os.homedir && os.homedir()) || process.env.HOME || ((process.env.LOGNAME || process.env.USER) && `/home/${process.env.LOGNAME || process.env.USER}`) || @@ -598,4 +599,4 @@ namespace ts.server { (process as any).noAsar = true; // Start listening ioSession.listen(); -} \ No newline at end of file +} From dcd225a8923bbb6fc4f168d41e7ab644bf8ce481 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Nov 2016 09:03:23 -0800 Subject: [PATCH 29/46] Fix comparable relation for keyof T Treat keyof T as string | number for purposes of indexing Allow indexed access types with for-in and in operator --- src/compiler/checker.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 024c3d4a983c3..ccd731e7a2c4d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6037,11 +6037,12 @@ namespace ts { const id = objectType.id + "," + indexType.id; return indexedAccessTypes[id] || (indexedAccessTypes[id] = createIndexedAccessType(objectType, indexType)); } - const apparentType = getApparentType(objectType); - if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) { + const apparentObjectType = getApparentType(objectType); + const apparentIndexType = indexType.flags & TypeFlags.Index ? stringOrNumberType : indexType; + if (apparentIndexType.flags & TypeFlags.Union && !(apparentIndexType.flags & TypeFlags.Primitive)) { const propTypes: Type[] = []; - for (const t of (indexType).types) { - const propType = getPropertyTypeForIndexType(apparentType, t, accessNode, /*cacheSymbol*/ false); + for (const t of (apparentIndexType).types) { + const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false); if (propType === unknownType) { return unknownType; } @@ -6049,7 +6050,7 @@ namespace ts { } return getUnionType(propTypes); } - return getPropertyTypeForIndexType(apparentType, indexType, accessNode, /*cacheSymbol*/ true); + return getPropertyTypeForIndexType(apparentObjectType, apparentIndexType, accessNode, /*cacheSymbol*/ true); } function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) { @@ -7123,7 +7124,10 @@ namespace ts { if (source.flags & TypeFlags.Index) { // A keyof T is related to a union type containing both string and number - if (maybeTypeOfKind(target, TypeFlags.String) && maybeTypeOfKind(target, TypeFlags.Number)) { + const related = relation === comparableRelation ? + maybeTypeOfKind(target, TypeFlags.String | TypeFlags.Number) : + maybeTypeOfKind(target, TypeFlags.String) && maybeTypeOfKind(target, TypeFlags.Number); + if (related) { return Ternary.True; } } @@ -14254,7 +14258,7 @@ namespace ts { if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) { error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -17148,7 +17152,7 @@ namespace ts { const rightType = checkNonNullExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } From a439e6213883a310bbeefb7cac7777f4cff6f04c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Nov 2016 15:10:22 -0800 Subject: [PATCH 30/46] Add tests --- .../types/keyof/keyofAndIndexedAccess.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 1e874aaf80f8a..522bfe34e156e 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -181,6 +181,46 @@ function f40(c: C) { let z: Z = c["z"]; } +function f50(k: keyof T, s: string, n: number) { + const x1 = s as keyof T; + const x2 = n as keyof T; + const x3 = k as string; + const x4 = k as number; + const x5 = k as string | number; +} + +function f51(k: K, s: string, n: number) { + const x1 = s as keyof T; + const x2 = n as keyof T; + const x3 = k as string; + const x4 = k as number; + const x5 = k as string | number; +} + +function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { + const x1 = obj[s]; + const x2 = obj[n]; + const x3 = obj[k]; +} + +function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { + const x1 = obj[s]; + const x2 = obj[n]; + const x3 = obj[k]; +} + +function f54(obj: T, key: keyof T) { + for (let s in obj[key]) { + } + const b = "foo" in obj[key]; +} + +function f55(obj: T, key: K) { + for (let s in obj[key]) { + } + const b = "foo" in obj[key]; +} + // Repros from #12011 class Base { From 4ce494a27d7727847eb94b508677ea981de8692c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Nov 2016 15:10:35 -0800 Subject: [PATCH 31/46] Accept new baselines --- .../reference/keyofAndIndexedAccess.js | 84 +++++++ .../reference/keyofAndIndexedAccess.symbols | 230 +++++++++++++++--- .../reference/keyofAndIndexedAccess.types | 182 ++++++++++++++ 3 files changed, 460 insertions(+), 36 deletions(-) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index dd59a5a1b4c72..eef81f4d5f76d 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -181,6 +181,46 @@ function f40(c: C) { let z: Z = c["z"]; } +function f50(k: keyof T, s: string, n: number) { + const x1 = s as keyof T; + const x2 = n as keyof T; + const x3 = k as string; + const x4 = k as number; + const x5 = k as string | number; +} + +function f51(k: K, s: string, n: number) { + const x1 = s as keyof T; + const x2 = n as keyof T; + const x3 = k as string; + const x4 = k as number; + const x5 = k as string | number; +} + +function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { + const x1 = obj[s]; + const x2 = obj[n]; + const x3 = obj[k]; +} + +function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { + const x1 = obj[s]; + const x2 = obj[n]; + const x3 = obj[k]; +} + +function f54(obj: T, key: keyof T) { + for (let s in obj[key]) { + } + const b = "foo" in obj[key]; +} + +function f55(obj: T, key: K) { + for (let s in obj[key]) { + } + const b = "foo" in obj[key]; +} + // Repros from #12011 class Base { @@ -329,6 +369,40 @@ function f40(c) { var y = c["y"]; var z = c["z"]; } +function f50(k, s, n) { + var x1 = s; + var x2 = n; + var x3 = k; + var x4 = k; + var x5 = k; +} +function f51(k, s, n) { + var x1 = s; + var x2 = n; + var x3 = k; + var x4 = k; + var x5 = k; +} +function f52(obj, k, s, n) { + var x1 = obj[s]; + var x2 = obj[n]; + var x3 = obj[k]; +} +function f53(obj, k, s, n) { + var x1 = obj[s]; + var x2 = obj[n]; + var x3 = obj[k]; +} +function f54(obj, key) { + for (var s in obj[key]) { + } + var b = "foo" in obj[key]; +} +function f55(obj, key) { + for (var s in obj[key]) { + } + var b = "foo" in obj[key]; +} // Repros from #12011 var Base = (function () { function Base() { @@ -454,6 +528,16 @@ declare class C { private z; } declare function f40(c: C): void; +declare function f50(k: keyof T, s: string, n: number): void; +declare function f51(k: K, s: string, n: number): void; +declare function f52(obj: { + [x: string]: boolean; +}, k: keyof T, s: string, n: number): void; +declare function f53(obj: { + [x: string]: boolean; +}, k: K, s: string, n: number): void; +declare function f54(obj: T, key: keyof T): void; +declare function f55(obj: T, key: K): void; declare class Base { get(prop: K): this[K]; set(prop: K, value: this[K]): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index a76cf32b8d2fa..0b10e368821bd 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -626,84 +626,242 @@ function f40(c: C) { >"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 167, 24)) } +function f50(k: keyof T, s: string, n: number) { +>f50 : Symbol(f50, Decl(keyofAndIndexedAccess.ts, 180, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 182, 27)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 182, 38)) + + const x1 = s as keyof T; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 183, 9)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 182, 27)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) + + const x2 = n as keyof T; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 184, 9)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 182, 38)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) + + const x3 = k as string; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 185, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) + + const x4 = k as number; +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 186, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) + + const x5 = k as string | number; +>x5 : Symbol(x5, Decl(keyofAndIndexedAccess.ts, 187, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) +} + +function f51(k: K, s: string, n: number) { +>f51 : Symbol(f51, Decl(keyofAndIndexedAccess.ts, 188, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 190, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 190, 15)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 190, 40)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 190, 51)) + + const x1 = s as keyof T; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 191, 9)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 190, 40)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) + + const x2 = n as keyof T; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 192, 9)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 190, 51)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) + + const x3 = k as string; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 193, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) + + const x4 = k as number; +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 194, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) + + const x5 = k as string | number; +>x5 : Symbol(x5, Decl(keyofAndIndexedAccess.ts, 195, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) +} + +function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { +>f52 : Symbol(f52, Decl(keyofAndIndexedAccess.ts, 196, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 198, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 198, 24)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 198, 46)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 198, 13)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 198, 58)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 198, 69)) + + const x1 = obj[s]; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 199, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 198, 58)) + + const x2 = obj[n]; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 200, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 198, 69)) + + const x3 = obj[k]; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 201, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 198, 46)) +} + +function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { +>f53 : Symbol(f53, Decl(keyofAndIndexedAccess.ts, 202, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 204, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 204, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 204, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 204, 43)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 204, 65)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 204, 15)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 204, 71)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 204, 82)) + + const x1 = obj[s]; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 205, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 204, 71)) + + const x2 = obj[n]; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 206, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 204, 82)) + + const x3 = obj[k]; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 207, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 204, 65)) +} + +function f54(obj: T, key: keyof T) { +>f54 : Symbol(f54, Decl(keyofAndIndexedAccess.ts, 208, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 210, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 210, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 210, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 210, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 210, 13)) + + for (let s in obj[key]) { +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 211, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 210, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 210, 23)) + } + const b = "foo" in obj[key]; +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 213, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 210, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 210, 23)) +} + +function f55(obj: T, key: K) { +>f55 : Symbol(f55, Decl(keyofAndIndexedAccess.ts, 214, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 216, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 216, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 216, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 216, 35)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 216, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 216, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 216, 15)) + + for (let s in obj[key]) { +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 217, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 216, 35)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 216, 42)) + } + const b = "foo" in obj[key]; +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 219, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 216, 35)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 216, 42)) +} + // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 184, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 185, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 185, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 185, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 224, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 225, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 225, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 225, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 185, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 225, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 187, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 188, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 188, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 188, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 188, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 188, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 227, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 228, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 228, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 228, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 228, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 228, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 188, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 188, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 228, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 228, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 191, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 231, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 193, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 233, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 195, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 235, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 187, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 191, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 187, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 195, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 227, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 231, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 227, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 235, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 198, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 238, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 184, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 191, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 184, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 224, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 231, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 224, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 202, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 242, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 204, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 244, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 206, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 246, 16)) setProperty(this, "parts", parts); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 202, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 206, 16)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 242, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 246, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 208, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 248, 5)) return getProperty(this, "parts") >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 202, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 242, 1)) } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index c252ea4e2bd97..020ac1141261e 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -737,6 +737,188 @@ function f40(c: C) { >"z" : "z" } +function f50(k: keyof T, s: string, n: number) { +>f50 : (k: keyof T, s: string, n: number) => void +>T : T +>k : keyof T +>T : T +>s : string +>n : number + + const x1 = s as keyof T; +>x1 : keyof T +>s as keyof T : keyof T +>s : string +>T : T + + const x2 = n as keyof T; +>x2 : keyof T +>n as keyof T : keyof T +>n : number +>T : T + + const x3 = k as string; +>x3 : string +>k as string : string +>k : keyof T + + const x4 = k as number; +>x4 : number +>k as number : number +>k : keyof T + + const x5 = k as string | number; +>x5 : string | number +>k as string | number : string | number +>k : keyof T +} + +function f51(k: K, s: string, n: number) { +>f51 : (k: K, s: string, n: number) => void +>T : T +>K : K +>T : T +>k : K +>K : K +>s : string +>n : number + + const x1 = s as keyof T; +>x1 : keyof T +>s as keyof T : keyof T +>s : string +>T : T + + const x2 = n as keyof T; +>x2 : keyof T +>n as keyof T : keyof T +>n : number +>T : T + + const x3 = k as string; +>x3 : string +>k as string : string +>k : K + + const x4 = k as number; +>x4 : number +>k as number : number +>k : K + + const x5 = k as string | number; +>x5 : string | number +>k as string | number : string | number +>k : K +} + +function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { +>f52 : (obj: { [x: string]: boolean; }, k: keyof T, s: string, n: number) => void +>T : T +>obj : { [x: string]: boolean; } +>x : string +>k : keyof T +>T : T +>s : string +>n : number + + const x1 = obj[s]; +>x1 : boolean +>obj[s] : boolean +>obj : { [x: string]: boolean; } +>s : string + + const x2 = obj[n]; +>x2 : boolean +>obj[n] : boolean +>obj : { [x: string]: boolean; } +>n : number + + const x3 = obj[k]; +>x3 : boolean +>obj[k] : boolean +>obj : { [x: string]: boolean; } +>k : keyof T +} + +function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { +>f53 : (obj: { [x: string]: boolean; }, k: K, s: string, n: number) => void +>T : T +>K : K +>T : T +>obj : { [x: string]: boolean; } +>x : string +>k : K +>K : K +>s : string +>n : number + + const x1 = obj[s]; +>x1 : boolean +>obj[s] : boolean +>obj : { [x: string]: boolean; } +>s : string + + const x2 = obj[n]; +>x2 : boolean +>obj[n] : boolean +>obj : { [x: string]: boolean; } +>n : number + + const x3 = obj[k]; +>x3 : { [x: string]: boolean; }[K] +>obj[k] : { [x: string]: boolean; }[K] +>obj : { [x: string]: boolean; } +>k : K +} + +function f54(obj: T, key: keyof T) { +>f54 : (obj: T, key: keyof T) => void +>T : T +>obj : T +>T : T +>key : keyof T +>T : T + + for (let s in obj[key]) { +>s : string +>obj[key] : T[keyof T] +>obj : T +>key : keyof T + } + const b = "foo" in obj[key]; +>b : boolean +>"foo" in obj[key] : boolean +>"foo" : "foo" +>obj[key] : T[keyof T] +>obj : T +>key : keyof T +} + +function f55(obj: T, key: K) { +>f55 : (obj: T, key: K) => void +>T : T +>K : K +>T : T +>obj : T +>T : T +>key : K +>K : K + + for (let s in obj[key]) { +>s : string +>obj[key] : T[K] +>obj : T +>key : K + } + const b = "foo" in obj[key]; +>b : boolean +>"foo" in obj[key] : boolean +>"foo" : "foo" +>obj[key] : T[K] +>obj : T +>key : K +} + // Repros from #12011 class Base { From 110c3ac6ace8d7498518d1836a644bdf740c9bfc Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Mon, 21 Nov 2016 10:30:38 -0800 Subject: [PATCH 32/46] Add locale options to tsserver (#12369) * add locale options to tsserver * make sys an argument * fix mistakes and address code review --- src/compiler/tsc.ts | 62 +--------------------------- src/compiler/utilities.ts | 85 ++++++++++++++++++++++++++++++++++----- src/server/server.ts | 5 +++ 3 files changed, 82 insertions(+), 70 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 10d4a0c1d3679..a7304eebe4b81 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -43,66 +43,6 @@ namespace ts { } } - /** - * Checks to see if the locale is in the appropriate format, - * and if it is, attempts to set the appropriate language. - */ - function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean { - const matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); - - if (!matchResult) { - errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, "en", "ja-jp")); - return false; - } - - const language = matchResult[1]; - const territory = matchResult[3]; - - // First try the entire locale, then fall back to just language if that's all we have. - // Either ways do not fail, and fallback to the English diagnostic strings. - if (!trySetLanguageAndTerritory(language, territory, errors)) { - trySetLanguageAndTerritory(language, undefined, errors); - } - - return true; - } - - function trySetLanguageAndTerritory(language: string, territory: string, errors: Diagnostic[]): boolean { - const compilerFilePath = normalizePath(sys.getExecutingFilePath()); - const containingDirectoryPath = getDirectoryPath(compilerFilePath); - - let filePath = combinePaths(containingDirectoryPath, language); - - if (territory) { - filePath = filePath + "-" + territory; - } - - filePath = sys.resolvePath(combinePaths(filePath, "diagnosticMessages.generated.json")); - - if (!sys.fileExists(filePath)) { - return false; - } - - // TODO: Add codePage support for readFile? - let fileContents = ""; - try { - fileContents = sys.readFile(filePath); - } - catch (e) { - errors.push(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, filePath)); - return false; - } - try { - ts.localizedDiagnosticMessages = JSON.parse(fileContents); - } - catch (e) { - errors.push(createCompilerDiagnostic(Diagnostics.Corrupted_locale_file_0, filePath)); - return false; - } - - return true; - } - function countLines(program: Program): number { let count = 0; forEach(program.getSourceFiles(), file => { @@ -263,7 +203,7 @@ namespace ts { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } - validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); + validateLocaleAndSetLanguage(commandLine.options.locale, sys, commandLine.errors); } // If there are any errors due to command line parsing and/or diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 546416884f1dc..09318fbe41ddd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -472,15 +472,15 @@ namespace ts { export function getTextOfPropertyName(name: PropertyName): string { switch (name.kind) { - case SyntaxKind.Identifier: - return (name).text; - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - return (name).text; - case SyntaxKind.ComputedPropertyName: - if (isStringOrNumericLiteral((name).expression)) { - return ((name).expression).text; - } + case SyntaxKind.Identifier: + return (name).text; + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + return (name).text; + case SyntaxKind.ComputedPropertyName: + if (isStringOrNumericLiteral((name).expression)) { + return ((name).expression).text; + } } return undefined; @@ -4554,4 +4554,71 @@ namespace ts { return flags; } + + /** + * Checks to see if the locale is in the appropriate format, + * and if it is, attempts to set the appropriate language. + */ + export function validateLocaleAndSetLanguage( + locale: string, + sys: { getExecutingFilePath(): string, resolvePath(path: string): string, fileExists(fileName: string): boolean, readFile(fileName: string): string }, + errors?: Diagnostic[]) { + const matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); + + if (!matchResult) { + if (errors) { + errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, "en", "ja-jp")); + } + return; + } + + const language = matchResult[1]; + const territory = matchResult[3]; + + // First try the entire locale, then fall back to just language if that's all we have. + // Either ways do not fail, and fallback to the English diagnostic strings. + if (!trySetLanguageAndTerritory(language, territory, errors)) { + trySetLanguageAndTerritory(language, /*territory*/ undefined, errors); + } + + function trySetLanguageAndTerritory(language: string, territory: string, errors?: Diagnostic[]): boolean { + const compilerFilePath = normalizePath(sys.getExecutingFilePath()); + const containingDirectoryPath = getDirectoryPath(compilerFilePath); + + let filePath = combinePaths(containingDirectoryPath, language); + + if (territory) { + filePath = filePath + "-" + territory; + } + + filePath = sys.resolvePath(combinePaths(filePath, "diagnosticMessages.generated.json")); + + if (!sys.fileExists(filePath)) { + return false; + } + + // TODO: Add codePage support for readFile? + let fileContents = ""; + try { + fileContents = sys.readFile(filePath); + } + catch (e) { + if (errors) { + errors.push(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, filePath)); + } + return false; + } + try { + ts.localizedDiagnosticMessages = JSON.parse(fileContents); + } + catch (e) { + if (errors) { + errors.push(createCompilerDiagnostic(Diagnostics.Corrupted_locale_file_0, filePath)); + } + return false; + } + + return true; + } + } } diff --git a/src/server/server.ts b/src/server/server.ts index afe0382084c06..1d013c8c62a74 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -578,6 +578,11 @@ namespace ts.server { } } + const localeStr = findArgument("--locale"); + if (localeStr) { + validateLocaleAndSetLanguage(localeStr, sys); + } + const useSingleInferredProject = hasArgument("--useSingleInferredProject"); const disableAutomaticTypingAcquisition = hasArgument("--disableAutomaticTypingAcquisition"); const telemetryEnabled = hasArgument(Arguments.EnableTelemetry); From 7c1f33f9136775646b45ffe0b8dae0657985abd0 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 21 Nov 2016 10:42:54 -0800 Subject: [PATCH 33/46] Fix lint errors --- src/services/codefixes/importFixes.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 4adda19689db9..bda310f2d3359 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -52,7 +52,7 @@ namespace ts.codefix { // than another existing one. For example, you may have new imports from "./foo/bar" // and "bar", when the new one is "bar/bar2" and the current one is "./foo/bar". The new // one and the current one are not comparable (one relative path and one absolute path), - // but the new one is worse than the other one, so should not add to the list. + // but the new one is worse than the other one, so should not add to the list. updatedNewImports.push(existingAction); break; case ModuleSpecifierComparison.Worse: @@ -145,7 +145,7 @@ namespace ts.codefix { if (localSymbol && localSymbol.name === name && checkSymbolHasMeaning(localSymbol, currentTokenMeaning)) { // check if this symbol is already used const symbolId = getUniqueSymbolId(localSymbol); - symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, /*isDefaultExport*/ true)); + symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, /*isDefault*/ true)); } } @@ -483,7 +483,7 @@ namespace ts.codefix { const normalizedTypeRoots = map(typeRoots, typeRoot => toPath(typeRoot, /*basePath*/ undefined, getCanonicalFileName)); for (const typeRoot of normalizedTypeRoots) { if (startsWith(moduleFileName, typeRoot)) { - let relativeFileName = moduleFileName.substring(typeRoot.length + 1); + const relativeFileName = moduleFileName.substring(typeRoot.length + 1); return removeExtensionAndIndexPostFix(relativeFileName); } } From b060107b516b04c37081419770374a62b99c2bed Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 21 Nov 2016 11:34:09 -0800 Subject: [PATCH 34/46] recompute character to column when comparing indentations (#12375) recompute character to column when comparing indentations --- src/services/formatting/formatting.ts | 15 ++++++++++++++- tests/cases/fourslash/formatWithTabs.ts | 16 ++++++++++++++++ tests/cases/fourslash/formatWithTabs2.ts | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formatWithTabs.ts create mode 100644 tests/cases/fourslash/formatWithTabs2.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 7f594ad82b1fd..bcd8cebb017e7 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -886,12 +886,25 @@ namespace ts.formatting { else { const tokenStart = sourceFile.getLineAndCharacterOfPosition(pos); const startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile); - if (indentation !== tokenStart.character || indentationIsDifferent(indentationString, startLinePosition)) { + if (indentation !== characterToColumn(startLinePosition, tokenStart.character) || indentationIsDifferent(indentationString, startLinePosition)) { recordReplace(startLinePosition, tokenStart.character, indentationString); } } } + function characterToColumn(startLinePosition: number, characterInLine: number): number { + let column = 0; + for (let i = 0; i < characterInLine; i++) { + if (sourceFile.text.charCodeAt(startLinePosition + i) === CharacterCodes.tab) { + column += options.tabSize - column % options.tabSize; + } + else { + column++; + } + } + return column; + } + function indentationIsDifferent(indentationString: string, startLinePosition: number): boolean { return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length); } diff --git a/tests/cases/fourslash/formatWithTabs.ts b/tests/cases/fourslash/formatWithTabs.ts new file mode 100644 index 0000000000000..c33808bd26acf --- /dev/null +++ b/tests/cases/fourslash/formatWithTabs.ts @@ -0,0 +1,16 @@ +/// + +////const foo = [ +//// 1 +////]; + +const options = format.copyFormatOptions(); +options.IndentSize = 2; +options.TabSize = 2; +options.ConvertTabsToSpaces = false; +format.setFormatOptions(options); +format.document(); +verify.currentFileContentIs( +`const foo = [ + 1 +];`); \ No newline at end of file diff --git a/tests/cases/fourslash/formatWithTabs2.ts b/tests/cases/fourslash/formatWithTabs2.ts new file mode 100644 index 0000000000000..cda82b9cf80cb --- /dev/null +++ b/tests/cases/fourslash/formatWithTabs2.ts @@ -0,0 +1,16 @@ +/// + +////const foo = [ +//// 1 +////]; + +const options = format.copyFormatOptions(); +options.IndentSize = 2; +options.TabSize = 2; +options.ConvertTabsToSpaces = false; +format.setFormatOptions(options); +format.document(); +verify.currentFileContentIs( +`const foo = [ + 1 +];`); \ No newline at end of file From 76ceab97dd744de160f28e2ec7412a6de4ca73dd Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 11:41:51 -0800 Subject: [PATCH 35/46] Make keyof T a string-like type --- src/compiler/checker.ts | 26 +++++++------------------- src/compiler/types.ts | 2 +- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fdb9f928928b4..3c8c0be77c709 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -142,7 +142,6 @@ namespace ts { const voidType = createIntrinsicType(TypeFlags.Void, "void"); const neverType = createIntrinsicType(TypeFlags.Never, "never"); const silentNeverType = createIntrinsicType(TypeFlags.Never, "never"); - const stringOrNumberType = getUnionType([stringType, numberType]); const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -3219,6 +3218,8 @@ namespace ts { // A variable declared in a for..in statement is always of type string if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { + // const indexType = getIndexType(checkNonNullExpression((declaration.parent.parent).expression)); + // return indexType.flags & TypeFlags.Index ? indexType : stringType; return stringType; } @@ -4688,7 +4689,6 @@ namespace ts { t.flags & TypeFlags.NumberLike ? globalNumberType : t.flags & TypeFlags.BooleanLike ? globalBooleanType : t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() : - t.flags & TypeFlags.Index ? stringOrNumberType : t; } @@ -5920,8 +5920,7 @@ namespace ts { function getIndexType(type: Type): Type { return type.flags & TypeFlags.TypeParameter ? getIndexTypeForTypeParameter(type) : getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(type) : - type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringOrNumberType : - getIndexInfoOfType(type, IndexKind.Number) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type)]) : + type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringType : getLiteralTypeFromPropertyNames(type); } @@ -6040,10 +6039,9 @@ namespace ts { return indexedAccessTypes[id] || (indexedAccessTypes[id] = createIndexedAccessType(objectType, indexType)); } const apparentObjectType = getApparentType(objectType); - const apparentIndexType = indexType.flags & TypeFlags.Index ? stringOrNumberType : indexType; - if (apparentIndexType.flags & TypeFlags.Union && !(apparentIndexType.flags & TypeFlags.Primitive)) { + if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) { const propTypes: Type[] = []; - for (const t of (apparentIndexType).types) { + for (const t of (indexType).types) { const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false); if (propType === unknownType) { return unknownType; @@ -6052,7 +6050,7 @@ namespace ts { } return getUnionType(propTypes); } - return getPropertyTypeForIndexType(apparentObjectType, apparentIndexType, accessNode, /*cacheSymbol*/ true); + return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true); } function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) { @@ -7124,16 +7122,6 @@ namespace ts { if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; - if (source.flags & TypeFlags.Index) { - // A keyof T is related to a union type containing both string and number - const related = relation === comparableRelation ? - maybeTypeOfKind(target, TypeFlags.String | TypeFlags.Number) : - maybeTypeOfKind(target, TypeFlags.String) && maybeTypeOfKind(target, TypeFlags.Number); - if (related) { - return Ternary.True; - } - } - if (getObjectFlags(source) & ObjectFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { @@ -15654,7 +15642,7 @@ namespace ts { const type = getTypeFromMappedTypeNode(node); const constraintType = getConstraintTypeFromMappedType(type); const keyType = constraintType.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(constraintType) : constraintType; - checkTypeAssignableTo(keyType, stringOrNumberType, node.typeParameter.constraint); + checkTypeAssignableTo(keyType, stringType, node.typeParameter.constraint); } function isPrivateWithinAmbient(node: Node): boolean { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2b8b6fe294e55..e79e136ac323e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2789,7 +2789,7 @@ namespace ts { Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never, /* @internal */ Primitive = String | Number | Boolean | Enum | ESSymbol | Void | Undefined | Null | Literal, - StringLike = String | StringLiteral, + StringLike = String | StringLiteral | Index, NumberLike = Number | NumberLiteral | Enum | EnumLiteral, BooleanLike = Boolean | BooleanLiteral, EnumLike = Enum | EnumLiteral, From 854a20f1febb50bfa4d814572adc777e8609b226 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 11:42:21 -0800 Subject: [PATCH 36/46] Update Record type --- src/lib/es5.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index e402a96fade0b..7ee478178021d 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1367,7 +1367,7 @@ type Pick = { /** * Construct a type with a set of properties K of type T */ -type Record = { +type Record = { [P in K]: T; } From 5498a95245183dab4e0d6be25de6912361101017 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 11:42:38 -0800 Subject: [PATCH 37/46] Update tests --- .../types/keyof/keyofAndIndexedAccess.ts | 22 +++++-------------- .../types/mapped/mappedTypeErrors.ts | 5 +++-- .../conformance/types/mapped/mappedTypes1.ts | 8 ++----- .../conformance/types/mapped/mappedTypes2.ts | 2 +- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 522bfe34e156e..690154cb7ac2a 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -95,22 +95,18 @@ function f10(shape: Shape) { function f11(a: Shape[]) { let len = getProperty(a, "length"); // number - let shape = getProperty(a, 1000); // Shape - setProperty(a, 1000, getProperty(a, 1001)); + setProperty(a, "length", len); } function f12(t: [Shape, boolean]) { let len = getProperty(t, "length"); - let s1 = getProperty(t, 0); // Shape let s2 = getProperty(t, "0"); // Shape - let b1 = getProperty(t, 1); // boolean let b2 = getProperty(t, "1"); // boolean - let x1 = getProperty(t, 2); // Shape | boolean } function f13(foo: any, bar: any) { let x = getProperty(foo, "x"); // any - let y = getProperty(foo, 100); // any + let y = getProperty(foo, "100"); // any let z = getProperty(foo, bar); // any } @@ -181,20 +177,14 @@ function f40(c: C) { let z: Z = c["z"]; } -function f50(k: keyof T, s: string, n: number) { +function f50(k: keyof T, s: string) { const x1 = s as keyof T; - const x2 = n as keyof T; - const x3 = k as string; - const x4 = k as number; - const x5 = k as string | number; + const x2 = k as string; } -function f51(k: K, s: string, n: number) { +function f51(k: K, s: string) { const x1 = s as keyof T; - const x2 = n as keyof T; - const x3 = k as string; - const x4 = k as number; - const x5 = k as string | number; + const x2 = k as string; } function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { diff --git a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts index c507bf64a6e10..b318cde3aab06 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts @@ -20,8 +20,9 @@ interface Point { // Constraint checking type T00 = { [P in P]: string }; // Error -type T01 = { [P in Date]: number }; // Error -type T02 = Record; // Error +type T01 = { [P in number]: string }; // Error +type T02 = { [P in Date]: number }; // Error +type T03 = Record; // Error type T10 = Pick; type T11 = Pick; // Error diff --git a/tests/cases/conformance/types/mapped/mappedTypes1.ts b/tests/cases/conformance/types/mapped/mappedTypes1.ts index bfc68aaa59d20..d090b73151824 100644 --- a/tests/cases/conformance/types/mapped/mappedTypes1.ts +++ b/tests/cases/conformance/types/mapped/mappedTypes1.ts @@ -27,13 +27,9 @@ type T37 = { [P in keyof symbol]: void }; type T38 = { [P in keyof never]: void }; type T40 = { [P in string]: void }; -type T41 = { [P in number]: void }; -type T42 = { [P in string | number]: void }; -type T43 = { [P in "a" | "b" | 0 | 1]: void }; +type T43 = { [P in "a" | "b"]: void }; type T44 = { [P in "a" | "b" | "0" | "1"]: void }; -type T45 = { [P in "a" | "b" | "0" | "1" | 0 | 1]: void }; -type T46 = { [P in number | "a" | "b" | 0 | 1]: void }; -type T47 = { [P in string | number | "a" | "b" | 0 | 1]: void }; +type T47 = { [P in string | "a" | "b" | "0" | "1"]: void }; declare function f1(): { [P in keyof T1]: void }; declare function f2(): { [P in keyof T1]: void }; diff --git a/tests/cases/conformance/types/mapped/mappedTypes2.ts b/tests/cases/conformance/types/mapped/mappedTypes2.ts index 7f5841410e456..e72a0c0a8924a 100644 --- a/tests/cases/conformance/types/mapped/mappedTypes2.ts +++ b/tests/cases/conformance/types/mapped/mappedTypes2.ts @@ -28,7 +28,7 @@ type DeepReadonly = { declare function assign(obj: T, props: Partial): void; declare function freeze(obj: T): Readonly; declare function pick(obj: T, ...keys: K[]): Pick; -declare function mapObject(obj: Record, f: (x: T) => U): Record; +declare function mapObject(obj: Record, f: (x: T) => U): Record; declare function proxify(obj: T): Proxify; interface Shape { From c5558482b7f2e3a8bc7b99ae1540c089b3e4d142 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 11:43:15 -0800 Subject: [PATCH 38/46] Accept new baselines --- .../reference/keyofAndIndexedAccess.js | 48 +- .../reference/keyofAndIndexedAccess.symbols | 625 ++++++++---------- .../reference/keyofAndIndexedAccess.types | 107 +-- .../reference/mappedTypeErrors.errors.txt | 42 +- tests/baselines/reference/mappedTypeErrors.js | 10 +- tests/baselines/reference/mappedTypes1.js | 25 +- .../baselines/reference/mappedTypes1.symbols | 64 +- tests/baselines/reference/mappedTypes1.types | 24 +- tests/baselines/reference/mappedTypes2.js | 4 +- .../baselines/reference/mappedTypes2.symbols | 24 +- tests/baselines/reference/mappedTypes2.types | 6 +- 11 files changed, 400 insertions(+), 579 deletions(-) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index eef81f4d5f76d..017669603a46f 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -95,22 +95,18 @@ function f10(shape: Shape) { function f11(a: Shape[]) { let len = getProperty(a, "length"); // number - let shape = getProperty(a, 1000); // Shape - setProperty(a, 1000, getProperty(a, 1001)); + setProperty(a, "length", len); } function f12(t: [Shape, boolean]) { let len = getProperty(t, "length"); - let s1 = getProperty(t, 0); // Shape let s2 = getProperty(t, "0"); // Shape - let b1 = getProperty(t, 1); // boolean let b2 = getProperty(t, "1"); // boolean - let x1 = getProperty(t, 2); // Shape | boolean } function f13(foo: any, bar: any) { let x = getProperty(foo, "x"); // any - let y = getProperty(foo, 100); // any + let y = getProperty(foo, "100"); // any let z = getProperty(foo, bar); // any } @@ -181,20 +177,14 @@ function f40(c: C) { let z: Z = c["z"]; } -function f50(k: keyof T, s: string, n: number) { +function f50(k: keyof T, s: string) { const x1 = s as keyof T; - const x2 = n as keyof T; - const x3 = k as string; - const x4 = k as number; - const x5 = k as string | number; + const x2 = k as string; } -function f51(k: K, s: string, n: number) { +function f51(k: K, s: string) { const x1 = s as keyof T; - const x2 = n as keyof T; - const x3 = k as string; - const x4 = k as number; - const x5 = k as string | number; + const x2 = k as string; } function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { @@ -297,20 +287,16 @@ function f10(shape) { } function f11(a) { var len = getProperty(a, "length"); // number - var shape = getProperty(a, 1000); // Shape - setProperty(a, 1000, getProperty(a, 1001)); + setProperty(a, "length", len); } function f12(t) { var len = getProperty(t, "length"); - var s1 = getProperty(t, 0); // Shape var s2 = getProperty(t, "0"); // Shape - var b1 = getProperty(t, 1); // boolean var b2 = getProperty(t, "1"); // boolean - var x1 = getProperty(t, 2); // Shape | boolean } function f13(foo, bar) { var x = getProperty(foo, "x"); // any - var y = getProperty(foo, 100); // any + var y = getProperty(foo, "100"); // any var z = getProperty(foo, bar); // any } var Component = (function () { @@ -369,19 +355,13 @@ function f40(c) { var y = c["y"]; var z = c["z"]; } -function f50(k, s, n) { +function f50(k, s) { var x1 = s; - var x2 = n; - var x3 = k; - var x4 = k; - var x5 = k; + var x2 = k; } -function f51(k, s, n) { +function f51(k, s) { var x1 = s; - var x2 = n; - var x3 = k; - var x4 = k; - var x5 = k; + var x2 = k; } function f52(obj, k, s, n) { var x1 = obj[s]; @@ -528,8 +508,8 @@ declare class C { private z; } declare function f40(c: C): void; -declare function f50(k: keyof T, s: string, n: number): void; -declare function f51(k: K, s: string, n: number): void; +declare function f50(k: keyof T, s: string): void; +declare function f51(k: K, s: string): void; declare function f52(obj: { [x: string]: boolean; }, k: keyof T, s: string, n: number): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 0b10e368821bd..8a2f1052d137f 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -299,569 +299,520 @@ function f11(a: Shape[]) { >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) >a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) - let shape = getProperty(a, 1000); // Shape ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 96, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) - - setProperty(a, 1000, getProperty(a, 1001)); + setProperty(a, "length", len); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) >a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 95, 7)) } function f12(t: [Shape, boolean]) { ->f12 : Symbol(f12, Decl(keyofAndIndexedAccess.ts, 98, 1)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) +>f12 : Symbol(f12, Decl(keyofAndIndexedAccess.ts, 97, 1)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let len = getProperty(t, "length"); ->len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 101, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) - - let s1 = getProperty(t, 0); // Shape ->s1 : Symbol(s1, Decl(keyofAndIndexedAccess.ts, 102, 7)) +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 100, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) let s2 = getProperty(t, "0"); // Shape ->s2 : Symbol(s2, Decl(keyofAndIndexedAccess.ts, 103, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) - - let b1 = getProperty(t, 1); // boolean ->b1 : Symbol(b1, Decl(keyofAndIndexedAccess.ts, 104, 7)) +>s2 : Symbol(s2, Decl(keyofAndIndexedAccess.ts, 101, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) let b2 = getProperty(t, "1"); // boolean ->b2 : Symbol(b2, Decl(keyofAndIndexedAccess.ts, 105, 7)) +>b2 : Symbol(b2, Decl(keyofAndIndexedAccess.ts, 102, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) - - let x1 = getProperty(t, 2); // Shape | boolean ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 106, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) } function f13(foo: any, bar: any) { ->f13 : Symbol(f13, Decl(keyofAndIndexedAccess.ts, 107, 1)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) ->bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 109, 22)) +>f13 : Symbol(f13, Decl(keyofAndIndexedAccess.ts, 103, 1)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 105, 22)) let x = getProperty(foo, "x"); // any ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 110, 7)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 106, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) - let y = getProperty(foo, 100); // any ->y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 111, 7)) + let y = getProperty(foo, "100"); // any +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 107, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) let z = getProperty(foo, bar); // any ->z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 112, 7)) +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 108, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) ->bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 109, 22)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 105, 22)) } class Component { ->Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) props: PropType; ->props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) getProperty(key: K) { ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 117, 16)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 117, 42)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 117, 16)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 113, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 113, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 113, 16)) return this.props[key]; ->this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) ->this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) ->props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 117, 42)) +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 113, 42)) } setProperty(key: K, value: PropType[K]) { ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 120, 16)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 120, 42)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 120, 16)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 120, 49)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 120, 16)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 116, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 116, 49)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) this.props[key] = value; ->this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) ->this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) ->props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 120, 42)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 120, 49)) +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 116, 42)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 116, 49)) } } function f20(component: Component) { ->f20 : Symbol(f20, Decl(keyofAndIndexedAccess.ts, 123, 1)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) +>f20 : Symbol(f20, Decl(keyofAndIndexedAccess.ts, 119, 1)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let name = component.getProperty("name"); // string ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 126, 7)) ->component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 122, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number ->widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 127, 7)) ->component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 123, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) >cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean ->nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 128, 7)) ->component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 124, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) >cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) component.setProperty("name", "rectangle"); ->component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) component.setProperty(cond ? "width" : "height", 10) ->component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) >cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) component.setProperty(cond ? "name" : "visible", true); // Technically not safe ->component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) >cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) } function pluck(array: T[], key: K) { ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 134, 15)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 134, 17)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 134, 15)) ->array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 134, 37)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 134, 15)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 134, 48)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 134, 17)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 130, 17)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 130, 37)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 130, 48)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 130, 17)) return array.map(x => x[key]); >array.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 134, 37)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 130, 37)) >map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 135, 21)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 135, 21)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 134, 48)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 131, 21)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 131, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 130, 48)) } function f30(shapes: Shape[]) { ->f30 : Symbol(f30, Decl(keyofAndIndexedAccess.ts, 136, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) +>f30 : Symbol(f30, Decl(keyofAndIndexedAccess.ts, 132, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let names = pluck(shapes, "name"); // string[] ->names : Symbol(names, Decl(keyofAndIndexedAccess.ts, 139, 7)) ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) +>names : Symbol(names, Decl(keyofAndIndexedAccess.ts, 135, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) let widths = pluck(shapes, "width"); // number[] ->widths : Symbol(widths, Decl(keyofAndIndexedAccess.ts, 140, 7)) ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) +>widths : Symbol(widths, Decl(keyofAndIndexedAccess.ts, 136, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] ->nameOrVisibles : Symbol(nameOrVisibles, Decl(keyofAndIndexedAccess.ts, 141, 7)) ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) +>nameOrVisibles : Symbol(nameOrVisibles, Decl(keyofAndIndexedAccess.ts, 137, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) >cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) } function f31(key: K) { ->f31 : Symbol(f31, Decl(keyofAndIndexedAccess.ts, 142, 1)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 144, 13)) +>f31 : Symbol(f31, Decl(keyofAndIndexedAccess.ts, 138, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 140, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 144, 36)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 144, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 140, 36)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 140, 13)) const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 145, 9)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 141, 9)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 145, 26)) ->width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 145, 39)) ->height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 145, 49)) ->visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 145, 61)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 141, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 141, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 141, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 141, 61)) return shape[key]; // Shape[K] ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 145, 9)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 144, 36)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 141, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 140, 36)) } function f32(key: K) { ->f32 : Symbol(f32, Decl(keyofAndIndexedAccess.ts, 147, 1)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 149, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 149, 43)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 149, 13)) +>f32 : Symbol(f32, Decl(keyofAndIndexedAccess.ts, 143, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 145, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 145, 43)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 145, 13)) const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 9)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 146, 9)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 150, 26)) ->width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 150, 39)) ->height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 150, 49)) ->visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 150, 61)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 146, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 146, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 146, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 146, 61)) return shape[key]; // Shape[K] ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 9)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 149, 43)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 146, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 145, 43)) } function f33(shape: S, key: K) { ->f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 152, 1)) ->S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 154, 13)) +>f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 148, 1)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 150, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 154, 29)) ->S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 154, 13)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 154, 49)) ->S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 154, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 154, 58)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 154, 29)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 150, 29)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 150, 13)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 49)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 150, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 150, 58)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 150, 29)) let name = getProperty(shape, "name"); ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 155, 7)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 151, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 154, 49)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 49)) let prop = getProperty(shape, key); ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 156, 7)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 152, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 154, 49)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 154, 58)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 49)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 150, 58)) return prop; ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 156, 7)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 152, 7)) } function f34(ts: TaggedShape) { ->f34 : Symbol(f34, Decl(keyofAndIndexedAccess.ts, 158, 1)) ->ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 160, 13)) +>f34 : Symbol(f34, Decl(keyofAndIndexedAccess.ts, 154, 1)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 156, 13)) >TaggedShape : Symbol(TaggedShape, Decl(keyofAndIndexedAccess.ts, 6, 1)) let tag1 = f33(ts, "tag"); ->tag1 : Symbol(tag1, Decl(keyofAndIndexedAccess.ts, 161, 7)) ->f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 152, 1)) ->ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 160, 13)) +>tag1 : Symbol(tag1, Decl(keyofAndIndexedAccess.ts, 157, 7)) +>f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 148, 1)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 156, 13)) let tag2 = getProperty(ts, "tag"); ->tag2 : Symbol(tag2, Decl(keyofAndIndexedAccess.ts, 162, 7)) +>tag2 : Symbol(tag2, Decl(keyofAndIndexedAccess.ts, 158, 7)) >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 160, 13)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 156, 13)) } class C { ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) public x: string; ->x : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 165, 9)) +>x : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 161, 9)) protected y: string; ->y : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 166, 21)) +>y : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 162, 21)) private z: string; ->z : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 167, 24)) +>z : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 163, 24)) } // Indexed access expressions have always permitted access to private and protected members. // For consistency we also permit such access in indexed access types. function f40(c: C) { ->f40 : Symbol(f40, Decl(keyofAndIndexedAccess.ts, 169, 1)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) +>f40 : Symbol(f40, Decl(keyofAndIndexedAccess.ts, 165, 1)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) type X = C["x"]; ->X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 173, 20)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 169, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) type Y = C["y"]; ->Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 174, 20)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 170, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) type Z = C["z"]; ->Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 175, 20)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 171, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) let x: X = c["x"]; ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 177, 7)) ->X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 173, 20)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) ->"x" : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 165, 9)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 173, 7)) +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 169, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) +>"x" : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 161, 9)) let y: Y = c["y"]; ->y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 178, 7)) ->Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 174, 20)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) ->"y" : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 166, 21)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 174, 7)) +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 170, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) +>"y" : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 162, 21)) let z: Z = c["z"]; ->z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 179, 7)) ->Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 175, 20)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) ->"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 167, 24)) +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 175, 7)) +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 171, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) +>"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 163, 24)) } -function f50(k: keyof T, s: string, n: number) { ->f50 : Symbol(f50, Decl(keyofAndIndexedAccess.ts, 180, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 182, 27)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 182, 38)) +function f50(k: keyof T, s: string) { +>f50 : Symbol(f50, Decl(keyofAndIndexedAccess.ts, 176, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 178, 13)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 178, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 178, 13)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 178, 27)) const x1 = s as keyof T; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 183, 9)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 182, 27)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) - - const x2 = n as keyof T; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 184, 9)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 182, 38)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 182, 13)) - - const x3 = k as string; ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 185, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) - - const x4 = k as number; ->x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 186, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) - - const x5 = k as string | number; ->x5 : Symbol(x5, Decl(keyofAndIndexedAccess.ts, 187, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 182, 16)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 179, 9)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 178, 27)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 178, 13)) + + const x2 = k as string; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 180, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 178, 16)) } -function f51(k: K, s: string, n: number) { ->f51 : Symbol(f51, Decl(keyofAndIndexedAccess.ts, 188, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 190, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 190, 15)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 190, 40)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 190, 51)) +function f51(k: K, s: string) { +>f51 : Symbol(f51, Decl(keyofAndIndexedAccess.ts, 181, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 183, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 183, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 183, 13)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 183, 35)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 183, 15)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 183, 40)) const x1 = s as keyof T; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 191, 9)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 190, 40)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) - - const x2 = n as keyof T; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 192, 9)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 190, 51)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) - - const x3 = k as string; ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 193, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) - - const x4 = k as number; ->x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 194, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) - - const x5 = k as string | number; ->x5 : Symbol(x5, Decl(keyofAndIndexedAccess.ts, 195, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 35)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 184, 9)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 183, 40)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 183, 13)) + + const x2 = k as string; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 185, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 183, 35)) } function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { ->f52 : Symbol(f52, Decl(keyofAndIndexedAccess.ts, 196, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 198, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 198, 24)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 198, 46)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 198, 13)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 198, 58)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 198, 69)) +>f52 : Symbol(f52, Decl(keyofAndIndexedAccess.ts, 186, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 188, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 188, 24)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 188, 46)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 188, 13)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 188, 58)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 188, 69)) const x1 = obj[s]; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 199, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 198, 58)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 189, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 188, 58)) const x2 = obj[n]; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 200, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 198, 69)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 190, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 188, 69)) const x3 = obj[k]; ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 201, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 198, 16)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 198, 46)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 191, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 188, 46)) } function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { ->f53 : Symbol(f53, Decl(keyofAndIndexedAccess.ts, 202, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 204, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 204, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 204, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 204, 43)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 204, 65)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 204, 15)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 204, 71)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 204, 82)) +>f53 : Symbol(f53, Decl(keyofAndIndexedAccess.ts, 192, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 194, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 194, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 194, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 194, 43)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 194, 65)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 194, 15)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 194, 71)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 194, 82)) const x1 = obj[s]; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 205, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 204, 71)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 195, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 194, 71)) const x2 = obj[n]; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 206, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 204, 82)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 196, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 194, 82)) const x3 = obj[k]; ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 207, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 204, 35)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 204, 65)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 197, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 194, 65)) } function f54(obj: T, key: keyof T) { ->f54 : Symbol(f54, Decl(keyofAndIndexedAccess.ts, 208, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 210, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 210, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 210, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 210, 23)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 210, 13)) +>f54 : Symbol(f54, Decl(keyofAndIndexedAccess.ts, 198, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 200, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 200, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 200, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 200, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 200, 13)) for (let s in obj[key]) { ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 211, 12)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 210, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 210, 23)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 201, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 200, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 200, 23)) } const b = "foo" in obj[key]; ->b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 213, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 210, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 210, 23)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 203, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 200, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 200, 23)) } function f55(obj: T, key: K) { ->f55 : Symbol(f55, Decl(keyofAndIndexedAccess.ts, 214, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 216, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 216, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 216, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 216, 35)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 216, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 216, 42)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 216, 15)) +>f55 : Symbol(f55, Decl(keyofAndIndexedAccess.ts, 204, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 206, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 206, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 206, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 206, 35)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 206, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 206, 15)) for (let s in obj[key]) { ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 217, 12)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 216, 35)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 216, 42)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 207, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 206, 35)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) } const b = "foo" in obj[key]; ->b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 219, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 216, 35)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 216, 42)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 209, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 206, 35)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) } // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 224, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 225, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 225, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 225, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 225, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 227, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 228, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 228, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 228, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 228, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 228, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 228, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 228, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 231, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 233, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 223, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 235, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 220, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 227, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 231, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 227, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 235, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 238, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 228, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 224, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 231, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 224, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 242, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 244, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 234, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 246, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16)) setProperty(this, "parts", parts); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 242, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 246, 16)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 248, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 238, 5)) return getProperty(this, "parts") >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 242, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 020ac1141261e..4c09909c0fd5b 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -54,10 +54,10 @@ const enum E { A, B, C } >C : E.C type K00 = keyof any; // string | number ->K00 : string | number +>K00 : string type K01 = keyof string; // number | "toString" | "charAt" | ... ->K01 : number | "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" +>K01 : "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... >K02 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" @@ -83,11 +83,11 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible" >Shape : Shape type K11 = keyof Shape[]; // number | "length" | "toString" | ... ->K11 : number | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K11 : "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" >Shape : Shape type K12 = keyof Dictionary; // string | number ->K12 : string | number +>K12 : string >Dictionary : Dictionary >Shape : Shape @@ -103,7 +103,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... >E : E type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... ->K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K16 : "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" type K17 = keyof (Shape | Item); // "name" >K17 : "name" @@ -126,7 +126,7 @@ type K20 = KeyOf; // "name" | "width" | "height" | "visible" >Shape : Shape type K21 = KeyOf>; // string | number ->K21 : string | number +>K21 : string >KeyOf : keyof T >Dictionary : Dictionary >Shape : Shape @@ -328,22 +328,12 @@ function f11(a: Shape[]) { >a : Shape[] >"length" : "length" - let shape = getProperty(a, 1000); // Shape ->shape : Shape ->getProperty(a, 1000) : Shape ->getProperty : (obj: T, key: K) => T[K] ->a : Shape[] ->1000 : 1000 - - setProperty(a, 1000, getProperty(a, 1001)); ->setProperty(a, 1000, getProperty(a, 1001)) : void + setProperty(a, "length", len); +>setProperty(a, "length", len) : void >setProperty : (obj: T, key: K, value: T[K]) => void >a : Shape[] ->1000 : 1000 ->getProperty(a, 1001) : Shape ->getProperty : (obj: T, key: K) => T[K] ->a : Shape[] ->1001 : 1001 +>"length" : "length" +>len : number } function f12(t: [Shape, boolean]) { @@ -358,13 +348,6 @@ function f12(t: [Shape, boolean]) { >t : [Shape, boolean] >"length" : "length" - let s1 = getProperty(t, 0); // Shape ->s1 : Shape ->getProperty(t, 0) : Shape ->getProperty : (obj: T, key: K) => T[K] ->t : [Shape, boolean] ->0 : 0 - let s2 = getProperty(t, "0"); // Shape >s2 : Shape >getProperty(t, "0") : Shape @@ -372,26 +355,12 @@ function f12(t: [Shape, boolean]) { >t : [Shape, boolean] >"0" : "0" - let b1 = getProperty(t, 1); // boolean ->b1 : boolean ->getProperty(t, 1) : boolean ->getProperty : (obj: T, key: K) => T[K] ->t : [Shape, boolean] ->1 : 1 - let b2 = getProperty(t, "1"); // boolean >b2 : boolean >getProperty(t, "1") : boolean >getProperty : (obj: T, key: K) => T[K] >t : [Shape, boolean] >"1" : "1" - - let x1 = getProperty(t, 2); // Shape | boolean ->x1 : boolean | Shape ->getProperty(t, 2) : boolean | Shape ->getProperty : (obj: T, key: K) => T[K] ->t : [Shape, boolean] ->2 : 2 } function f13(foo: any, bar: any) { @@ -406,12 +375,12 @@ function f13(foo: any, bar: any) { >foo : any >"x" : "x" - let y = getProperty(foo, 100); // any + let y = getProperty(foo, "100"); // any >y : any ->getProperty(foo, 100) : any +>getProperty(foo, "100") : any >getProperty : (obj: T, key: K) => T[K] >foo : any ->100 : 100 +>"100" : "100" let z = getProperty(foo, bar); // any >z : any @@ -737,13 +706,12 @@ function f40(c: C) { >"z" : "z" } -function f50(k: keyof T, s: string, n: number) { ->f50 : (k: keyof T, s: string, n: number) => void +function f50(k: keyof T, s: string) { +>f50 : (k: keyof T, s: string) => void >T : T >k : keyof T >T : T >s : string ->n : number const x1 = s as keyof T; >x1 : keyof T @@ -751,37 +719,20 @@ function f50(k: keyof T, s: string, n: number) { >s : string >T : T - const x2 = n as keyof T; ->x2 : keyof T ->n as keyof T : keyof T ->n : number ->T : T - - const x3 = k as string; ->x3 : string + const x2 = k as string; +>x2 : string >k as string : string ->k : keyof T - - const x4 = k as number; ->x4 : number ->k as number : number ->k : keyof T - - const x5 = k as string | number; ->x5 : string | number ->k as string | number : string | number >k : keyof T } -function f51(k: K, s: string, n: number) { ->f51 : (k: K, s: string, n: number) => void +function f51(k: K, s: string) { +>f51 : (k: K, s: string) => void >T : T >K : K >T : T >k : K >K : K >s : string ->n : number const x1 = s as keyof T; >x1 : keyof T @@ -789,25 +740,9 @@ function f51(k: K, s: string, n: number) { >s : string >T : T - const x2 = n as keyof T; ->x2 : keyof T ->n as keyof T : keyof T ->n : number ->T : T - - const x3 = k as string; ->x3 : string + const x2 = k as string; +>x2 : string >k as string : string ->k : K - - const x4 = k as number; ->x4 : number ->k as number : number ->k : K - - const x5 = k as string | number; ->x5 : string | number ->k as string | number : string | number >k : K } diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index 0e1198285baa8..b3cba7eb54d6a 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -1,29 +1,28 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(20,20): error TS2313: Type parameter 'P' has a circular constraint. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(21,20): error TS2322: Type 'Date' is not assignable to type 'string | number'. - Type 'Date' is not assignable to type 'number'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(22,19): error TS2344: Type 'Date' does not satisfy the constraint 'string | number'. - Type 'Date' is not assignable to type 'number'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(25,24): error TS2344: Type '"foo"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(26,24): error TS2344: Type '"name" | "foo"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(21,20): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(22,20): error TS2322: Type 'Date' is not assignable to type 'string'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(23,19): error TS2344: Type 'Date' does not satisfy the constraint 'string'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(26,24): error TS2344: Type '"foo"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(27,24): error TS2344: Type '"name" | "foo"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. Type '"foo"' is not assignable to type '"name" | "width" | "height" | "visible"'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(28,24): error TS2344: Type '"x" | "y"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(29,24): error TS2344: Type '"x" | "y"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. Type '"x"' is not assignable to type '"name" | "width" | "height" | "visible"'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(30,24): error TS2344: Type 'undefined' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(33,24): error TS2344: Type 'T' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(31,24): error TS2344: Type 'undefined' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(34,24): error TS2344: Type 'T' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. Type 'T' is not assignable to type '"visible"'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(37,24): error TS2344: Type 'T' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(38,24): error TS2344: Type 'T' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. Type 'string | number' is not assignable to type '"name" | "width" | "height" | "visible"'. Type 'string' is not assignable to type '"name" | "width" | "height" | "visible"'. Type 'T' is not assignable to type '"visible"'. Type 'string | number' is not assignable to type '"visible"'. Type 'string' is not assignable to type '"visible"'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(59,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ [P in keyof T]?: T[P]; }'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(60,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ readonly [P in keyof T]: T[P]; }'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(61,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ readonly [P in keyof T]?: T[P]; }'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(66,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ [P in keyof T]: T[P][]; }'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(60,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ [P in keyof T]?: T[P]; }'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(61,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ readonly [P in keyof T]: T[P]; }'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(62,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ readonly [P in keyof T]?: T[P]; }'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(67,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ [P in keyof T]: T[P][]; }'. -==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (13 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (14 errors) ==== interface Shape { name: string; @@ -46,14 +45,15 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(66,9): error TS2403: Su type T00 = { [P in P]: string }; // Error ~ !!! error TS2313: Type parameter 'P' has a circular constraint. - type T01 = { [P in Date]: number }; // Error + type T01 = { [P in number]: string }; // Error + ~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + type T02 = { [P in Date]: number }; // Error ~~~~ -!!! error TS2322: Type 'Date' is not assignable to type 'string | number'. -!!! error TS2322: Type 'Date' is not assignable to type 'number'. - type T02 = Record; // Error +!!! error TS2322: Type 'Date' is not assignable to type 'string'. + type T03 = Record; // Error ~~~~ -!!! error TS2344: Type 'Date' does not satisfy the constraint 'string | number'. -!!! error TS2344: Type 'Date' is not assignable to type 'number'. +!!! error TS2344: Type 'Date' does not satisfy the constraint 'string'. type T10 = Pick; type T11 = Pick; // Error diff --git a/tests/baselines/reference/mappedTypeErrors.js b/tests/baselines/reference/mappedTypeErrors.js index fe03b5c959374..cb840da32f7ba 100644 --- a/tests/baselines/reference/mappedTypeErrors.js +++ b/tests/baselines/reference/mappedTypeErrors.js @@ -19,8 +19,9 @@ interface Point { // Constraint checking type T00 = { [P in P]: string }; // Error -type T01 = { [P in Date]: number }; // Error -type T02 = Record; // Error +type T01 = { [P in number]: string }; // Error +type T02 = { [P in Date]: number }; // Error +type T03 = Record; // Error type T10 = Pick; type T11 = Pick; // Error @@ -116,9 +117,12 @@ declare type T00 = { [P in P]: string; }; declare type T01 = { + [P in number]: string; +}; +declare type T02 = { [P in Date]: number; }; -declare type T02 = Record; +declare type T03 = Record; declare type T10 = Pick; declare type T11 = Pick; declare type T12 = Pick; diff --git a/tests/baselines/reference/mappedTypes1.js b/tests/baselines/reference/mappedTypes1.js index 71a8d5abb67e2..a172b637d1c8e 100644 --- a/tests/baselines/reference/mappedTypes1.js +++ b/tests/baselines/reference/mappedTypes1.js @@ -26,13 +26,9 @@ type T37 = { [P in keyof symbol]: void }; type T38 = { [P in keyof never]: void }; type T40 = { [P in string]: void }; -type T41 = { [P in number]: void }; -type T42 = { [P in string | number]: void }; -type T43 = { [P in "a" | "b" | 0 | 1]: void }; +type T43 = { [P in "a" | "b"]: void }; type T44 = { [P in "a" | "b" | "0" | "1"]: void }; -type T45 = { [P in "a" | "b" | "0" | "1" | 0 | 1]: void }; -type T46 = { [P in number | "a" | "b" | 0 | 1]: void }; -type T47 = { [P in string | number | "a" | "b" | 0 | 1]: void }; +type T47 = { [P in string | "a" | "b" | "0" | "1"]: void }; declare function f1(): { [P in keyof T1]: void }; declare function f2(): { [P in keyof T1]: void }; @@ -114,26 +110,14 @@ declare type T38 = { declare type T40 = { [P in string]: void; }; -declare type T41 = { - [P in number]: void; -}; -declare type T42 = { - [P in string | number]: void; -}; declare type T43 = { - [P in "a" | "b" | 0 | 1]: void; + [P in "a" | "b"]: void; }; declare type T44 = { [P in "a" | "b" | "0" | "1"]: void; }; -declare type T45 = { - [P in "a" | "b" | "0" | "1" | 0 | 1]: void; -}; -declare type T46 = { - [P in number | "a" | "b" | 0 | 1]: void; -}; declare type T47 = { - [P in string | number | "a" | "b" | 0 | 1]: void; + [P in string | "a" | "b" | "0" | "1"]: void; }; declare function f1(): { [P in keyof T1]: void; @@ -146,7 +130,6 @@ declare function f3(): { }; declare let x1: {}; declare let x2: { - [x: number]: void; toString: void; charAt: void; charCodeAt: void; diff --git a/tests/baselines/reference/mappedTypes1.symbols b/tests/baselines/reference/mappedTypes1.symbols index 908fbb3b0e1ae..88ced68aa0e5b 100644 --- a/tests/baselines/reference/mappedTypes1.symbols +++ b/tests/baselines/reference/mappedTypes1.symbols @@ -110,61 +110,45 @@ type T40 = { [P in string]: void }; >T40 : Symbol(T40, Decl(mappedTypes1.ts, 24, 40)) >P : Symbol(P, Decl(mappedTypes1.ts, 26, 14)) -type T41 = { [P in number]: void }; ->T41 : Symbol(T41, Decl(mappedTypes1.ts, 26, 35)) +type T43 = { [P in "a" | "b"]: void }; +>T43 : Symbol(T43, Decl(mappedTypes1.ts, 26, 35)) >P : Symbol(P, Decl(mappedTypes1.ts, 27, 14)) -type T42 = { [P in string | number]: void }; ->T42 : Symbol(T42, Decl(mappedTypes1.ts, 27, 35)) +type T44 = { [P in "a" | "b" | "0" | "1"]: void }; +>T44 : Symbol(T44, Decl(mappedTypes1.ts, 27, 38)) >P : Symbol(P, Decl(mappedTypes1.ts, 28, 14)) -type T43 = { [P in "a" | "b" | 0 | 1]: void }; ->T43 : Symbol(T43, Decl(mappedTypes1.ts, 28, 44)) +type T47 = { [P in string | "a" | "b" | "0" | "1"]: void }; +>T47 : Symbol(T47, Decl(mappedTypes1.ts, 28, 50)) >P : Symbol(P, Decl(mappedTypes1.ts, 29, 14)) -type T44 = { [P in "a" | "b" | "0" | "1"]: void }; ->T44 : Symbol(T44, Decl(mappedTypes1.ts, 29, 46)) ->P : Symbol(P, Decl(mappedTypes1.ts, 30, 14)) - -type T45 = { [P in "a" | "b" | "0" | "1" | 0 | 1]: void }; ->T45 : Symbol(T45, Decl(mappedTypes1.ts, 30, 50)) ->P : Symbol(P, Decl(mappedTypes1.ts, 31, 14)) - -type T46 = { [P in number | "a" | "b" | 0 | 1]: void }; ->T46 : Symbol(T46, Decl(mappedTypes1.ts, 31, 58)) ->P : Symbol(P, Decl(mappedTypes1.ts, 32, 14)) - -type T47 = { [P in string | number | "a" | "b" | 0 | 1]: void }; ->T47 : Symbol(T47, Decl(mappedTypes1.ts, 32, 55)) ->P : Symbol(P, Decl(mappedTypes1.ts, 33, 14)) - declare function f1(): { [P in keyof T1]: void }; ->f1 : Symbol(f1, Decl(mappedTypes1.ts, 33, 64)) ->T1 : Symbol(T1, Decl(mappedTypes1.ts, 35, 20)) ->P : Symbol(P, Decl(mappedTypes1.ts, 35, 30)) ->T1 : Symbol(T1, Decl(mappedTypes1.ts, 35, 20)) +>f1 : Symbol(f1, Decl(mappedTypes1.ts, 29, 59)) +>T1 : Symbol(T1, Decl(mappedTypes1.ts, 31, 20)) +>P : Symbol(P, Decl(mappedTypes1.ts, 31, 30)) +>T1 : Symbol(T1, Decl(mappedTypes1.ts, 31, 20)) declare function f2(): { [P in keyof T1]: void }; ->f2 : Symbol(f2, Decl(mappedTypes1.ts, 35, 53)) ->T1 : Symbol(T1, Decl(mappedTypes1.ts, 36, 20)) ->P : Symbol(P, Decl(mappedTypes1.ts, 36, 45)) ->T1 : Symbol(T1, Decl(mappedTypes1.ts, 36, 20)) +>f2 : Symbol(f2, Decl(mappedTypes1.ts, 31, 53)) +>T1 : Symbol(T1, Decl(mappedTypes1.ts, 32, 20)) +>P : Symbol(P, Decl(mappedTypes1.ts, 32, 45)) +>T1 : Symbol(T1, Decl(mappedTypes1.ts, 32, 20)) declare function f3(): { [P in keyof T1]: void }; ->f3 : Symbol(f3, Decl(mappedTypes1.ts, 36, 68)) ->T1 : Symbol(T1, Decl(mappedTypes1.ts, 37, 20)) ->P : Symbol(P, Decl(mappedTypes1.ts, 37, 45)) ->T1 : Symbol(T1, Decl(mappedTypes1.ts, 37, 20)) +>f3 : Symbol(f3, Decl(mappedTypes1.ts, 32, 68)) +>T1 : Symbol(T1, Decl(mappedTypes1.ts, 33, 20)) +>P : Symbol(P, Decl(mappedTypes1.ts, 33, 45)) +>T1 : Symbol(T1, Decl(mappedTypes1.ts, 33, 20)) let x1 = f1(); ->x1 : Symbol(x1, Decl(mappedTypes1.ts, 39, 3)) ->f1 : Symbol(f1, Decl(mappedTypes1.ts, 33, 64)) +>x1 : Symbol(x1, Decl(mappedTypes1.ts, 35, 3)) +>f1 : Symbol(f1, Decl(mappedTypes1.ts, 29, 59)) let x2 = f2(); ->x2 : Symbol(x2, Decl(mappedTypes1.ts, 40, 3)) ->f2 : Symbol(f2, Decl(mappedTypes1.ts, 35, 53)) +>x2 : Symbol(x2, Decl(mappedTypes1.ts, 36, 3)) +>f2 : Symbol(f2, Decl(mappedTypes1.ts, 31, 53)) let x3 = f3(); ->x3 : Symbol(x3, Decl(mappedTypes1.ts, 41, 3)) ->f3 : Symbol(f3, Decl(mappedTypes1.ts, 36, 68)) +>x3 : Symbol(x3, Decl(mappedTypes1.ts, 37, 3)) +>f3 : Symbol(f3, Decl(mappedTypes1.ts, 32, 68)) diff --git a/tests/baselines/reference/mappedTypes1.types b/tests/baselines/reference/mappedTypes1.types index 06aeaa8962130..6886810c3943a 100644 --- a/tests/baselines/reference/mappedTypes1.types +++ b/tests/baselines/reference/mappedTypes1.types @@ -112,15 +112,7 @@ type T40 = { [P in string]: void }; >T40 : T40 >P : P -type T41 = { [P in number]: void }; ->T41 : T41 ->P : P - -type T42 = { [P in string | number]: void }; ->T42 : T42 ->P : P - -type T43 = { [P in "a" | "b" | 0 | 1]: void }; +type T43 = { [P in "a" | "b"]: void }; >T43 : T43 >P : P @@ -128,15 +120,7 @@ type T44 = { [P in "a" | "b" | "0" | "1"]: void }; >T44 : T44 >P : P -type T45 = { [P in "a" | "b" | "0" | "1" | 0 | 1]: void }; ->T45 : T45 ->P : P - -type T46 = { [P in number | "a" | "b" | 0 | 1]: void }; ->T46 : T46 ->P : P - -type T47 = { [P in string | number | "a" | "b" | 0 | 1]: void }; +type T47 = { [P in string | "a" | "b" | "0" | "1"]: void }; >T47 : T47 >P : P @@ -164,8 +148,8 @@ let x1 = f1(); >f1 : () => { [P in keyof T1]: void; } let x2 = f2(); ->x2 : { [x: number]: void; toString: void; charAt: void; charCodeAt: void; concat: void; indexOf: void; lastIndexOf: void; localeCompare: void; match: void; replace: void; search: void; slice: void; split: void; substring: void; toLowerCase: void; toLocaleLowerCase: void; toUpperCase: void; toLocaleUpperCase: void; trim: void; length: void; substr: void; valueOf: void; } ->f2() : { [x: number]: void; toString: void; charAt: void; charCodeAt: void; concat: void; indexOf: void; lastIndexOf: void; localeCompare: void; match: void; replace: void; search: void; slice: void; split: void; substring: void; toLowerCase: void; toLocaleLowerCase: void; toUpperCase: void; toLocaleUpperCase: void; trim: void; length: void; substr: void; valueOf: void; } +>x2 : { toString: void; charAt: void; charCodeAt: void; concat: void; indexOf: void; lastIndexOf: void; localeCompare: void; match: void; replace: void; search: void; slice: void; split: void; substring: void; toLowerCase: void; toLocaleLowerCase: void; toUpperCase: void; toLocaleUpperCase: void; trim: void; length: void; substr: void; valueOf: void; } +>f2() : { toString: void; charAt: void; charCodeAt: void; concat: void; indexOf: void; lastIndexOf: void; localeCompare: void; match: void; replace: void; search: void; slice: void; split: void; substring: void; toLowerCase: void; toLocaleLowerCase: void; toUpperCase: void; toLocaleUpperCase: void; trim: void; length: void; substr: void; valueOf: void; } >f2 : () => { [P in keyof T1]: void; } let x3 = f3(); diff --git a/tests/baselines/reference/mappedTypes2.js b/tests/baselines/reference/mappedTypes2.js index 25bb3fb6ded81..580cb36c74163 100644 --- a/tests/baselines/reference/mappedTypes2.js +++ b/tests/baselines/reference/mappedTypes2.js @@ -27,7 +27,7 @@ type DeepReadonly = { declare function assign(obj: T, props: Partial): void; declare function freeze(obj: T): Readonly; declare function pick(obj: T, ...keys: K[]): Pick; -declare function mapObject(obj: Record, f: (x: T) => U): Record; +declare function mapObject(obj: Record, f: (x: T) => U): Record; declare function proxify(obj: T): Proxify; interface Shape { @@ -148,7 +148,7 @@ declare type DeepReadonly = { declare function assign(obj: T, props: Partial): void; declare function freeze(obj: T): Readonly; declare function pick(obj: T, ...keys: K[]): Pick; -declare function mapObject(obj: Record, f: (x: T) => U): Record; +declare function mapObject(obj: Record, f: (x: T) => U): Record; declare function proxify(obj: T): Proxify; interface Shape { name: string; diff --git a/tests/baselines/reference/mappedTypes2.symbols b/tests/baselines/reference/mappedTypes2.symbols index a610658869e0a..1b6fe299140eb 100644 --- a/tests/baselines/reference/mappedTypes2.symbols +++ b/tests/baselines/reference/mappedTypes2.symbols @@ -126,25 +126,25 @@ declare function pick(obj: T, ...keys: K[]): Pick; >T : Symbol(T, Decl(mappedTypes2.ts, 27, 22)) >K : Symbol(K, Decl(mappedTypes2.ts, 27, 24)) -declare function mapObject(obj: Record, f: (x: T) => U): Record; +declare function mapObject(obj: Record, f: (x: T) => U): Record; >mapObject : Symbol(mapObject, Decl(mappedTypes2.ts, 27, 78)) >K : Symbol(K, Decl(mappedTypes2.ts, 28, 27)) ->T : Symbol(T, Decl(mappedTypes2.ts, 28, 53)) ->U : Symbol(U, Decl(mappedTypes2.ts, 28, 56)) ->obj : Symbol(obj, Decl(mappedTypes2.ts, 28, 60)) +>T : Symbol(T, Decl(mappedTypes2.ts, 28, 44)) +>U : Symbol(U, Decl(mappedTypes2.ts, 28, 47)) +>obj : Symbol(obj, Decl(mappedTypes2.ts, 28, 51)) >Record : Symbol(Record, Decl(lib.d.ts, --, --)) >K : Symbol(K, Decl(mappedTypes2.ts, 28, 27)) ->T : Symbol(T, Decl(mappedTypes2.ts, 28, 53)) ->f : Symbol(f, Decl(mappedTypes2.ts, 28, 78)) ->x : Symbol(x, Decl(mappedTypes2.ts, 28, 83)) ->T : Symbol(T, Decl(mappedTypes2.ts, 28, 53)) ->U : Symbol(U, Decl(mappedTypes2.ts, 28, 56)) +>T : Symbol(T, Decl(mappedTypes2.ts, 28, 44)) +>f : Symbol(f, Decl(mappedTypes2.ts, 28, 69)) +>x : Symbol(x, Decl(mappedTypes2.ts, 28, 74)) +>T : Symbol(T, Decl(mappedTypes2.ts, 28, 44)) +>U : Symbol(U, Decl(mappedTypes2.ts, 28, 47)) >Record : Symbol(Record, Decl(lib.d.ts, --, --)) >K : Symbol(K, Decl(mappedTypes2.ts, 28, 27)) ->U : Symbol(U, Decl(mappedTypes2.ts, 28, 56)) +>U : Symbol(U, Decl(mappedTypes2.ts, 28, 47)) declare function proxify(obj: T): Proxify; ->proxify : Symbol(proxify, Decl(mappedTypes2.ts, 28, 109)) +>proxify : Symbol(proxify, Decl(mappedTypes2.ts, 28, 100)) >T : Symbol(T, Decl(mappedTypes2.ts, 29, 25)) >obj : Symbol(obj, Decl(mappedTypes2.ts, 29, 28)) >T : Symbol(T, Decl(mappedTypes2.ts, 29, 25)) @@ -295,7 +295,7 @@ function f5(shape: Shape) { const p = proxify(shape); >p : Symbol(p, Decl(mappedTypes2.ts, 79, 9)) ->proxify : Symbol(proxify, Decl(mappedTypes2.ts, 28, 109)) +>proxify : Symbol(proxify, Decl(mappedTypes2.ts, 28, 100)) >shape : Symbol(shape, Decl(mappedTypes2.ts, 78, 12)) let name = p.name.get(); diff --git a/tests/baselines/reference/mappedTypes2.types b/tests/baselines/reference/mappedTypes2.types index 8c487288a6f22..14ca77e46809c 100644 --- a/tests/baselines/reference/mappedTypes2.types +++ b/tests/baselines/reference/mappedTypes2.types @@ -126,8 +126,8 @@ declare function pick(obj: T, ...keys: K[]): Pick; >T : T >K : K -declare function mapObject(obj: Record, f: (x: T) => U): Record; ->mapObject : (obj: Record, f: (x: T) => U) => Record +declare function mapObject(obj: Record, f: (x: T) => U): Record; +>mapObject : (obj: Record, f: (x: T) => U) => Record >K : K >T : T >U : U @@ -297,7 +297,7 @@ function f4() { const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number } >lengths : Record<"foo" | "bar" | "baz", number> >mapObject(rec, s => s.length) : Record<"foo" | "bar" | "baz", number> ->mapObject : (obj: Record, f: (x: T) => U) => Record +>mapObject : (obj: Record, f: (x: T) => U) => Record >rec : { foo: string; bar: string; baz: string; } >s => s.length : (s: string) => number >s : string From 4c6b94f16fbf9752181178a95bb3f53e9d2f6ef2 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 21 Nov 2016 12:52:13 -0800 Subject: [PATCH 39/46] wrap subexpressions of conditional expressions in parens if necessary (#12420) --- src/compiler/factory.ts | 17 ++++++++--- .../commaOperatorInConditionalExpression.js | 14 +++++++++ ...mmaOperatorInConditionalExpression.symbols | 18 +++++++++++ ...commaOperatorInConditionalExpression.types | 30 +++++++++++++++++++ .../commaOperatorInConditionalExpression.ts | 5 ++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/commaOperatorInConditionalExpression.js create mode 100644 tests/baselines/reference/commaOperatorInConditionalExpression.symbols create mode 100644 tests/baselines/reference/commaOperatorInConditionalExpression.types create mode 100644 tests/cases/compiler/commaOperatorInConditionalExpression.ts diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index d797fff92f4d5..63333dbe0b2df 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -654,16 +654,16 @@ namespace ts { if (whenFalse) { // second overload node.questionToken = questionTokenOrWhenTrue; - node.whenTrue = whenTrueOrWhenFalse; + node.whenTrue = parenthesizeSubexpressionOfConditionalExpression(whenTrueOrWhenFalse); node.colonToken = colonTokenOrLocation; - node.whenFalse = whenFalse; + node.whenFalse = parenthesizeSubexpressionOfConditionalExpression(whenFalse); } else { // first overload node.questionToken = createToken(SyntaxKind.QuestionToken); - node.whenTrue = questionTokenOrWhenTrue; + node.whenTrue = parenthesizeSubexpressionOfConditionalExpression(questionTokenOrWhenTrue); node.colonToken = createToken(SyntaxKind.ColonToken); - node.whenFalse = whenTrueOrWhenFalse; + node.whenFalse = parenthesizeSubexpressionOfConditionalExpression(whenTrueOrWhenFalse); } return node; } @@ -2381,6 +2381,15 @@ namespace ts { return condition; } + function parenthesizeSubexpressionOfConditionalExpression(e: Expression): Expression { + // per ES grammar both 'whenTrue' and 'whenFalse' parts of conditional expression are assignment expressions + // so in case when comma expression is introduced as a part of previous transformations + // if should be wrapped in parens since comma operator has the lowest precedence + return e.kind === SyntaxKind.BinaryExpression && (e).operatorToken.kind === SyntaxKind.CommaToken + ? createParen(e) + : e; + } + /** * Wraps an expression in parentheses if it is needed in order to use the expression * as the expression of a NewExpression node. diff --git a/tests/baselines/reference/commaOperatorInConditionalExpression.js b/tests/baselines/reference/commaOperatorInConditionalExpression.js new file mode 100644 index 0000000000000..be1705936e410 --- /dev/null +++ b/tests/baselines/reference/commaOperatorInConditionalExpression.js @@ -0,0 +1,14 @@ +//// [commaOperatorInConditionalExpression.ts] +function f (m: string) { + [1, 2, 3].map(i => { + return true? { [m]: i } : { [m]: i + 1 } + }) +} + +//// [commaOperatorInConditionalExpression.js] +function f(m) { + [1, 2, 3].map(function (i) { + return true ? (_a = {}, _a[m] = i, _a) : (_b = {}, _b[m] = i + 1, _b); + var _a, _b; + }); +} diff --git a/tests/baselines/reference/commaOperatorInConditionalExpression.symbols b/tests/baselines/reference/commaOperatorInConditionalExpression.symbols new file mode 100644 index 0000000000000..18f749c5c5ceb --- /dev/null +++ b/tests/baselines/reference/commaOperatorInConditionalExpression.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/commaOperatorInConditionalExpression.ts === +function f (m: string) { +>f : Symbol(f, Decl(commaOperatorInConditionalExpression.ts, 0, 0)) +>m : Symbol(m, Decl(commaOperatorInConditionalExpression.ts, 0, 12)) + + [1, 2, 3].map(i => { +>[1, 2, 3].map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>i : Symbol(i, Decl(commaOperatorInConditionalExpression.ts, 1, 18)) + + return true? { [m]: i } : { [m]: i + 1 } +>m : Symbol(m, Decl(commaOperatorInConditionalExpression.ts, 0, 12)) +>i : Symbol(i, Decl(commaOperatorInConditionalExpression.ts, 1, 18)) +>m : Symbol(m, Decl(commaOperatorInConditionalExpression.ts, 0, 12)) +>i : Symbol(i, Decl(commaOperatorInConditionalExpression.ts, 1, 18)) + + }) +} diff --git a/tests/baselines/reference/commaOperatorInConditionalExpression.types b/tests/baselines/reference/commaOperatorInConditionalExpression.types new file mode 100644 index 0000000000000..f46282f9b6b9e --- /dev/null +++ b/tests/baselines/reference/commaOperatorInConditionalExpression.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commaOperatorInConditionalExpression.ts === +function f (m: string) { +>f : (m: string) => void +>m : string + + [1, 2, 3].map(i => { +>[1, 2, 3].map(i => { return true? { [m]: i } : { [m]: i + 1 } }) : { [x: string]: number; }[] +>[1, 2, 3].map : { (this: [number, number, number, number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [number, number, number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U, U, U]; (this: [number, number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U, U]; (this: [number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): U[]; } +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>map : { (this: [number, number, number, number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [number, number, number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U, U, U]; (this: [number, number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U, U]; (this: [number, number], callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): U[]; } +>i => { return true? { [m]: i } : { [m]: i + 1 } } : (i: number) => { [x: string]: number; } +>i : number + + return true? { [m]: i } : { [m]: i + 1 } +>true? { [m]: i } : { [m]: i + 1 } : { [x: string]: number; } +>true : true +>{ [m]: i } : { [x: string]: number; } +>m : string +>i : number +>{ [m]: i + 1 } : { [x: string]: number; } +>m : string +>i + 1 : number +>i : number +>1 : 1 + + }) +} diff --git a/tests/cases/compiler/commaOperatorInConditionalExpression.ts b/tests/cases/compiler/commaOperatorInConditionalExpression.ts new file mode 100644 index 0000000000000..a65d8ba18827d --- /dev/null +++ b/tests/cases/compiler/commaOperatorInConditionalExpression.ts @@ -0,0 +1,5 @@ +function f (m: string) { + [1, 2, 3].map(i => { + return true? { [m]: i } : { [m]: i + 1 } + }) +} \ No newline at end of file From 1710df5f28fed8dfa7630978c873ed1bf6ee3983 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 12:56:32 -0800 Subject: [PATCH 40/46] Type of for-in variable is keyof T when object type is a type parameter --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3c8c0be77c709..89daf7ea0cb5e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3216,11 +3216,11 @@ namespace ts { } } - // A variable declared in a for..in statement is always of type string + // A variable declared in a for..in statement is of type string, or of type keyof T when the + // right hand expression is of a type parameter type. if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { - // const indexType = getIndexType(checkNonNullExpression((declaration.parent.parent).expression)); - // return indexType.flags & TypeFlags.Index ? indexType : stringType; - return stringType; + const indexType = getIndexType(checkNonNullExpression((declaration.parent.parent).expression)); + return indexType.flags & TypeFlags.Index ? indexType : stringType; } if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { From dbc661f88e62ce06c44a6b67b13da40dbf668d10 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 12:57:43 -0800 Subject: [PATCH 41/46] Accept new baselines --- tests/baselines/reference/for-inStatements.errors.txt | 8 +++++++- .../reference/for-inStatementsInvalid.errors.txt | 8 +++++++- tests/baselines/reference/forInStatement3.types | 2 +- tests/baselines/reference/implicitAnyInCatch.types | 2 +- tests/baselines/reference/inOperatorWithGeneric.types | 2 +- .../reference/parserES5ForOfStatement19.errors.txt | 7 ------- .../baselines/reference/parserES5ForOfStatement19.symbols | 5 +++++ tests/baselines/reference/parserES5ForOfStatement19.types | 5 +++++ .../reference/parserES5ForOfStatement20.errors.txt | 7 ++----- .../baselines/reference/parserForOfStatement19.errors.txt | 7 ------- tests/baselines/reference/parserForOfStatement19.symbols | 5 +++++ tests/baselines/reference/parserForOfStatement19.types | 5 +++++ .../baselines/reference/parserForOfStatement20.errors.txt | 7 ++----- tests/baselines/reference/recursiveLetConst.errors.txt | 5 +---- 14 files changed, 42 insertions(+), 33 deletions(-) delete mode 100644 tests/baselines/reference/parserES5ForOfStatement19.errors.txt create mode 100644 tests/baselines/reference/parserES5ForOfStatement19.symbols create mode 100644 tests/baselines/reference/parserES5ForOfStatement19.types delete mode 100644 tests/baselines/reference/parserForOfStatement19.errors.txt create mode 100644 tests/baselines/reference/parserForOfStatement19.symbols create mode 100644 tests/baselines/reference/parserForOfStatement19.types diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index f0e6c950ebb0f..c5ca29d21500b 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -1,7 +1,9 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(33,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(50,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. -==== tests/cases/conformance/statements/for-inStatements/for-inStatements.ts (1 errors) ==== +==== tests/cases/conformance/statements/for-inStatements/for-inStatements.ts (3 errors) ==== var aString: string; for (aString in {}) { } @@ -35,6 +37,8 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in this.biz()) { } for (var x in this.biz) { } for (var x in this) { } + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. return null; } @@ -52,6 +56,8 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in this.biz()) { } for (var x in this.biz) { } for (var x in this) { } + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. for (var x in super.biz) { } for (var x in super.biz()) { } diff --git a/tests/baselines/reference/for-inStatementsInvalid.errors.txt b/tests/baselines/reference/for-inStatementsInvalid.errors.txt index 00ab58ab94da1..f98349973a368 100644 --- a/tests/baselines/reference/for-inStatementsInvalid.errors.txt +++ b/tests/baselines/reference/for-inStatementsInvalid.errors.txt @@ -9,13 +9,15 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(1 tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(20,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(22,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(29,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(31,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(38,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(46,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(48,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(51,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(62,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. -==== tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts (15 errors) ==== +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts (17 errors) ==== var aNumber: number; for (aNumber in {}) { } ~~~~~~~ @@ -69,6 +71,8 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. for (var x in this.biz) { } for (var x in this) { } + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. return null; } @@ -90,6 +94,8 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. for (var x in this.biz) { } for (var x in this) { } + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. for (var x in super.biz) { } for (var x in super.biz()) { } diff --git a/tests/baselines/reference/forInStatement3.types b/tests/baselines/reference/forInStatement3.types index d3767790ed2e3..09e6cf3ad9668 100644 --- a/tests/baselines/reference/forInStatement3.types +++ b/tests/baselines/reference/forInStatement3.types @@ -8,7 +8,7 @@ function F() { >T : T for (var a in expr) { ->a : string +>a : keyof T >expr : T } } diff --git a/tests/baselines/reference/implicitAnyInCatch.types b/tests/baselines/reference/implicitAnyInCatch.types index d2a1be4a910bf..93cce09928e00 100644 --- a/tests/baselines/reference/implicitAnyInCatch.types +++ b/tests/baselines/reference/implicitAnyInCatch.types @@ -22,7 +22,7 @@ class C { >temp : () => void for (var x in this) { ->x : string +>x : keyof this >this : this } } diff --git a/tests/baselines/reference/inOperatorWithGeneric.types b/tests/baselines/reference/inOperatorWithGeneric.types index facdb7b50e246..eba9bf1419b5c 100644 --- a/tests/baselines/reference/inOperatorWithGeneric.types +++ b/tests/baselines/reference/inOperatorWithGeneric.types @@ -9,7 +9,7 @@ class C { >T : T for (var p in x) { ->p : string +>p : keyof T >x : T } } diff --git a/tests/baselines/reference/parserES5ForOfStatement19.errors.txt b/tests/baselines/reference/parserES5ForOfStatement19.errors.txt deleted file mode 100644 index 9d0bb02f1efb5..0000000000000 --- a/tests/baselines/reference/parserES5ForOfStatement19.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts(1,16): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. - - -==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts (1 errors) ==== - for (var of in of) { } - ~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement19.symbols b/tests/baselines/reference/parserES5ForOfStatement19.symbols new file mode 100644 index 0000000000000..93ba77e3db94c --- /dev/null +++ b/tests/baselines/reference/parserES5ForOfStatement19.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts === +for (var of in of) { } +>of : Symbol(of, Decl(parserES5ForOfStatement19.ts, 0, 8)) +>of : Symbol(of, Decl(parserES5ForOfStatement19.ts, 0, 8)) + diff --git a/tests/baselines/reference/parserES5ForOfStatement19.types b/tests/baselines/reference/parserES5ForOfStatement19.types new file mode 100644 index 0000000000000..13abc7ae757b4 --- /dev/null +++ b/tests/baselines/reference/parserES5ForOfStatement19.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts === +for (var of in of) { } +>of : any +>of : any + diff --git a/tests/baselines/reference/parserES5ForOfStatement20.errors.txt b/tests/baselines/reference/parserES5ForOfStatement20.errors.txt index 2bfc54590ad54..4aee32394b60b 100644 --- a/tests/baselines/reference/parserES5ForOfStatement20.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement20.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts(1,10): error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts(1,20): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. -==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts (1 errors) ==== for (var of = 0 in of) { } ~~ -!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. - ~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file +!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement19.errors.txt b/tests/baselines/reference/parserForOfStatement19.errors.txt deleted file mode 100644 index a111498efe709..0000000000000 --- a/tests/baselines/reference/parserForOfStatement19.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts(1,16): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. - - -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts (1 errors) ==== - for (var of in of) { } - ~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement19.symbols b/tests/baselines/reference/parserForOfStatement19.symbols new file mode 100644 index 0000000000000..1e123349e13c6 --- /dev/null +++ b/tests/baselines/reference/parserForOfStatement19.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts === +for (var of in of) { } +>of : Symbol(of, Decl(parserForOfStatement19.ts, 0, 8)) +>of : Symbol(of, Decl(parserForOfStatement19.ts, 0, 8)) + diff --git a/tests/baselines/reference/parserForOfStatement19.types b/tests/baselines/reference/parserForOfStatement19.types new file mode 100644 index 0000000000000..6fcc5e8f79216 --- /dev/null +++ b/tests/baselines/reference/parserForOfStatement19.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts === +for (var of in of) { } +>of : any +>of : any + diff --git a/tests/baselines/reference/parserForOfStatement20.errors.txt b/tests/baselines/reference/parserForOfStatement20.errors.txt index f2b6ac39a8332..461f307f6b936 100644 --- a/tests/baselines/reference/parserForOfStatement20.errors.txt +++ b/tests/baselines/reference/parserForOfStatement20.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts(1,10): error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts(1,20): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts (1 errors) ==== for (var of = 0 in of) { } ~~ -!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. - ~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file +!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. \ No newline at end of file diff --git a/tests/baselines/reference/recursiveLetConst.errors.txt b/tests/baselines/reference/recursiveLetConst.errors.txt index 6d3f15880bb96..88ecb379e5ef8 100644 --- a/tests/baselines/reference/recursiveLetConst.errors.txt +++ b/tests/baselines/reference/recursiveLetConst.errors.txt @@ -5,14 +5,13 @@ tests/cases/compiler/recursiveLetConst.ts(5,14): error TS2448: Block-scoped vari tests/cases/compiler/recursiveLetConst.ts(6,14): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(7,1): error TS7027: Unreachable code detected. tests/cases/compiler/recursiveLetConst.ts(7,16): error TS2448: Block-scoped variable 'v' used before its declaration. -tests/cases/compiler/recursiveLetConst.ts(8,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/compiler/recursiveLetConst.ts(8,15): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(9,15): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(10,17): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(11,11): error TS2448: Block-scoped variable 'x2' used before its declaration. -==== tests/cases/compiler/recursiveLetConst.ts (12 errors) ==== +==== tests/cases/compiler/recursiveLetConst.ts (11 errors) ==== 'use strict' let x = x + 1; ~ @@ -36,8 +35,6 @@ tests/cases/compiler/recursiveLetConst.ts(11,11): error TS2448: Block-scoped var !!! error TS2448: Block-scoped variable 'v' used before its declaration. for (let v in v) { } ~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. - ~ !!! error TS2448: Block-scoped variable 'v' used before its declaration. for (let v of v) { } ~ From b662a8b31906558ec1bd90d8668e78042d2e567c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 21 Nov 2016 13:10:42 -0800 Subject: [PATCH 42/46] Add test case --- .../reference/keyofAndIndexedAccess.js | 12 +++ .../reference/keyofAndIndexedAccess.symbols | 92 +++++++++++-------- .../reference/keyofAndIndexedAccess.types | 23 +++++ .../types/keyof/keyofAndIndexedAccess.ts | 6 ++ 4 files changed, 97 insertions(+), 36 deletions(-) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 017669603a46f..1cc8846bbbdd3 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -211,6 +211,12 @@ function f55(obj: T, key: K) { const b = "foo" in obj[key]; } +function f60(source: T, target: T) { + for (let k in source) { + target[k] = source[k]; + } +} + // Repros from #12011 class Base { @@ -383,6 +389,11 @@ function f55(obj, key) { } var b = "foo" in obj[key]; } +function f60(source, target) { + for (var k in source) { + target[k] = source[k]; + } +} // Repros from #12011 var Base = (function () { function Base() { @@ -518,6 +529,7 @@ declare function f53(obj: { }, k: K, s: string, n: number): void; declare function f54(obj: T, key: keyof T): void; declare function f55(obj: T, key: K): void; +declare function f60(source: T, target: T): void; declare class Base { get(prop: K): this[K]; set(prop: K, value: this[K]): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 8a2f1052d137f..634dfe09da9e9 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -735,84 +735,104 @@ function f55(obj: T, key: K) { >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) } +function f60(source: T, target: T) { +>f60 : Symbol(f60, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) +>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) + + for (let k in source) { +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) + + target[k] = source[k]; +>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) + } +} + // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 223, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 229, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 228, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 234, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 234, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 240, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16)) setProperty(this, "parts", parts); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 238, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 244, 5)) return getProperty(this, "parts") >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 4c09909c0fd5b..916b82aaf40d0 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -854,6 +854,29 @@ function f55(obj: T, key: K) { >key : K } +function f60(source: T, target: T) { +>f60 : (source: T, target: T) => void +>T : T +>source : T +>T : T +>target : T +>T : T + + for (let k in source) { +>k : keyof T +>source : T + + target[k] = source[k]; +>target[k] = source[k] : T[keyof T] +>target[k] : T[keyof T] +>target : T +>k : keyof T +>source[k] : T[keyof T] +>source : T +>k : keyof T + } +} + // Repros from #12011 class Base { diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 690154cb7ac2a..b0451b8d55cd6 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -211,6 +211,12 @@ function f55(obj: T, key: K) { const b = "foo" in obj[key]; } +function f60(source: T, target: T) { + for (let k in source) { + target[k] = source[k]; + } +} + // Repros from #12011 class Base { From 9009da225c75bdb1d100b1f9bb2af6acae29863e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 21 Nov 2016 17:25:31 -0800 Subject: [PATCH 43/46] Update baseline-accept configuration --- Jakefile.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 087bbb675117c..24d1cc3c79ed3 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -1086,12 +1086,10 @@ task("tests-debug", ["setDebugMode", "tests"]); // Makes the test results the new baseline desc("Makes the most recent test results the new baseline, overwriting the old baseline"); task("baseline-accept", function () { - acceptBaseline(""); + acceptBaseline(localBaseline, refBaseline); }); -function acceptBaseline(containerFolder) { - var sourceFolder = path.join(localBaseline, containerFolder); - var targetFolder = path.join(refBaseline, containerFolder); +function acceptBaseline(sourceFolder, targetFolder) { console.log('Accept baselines from ' + sourceFolder + ' to ' + targetFolder); var files = fs.readdirSync(sourceFolder); var deleteEnding = '.delete'; @@ -1115,12 +1113,12 @@ function acceptBaseline(containerFolder) { desc("Makes the most recent rwc test results the new baseline, overwriting the old baseline"); task("baseline-accept-rwc", function () { - acceptBaseline("rwc"); + acceptBaseline(localRwcBaseline, refRwcBaseline); }); desc("Makes the most recent test262 test results the new baseline, overwriting the old baseline"); task("baseline-accept-test262", function () { - acceptBaseline("test262"); + acceptBaseline(localTest262Baseline, refTest262Baseline); }); From 843d08b5af6a31c2c3c92f57bfbe0abad6e53e77 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 21 Nov 2016 17:25:38 -0800 Subject: [PATCH 44/46] increase timeout --- Jakefile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile.js b/Jakefile.js index 24d1cc3c79ed3..3454ca8ae30aa 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -930,7 +930,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } if (tests && tests.toLocaleLowerCase() === "rwc") { - testTimeout = 400000; + testTimeout = 800000; } colors = process.env.colors || process.env.color; From 5403ce62ed0df80177d664c0ab77d6a62c672d28 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 21 Nov 2016 17:26:10 -0800 Subject: [PATCH 45/46] normalize path in harness --- src/harness/harness.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 88346557ba7c2..26a4a6f963dc9 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -2015,7 +2015,7 @@ namespace Harness { export function isDefaultLibraryFile(filePath: string): boolean { // We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts" - const fileName = ts.getBaseFileName(filePath); + const fileName = ts.getBaseFileName(ts.normalizeSlashes(filePath)); return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts"); } From b8b6e6149194e6c99b752de469334a676a91a975 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 21 Nov 2016 17:26:18 -0800 Subject: [PATCH 46/46] handel missing files gracefully --- src/harness/rwcRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 9f9bf8589f08a..44d2c981c8476 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -199,7 +199,7 @@ namespace RWC { } // Do not include the library in the baselines to avoid noise const baselineFiles = inputFiles.concat(otherFiles).filter(f => !Harness.isDefaultLibraryFile(f.unitName)); - const errors = compilerResult.errors.filter(e => !Harness.isDefaultLibraryFile(e.file.fileName)); + const errors = compilerResult.errors.filter(e => e.file && !Harness.isDefaultLibraryFile(e.file.fileName)); return Harness.Compiler.getErrorBaseline(baselineFiles, errors); }, baselineOpts); });