Merge pull request #3031 from Microsoft/generators

Basic support for generators as iterators
This commit is contained in:
Jason Freeman
2015-05-29 17:48:11 -07:00
349 changed files with 4068 additions and 651 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "http://typescriptlang.org/",
"version": "1.5.2",
"version": "1.5.3",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
+375 -228
View File
@@ -91,6 +91,9 @@ module ts {
let circularType = createIntrinsicType(TypeFlags.Any, "__circular__");
let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
let emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
emptyGenericType.instantiations = {};
let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
@@ -99,19 +102,20 @@ module ts {
let globals: SymbolTable = {};
let globalArraySymbol: Symbol;
let globalESSymbolConstructorSymbol: Symbol;
let globalObjectType: ObjectType;
let globalFunctionType: ObjectType;
let globalArrayType: ObjectType;
let globalArrayType: GenericType;
let globalStringType: ObjectType;
let globalNumberType: ObjectType;
let globalBooleanType: ObjectType;
let globalRegExpType: ObjectType;
let globalTemplateStringsArrayType: ObjectType;
let globalESSymbolType: ObjectType;
let globalIterableType: ObjectType;
let globalIterableType: GenericType;
let globalIteratorType: GenericType;
let globalIterableIteratorType: GenericType;
let anyArrayType: Type;
let getGlobalClassDecoratorType: () => ObjectType;
@@ -2150,7 +2154,7 @@ module ts {
// checkRightHandSideOfForOf will return 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.
// or it may have led to an error inside getElementTypeOfIterable.
return checkRightHandSideOfForOf((<ForOfStatement>declaration.parent.parent).expression) || anyType;
}
if (isBindingPattern(declaration.parent)) {
@@ -3473,16 +3477,16 @@ module ts {
}
if (!symbol) {
return emptyObjectType;
return arity ? emptyGenericType : emptyObjectType;
}
let type = getDeclaredTypeOfSymbol(symbol);
if (!(type.flags & TypeFlags.ObjectType)) {
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
return emptyObjectType;
return arity ? emptyGenericType : emptyObjectType;
}
if (((<InterfaceType>type).typeParameters ? (<InterfaceType>type).typeParameters.length : 0) !== arity) {
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
return emptyObjectType;
return arity ? emptyGenericType : emptyObjectType;
}
return <ObjectType>type;
}
@@ -3507,16 +3511,23 @@ module ts {
return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"));
}
/**
* Instantiates a global type that is generic with some element type, and returns that instantiation.
*/
function createTypeFromGenericGlobalType(genericGlobalType: GenericType, elementType: Type): Type {
return <ObjectType>genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType;
}
function createIterableType(elementType: Type): Type {
return globalIterableType !== emptyObjectType ? createTypeReference(<GenericType>globalIterableType, [elementType]) : emptyObjectType;
return createTypeFromGenericGlobalType(globalIterableType, elementType);
}
function createIterableIteratorType(elementType: Type): Type {
return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType);
}
function createArrayType(elementType: Type): Type {
// globalArrayType will be undefined if we get here during creation of the Array type. This for example happens if
// user code augments the Array type with call or construct signatures that have an array type as the return type.
// We instead use globalArraySymbol to obtain the (not yet fully constructed) Array type.
let arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol);
return arrayType !== emptyObjectType ? createTypeReference(<GenericType>arrayType, [elementType]) : emptyObjectType;
return createTypeFromGenericGlobalType(globalArrayType, elementType);
}
function getTypeFromArrayTypeNode(node: ArrayTypeNode): Type {
@@ -5784,20 +5795,44 @@ module ts {
}
function getContextualTypeForReturnExpression(node: Expression): Type {
let func = getContainingFunction(node);
if (func && !func.asteriskToken) {
return getContextualReturnType(func);
}
return undefined;
}
function getContextualTypeForYieldOperand(node: YieldExpression): Type {
let func = getContainingFunction(node);
if (func) {
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
if (func.type || func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<AccessorDeclaration>getDeclarationOfKind(func.symbol, SyntaxKind.SetAccessor))) {
return getReturnTypeOfSignature(getSignatureFromDeclaration(func));
}
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
let signature = getContextualSignatureForFunctionLikeDeclaration(<FunctionExpression>func);
if (signature) {
return getReturnTypeOfSignature(signature);
let contextualReturnType = getContextualReturnType(func);
if (contextualReturnType) {
return node.asteriskToken
? contextualReturnType
: getElementTypeOfIterableIterator(contextualReturnType);
}
}
return undefined;
}
function getContextualReturnType(functionDecl: FunctionLikeDeclaration): Type {
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
if (functionDecl.type ||
functionDecl.kind === SyntaxKind.Constructor ||
functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<AccessorDeclaration>getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) {
return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
}
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
let signature = getContextualSignatureForFunctionLikeDeclaration(<FunctionExpression>functionDecl);
if (signature) {
return getReturnTypeOfSignature(signature);
}
return undefined;
}
@@ -5935,7 +5970,7 @@ module ts {
let index = indexOf(arrayLiteral.elements, node);
return getTypeOfPropertyOfContextualType(type, "" + index)
|| getIndexTypeOfContextualType(type, IndexKind.Number)
|| (languageVersion >= ScriptTarget.ES6 ? checkIteratedType(type, /*expressionForError*/ undefined) : undefined);
|| (languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(type, /*errorNode*/ undefined) : undefined);
}
return undefined;
}
@@ -5967,6 +6002,8 @@ module ts {
case SyntaxKind.ArrowFunction:
case SyntaxKind.ReturnStatement:
return getContextualTypeForReturnExpression(node);
case SyntaxKind.YieldExpression:
return getContextualTypeForYieldOperand(<YieldExpression>parent);
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return getContextualTypeForArgument(<CallExpression>parent, node);
@@ -6006,8 +6043,10 @@ module ts {
}
function getContextualSignatureForFunctionLikeDeclaration(node: FunctionLikeDeclaration): Signature {
// Only function expressions and arrow functions are contextually typed.
return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(<FunctionExpression>node) : undefined;
// Only function expressions, arrow functions, and object literal methods are contextually typed.
return isFunctionExpressionOrArrowFunction(node) || isObjectLiteralMethod(node)
? getContextualSignature(<FunctionExpression>node)
: undefined;
}
// Return the contextual signature for a given expression node. A contextual type provides a
@@ -6122,7 +6161,7 @@ module ts {
// if there is no index type / iterated type.
let restArrayType = checkExpression((<SpreadElementExpression>e).expression, contextualMapper);
let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) ||
(languageVersion >= ScriptTarget.ES6 ? checkIteratedType(restArrayType, /*expressionForError*/ undefined) : undefined);
(languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined);
if (restElementType) {
elementTypes.push(restElementType);
@@ -7316,17 +7355,42 @@ module ts {
type = checkExpressionCached(<Expression>func.body, contextualMapper);
}
else {
// Aggregate the types of expressions within all the return statements.
let types = checkAndAggregateReturnExpressionTypes(<Block>func.body, contextualMapper);
if (types.length === 0) {
return voidType;
let types: Type[];
let funcIsGenerator = !!func.asteriskToken;
if (funcIsGenerator) {
types = checkAndAggregateYieldOperandTypes(<Block>func.body, contextualMapper);
if (types.length === 0) {
let iterableIteratorAny = createIterableIteratorType(anyType);
if (compilerOptions.noImplicitAny) {
error(func.asteriskToken,
Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny));
}
return iterableIteratorAny;
}
}
// When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the
// return expressions to have a best common supertype.
else {
types = checkAndAggregateReturnExpressionTypes(<Block>func.body, contextualMapper);
if (types.length === 0) {
return voidType;
}
}
// When yield/return statements are contextually typed we allow the return type to be a union type.
// Otherwise we require the yield/return expressions to have a best common supertype.
type = contextualSignature ? getUnionType(types) : getCommonSupertype(types);
if (!type) {
error(func, Diagnostics.No_best_common_type_exists_among_return_expressions);
return unknownType;
if (funcIsGenerator) {
error(func, Diagnostics.No_best_common_type_exists_among_yield_expressions);
return createIterableIteratorType(unknownType);
}
else {
error(func, Diagnostics.No_best_common_type_exists_among_return_expressions);
return unknownType;
}
}
if (funcIsGenerator) {
type = createIterableIteratorType(type);
}
}
if (!contextualSignature) {
@@ -7335,7 +7399,28 @@ module ts {
return getWidenedType(type);
}
/// Returns a set of types relating to every return expression relating to a function block.
function checkAndAggregateYieldOperandTypes(body: Block, contextualMapper?: TypeMapper): Type[] {
let aggregatedTypes: Type[] = [];
forEachYieldExpression(body, yieldExpression => {
let expr = yieldExpression.expression;
if (expr) {
let type = checkExpressionCached(expr, contextualMapper);
if (yieldExpression.asteriskToken) {
// A yield* expression effectively yields everything that its operand yields
type = checkElementTypeOfIterable(type, yieldExpression.expression);
}
if (!contains(aggregatedTypes, type)) {
aggregatedTypes.push(type);
}
}
});
return aggregatedTypes;
}
function checkAndAggregateReturnExpressionTypes(body: Block, contextualMapper?: TypeMapper): Type[] {
let aggregatedTypes: Type[] = [];
@@ -7978,14 +8063,58 @@ module ts {
}
}
function checkYieldExpression(node: YieldExpression): void {
function isYieldExpressionInClass(node: YieldExpression): boolean {
let current: Node = node
let parent = node.parent;
while (parent) {
if (isFunctionLike(parent) && current === (<FunctionLikeDeclaration>parent).body) {
return false;
}
else if (current.kind === SyntaxKind.ClassDeclaration || current.kind === SyntaxKind.ClassExpression) {
return true;
}
current = parent;
parent = parent.parent;
}
return false;
}
function checkYieldExpression(node: YieldExpression): Type {
// Grammar checking
if (!(node.parserContextFlags & ParserContextFlags.Yield)) {
grammarErrorOnFirstToken(node, Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) {
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
}
else {
grammarErrorOnFirstToken(node, Diagnostics.yield_expressions_are_not_currently_supported);
if (node.expression) {
let func = getContainingFunction(node);
// If the user's code is syntactically correct, the func should always have a star. After all,
// we are in a yield context.
if (func && func.asteriskToken) {
let expressionType = checkExpressionCached(node.expression, /*contextualMapper*/ undefined);
let expressionElementType: Type;
let nodeIsYieldStar = !!node.asteriskToken;
if (nodeIsYieldStar) {
expressionElementType = checkElementTypeOfIterable(expressionType, node.expression);
}
// There is no point in doing an assignability check if the function
// has no explicit return type because the return type is directly computed
// from the yield expressions.
if (func.type) {
let signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType;
if (nodeIsYieldStar) {
checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, /*headMessage*/ undefined);
}
else {
checkTypeAssignableTo(expressionType, signatureElementType, node.expression, /*headMessage*/ undefined);
}
}
}
}
// Both yield and yield* expressions have type 'any'
return anyType;
}
function checkConditionalExpression(node: ConditionalExpression, contextualMapper?: TypeMapper): Type {
@@ -8175,8 +8304,7 @@ module ts {
case SyntaxKind.OmittedExpression:
return undefinedType;
case SyntaxKind.YieldExpression:
checkYieldExpression(<YieldExpression>node);
return unknownType;
return checkYieldExpression(<YieldExpression>node);
}
return unknownType;
}
@@ -8229,6 +8357,16 @@ module ts {
}
}
function isSyntacticallyValidGenerator(node: SignatureDeclaration): boolean {
if (!(<FunctionLikeDeclaration>node).asteriskToken || !(<FunctionLikeDeclaration>node).body) {
return false;
}
return node.kind === SyntaxKind.MethodDeclaration ||
node.kind === SyntaxKind.FunctionDeclaration ||
node.kind === SyntaxKind.FunctionExpression;
}
function checkSignatureDeclaration(node: SignatureDeclaration) {
// Grammar checking
if (node.kind === SyntaxKind.IndexSignature) {
@@ -8261,6 +8399,27 @@ module ts {
break;
}
}
if (node.type) {
if (languageVersion >= ScriptTarget.ES6 && isSyntacticallyValidGenerator(node)) {
let returnType = getTypeFromTypeNode(node.type);
if (returnType === voidType) {
error(node.type, Diagnostics.A_generator_cannot_have_a_void_type_annotation);
}
else {
let generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType;
let iterableIteratorInstantiation = createIterableIteratorType(generatorElementType);
// Naively, one could check that IterableIterator<any> is assignable to the return type annotation.
// However, that would not catch the error in the following case.
//
// interface BadGenerator extends Iterable<number>, Iterator<string> { }
// function* g(): BadGenerator { } // Iterable and Iterator have different types!
//
checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type);
}
}
}
}
checkSpecializedSignatureDeclaration(node);
@@ -9032,10 +9191,19 @@ module ts {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
// in an ambient context
if (compilerOptions.noImplicitAny && nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) {
reportImplicitAnyError(node, anyType);
if (produceDiagnostics && !node.type) {
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
// in an ambient context
if (compilerOptions.noImplicitAny && nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) {
reportImplicitAnyError(node, anyType);
}
if (node.asteriskToken && nodeIsPresent(node.body)) {
// A generator with a body and no type annotation can still cause errors. It can error if the
// yielded values have no common supertype, or it can give an implicit any error if it has no
// yielded values. The only way to trigger these errors is to try checking its return type.
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
}
}
}
@@ -9450,7 +9618,7 @@ module ts {
// 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.
// getElementTypeOfIterable.
if (iteratedType) {
checkTypeAssignableTo(iteratedType, leftType, varExpr, /*headMessage*/ undefined);
}
@@ -9526,7 +9694,7 @@ module ts {
}
if (languageVersion >= ScriptTarget.ES6) {
return checkIteratedType(inputType, errorNode) || anyType;
return checkElementTypeOfIterable(inputType, errorNode);
}
if (allowStringInput) {
@@ -9547,100 +9715,143 @@ module ts {
/**
* When errorNode is undefined, it means we should not report any errors.
*/
function checkIteratedType(iterable: Type, errorNode: Node): Type {
Debug.assert(languageVersion >= ScriptTarget.ES6);
let iteratedType = getIteratedType(iterable, errorNode);
function checkElementTypeOfIterable(iterable: Type, errorNode: Node): Type {
let elementType = getElementTypeOfIterable(iterable, errorNode);
// Now even though we have extracted the iteratedType, we will have to validate that the type
// passed in is actually an Iterable.
if (errorNode && iteratedType) {
checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode);
if (errorNode && elementType) {
checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode);
}
return iteratedType;
function getIteratedType(iterable: Type, errorNode: Node) {
// 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;
}
return elementType || anyType;
}
/**
* 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<T>
* }
* }
*
* 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'.
*/
function getElementTypeOfIterable(type: Type, errorNode: Node): Type {
if (type.flags & TypeFlags.Any) {
return undefined;
}
let typeAsIterable = <IterableOrIteratorType>type;
if (!typeAsIterable.iterableElementType) {
// As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
// then just grab its type argument.
if ((iterable.flags & TypeFlags.Reference) && (<GenericType>iterable).target === globalIterableType) {
return (<GenericType>iterable).typeArguments[0];
if ((type.flags & TypeFlags.Reference) && (<GenericType>type).target === globalIterableType) {
typeAsIterable.iterableElementType = (<GenericType>type).typeArguments[0];
}
let iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator"));
if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) {
return undefined;
}
let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray;
if (iteratorFunctionSignatures.length === 0) {
if (errorNode) {
error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
else {
let iteratorFunction = getTypeOfPropertyOfType(type, getPropertyNameForKnownSymbolName("iterator"));
if (iteratorFunction && iteratorFunction.flags & TypeFlags.Any) {
return undefined;
}
return undefined;
}
let iterator = getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature));
if (allConstituentTypesHaveKind(iterator, TypeFlags.Any)) {
return undefined;
}
let iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next");
if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, TypeFlags.Any)) {
return undefined;
}
let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray;
if (iteratorNextFunctionSignatures.length === 0) {
if (errorNode) {
error(errorNode, Diagnostics.An_iterator_must_have_a_next_method);
let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray;
if (iteratorFunctionSignatures.length === 0) {
if (errorNode) {
error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
}
return undefined;
}
return undefined;
}
let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
if (allConstituentTypesHaveKind(iteratorNextResult, TypeFlags.Any)) {
return undefined;
typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode);
}
let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
if (!iteratorNextValue) {
if (errorNode) {
error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
}
return undefined;
}
return iteratorNextValue;
}
return typeAsIterable.iterableElementType;
}
/**
* This function has very similar logic as getElementTypeOfIterable, except that it operates on
* Iterators instead of Iterables. Here is the structure:
*
* { // iterator
* next: { // iteratorNextFunction
* (): { // iteratorNextResult
* value: T // iteratorNextValue
* }
* }
* }
*
*/
function getElementTypeOfIterator(type: Type, errorNode: Node): Type {
if (type.flags & TypeFlags.Any) {
return undefined;
}
let typeAsIterator = <IterableOrIteratorType>type;
if (!typeAsIterator.iteratorElementType) {
// As an optimization, if the type is instantiated directly using the globalIteratorType (Iterator<number>),
// then just grab its type argument.
if ((type.flags & TypeFlags.Reference) && (<GenericType>type).target === globalIteratorType) {
typeAsIterator.iteratorElementType = (<GenericType>type).typeArguments[0];
}
else {
let iteratorNextFunction = getTypeOfPropertyOfType(type, "next");
if (iteratorNextFunction && iteratorNextFunction.flags & TypeFlags.Any) {
return undefined;
}
let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray;
if (iteratorNextFunctionSignatures.length === 0) {
if (errorNode) {
error(errorNode, Diagnostics.An_iterator_must_have_a_next_method);
}
return undefined;
}
let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
if (iteratorNextResult.flags & TypeFlags.Any) {
return undefined;
}
let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
if (!iteratorNextValue) {
if (errorNode) {
error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
}
return undefined;
}
typeAsIterator.iteratorElementType = iteratorNextValue;
}
}
return typeAsIterator.iteratorElementType;
}
function getElementTypeOfIterableIterator(type: Type): Type {
if (type.flags & TypeFlags.Any) {
return undefined;
}
// As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator<number>),
// then just grab its type argument.
if ((type.flags & TypeFlags.Reference) && (<GenericType>type).target === globalIterableIteratorType) {
return (<GenericType>type).typeArguments[0];
}
return getElementTypeOfIterable(type, /*errorNode*/ undefined) ||
getElementTypeOfIterator(type, /*errorNode*/ undefined);
}
/**
@@ -9734,19 +9945,26 @@ module ts {
if (func) {
let returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func));
let exprType = checkExpressionCached(node.expression);
if (func.asteriskToken) {
// A generator does not need its return expressions checked against its return type.
// Instead, the yield expressions are checked against the element type.
// TODO: Check return expressions of generators when return type tracking is added
// for generators.
return;
}
if (func.kind === SyntaxKind.SetAccessor) {
error(node.expression, Diagnostics.Setters_cannot_return_a_value);
}
else {
if (func.kind === SyntaxKind.Constructor) {
if (!isTypeAssignableTo(exprType, returnType)) {
error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
}
}
else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) {
checkTypeAssignableTo(exprType, returnType, node.expression, /*headMessage*/ undefined);
else if (func.kind === SyntaxKind.Constructor) {
if (!isTypeAssignableTo(exprType, returnType)) {
error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
}
}
else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) {
checkTypeAssignableTo(exprType, returnType, node.expression, /*headMessage*/ undefined);
}
}
}
}
@@ -11227,93 +11445,6 @@ module ts {
return node.parent && node.parent.kind === SyntaxKind.ExpressionWithTypeArguments;
}
function isTypeNode(node: Node): boolean {
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
return true;
}
switch (node.kind) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.BooleanKeyword:
case SyntaxKind.SymbolKeyword:
return true;
case SyntaxKind.VoidKeyword:
return node.parent.kind !== SyntaxKind.VoidExpression;
case SyntaxKind.StringLiteral:
// Specialized signatures can have string literals as their parameters' type names
return node.parent.kind === SyntaxKind.Parameter;
case SyntaxKind.ExpressionWithTypeArguments:
return true;
// Identifiers and qualified names may be type nodes, depending on their context. Climb
// above them to find the lowest container
case SyntaxKind.Identifier:
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
if (node.parent.kind === SyntaxKind.QualifiedName && (<QualifiedName>node.parent).right === node) {
node = node.parent;
}
else if (node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node) {
node = node.parent;
}
// fall through
case SyntaxKind.QualifiedName:
case SyntaxKind.PropertyAccessExpression:
// At this point, node is either a qualified name or an identifier
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression,
"'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'.");
let parent = node.parent;
if (parent.kind === SyntaxKind.TypeQuery) {
return false;
}
// Do not recursively call isTypeNode on the parent. In the example:
//
// let a: A.B.C;
//
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
// A.B.C is a type node.
if (SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= SyntaxKind.LastTypeNode) {
return true;
}
switch (parent.kind) {
case SyntaxKind.ExpressionWithTypeArguments:
return true;
case SyntaxKind.TypeParameter:
return node === (<TypeParameterDeclaration>parent).constraint;
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.Parameter:
case SyntaxKind.VariableDeclaration:
return node === (<VariableLikeDeclaration>parent).type;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
case SyntaxKind.Constructor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node === (<FunctionLikeDeclaration>parent).type;
case SyntaxKind.CallSignature:
case SyntaxKind.ConstructSignature:
case SyntaxKind.IndexSignature:
return node === (<SignatureDeclaration>parent).type;
case SyntaxKind.TypeAssertionExpression:
return node === (<TypeAssertion>parent).type;
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return (<CallExpression>parent).typeArguments && indexOf((<CallExpression>parent).typeArguments, node) >= 0;
case SyntaxKind.TaggedTemplateExpression:
// TODO (drosen): TaggedTemplateExpressions may eventually support type arguments.
return false;
}
}
return false;
}
function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide: EntityName): ImportEqualsDeclaration | ExportAssignment {
while (nodeOnRightSide.parent.kind === SyntaxKind.QualifiedName) {
nodeOnRightSide = <QualifiedName>nodeOnRightSide.parent;
@@ -12048,8 +12179,7 @@ module ts {
getSymbolLinks(unknownSymbol).type = unknownType;
globals[undefinedSymbol.name] = undefinedSymbol;
// Initialize special types
globalArraySymbol = getGlobalTypeSymbol("Array");
globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, /*arity*/ 1);
globalArrayType = <GenericType>getGlobalType("Array", /*arity*/ 1);
globalObjectType = getGlobalType("Object");
globalFunctionType = getGlobalType("Function");
globalStringType = getGlobalType("String");
@@ -12067,7 +12197,9 @@ module ts {
globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray");
globalESSymbolType = getGlobalType("Symbol");
globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol");
globalIterableType = getGlobalType("Iterable", /*arity*/ 1);
globalIterableType = <GenericType>getGlobalType("Iterable", /*arity*/ 1);
globalIteratorType = <GenericType>getGlobalType("Iterator", /*arity*/ 1);
globalIterableIteratorType = <GenericType>getGlobalType("IterableIterator", /*arity*/ 1);
}
else {
globalTemplateStringsArrayType = unknownType;
@@ -12077,6 +12209,9 @@ module ts {
// a global Symbol already, particularly if it is a class.
globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
globalESSymbolConstructorSymbol = undefined;
globalIterableType = emptyGenericType;
globalIteratorType = emptyGenericType;
globalIterableIteratorType = emptyGenericType;
}
anyArrayType = createArrayType(anyType);
@@ -12624,7 +12759,19 @@ module ts {
function checkGrammarForGenerator(node: FunctionLikeDeclaration) {
if (node.asteriskToken) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_currently_supported);
Debug.assert(
node.kind === SyntaxKind.FunctionDeclaration ||
node.kind === SyntaxKind.FunctionExpression ||
node.kind === SyntaxKind.MethodDeclaration);
if (isInAmbientContext(node)) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
}
if (!node.body) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
}
if (languageVersion < ScriptTarget.ES6) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
}
}
}
@@ -120,7 +120,7 @@ module ts {
Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." },
Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." },
A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." },
Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." },
A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." },
@@ -174,6 +174,9 @@ module ts {
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1219, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
Generators_are_not_allowed_in_an_ambient_context: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
An_overload_signature_cannot_be_declared_as_a_generator: { code: 1221, category: DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." },
_0_tag_already_specified: { code: 1219, category: DiagnosticCategory.Error, key: "'{0}' tag already specified." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
@@ -366,6 +369,8 @@ module ts {
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
No_best_common_type_exists_among_yield_expressions: { code: 2504, category: DiagnosticCategory.Error, key: "No best common type exists among yield expressions." },
A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." },
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}'." },
@@ -523,6 +528,7 @@ module ts {
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." },
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." },
import_can_only_be_used_in_a_ts_file: { code: 8002, category: DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." },
@@ -540,8 +546,6 @@ module ts {
enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." },
type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." },
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
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." },
Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." },
class_expressions_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." },
+29 -11
View File
@@ -467,7 +467,7 @@
"category": "Error",
"code": 1162
},
"'yield' expression must be contained_within a generator declaration.": {
"A 'yield' expression is only allowed in a generator body.": {
"category": "Error",
"code": 1163
},
@@ -682,7 +682,21 @@
"Export assignment is not supported when '--module' flag is 'system'.": {
"category": "Error",
"code": 1218
},
"Generators are only available when targeting ECMAScript 6 or higher.": {
"category": "Error",
"code": 1219
},
"Generators are not allowed in an ambient context.": {
"category": "Error",
"code": 1220
},
"An overload signature cannot be declared as a generator.": {
"category": "Error",
"code": 1221
},
"'{0}' tag already specified.": {
"category": "Error",
"code": 1219
@@ -1442,15 +1456,23 @@
"A rest element cannot contain a binding pattern.": {
"category": "Error",
"code": 2501
},
},
"'{0}' is referenced directly or indirectly in its own type annotation.": {
"category": "Error",
"code": 2502
},
},
"Cannot find namespace '{0}'.": {
"category": "Error",
"code": 2503
},
"No best common type exists among yield expressions.": {
"category": "Error",
"code": 2504
},
"A generator cannot have a 'void' type annotation.": {
"category": "Error",
"code": 2505
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
@@ -2083,6 +2105,10 @@
"category": "Error",
"code": 7024
},
"Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type.": {
"category": "Error",
"code": 7025
},
"You cannot rename this element.": {
"category": "Error",
"code": 8000
@@ -2152,14 +2178,6 @@
"code": 8017
},
"'yield' expressions are not currently supported.": {
"category": "Error",
"code": 9000
},
"Generators are not currently supported.": {
"category": "Error",
"code": 9001
},
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": {
"category": "Error",
"code": 9002
+14 -1
View File
@@ -4143,7 +4143,20 @@ module ts {
property.name = name;
property.questionToken = questionToken;
property.type = parseTypeAnnotation();
property.initializer = allowInAnd(parseNonParameterInitializer);
// For instance properties specifically, since they are evaluated inside the constructor,
// we do *not * want to parse yield expressions, so we specifically turn the yield context
// off. The grammar would look something like this:
//
// MemberVariableDeclaration[Yield]:
// AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In];
// AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield];
//
// The checker may still error in the static case to explicitly disallow the yield expression.
property.initializer = modifiers && modifiers.flags & NodeFlags.Static
? allowInAnd(parseNonParameterInitializer)
: doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.DisallowIn, parseNonParameterInitializer);
parseSemicolon();
return finishNode(property);
}
+8 -1
View File
@@ -693,7 +693,7 @@ module ts {
export interface YieldExpression extends Expression {
asteriskToken?: Node;
expression: Expression;
expression?: Expression;
}
export interface BinaryExpression extends Expression {
@@ -1676,6 +1676,13 @@ module ts {
numberIndexType: Type; // Numeric index type
}
// Just a place to cache element types of iterables and iterators
/* @internal */
export interface IterableOrIteratorType extends ObjectType, UnionType {
iterableElementType?: Type;
iteratorElementType?: Type;
}
// Type parameters (TypeFlags.TypeParameter)
export interface TypeParameter extends Type {
constraint: Type; // Constraint
+128
View File
@@ -408,6 +408,93 @@ module ts {
export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
export function isTypeNode(node: Node): boolean {
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
return true;
}
switch (node.kind) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.BooleanKeyword:
case SyntaxKind.SymbolKeyword:
return true;
case SyntaxKind.VoidKeyword:
return node.parent.kind !== SyntaxKind.VoidExpression;
case SyntaxKind.StringLiteral:
// Specialized signatures can have string literals as their parameters' type names
return node.parent.kind === SyntaxKind.Parameter;
case SyntaxKind.ExpressionWithTypeArguments:
return true;
// Identifiers and qualified names may be type nodes, depending on their context. Climb
// above them to find the lowest container
case SyntaxKind.Identifier:
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
if (node.parent.kind === SyntaxKind.QualifiedName && (<QualifiedName>node.parent).right === node) {
node = node.parent;
}
else if (node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node) {
node = node.parent;
}
// fall through
case SyntaxKind.QualifiedName:
case SyntaxKind.PropertyAccessExpression:
// At this point, node is either a qualified name or an identifier
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression,
"'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'.");
let parent = node.parent;
if (parent.kind === SyntaxKind.TypeQuery) {
return false;
}
// Do not recursively call isTypeNode on the parent. In the example:
//
// let a: A.B.C;
//
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
// A.B.C is a type node.
if (SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= SyntaxKind.LastTypeNode) {
return true;
}
switch (parent.kind) {
case SyntaxKind.ExpressionWithTypeArguments:
return true;
case SyntaxKind.TypeParameter:
return node === (<TypeParameterDeclaration>parent).constraint;
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.Parameter:
case SyntaxKind.VariableDeclaration:
return node === (<VariableLikeDeclaration>parent).type;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
case SyntaxKind.Constructor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node === (<FunctionLikeDeclaration>parent).type;
case SyntaxKind.CallSignature:
case SyntaxKind.ConstructSignature:
case SyntaxKind.IndexSignature:
return node === (<SignatureDeclaration>parent).type;
case SyntaxKind.TypeAssertionExpression:
return node === (<TypeAssertion>parent).type;
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return (<CallExpression>parent).typeArguments && indexOf((<CallExpression>parent).typeArguments, node) >= 0;
case SyntaxKind.TaggedTemplateExpression:
// TODO (drosen): TaggedTemplateExpressions may eventually support type arguments.
return false;
}
}
return false;
}
// Warning: This has the same semantics as the forEach family of functions,
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
@@ -438,6 +525,46 @@ module ts {
}
}
export function forEachYieldExpression(body: Block, visitor: (expr: YieldExpression) => void): void {
return traverse(body);
function traverse(node: Node): void {
switch (node.kind) {
case SyntaxKind.YieldExpression:
visitor(<YieldExpression>node);
let operand = (<YieldExpression>node).expression;
if (operand) {
traverse(operand);
}
case SyntaxKind.EnumDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.ClassDeclaration:
// These are not allowed inside a generator now, but eventually they may be allowed
// as local types. Regardless, any yield statements contained within them should be
// skipped in this traversal.
return;
default:
if (isFunctionLike(node)) {
let name = (<FunctionLikeDeclaration>node).name;
if (name && name.kind === SyntaxKind.ComputedPropertyName) {
// Note that we will not include methods/accessors of a class because they would require
// first descending into the class. This is by design.
traverse((<ComputedPropertyName>name).expression);
return;
}
}
else if (!isTypeNode(node)) {
// This is the general case, which should include mostly expressions and statements.
// Also includes NodeArrays.
forEachChild(node, traverse);
}
}
}
}
export function isVariableLike(node: Node): boolean {
if (node) {
switch (node.kind) {
@@ -739,6 +866,7 @@ module ts {
case SyntaxKind.TemplateExpression:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.OmittedExpression:
case SyntaxKind.YieldExpression:
return true;
case SyntaxKind.QualifiedName:
while (node.parent.kind === SyntaxKind.QualifiedName) {
-8
View File
@@ -505,14 +505,6 @@ interface GeneratorFunctionConstructor {
}
declare var GeneratorFunction: GeneratorFunctionConstructor;
interface Generator<T> extends IterableIterator<T> {
next(value?: any): IteratorResult<T>;
throw(exception: any): IteratorResult<T>;
return(value: T): IteratorResult<T>;
[Symbol.iterator](): Generator<T>;
[Symbol.toStringTag]: string;
}
interface Math {
/**
* Returns the number of leading zero bits in the 32-bit binary representation of a number.
+22 -1
View File
@@ -193,12 +193,18 @@ module ts.formatting {
// Insert space after function keyword for anonymous functions
public SpaceAfterAnonymousFunctionKeyword: Rule;
public NoSpaceAfterAnonymousFunctionKeyword: Rule;
// Insert space after @ in decorator
public SpaceBeforeAt: Rule;
public NoSpaceAfterAt: Rule;
public SpaceAfterDecorator: Rule;
// Generator: function*
public NoSpaceBetweenFunctionKeywordAndStar: Rule;
public SpaceAfterStarInGeneratorDeclaration: Rule;
public NoSpaceBetweenYieldKeywordAndStar: Rule;
public SpaceBetweenYieldOrYieldStarAndOperand: Rule;
constructor() {
///
/// Common Rules
@@ -340,6 +346,11 @@ module ts.formatting {
this.NoSpaceAfterAt = new Rule(RuleDescriptor.create3(SyntaxKind.AtToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.SpaceAfterDecorator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.ExportKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.ClassKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PublicKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword, SyntaxKind.OpenBracketToken, SyntaxKind.AsteriskToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), RuleAction.Space));
this.NoSpaceBetweenFunctionKeywordAndStar = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), RuleAction.Delete));
this.SpaceAfterStarInGeneratorDeclaration = new Rule(RuleDescriptor.create3(SyntaxKind.AsteriskToken, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.OpenParenToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), RuleAction.Space));
this.NoSpaceBetweenYieldKeywordAndStar = new Rule(RuleDescriptor.create1(SyntaxKind.YieldKeyword, SyntaxKind.AsteriskToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), RuleAction.Delete));
this.SpaceBetweenYieldOrYieldStarAndOperand = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.YieldKeyword, SyntaxKind.AsteriskToken]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), RuleAction.Space));
// These rules are higher in priority than user-configurable rules.
this.HighPriorityCommonRules =
[
@@ -357,7 +368,9 @@ module ts.formatting {
this.NoSpaceAfterCloseBrace,
this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext,
this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets,
this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration,
this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember,
this.NoSpaceBetweenYieldKeywordAndStar, this.SpaceBetweenYieldOrYieldStarAndOperand,
this.NoSpaceBetweenReturnAndSemicolon,
this.SpaceAfterCertainKeywords,
this.SpaceAfterLetConstInVariableDeclaration,
@@ -574,6 +587,10 @@ module ts.formatting {
return false;
}
static IsFunctionDeclarationOrFunctionExpressionContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.FunctionDeclaration || context.contextNode.kind === SyntaxKind.FunctionExpression;
}
static IsTypeScriptDeclWithBlockContext(context: FormattingContext): boolean {
return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode);
}
@@ -717,5 +734,9 @@ module ts.formatting {
static IsVoidOpContext(context: FormattingContext): boolean {
return context.currentTokenSpan.kind === SyntaxKind.VoidKeyword && context.currentTokenParent.kind === SyntaxKind.VoidExpression;
}
static IsYieldOrYieldStarWithOperand(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.YieldExpression && (<YieldExpression>context.contextNode).expression !== undefined;
}
}
}
+1 -1
View File
@@ -989,4 +989,4 @@ module TypeScript.Services {
}
/* @internal */
let toolsVersion = "1.4";
let toolsVersion = "1.5";
@@ -1,8 +1,8 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (1 errors) ====
function * foo(a = yield => yield) {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
}
@@ -1,8 +1,8 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts (1 errors) ====
function * yield() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
}
@@ -1,11 +1,11 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(3,11): error TS2304: Cannot find name 'yield'.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts (2 errors) ====
function * foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
// Legal to use 'yield' in a type context.
var v: yield;
~~~~~
@@ -1,8 +1,8 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts (1 errors) ====
function * foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
}
@@ -1,11 +1,11 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2304: Cannot find name 'yield'.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts (2 errors) ====
function*foo(a = yield) {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
~~~~~
!!! error TS2304: Cannot find name 'yield'.
}
@@ -1,16 +1,16 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2304: Cannot find name 'yield'.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts (3 errors) ====
function*bar() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
// 'yield' here is an identifier, and not a yield expression.
function*foo(a = yield) {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
~~~~~
!!! error TS2304: Cannot find name 'yield'.
}
@@ -1,12 +1,9 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,14): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ====
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (1 errors) ====
function * foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
var v = { [yield]: foo }
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -1,7 +1,7 @@
tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts (1 errors) ====
var v = function * () { }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
@@ -1,7 +1,7 @@
tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts (1 errors) ====
var v = function * foo() { }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
@@ -1,7 +1,7 @@
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts(1,11): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts(1,11): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts (1 errors) ====
var v = { *foo() { } }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
@@ -1,10 +1,10 @@
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,13): error TS2304: Cannot find name 'foo'.
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ====
var v = { *[foo()]() { } }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
~~~
!!! error TS2304: Cannot find name 'foo'.
@@ -1,9 +1,9 @@
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts(2,4): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts(2,4): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts (1 errors) ====
class C {
*foo() { }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
}
@@ -1,9 +1,9 @@
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts (1 errors) ====
class C {
public * foo() { }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
}
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,6): error TS2304: Cannot find name 'foo'.
@@ -6,7 +6,7 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration
class C {
*[foo]() { }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
~~~
!!! error TS2304: Cannot find name 'foo'.
}
@@ -1,9 +1,9 @@
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts(2,4): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts(2,4): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts (1 errors) ====
class C {
*foo<T>() { }
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
}
@@ -1,14 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(1,11): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(2,5): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(1,11): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(2,11): error TS2304: Cannot find name 'foo'.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts (2 errors) ====
var v = { * foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield(foo);
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
~~~
!!! error TS2304: Cannot find name 'foo'.
}
}
@@ -1,14 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(2,3): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(3,5): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(2,3): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(3,11): error TS2304: Cannot find name 'foo'.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts (2 errors) ====
class C {
*foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield(foo);
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
~~~
!!! error TS2304: Cannot find name 'foo'.
}
}
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts(3,6): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts(3,6): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts(3,6): erro
constructor() {
yield foo
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
}
}
@@ -1,10 +1,7 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,19): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (2 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (1 errors) ====
function* foo() { yield }
~
!!! error TS9001: Generators are not currently supported.
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts(3,6): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts(3,6): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts(3,6): erro
foo() {
yield foo
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
}
}
@@ -1,9 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression15_es6.ts(2,6): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression15_es6.ts(2,6): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression15_es6.ts (1 errors) ====
var v = () => {
yield foo
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
}
@@ -1,14 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(3,5): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(3,5): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts (2 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
function bar() {
yield foo;
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
}
}
@@ -1,6 +1,6 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,15): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,15): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,23): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,23): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts (3 errors) ====
@@ -10,4 +10,4 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,23): err
~~~
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
@@ -1,8 +1,8 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts (1 errors) ====
"use strict";
yield(foo);
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
@@ -1,19 +1,16 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(3,13): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(4,7): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(3,13): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts (3 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts (2 errors) ====
function*foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
function bar() {
function* quux() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield(foo);
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
}
}
@@ -1,7 +1,7 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression2_es6.ts(1,1): error TS1163: 'yield' expression must be contained_within a generator declaration.
tests/cases/conformance/es6/yieldExpressions/YieldExpression2_es6.ts(1,1): error TS1163: A 'yield' expression is only allowed in a generator body.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression2_es6.ts (1 errors) ====
yield foo;
~~~~~
!!! error TS1163: 'yield' expression must be contained_within a generator declaration.
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
@@ -1,16 +1,10 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(3,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts (3 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts (1 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
yield
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -1,16 +1,10 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(3,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts (3 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts (1 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield;
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
yield;
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -1,12 +1,12 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(2,9): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts (2 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield*foo
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
~~~
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
}
@@ -1,12 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts(1,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts (2 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts (1 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield foo
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -1,16 +1,13 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(1,1): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(2,9): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(3,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(2,9): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts (3 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts (2 errors) ====
yield(foo);
~~~~~
!!! error TS2304: Cannot find name 'yield'.
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield(foo);
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -1,12 +1,12 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(1,17): error TS9001: Generators are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported.
tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(1,17): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(2,9): error TS2304: Cannot find name 'foo'.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts (2 errors) ====
var v = function*() {
~
!!! error TS9001: Generators are not currently supported.
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield(foo);
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
~~~
!!! error TS2304: Cannot find name 'foo'.
}
@@ -0,0 +1,10 @@
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts(1,1): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts(1,9): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts (2 errors) ====
yield * [];
~~~~~
!!! error TS2304: Cannot find name 'yield'.
~~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
@@ -0,0 +1,5 @@
//// [YieldStarExpression1_es6.ts]
yield * [];
//// [YieldStarExpression1_es6.js]
yield * [];
@@ -0,0 +1,10 @@
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts(1,1): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts(1,8): error TS1109: Expression expected.
==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts (2 errors) ====
yield *;
~~~~~
!!! error TS2304: Cannot find name 'yield'.
~
!!! error TS1109: Expression expected.
@@ -0,0 +1,5 @@
//// [YieldStarExpression2_es6.ts]
yield *;
//// [YieldStarExpression2_es6.js]
yield * ;
@@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts(2,12): error TS1109: Expression expected.
==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts (1 errors) ====
function *g() {
yield *;
~
!!! error TS1109: Expression expected.
}
@@ -0,0 +1,9 @@
//// [YieldStarExpression3_es6.ts]
function *g() {
yield *;
}
//// [YieldStarExpression3_es6.js]
function g() {
yield* ;
}
@@ -0,0 +1,12 @@
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts(1,10): error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts(2,13): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts (2 errors) ====
function *g() {
~
!!! error TS1219: Generators are only available when targeting ECMAScript 6 or higher.
yield * [];
~~
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
}
@@ -0,0 +1,9 @@
//// [YieldStarExpression4_es6.ts]
function *g() {
yield * [];
}
//// [YieldStarExpression4_es6.js]
function g() {
yield* [];
}
@@ -5,7 +5,7 @@ function f() {
if (Math.random()) {
>Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1699, 1))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60))
>random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
let arguments = 100;
@@ -8,7 +8,7 @@ function f() {
if (Math.random()) {
>Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1699, 1))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60))
>random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
const arguments = 100;
@@ -8,7 +8,7 @@ function f() {
if (Math.random()) {
>Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1699, 1))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60))
>random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
return () => arguments[0];
@@ -9,7 +9,7 @@ function f() {
if (Math.random()) {
>Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1699, 1))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60))
>random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
return () => arguments[0];
@@ -9,7 +9,7 @@ function f() {
if (Math.random()) {
>Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1699, 1))
>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60))
>random : Symbol(Math.random, Decl(lib.d.ts, 608, 38))
return () => arguments;
+1 -1
View File
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/for-ofStatements/for-of37.ts ===
var map = new Map([["", true]]);
>map : Symbol(map, Decl(for-of37.ts, 0, 3))
>Map : Symbol(Map, Decl(lib.d.ts, 1872, 1), Decl(lib.d.ts, 1894, 11))
>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11))
for (var v of map) {
>v : Symbol(v, Decl(for-of37.ts, 1, 8))
+1 -1
View File
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/for-ofStatements/for-of38.ts ===
var map = new Map([["", true]]);
>map : Symbol(map, Decl(for-of38.ts, 0, 3))
>Map : Symbol(Map, Decl(lib.d.ts, 1872, 1), Decl(lib.d.ts, 1894, 11))
>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11))
for (var [k, v] of map) {
>k : Symbol(k, Decl(for-of38.ts, 1, 10))
+1 -1
View File
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/for-ofStatements/for-of40.ts ===
var map = new Map([["", true]]);
>map : Symbol(map, Decl(for-of40.ts, 0, 3))
>Map : Symbol(Map, Decl(lib.d.ts, 1872, 1), Decl(lib.d.ts, 1894, 11))
>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11))
for (var [k = "", v = false] of map) {
>k : Symbol(k, Decl(for-of40.ts, 1, 10))
+1 -1
View File
@@ -5,7 +5,7 @@ var k: string, v: boolean;
var map = new Map([["", true]]);
>map : Symbol(map, Decl(for-of45.ts, 1, 3))
>Map : Symbol(Map, Decl(lib.d.ts, 1872, 1), Decl(lib.d.ts, 1894, 11))
>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11))
for ([k = "", v = false] of map) {
>k : Symbol(k, Decl(for-of45.ts, 0, 3))
+1 -1
View File
@@ -1,7 +1,7 @@
=== tests/cases/conformance/es6/for-ofStatements/for-of50.ts ===
var map = new Map([["", true]]);
>map : Symbol(map, Decl(for-of50.ts, 0, 3))
>Map : Symbol(Map, Decl(lib.d.ts, 1872, 1), Decl(lib.d.ts, 1894, 11))
>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11))
for (const [k, v] of map) {
>k : Symbol(k, Decl(for-of50.ts, 1, 12))
@@ -1,12 +0,0 @@
tests/cases/compiler/generatorES6_1.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/compiler/generatorES6_1.ts(2,5): error TS9000: 'yield' expressions are not currently supported.
==== tests/cases/compiler/generatorES6_1.ts (2 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
yield
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -0,0 +1,6 @@
=== tests/cases/compiler/generatorES6_1.ts ===
function* foo() {
>foo : Symbol(foo, Decl(generatorES6_1.ts, 0, 0))
yield
}
@@ -0,0 +1,7 @@
=== tests/cases/compiler/generatorES6_1.ts ===
function* foo() {
>foo : () => IterableIterator<any>
yield
>yield : any
}
@@ -1,14 +0,0 @@
tests/cases/compiler/generatorES6_2.ts(2,12): error TS9001: Generators are not currently supported.
tests/cases/compiler/generatorES6_2.ts(3,9): error TS9000: 'yield' expressions are not currently supported.
==== tests/cases/compiler/generatorES6_2.ts (2 errors) ====
class C {
public * foo() {
~
!!! error TS9001: Generators are not currently supported.
yield 1
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
}
@@ -0,0 +1,10 @@
=== tests/cases/compiler/generatorES6_2.ts ===
class C {
>C : Symbol(C, Decl(generatorES6_2.ts, 0, 0))
public * foo() {
>foo : Symbol(foo, Decl(generatorES6_2.ts, 0, 9))
yield 1
}
}
@@ -0,0 +1,12 @@
=== tests/cases/compiler/generatorES6_2.ts ===
class C {
>C : C
public * foo() {
>foo : () => IterableIterator<number>
yield 1
>yield 1 : any
>1 : number
}
}
@@ -1,12 +0,0 @@
tests/cases/compiler/generatorES6_3.ts(1,17): error TS9001: Generators are not currently supported.
tests/cases/compiler/generatorES6_3.ts(2,5): error TS9000: 'yield' expressions are not currently supported.
==== tests/cases/compiler/generatorES6_3.ts (2 errors) ====
var v = function*() {
~
!!! error TS9001: Generators are not currently supported.
yield 0
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
@@ -0,0 +1,6 @@
=== tests/cases/compiler/generatorES6_3.ts ===
var v = function*() {
>v : Symbol(v, Decl(generatorES6_3.ts, 0, 3))
yield 0
}
@@ -0,0 +1,9 @@
=== tests/cases/compiler/generatorES6_3.ts ===
var v = function*() {
>v : () => IterableIterator<number>
>function*() { yield 0} : () => IterableIterator<number>
yield 0
>yield 0 : any
>0 : number
}
@@ -1,14 +0,0 @@
tests/cases/compiler/generatorES6_4.ts(2,4): error TS9001: Generators are not currently supported.
tests/cases/compiler/generatorES6_4.ts(3,8): error TS9000: 'yield' expressions are not currently supported.
==== tests/cases/compiler/generatorES6_4.ts (2 errors) ====
var v = {
*foo() {
~
!!! error TS9001: Generators are not currently supported.
yield 0
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
}
@@ -0,0 +1,10 @@
=== tests/cases/compiler/generatorES6_4.ts ===
var v = {
>v : Symbol(v, Decl(generatorES6_4.ts, 0, 3))
*foo() {
>foo : Symbol(foo, Decl(generatorES6_4.ts, 0, 9))
yield 0
}
}
@@ -0,0 +1,13 @@
=== tests/cases/compiler/generatorES6_4.ts ===
var v = {
>v : { foo(): IterableIterator<number>; }
>{ *foo() { yield 0 }} : { foo(): IterableIterator<number>; }
*foo() {
>foo : () => IterableIterator<number>
yield 0
>yield 0 : any
>0 : number
}
}
@@ -1,12 +1,15 @@
tests/cases/compiler/generatorES6_5.ts(1,9): error TS9001: Generators are not currently supported.
tests/cases/compiler/generatorES6_5.ts(2,5): error TS9000: 'yield' expressions are not currently supported.
tests/cases/compiler/generatorES6_5.ts(2,11): error TS2304: Cannot find name 'a'.
tests/cases/compiler/generatorES6_5.ts(2,15): error TS2304: Cannot find name 'b'.
tests/cases/compiler/generatorES6_5.ts(2,19): error TS2304: Cannot find name 'c'.
==== tests/cases/compiler/generatorES6_5.ts (2 errors) ====
==== tests/cases/compiler/generatorES6_5.ts (3 errors) ====
function* foo() {
~
!!! error TS9001: Generators are not currently supported.
yield a ? b : c;
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2304: Cannot find name 'b'.
~
!!! error TS2304: Cannot find name 'c'.
}
@@ -1,14 +0,0 @@
tests/cases/compiler/generatorES6_6.ts(2,3): error TS9001: Generators are not currently supported.
tests/cases/compiler/generatorES6_6.ts(3,13): error TS9000: 'yield' expressions are not currently supported.
==== tests/cases/compiler/generatorES6_6.ts (2 errors) ====
class C {
*[Symbol.iterator]() {
~
!!! error TS9001: Generators are not currently supported.
let a = yield 1;
~~~~~
!!! error TS9000: 'yield' expressions are not currently supported.
}
}
@@ -0,0 +1,13 @@
=== tests/cases/compiler/generatorES6_6.ts ===
class C {
>C : Symbol(C, Decl(generatorES6_6.ts, 0, 0))
*[Symbol.iterator]() {
>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31))
>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1292, 11))
>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31))
let a = yield 1;
>a : Symbol(a, Decl(generatorES6_6.ts, 2, 7))
}
}
@@ -0,0 +1,15 @@
=== tests/cases/compiler/generatorES6_6.ts ===
class C {
>C : C
*[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
let a = yield 1;
>a : any
>yield 1 : any
>1 : number
}
}
@@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts(2,5): error TS1220: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts (1 errors) ====
declare class C {
*generator(): any;
~
!!! error TS1220: Generators are not allowed in an ambient context.
}
@@ -0,0 +1,6 @@
//// [generatorInAmbientContext1.ts]
declare class C {
*generator(): any;
}
//// [generatorInAmbientContext1.js]
@@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts(2,14): error TS1220: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts (1 errors) ====
declare module M {
function *generator(): any;
~
!!! error TS1220: Generators are not allowed in an ambient context.
}
@@ -0,0 +1,6 @@
//// [generatorInAmbientContext2.ts]
declare module M {
function *generator(): any;
}
//// [generatorInAmbientContext2.js]
@@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts(2,5): error TS1220: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts (1 errors) ====
declare class C {
*generator(): any;
~
!!! error TS1220: Generators are not allowed in an ambient context.
}
@@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts(2,14): error TS1220: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts (1 errors) ====
declare module M {
function *generator(): any;
~
!!! error TS1220: Generators are not allowed in an ambient context.
}
@@ -0,0 +1,15 @@
//// [generatorInAmbientContext5.ts]
class C {
*generator(): any { }
}
//// [generatorInAmbientContext5.js]
class C {
*generator() { }
}
//// [generatorInAmbientContext5.d.ts]
declare class C {
generator(): any;
}
@@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts ===
class C {
>C : Symbol(C, Decl(generatorInAmbientContext5.ts, 0, 0))
*generator(): any { }
>generator : Symbol(generator, Decl(generatorInAmbientContext5.ts, 0, 9))
}
@@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts ===
class C {
>C : C
*generator(): any { }
>generator : () => any
}
@@ -0,0 +1,17 @@
//// [generatorInAmbientContext6.ts]
module M {
export function *generator(): any { }
}
//// [generatorInAmbientContext6.js]
var M;
(function (M) {
function* generator() { }
M.generator = generator;
})(M || (M = {}));
//// [generatorInAmbientContext6.d.ts]
declare module M {
function generator(): any;
}
@@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts ===
module M {
>M : Symbol(M, Decl(generatorInAmbientContext6.ts, 0, 0))
export function *generator(): any { }
>generator : Symbol(generator, Decl(generatorInAmbientContext6.ts, 0, 10))
}
@@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts ===
module M {
>M : typeof M
export function *generator(): any { }
>generator : () => any
}
@@ -0,0 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(2,13): error TS1221: An overload signature cannot be declared as a generator.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(3,13): error TS1221: An overload signature cannot be declared as a generator.
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts (2 errors) ====
module M {
function* f(s: string): Iterable<any>;
~
!!! error TS1221: An overload signature cannot be declared as a generator.
function* f(s: number): Iterable<any>;
~
!!! error TS1221: An overload signature cannot be declared as a generator.
function* f(s: any): Iterable<any> { }
}
@@ -0,0 +1,12 @@
//// [generatorOverloads1.ts]
module M {
function* f(s: string): Iterable<any>;
function* f(s: number): Iterable<any>;
function* f(s: any): Iterable<any> { }
}
//// [generatorOverloads1.js]
var M;
(function (M) {
function* f(s) { }
})(M || (M = {}));
@@ -0,0 +1,17 @@
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(2,13): error TS1220: Generators are not allowed in an ambient context.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(3,13): error TS1220: Generators are not allowed in an ambient context.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(4,13): error TS1220: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts (3 errors) ====
declare module M {
function* f(s: string): Iterable<any>;
~
!!! error TS1220: Generators are not allowed in an ambient context.
function* f(s: number): Iterable<any>;
~
!!! error TS1220: Generators are not allowed in an ambient context.
function* f(s: any): Iterable<any>;
~
!!! error TS1220: Generators are not allowed in an ambient context.
}
@@ -0,0 +1,8 @@
//// [generatorOverloads2.ts]
declare module M {
function* f(s: string): Iterable<any>;
function* f(s: number): Iterable<any>;
function* f(s: any): Iterable<any>;
}
//// [generatorOverloads2.js]
@@ -0,0 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(2,5): error TS1221: An overload signature cannot be declared as a generator.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(3,5): error TS1221: An overload signature cannot be declared as a generator.
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts (2 errors) ====
class C {
*f(s: string): Iterable<any>;
~
!!! error TS1221: An overload signature cannot be declared as a generator.
*f(s: number): Iterable<any>;
~
!!! error TS1221: An overload signature cannot be declared as a generator.
*f(s: any): Iterable<any> { }
}
@@ -0,0 +1,11 @@
//// [generatorOverloads3.ts]
class C {
*f(s: string): Iterable<any>;
*f(s: number): Iterable<any>;
*f(s: any): Iterable<any> { }
}
//// [generatorOverloads3.js]
class C {
*f(s) { }
}
@@ -0,0 +1,11 @@
//// [generatorOverloads4.ts]
class C {
f(s: string): Iterable<any>;
f(s: number): Iterable<any>;
*f(s: any): Iterable<any> { }
}
//// [generatorOverloads4.js]
class C {
*f(s) { }
}
@@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts ===
class C {
>C : Symbol(C, Decl(generatorOverloads4.ts, 0, 0))
f(s: string): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32))
>s : Symbol(s, Decl(generatorOverloads4.ts, 1, 6))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1))
f(s: number): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32))
>s : Symbol(s, Decl(generatorOverloads4.ts, 2, 6))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1))
*f(s: any): Iterable<any> { }
>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32))
>s : Symbol(s, Decl(generatorOverloads4.ts, 3, 7))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1))
}
@@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts ===
class C {
>C : C
f(s: string): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : string
>Iterable : Iterable<T>
f(s: number): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : number
>Iterable : Iterable<T>
*f(s: any): Iterable<any> { }
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : any
>Iterable : Iterable<T>
}
@@ -0,0 +1,12 @@
//// [generatorOverloads5.ts]
module M {
function f(s: string): Iterable<any>;
function f(s: number): Iterable<any>;
function* f(s: any): Iterable<any> { }
}
//// [generatorOverloads5.js]
var M;
(function (M) {
function* f(s) { }
})(M || (M = {}));
@@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts ===
module M {
>M : Symbol(M, Decl(generatorOverloads5.ts, 0, 0))
function f(s: string): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41))
>s : Symbol(s, Decl(generatorOverloads5.ts, 1, 15))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1))
function f(s: number): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41))
>s : Symbol(s, Decl(generatorOverloads5.ts, 2, 15))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1))
function* f(s: any): Iterable<any> { }
>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41))
>s : Symbol(s, Decl(generatorOverloads5.ts, 3, 16))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1))
}
@@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts ===
module M {
>M : typeof M
function f(s: string): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : string
>Iterable : Iterable<T>
function f(s: number): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : number
>Iterable : Iterable<T>
function* f(s: any): Iterable<any> { }
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : any
>Iterable : Iterable<T>
}

Some files were not shown because too many files have changed in this diff Show More