Simplify syntaxtree.
This commit is contained in:
parent
01ce9f8cc8
commit
1ac2f818b3
|
@ -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);
}
|
||||
else if (parameter.equalsValueClause) {
|
||||
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_an_initializer);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_an_initializer);
}
|
||||
else if (!parameter.typeAnnotation) {
|
||||
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_must_have_a_type_annotation);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_must_have_a_type_annotation);
}
|
||||
else if (parameter.typeAnnotation.type.kind !== SyntaxKind.StringKeyword &&
|
||||
parameter.typeAnnotation.type.kind !== SyntaxKind.NumberKeyword) {
|
||||
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_type_must_be_string_or_number);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_type_must_be_string_or_number);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -383,28 +361,20 @@ module TypeScript {
|
|||
|
||||
if (heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ExtendsKeyword) {
|
||||
if (seenExtendsClause) {
|
||||
this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
}
|
||||
|
||||
if (seenImplementsClause) {
|
||||
this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_must_precede_implements_clause);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_must_precede_implements_clause);
}
|
||||
|
||||
if (nonSeparatorCount(heritageClause.typeNames) > 1) {
|
||||
this.pushDiagnostic(heritageClause, DiagnosticCode.Classes_can_only_extend_a_single_class);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(heritageClause, DiagnosticCode.Classes_can_only_extend_a_single_class);
}
|
||||
|
||||
seenExtendsClause = true;
|
||||
}
|
||||
else {
|
||||
Debug.assert(heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ImplementsKeyword);
|
||||
if (seenImplementsClause) {
|
||||
this.pushDiagnostic(heritageClause, DiagnosticCode.implements_clause_already_seen);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(heritageClause, DiagnosticCode.implements_clause_already_seen);
}
|
||||
|
||||
seenImplementsClause = true;
|
||||
}
|
||||
|
@ -419,9 +389,7 @@ module TypeScript {
|
|||
var declareToken = SyntaxUtilities.getToken(modifiers, SyntaxKind.DeclareKeyword);
|
||||
|
||||
if (declareToken) {
|
||||
this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -432,9 +400,7 @@ module TypeScript {
|
|||
// We're at the top level in a declaration file, a 'declare' modifiers is required
|
||||
// on most module elements.
|
||||
if (!SyntaxUtilities.containsToken(modifiers, SyntaxKind.DeclareKeyword)) {
|
||||
this.pushDiagnostic(reportToken, DiagnosticCode.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(reportToken, DiagnosticCode.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,17 +429,13 @@ module TypeScript {
|
|||
|
||||
if (heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ExtendsKeyword) {
|
||||
if (seenExtendsClause) {
|
||||
this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(heritageClause, DiagnosticCode.extends_clause_already_seen);
}
|
||||
|
||||
seenExtendsClause = true;
|
||||
}
|
||||
else {
|
||||
Debug.assert(heritageClause.extendsOrImplementsKeyword.kind === SyntaxKind.ImplementsKeyword);
|
||||
this.pushDiagnostic(heritageClause, DiagnosticCode.Interface_declaration_cannot_have_implements_clause);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(heritageClause, DiagnosticCode.Interface_declaration_cannot_have_implements_clause);
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -483,9 +445,7 @@ module TypeScript {
|
|||
for (var i = 0, n = modifiers.length; i < n; i++) {
|
||||
var modifier = modifiers[i];
|
||||
if (modifier.kind === SyntaxKind.DeclareKeyword) {
|
||||
this.pushDiagnostic(modifier,
|
||||
DiagnosticCode.A_declare_modifier_cannot_be_used_with_an_interface_declaration);
|
||||
return true;
|
||||
return this.pushDiagnostic(modifier, DiagnosticCode.A_declare_modifier_cannot_be_used_with_an_interface_declaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -619,9 +579,7 @@ module TypeScript {
|
|||
|
||||
private checkGetAccessorParameter(node: GetAccessorSyntax): boolean {
|
||||
if (node.callSignature.parameterList.parameters.length !== 0) {
|
||||
this.pushDiagnostic(node.propertyName, DiagnosticCode.get_accessor_cannot_have_parameters);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.propertyName, DiagnosticCode.get_accessor_cannot_have_parameters);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -636,18 +594,14 @@ module TypeScript {
|
|||
|
||||
private checkIndexMemberModifiers(node: IndexMemberDeclarationSyntax): boolean {
|
||||
if (node.modifiers.length > 0) {
|
||||
this.pushDiagnostic(node.modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private checkEcmaScriptVersionIsAtLeast(reportToken: ISyntaxToken, languageVersion: ts.ScriptTarget, diagnosticKey: string): boolean {
|
||||
if (this.syntaxTree.languageVersion() < languageVersion) {
|
||||
this.pushDiagnostic(reportToken, diagnosticKey);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(reportToken, diagnosticKey);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -677,40 +631,30 @@ module TypeScript {
|
|||
|
||||
private checkForSemicolonInsteadOfBlock(parent: ISyntaxNode, node: BlockSyntax | ExpressionBody | ISyntaxToken): boolean {
|
||||
if (node === undefined) {
|
||||
this.pushDiagnosticAt(fullEnd(parent), 0, DiagnosticCode._0_expected, ["{"]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnosticAt(fullEnd(parent), 0, DiagnosticCode._0_expected, ["{"]);
}
|
||||
else if (node.kind === SyntaxKind.SemicolonToken) {
|
||||
this.pushDiagnostic(node, DiagnosticCode._0_expected, ["{"]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node, DiagnosticCode._0_expected, ["{"]);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private checkForDisallowedSetAccessorTypeAnnotation(accessor: SetAccessorSyntax): boolean {
|
||||
if (accessor.callSignature.typeAnnotation) {
|
||||
this.pushDiagnostic(accessor.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_set_accessor);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(accessor.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_set_accessor);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private checkForDisallowedAccessorTypeParameters(callSignature: CallSignatureSyntax): boolean {
|
||||
if (callSignature.typeParameterList) {
|
||||
this.pushDiagnostic(callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_an_accessor);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_an_accessor);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private checkForAccessorDeclarationInAmbientContext(accessor: ISyntaxNode): boolean {
|
||||
if (this.inAmbientDeclaration) {
|
||||
this.pushDiagnostic(accessor, DiagnosticCode.Accessors_are_not_allowed_in_ambient_contexts);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(accessor, DiagnosticCode.Accessors_are_not_allowed_in_ambient_contexts);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -718,26 +662,18 @@ module TypeScript {
|
|||
private checkSetAccessorParameter(node: SetAccessorSyntax): boolean {
|
||||
var parameters = node.callSignature.parameterList.parameters;
|
||||
if (nonSeparatorCount(parameters) !== 1) {
|
||||
this.pushDiagnostic(node.propertyName, DiagnosticCode.set_accessor_must_have_exactly_one_parameter);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.propertyName, DiagnosticCode.set_accessor_must_have_exactly_one_parameter);
}
|
||||
|
||||
var parameter = nonSeparatorAt(parameters, 0);
|
||||
|
||||
if (parameter.questionToken) {
|
||||
this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_parameter_cannot_be_optional);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_parameter_cannot_be_optional);
}
|
||||
|
||||
if (parameter.equalsValueClause) {
|
||||
this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_parameter_cannot_have_an_initializer);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_parameter_cannot_have_an_initializer);
}
|
||||
|
||||
if (parameter.dotDotDotToken) {
|
||||
this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_cannot_have_rest_parameter);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(parameter, DiagnosticCode.set_accessor_cannot_have_rest_parameter);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -800,13 +736,11 @@ module TypeScript {
|
|||
// new Foo[]
|
||||
var start = TypeScript.start(node.openBracketToken);
|
||||
var end = TypeScript.fullEnd(node.closeBracketToken);
|
||||
this.pushDiagnosticAt(start, end - start, DiagnosticCode.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
|
||||
return this.pushDiagnosticAt(start, end - start, DiagnosticCode.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
|
||||
}
|
||||
else {
|
||||
this.pushDiagnostic(node.closeBracketToken, DiagnosticCode.Expression_expected);
|
||||
return this.pushDiagnostic(node.closeBracketToken, DiagnosticCode.Expression_expected);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -834,9 +768,7 @@ module TypeScript {
|
|||
var enumElement = nonSeparatorAt(node.enumElements, i);
|
||||
|
||||
if (!enumElement.equalsValueClause && previousValueWasComputed) {
|
||||
this.pushDiagnostic(enumElement, DiagnosticCode.Enum_member_must_have_initializer);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(enumElement, DiagnosticCode.Enum_member_must_have_initializer);
}
|
||||
|
||||
if (enumElement.equalsValueClause) {
|
||||
var value = enumElement.equalsValueClause.value;
|
||||
|
@ -881,9 +813,7 @@ module TypeScript {
|
|||
var modifier = modifiers[i];
|
||||
if (SyntaxFacts.isAccessibilityModifier(modifier.kind) ||
|
||||
modifier.kind === SyntaxKind.StaticKeyword) {
|
||||
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_module_element, [modifier.text()]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_module_element, [modifier.text()]);
}
|
||||
|
||||
if (modifier.kind === SyntaxKind.DeclareKeyword) {
|
||||
if (seenDeclareModifier) {
|
||||
|
@ -952,9 +882,7 @@ module TypeScript {
|
|||
var declareToken = SyntaxUtilities.getToken(modifiers, SyntaxKind.DeclareKeyword);
|
||||
|
||||
if (declareToken) {
|
||||
this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_with_an_import_declaration);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(declareToken, DiagnosticCode.A_declare_modifier_cannot_be_used_with_an_import_declaration);
}
|
||||
}
|
||||
|
||||
public visitImportDeclaration(node: ImportDeclarationSyntax): any {
|
||||
|
@ -999,9 +927,7 @@ module TypeScript {
|
|||
var child = node.moduleElements[i];
|
||||
|
||||
if (child.kind === SyntaxKind.ExportAssignment) {
|
||||
this.pushDiagnostic(child, DiagnosticCode.Export_assignment_cannot_be_used_in_internal_modules);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(child, DiagnosticCode.Export_assignment_cannot_be_used_in_internal_modules);
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1021,9 +947,7 @@ module TypeScript {
|
|||
|
||||
public checkForMalformedBlock(node: BlockSyntax): boolean {
|
||||
if (node.equalsGreaterThanToken || node.openBraceToken === undefined) {
|
||||
this.pushDiagnostic(firstToken(node), DiagnosticCode._0_expected, ["{"]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(firstToken(node), DiagnosticCode._0_expected, ["{"]);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1033,13 +957,11 @@ module TypeScript {
|
|||
// Provide a specialized message for a block as a statement versus the block as a
|
||||
// function body.
|
||||
if (node.parent.kind === SyntaxKind.List) {
|
||||
this.pushDiagnostic(firstToken(node), DiagnosticCode.Statements_are_not_allowed_in_ambient_contexts);
|
||||
return this.pushDiagnostic(firstToken(node), DiagnosticCode.Statements_are_not_allowed_in_ambient_contexts);
|
||||
}
|
||||
else {
|
||||
this.pushDiagnostic(firstToken(node), DiagnosticCode.A_function_implementation_cannot_be_declared_in_an_ambient_context);
|
||||
return this.pushDiagnostic(firstToken(node), DiagnosticCode.A_function_implementation_cannot_be_declared_in_an_ambient_context);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1047,9 +969,7 @@ module TypeScript {
|
|||
|
||||
private checkForStatementInAmbientContxt(node: IStatementSyntax): boolean {
|
||||
if (this.inAmbientDeclaration || this.syntaxTree.isDeclaration()) {
|
||||
this.pushDiagnostic(firstToken(node), DiagnosticCode.Statements_are_not_allowed_in_ambient_contexts);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(firstToken(node), DiagnosticCode.Statements_are_not_allowed_in_ambient_contexts);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1111,24 +1031,20 @@ module TypeScript {
|
|||
// unreachable label (as opposed to a non-existed label)
|
||||
var breakableLabels = this.getEnclosingLabels(node, /*breakable:*/ true, /*crossFunctions:*/ true);
|
||||
if (ArrayUtilities.any(breakableLabels, s => tokenValueText(s.identifier) === tokenValueText(node.identifier))) {
|
||||
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
}
|
||||
else {
|
||||
this.pushDiagnostic(node, DiagnosticCode.Jump_target_not_found);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.Jump_target_not_found);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (!this.inIterationStatement(node, /*crossFunctions:*/ false) && !this.inSwitchStatement(node)) {
|
||||
if (this.inIterationStatement(node, /*crossFunctions:*/ true)) {
|
||||
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
}
|
||||
else {
|
||||
this.pushDiagnostic(node, DiagnosticCode.break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1236,13 +1152,11 @@ module TypeScript {
|
|||
|
||||
if (!this.inIterationStatement(node, /*crossFunctions:*/ false)) {
|
||||
if (this.inIterationStatement(node, /*crossFunctions:*/ true)) {
|
||||
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
}
|
||||
else {
|
||||
this.pushDiagnostic(node, DiagnosticCode.continue_statement_can_only_be_used_within_an_enclosing_iteration_statement);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.continue_statement_can_only_be_used_within_an_enclosing_iteration_statement);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (node.identifier) {
|
||||
var continuableLabels = this.getEnclosingLabels(node, /*breakable:*/ false, /*crossFunctions:*/ false);
|
||||
|
@ -1255,13 +1169,11 @@ module TypeScript {
|
|||
var continuableLabels = this.getEnclosingLabels(node, /*breakable:*/ false, /*crossFunctions:*/ true);
|
||||
|
||||
if (ArrayUtilities.any(continuableLabels, s => tokenValueText(s.identifier) === tokenValueText(node.identifier))) {
|
||||
this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.Jump_target_cannot_cross_function_boundary);
|
||||
}
|
||||
else {
|
||||
this.pushDiagnostic(node, DiagnosticCode.Jump_target_not_found);
|
||||
return this.pushDiagnostic(node, DiagnosticCode.Jump_target_not_found);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1313,9 +1225,7 @@ module TypeScript {
|
|||
|
||||
private checkForInLeftHandSideExpression(node: ForInStatementSyntax): boolean {
|
||||
if (node.left.kind !== SyntaxKind.VariableDeclaration && !SyntaxUtilities.isLeftHandSizeExpression(node.left)) {
|
||||
this.pushDiagnostic(node.left, DiagnosticCode.Invalid_left_hand_side_in_for_in_statement);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.left, DiagnosticCode.Invalid_left_hand_side_in_for_in_statement);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1325,9 +1235,7 @@ module TypeScript {
|
|||
// allows a very restricted form. Specifically, there must be only a single Variable
|
||||
// Declarator in the Declaration.
|
||||
if (node.left.kind === SyntaxKind.VariableDeclaration && (<VariableDeclarationSyntax>node.left).variableDeclarators.length > 1) {
|
||||
this.pushDiagnostic(node.left, DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.left, DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1382,9 +1290,7 @@ module TypeScript {
|
|||
// It is invalid to have a label enclosed in a label of the same name.
|
||||
var matchingLabel = ArrayUtilities.firstOrDefault(breakableLabels, s => tokenValueText(s.identifier) === labelIdentifier);
|
||||
if (matchingLabel) {
|
||||
this.pushDiagnostic(node.identifier, DiagnosticCode.Duplicate_identifier_0, [labelIdentifier]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.identifier, DiagnosticCode.Duplicate_identifier_0, [labelIdentifier]);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1405,9 +1311,7 @@ module TypeScript {
|
|||
}
|
||||
}
|
||||
|
||||
this.pushDiagnostic(firstToken(node), DiagnosticCode.return_statement_must_be_contained_within_a_function_body);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(firstToken(node), DiagnosticCode.return_statement_must_be_contained_within_a_function_body);
}
|
||||
|
||||
public visitSwitchStatement(node: SwitchStatementSyntax): void {
|
||||
if (this.checkForStatementInAmbientContxt(node)) {
|
||||
|
@ -1428,9 +1332,7 @@ module TypeScript {
|
|||
|
||||
public checkForMissingThrowStatementExpression(node: ThrowStatementSyntax): boolean {
|
||||
if (node.expression === undefined) {
|
||||
this.pushDiagnosticAt(fullEnd(node.throwKeyword), 0, DiagnosticCode.Expression_expected);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnosticAt(fullEnd(node.throwKeyword), 0, DiagnosticCode.Expression_expected);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1462,9 +1364,7 @@ module TypeScript {
|
|||
|
||||
private checkForWithInStrictMode(node: WithStatementSyntax): boolean {
|
||||
if (parsedInStrictModeContext(node)) {
|
||||
this.pushDiagnostic(firstToken(node), DiagnosticCode.with_statements_are_not_allowed_in_strict_mode);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(firstToken(node), DiagnosticCode.with_statements_are_not_allowed_in_strict_mode);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1472,9 +1372,7 @@ module TypeScript {
|
|||
private checkForDisallowedModifiers(modifiers: ISyntaxToken[]): boolean {
|
||||
if (this.inBlock || this.inObjectLiteralExpression) {
|
||||
if (modifiers.length > 0) {
|
||||
this.pushDiagnostic(modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(modifiers[0], DiagnosticCode.Modifiers_cannot_appear_here);
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1510,9 +1408,7 @@ module TypeScript {
|
|||
|
||||
private checkForAsyncGenerator(asyncKeyword: ISyntaxToken, asterixToken: ISyntaxToken) {
|
||||
if (asyncKeyword && asterixToken) {
|
||||
this.pushDiagnostic(asyncKeyword, DiagnosticCode.A_generator_declaration_cannot_have_the_async_modifier);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(asyncKeyword, DiagnosticCode.A_generator_declaration_cannot_have_the_async_modifier);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1602,18 +1498,14 @@ module TypeScript {
|
|||
|
||||
private checkForDisallowedTemplatePropertyName(propertyName: IPropertyNameSyntax): boolean {
|
||||
if (propertyName.kind === SyntaxKind.NoSubstitutionTemplateToken) {
|
||||
this.pushDiagnostic(propertyName, DiagnosticCode.Template_literal_cannot_be_used_as_an_element_name);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(propertyName, DiagnosticCode.Template_literal_cannot_be_used_as_an_element_name);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private checkForDisallowedComputedPropertyName(propertyName: IPropertyNameSyntax): boolean {
|
||||
if (propertyName.kind === SyntaxKind.ComputedPropertyName) {
|
||||
this.pushDiagnostic(propertyName, DiagnosticCode.Computed_property_names_cannot_be_used_here);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(propertyName, DiagnosticCode.Computed_property_names_cannot_be_used_here);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1631,9 +1523,7 @@ module TypeScript {
|
|||
|
||||
private checkVariableDeclaratorInitializer(node: VariableDeclaratorSyntax): boolean {
|
||||
if (this.inAmbientDeclaration && node.equalsValueClause) {
|
||||
this.pushDiagnostic(firstToken(node.equalsValueClause.value), DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(firstToken(node.equalsValueClause.value), DiagnosticCode.Initializers_are_not_allowed_in_ambient_contexts);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1655,9 +1545,7 @@ module TypeScript {
|
|||
for (var i = 0, n = modifiers.length; i < n; i++) {
|
||||
var child = modifiers[i];
|
||||
if (child.kind !== SyntaxKind.PublicKeyword) {
|
||||
this.pushDiagnostic(child, DiagnosticCode._0_modifier_cannot_appear_on_a_constructor_declaration, [SyntaxFacts.getText(child.kind)]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(child, DiagnosticCode._0_modifier_cannot_appear_on_a_constructor_declaration, [SyntaxFacts.getText(child.kind)]);
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1665,18 +1553,14 @@ module TypeScript {
|
|||
|
||||
private checkConstructorTypeParameterList(node: ConstructorDeclarationSyntax): boolean {
|
||||
if (node.callSignature.typeParameterList) {
|
||||
this.pushDiagnostic(node.callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.callSignature.typeParameterList, DiagnosticCode.Type_parameters_cannot_appear_on_a_constructor_declaration);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private checkConstructorTypeAnnotation(node: ConstructorDeclarationSyntax): boolean {
|
||||
if (node.callSignature.typeAnnotation) {
|
||||
this.pushDiagnostic(node.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.callSignature.typeAnnotation, DiagnosticCode.Type_annotation_cannot_appear_on_a_constructor_declaration);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1717,9 +1601,7 @@ module TypeScript {
|
|||
private checkForDisallowedEvalOrArguments(node: ISyntaxNode, token: ISyntaxToken): boolean {
|
||||
if (token) {
|
||||
if (parsedInStrictModeContext(node) && this.isEvalOrArguments(token)) {
|
||||
this.pushDiagnostic(token, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(token)]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(token, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(token)]);
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1764,9 +1646,7 @@ module TypeScript {
|
|||
|
||||
private checkIllegalAssignment(node: BinaryExpressionSyntax): boolean {
|
||||
if (parsedInStrictModeContext(node) && SyntaxFacts.isAssignmentOperatorToken(node.operatorToken.kind) && this.isEvalOrArguments(node.left)) {
|
||||
this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.left)]);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.left)]);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1796,9 +1676,7 @@ module TypeScript {
|
|||
|
||||
private checkConstraintType(node: ConstraintSyntax): boolean {
|
||||
if (!SyntaxFacts.isType(node.typeOrExpression.kind)) {
|
||||
this.pushDiagnostic(node.typeOrExpression, DiagnosticCode.Type_expected);
|
||||
return true;
|
||||
}
|
||||
return this.pushDiagnostic(node.typeOrExpression, DiagnosticCode.Type_expected);
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue