Report errors for using yield/generators right now.

This commit is contained in:
Cyrus Najmabadi
2014-11-25 12:16:31 -08:00
parent af4a12151c
commit 5b539f0636
72 changed files with 227 additions and 405 deletions

View File

@@ -414,5 +414,7 @@ module ts {
_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." },
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
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." },
};
}

View File

@@ -1654,5 +1654,13 @@
"You cannot rename this element.": {
"category": "Error",
"code": 8000
},
"'yield' expressions are not currently supported.": {
"category": "Error",
"code": 9000
},
"'generators' are not currently supported.": {
"category": "Error",
"code": 9001
}
}

View File

@@ -4302,12 +4302,20 @@ module ts {
function checkFunctionDeclaration(node: FunctionLikeDeclaration) {
return checkAnyParsedSignature(node) ||
checkFunctionName(node.name) ||
checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false);
checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) ||
checkForGenerator(node);
}
function checkForGenerator(node: Node) {
if (node.flags & NodeFlags.Generator) {
return grammarErrorOnFirstToken(node, Diagnostics.generators_are_not_currently_supported);
}
}
function checkFunctionExpression(node: FunctionExpression) {
return checkAnyParsedSignature(node) ||
checkFunctionName(node.name);
checkFunctionName(node.name) ||
checkForGenerator(node);
}
function checkFunctionName(name: Node) {
@@ -4386,7 +4394,8 @@ module ts {
function checkMethod(node: MethodDeclaration) {
return checkAnyParsedSignature(node) ||
checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) ||
(node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional));
(node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)) ||
checkForGenerator(node);
}
function checkForBodyInAmbientContext(body: Block | Expression, isConstructor: boolean): boolean {
@@ -4732,7 +4741,8 @@ module ts {
}
function checkPropertyAssignment(node: PropertyDeclaration) {
return checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional);
return checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional) ||
checkForGenerator(node);
}
function checkForInvalidQuestionMark(node: Declaration, message: DiagnosticMessage) {
@@ -4963,6 +4973,7 @@ module ts {
if (!(node.parserContextFlags & ParserContextFlags.Yield)) {
return grammarErrorOnFirstToken(node, Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
}
return grammarErrorOnFirstToken(node, Diagnostics.yield_expressions_are_not_currently_supported);
}
}