mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 04:17:34 -06:00
Merge pull request #2164 from Microsoft/for-ofES6
Support 'for...of' loops in ES6
This commit is contained in:
commit
d6045e4ba8
@ -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,(<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
|
||||
var symbol = resolveName(location, (<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
|
||||
if (!symbol) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (name.kind === SyntaxKind.QualifiedName) {
|
||||
var namespace = resolveEntityName(location,(<QualifiedName>name).left, SymbolFlags.Namespace);
|
||||
var namespace = resolveEntityName(location, (<QualifiedName>name).left, SymbolFlags.Namespace);
|
||||
if (!namespace || namespace === unknownSymbol || getFullWidth((<QualifiedName>name).right) === 0) return;
|
||||
var symbol = getSymbol(getExportsOfSymbol(namespace), (<QualifiedName>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(<ForOfStatement>declaration.parent.parent);
|
||||
}
|
||||
if (isBindingPattern(declaration.parent)) {
|
||||
return getTypeForBindingElement(<BindingElement>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((<ConditionalExpression>node).whenFalse);
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return (<BinaryExpression>node).operatorToken.kind === SyntaxKind.BarBarToken &&
|
||||
(isContextSensitive((<BinaryExpression>node).left) || isContextSensitive((<BinaryExpression>node).right));
|
||||
(isContextSensitive((<BinaryExpression>node).left) || isContextSensitive((<BinaryExpression>node).right));
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return isContextSensitive((<PropertyAssignment>node).initializer);
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
@ -4999,7 +5003,7 @@ module ts {
|
||||
break;
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
if ((<PrefixUnaryExpression>expr).operator === SyntaxKind.ExclamationToken) {
|
||||
return narrowType(type,(<PrefixUnaryExpression>expr).operand, !assumeTrue);
|
||||
return narrowType(type, (<PrefixUnaryExpression>expr).operand, !assumeTrue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -5070,7 +5074,7 @@ module ts {
|
||||
nodeLinks.importOnRightSide = symbol;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (symbolLinks.referenced) {
|
||||
markLinkedImportsAsReferenced(<ImportEqualsDeclaration>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 = <ArrayLiteralExpression>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(<LiteralExpression>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, (<FunctionExpression>node).name);
|
||||
checkCollisionWithCapturedThisVariable(node,(<FunctionExpression>node).name);
|
||||
checkCollisionWithCapturedThisVariable(node, (<FunctionExpression>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(<FunctionLikeDeclaration>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 = <Expression>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 = <VariableDeclarationList>node.initializer;
|
||||
if (variableDeclarationList.declarations.length >= 1) {
|
||||
var decl = variableDeclarationList.declarations[0];
|
||||
checkVariableDeclaration(decl);
|
||||
var variable = (<VariableDeclarationList>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 = <Expression>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 = <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(<GenericType>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.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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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." },
|
||||
};
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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.
|
||||
@ -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 []) { }
|
||||
@ -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.
|
||||
@ -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 []) { }
|
||||
@ -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.
|
||||
@ -0,0 +1,7 @@
|
||||
//// [for-inStatementsDestructuring3.ts]
|
||||
var a, b;
|
||||
for ([a, b] in []) { }
|
||||
|
||||
//// [for-inStatementsDestructuring3.js]
|
||||
var a, b;
|
||||
for ([a, b] in []) { }
|
||||
@ -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.
|
||||
@ -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 []) { }
|
||||
7
tests/baselines/reference/for-of1.js
Normal file
7
tests/baselines/reference/for-of1.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [for-of1.ts]
|
||||
var v;
|
||||
for (v of []) { }
|
||||
|
||||
//// [for-of1.js]
|
||||
var v;
|
||||
for (v of []) { }
|
||||
8
tests/baselines/reference/for-of1.types
Normal file
8
tests/baselines/reference/for-of1.types
Normal file
@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/es6/for-ofStatements/for-of1.ts ===
|
||||
var v;
|
||||
>v : any
|
||||
|
||||
for (v of []) { }
|
||||
>v : any
|
||||
>[] : undefined[]
|
||||
|
||||
8
tests/baselines/reference/for-of10.errors.txt
Normal file
8
tests/baselines/reference/for-of10.errors.txt
Normal file
@ -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'.
|
||||
7
tests/baselines/reference/for-of10.js
Normal file
7
tests/baselines/reference/for-of10.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [for-of10.ts]
|
||||
var v: string;
|
||||
for (v of [0]) { }
|
||||
|
||||
//// [for-of10.js]
|
||||
var v;
|
||||
for (v of [0]) { }
|
||||
10
tests/baselines/reference/for-of11.errors.txt
Normal file
10
tests/baselines/reference/for-of11.errors.txt
Normal file
@ -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'.
|
||||
7
tests/baselines/reference/for-of11.js
Normal file
7
tests/baselines/reference/for-of11.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [for-of11.ts]
|
||||
var v: string;
|
||||
for (v of [0, ""]) { }
|
||||
|
||||
//// [for-of11.js]
|
||||
var v;
|
||||
for (v of [0, ""]) { }
|
||||
10
tests/baselines/reference/for-of12.errors.txt
Normal file
10
tests/baselines/reference/for-of12.errors.txt
Normal file
@ -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'.
|
||||
7
tests/baselines/reference/for-of12.js
Normal file
7
tests/baselines/reference/for-of12.js
Normal file
@ -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()) { }
|
||||
7
tests/baselines/reference/for-of13.js
Normal file
7
tests/baselines/reference/for-of13.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [for-of13.ts]
|
||||
var v: string;
|
||||
for (v of [""].values()) { }
|
||||
|
||||
//// [for-of13.js]
|
||||
var v;
|
||||
for (v of [""].values()) { }
|
||||
11
tests/baselines/reference/for-of13.types
Normal file
11
tests/baselines/reference/for-of13.types
Normal file
@ -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<string>
|
||||
>[""].values : () => IterableIterator<string>
|
||||
>[""] : string[]
|
||||
>values : () => IterableIterator<string>
|
||||
|
||||
14
tests/baselines/reference/for-of14.errors.txt
Normal file
14
tests/baselines/reference/for-of14.errors.txt
Normal file
@ -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 "";
|
||||
}
|
||||
}
|
||||
21
tests/baselines/reference/for-of14.js
Normal file
21
tests/baselines/reference/for-of14.js
Normal file
@ -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;
|
||||
})();
|
||||
17
tests/baselines/reference/for-of15.errors.txt
Normal file
17
tests/baselines/reference/for-of15.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
27
tests/baselines/reference/for-of15.js
Normal file
27
tests/baselines/reference/for-of15.js
Normal file
@ -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;
|
||||
})();
|
||||
14
tests/baselines/reference/for-of16.errors.txt
Normal file
14
tests/baselines/reference/for-of16.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
21
tests/baselines/reference/for-of16.js
Normal file
21
tests/baselines/reference/for-of16.js
Normal file
@ -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;
|
||||
})();
|
||||
20
tests/baselines/reference/for-of17.errors.txt
Normal file
20
tests/baselines/reference/for-of17.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
33
tests/baselines/reference/for-of17.js
Normal file
33
tests/baselines/reference/for-of17.js
Normal file
@ -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;
|
||||
})();
|
||||
33
tests/baselines/reference/for-of18.js
Normal file
33
tests/baselines/reference/for-of18.js
Normal file
@ -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;
|
||||
})();
|
||||
35
tests/baselines/reference/for-of18.types
Normal file
35
tests/baselines/reference/for-of18.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
41
tests/baselines/reference/for-of19.js
Normal file
41
tests/baselines/reference/for-of19.js
Normal file
@ -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;
|
||||
})();
|
||||
41
tests/baselines/reference/for-of19.types
Normal file
41
tests/baselines/reference/for-of19.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
11
tests/baselines/reference/for-of2.errors.txt
Normal file
11
tests/baselines/reference/for-of2.errors.txt
Normal file
@ -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.
|
||||
7
tests/baselines/reference/for-of2.js
Normal file
7
tests/baselines/reference/for-of2.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [for-of2.ts]
|
||||
const v;
|
||||
for (v of []) { }
|
||||
|
||||
//// [for-of2.js]
|
||||
const v;
|
||||
for (v of []) { }
|
||||
41
tests/baselines/reference/for-of20.js
Normal file
41
tests/baselines/reference/for-of20.js
Normal file
@ -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;
|
||||
})();
|
||||
41
tests/baselines/reference/for-of20.types
Normal file
41
tests/baselines/reference/for-of20.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
41
tests/baselines/reference/for-of21.js
Normal file
41
tests/baselines/reference/for-of21.js
Normal file
@ -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;
|
||||
})();
|
||||
41
tests/baselines/reference/for-of21.types
Normal file
41
tests/baselines/reference/for-of21.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
42
tests/baselines/reference/for-of22.js
Normal file
42
tests/baselines/reference/for-of22.js
Normal file
@ -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;
|
||||
})();
|
||||
42
tests/baselines/reference/for-of22.types
Normal file
42
tests/baselines/reference/for-of22.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
41
tests/baselines/reference/for-of23.js
Normal file
41
tests/baselines/reference/for-of23.js
Normal file
@ -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;
|
||||
})();
|
||||
41
tests/baselines/reference/for-of23.types
Normal file
41
tests/baselines/reference/for-of23.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
8
tests/baselines/reference/for-of24.js
Normal file
8
tests/baselines/reference/for-of24.js
Normal file
@ -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) { }
|
||||
8
tests/baselines/reference/for-of24.types
Normal file
8
tests/baselines/reference/for-of24.types
Normal file
@ -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
|
||||
|
||||
21
tests/baselines/reference/for-of25.js
Normal file
21
tests/baselines/reference/for-of25.js
Normal file
@ -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;
|
||||
})();
|
||||
21
tests/baselines/reference/for-of25.types
Normal file
21
tests/baselines/reference/for-of25.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
27
tests/baselines/reference/for-of26.js
Normal file
27
tests/baselines/reference/for-of26.js
Normal file
@ -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;
|
||||
})();
|
||||
27
tests/baselines/reference/for-of26.types
Normal file
27
tests/baselines/reference/for-of26.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
14
tests/baselines/reference/for-of27.js
Normal file
14
tests/baselines/reference/for-of27.js
Normal file
@ -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;
|
||||
})();
|
||||
14
tests/baselines/reference/for-of27.types
Normal file
14
tests/baselines/reference/for-of27.types
Normal file
@ -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
|
||||
}
|
||||
20
tests/baselines/reference/for-of28.js
Normal file
20
tests/baselines/reference/for-of28.js
Normal file
@ -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;
|
||||
})();
|
||||
21
tests/baselines/reference/for-of28.types
Normal file
21
tests/baselines/reference/for-of28.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
14
tests/baselines/reference/for-of29.errors.txt
Normal file
14
tests/baselines/reference/for-of29.errors.txt
Normal file
@ -0,0 +1,14 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of29.ts(5,15): error TS2322: Type '{ [Symbol.iterator]?(): Iterator<string>; }' is not assignable to type 'Iterable<string>'.
|
||||
Property '[Symbol.iterator]' is optional in type '{ [Symbol.iterator]?(): Iterator<string>; }' but required in type 'Iterable<string>'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of29.ts (1 errors) ====
|
||||
var iterableWithOptionalIterator: {
|
||||
[Symbol.iterator]?(): Iterator<string>
|
||||
};
|
||||
|
||||
for (var v of iterableWithOptionalIterator) { }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ [Symbol.iterator]?(): Iterator<string>; }' is not assignable to type 'Iterable<string>'.
|
||||
!!! error TS2322: Property '[Symbol.iterator]' is optional in type '{ [Symbol.iterator]?(): Iterator<string>; }' but required in type 'Iterable<string>'.
|
||||
|
||||
11
tests/baselines/reference/for-of29.js
Normal file
11
tests/baselines/reference/for-of29.js
Normal file
@ -0,0 +1,11 @@
|
||||
//// [for-of29.ts]
|
||||
var iterableWithOptionalIterator: {
|
||||
[Symbol.iterator]?(): Iterator<string>
|
||||
};
|
||||
|
||||
for (var v of iterableWithOptionalIterator) { }
|
||||
|
||||
|
||||
//// [for-of29.js]
|
||||
var iterableWithOptionalIterator;
|
||||
for (var v of iterableWithOptionalIterator) { }
|
||||
8
tests/baselines/reference/for-of3.errors.txt
Normal file
8
tests/baselines/reference/for-of3.errors.txt
Normal file
@ -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.
|
||||
7
tests/baselines/reference/for-of3.js
Normal file
7
tests/baselines/reference/for-of3.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [for-of3.ts]
|
||||
var v;
|
||||
for (v++ of []) { }
|
||||
|
||||
//// [for-of3.js]
|
||||
var v;
|
||||
for (v++ of []) { }
|
||||
32
tests/baselines/reference/for-of30.errors.txt
Normal file
32
tests/baselines/reference/for-of30.errors.txt
Normal file
@ -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<string>'.
|
||||
Types of property '[Symbol.iterator]' are incompatible.
|
||||
Type '() => StringIterator' is not assignable to type '() => Iterator<string>'.
|
||||
Type 'StringIterator' is not assignable to type 'Iterator<string>'.
|
||||
Types of property 'return' are incompatible.
|
||||
Type 'number' is not assignable to type '(value?: any) => IteratorResult<string>'.
|
||||
|
||||
|
||||
==== 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<string>'.
|
||||
!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible.
|
||||
!!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator<string>'.
|
||||
!!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator<string>'.
|
||||
!!! error TS2322: Types of property 'return' are incompatible.
|
||||
!!! error TS2322: Type 'number' is not assignable to type '(value?: any) => IteratorResult<string>'.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
done: false,
|
||||
value: ""
|
||||
}
|
||||
}
|
||||
|
||||
return = 0;
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
35
tests/baselines/reference/for-of30.js
Normal file
35
tests/baselines/reference/for-of30.js
Normal file
@ -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;
|
||||
})();
|
||||
34
tests/baselines/reference/for-of31.errors.txt
Normal file
34
tests/baselines/reference/for-of31.errors.txt
Normal file
@ -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<string>'.
|
||||
Types of property '[Symbol.iterator]' are incompatible.
|
||||
Type '() => StringIterator' is not assignable to type '() => Iterator<string>'.
|
||||
Type 'StringIterator' is not assignable to type 'Iterator<string>'.
|
||||
Types of property 'next' are incompatible.
|
||||
Type '() => { value: string; }' is not assignable to type '() => IteratorResult<string>'.
|
||||
Type '{ value: string; }' is not assignable to type 'IteratorResult<string>'.
|
||||
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<string>'.
|
||||
!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible.
|
||||
!!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator<string>'.
|
||||
!!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator<string>'.
|
||||
!!! error TS2322: Types of property 'next' are incompatible.
|
||||
!!! error TS2322: Type '() => { value: string; }' is not assignable to type '() => IteratorResult<string>'.
|
||||
!!! error TS2322: Type '{ value: string; }' is not assignable to type 'IteratorResult<string>'.
|
||||
!!! error TS2322: Property 'done' is missing in type '{ value: string; }'.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
// no done property
|
||||
value: ""
|
||||
}
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
32
tests/baselines/reference/for-of31.js
Normal file
32
tests/baselines/reference/for-of31.js
Normal file
@ -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;
|
||||
})();
|
||||
7
tests/baselines/reference/for-of32.errors.txt
Normal file
7
tests/baselines/reference/for-of32.errors.txt
Normal file
@ -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.
|
||||
5
tests/baselines/reference/for-of32.js
Normal file
5
tests/baselines/reference/for-of32.js
Normal file
@ -0,0 +1,5 @@
|
||||
//// [for-of32.ts]
|
||||
for (var v of v) { }
|
||||
|
||||
//// [for-of32.js]
|
||||
for (var v of v) { }
|
||||
13
tests/baselines/reference/for-of33.errors.txt
Normal file
13
tests/baselines/reference/for-of33.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
19
tests/baselines/reference/for-of33.js
Normal file
19
tests/baselines/reference/for-of33.js
Normal file
@ -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;
|
||||
})();
|
||||
17
tests/baselines/reference/for-of34.errors.txt
Normal file
17
tests/baselines/reference/for-of34.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
26
tests/baselines/reference/for-of34.js
Normal file
26
tests/baselines/reference/for-of34.js
Normal file
@ -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;
|
||||
})();
|
||||
20
tests/baselines/reference/for-of35.errors.txt
Normal file
20
tests/baselines/reference/for-of35.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
32
tests/baselines/reference/for-of35.js
Normal file
32
tests/baselines/reference/for-of35.js
Normal file
@ -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;
|
||||
})();
|
||||
11
tests/baselines/reference/for-of36.js
Normal file
11
tests/baselines/reference/for-of36.js
Normal file
@ -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;
|
||||
}
|
||||
12
tests/baselines/reference/for-of36.types
Normal file
12
tests/baselines/reference/for-of36.types
Normal file
@ -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
|
||||
}
|
||||
11
tests/baselines/reference/for-of37.js
Normal file
11
tests/baselines/reference/for-of37.js
Normal file
@ -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;
|
||||
}
|
||||
15
tests/baselines/reference/for-of37.types
Normal file
15
tests/baselines/reference/for-of37.types
Normal file
@ -0,0 +1,15 @@
|
||||
=== tests/cases/conformance/es6/for-ofStatements/for-of37.ts ===
|
||||
var map = new Map([["", true]]);
|
||||
>map : Map<string, boolean>
|
||||
>new Map([["", true]]) : Map<string, boolean>
|
||||
>Map : MapConstructor
|
||||
>[["", true]] : [string, boolean][]
|
||||
>["", true] : [string, boolean]
|
||||
|
||||
for (var v of map) {
|
||||
>v : [string, boolean]
|
||||
>map : Map<string, boolean>
|
||||
|
||||
v;
|
||||
>v : [string, boolean]
|
||||
}
|
||||
13
tests/baselines/reference/for-of38.js
Normal file
13
tests/baselines/reference/for-of38.js
Normal file
@ -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;
|
||||
}
|
||||
19
tests/baselines/reference/for-of38.types
Normal file
19
tests/baselines/reference/for-of38.types
Normal file
@ -0,0 +1,19 @@
|
||||
=== tests/cases/conformance/es6/for-ofStatements/for-of38.ts ===
|
||||
var map = new Map([["", true]]);
|
||||
>map : Map<string, boolean>
|
||||
>new Map([["", true]]) : Map<string, boolean>
|
||||
>Map : MapConstructor
|
||||
>[["", true]] : [string, boolean][]
|
||||
>["", true] : [string, boolean]
|
||||
|
||||
for (var [k, v] of map) {
|
||||
>k : string
|
||||
>v : boolean
|
||||
>map : Map<string, boolean>
|
||||
|
||||
k;
|
||||
>k : string
|
||||
|
||||
v;
|
||||
>v : boolean
|
||||
}
|
||||
13
tests/baselines/reference/for-of39.errors.txt
Normal file
13
tests/baselines/reference/for-of39.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
13
tests/baselines/reference/for-of39.js
Normal file
13
tests/baselines/reference/for-of39.js
Normal file
@ -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;
|
||||
}
|
||||
9
tests/baselines/reference/for-of4.js
Normal file
9
tests/baselines/reference/for-of4.js
Normal file
@ -0,0 +1,9 @@
|
||||
//// [for-of4.ts]
|
||||
for (var v of [0]) {
|
||||
v;
|
||||
}
|
||||
|
||||
//// [for-of4.js]
|
||||
for (var v of [0]) {
|
||||
v;
|
||||
}
|
||||
8
tests/baselines/reference/for-of4.types
Normal file
8
tests/baselines/reference/for-of4.types
Normal file
@ -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
|
||||
}
|
||||
13
tests/baselines/reference/for-of40.js
Normal file
13
tests/baselines/reference/for-of40.js
Normal file
@ -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;
|
||||
}
|
||||
19
tests/baselines/reference/for-of40.types
Normal file
19
tests/baselines/reference/for-of40.types
Normal file
@ -0,0 +1,19 @@
|
||||
=== tests/cases/conformance/es6/for-ofStatements/for-of40.ts ===
|
||||
var map = new Map([["", true]]);
|
||||
>map : Map<string, boolean>
|
||||
>new Map([["", true]]) : Map<string, boolean>
|
||||
>Map : MapConstructor
|
||||
>[["", true]] : [string, boolean][]
|
||||
>["", true] : [string, boolean]
|
||||
|
||||
for (var [k = "", v = false] of map) {
|
||||
>k : string
|
||||
>v : boolean
|
||||
>map : Map<string, boolean>
|
||||
|
||||
k;
|
||||
>k : string
|
||||
|
||||
v;
|
||||
>v : boolean
|
||||
}
|
||||
13
tests/baselines/reference/for-of41.js
Normal file
13
tests/baselines/reference/for-of41.js
Normal file
@ -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;
|
||||
}
|
||||
24
tests/baselines/reference/for-of41.types
Normal file
24
tests/baselines/reference/for-of41.types
Normal file
@ -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
|
||||
}
|
||||
13
tests/baselines/reference/for-of42.js
Normal file
13
tests/baselines/reference/for-of42.js
Normal file
@ -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;
|
||||
}
|
||||
21
tests/baselines/reference/for-of42.types
Normal file
21
tests/baselines/reference/for-of42.types
Normal file
@ -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
|
||||
}
|
||||
11
tests/baselines/reference/for-of43.errors.txt
Normal file
11
tests/baselines/reference/for-of43.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
13
tests/baselines/reference/for-of43.js
Normal file
13
tests/baselines/reference/for-of43.js
Normal file
@ -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;
|
||||
}
|
||||
13
tests/baselines/reference/for-of44.js
Normal file
13
tests/baselines/reference/for-of44.js
Normal file
@ -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;
|
||||
}
|
||||
21
tests/baselines/reference/for-of44.types
Normal file
21
tests/baselines/reference/for-of44.types
Normal file
@ -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
|
||||
}
|
||||
15
tests/baselines/reference/for-of45.js
Normal file
15
tests/baselines/reference/for-of45.js
Normal file
@ -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;
|
||||
}
|
||||
26
tests/baselines/reference/for-of45.types
Normal file
26
tests/baselines/reference/for-of45.types
Normal file
@ -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<string, boolean>
|
||||
>new Map([["", true]]) : Map<string, boolean>
|
||||
>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<string, boolean>
|
||||
|
||||
k;
|
||||
>k : string
|
||||
|
||||
v;
|
||||
>v : boolean
|
||||
}
|
||||
15
tests/baselines/reference/for-of46.errors.txt
Normal file
15
tests/baselines/reference/for-of46.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
15
tests/baselines/reference/for-of46.js
Normal file
15
tests/baselines/reference/for-of46.js
Normal file
@ -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;
|
||||
}
|
||||
13
tests/baselines/reference/for-of47.errors.txt
Normal file
13
tests/baselines/reference/for-of47.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
20
tests/baselines/reference/for-of47.js
Normal file
20
tests/baselines/reference/for-of47.js
Normal file
@ -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;
|
||||
}
|
||||
13
tests/baselines/reference/for-of48.errors.txt
Normal file
13
tests/baselines/reference/for-of48.errors.txt
Normal file
@ -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;
|
||||
}
|
||||
20
tests/baselines/reference/for-of48.js
Normal file
20
tests/baselines/reference/for-of48.js
Normal file
@ -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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user