diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2300c4fad5f90..9daa87daed48e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -97,6 +97,7 @@ module ts { var globalRegExpType: ObjectType; var globalTemplateStringsArrayType: ObjectType; var globalESSymbolType: ObjectType; + var globalIterableType: ObjectType; var anyArrayType: Type; @@ -589,13 +590,13 @@ module ts { } if (name.kind === SyntaxKind.Identifier) { - var symbol = resolveName(location,(name).text, meaning, Diagnostics.Cannot_find_name_0, name); + var symbol = resolveName(location, (name).text, meaning, Diagnostics.Cannot_find_name_0, name); if (!symbol) { return; } } else if (name.kind === SyntaxKind.QualifiedName) { - var namespace = resolveEntityName(location,(name).left, SymbolFlags.Namespace); + var namespace = resolveEntityName(location, (name).left, SymbolFlags.Namespace); if (!namespace || namespace === unknownSymbol || getFullWidth((name).right) === 0) return; var symbol = getSymbol(getExportsOfSymbol(namespace), (name).right.text, meaning); if (!symbol) { @@ -1859,6 +1860,9 @@ module ts { if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { return anyType; } + if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { + return getTypeForVariableDeclarationInForOfStatement(declaration.parent.parent); + } if (isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } @@ -3150,8 +3154,8 @@ module ts { return resolveName(undefined, name, meaning, diagnostic, name); } - function getGlobalType(name: string): ObjectType { - return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), 0); + function getGlobalType(name: string, arity = 0): ObjectType { + return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } function getGlobalESSymbolConstructorSymbol() { @@ -3533,7 +3537,7 @@ module ts { isContextSensitive((node).whenFalse); case SyntaxKind.BinaryExpression: return (node).operatorToken.kind === SyntaxKind.BarBarToken && - (isContextSensitive((node).left) || isContextSensitive((node).right)); + (isContextSensitive((node).left) || isContextSensitive((node).right)); case SyntaxKind.PropertyAssignment: return isContextSensitive((node).initializer); case SyntaxKind.MethodDeclaration: @@ -4999,7 +5003,7 @@ module ts { break; case SyntaxKind.PrefixUnaryExpression: if ((expr).operator === SyntaxKind.ExclamationToken) { - return narrowType(type,(expr).operand, !assumeTrue); + return narrowType(type, (expr).operand, !assumeTrue); } break; } @@ -5070,7 +5074,7 @@ module ts { nodeLinks.importOnRightSide = symbol; } } - + if (symbolLinks.referenced) { markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)); } @@ -5491,7 +5495,7 @@ module ts { return propertyType; } } - + return isNumericName(element.name) && getIndexTypeOfContextualType(type, IndexKind.Number) || getIndexTypeOfContextualType(type, IndexKind.String); } @@ -5500,14 +5504,17 @@ module ts { } // In an array literal contextually typed by a type T, the contextual type of an element expression at index N is - // the type of the property with the numeric name N in T, if one exists. Otherwise, it is the type of the numeric - // index signature in T, if one exists. + // the type of the property with the numeric name N in T, if one exists. Otherwise, if T has a numeric index signature, + // it is the type of the numeric index signature in T. Otherwise, in ES6 and higher, the contextual type is the iterated + // type of T. function getContextualTypeForElementExpression(node: Expression): Type { var arrayLiteral = node.parent; var type = getContextualType(arrayLiteral); if (type) { var index = indexOf(arrayLiteral.elements, node); - return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, IndexKind.Number); + return getTypeOfPropertyOfContextualType(type, "" + index) + || getIndexTypeOfContextualType(type, IndexKind.Number) + || (languageVersion >= ScriptTarget.ES6 ? checkIteratedType(type, /*expressionForError*/ undefined) : undefined); } return undefined; } @@ -6084,7 +6091,7 @@ module ts { if (!leftHandSideSymbol) { return false; } - + var globalESSymbol = getGlobalESSymbolConstructorSymbol(); if (!globalESSymbol) { // Already errored when we tried to look up the symbol @@ -6358,7 +6365,7 @@ module ts { // unless we're reporting errors var argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression ? globalTemplateStringsArrayType : arg.kind === SyntaxKind.StringLiteral && !reportErrors ? getStringLiteralType(arg) : - checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); // Use argument expression as error location when reporting errors if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { @@ -6983,7 +6990,7 @@ module ts { if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { checkCollisionWithCapturedSuperVariable(node, (node).name); - checkCollisionWithCapturedThisVariable(node,(node).name); + checkCollisionWithCapturedThisVariable(node, (node).name); } return type; @@ -7017,7 +7024,7 @@ module ts { return true; } - function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVarianleMessage: DiagnosticMessage): boolean { + function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { function findSymbol(n: Node): Symbol { var symbol = getNodeLinks(n).resolvedSymbol; // Because we got the symbol from the resolvedSymbol property, it might be of kind @@ -7084,7 +7091,7 @@ module ts { return false; } if (isConstVariableReference(n)) { - error(n, constantVarianleMessage); + error(n, constantVariableMessage); return false; } return true; @@ -7276,7 +7283,7 @@ module ts { var propName = "" + i; var type = sourceType.flags & TypeFlags.Any ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : - getIndexTypeOfType(sourceType, IndexKind.Number); + getIndexTypeOfType(sourceType, IndexKind.Number); if (type) { checkDestructuringAssignment(e, type, contextualMapper); } @@ -7430,7 +7437,7 @@ module ts { if (!checkForDisallowedESSymbolOperand(operator)) { return booleanType; } - // Fall through + // Fall through case SyntaxKind.EqualsEqualsToken: case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: @@ -7454,7 +7461,7 @@ module ts { return rightType; } - // Return type is true if there was no error, false if there was an error. + // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator: SyntaxKind): boolean { var offendingSymbolOperand = someConstituentTypeHasKind(leftType, TypeFlags.ESSymbol) ? node.left : @@ -7758,8 +7765,8 @@ module ts { } // TODO (yuisu): Remove this check in else-if when SyntaxKind.Construct is moved and ambient context is handled else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType || - node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.Constructor || - node.kind === SyntaxKind.ConstructSignature){ + node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.Constructor || + node.kind === SyntaxKind.ConstructSignature) { checkGrammarFunctionLikeDeclaration(node); } @@ -8369,9 +8376,9 @@ module ts { function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || - checkGrammarFunctionName(node.name) || - checkGrammarForGenerator(node); + checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || + checkGrammarFunctionName(node.name) || + checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); @@ -8478,7 +8485,7 @@ module ts { return true; } - + function checkCollisionWithCapturedThisVariable(node: Node, name: Identifier): void { if (needCollisionCheckForIdentifier(node, name, "_this")) { potentialThisCollisions.push(node); @@ -8488,7 +8495,7 @@ module ts { // this function will run after checking the source file so 'CaptureThis' is correct for all nodes function checkIfThisIsCapturedInEnclosingScope(node: Node): void { var current = node; - while (current) { + while (current) { if (getNodeCheckFlags(current) & NodeCheckFlags.CaptureThis) { var isDeclaration = node.kind !== SyntaxKind.Identifier; if (isDeclaration) { @@ -8589,8 +8596,8 @@ module ts { var namesShareScope = container && (container.kind === SyntaxKind.Block && isAnyFunction(container.parent) || - (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || - container.kind === SyntaxKind.SourceFile); + (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || + container.kind === SyntaxKind.SourceFile); // here we know that function scoped variable is shadowed by block scoped one // if they are defined in the same scope - binder has already reported redeclaration error @@ -8796,9 +8803,50 @@ module ts { checkSourceElement(node.statement); } - function checkForOfStatement(node: ForOfStatement) { - // TODO: not yet implemented - checkGrammarForOfStatement(node); + function checkForOfStatement(node: ForOfStatement): void { + if (languageVersion < ScriptTarget.ES6) { + grammarErrorOnFirstToken(node, Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); + return; + } + + checkGrammarForInOrForOfStatement(node) + + // Check the LHS and RHS + // If the LHS is a declaration, just check it as a variable declaration, which will in turn check the RHS + // via getTypeForVariableDeclarationInForOfStatement. + // If the LHS is an expression, check the LHS, as a destructuring assignment or as a reference. + // Then check that the RHS is assignable to it. + if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { + checkForInOrForOfVariableDeclaration(node); + } + else { + var varExpr = node.initializer; + var rightType = checkExpression(node.expression); + var iteratedType = checkIteratedType(rightType, node.expression); + + // There may be a destructuring assignment on the left side + if (varExpr.kind === SyntaxKind.ArrayLiteralExpression || varExpr.kind === SyntaxKind.ObjectLiteralExpression) { + // iteratedType may be undefined. In this case, we still want to check the structure of + // varExpr, in particular making sure it's a valid LeftHandSideExpression. But we'd like + // to short circuit the type relation checking as much as possible, so we pass the unknownType. + checkDestructuringAssignment(varExpr, iteratedType || unknownType); + } + else { + var leftType = checkExpression(varExpr); + checkReferenceExpression(varExpr, /*invalidReferenceMessage*/ Diagnostics.Invalid_left_hand_side_in_for_of_statement, + /*constantVariableMessage*/ Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant); + + // iteratedType will be undefined if the rightType was missing properties/signatures + // required to get its iteratedType (like [Symbol.iterator] or next). This may be + // because we accessed properties from anyType, or it may have led to an error inside + // getIteratedType. + if (iteratedType) { + checkTypeAssignableTo(iteratedType, leftType, varExpr, /*headMessage*/ undefined); + } + } + } + + checkSourceElement(node.statement); } function checkForInStatement(node: ForInStatement) { @@ -8811,11 +8859,12 @@ module ts { // VarDecl must be a variable declaration without a type annotation that declares a variable of type Any, // and Expr must be an expression of type Any, an object type, or a type parameter type. if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - var decl = variableDeclarationList.declarations[0]; - checkVariableDeclaration(decl); + var variable = (node.initializer).declarations[0]; + if (variable && isBindingPattern(variable.name)) { + error(variable.name, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } + + checkForInOrForOfVariableDeclaration(node); } else { // In a 'for-in' statement of the form @@ -8823,26 +8872,148 @@ module ts { // Var must be an expression classified as a reference of type Any or the String primitive type, // and Expr must be an expression of type Any, an object type, or a type parameter type. var varExpr = node.initializer; - var exprType = checkExpression(varExpr); - if (!allConstituentTypesHaveKind(exprType, TypeFlags.Any | TypeFlags.StringLike)) { + var leftType = checkExpression(varExpr); + if (varExpr.kind === SyntaxKind.ArrayLiteralExpression || varExpr.kind === SyntaxKind.ObjectLiteralExpression) { + error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); + } + else if (!allConstituentTypesHaveKind(leftType, TypeFlags.Any | TypeFlags.StringLike)) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant); } } - var exprType = checkExpression(node.expression); + var rightType = checkExpression(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 (!allConstituentTypesHaveKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { + if (!allConstituentTypesHaveKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { 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); } checkSourceElement(node.statement); } + function checkForInOrForOfVariableDeclaration(iterationStatement: ForInStatement | ForOfStatement): void { + var variableDeclarationList = iterationStatement.initializer; + // checkGrammarForInOrForOfStatement will check that there is exactly one declaration. + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); + } + } + + function getTypeForVariableDeclarationInForOfStatement(forOfStatement: ForOfStatement): Type { + // Temporarily return 'any' below ES6 + if (languageVersion < ScriptTarget.ES6) { + return anyType; + } + + // iteratedType will be undefined if the for-of expression type was missing properties/signatures + // required to get its iteratedType (like [Symbol.iterator] or next). This may be + // because we accessed properties from anyType, or it may have led to an error inside + // getIteratedType. + var expressionType = getTypeOfExpression(forOfStatement.expression); + return checkIteratedType(expressionType, forOfStatement.expression) || anyType; + } + + /** + * When expressionForError is undefined, it means we should not report any errors. + */ + function checkIteratedType(iterable: Type, expressionForError: Expression): Type { + Debug.assert(languageVersion >= ScriptTarget.ES6); + var iteratedType = getIteratedType(iterable, expressionForError); + // Now even though we have extracted the iteratedType, we will have to validate that the type + // passed in is actually an Iterable. + if (expressionForError && iteratedType) { + var completeIterableType = globalIterableType !== emptyObjectType + ? createTypeReference(globalIterableType, [iteratedType]) + : emptyObjectType; + checkTypeAssignableTo(iterable, completeIterableType, expressionForError); + } + + return iteratedType; + + function getIteratedType(iterable: Type, expressionForError: Expression) { + // We want to treat type as an iterable, and get the type it is an iterable of. The iterable + // must have the following structure (annotated with the names of the variables below): + // + // { // iterable + // [Symbol.iterator]: { // iteratorFunction + // (): { // iterator + // next: { // iteratorNextFunction + // (): { // iteratorNextResult + // value: T // iteratorNextValue + // } + // } + // } + // } + // } + // + // T is the type we are after. At every level that involves analyzing return types + // of signatures, we union the return types of all the signatures. + // + // Another thing to note is that at any step of this process, we could run into a dead end, + // meaning either the property is missing, or we run into the anyType. If either of these things + // happens, we return undefined to signal that we could not find the iterated type. If a property + // is missing, and the previous step did not result in 'any', then we also give an error if the + // caller requested it. Then the caller can decide what to do in the case where there is no iterated + // type. This is different from returning anyType, because that would signify that we have matched the + // whole pattern and that T (above) is 'any'. + + if (allConstituentTypesHaveKind(iterable, TypeFlags.Any)) { + return undefined; + } + + var iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) { + return undefined; + } + + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + + var iterator = getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iterator, TypeFlags.Any)) { + return undefined; + } + + var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); + if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, TypeFlags.Any)) { + return undefined; + } + + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method); + } + return undefined; + } + + var iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iteratorNextResult, TypeFlags.Any)) { + return undefined; + } + + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (expressionForError) { + error(expressionForError, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + + return iteratorNextValue; + } + } + function checkBreakOrContinueStatement(node: BreakOrContinueStatement) { // Grammar checking checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); @@ -10805,7 +10976,7 @@ module ts { globals[undefinedSymbol.name] = undefinedSymbol; // Initialize special types globalArraySymbol = getGlobalTypeSymbol("Array"); - globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, 1); + globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, /*arity*/ 1); globalObjectType = getGlobalType("Object"); globalFunctionType = getGlobalType("Function"); globalStringType = getGlobalType("String"); @@ -10819,6 +10990,7 @@ module ts { globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); + globalIterableType = getGlobalType("Iterable", /*arity*/ 1); } else { globalTemplateStringsArrayType = unknownType; @@ -11325,16 +11497,6 @@ module ts { return false; } - function checkGrammarForOfStatement(forOfStatement: ForOfStatement): boolean { - // Temporarily disallow for-of statements until type check work is complete. - return grammarErrorOnFirstToken(forOfStatement, Diagnostics.for_of_statements_are_not_currently_supported); - if (languageVersion < ScriptTarget.ES6) { - return grammarErrorOnFirstToken(forOfStatement, Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); - } - - return checkGrammarForInOrForOfStatement(forOfStatement); - } - function checkGrammarAccessor(accessor: MethodDeclaration): boolean { var kind = accessor.kind; if (languageVersion < ScriptTarget.ES5) { @@ -11509,22 +11671,23 @@ module ts { } function checkGrammarVariableDeclaration(node: VariableDeclaration) { - if (isInAmbientContext(node)) { - if (isBindingPattern(node.name)) { - return grammarErrorOnNode(node, Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); - } - if (node.initializer) { - // Error on equals token which immediate precedes the initializer - return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + if (node.parent.parent.kind !== SyntaxKind.ForInStatement && node.parent.parent.kind !== SyntaxKind.ForOfStatement) { + if (isInAmbientContext(node)) { + if (isBindingPattern(node.name)) { + return grammarErrorOnNode(node, Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + // Error on equals token which immediate precedes the initializer + var equalsTokenLength = "=".length; + return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, + equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } } - } - else { - if (!node.initializer) { + else if (!node.initializer) { if (isBindingPattern(node.name) && !isBindingPattern(node.parent)) { return grammarErrorOnNode(node, Diagnostics.A_destructuring_declaration_must_have_an_initializer); } - // const declarations should not be initialized in for-in for-of statements - if (isConst(node) && node.parent.parent.kind !== SyntaxKind.ForInStatement && node.parent.parent.kind !== SyntaxKind.ForOfStatement) { + if (isConst(node)) { return grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0e8d1bdd25fa2..758c3ee6ba7e3 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -328,6 +328,13 @@ module ts { for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 2482, category: DiagnosticCategory.Error, key: "'for...of' statements are only available when targeting ECMAScript 6 or higher." }, The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." }, Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: DiagnosticCategory.Error, key: "Export declaration conflicts with exported declaration of '{0}'" }, + The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." }, + Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." }, + The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: DiagnosticCategory.Error, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." }, + The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: DiagnosticCategory.Error, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." }, + The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: DiagnosticCategory.Error, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -474,6 +481,5 @@ module ts { yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, - for_of_statements_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'for...of' statements are not currently supported." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index cca74aac7ce68..b4786bb93d76e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1304,6 +1304,34 @@ "category": "Error", "code": 2484 }, + "The left-hand side of a 'for...of' statement cannot be a previously defined constant.": { + "category": "Error", + "code": 2485 + }, + "The left-hand side of a 'for...in' statement cannot be a previously defined constant.": { + "category": "Error", + "code": 2486 + }, + "Invalid left-hand side in 'for...of' statement.": { + "category": "Error", + "code": 2487 + }, + "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.": { + "category": "Error", + "code": 2488 + }, + "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.": { + "category": "Error", + "code": 2489 + }, + "The type returned by the 'next()' method of an iterator must have a 'value' property.": { + "category": "Error", + "code": 2490 + }, + "The left-hand side of a 'for...in' statement cannot be a destructuring pattern.": { + "category": "Error", + "code": 2491 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -1889,9 +1917,5 @@ "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { "category": "Error", "code": 9002 - }, - "'for...of' statements are not currently supported.": { - "category": "Error", - "code": 9003 } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index af574572055cf..736d5454c9797 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -683,7 +683,7 @@ module ts { } export function isBindingPattern(node: Node) { - return node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern; + return !!node && (node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern); } export function isInAmbientContext(node: Node): boolean { diff --git a/tests/baselines/reference/downlevelLetConst16.errors.txt b/tests/baselines/reference/downlevelLetConst16.errors.txt index dafdd5b7b074d..c488e96ca2326 100644 --- a/tests/baselines/reference/downlevelLetConst16.errors.txt +++ b/tests/baselines/reference/downlevelLetConst16.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/downlevelLetConst16.ts(189,5): error TS9003: 'for...of' statements are not currently supported. -tests/cases/compiler/downlevelLetConst16.ts(196,5): error TS9003: 'for...of' statements are not currently supported. -tests/cases/compiler/downlevelLetConst16.ts(203,5): error TS9003: 'for...of' statements are not currently supported. -tests/cases/compiler/downlevelLetConst16.ts(210,5): error TS9003: 'for...of' statements are not currently supported. -tests/cases/compiler/downlevelLetConst16.ts(217,5): error TS9003: 'for...of' statements are not currently supported. -tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst16.ts(189,5): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst16.ts(196,5): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst16.ts(203,5): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst16.ts(210,5): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst16.ts(217,5): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/compiler/downlevelLetConst16.ts (6 errors) ==== @@ -197,7 +197,7 @@ tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' sta function foo7() { for (let x of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } use(x); @@ -206,7 +206,7 @@ tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' sta function foo8() { for (let [x] of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } use(x); @@ -215,7 +215,7 @@ tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' sta function foo9() { for (let {a: x} of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } use(x); @@ -224,7 +224,7 @@ tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' sta function foo10() { for (const x of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } use(x); @@ -233,7 +233,7 @@ tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' sta function foo11() { for (const [x] of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } use(x); @@ -242,7 +242,7 @@ tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' sta function foo12() { for (const {a: x} of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } use(x); diff --git a/tests/baselines/reference/downlevelLetConst17.errors.txt b/tests/baselines/reference/downlevelLetConst17.errors.txt index a185ca4abe1e1..ef8f2b89085d9 100644 --- a/tests/baselines/reference/downlevelLetConst17.errors.txt +++ b/tests/baselines/reference/downlevelLetConst17.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/downlevelLetConst17.ts(66,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst17.ts(66,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/compiler/downlevelLetConst17.ts (1 errors) ==== @@ -69,6 +69,6 @@ tests/cases/compiler/downlevelLetConst17.ts(66,1): error TS9003: 'for...of' stat // TODO: update once for-of statements are supported downlevel for (const x of []) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. use(x); } \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsDestructuring.errors.txt b/tests/baselines/reference/for-inStatementsDestructuring.errors.txt new file mode 100644 index 0000000000000..e540b182cf5e7 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts(1,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. + + +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts (1 errors) ==== + for (var [a, b] in []) {} + ~~~~~~ +!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsDestructuring.js b/tests/baselines/reference/for-inStatementsDestructuring.js new file mode 100644 index 0000000000000..e5e00d5b3ab56 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring.js @@ -0,0 +1,5 @@ +//// [for-inStatementsDestructuring.ts] +for (var [a, b] in []) {} + +//// [for-inStatementsDestructuring.js] +for (var _a = void 0, a = _a[0], b = _a[1] in []) { } diff --git a/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt b/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt new file mode 100644 index 0000000000000..56d2436d4c78f --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. + + +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts (1 errors) ==== + for (var {a, b} in []) {} + ~~~~~~ +!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsDestructuring2.js b/tests/baselines/reference/for-inStatementsDestructuring2.js new file mode 100644 index 0000000000000..41a6d30919f50 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring2.js @@ -0,0 +1,5 @@ +//// [for-inStatementsDestructuring2.ts] +for (var {a, b} in []) {} + +//// [for-inStatementsDestructuring2.js] +for (var _a = void 0, a = _a.a, b = _a.b in []) { } diff --git a/tests/baselines/reference/for-inStatementsDestructuring3.errors.txt b/tests/baselines/reference/for-inStatementsDestructuring3.errors.txt new file mode 100644 index 0000000000000..e3ce65f872d0a --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring3.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring3.ts(2,6): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. + + +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring3.ts (1 errors) ==== + var a, b; + for ([a, b] in []) { } + ~~~~~~ +!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsDestructuring3.js b/tests/baselines/reference/for-inStatementsDestructuring3.js new file mode 100644 index 0000000000000..0970740acab85 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring3.js @@ -0,0 +1,7 @@ +//// [for-inStatementsDestructuring3.ts] +var a, b; +for ([a, b] in []) { } + +//// [for-inStatementsDestructuring3.js] +var a, b; +for ([a, b] in []) { } diff --git a/tests/baselines/reference/for-inStatementsDestructuring4.errors.txt b/tests/baselines/reference/for-inStatementsDestructuring4.errors.txt new file mode 100644 index 0000000000000..8d3fe2d1b5362 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring4.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring4.ts(2,6): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. + + +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring4.ts (1 errors) ==== + var a, b; + for ({a, b} in []) { } + ~~~~~~ +!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsDestructuring4.js b/tests/baselines/reference/for-inStatementsDestructuring4.js new file mode 100644 index 0000000000000..0cce61ac96d71 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsDestructuring4.js @@ -0,0 +1,7 @@ +//// [for-inStatementsDestructuring4.ts] +var a, b; +for ({a, b} in []) { } + +//// [for-inStatementsDestructuring4.js] +var a, b; +for ({ a: a, b: b } in []) { } diff --git a/tests/baselines/reference/for-of1.js b/tests/baselines/reference/for-of1.js new file mode 100644 index 0000000000000..9df6a96d78f54 --- /dev/null +++ b/tests/baselines/reference/for-of1.js @@ -0,0 +1,7 @@ +//// [for-of1.ts] +var v; +for (v of []) { } + +//// [for-of1.js] +var v; +for (v of []) { } diff --git a/tests/baselines/reference/for-of1.types b/tests/baselines/reference/for-of1.types new file mode 100644 index 0000000000000..b21bb6046a701 --- /dev/null +++ b/tests/baselines/reference/for-of1.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of1.ts === +var v; +>v : any + +for (v of []) { } +>v : any +>[] : undefined[] + diff --git a/tests/baselines/reference/for-of10.errors.txt b/tests/baselines/reference/for-of10.errors.txt new file mode 100644 index 0000000000000..1636f1a02d045 --- /dev/null +++ b/tests/baselines/reference/for-of10.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/for-ofStatements/for-of10.ts(2,6): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of10.ts (1 errors) ==== + var v: string; + for (v of [0]) { } + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/for-of10.js b/tests/baselines/reference/for-of10.js new file mode 100644 index 0000000000000..7fd05f5479b2e --- /dev/null +++ b/tests/baselines/reference/for-of10.js @@ -0,0 +1,7 @@ +//// [for-of10.ts] +var v: string; +for (v of [0]) { } + +//// [for-of10.js] +var v; +for (v of [0]) { } diff --git a/tests/baselines/reference/for-of11.errors.txt b/tests/baselines/reference/for-of11.errors.txt new file mode 100644 index 0000000000000..dc527e73efe2b --- /dev/null +++ b/tests/baselines/reference/for-of11.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of11.ts (1 errors) ==== + var v: string; + for (v of [0, ""]) { } + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/for-of11.js b/tests/baselines/reference/for-of11.js new file mode 100644 index 0000000000000..055ed0039dc8d --- /dev/null +++ b/tests/baselines/reference/for-of11.js @@ -0,0 +1,7 @@ +//// [for-of11.ts] +var v: string; +for (v of [0, ""]) { } + +//// [for-of11.js] +var v; +for (v of [0, ""]) { } diff --git a/tests/baselines/reference/for-of12.errors.txt b/tests/baselines/reference/for-of12.errors.txt new file mode 100644 index 0000000000000..f19fa5ed0146d --- /dev/null +++ b/tests/baselines/reference/for-of12.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of12.ts (1 errors) ==== + var v: string; + for (v of [0, ""].values()) { } + ~ +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/for-of12.js b/tests/baselines/reference/for-of12.js new file mode 100644 index 0000000000000..6185ca8e33137 --- /dev/null +++ b/tests/baselines/reference/for-of12.js @@ -0,0 +1,7 @@ +//// [for-of12.ts] +var v: string; +for (v of [0, ""].values()) { } + +//// [for-of12.js] +var v; +for (v of [0, ""].values()) { } diff --git a/tests/baselines/reference/for-of13.js b/tests/baselines/reference/for-of13.js new file mode 100644 index 0000000000000..e66668f173646 --- /dev/null +++ b/tests/baselines/reference/for-of13.js @@ -0,0 +1,7 @@ +//// [for-of13.ts] +var v: string; +for (v of [""].values()) { } + +//// [for-of13.js] +var v; +for (v of [""].values()) { } diff --git a/tests/baselines/reference/for-of13.types b/tests/baselines/reference/for-of13.types new file mode 100644 index 0000000000000..4bb29c1e0ab76 --- /dev/null +++ b/tests/baselines/reference/for-of13.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of13.ts === +var v: string; +>v : string + +for (v of [""].values()) { } +>v : string +>[""].values() : IterableIterator +>[""].values : () => IterableIterator +>[""] : string[] +>values : () => IterableIterator + diff --git a/tests/baselines/reference/for-of14.errors.txt b/tests/baselines/reference/for-of14.errors.txt new file mode 100644 index 0000000000000..5e8223381c72c --- /dev/null +++ b/tests/baselines/reference/for-of14.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/for-ofStatements/for-of14.ts(2,11): error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of14.ts (1 errors) ==== + var v: string; + for (v of new StringIterator) { } // Should fail because the iterator is not iterable + ~~~~~~~~~~~~~~~~~~ +!!! error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator. + + class StringIterator { + next() { + return ""; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of14.js b/tests/baselines/reference/for-of14.js new file mode 100644 index 0000000000000..d5f9e29b76673 --- /dev/null +++ b/tests/baselines/reference/for-of14.js @@ -0,0 +1,21 @@ +//// [for-of14.ts] +var v: string; +for (v of new StringIterator) { } // Should fail because the iterator is not iterable + +class StringIterator { + next() { + return ""; + } +} + +//// [for-of14.js] +var v; +for (v of new StringIterator) { } // Should fail because the iterator is not iterable +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return ""; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of15.errors.txt b/tests/baselines/reference/for-of15.errors.txt new file mode 100644 index 0000000000000..20a4abe4bd07c --- /dev/null +++ b/tests/baselines/reference/for-of15.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/for-ofStatements/for-of15.ts(2,11): error TS2490: The type returned by the 'next()' method of an iterator must have a 'value' property. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of15.ts (1 errors) ==== + var v: string; + for (v of new StringIterator) { } // Should fail + ~~~~~~~~~~~~~~~~~~ +!!! error TS2490: The type returned by the 'next()' method of an iterator must have a 'value' property. + + class StringIterator { + next() { + return ""; + } + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of15.js b/tests/baselines/reference/for-of15.js new file mode 100644 index 0000000000000..369553897566e --- /dev/null +++ b/tests/baselines/reference/for-of15.js @@ -0,0 +1,27 @@ +//// [for-of15.ts] +var v: string; +for (v of new StringIterator) { } // Should fail + +class StringIterator { + next() { + return ""; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of15.js] +var v; +for (v of new StringIterator) { } // Should fail +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return ""; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of16.errors.txt b/tests/baselines/reference/for-of16.errors.txt new file mode 100644 index 0000000000000..e3ecca1a25637 --- /dev/null +++ b/tests/baselines/reference/for-of16.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/for-ofStatements/for-of16.ts(2,11): error TS2489: The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of16.ts (1 errors) ==== + var v: string; + for (v of new StringIterator) { } // Should fail + ~~~~~~~~~~~~~~~~~~ +!!! error TS2489: The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method. + + class StringIterator { + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of16.js b/tests/baselines/reference/for-of16.js new file mode 100644 index 0000000000000..21ba2adb75c47 --- /dev/null +++ b/tests/baselines/reference/for-of16.js @@ -0,0 +1,21 @@ +//// [for-of16.ts] +var v: string; +for (v of new StringIterator) { } // Should fail + +class StringIterator { + [Symbol.iterator]() { + return this; + } +} + +//// [for-of16.js] +var v; +for (v of new StringIterator) { } // Should fail +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of17.errors.txt b/tests/baselines/reference/for-of17.errors.txt new file mode 100644 index 0000000000000..dfdeb8db007a9 --- /dev/null +++ b/tests/baselines/reference/for-of17.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/for-ofStatements/for-of17.ts(2,6): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of17.ts (1 errors) ==== + var v: string; + for (v of new NumberIterator) { } // Should succeed + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + + class NumberIterator { + next() { + return { + value: 0, + done: false + }; + } + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of17.js b/tests/baselines/reference/for-of17.js new file mode 100644 index 0000000000000..5c56cdab44596 --- /dev/null +++ b/tests/baselines/reference/for-of17.js @@ -0,0 +1,33 @@ +//// [for-of17.ts] +var v: string; +for (v of new NumberIterator) { } // Should succeed + +class NumberIterator { + next() { + return { + value: 0, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of17.js] +var v; +for (v of new NumberIterator) { } // Should succeed +var NumberIterator = (function () { + function NumberIterator() { + } + NumberIterator.prototype.next = function () { + return { + value: 0, + done: false + }; + }; + NumberIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return NumberIterator; +})(); diff --git a/tests/baselines/reference/for-of18.js b/tests/baselines/reference/for-of18.js new file mode 100644 index 0000000000000..57168d9bf0783 --- /dev/null +++ b/tests/baselines/reference/for-of18.js @@ -0,0 +1,33 @@ +//// [for-of18.ts] +var v: string; +for (v of new StringIterator) { } // Should succeed + +class StringIterator { + next() { + return { + value: "", + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of18.js] +var v; +for (v of new StringIterator) { } // Should succeed +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return { + value: "", + done: false + }; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of18.types b/tests/baselines/reference/for-of18.types new file mode 100644 index 0000000000000..9ade935947581 --- /dev/null +++ b/tests/baselines/reference/for-of18.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of18.ts === +var v: string; +>v : string + +for (v of new StringIterator) { } // Should succeed +>v : string +>new StringIterator : StringIterator +>StringIterator : typeof StringIterator + +class StringIterator { +>StringIterator : StringIterator + + next() { +>next : () => { value: string; done: boolean; } + + return { +>{ value: "", done: false } : { value: string; done: boolean; } + + value: "", +>value : string + + done: false +>done : boolean + + }; + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : StringIterator + } +} diff --git a/tests/baselines/reference/for-of19.js b/tests/baselines/reference/for-of19.js new file mode 100644 index 0000000000000..eefb9339f18bd --- /dev/null +++ b/tests/baselines/reference/for-of19.js @@ -0,0 +1,41 @@ +//// [for-of19.ts] +for (var v of new FooIterator) { + v; +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of19.js] +for (var v of new FooIterator) { + v; +} +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var FooIterator = (function () { + function FooIterator() { + } + FooIterator.prototype.next = function () { + return { + value: new Foo, + done: false + }; + }; + FooIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return FooIterator; +})(); diff --git a/tests/baselines/reference/for-of19.types b/tests/baselines/reference/for-of19.types new file mode 100644 index 0000000000000..49172b09d83ea --- /dev/null +++ b/tests/baselines/reference/for-of19.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of19.ts === +for (var v of new FooIterator) { +>v : Foo +>new FooIterator : FooIterator +>FooIterator : typeof FooIterator + + v; +>v : Foo +} + +class Foo { } +>Foo : Foo + +class FooIterator { +>FooIterator : FooIterator + + next() { +>next : () => { value: Foo; done: boolean; } + + return { +>{ value: new Foo, done: false } : { value: Foo; done: boolean; } + + value: new Foo, +>value : Foo +>new Foo : Foo +>Foo : typeof Foo + + done: false +>done : boolean + + }; + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : FooIterator + } +} diff --git a/tests/baselines/reference/for-of2.errors.txt b/tests/baselines/reference/for-of2.errors.txt new file mode 100644 index 0000000000000..0b5133cde13ee --- /dev/null +++ b/tests/baselines/reference/for-of2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/for-ofStatements/for-of2.ts(1,7): error TS1155: 'const' declarations must be initialized +tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a previously defined constant. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of2.ts (2 errors) ==== + const v; + ~ +!!! error TS1155: 'const' declarations must be initialized + for (v of []) { } + ~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a previously defined constant. \ No newline at end of file diff --git a/tests/baselines/reference/for-of2.js b/tests/baselines/reference/for-of2.js new file mode 100644 index 0000000000000..d7eceb7c49ed4 --- /dev/null +++ b/tests/baselines/reference/for-of2.js @@ -0,0 +1,7 @@ +//// [for-of2.ts] +const v; +for (v of []) { } + +//// [for-of2.js] +const v; +for (v of []) { } diff --git a/tests/baselines/reference/for-of20.js b/tests/baselines/reference/for-of20.js new file mode 100644 index 0000000000000..39b1081954be7 --- /dev/null +++ b/tests/baselines/reference/for-of20.js @@ -0,0 +1,41 @@ +//// [for-of20.ts] +for (let v of new FooIterator) { + v; +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of20.js] +for (let v of new FooIterator) { + v; +} +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var FooIterator = (function () { + function FooIterator() { + } + FooIterator.prototype.next = function () { + return { + value: new Foo, + done: false + }; + }; + FooIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return FooIterator; +})(); diff --git a/tests/baselines/reference/for-of20.types b/tests/baselines/reference/for-of20.types new file mode 100644 index 0000000000000..e967869fbd067 --- /dev/null +++ b/tests/baselines/reference/for-of20.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of20.ts === +for (let v of new FooIterator) { +>v : Foo +>new FooIterator : FooIterator +>FooIterator : typeof FooIterator + + v; +>v : Foo +} + +class Foo { } +>Foo : Foo + +class FooIterator { +>FooIterator : FooIterator + + next() { +>next : () => { value: Foo; done: boolean; } + + return { +>{ value: new Foo, done: false } : { value: Foo; done: boolean; } + + value: new Foo, +>value : Foo +>new Foo : Foo +>Foo : typeof Foo + + done: false +>done : boolean + + }; + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : FooIterator + } +} diff --git a/tests/baselines/reference/for-of21.js b/tests/baselines/reference/for-of21.js new file mode 100644 index 0000000000000..5deaad3c2d8f6 --- /dev/null +++ b/tests/baselines/reference/for-of21.js @@ -0,0 +1,41 @@ +//// [for-of21.ts] +for (const v of new FooIterator) { + v; +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of21.js] +for (const v of new FooIterator) { + v; +} +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var FooIterator = (function () { + function FooIterator() { + } + FooIterator.prototype.next = function () { + return { + value: new Foo, + done: false + }; + }; + FooIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return FooIterator; +})(); diff --git a/tests/baselines/reference/for-of21.types b/tests/baselines/reference/for-of21.types new file mode 100644 index 0000000000000..362f92577e23e --- /dev/null +++ b/tests/baselines/reference/for-of21.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of21.ts === +for (const v of new FooIterator) { +>v : Foo +>new FooIterator : FooIterator +>FooIterator : typeof FooIterator + + v; +>v : Foo +} + +class Foo { } +>Foo : Foo + +class FooIterator { +>FooIterator : FooIterator + + next() { +>next : () => { value: Foo; done: boolean; } + + return { +>{ value: new Foo, done: false } : { value: Foo; done: boolean; } + + value: new Foo, +>value : Foo +>new Foo : Foo +>Foo : typeof Foo + + done: false +>done : boolean + + }; + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : FooIterator + } +} diff --git a/tests/baselines/reference/for-of22.js b/tests/baselines/reference/for-of22.js new file mode 100644 index 0000000000000..d38accb6cd818 --- /dev/null +++ b/tests/baselines/reference/for-of22.js @@ -0,0 +1,42 @@ +//// [for-of22.ts] +v; +for (var v of new FooIterator) { + +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of22.js] +v; +for (var v of new FooIterator) { +} +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var FooIterator = (function () { + function FooIterator() { + } + FooIterator.prototype.next = function () { + return { + value: new Foo, + done: false + }; + }; + FooIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return FooIterator; +})(); diff --git a/tests/baselines/reference/for-of22.types b/tests/baselines/reference/for-of22.types new file mode 100644 index 0000000000000..bb2d5569bfc69 --- /dev/null +++ b/tests/baselines/reference/for-of22.types @@ -0,0 +1,42 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of22.ts === +v; +>v : Foo + +for (var v of new FooIterator) { +>v : Foo +>new FooIterator : FooIterator +>FooIterator : typeof FooIterator + +} + +class Foo { } +>Foo : Foo + +class FooIterator { +>FooIterator : FooIterator + + next() { +>next : () => { value: Foo; done: boolean; } + + return { +>{ value: new Foo, done: false } : { value: Foo; done: boolean; } + + value: new Foo, +>value : Foo +>new Foo : Foo +>Foo : typeof Foo + + done: false +>done : boolean + + }; + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : FooIterator + } +} diff --git a/tests/baselines/reference/for-of23.js b/tests/baselines/reference/for-of23.js new file mode 100644 index 0000000000000..87bb1fd428d29 --- /dev/null +++ b/tests/baselines/reference/for-of23.js @@ -0,0 +1,41 @@ +//// [for-of23.ts] +for (const v of new FooIterator) { + const v = 0; // new scope +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of23.js] +for (const v of new FooIterator) { + const v = 0; // new scope +} +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var FooIterator = (function () { + function FooIterator() { + } + FooIterator.prototype.next = function () { + return { + value: new Foo, + done: false + }; + }; + FooIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return FooIterator; +})(); diff --git a/tests/baselines/reference/for-of23.types b/tests/baselines/reference/for-of23.types new file mode 100644 index 0000000000000..b490616edc88b --- /dev/null +++ b/tests/baselines/reference/for-of23.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of23.ts === +for (const v of new FooIterator) { +>v : Foo +>new FooIterator : FooIterator +>FooIterator : typeof FooIterator + + const v = 0; // new scope +>v : number +} + +class Foo { } +>Foo : Foo + +class FooIterator { +>FooIterator : FooIterator + + next() { +>next : () => { value: Foo; done: boolean; } + + return { +>{ value: new Foo, done: false } : { value: Foo; done: boolean; } + + value: new Foo, +>value : Foo +>new Foo : Foo +>Foo : typeof Foo + + done: false +>done : boolean + + }; + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : FooIterator + } +} diff --git a/tests/baselines/reference/for-of24.js b/tests/baselines/reference/for-of24.js new file mode 100644 index 0000000000000..b491851960332 --- /dev/null +++ b/tests/baselines/reference/for-of24.js @@ -0,0 +1,8 @@ +//// [for-of24.ts] +var x: any; +for (var v of x) { } + + +//// [for-of24.js] +var x; +for (var v of x) { } diff --git a/tests/baselines/reference/for-of24.types b/tests/baselines/reference/for-of24.types new file mode 100644 index 0000000000000..dc27cc32e2164 --- /dev/null +++ b/tests/baselines/reference/for-of24.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of24.ts === +var x: any; +>x : any + +for (var v of x) { } +>v : any +>x : any + diff --git a/tests/baselines/reference/for-of25.js b/tests/baselines/reference/for-of25.js new file mode 100644 index 0000000000000..21b5ce1408bce --- /dev/null +++ b/tests/baselines/reference/for-of25.js @@ -0,0 +1,21 @@ +//// [for-of25.ts] +var x: any; +for (var v of new StringIterator) { } + +class StringIterator { + [Symbol.iterator]() { + return x; + } +} + +//// [for-of25.js] +var x; +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype[Symbol.iterator] = function () { + return x; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of25.types b/tests/baselines/reference/for-of25.types new file mode 100644 index 0000000000000..c4d6b32aebc4e --- /dev/null +++ b/tests/baselines/reference/for-of25.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of25.ts === +var x: any; +>x : any + +for (var v of new StringIterator) { } +>v : any +>new StringIterator : StringIterator +>StringIterator : typeof StringIterator + +class StringIterator { +>StringIterator : StringIterator + + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return x; +>x : any + } +} diff --git a/tests/baselines/reference/for-of26.js b/tests/baselines/reference/for-of26.js new file mode 100644 index 0000000000000..a45492a81c015 --- /dev/null +++ b/tests/baselines/reference/for-of26.js @@ -0,0 +1,27 @@ +//// [for-of26.ts] +var x: any; +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return x; + } + [Symbol.iterator]() { + return this; + } +} + +//// [for-of26.js] +var x; +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return x; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of26.types b/tests/baselines/reference/for-of26.types new file mode 100644 index 0000000000000..d2608fbf15434 --- /dev/null +++ b/tests/baselines/reference/for-of26.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of26.ts === +var x: any; +>x : any + +for (var v of new StringIterator) { } +>v : any +>new StringIterator : StringIterator +>StringIterator : typeof StringIterator + +class StringIterator { +>StringIterator : StringIterator + + next() { +>next : () => any + + return x; +>x : any + } + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : StringIterator + } +} diff --git a/tests/baselines/reference/for-of27.js b/tests/baselines/reference/for-of27.js new file mode 100644 index 0000000000000..91e1e7194c136 --- /dev/null +++ b/tests/baselines/reference/for-of27.js @@ -0,0 +1,14 @@ +//// [for-of27.ts] +for (var v of new StringIterator) { } + +class StringIterator { + [Symbol.iterator]: any; +} + +//// [for-of27.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of27.types b/tests/baselines/reference/for-of27.types new file mode 100644 index 0000000000000..8e9130ce272b0 --- /dev/null +++ b/tests/baselines/reference/for-of27.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of27.ts === +for (var v of new StringIterator) { } +>v : any +>new StringIterator : StringIterator +>StringIterator : typeof StringIterator + +class StringIterator { +>StringIterator : StringIterator + + [Symbol.iterator]: any; +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol +} diff --git a/tests/baselines/reference/for-of28.js b/tests/baselines/reference/for-of28.js new file mode 100644 index 0000000000000..06029e6bb089e --- /dev/null +++ b/tests/baselines/reference/for-of28.js @@ -0,0 +1,20 @@ +//// [for-of28.ts] +for (var v of new StringIterator) { } + +class StringIterator { + next: any; + [Symbol.iterator]() { + return this; + } +} + +//// [for-of28.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of28.types b/tests/baselines/reference/for-of28.types new file mode 100644 index 0000000000000..91b77a55a4dfb --- /dev/null +++ b/tests/baselines/reference/for-of28.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of28.ts === +for (var v of new StringIterator) { } +>v : any +>new StringIterator : StringIterator +>StringIterator : typeof StringIterator + +class StringIterator { +>StringIterator : StringIterator + + next: any; +>next : any + + [Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + return this; +>this : StringIterator + } +} diff --git a/tests/baselines/reference/for-of29.errors.txt b/tests/baselines/reference/for-of29.errors.txt new file mode 100644 index 0000000000000..748fcf490505a --- /dev/null +++ b/tests/baselines/reference/for-of29.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/for-ofStatements/for-of29.ts(5,15): error TS2322: Type '{ [Symbol.iterator]?(): Iterator; }' is not assignable to type 'Iterable'. + Property '[Symbol.iterator]' is optional in type '{ [Symbol.iterator]?(): Iterator; }' but required in type 'Iterable'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of29.ts (1 errors) ==== + var iterableWithOptionalIterator: { + [Symbol.iterator]?(): Iterator + }; + + for (var v of iterableWithOptionalIterator) { } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ [Symbol.iterator]?(): Iterator; }' is not assignable to type 'Iterable'. +!!! error TS2322: Property '[Symbol.iterator]' is optional in type '{ [Symbol.iterator]?(): Iterator; }' but required in type 'Iterable'. + \ No newline at end of file diff --git a/tests/baselines/reference/for-of29.js b/tests/baselines/reference/for-of29.js new file mode 100644 index 0000000000000..450cafbde856c --- /dev/null +++ b/tests/baselines/reference/for-of29.js @@ -0,0 +1,11 @@ +//// [for-of29.ts] +var iterableWithOptionalIterator: { + [Symbol.iterator]?(): Iterator +}; + +for (var v of iterableWithOptionalIterator) { } + + +//// [for-of29.js] +var iterableWithOptionalIterator; +for (var v of iterableWithOptionalIterator) { } diff --git a/tests/baselines/reference/for-of3.errors.txt b/tests/baselines/reference/for-of3.errors.txt new file mode 100644 index 0000000000000..ba8e3e4a5c688 --- /dev/null +++ b/tests/baselines/reference/for-of3.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Invalid left-hand side in 'for...of' statement. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ==== + var v; + for (v++ of []) { } + ~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. \ No newline at end of file diff --git a/tests/baselines/reference/for-of3.js b/tests/baselines/reference/for-of3.js new file mode 100644 index 0000000000000..7ef271877021a --- /dev/null +++ b/tests/baselines/reference/for-of3.js @@ -0,0 +1,7 @@ +//// [for-of3.ts] +var v; +for (v++ of []) { } + +//// [for-of3.js] +var v; +for (v++ of []) { } diff --git a/tests/baselines/reference/for-of30.errors.txt b/tests/baselines/reference/for-of30.errors.txt new file mode 100644 index 0000000000000..6434b5294d543 --- /dev/null +++ b/tests/baselines/reference/for-of30.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/es6/for-ofStatements/for-of30.ts(1,15): error TS2322: Type 'StringIterator' is not assignable to type 'Iterable'. + Types of property '[Symbol.iterator]' are incompatible. + Type '() => StringIterator' is not assignable to type '() => Iterator'. + Type 'StringIterator' is not assignable to type 'Iterator'. + Types of property 'return' are incompatible. + Type 'number' is not assignable to type '(value?: any) => IteratorResult'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of30.ts (1 errors) ==== + for (var v of new StringIterator) { } + ~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterable'. +!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible. +!!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator'. +!!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator'. +!!! error TS2322: Types of property 'return' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type '(value?: any) => IteratorResult'. + + class StringIterator { + next() { + return { + done: false, + value: "" + } + } + + return = 0; + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of30.js b/tests/baselines/reference/for-of30.js new file mode 100644 index 0000000000000..4618dae5ff607 --- /dev/null +++ b/tests/baselines/reference/for-of30.js @@ -0,0 +1,35 @@ +//// [for-of30.ts] +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return { + done: false, + value: "" + } + } + + return = 0; + + [Symbol.iterator]() { + return this; + } +} + +//// [for-of30.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + this.return = 0; + } + StringIterator.prototype.next = function () { + return { + done: false, + value: "" + }; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of31.errors.txt b/tests/baselines/reference/for-of31.errors.txt new file mode 100644 index 0000000000000..74afff00e99e3 --- /dev/null +++ b/tests/baselines/reference/for-of31.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/es6/for-ofStatements/for-of31.ts(1,15): error TS2322: Type 'StringIterator' is not assignable to type 'Iterable'. + Types of property '[Symbol.iterator]' are incompatible. + Type '() => StringIterator' is not assignable to type '() => Iterator'. + Type 'StringIterator' is not assignable to type 'Iterator'. + Types of property 'next' are incompatible. + Type '() => { value: string; }' is not assignable to type '() => IteratorResult'. + Type '{ value: string; }' is not assignable to type 'IteratorResult'. + Property 'done' is missing in type '{ value: string; }'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of31.ts (1 errors) ==== + for (var v of new StringIterator) { } + ~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterable'. +!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible. +!!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator'. +!!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator'. +!!! error TS2322: Types of property 'next' are incompatible. +!!! error TS2322: Type '() => { value: string; }' is not assignable to type '() => IteratorResult'. +!!! error TS2322: Type '{ value: string; }' is not assignable to type 'IteratorResult'. +!!! error TS2322: Property 'done' is missing in type '{ value: string; }'. + + class StringIterator { + next() { + return { + // no done property + value: "" + } + } + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of31.js b/tests/baselines/reference/for-of31.js new file mode 100644 index 0000000000000..588c75a1145c1 --- /dev/null +++ b/tests/baselines/reference/for-of31.js @@ -0,0 +1,32 @@ +//// [for-of31.ts] +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return { + // no done property + value: "" + } + } + + [Symbol.iterator]() { + return this; + } +} + +//// [for-of31.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return { + // no done property + value: "" + }; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of32.errors.txt b/tests/baselines/reference/for-of32.errors.txt new file mode 100644 index 0000000000000..4b139d386c0c9 --- /dev/null +++ b/tests/baselines/reference/for-of32.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of32.ts (1 errors) ==== + for (var v of v) { } + ~ +!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file diff --git a/tests/baselines/reference/for-of32.js b/tests/baselines/reference/for-of32.js new file mode 100644 index 0000000000000..d25d16fbebe0f --- /dev/null +++ b/tests/baselines/reference/for-of32.js @@ -0,0 +1,5 @@ +//// [for-of32.ts] +for (var v of v) { } + +//// [for-of32.js] +for (var v of v) { } diff --git a/tests/baselines/reference/for-of33.errors.txt b/tests/baselines/reference/for-of33.errors.txt new file mode 100644 index 0000000000000..1c631042d7d0c --- /dev/null +++ b/tests/baselines/reference/for-of33.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (1 errors) ==== + for (var v of new StringIterator) { } + ~ +!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + class StringIterator { + [Symbol.iterator]() { + return v; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of33.js b/tests/baselines/reference/for-of33.js new file mode 100644 index 0000000000000..91d8de41c6ab6 --- /dev/null +++ b/tests/baselines/reference/for-of33.js @@ -0,0 +1,19 @@ +//// [for-of33.ts] +for (var v of new StringIterator) { } + +class StringIterator { + [Symbol.iterator]() { + return v; + } +} + +//// [for-of33.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype[Symbol.iterator] = function () { + return v; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of34.errors.txt b/tests/baselines/reference/for-of34.errors.txt new file mode 100644 index 0000000000000..994302db88b43 --- /dev/null +++ b/tests/baselines/reference/for-of34.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (1 errors) ==== + for (var v of new StringIterator) { } + ~ +!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + class StringIterator { + next() { + return v; + } + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of34.js b/tests/baselines/reference/for-of34.js new file mode 100644 index 0000000000000..ccb6006c63d5e --- /dev/null +++ b/tests/baselines/reference/for-of34.js @@ -0,0 +1,26 @@ +//// [for-of34.ts] +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return v; + } + + [Symbol.iterator]() { + return this; + } +} + +//// [for-of34.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return v; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of35.errors.txt b/tests/baselines/reference/for-of35.errors.txt new file mode 100644 index 0000000000000..f83b6d2ec3cec --- /dev/null +++ b/tests/baselines/reference/for-of35.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (1 errors) ==== + for (var v of new StringIterator) { } + ~ +!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. + + class StringIterator { + next() { + return { + done: true, + value: v + } + } + + [Symbol.iterator]() { + return this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of35.js b/tests/baselines/reference/for-of35.js new file mode 100644 index 0000000000000..a4f1a37e3bfe0 --- /dev/null +++ b/tests/baselines/reference/for-of35.js @@ -0,0 +1,32 @@ +//// [for-of35.ts] +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return { + done: true, + value: v + } + } + + [Symbol.iterator]() { + return this; + } +} + +//// [for-of35.js] +for (var v of new StringIterator) { } +var StringIterator = (function () { + function StringIterator() { + } + StringIterator.prototype.next = function () { + return { + done: true, + value: v + }; + }; + StringIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return StringIterator; +})(); diff --git a/tests/baselines/reference/for-of36.js b/tests/baselines/reference/for-of36.js new file mode 100644 index 0000000000000..14523695151ca --- /dev/null +++ b/tests/baselines/reference/for-of36.js @@ -0,0 +1,11 @@ +//// [for-of36.ts] +var tuple: [string, boolean] = ["", true]; +for (var v of tuple) { + v; +} + +//// [for-of36.js] +var tuple = ["", true]; +for (var v of tuple) { + v; +} diff --git a/tests/baselines/reference/for-of36.types b/tests/baselines/reference/for-of36.types new file mode 100644 index 0000000000000..da03367ba5d6b --- /dev/null +++ b/tests/baselines/reference/for-of36.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of36.ts === +var tuple: [string, boolean] = ["", true]; +>tuple : [string, boolean] +>["", true] : [string, boolean] + +for (var v of tuple) { +>v : string | boolean +>tuple : [string, boolean] + + v; +>v : string | boolean +} diff --git a/tests/baselines/reference/for-of37.js b/tests/baselines/reference/for-of37.js new file mode 100644 index 0000000000000..472193e6cb51f --- /dev/null +++ b/tests/baselines/reference/for-of37.js @@ -0,0 +1,11 @@ +//// [for-of37.ts] +var map = new Map([["", true]]); +for (var v of map) { + v; +} + +//// [for-of37.js] +var map = new Map([["", true]]); +for (var v of map) { + v; +} diff --git a/tests/baselines/reference/for-of37.types b/tests/baselines/reference/for-of37.types new file mode 100644 index 0000000000000..f137db79af098 --- /dev/null +++ b/tests/baselines/reference/for-of37.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of37.ts === +var map = new Map([["", true]]); +>map : Map +>new Map([["", true]]) : Map +>Map : MapConstructor +>[["", true]] : [string, boolean][] +>["", true] : [string, boolean] + +for (var v of map) { +>v : [string, boolean] +>map : Map + + v; +>v : [string, boolean] +} diff --git a/tests/baselines/reference/for-of38.js b/tests/baselines/reference/for-of38.js new file mode 100644 index 0000000000000..1f0ac09682e25 --- /dev/null +++ b/tests/baselines/reference/for-of38.js @@ -0,0 +1,13 @@ +//// [for-of38.ts] +var map = new Map([["", true]]); +for (var [k, v] of map) { + k; + v; +} + +//// [for-of38.js] +var map = new Map([["", true]]); +for (var [k, v] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of38.types b/tests/baselines/reference/for-of38.types new file mode 100644 index 0000000000000..cdd1e05dd7eae --- /dev/null +++ b/tests/baselines/reference/for-of38.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of38.ts === +var map = new Map([["", true]]); +>map : Map +>new Map([["", true]]) : Map +>Map : MapConstructor +>[["", true]] : [string, boolean][] +>["", true] : [string, boolean] + +for (var [k, v] of map) { +>k : string +>v : boolean +>map : Map + + k; +>k : string + + v; +>v : boolean +} diff --git a/tests/baselines/reference/for-of39.errors.txt b/tests/baselines/reference/for-of39.errors.txt new file mode 100644 index 0000000000000..48db183a58cd3 --- /dev/null +++ b/tests/baselines/reference/for-of39.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/for-ofStatements/for-of39.ts(1,15): error TS2453: The type argument for type parameter 'V' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'boolean' is not a valid type argument because it is not a supertype of candidate 'number'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of39.ts (1 errors) ==== + var map = new Map([["", true], ["", 0]]); + ~~~ +!!! error TS2453: The type argument for type parameter 'V' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'boolean' is not a valid type argument because it is not a supertype of candidate 'number'. + for (var [k, v] of map) { + k; + v; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of39.js b/tests/baselines/reference/for-of39.js new file mode 100644 index 0000000000000..91dbc56c0abce --- /dev/null +++ b/tests/baselines/reference/for-of39.js @@ -0,0 +1,13 @@ +//// [for-of39.ts] +var map = new Map([["", true], ["", 0]]); +for (var [k, v] of map) { + k; + v; +} + +//// [for-of39.js] +var map = new Map([["", true], ["", 0]]); +for (var [k, v] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of4.js b/tests/baselines/reference/for-of4.js new file mode 100644 index 0000000000000..147619d2fe2ef --- /dev/null +++ b/tests/baselines/reference/for-of4.js @@ -0,0 +1,9 @@ +//// [for-of4.ts] +for (var v of [0]) { + v; +} + +//// [for-of4.js] +for (var v of [0]) { + v; +} diff --git a/tests/baselines/reference/for-of4.types b/tests/baselines/reference/for-of4.types new file mode 100644 index 0000000000000..2076fae84fc48 --- /dev/null +++ b/tests/baselines/reference/for-of4.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of4.ts === +for (var v of [0]) { +>v : number +>[0] : number[] + + v; +>v : number +} diff --git a/tests/baselines/reference/for-of40.js b/tests/baselines/reference/for-of40.js new file mode 100644 index 0000000000000..243f81097db9a --- /dev/null +++ b/tests/baselines/reference/for-of40.js @@ -0,0 +1,13 @@ +//// [for-of40.ts] +var map = new Map([["", true]]); +for (var [k = "", v = false] of map) { + k; + v; +} + +//// [for-of40.js] +var map = new Map([["", true]]); +for (var [k = "", v = false] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of40.types b/tests/baselines/reference/for-of40.types new file mode 100644 index 0000000000000..c0fe7cbbc0267 --- /dev/null +++ b/tests/baselines/reference/for-of40.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of40.ts === +var map = new Map([["", true]]); +>map : Map +>new Map([["", true]]) : Map +>Map : MapConstructor +>[["", true]] : [string, boolean][] +>["", true] : [string, boolean] + +for (var [k = "", v = false] of map) { +>k : string +>v : boolean +>map : Map + + k; +>k : string + + v; +>v : boolean +} diff --git a/tests/baselines/reference/for-of41.js b/tests/baselines/reference/for-of41.js new file mode 100644 index 0000000000000..0fa380c53c499 --- /dev/null +++ b/tests/baselines/reference/for-of41.js @@ -0,0 +1,13 @@ +//// [for-of41.ts] +var array = [{x: [0], y: {p: ""}}] +for (var {x: [a], y: {p}} of array) { + a; + p; +} + +//// [for-of41.js] +var array = [{ x: [0], y: { p: "" } }]; +for (var { x: [a], y: { p } } of array) { + a; + p; +} diff --git a/tests/baselines/reference/for-of41.types b/tests/baselines/reference/for-of41.types new file mode 100644 index 0000000000000..54e58aa1ec7a5 --- /dev/null +++ b/tests/baselines/reference/for-of41.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of41.ts === +var array = [{x: [0], y: {p: ""}}] +>array : { x: number[]; y: { p: string; }; }[] +>[{x: [0], y: {p: ""}}] : { x: number[]; y: { p: string; }; }[] +>{x: [0], y: {p: ""}} : { x: number[]; y: { p: string; }; } +>x : number[] +>[0] : number[] +>y : { p: string; } +>{p: ""} : { p: string; } +>p : string + +for (var {x: [a], y: {p}} of array) { +>x : unknown +>a : number +>y : unknown +>p : string +>array : { x: number[]; y: { p: string; }; }[] + + a; +>a : number + + p; +>p : string +} diff --git a/tests/baselines/reference/for-of42.js b/tests/baselines/reference/for-of42.js new file mode 100644 index 0000000000000..1fa9219df47b3 --- /dev/null +++ b/tests/baselines/reference/for-of42.js @@ -0,0 +1,13 @@ +//// [for-of42.ts] +var array = [{ x: "", y: 0 }] +for (var {x: a, y: b} of array) { + a; + b; +} + +//// [for-of42.js] +var array = [{ x: "", y: 0 }]; +for (var { x: a, y: b } of array) { + a; + b; +} diff --git a/tests/baselines/reference/for-of42.types b/tests/baselines/reference/for-of42.types new file mode 100644 index 0000000000000..1a819452770fb --- /dev/null +++ b/tests/baselines/reference/for-of42.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of42.ts === +var array = [{ x: "", y: 0 }] +>array : { x: string; y: number; }[] +>[{ x: "", y: 0 }] : { x: string; y: number; }[] +>{ x: "", y: 0 } : { x: string; y: number; } +>x : string +>y : number + +for (var {x: a, y: b} of array) { +>x : unknown +>a : string +>y : unknown +>b : number +>array : { x: string; y: number; }[] + + a; +>a : string + + b; +>b : number +} diff --git a/tests/baselines/reference/for-of43.errors.txt b/tests/baselines/reference/for-of43.errors.txt new file mode 100644 index 0000000000000..c5790278e5341 --- /dev/null +++ b/tests/baselines/reference/for-of43.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/for-ofStatements/for-of43.ts(2,25): error TS2322: Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of43.ts (1 errors) ==== + var array = [{ x: "", y: 0 }] + for (var {x: a = "", y: b = true} of array) { + ~ +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + a; + b; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of43.js b/tests/baselines/reference/for-of43.js new file mode 100644 index 0000000000000..de3b4fcd9b0ab --- /dev/null +++ b/tests/baselines/reference/for-of43.js @@ -0,0 +1,13 @@ +//// [for-of43.ts] +var array = [{ x: "", y: 0 }] +for (var {x: a = "", y: b = true} of array) { + a; + b; +} + +//// [for-of43.js] +var array = [{ x: "", y: 0 }]; +for (var { x: a = "", y: b = true } of array) { + a; + b; +} diff --git a/tests/baselines/reference/for-of44.js b/tests/baselines/reference/for-of44.js new file mode 100644 index 0000000000000..087485ed73f81 --- /dev/null +++ b/tests/baselines/reference/for-of44.js @@ -0,0 +1,13 @@ +//// [for-of44.ts] +var array: [number, string | boolean | symbol][] = [[0, ""], [0, true], [1, Symbol()]] +for (var [num, strBoolSym] of array) { + num; + strBoolSym; +} + +//// [for-of44.js] +var array = [[0, ""], [0, true], [1, Symbol()]]; +for (var [num, strBoolSym] of array) { + num; + strBoolSym; +} diff --git a/tests/baselines/reference/for-of44.types b/tests/baselines/reference/for-of44.types new file mode 100644 index 0000000000000..078b49bd309f9 --- /dev/null +++ b/tests/baselines/reference/for-of44.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of44.ts === +var array: [number, string | boolean | symbol][] = [[0, ""], [0, true], [1, Symbol()]] +>array : [number, string | boolean | symbol][] +>[[0, ""], [0, true], [1, Symbol()]] : ([number, string] | [number, boolean] | [number, symbol])[] +>[0, ""] : [number, string] +>[0, true] : [number, boolean] +>[1, Symbol()] : [number, symbol] +>Symbol() : symbol +>Symbol : SymbolConstructor + +for (var [num, strBoolSym] of array) { +>num : number +>strBoolSym : string | boolean | symbol +>array : [number, string | boolean | symbol][] + + num; +>num : number + + strBoolSym; +>strBoolSym : string | boolean | symbol +} diff --git a/tests/baselines/reference/for-of45.js b/tests/baselines/reference/for-of45.js new file mode 100644 index 0000000000000..1222b2dcdd5e8 --- /dev/null +++ b/tests/baselines/reference/for-of45.js @@ -0,0 +1,15 @@ +//// [for-of45.ts] +var k: string, v: boolean; +var map = new Map([["", true]]); +for ([k = "", v = false] of map) { + k; + v; +} + +//// [for-of45.js] +var k, v; +var map = new Map([["", true]]); +for ([k = "", v = false] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of45.types b/tests/baselines/reference/for-of45.types new file mode 100644 index 0000000000000..8ac4b9fa7e97c --- /dev/null +++ b/tests/baselines/reference/for-of45.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of45.ts === +var k: string, v: boolean; +>k : string +>v : boolean + +var map = new Map([["", true]]); +>map : Map +>new Map([["", true]]) : Map +>Map : MapConstructor +>[["", true]] : [string, boolean][] +>["", true] : [string, boolean] + +for ([k = "", v = false] of map) { +>[k = "", v = false] : (string | boolean)[] +>k = "" : string +>k : string +>v = false : boolean +>v : boolean +>map : Map + + k; +>k : string + + v; +>v : boolean +} diff --git a/tests/baselines/reference/for-of46.errors.txt b/tests/baselines/reference/for-of46.errors.txt new file mode 100644 index 0000000000000..13685b122ca7e --- /dev/null +++ b/tests/baselines/reference/for-of46.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/for-ofStatements/for-of46.ts(3,7): error TS2322: Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/es6/for-ofStatements/for-of46.ts(3,18): error TS2322: Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of46.ts (2 errors) ==== + var k: string, v: boolean; + var map = new Map([["", true]]); + for ([k = false, v = ""] of map) { + ~ +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + ~ +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. + k; + v; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of46.js b/tests/baselines/reference/for-of46.js new file mode 100644 index 0000000000000..2ea15936c5411 --- /dev/null +++ b/tests/baselines/reference/for-of46.js @@ -0,0 +1,15 @@ +//// [for-of46.ts] +var k: string, v: boolean; +var map = new Map([["", true]]); +for ([k = false, v = ""] of map) { + k; + v; +} + +//// [for-of46.js] +var k, v; +var map = new Map([["", true]]); +for ([k = false, v = ""] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of47.errors.txt b/tests/baselines/reference/for-of47.errors.txt new file mode 100644 index 0000000000000..241dc107caa64 --- /dev/null +++ b/tests/baselines/reference/for-of47.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/for-ofStatements/for-of47.ts(4,13): error TS2322: Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of47.ts (1 errors) ==== + var x: string, y: number; + var array = [{ x: "", y: true }] + enum E { x } + for ({x, y: y = E.x} of array) { + ~ +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + x; + y; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of47.js b/tests/baselines/reference/for-of47.js new file mode 100644 index 0000000000000..b2de46d677f7d --- /dev/null +++ b/tests/baselines/reference/for-of47.js @@ -0,0 +1,20 @@ +//// [for-of47.ts] +var x: string, y: number; +var array = [{ x: "", y: true }] +enum E { x } +for ({x, y: y = E.x} of array) { + x; + y; +} + +//// [for-of47.js] +var x, y; +var array = [{ x: "", y: true }]; +var E; +(function (E) { + E[E["x"] = 0] = "x"; +})(E || (E = {})); +for ({ x, y: y = 0 /* x */ } of array) { + x; + y; +} diff --git a/tests/baselines/reference/for-of48.errors.txt b/tests/baselines/reference/for-of48.errors.txt new file mode 100644 index 0000000000000..f6826e14c6138 --- /dev/null +++ b/tests/baselines/reference/for-of48.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/for-ofStatements/for-of48.ts(4,12): error TS1005: ':' expected. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of48.ts (1 errors) ==== + var x: string, y: number; + var array = [{ x: "", y: true }] + enum E { x } + for ({x, y = E.x} of array) { + ~ +!!! error TS1005: ':' expected. + x; + y; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of48.js b/tests/baselines/reference/for-of48.js new file mode 100644 index 0000000000000..15b9f5f12f61f --- /dev/null +++ b/tests/baselines/reference/for-of48.js @@ -0,0 +1,20 @@ +//// [for-of48.ts] +var x: string, y: number; +var array = [{ x: "", y: true }] +enum E { x } +for ({x, y = E.x} of array) { + x; + y; +} + +//// [for-of48.js] +var x, y; +var array = [{ x: "", y: true }]; +var E; +(function (E) { + E[E["x"] = 0] = "x"; +})(E || (E = {})); +for ({ x, y: = 0 /* x */ } of array) { + x; + y; +} diff --git a/tests/baselines/reference/for-of49.errors.txt b/tests/baselines/reference/for-of49.errors.txt new file mode 100644 index 0000000000000..d5bc314e678f9 --- /dev/null +++ b/tests/baselines/reference/for-of49.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/for-ofStatements/for-of49.ts(3,13): error TS2364: Invalid left-hand side of assignment expression. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of49.ts (1 errors) ==== + var k: string, v: boolean; + var map = new Map([["", true]]); + for ([k, ...[v]] of map) { + ~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + k; + v; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of49.js b/tests/baselines/reference/for-of49.js new file mode 100644 index 0000000000000..ac7f99f3607c4 --- /dev/null +++ b/tests/baselines/reference/for-of49.js @@ -0,0 +1,15 @@ +//// [for-of49.ts] +var k: string, v: boolean; +var map = new Map([["", true]]); +for ([k, ...[v]] of map) { + k; + v; +} + +//// [for-of49.js] +var k, v; +var map = new Map([["", true]]); +for ([k, ...[v]] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of5.js b/tests/baselines/reference/for-of5.js new file mode 100644 index 0000000000000..4d93b0bd48383 --- /dev/null +++ b/tests/baselines/reference/for-of5.js @@ -0,0 +1,9 @@ +//// [for-of5.ts] +for (let v of [0]) { + v; +} + +//// [for-of5.js] +for (let v of [0]) { + v; +} diff --git a/tests/baselines/reference/for-of5.types b/tests/baselines/reference/for-of5.types new file mode 100644 index 0000000000000..feac5ef9e521f --- /dev/null +++ b/tests/baselines/reference/for-of5.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of5.ts === +for (let v of [0]) { +>v : number +>[0] : number[] + + v; +>v : number +} diff --git a/tests/baselines/reference/for-of50.js b/tests/baselines/reference/for-of50.js new file mode 100644 index 0000000000000..a300812e6a960 --- /dev/null +++ b/tests/baselines/reference/for-of50.js @@ -0,0 +1,13 @@ +//// [for-of50.ts] +var map = new Map([["", true]]); +for (const [k, v] of map) { + k; + v; +} + +//// [for-of50.js] +var map = new Map([["", true]]); +for (const [k, v] of map) { + k; + v; +} diff --git a/tests/baselines/reference/for-of50.types b/tests/baselines/reference/for-of50.types new file mode 100644 index 0000000000000..a38f385517447 --- /dev/null +++ b/tests/baselines/reference/for-of50.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of50.ts === +var map = new Map([["", true]]); +>map : Map +>new Map([["", true]]) : Map +>Map : MapConstructor +>[["", true]] : [string, boolean][] +>["", true] : [string, boolean] + +for (const [k, v] of map) { +>k : string +>v : boolean +>map : Map + + k; +>k : string + + v; +>v : boolean +} diff --git a/tests/baselines/reference/for-of51.errors.txt b/tests/baselines/reference/for-of51.errors.txt new file mode 100644 index 0000000000000..54a6eb9d89c84 --- /dev/null +++ b/tests/baselines/reference/for-of51.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/for-ofStatements/for-of51.ts(1,10): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of51.ts (1 errors) ==== + for (let let of []) {} + ~~~ +!!! error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations. \ No newline at end of file diff --git a/tests/baselines/reference/for-of51.js b/tests/baselines/reference/for-of51.js new file mode 100644 index 0000000000000..cae8c8b38fef8 --- /dev/null +++ b/tests/baselines/reference/for-of51.js @@ -0,0 +1,5 @@ +//// [for-of51.ts] +for (let let of []) {} + +//// [for-of51.js] +for (let let of []) { } diff --git a/tests/baselines/reference/for-of52.errors.txt b/tests/baselines/reference/for-of52.errors.txt new file mode 100644 index 0000000000000..5110768e10471 --- /dev/null +++ b/tests/baselines/reference/for-of52.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/for-ofStatements/for-of52.ts(1,11): error TS2451: Cannot redeclare block-scoped variable 'v'. +tests/cases/conformance/es6/for-ofStatements/for-of52.ts(1,14): error TS2451: Cannot redeclare block-scoped variable 'v'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of52.ts (2 errors) ==== + for (let [v, v] of [[]]) {} + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'v'. + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'v'. \ No newline at end of file diff --git a/tests/baselines/reference/for-of52.js b/tests/baselines/reference/for-of52.js new file mode 100644 index 0000000000000..48e1dca936cb7 --- /dev/null +++ b/tests/baselines/reference/for-of52.js @@ -0,0 +1,5 @@ +//// [for-of52.ts] +for (let [v, v] of [[]]) {} + +//// [for-of52.js] +for (let [v, v] of [[]]) { } diff --git a/tests/baselines/reference/for-of53.js b/tests/baselines/reference/for-of53.js new file mode 100644 index 0000000000000..810d23644a6fb --- /dev/null +++ b/tests/baselines/reference/for-of53.js @@ -0,0 +1,9 @@ +//// [for-of53.ts] +for (let v of []) { + var v; +} + +//// [for-of53.js] +for (let v of []) { + var v; +} diff --git a/tests/baselines/reference/for-of53.types b/tests/baselines/reference/for-of53.types new file mode 100644 index 0000000000000..475d63e9b5af5 --- /dev/null +++ b/tests/baselines/reference/for-of53.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of53.ts === +for (let v of []) { +>v : any +>[] : undefined[] + + var v; +>v : any +} diff --git a/tests/baselines/reference/for-of54.errors.txt b/tests/baselines/reference/for-of54.errors.txt new file mode 100644 index 0000000000000..cb040c443828a --- /dev/null +++ b/tests/baselines/reference/for-of54.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/for-ofStatements/for-of54.ts(2,9): error TS2481: Cannot initialize outer scoped variable 'v' in the same scope as block scoped declaration 'v'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of54.ts (1 errors) ==== + for (let v of []) { + var v = 0; + ~ +!!! error TS2481: Cannot initialize outer scoped variable 'v' in the same scope as block scoped declaration 'v'. + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of54.js b/tests/baselines/reference/for-of54.js new file mode 100644 index 0000000000000..442e6e861462d --- /dev/null +++ b/tests/baselines/reference/for-of54.js @@ -0,0 +1,9 @@ +//// [for-of54.ts] +for (let v of []) { + var v = 0; +} + +//// [for-of54.js] +for (let v of []) { + var v = 0; +} diff --git a/tests/baselines/reference/for-of55.js b/tests/baselines/reference/for-of55.js new file mode 100644 index 0000000000000..a0f949c6ce591 --- /dev/null +++ b/tests/baselines/reference/for-of55.js @@ -0,0 +1,11 @@ +//// [for-of55.ts] +let v = [1]; +for (let v of v) { + v; +} + +//// [for-of55.js] +let v = [1]; +for (let v of v) { + v; +} diff --git a/tests/baselines/reference/for-of55.types b/tests/baselines/reference/for-of55.types new file mode 100644 index 0000000000000..b0f5aab3feee2 --- /dev/null +++ b/tests/baselines/reference/for-of55.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of55.ts === +let v = [1]; +>v : number[] +>[1] : number[] + +for (let v of v) { +>v : any +>v : any + + v; +>v : any +} diff --git a/tests/baselines/reference/for-of56.js b/tests/baselines/reference/for-of56.js new file mode 100644 index 0000000000000..0992b9c0bb961 --- /dev/null +++ b/tests/baselines/reference/for-of56.js @@ -0,0 +1,5 @@ +//// [for-of56.ts] +for (var let of []) {} + +//// [for-of56.js] +for (var let of []) { } diff --git a/tests/baselines/reference/for-of56.types b/tests/baselines/reference/for-of56.types new file mode 100644 index 0000000000000..d853ff9f62c72 --- /dev/null +++ b/tests/baselines/reference/for-of56.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of56.ts === +for (var let of []) {} +>let : any +>[] : undefined[] + diff --git a/tests/baselines/reference/for-of6.errors.txt b/tests/baselines/reference/for-of6.errors.txt new file mode 100644 index 0000000000000..03f41d18b2b2e --- /dev/null +++ b/tests/baselines/reference/for-of6.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/for-ofStatements/for-of6.ts(1,6): error TS2304: Cannot find name 'v'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of6.ts (1 errors) ==== + for (v of [0]) { + ~ +!!! error TS2304: Cannot find name 'v'. + let v; + } \ No newline at end of file diff --git a/tests/baselines/reference/for-of6.js b/tests/baselines/reference/for-of6.js new file mode 100644 index 0000000000000..24e93e2a9fd6a --- /dev/null +++ b/tests/baselines/reference/for-of6.js @@ -0,0 +1,9 @@ +//// [for-of6.ts] +for (v of [0]) { + let v; +} + +//// [for-of6.js] +for (v of [0]) { + let v; +} diff --git a/tests/baselines/reference/for-of7.errors.txt b/tests/baselines/reference/for-of7.errors.txt new file mode 100644 index 0000000000000..e67c51e2d9628 --- /dev/null +++ b/tests/baselines/reference/for-of7.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/for-ofStatements/for-of7.ts(1,1): error TS2304: Cannot find name 'v'. + + +==== tests/cases/conformance/es6/for-ofStatements/for-of7.ts (1 errors) ==== + v; + ~ +!!! error TS2304: Cannot find name 'v'. + for (let v of [0]) { } \ No newline at end of file diff --git a/tests/baselines/reference/for-of7.js b/tests/baselines/reference/for-of7.js new file mode 100644 index 0000000000000..04aadd9736a2f --- /dev/null +++ b/tests/baselines/reference/for-of7.js @@ -0,0 +1,7 @@ +//// [for-of7.ts] +v; +for (let v of [0]) { } + +//// [for-of7.js] +v; +for (let v of [0]) { } diff --git a/tests/baselines/reference/for-of8.js b/tests/baselines/reference/for-of8.js new file mode 100644 index 0000000000000..f33d69166dc44 --- /dev/null +++ b/tests/baselines/reference/for-of8.js @@ -0,0 +1,7 @@ +//// [for-of8.ts] +v; +for (var v of [0]) { } + +//// [for-of8.js] +v; +for (var v of [0]) { } diff --git a/tests/baselines/reference/for-of8.types b/tests/baselines/reference/for-of8.types new file mode 100644 index 0000000000000..5f239d141fee6 --- /dev/null +++ b/tests/baselines/reference/for-of8.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of8.ts === +v; +>v : number + +for (var v of [0]) { } +>v : number +>[0] : number[] + diff --git a/tests/baselines/reference/for-of9.js b/tests/baselines/reference/for-of9.js new file mode 100644 index 0000000000000..f96d353bd7a76 --- /dev/null +++ b/tests/baselines/reference/for-of9.js @@ -0,0 +1,9 @@ +//// [for-of9.ts] +var v: string; +for (v of ["hello"]) { } +for (v of "hello") { } + +//// [for-of9.js] +var v; +for (v of ["hello"]) { } +for (v of "hello") { } diff --git a/tests/baselines/reference/for-of9.types b/tests/baselines/reference/for-of9.types new file mode 100644 index 0000000000000..55c8167094f76 --- /dev/null +++ b/tests/baselines/reference/for-of9.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/for-ofStatements/for-of9.ts === +var v: string; +>v : string + +for (v of ["hello"]) { } +>v : string +>["hello"] : string[] + +for (v of "hello") { } +>v : string + diff --git a/tests/baselines/reference/iterableContextualTyping1.js b/tests/baselines/reference/iterableContextualTyping1.js new file mode 100644 index 0000000000000..8621bbd8417ef --- /dev/null +++ b/tests/baselines/reference/iterableContextualTyping1.js @@ -0,0 +1,5 @@ +//// [iterableContextualTyping1.ts] +var iter: Iterable<(x: string) => number> = [s => s.length]; + +//// [iterableContextualTyping1.js] +var iter = [s => s.length]; diff --git a/tests/baselines/reference/iterableContextualTyping1.types b/tests/baselines/reference/iterableContextualTyping1.types new file mode 100644 index 0000000000000..386d64312fc7b --- /dev/null +++ b/tests/baselines/reference/iterableContextualTyping1.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/expressions/contextualTyping/iterableContextualTyping1.ts === +var iter: Iterable<(x: string) => number> = [s => s.length]; +>iter : Iterable<(x: string) => number> +>Iterable : Iterable +>x : string +>[s => s.length] : ((s: string) => number)[] +>s => s.length : (s: string) => number +>s : string +>s.length : number +>s : string +>length : number + diff --git a/tests/baselines/reference/parserES5ForOfStatement1.d.errors.txt b/tests/baselines/reference/parserES5ForOfStatement1.d.errors.txt index 9c1a39b1f4ad9..c280b597b2c11 100644 --- a/tests/baselines/reference/parserES5ForOfStatement1.d.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement1.d.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement1.d.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement1.d.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement1.d.ts (1 errors) ==== for (var i of e) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement10.errors.txt b/tests/baselines/reference/parserES5ForOfStatement10.errors.txt index d7f411b1879cb..5cee7472d24a1 100644 --- a/tests/baselines/reference/parserES5ForOfStatement10.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement10.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement10.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement10.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement10.ts (1 errors) ==== for (const v of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement11.errors.txt b/tests/baselines/reference/parserES5ForOfStatement11.errors.txt index 48805a336c722..79b16ed1ad66c 100644 --- a/tests/baselines/reference/parserES5ForOfStatement11.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement11.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement11.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement11.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement11.ts (1 errors) ==== for (const [a, b] of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement12.errors.txt b/tests/baselines/reference/parserES5ForOfStatement12.errors.txt index 3b9f242b97567..cdb6db690cf9b 100644 --- a/tests/baselines/reference/parserES5ForOfStatement12.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement12.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement12.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement12.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement12.ts (1 errors) ==== for (const {a, b} of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement13.errors.txt b/tests/baselines/reference/parserES5ForOfStatement13.errors.txt index 8b8c8ce086880..9d97fd9e24916 100644 --- a/tests/baselines/reference/parserES5ForOfStatement13.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement13.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement13.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement13.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement13.ts (1 errors) ==== for (let {a, b} of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement14.errors.txt b/tests/baselines/reference/parserES5ForOfStatement14.errors.txt index dc4db95270afe..303439ec44779 100644 --- a/tests/baselines/reference/parserES5ForOfStatement14.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement14.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement14.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement14.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement14.ts (1 errors) ==== for (let [a, b] of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement15.errors.txt b/tests/baselines/reference/parserES5ForOfStatement15.errors.txt index 07aa6dd5b3714..f0eab288fa7ea 100644 --- a/tests/baselines/reference/parserES5ForOfStatement15.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement15.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement15.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement15.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement15.ts (1 errors) ==== for (var [a, b] of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement16.errors.txt b/tests/baselines/reference/parserES5ForOfStatement16.errors.txt index 15a3e4f7f0bc5..b9248140f3302 100644 --- a/tests/baselines/reference/parserES5ForOfStatement16.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement16.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement16.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement16.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement16.ts (1 errors) ==== for (var {a, b} of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement18.errors.txt b/tests/baselines/reference/parserES5ForOfStatement18.errors.txt index fc314e510125f..e123be9c4f717 100644 --- a/tests/baselines/reference/parserES5ForOfStatement18.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement18.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement18.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement18.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement18.ts (1 errors) ==== for (var of of of) { } ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. \ No newline at end of file +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement2.errors.txt b/tests/baselines/reference/parserES5ForOfStatement2.errors.txt index 347ae29ddb8eb..618e2f3f0ae38 100644 --- a/tests/baselines/reference/parserES5ForOfStatement2.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement2.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement2.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement2.ts (1 errors) ==== for (var of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement21.errors.txt b/tests/baselines/reference/parserES5ForOfStatement21.errors.txt index 2ddbf4b5666f3..14d97f49fafbc 100644 --- a/tests/baselines/reference/parserES5ForOfStatement21.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement21.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement21.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement21.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement21.ts (1 errors) ==== for (var of of) { } ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. \ No newline at end of file +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement3.errors.txt b/tests/baselines/reference/parserES5ForOfStatement3.errors.txt index 553ca40aee0db..dd888a3120ab0 100644 --- a/tests/baselines/reference/parserES5ForOfStatement3.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement3.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement3.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement3.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement3.ts (1 errors) ==== for (var a, b of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement4.errors.txt b/tests/baselines/reference/parserES5ForOfStatement4.errors.txt index 6a08c8942edb0..b94de56b17ceb 100644 --- a/tests/baselines/reference/parserES5ForOfStatement4.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement4.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement4.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement4.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement4.ts (1 errors) ==== for (var a = 1 of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement5.errors.txt b/tests/baselines/reference/parserES5ForOfStatement5.errors.txt index 212eae8ac106f..0b8dafc0b900a 100644 --- a/tests/baselines/reference/parserES5ForOfStatement5.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement5.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement5.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement5.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement5.ts (1 errors) ==== for (var a: number of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement6.errors.txt b/tests/baselines/reference/parserES5ForOfStatement6.errors.txt index e331b66eb8530..04ac84fbd73f8 100644 --- a/tests/baselines/reference/parserES5ForOfStatement6.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement6.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement6.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement6.ts (1 errors) ==== for (var a = 1, b = 2 of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement7.errors.txt b/tests/baselines/reference/parserES5ForOfStatement7.errors.txt index 5ba60c264eb36..1def5279f651f 100644 --- a/tests/baselines/reference/parserES5ForOfStatement7.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement7.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement7.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement7.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement7.ts (1 errors) ==== for (var a: number = 1, b: string = "" of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement8.errors.txt b/tests/baselines/reference/parserES5ForOfStatement8.errors.txt index 3696bf11f8c18..829fea57e6ecd 100644 --- a/tests/baselines/reference/parserES5ForOfStatement8.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement8.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement8.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement8.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement8.ts (1 errors) ==== for (var v of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement9.errors.txt b/tests/baselines/reference/parserES5ForOfStatement9.errors.txt index 6e2e9d05705d7..4cf082b4f15fc 100644 --- a/tests/baselines/reference/parserES5ForOfStatement9.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement9.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement9.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement9.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement9.ts (1 errors) ==== for (let v of X) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement1.d.errors.txt b/tests/baselines/reference/parserForOfStatement1.d.errors.txt index 05af0a6f77587..c492c7817e83e 100644 --- a/tests/baselines/reference/parserForOfStatement1.d.errors.txt +++ b/tests/baselines/reference/parserForOfStatement1.d.errors.txt @@ -1,8 +1,11 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement1.d.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement1.d.ts(1,1): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement1.d.ts(1,15): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement1.d.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement1.d.ts (2 errors) ==== for (var i of e) { ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. +!!! error TS1036: Statements are not allowed in ambient contexts. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement10.errors.txt b/tests/baselines/reference/parserForOfStatement10.errors.txt index 570c319b51fa5..d2fc73e6b6829 100644 --- a/tests/baselines/reference/parserForOfStatement10.errors.txt +++ b/tests/baselines/reference/parserForOfStatement10.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement10.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement10.ts(1,17): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement10.ts (1 errors) ==== for (const v of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement11.errors.txt b/tests/baselines/reference/parserForOfStatement11.errors.txt index f253a2d4295f1..2c5af586ae3bc 100644 --- a/tests/baselines/reference/parserForOfStatement11.errors.txt +++ b/tests/baselines/reference/parserForOfStatement11.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement11.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement11.ts(1,22): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement11.ts (1 errors) ==== for (const [a, b] of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement12.errors.txt b/tests/baselines/reference/parserForOfStatement12.errors.txt index 07ef449898422..951b70eac35b2 100644 --- a/tests/baselines/reference/parserForOfStatement12.errors.txt +++ b/tests/baselines/reference/parserForOfStatement12.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement12.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement12.ts(1,22): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement12.ts (1 errors) ==== for (const {a, b} of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement13.errors.txt b/tests/baselines/reference/parserForOfStatement13.errors.txt index 6c10a7b05820e..c789ab89d9a10 100644 --- a/tests/baselines/reference/parserForOfStatement13.errors.txt +++ b/tests/baselines/reference/parserForOfStatement13.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement13.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement13.ts(1,20): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement13.ts (1 errors) ==== for (let {a, b} of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement14.errors.txt b/tests/baselines/reference/parserForOfStatement14.errors.txt index 209a39c0513f6..46e71e5242fc6 100644 --- a/tests/baselines/reference/parserForOfStatement14.errors.txt +++ b/tests/baselines/reference/parserForOfStatement14.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement14.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement14.ts(1,20): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement14.ts (1 errors) ==== for (let [a, b] of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement15.errors.txt b/tests/baselines/reference/parserForOfStatement15.errors.txt index c5fd77af29979..0f159c7a25a46 100644 --- a/tests/baselines/reference/parserForOfStatement15.errors.txt +++ b/tests/baselines/reference/parserForOfStatement15.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement15.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement15.ts(1,20): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement15.ts (1 errors) ==== for (var [a, b] of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement16.errors.txt b/tests/baselines/reference/parserForOfStatement16.errors.txt index d169eef125688..3d950fd145d53 100644 --- a/tests/baselines/reference/parserForOfStatement16.errors.txt +++ b/tests/baselines/reference/parserForOfStatement16.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement16.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement16.ts(1,20): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement16.ts (1 errors) ==== for (var {a, b} of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement18.errors.txt b/tests/baselines/reference/parserForOfStatement18.errors.txt deleted file mode 100644 index 9312af76fc10d..0000000000000 --- a/tests/baselines/reference/parserForOfStatement18.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement18.ts(1,1): error TS9003: 'for...of' statements are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement18.ts (1 errors) ==== - for (var of of of) { } - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement18.types b/tests/baselines/reference/parserForOfStatement18.types new file mode 100644 index 0000000000000..8e3b52ac87743 --- /dev/null +++ b/tests/baselines/reference/parserForOfStatement18.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement18.ts === +for (var of of of) { } +>of : any +>of : any + diff --git a/tests/baselines/reference/parserForOfStatement2.errors.txt b/tests/baselines/reference/parserForOfStatement2.errors.txt index 8e7da4973086a..7229fe4196d23 100644 --- a/tests/baselines/reference/parserForOfStatement2.errors.txt +++ b/tests/baselines/reference/parserForOfStatement2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement2.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement2.ts(1,9): error TS1123: Variable declaration list cannot be empty. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement2.ts (1 errors) ==== for (var of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + +!!! error TS1123: Variable declaration list cannot be empty. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement21.errors.txt b/tests/baselines/reference/parserForOfStatement21.errors.txt index dad48f415cdb0..9103e2fedeebe 100644 --- a/tests/baselines/reference/parserForOfStatement21.errors.txt +++ b/tests/baselines/reference/parserForOfStatement21.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement21.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement21.ts(1,9): error TS1123: Variable declaration list cannot be empty. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement21.ts (1 errors) ==== for (var of of) { } - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. \ No newline at end of file + +!!! error TS1123: Variable declaration list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement3.errors.txt b/tests/baselines/reference/parserForOfStatement3.errors.txt index 83985f1a7109a..a565ae37d3258 100644 --- a/tests/baselines/reference/parserForOfStatement3.errors.txt +++ b/tests/baselines/reference/parserForOfStatement3.errors.txt @@ -1,8 +1,11 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement3.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement3.ts(1,13): error TS1188: Only a single variable declaration is allowed in a 'for...of' statement. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement3.ts(1,18): error TS2304: Cannot find name 'X'. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement3.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement3.ts (2 errors) ==== for (var a, b of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS1188: Only a single variable declaration is allowed in a 'for...of' statement. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement4.errors.txt b/tests/baselines/reference/parserForOfStatement4.errors.txt index 94dd08ed5973c..97873682082ad 100644 --- a/tests/baselines/reference/parserForOfStatement4.errors.txt +++ b/tests/baselines/reference/parserForOfStatement4.errors.txt @@ -1,8 +1,11 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement4.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement4.ts(1,10): error TS1190: The variable declaration of a 'for...of' statement cannot have an initializer. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement4.ts(1,19): error TS2304: Cannot find name 'X'. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement4.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement4.ts (2 errors) ==== for (var a = 1 of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS1190: The variable declaration of a 'for...of' statement cannot have an initializer. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement5.errors.txt b/tests/baselines/reference/parserForOfStatement5.errors.txt index 6570f4a075534..e3ed32359105c 100644 --- a/tests/baselines/reference/parserForOfStatement5.errors.txt +++ b/tests/baselines/reference/parserForOfStatement5.errors.txt @@ -1,8 +1,11 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts(1,10): error TS2483: The left-hand side of a 'for...of' statement cannot use a type annotation. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts(1,23): error TS2304: Cannot find name 'X'. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts (2 errors) ==== for (var a: number of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2483: The left-hand side of a 'for...of' statement cannot use a type annotation. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement6.errors.txt b/tests/baselines/reference/parserForOfStatement6.errors.txt index 6208749911f62..59a18f03bcd96 100644 --- a/tests/baselines/reference/parserForOfStatement6.errors.txt +++ b/tests/baselines/reference/parserForOfStatement6.errors.txt @@ -1,8 +1,11 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement6.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement6.ts(1,17): error TS1188: Only a single variable declaration is allowed in a 'for...of' statement. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement6.ts(1,26): error TS2304: Cannot find name 'X'. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement6.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement6.ts (2 errors) ==== for (var a = 1, b = 2 of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS1188: Only a single variable declaration is allowed in a 'for...of' statement. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement7.errors.txt b/tests/baselines/reference/parserForOfStatement7.errors.txt index 1810daad5ee35..f5ab97b441318 100644 --- a/tests/baselines/reference/parserForOfStatement7.errors.txt +++ b/tests/baselines/reference/parserForOfStatement7.errors.txt @@ -1,8 +1,11 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement7.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement7.ts(1,25): error TS1188: Only a single variable declaration is allowed in a 'for...of' statement. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement7.ts(1,43): error TS2304: Cannot find name 'X'. -==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement7.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement7.ts (2 errors) ==== for (var a: number = 1, b: string = "" of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS1188: Only a single variable declaration is allowed in a 'for...of' statement. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement8.errors.txt b/tests/baselines/reference/parserForOfStatement8.errors.txt index 8e2c41d0cef8d..5fe9bb4341507 100644 --- a/tests/baselines/reference/parserForOfStatement8.errors.txt +++ b/tests/baselines/reference/parserForOfStatement8.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement8.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement8.ts(1,15): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement8.ts (1 errors) ==== for (var v of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement9.errors.txt b/tests/baselines/reference/parserForOfStatement9.errors.txt index 01fd729e9cd5b..fae9beec25319 100644 --- a/tests/baselines/reference/parserForOfStatement9.errors.txt +++ b/tests/baselines/reference/parserForOfStatement9.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement9.ts(1,1): error TS9003: 'for...of' statements are not currently supported. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement9.ts(1,15): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement9.ts (1 errors) ==== for (let v of X) { - ~~~ -!!! error TS9003: 'for...of' statements are not currently supported. + ~ +!!! error TS2304: Cannot find name 'X'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForStatement5.errors.txt b/tests/baselines/reference/parserForStatement5.errors.txt index 72c9bffce4c2a..ae1e855b76544 100644 --- a/tests/baselines/reference/parserForStatement5.errors.txt +++ b/tests/baselines/reference/parserForStatement5.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement5.ts(1,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement5.ts(1,6): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement5.ts(1,12): error TS2304: Cannot find name 'b'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement5.ts (2 errors) ==== for ({} in b) { ~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of1.ts b/tests/cases/conformance/es6/for-ofStatements/for-of1.ts new file mode 100644 index 0000000000000..b9e25f2060669 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of1.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var v; +for (v of []) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of10.ts b/tests/cases/conformance/es6/for-ofStatements/for-of10.ts new file mode 100644 index 0000000000000..dec00541e9327 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of10.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var v: string; +for (v of [0]) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of11.ts b/tests/cases/conformance/es6/for-ofStatements/for-of11.ts new file mode 100644 index 0000000000000..e434758efa49a --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of11.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var v: string; +for (v of [0, ""]) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of12.ts b/tests/cases/conformance/es6/for-ofStatements/for-of12.ts new file mode 100644 index 0000000000000..78cfbaccecb2e --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of12.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var v: string; +for (v of [0, ""].values()) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of13.ts b/tests/cases/conformance/es6/for-ofStatements/for-of13.ts new file mode 100644 index 0000000000000..2f2b922cb1dbe --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of13.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var v: string; +for (v of [""].values()) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of14.ts b/tests/cases/conformance/es6/for-ofStatements/for-of14.ts new file mode 100644 index 0000000000000..84fbda4825cc0 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of14.ts @@ -0,0 +1,9 @@ +//@target: ES6 +var v: string; +for (v of new StringIterator) { } // Should fail because the iterator is not iterable + +class StringIterator { + next() { + return ""; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of15.ts b/tests/cases/conformance/es6/for-ofStatements/for-of15.ts new file mode 100644 index 0000000000000..1973e7ff95ed3 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of15.ts @@ -0,0 +1,12 @@ +//@target: ES6 +var v: string; +for (v of new StringIterator) { } // Should fail + +class StringIterator { + next() { + return ""; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of16.ts b/tests/cases/conformance/es6/for-ofStatements/for-of16.ts new file mode 100644 index 0000000000000..8f7bd6d8486aa --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of16.ts @@ -0,0 +1,9 @@ +//@target: ES6 +var v: string; +for (v of new StringIterator) { } // Should fail + +class StringIterator { + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of17.ts b/tests/cases/conformance/es6/for-ofStatements/for-of17.ts new file mode 100644 index 0000000000000..431f066d477bb --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of17.ts @@ -0,0 +1,15 @@ +//@target: ES6 +var v: string; +for (v of new NumberIterator) { } // Should succeed + +class NumberIterator { + next() { + return { + value: 0, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of18.ts b/tests/cases/conformance/es6/for-ofStatements/for-of18.ts new file mode 100644 index 0000000000000..407ad7f0ed8f4 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of18.ts @@ -0,0 +1,15 @@ +//@target: ES6 +var v: string; +for (v of new StringIterator) { } // Should succeed + +class StringIterator { + next() { + return { + value: "", + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of19.ts b/tests/cases/conformance/es6/for-ofStatements/for-of19.ts new file mode 100644 index 0000000000000..ff80b2690effc --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of19.ts @@ -0,0 +1,17 @@ +//@target: ES6 +for (var v of new FooIterator) { + v; +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of2.ts b/tests/cases/conformance/es6/for-ofStatements/for-of2.ts new file mode 100644 index 0000000000000..77f72330deec3 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of2.ts @@ -0,0 +1,3 @@ +//@target: ES6 +const v; +for (v of []) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of20.ts b/tests/cases/conformance/es6/for-ofStatements/for-of20.ts new file mode 100644 index 0000000000000..615f514937523 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of20.ts @@ -0,0 +1,17 @@ +//@target: ES6 +for (let v of new FooIterator) { + v; +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of21.ts b/tests/cases/conformance/es6/for-ofStatements/for-of21.ts new file mode 100644 index 0000000000000..4e4621034e1a5 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of21.ts @@ -0,0 +1,17 @@ +//@target: ES6 +for (const v of new FooIterator) { + v; +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of22.ts b/tests/cases/conformance/es6/for-ofStatements/for-of22.ts new file mode 100644 index 0000000000000..10a96502cddbf --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of22.ts @@ -0,0 +1,18 @@ +//@target: ES6 +v; +for (var v of new FooIterator) { + +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of23.ts b/tests/cases/conformance/es6/for-ofStatements/for-of23.ts new file mode 100644 index 0000000000000..81227cd066530 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of23.ts @@ -0,0 +1,17 @@ +//@target: ES6 +for (const v of new FooIterator) { + const v = 0; // new scope +} + +class Foo { } +class FooIterator { + next() { + return { + value: new Foo, + done: false + }; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of24.ts b/tests/cases/conformance/es6/for-ofStatements/for-of24.ts new file mode 100644 index 0000000000000..6f68821a0b585 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of24.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var x: any; +for (var v of x) { } diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of25.ts b/tests/cases/conformance/es6/for-ofStatements/for-of25.ts new file mode 100644 index 0000000000000..a1698bd28244a --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of25.ts @@ -0,0 +1,9 @@ +//@target: ES6 +var x: any; +for (var v of new StringIterator) { } + +class StringIterator { + [Symbol.iterator]() { + return x; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of26.ts b/tests/cases/conformance/es6/for-ofStatements/for-of26.ts new file mode 100644 index 0000000000000..0ab564a4f5227 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of26.ts @@ -0,0 +1,12 @@ +//@target: ES6 +var x: any; +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return x; + } + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of27.ts b/tests/cases/conformance/es6/for-ofStatements/for-of27.ts new file mode 100644 index 0000000000000..8f2b84cbe1dea --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of27.ts @@ -0,0 +1,6 @@ +//@target: ES6 +for (var v of new StringIterator) { } + +class StringIterator { + [Symbol.iterator]: any; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of28.ts b/tests/cases/conformance/es6/for-ofStatements/for-of28.ts new file mode 100644 index 0000000000000..8c693193b0876 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of28.ts @@ -0,0 +1,9 @@ +//@target: ES6 +for (var v of new StringIterator) { } + +class StringIterator { + next: any; + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of29.ts b/tests/cases/conformance/es6/for-ofStatements/for-of29.ts new file mode 100644 index 0000000000000..8df83db158808 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of29.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var iterableWithOptionalIterator: { + [Symbol.iterator]?(): Iterator +}; + +for (var v of iterableWithOptionalIterator) { } diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts new file mode 100644 index 0000000000000..7eb1e1fd220fd --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var v; +for (v++ of []) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of30.ts b/tests/cases/conformance/es6/for-ofStatements/for-of30.ts new file mode 100644 index 0000000000000..03b97c23136ad --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of30.ts @@ -0,0 +1,17 @@ +//@target: ES6 +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return { + done: false, + value: "" + } + } + + return = 0; + + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of31.ts b/tests/cases/conformance/es6/for-ofStatements/for-of31.ts new file mode 100644 index 0000000000000..307f9b7cd4385 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of31.ts @@ -0,0 +1,15 @@ +//@target: ES6 +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return { + // no done property + value: "" + } + } + + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of32.ts b/tests/cases/conformance/es6/for-ofStatements/for-of32.ts new file mode 100644 index 0000000000000..de95350b72480 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of32.ts @@ -0,0 +1,3 @@ +//@target: ES6 +//@noImplicitAny: true +for (var v of v) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of33.ts b/tests/cases/conformance/es6/for-ofStatements/for-of33.ts new file mode 100644 index 0000000000000..b73d2daee8ac4 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of33.ts @@ -0,0 +1,9 @@ +//@target: ES6 +//@noImplicitAny: true +for (var v of new StringIterator) { } + +class StringIterator { + [Symbol.iterator]() { + return v; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of34.ts b/tests/cases/conformance/es6/for-ofStatements/for-of34.ts new file mode 100644 index 0000000000000..d00f5ccde2eb3 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of34.ts @@ -0,0 +1,13 @@ +//@target: ES6 +//@noImplicitAny: true +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return v; + } + + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of35.ts b/tests/cases/conformance/es6/for-ofStatements/for-of35.ts new file mode 100644 index 0000000000000..0d66ce39edfef --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of35.ts @@ -0,0 +1,16 @@ +//@target: ES6 +//@noImplicitAny: true +for (var v of new StringIterator) { } + +class StringIterator { + next() { + return { + done: true, + value: v + } + } + + [Symbol.iterator]() { + return this; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of36.ts b/tests/cases/conformance/es6/for-ofStatements/for-of36.ts new file mode 100644 index 0000000000000..e67806fef64ab --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of36.ts @@ -0,0 +1,5 @@ +//@target: ES6 +var tuple: [string, boolean] = ["", true]; +for (var v of tuple) { + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of37.ts b/tests/cases/conformance/es6/for-ofStatements/for-of37.ts new file mode 100644 index 0000000000000..561e3bf2e52f1 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of37.ts @@ -0,0 +1,5 @@ +//@target: ES6 +var map = new Map([["", true]]); +for (var v of map) { + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of38.ts b/tests/cases/conformance/es6/for-ofStatements/for-of38.ts new file mode 100644 index 0000000000000..0511ff140bd89 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of38.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var map = new Map([["", true]]); +for (var [k, v] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of39.ts b/tests/cases/conformance/es6/for-ofStatements/for-of39.ts new file mode 100644 index 0000000000000..1d3ae5fc76c5b --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of39.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var map = new Map([["", true], ["", 0]]); +for (var [k, v] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of4.ts b/tests/cases/conformance/es6/for-ofStatements/for-of4.ts new file mode 100644 index 0000000000000..d37925b67a00f --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of4.ts @@ -0,0 +1,4 @@ +//@target: ES6 +for (var v of [0]) { + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of40.ts b/tests/cases/conformance/es6/for-ofStatements/for-of40.ts new file mode 100644 index 0000000000000..128e6b4f186fc --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of40.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var map = new Map([["", true]]); +for (var [k = "", v = false] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of41.ts b/tests/cases/conformance/es6/for-ofStatements/for-of41.ts new file mode 100644 index 0000000000000..207ab8ab2b9a4 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of41.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var array = [{x: [0], y: {p: ""}}] +for (var {x: [a], y: {p}} of array) { + a; + p; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of42.ts b/tests/cases/conformance/es6/for-ofStatements/for-of42.ts new file mode 100644 index 0000000000000..2eb25ab52f25c --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of42.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var array = [{ x: "", y: 0 }] +for (var {x: a, y: b} of array) { + a; + b; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of43.ts b/tests/cases/conformance/es6/for-ofStatements/for-of43.ts new file mode 100644 index 0000000000000..fec349e107335 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of43.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var array = [{ x: "", y: 0 }] +for (var {x: a = "", y: b = true} of array) { + a; + b; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of44.ts b/tests/cases/conformance/es6/for-ofStatements/for-of44.ts new file mode 100644 index 0000000000000..7d7d21d8691e9 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of44.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var array: [number, string | boolean | symbol][] = [[0, ""], [0, true], [1, Symbol()]] +for (var [num, strBoolSym] of array) { + num; + strBoolSym; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of45.ts b/tests/cases/conformance/es6/for-ofStatements/for-of45.ts new file mode 100644 index 0000000000000..f347069ab1009 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of45.ts @@ -0,0 +1,7 @@ +//@target: ES6 +var k: string, v: boolean; +var map = new Map([["", true]]); +for ([k = "", v = false] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of46.ts b/tests/cases/conformance/es6/for-ofStatements/for-of46.ts new file mode 100644 index 0000000000000..a08791068b7af --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of46.ts @@ -0,0 +1,7 @@ +//@target: ES6 +var k: string, v: boolean; +var map = new Map([["", true]]); +for ([k = false, v = ""] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of47.ts b/tests/cases/conformance/es6/for-ofStatements/for-of47.ts new file mode 100644 index 0000000000000..bd21a0db382be --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of47.ts @@ -0,0 +1,8 @@ +//@target: ES6 +var x: string, y: number; +var array = [{ x: "", y: true }] +enum E { x } +for ({x, y: y = E.x} of array) { + x; + y; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of48.ts b/tests/cases/conformance/es6/for-ofStatements/for-of48.ts new file mode 100644 index 0000000000000..c2e228d0fb923 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of48.ts @@ -0,0 +1,8 @@ +//@target: ES6 +var x: string, y: number; +var array = [{ x: "", y: true }] +enum E { x } +for ({x, y = E.x} of array) { + x; + y; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of49.ts b/tests/cases/conformance/es6/for-ofStatements/for-of49.ts new file mode 100644 index 0000000000000..62fa4acd4251f --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of49.ts @@ -0,0 +1,7 @@ +//@target: ES6 +var k: string, v: boolean; +var map = new Map([["", true]]); +for ([k, ...[v]] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of5.ts b/tests/cases/conformance/es6/for-ofStatements/for-of5.ts new file mode 100644 index 0000000000000..2a581676b4b87 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of5.ts @@ -0,0 +1,4 @@ +//@target: ES6 +for (let v of [0]) { + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of50.ts b/tests/cases/conformance/es6/for-ofStatements/for-of50.ts new file mode 100644 index 0000000000000..d4e1bba5ae4af --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of50.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var map = new Map([["", true]]); +for (const [k, v] of map) { + k; + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of51.ts b/tests/cases/conformance/es6/for-ofStatements/for-of51.ts new file mode 100644 index 0000000000000..a97b05d7fe9a9 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of51.ts @@ -0,0 +1,2 @@ +//@target: ES6 +for (let let of []) {} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of52.ts b/tests/cases/conformance/es6/for-ofStatements/for-of52.ts new file mode 100644 index 0000000000000..80cc680060dec --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of52.ts @@ -0,0 +1,2 @@ +//@target: ES6 +for (let [v, v] of [[]]) {} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of53.ts b/tests/cases/conformance/es6/for-ofStatements/for-of53.ts new file mode 100644 index 0000000000000..34db2bab70444 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of53.ts @@ -0,0 +1,4 @@ +//@target: ES6 +for (let v of []) { + var v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of54.ts b/tests/cases/conformance/es6/for-ofStatements/for-of54.ts new file mode 100644 index 0000000000000..6cf79ae0945b1 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of54.ts @@ -0,0 +1,4 @@ +//@target: ES6 +for (let v of []) { + var v = 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of55.ts b/tests/cases/conformance/es6/for-ofStatements/for-of55.ts new file mode 100644 index 0000000000000..e1d16a3e06807 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of55.ts @@ -0,0 +1,5 @@ +//@target: ES6 +let v = [1]; +for (let v of v) { + v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of56.ts b/tests/cases/conformance/es6/for-ofStatements/for-of56.ts new file mode 100644 index 0000000000000..3b73a5294251d --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of56.ts @@ -0,0 +1,2 @@ +//@target: ES6 +for (var let of []) {} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of6.ts b/tests/cases/conformance/es6/for-ofStatements/for-of6.ts new file mode 100644 index 0000000000000..1d8eccde01ac2 --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of6.ts @@ -0,0 +1,4 @@ +//@target: ES6 +for (v of [0]) { + let v; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of7.ts b/tests/cases/conformance/es6/for-ofStatements/for-of7.ts new file mode 100644 index 0000000000000..5303278d9103e --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of7.ts @@ -0,0 +1,3 @@ +//@target: ES6 +v; +for (let v of [0]) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of8.ts b/tests/cases/conformance/es6/for-ofStatements/for-of8.ts new file mode 100644 index 0000000000000..34bd4943c707e --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of8.ts @@ -0,0 +1,3 @@ +//@target: ES6 +v; +for (var v of [0]) { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of9.ts b/tests/cases/conformance/es6/for-ofStatements/for-of9.ts new file mode 100644 index 0000000000000..45a3c7e1d943d --- /dev/null +++ b/tests/cases/conformance/es6/for-ofStatements/for-of9.ts @@ -0,0 +1,4 @@ +//@target: ES6 +var v: string; +for (v of ["hello"]) { } +for (v of "hello") { } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/iterableContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/iterableContextualTyping1.ts new file mode 100644 index 0000000000000..542d192801166 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/iterableContextualTyping1.ts @@ -0,0 +1,2 @@ +//@target: ES6 +var iter: Iterable<(x: string) => number> = [s => s.length]; \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts new file mode 100644 index 0000000000000..94868ef3bd62e --- /dev/null +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts @@ -0,0 +1 @@ +for (var [a, b] in []) {} \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts new file mode 100644 index 0000000000000..8671acc675b87 --- /dev/null +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts @@ -0,0 +1 @@ +for (var {a, b} in []) {} \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring3.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring3.ts new file mode 100644 index 0000000000000..411261dee43a0 --- /dev/null +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring3.ts @@ -0,0 +1,2 @@ +var a, b; +for ([a, b] in []) { } \ No newline at end of file diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring4.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring4.ts new file mode 100644 index 0000000000000..816dd564b6a1b --- /dev/null +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring4.ts @@ -0,0 +1,2 @@ +var a, b; +for ({a, b} in []) { } \ No newline at end of file