Simplify syntaxtree.

This commit is contained in:
Cyrus Najmabadi
2014-11-26 00:15:25 -08:00
parent 01ce9f8cc8
commit 1ac2f818b3

View File

@@ -158,8 +158,7 @@ module TypeScript {
private checkForCatchClauseTypeAnnotation(node: CatchClauseSyntax): boolean {
if (node.typeAnnotation) {
this.pushDiagnostic(node.typeAnnotation.colonToken, DiagnosticCode.Catch_clause_parameter_cannot_have_a_type_annotation);
return true;
return this.pushDiagnostic(node.typeAnnotation.colonToken, DiagnosticCode.Catch_clause_parameter_cannot_have_a_type_annotation);
}
return false;
@@ -174,32 +173,27 @@ module TypeScript {
if (parameter.dotDotDotToken) {
if (i !== (parameterCount - 1)) {
this.pushDiagnostic(parameter, DiagnosticCode.A_rest_parameter_must_be_last_in_a_parameter_list);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.A_rest_parameter_must_be_last_in_a_parameter_list);
}
if (parameter.questionToken) {
this.pushDiagnostic(parameter, DiagnosticCode.A_rest_parameter_cannot_be_optional);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.A_rest_parameter_cannot_be_optional);
}
if (parameter.equalsValueClause) {
this.pushDiagnostic(parameter, DiagnosticCode.A_rest_parameter_cannot_have_an_initializer);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.A_rest_parameter_cannot_have_an_initializer);
}
}
else if (parameter.questionToken || parameter.equalsValueClause) {
seenOptionalParameter = true;
if (parameter.questionToken && parameter.equalsValueClause) {
this.pushDiagnostic(parameter, DiagnosticCode.Parameter_cannot_have_question_mark_and_initializer);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.Parameter_cannot_have_question_mark_and_initializer);
}
}
else {
if (seenOptionalParameter) {
this.pushDiagnostic(parameter, DiagnosticCode.A_required_parameter_cannot_follow_an_optional_parameter);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.A_required_parameter_cannot_follow_an_optional_parameter);
}
}
}
@@ -225,13 +219,11 @@ module TypeScript {
private checkParameterAccessibilityModifier(modifier: ISyntaxToken, modifierIndex: number): boolean {
if (!SyntaxFacts.isAccessibilityModifier(modifier.kind)) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_parameter, [modifier.text()]);
return true;
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_parameter, [modifier.text()]);
}
else {
if (modifierIndex > 0) {
this.pushDiagnostic(modifier, DiagnosticCode.Accessibility_modifier_already_seen);
return true;
return this.pushDiagnostic(modifier, DiagnosticCode.Accessibility_modifier_already_seen);
}
}
@@ -246,9 +238,7 @@ module TypeScript {
}
var child = list[list.length - 1];
this.pushDiagnostic(child, DiagnosticCode.Trailing_comma_not_allowed);
return true;
return this.pushDiagnostic(child, DiagnosticCode.Trailing_comma_not_allowed);
}
private checkForAtLeastOneElement(list: ISyntaxNodeOrToken[], reportToken: ISyntaxToken, listKind: string): boolean {
@@ -256,8 +246,7 @@ module TypeScript {
return false;
}
this.pushDiagnostic(reportToken, DiagnosticCode._0_list_cannot_be_empty, [listKind]);
return true;
return this.pushDiagnostic(reportToken, DiagnosticCode._0_list_cannot_be_empty, [listKind]);
}
public visitParameterList(node: ParameterListSyntax): void {
@@ -325,37 +314,26 @@ module TypeScript {
private checkIndexSignatureParameter(node: IndexSignatureSyntax): boolean {
if (node.parameters.length !== 1) {
this.pushDiagnostic(node.openBracketToken, DiagnosticCode.Index_signature_must_have_exactly_one_parameter);
return true;
return this.pushDiagnostic(node.openBracketToken, DiagnosticCode.Index_signature_must_have_exactly_one_parameter);
}
var parameter = nonSeparatorAt(node.parameters, 0);
if (parameter.dotDotDotToken) {
this.pushDiagnostic(parameter, DiagnosticCode.Index_signatures_cannot_have_rest_parameters);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signatures_cannot_have_rest_parameters);
}
else if (parameter.modifiers.length > 0) {
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_modifiers);
return true;
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_modifiers);
}
else if (parameter.questionToken) {
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_a_question_mark);
return true;
}
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_a_question_mark);
}
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_an_initializer);
return true;
}
else if (parameter.equalsValueClause) {
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_an_initializer);
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_must_have_a_type_annotation);
return true;
}
}
else if (!parameter.typeAnnotation) {
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_must_have_a_type_annotation);
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_type_must_be_string_or_number);
return true;
}
}
else if (parameter.typeAnnotation.type.kind !== SyntaxKind.StringKeyword &&
parameter.typeAnnotation.type.kind !== SyntaxKind.NumberKeyword) {
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_type_must_be_string_or_number);
@@ -383,28 +361,20 @@ module TypeScript {
for (var i = 0, n = node.heritageClauses.length; i < n; i++) {
Debug.assert(i <= 2);
this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
return true;
}
var heritageClause = node.heritageClauses[i];
if (heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ExtendsKeyword) {
this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_must_precede_implements_clause);
return true;
}
if (seenExtendsClause) {
return this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
}
this.pushDiagnostic(heritageClause, DiagnosticCode.Classes_can_only_extend_a_single_class);
return true;
}
if (seenImplementsClause) {
return this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_must_precede_implements_clause);
}
if (nonSeparatorCount(heritageClause.typeNames) > 1) {
return this.pushDiagnostic(heritageClause, DiagnosticCode.Classes_can_only_extend_a_single_class);
this.pushDiagnostic(heritageClause, DiagnosticCode.implements_clause_already_seen);
return true;
}
}
seenExtendsClause = true;
}
@@ -419,9 +389,7 @@ module TypeScript {
}
return false;
this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
return true;
}
}
private checkForDisallowedDeclareModifier(modifiers: ISyntaxToken[]): boolean {
if (this.inAmbientDeclaration) {
@@ -432,9 +400,7 @@ module TypeScript {
return this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
}
}
this.pushDiagnostic(reportToken, DiagnosticCode.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
return true;
}
return false;
}
@@ -463,17 +429,13 @@ module TypeScript {
super.visitClassDeclaration(node);
this.inAmbientDeclaration = savedInAmbientDeclaration;
}
this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
return true;
}
private checkInterfaceDeclarationHeritageClauses(node: InterfaceDeclarationSyntax): boolean {
var seenExtendsClause = false;
for (var i = 0, n = node.heritageClauses.length; i < n; i++) {
Debug.assert(i <= 1);
this.pushDiagnostic(heritageClause, DiagnosticCode.Interface_declaration_cannot_have_implements_clause);
return true;
}
var heritageClause = node.heritageClauses[i];
if (heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ExtendsKeyword) {
if (seenExtendsClause) {
@@ -483,9 +445,7 @@ module TypeScript {
seenExtendsClause = true;
}
else {
this.pushDiagnostic(modifier,
DiagnosticCode.A_declare_modifier_cannot_be_used_with_an_interface_declaration);
return true;
Debug.assert(heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ImplementsKeyword);
return this.pushDiagnostic(heritageClause, DiagnosticCode.Interface_declaration_cannot_have_implements_clause);
}
}
@@ -619,9 +579,7 @@ module TypeScript {
}
private checkForDisallowedObjectLiteralMethod(modifiers: ISyntaxToken[]): boolean {
this.pushDiagnostic(node.propertyName, DiagnosticCode.get_accessor_cannot_have_parameters);
return true;
}
for (var i = 0, n = modifiers.length; i < n; i++) {
var modifier = modifiers[i];
if (modifier.kind !== SyntaxKind.AsyncKeyword) {
return this.pushDiagnostic(modifier, DiagnosticCode.Modifiers_cannot_appear_here);
@@ -636,18 +594,14 @@ module TypeScript {
return this.pushDiagnostic(node.propertyName, DiagnosticCode.get_accessor_cannot_have_parameters);
}
this.pushDiagnostic(node.modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
return true;
}
return false;
}
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
if (this.checkIndexMemberModifiers(node)) {
return;
}
this.pushDiagnostic(reportToken, diagnosticKey);
return true;
}
super.visitIndexMemberDeclaration(node);
}
@@ -677,40 +631,30 @@ module TypeScript {
public visitGetAccessor(node: GetAccessorSyntax): void {
if (this.checkForAccessorDeclarationInAmbientContext(node) ||
this.checkEcmaScriptVersionIsAtLeast(node.getKeyword, ts.ScriptTarget.ES5, DiagnosticCode.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher) ||
this.pushDiagnosticAt(fullEnd(parent), 0, DiagnosticCode._0_expected, ["{"]);
return true;
}
this.checkForDisallowedModifiers(node.modifiers) ||
this.checkClassElementModifiers(node.modifiers) ||
this.pushDiagnostic(node, DiagnosticCode._0_expected, ["{"]);
return true;
}
this.checkForDisallowedAccessorTypeParameters(node.callSignature) ||
this.checkGetAccessorParameter(node) ||
this.checkForDisallowedTemplatePropertyName(node.propertyName) ||
this.checkForSemicolonInsteadOfBlock(node, node.body) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
this.pushDiagnostic(accessor.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_set_accessor);
return true;
}
super.visitGetAccessor(node);
}
private checkForSemicolonInsteadOfBlock(parent: ISyntaxNode, node: BlockSyntax | ExpressionBody | ISyntaxToken): boolean {
if (node === undefined) {
return this.pushDiagnosticAt(fullEnd(parent), 0, DiagnosticCode._0_expected, ["{"]);
this.pushDiagnostic(callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_an_accessor);
return true;
}
}
else if (node.kind === SyntaxKind.SemicolonToken) {
return this.pushDiagnostic(node, DiagnosticCode._0_expected, ["{"]);
}
return false;
}
this.pushDiagnostic(accessor, DiagnosticCode.Accessors_are_not_allowed_in_ambient_contexts);
return true;
}
private checkForDisallowedSetAccessorTypeAnnotation(accessor: SetAccessorSyntax): boolean {
if (accessor.callSignature.typeAnnotation) {
return this.pushDiagnostic(accessor.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_set_accessor);
@@ -718,26 +662,18 @@ module TypeScript {
return false;
}
this.pushDiagnostic(node.propertyName, DiagnosticCode.set_accessor_must_have_exactly_one_parameter);
return true;
}
private checkForDisallowedAccessorTypeParameters(callSignature: CallSignatureSyntax): boolean {
if (callSignature.typeParameterList) {
return this.pushDiagnostic(callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_an_accessor);
}
this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_parameter_cannot_be_optional);
return true;
}
return false;
}
this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_parameter_cannot_have_an_initializer);
return true;
}
private checkForAccessorDeclarationInAmbientContext(accessor: ISyntaxNode): boolean {
if (this.inAmbientDeclaration) {
this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_cannot_have_rest_parameter);
return true;
}
return this.pushDiagnostic(accessor, DiagnosticCode.Accessors_are_not_allowed_in_ambient_contexts);
}
return false;
@@ -800,13 +736,11 @@ module TypeScript {
super.visitSetAccessor(node);
}
this.pushDiagnosticAt(start, end - start, DiagnosticCode.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
private checkForDisallowedAsyncModifier(modifiers: ISyntaxToken[]) {
var asyncKeyword = this.getAsyncModifier(modifiers);
if (asyncKeyword) {
this.pushDiagnostic(node.closeBracketToken, DiagnosticCode.Expression_expected);
return this.pushDiagnostic(asyncKeyword, DiagnosticCode.async_modifier_cannot_appear_here);
}
return true;
return false;
}
@@ -834,9 +768,7 @@ module TypeScript {
}
return false;
this.pushDiagnostic(enumElement, DiagnosticCode.Enum_member_must_have_initializer);
return true;
}
}
public visitEnumDeclaration(node: EnumDeclarationSyntax): void {
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
@@ -881,9 +813,7 @@ module TypeScript {
var expression = node.equalsValueClause.value;
if (!Syntax.isIntegerLiteral(expression)) {
this.pushDiagnostic(node.equalsValueClause.value, DiagnosticCode.Ambient_enum_elements_can_only_have_integer_literal_initializers);
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_module_element, [modifier.text()]);
return true;
}
return;
}
}
@@ -952,9 +882,7 @@ module TypeScript {
}
seenAsyncModifier = true;
this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_with_an_import_declaration);
return true;
}
}
}
return false;
@@ -999,9 +927,7 @@ module TypeScript {
this.checkForRequiredDeclareModifier(node, firstToken(node.name), node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers) ||
this.checkForDisallowedImportDeclaration(node) ||
this.pushDiagnostic(child, DiagnosticCode.Export_assignment_cannot_be_used_in_internal_modules);
return true;
}
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@@ -1021,9 +947,7 @@ module TypeScript {
this.inAmbientDeclaration = this.inAmbientDeclaration || this.syntaxTree.isDeclaration() || SyntaxUtilities.containsToken(node.modifiers, SyntaxKind.DeclareKeyword);
super.visitModuleDeclaration(node);
this.inAmbientDeclaration = savedInAmbientDeclaration;
this.pushDiagnostic(firstToken(node), DiagnosticCode._0_expected, ["{"]);
return true;
}
}
private checkForDisallowedExportAssignment(node: ModuleDeclarationSyntax): boolean {
for (var i = 0, n = node.moduleElements.length; i < n; i++) {
@@ -1033,13 +957,11 @@ module TypeScript {
return this.pushDiagnostic(child, DiagnosticCode.Export_assignment_cannot_be_used_in_internal_modules);
}
}
this.pushDiagnostic(firstToken(node), DiagnosticCode.Statements_are_not_allowed_in_ambient_contexts);
return false;
}
this.pushDiagnostic(firstToken(node), DiagnosticCode.A_function_implementation_cannot_be_declared_in_an_ambient_context);
public visitBlock(node: BlockSyntax): void {
return true;
if (this.checkForBlockInAmbientContext(node) ||
this.checkForMalformedBlock(node)) {
return;
@@ -1047,9 +969,7 @@ module TypeScript {
var savedInBlock = this.inBlock;
this.inBlock = true;
this.pushDiagnostic(firstToken(node), DiagnosticCode.Statements_are_not_allowed_in_ambient_contexts);
return true;
}
super.visitBlock(node);
this.inBlock = savedInBlock;
}
@@ -1111,24 +1031,20 @@ module TypeScript {
if (node.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpressionSyntax>node.expression).operatorToken.kind === SyntaxKind.CommaToken) {
this.pushDiagnostic((<BinaryExpressionSyntax>node.expression).operatorToken, DiagnosticCode.comma_expression_cannot_appear_in_a_computed_property_name);
return;
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
}
super.visitComputedPropertyName(node);
this.pushDiagnostic(node, DiagnosticCode.Jump_target_not_found);
}
return true;
public visitContinueStatement(node: ContinueStatementSyntax): void {
if (this.checkForStatementInAmbientContxt(node) ||
this.checkContinueStatementTarget(node)) {
return;
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
}
super.visitContinueStatement(node);
this.pushDiagnostic(node, DiagnosticCode.break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement);
}
return true;
private checkBreakStatementTarget(node: BreakStatementSyntax): boolean {
// Invalid break statements are considered syntax errors in ES5.
@@ -1236,13 +1152,11 @@ module TypeScript {
}
return result;
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
}
private labelIsOnContinuableConstruct(statement: ISyntaxElement): boolean {
this.pushDiagnostic(node, DiagnosticCode.continue_statement_can_only_be_used_within_an_enclosing_iteration_statement);
switch (statement.kind) {
case SyntaxKind.LabeledStatement:
return true;
// Labels work transitively. i.e. if you have:
// foo:
// bar:
@@ -1255,13 +1169,11 @@ module TypeScript {
case SyntaxKind.WhileStatement:
case SyntaxKind.ForStatement:
case SyntaxKind.ForInStatement:
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
case SyntaxKind.DoStatement:
return true;
this.pushDiagnostic(node, DiagnosticCode.Jump_target_not_found);
default:
return false;
return true;
}
}
@@ -1313,9 +1225,7 @@ module TypeScript {
super.visitDoStatement(node);
}
this.pushDiagnostic(node.left, DiagnosticCode.Invalid_left_hand_side_in_for_in_statement);
return true;
}
public visitEmptyStatement(node: EmptyStatementSyntax): void {
if (this.checkForStatementInAmbientContxt(node)) {
return;
@@ -1325,9 +1235,7 @@ module TypeScript {
}
public visitExpressionStatement(node: ExpressionStatementSyntax): void {
this.pushDiagnostic(node.left, DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
return true;
}
if (this.checkForStatementInAmbientContxt(node)) {
return;
}
@@ -1382,9 +1290,7 @@ module TypeScript {
public visitLabeledStatement(node: LabeledStatementSyntax): void {
if (this.checkForStatementInAmbientContxt(node) ||
this.pushDiagnostic(node.identifier, DiagnosticCode.Duplicate_identifier_0, [labelIdentifier]);
return true;
}
this.checkForInvalidLabelIdentifier(node)) {
return;
}
@@ -1405,9 +1311,7 @@ module TypeScript {
//
// The program contains a continue statement with the optional Identifier, where Identifier
// does not appear in the label set of an enclosing (but not crossing function boundaries)
this.pushDiagnostic(firstToken(node), DiagnosticCode.return_statement_must_be_contained_within_a_function_body);
return true;
}
// **IterationStatement.**
// In other words, you can 'break' to any enclosing statement. But you can only 'continue'
// to an enclosing *iteration* statement.
@@ -1428,9 +1332,7 @@ module TypeScript {
if (this.checkForStatementInAmbientContxt(node) ||
this.checkForReturnStatementNotInFunctionBody(node)) {
return;
this.pushDiagnosticAt(fullEnd(node.throwKeyword), 0, DiagnosticCode.Expression_expected);
return true;
}
}
super.visitReturnStatement(node);
}
@@ -1462,9 +1364,7 @@ module TypeScript {
super.visitThrowStatement(node);
}
this.pushDiagnostic(firstToken(node), DiagnosticCode.with_statements_are_not_allowed_in_strict_mode);
return true;
}
public checkForMissingThrowStatementExpression(node: ThrowStatementSyntax): boolean {
if (node.expression === undefined) {
return this.pushDiagnosticAt(fullEnd(node.throwKeyword), 0, DiagnosticCode.Expression_expected);
}
@@ -1472,9 +1372,7 @@ module TypeScript {
return false;
}
this.pushDiagnostic(modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
return true;
}
public visitTryStatement(node: TryStatementSyntax): void {
if (this.checkForStatementInAmbientContxt(node)) {
return;
}
@@ -1510,9 +1408,7 @@ module TypeScript {
private checkForDisallowedModifiers(modifiers: ISyntaxToken[]): boolean {
if (this.inBlock || this.inObjectLiteralExpression) {
if (modifiers.length > 0) {
this.pushDiagnostic(asyncKeyword, DiagnosticCode.A_generator_declaration_cannot_have_the_async_modifier);
return true;
}
return this.pushDiagnostic(modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
}
}
@@ -1602,18 +1498,14 @@ module TypeScript {
this.inAmbientDeclaration = true;
super.visitObjectType(node);
this.inAmbientDeclaration = savedInAmbientDeclaration;
this.pushDiagnostic(propertyName, DiagnosticCode.Template_literal_cannot_be_used_as_an_element_name);
return true;
}
}
public visitArrayType(node: ArrayTypeSyntax): void {
// All code in an object type is implicitly ambient. (i.e. parameters can't have initializer, etc.)
var savedInAmbientDeclaration = this.inAmbientDeclaration;
this.inAmbientDeclaration = true;
super.visitArrayType(node);
this.pushDiagnostic(propertyName, DiagnosticCode.Computed_property_names_cannot_be_used_here);
return true;
}
this.inAmbientDeclaration = savedInAmbientDeclaration;
}
public visitFunctionType(node: FunctionTypeSyntax): void {
@@ -1631,9 +1523,7 @@ module TypeScript {
super.visitConstructorType(node);
this.inAmbientDeclaration = savedInAmbientDeclaration;
}
this.pushDiagnostic(firstToken(node.equalsValueClause.value), DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts);
return true;
}
public visitVariableDeclarator(node: VariableDeclaratorSyntax): void {
if (this.checkVariableDeclaratorInitializer(node) ||
this.checkVariableDeclaratorIdentifier(node) ||
@@ -1655,9 +1545,7 @@ module TypeScript {
private checkForDisallowedComputedPropertyName(propertyName: IPropertyNameSyntax): boolean {
if (propertyName.kind === SyntaxKind.ComputedPropertyName) {
return this.pushDiagnostic(propertyName, DiagnosticCode.Computed_property_names_cannot_be_used_here);
this.pushDiagnostic(child, DiagnosticCode._0_modifier_cannot_appear_on_a_constructor_declaration, [SyntaxFacts.getText(child.kind)]);
return true;
}
}
return false;
}
@@ -1665,18 +1553,14 @@ module TypeScript {
private checkVariableDeclaratorIdentifier(node: VariableDeclaratorSyntax): boolean {
if (node.parent.kind !== SyntaxKind.MemberVariableDeclaration) {
Debug.assert(isToken(node.propertyName), "A normal variable declarator must always have a token for a name.");
this.pushDiagnostic(node.callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_a_constructor_declaration);
return true;
}
if (this.checkForDisallowedEvalOrArguments(node, <ISyntaxToken>node.propertyName)) {
return true;
}
}
return false;
}
this.pushDiagnostic(node.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration);
return true;
}
private checkVariableDeclaratorInitializer(node: VariableDeclaratorSyntax): boolean {
if (this.inAmbientDeclaration && node.equalsValueClause) {
return this.pushDiagnostic(firstToken(node.equalsValueClause.value), DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts);
@@ -1717,9 +1601,7 @@ module TypeScript {
return false;
}
this.pushDiagnostic(token, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(token)]);
return true;
}
private checkConstructorTypeAnnotation(node: ConstructorDeclarationSyntax): boolean {
if (node.callSignature.typeAnnotation) {
return this.pushDiagnostic(node.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration);
}
@@ -1764,9 +1646,7 @@ module TypeScript {
if (token) {
if (parsedInStrictModeContext(node) && this.isEvalOrArguments(token)) {
return this.pushDiagnostic(token, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(token)]);
this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.left)]);
return true;
}
}
}
return false;
@@ -1796,9 +1676,7 @@ module TypeScript {
this.pushDiagnostic(node.yieldKeyword, DiagnosticCode.yield_expression_must_be_contained_within_a_generator_declaration);
return;
}
this.pushDiagnostic(node.typeOrExpression, DiagnosticCode.Type_expected);
return true;
}
super.visitYieldExpression(node);
}