From 291b46826240b98278cdf3e813bcbe033339ab3f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 16 Dec 2014 23:22:46 -0800 Subject: [PATCH] Update LKG. --- bin/tsc.js | 2306 +++++++++++++------------- bin/typescript.d.ts | 8 +- bin/typescriptServices.d.ts | 8 +- bin/typescriptServices.js | 2306 +++++++++++++------------- bin/typescriptServices_internal.d.ts | 261 +++ bin/typescript_internal.d.ts | 261 +++ 6 files changed, 2770 insertions(+), 2380 deletions(-) create mode 100644 bin/typescriptServices_internal.d.ts create mode 100644 bin/typescript_internal.d.ts diff --git a/bin/tsc.js b/bin/tsc.js index ff98a7db289..e1b93961fc6 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -804,89 +804,87 @@ var ts; ts.Diagnostics = { Unterminated_string_literal: { code: 1002, category: 1 /* Error */, key: "Unterminated string literal." }, Identifier_expected: { code: 1003, category: 1 /* Error */, key: "Identifier expected." }, - _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected." }, + _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected.", isEarly: true }, A_file_cannot_have_a_reference_to_itself: { code: 1006, category: 1 /* Error */, key: "A file cannot have a reference to itself." }, - Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed." }, + Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed.", isEarly: true }, Asterisk_Slash_expected: { code: 1010, category: 1 /* Error */, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1 /* Error */, key: "Unexpected token." }, - Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1 /* Error */, key: "Catch clause parameter cannot have a type annotation." }, - A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1 /* Error */, key: "A rest parameter must be last in a parameter list." }, - Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1 /* Error */, key: "Parameter cannot have question mark and initializer." }, - A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1 /* Error */, key: "A required parameter cannot follow an optional parameter." }, - An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: 1 /* Error */, key: "An index signature cannot have a rest parameter." }, - An_index_signature_parameter_cannot_have_an_accessibility_modifier: { code: 1018, category: 1 /* Error */, key: "An index signature parameter cannot have an accessibility modifier." }, - An_index_signature_parameter_cannot_have_a_question_mark: { code: 1019, category: 1 /* Error */, key: "An index signature parameter cannot have a question mark." }, - An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: 1 /* Error */, key: "An index signature parameter cannot have an initializer." }, - An_index_signature_must_have_a_type_annotation: { code: 1021, category: 1 /* Error */, key: "An index signature must have a type annotation." }, - An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: 1 /* Error */, key: "An index signature parameter must have a type annotation." }, - An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: 1 /* Error */, key: "An index signature parameter type must be 'string' or 'number'." }, + Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1 /* Error */, key: "Catch clause parameter cannot have a type annotation.", isEarly: true }, + A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1 /* Error */, key: "A rest parameter must be last in a parameter list.", isEarly: true }, + Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1 /* Error */, key: "Parameter cannot have question mark and initializer.", isEarly: true }, + A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1 /* Error */, key: "A required parameter cannot follow an optional parameter.", isEarly: true }, + An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: 1 /* Error */, key: "An index signature cannot have a rest parameter.", isEarly: true }, + An_index_signature_parameter_cannot_have_an_accessibility_modifier: { code: 1018, category: 1 /* Error */, key: "An index signature parameter cannot have an accessibility modifier.", isEarly: true }, + An_index_signature_parameter_cannot_have_a_question_mark: { code: 1019, category: 1 /* Error */, key: "An index signature parameter cannot have a question mark.", isEarly: true }, + An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: 1 /* Error */, key: "An index signature parameter cannot have an initializer.", isEarly: true }, + An_index_signature_must_have_a_type_annotation: { code: 1021, category: 1 /* Error */, key: "An index signature must have a type annotation.", isEarly: true }, + An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: 1 /* Error */, key: "An index signature parameter must have a type annotation.", isEarly: true }, + An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: 1 /* Error */, key: "An index signature parameter type must be 'string' or 'number'.", isEarly: true }, A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: 1 /* Error */, key: "A class or interface declaration can only have one 'extends' clause." }, An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: 1 /* Error */, key: "An 'extends' clause must precede an 'implements' clause." }, A_class_can_only_extend_a_single_class: { code: 1026, category: 1 /* Error */, key: "A class can only extend a single class." }, A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: 1 /* Error */, key: "A class declaration can only have one 'implements' clause." }, - Accessibility_modifier_already_seen: { code: 1028, category: 1 /* Error */, key: "Accessibility modifier already seen." }, - _0_modifier_must_precede_1_modifier: { code: 1029, category: 1 /* Error */, key: "'{0}' modifier must precede '{1}' modifier." }, - _0_modifier_already_seen: { code: 1030, category: 1 /* Error */, key: "'{0}' modifier already seen." }, - _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a class element." }, + Accessibility_modifier_already_seen: { code: 1028, category: 1 /* Error */, key: "Accessibility modifier already seen.", isEarly: true }, + _0_modifier_must_precede_1_modifier: { code: 1029, category: 1 /* Error */, key: "'{0}' modifier must precede '{1}' modifier.", isEarly: true }, + _0_modifier_already_seen: { code: 1030, category: 1 /* Error */, key: "'{0}' modifier already seen.", isEarly: true }, + _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a class element.", isEarly: true }, An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: 1 /* Error */, key: "An interface declaration cannot have an 'implements' clause." }, super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: 1 /* Error */, key: "'super' must be followed by an argument list or member access." }, - Only_ambient_modules_can_use_quoted_names: { code: 1035, category: 1 /* Error */, key: "Only ambient modules can use quoted names." }, - Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: 1 /* Error */, key: "Statements are not allowed in ambient contexts." }, - A_function_implementation_cannot_be_declared_in_an_ambient_context: { code: 1037, category: 1 /* Error */, key: "A function implementation cannot be declared in an ambient context." }, - A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: 1 /* Error */, key: "A 'declare' modifier cannot be used in an already ambient context." }, - Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: 1 /* Error */, key: "Initializers are not allowed in ambient contexts." }, - _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a module element." }, - A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an interface declaration." }, + Only_ambient_modules_can_use_quoted_names: { code: 1035, category: 1 /* Error */, key: "Only ambient modules can use quoted names.", isEarly: true }, + Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: 1 /* Error */, key: "Statements are not allowed in ambient contexts.", isEarly: true }, + A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: 1 /* Error */, key: "A 'declare' modifier cannot be used in an already ambient context.", isEarly: true }, + Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: 1 /* Error */, key: "Initializers are not allowed in ambient contexts.", isEarly: true }, + _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a module element.", isEarly: true }, + A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an interface declaration.", isEarly: true }, A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: 1 /* Error */, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." }, - A_rest_parameter_cannot_be_optional: { code: 1047, category: 1 /* Error */, key: "A rest parameter cannot be optional." }, - A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: 1 /* Error */, key: "A rest parameter cannot have an initializer." }, - A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: 1 /* Error */, key: "A 'set' accessor must have exactly one parameter." }, - A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: 1 /* Error */, key: "A 'set' accessor cannot have an optional parameter." }, - A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: 1 /* Error */, key: "A 'set' accessor parameter cannot have an initializer." }, - A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: 1 /* Error */, key: "A 'set' accessor cannot have rest parameter." }, - A_get_accessor_cannot_have_parameters: { code: 1054, category: 1 /* Error */, key: "A 'get' accessor cannot have parameters." }, - Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: 1 /* Error */, key: "Accessors are only available when targeting ECMAScript 5 and higher." }, - Enum_member_must_have_initializer: { code: 1061, category: 1 /* Error */, key: "Enum member must have initializer." }, - An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: 1 /* Error */, key: "An export assignment cannot be used in an internal module." }, - Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: 1 /* Error */, key: "Ambient enum elements can only have integer literal initializers." }, + A_rest_parameter_cannot_be_optional: { code: 1047, category: 1 /* Error */, key: "A rest parameter cannot be optional.", isEarly: true }, + A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: 1 /* Error */, key: "A rest parameter cannot have an initializer.", isEarly: true }, + A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: 1 /* Error */, key: "A 'set' accessor must have exactly one parameter.", isEarly: true }, + A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: 1 /* Error */, key: "A 'set' accessor cannot have an optional parameter.", isEarly: true }, + A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: 1 /* Error */, key: "A 'set' accessor parameter cannot have an initializer.", isEarly: true }, + A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: 1 /* Error */, key: "A 'set' accessor cannot have rest parameter.", isEarly: true }, + A_get_accessor_cannot_have_parameters: { code: 1054, category: 1 /* Error */, key: "A 'get' accessor cannot have parameters.", isEarly: true }, + Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: 1 /* Error */, key: "Accessors are only available when targeting ECMAScript 5 and higher.", isEarly: true }, + Enum_member_must_have_initializer: { code: 1061, category: 1 /* Error */, key: "Enum member must have initializer.", isEarly: true }, + An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: 1 /* Error */, key: "An export assignment cannot be used in an internal module.", isEarly: true }, + Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: 1 /* Error */, key: "Ambient enum elements can only have integer literal initializers.", isEarly: true }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: 1 /* Error */, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, - A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an import declaration." }, + A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an import declaration.", isEarly: true }, Invalid_reference_directive_syntax: { code: 1084, category: 1 /* Error */, key: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: 1 /* Error */, key: "Octal literals are not available when targeting ECMAScript 5 and higher." }, - An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: 1 /* Error */, key: "An accessor cannot be declared in an ambient context." }, - _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a constructor declaration." }, - _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a parameter." }, - Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: { code: 1091, category: 1 /* Error */, key: "Only a single variable declaration is allowed in a 'for...in' statement." }, - Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: 1 /* Error */, key: "Type parameters cannot appear on a constructor declaration." }, - Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: 1 /* Error */, key: "Type annotation cannot appear on a constructor declaration." }, - An_accessor_cannot_have_type_parameters: { code: 1094, category: 1 /* Error */, key: "An accessor cannot have type parameters." }, - A_set_accessor_cannot_have_a_return_type_annotation: { code: 1095, category: 1 /* Error */, key: "A 'set' accessor cannot have a return type annotation." }, - An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: 1 /* Error */, key: "An index signature must have exactly one parameter." }, - _0_list_cannot_be_empty: { code: 1097, category: 1 /* Error */, key: "'{0}' list cannot be empty." }, - Type_parameter_list_cannot_be_empty: { code: 1098, category: 1 /* Error */, key: "Type parameter list cannot be empty." }, - Type_argument_list_cannot_be_empty: { code: 1099, category: 1 /* Error */, key: "Type argument list cannot be empty." }, - Invalid_use_of_0_in_strict_mode: { code: 1100, category: 1 /* Error */, key: "Invalid use of '{0}' in strict mode." }, - with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: 1 /* Error */, key: "'with' statements are not allowed in strict mode." }, - delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: 1 /* Error */, key: "'delete' cannot be called on an identifier in strict mode." }, - A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: { code: 1104, category: 1 /* Error */, key: "A 'continue' statement can only be used within an enclosing iteration statement." }, - A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: { code: 1105, category: 1 /* Error */, key: "A 'break' statement can only be used within an enclosing iteration or switch statement." }, - Jump_target_cannot_cross_function_boundary: { code: 1107, category: 1 /* Error */, key: "Jump target cannot cross function boundary." }, - A_return_statement_can_only_be_used_within_a_function_body: { code: 1108, category: 1 /* Error */, key: "A 'return' statement can only be used within a function body." }, - Expression_expected: { code: 1109, category: 1 /* Error */, key: "Expression expected." }, - Type_expected: { code: 1110, category: 1 /* Error */, key: "Type expected." }, - A_constructor_implementation_cannot_be_declared_in_an_ambient_context: { code: 1111, category: 1 /* Error */, key: "A constructor implementation cannot be declared in an ambient context." }, - A_class_member_cannot_be_declared_optional: { code: 1112, category: 1 /* Error */, key: "A class member cannot be declared optional." }, - A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: 1 /* Error */, key: "A 'default' clause cannot appear more than once in a 'switch' statement." }, - Duplicate_label_0: { code: 1114, category: 1 /* Error */, key: "Duplicate label '{0}'" }, - A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: 1 /* Error */, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement." }, - A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: 1 /* Error */, key: "A 'break' statement can only jump to a label of an enclosing statement." }, - An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: 1 /* Error */, key: "An object literal cannot have multiple properties with the same name in strict mode." }, - An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: 1 /* Error */, key: "An object literal cannot have multiple get/set accessors with the same name." }, - An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: 1 /* Error */, key: "An object literal cannot have property and accessor with the same name." }, - An_export_assignment_cannot_have_modifiers: { code: 1120, category: 1 /* Error */, key: "An export assignment cannot have modifiers." }, - Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: 1 /* Error */, key: "Octal literals are not allowed in strict mode." }, - A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: 1 /* Error */, key: "A tuple type element list cannot be empty." }, - Variable_declaration_list_cannot_be_empty: { code: 1123, category: 1 /* Error */, key: "Variable declaration list cannot be empty." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: 1 /* Error */, key: "Octal literals are not available when targeting ECMAScript 5 and higher.", isEarly: true }, + An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: 1 /* Error */, key: "An accessor cannot be declared in an ambient context.", isEarly: true }, + _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a constructor declaration.", isEarly: true }, + _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a parameter.", isEarly: true }, + Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: { code: 1091, category: 1 /* Error */, key: "Only a single variable declaration is allowed in a 'for...in' statement.", isEarly: true }, + Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: 1 /* Error */, key: "Type parameters cannot appear on a constructor declaration.", isEarly: true }, + Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: 1 /* Error */, key: "Type annotation cannot appear on a constructor declaration.", isEarly: true }, + An_accessor_cannot_have_type_parameters: { code: 1094, category: 1 /* Error */, key: "An accessor cannot have type parameters.", isEarly: true }, + A_set_accessor_cannot_have_a_return_type_annotation: { code: 1095, category: 1 /* Error */, key: "A 'set' accessor cannot have a return type annotation.", isEarly: true }, + An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: 1 /* Error */, key: "An index signature must have exactly one parameter.", isEarly: true }, + _0_list_cannot_be_empty: { code: 1097, category: 1 /* Error */, key: "'{0}' list cannot be empty.", isEarly: true }, + Type_parameter_list_cannot_be_empty: { code: 1098, category: 1 /* Error */, key: "Type parameter list cannot be empty.", isEarly: true }, + Type_argument_list_cannot_be_empty: { code: 1099, category: 1 /* Error */, key: "Type argument list cannot be empty.", isEarly: true }, + Invalid_use_of_0_in_strict_mode: { code: 1100, category: 1 /* Error */, key: "Invalid use of '{0}' in strict mode.", isEarly: true }, + with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: 1 /* Error */, key: "'with' statements are not allowed in strict mode.", isEarly: true }, + delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: 1 /* Error */, key: "'delete' cannot be called on an identifier in strict mode.", isEarly: true }, + A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: { code: 1104, category: 1 /* Error */, key: "A 'continue' statement can only be used within an enclosing iteration statement.", isEarly: true }, + A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: { code: 1105, category: 1 /* Error */, key: "A 'break' statement can only be used within an enclosing iteration or switch statement.", isEarly: true }, + Jump_target_cannot_cross_function_boundary: { code: 1107, category: 1 /* Error */, key: "Jump target cannot cross function boundary.", isEarly: true }, + A_return_statement_can_only_be_used_within_a_function_body: { code: 1108, category: 1 /* Error */, key: "A 'return' statement can only be used within a function body.", isEarly: true }, + Expression_expected: { code: 1109, category: 1 /* Error */, key: "Expression expected.", isEarly: true }, + Type_expected: { code: 1110, category: 1 /* Error */, key: "Type expected.", isEarly: true }, + A_class_member_cannot_be_declared_optional: { code: 1112, category: 1 /* Error */, key: "A class member cannot be declared optional.", isEarly: true }, + A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: 1 /* Error */, key: "A 'default' clause cannot appear more than once in a 'switch' statement.", isEarly: true }, + Duplicate_label_0: { code: 1114, category: 1 /* Error */, key: "Duplicate label '{0}'", isEarly: true }, + A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: 1 /* Error */, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement.", isEarly: true }, + A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: 1 /* Error */, key: "A 'break' statement can only jump to a label of an enclosing statement.", isEarly: true }, + An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: 1 /* Error */, key: "An object literal cannot have multiple properties with the same name in strict mode.", isEarly: true }, + An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: 1 /* Error */, key: "An object literal cannot have multiple get/set accessors with the same name.", isEarly: true }, + An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: 1 /* Error */, key: "An object literal cannot have property and accessor with the same name.", isEarly: true }, + An_export_assignment_cannot_have_modifiers: { code: 1120, category: 1 /* Error */, key: "An export assignment cannot have modifiers.", isEarly: true }, + Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: 1 /* Error */, key: "Octal literals are not allowed in strict mode.", isEarly: true }, + A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: 1 /* Error */, key: "A tuple type element list cannot be empty.", isEarly: true }, + Variable_declaration_list_cannot_be_empty: { code: 1123, category: 1 /* Error */, key: "Variable declaration list cannot be empty.", isEarly: true }, Digit_expected: { code: 1124, category: 1 /* Error */, key: "Digit expected." }, Hexadecimal_digit_expected: { code: 1125, category: 1 /* Error */, key: "Hexadecimal digit expected." }, Unexpected_end_of_text: { code: 1126, category: 1 /* Error */, key: "Unexpected end of text." }, @@ -898,52 +896,53 @@ var ts; Enum_member_expected: { code: 1132, category: 1 /* Error */, key: "Enum member expected." }, Type_reference_expected: { code: 1133, category: 1 /* Error */, key: "Type reference expected." }, Variable_declaration_expected: { code: 1134, category: 1 /* Error */, key: "Variable declaration expected." }, - Argument_expression_expected: { code: 1135, category: 1 /* Error */, key: "Argument expression expected." }, + Argument_expression_expected: { code: 1135, category: 1 /* Error */, key: "Argument expression expected.", isEarly: true }, Property_assignment_expected: { code: 1136, category: 1 /* Error */, key: "Property assignment expected." }, Expression_or_comma_expected: { code: 1137, category: 1 /* Error */, key: "Expression or comma expected." }, Parameter_declaration_expected: { code: 1138, category: 1 /* Error */, key: "Parameter declaration expected." }, Type_parameter_declaration_expected: { code: 1139, category: 1 /* Error */, key: "Type parameter declaration expected." }, Type_argument_expected: { code: 1140, category: 1 /* Error */, key: "Type argument expected." }, - String_literal_expected: { code: 1141, category: 1 /* Error */, key: "String literal expected." }, - Line_break_not_permitted_here: { code: 1142, category: 1 /* Error */, key: "Line break not permitted here." }, + String_literal_expected: { code: 1141, category: 1 /* Error */, key: "String literal expected.", isEarly: true }, + Line_break_not_permitted_here: { code: 1142, category: 1 /* Error */, key: "Line break not permitted here.", isEarly: true }, or_expected: { code: 1144, category: 1 /* Error */, key: "'{' or ';' expected." }, - Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: 1 /* Error */, key: "Modifiers not permitted on index signature members." }, + Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: 1 /* Error */, key: "Modifiers not permitted on index signature members.", isEarly: true }, Declaration_expected: { code: 1146, category: 1 /* Error */, key: "Declaration expected." }, - Import_declarations_in_an_internal_module_cannot_reference_an_external_module: { code: 1147, category: 1 /* Error */, key: "Import declarations in an internal module cannot reference an external module." }, + Import_declarations_in_an_internal_module_cannot_reference_an_external_module: { code: 1147, category: 1 /* Error */, key: "Import declarations in an internal module cannot reference an external module.", isEarly: true }, Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: 1 /* Error */, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: 1 /* Error */, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, - new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead.", isEarly: true }, var_let_or_const_expected: { code: 1152, category: 1 /* Error */, key: "'var', 'let' or 'const' expected." }, - let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: 1 /* Error */, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, - const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: 1 /* Error */, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, - const_declarations_must_be_initialized: { code: 1155, category: 1 /* Error */, key: "'const' declarations must be initialized" }, - const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1 /* Error */, key: "'const' declarations can only be declared inside a block." }, - let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1 /* Error */, key: "'let' declarations can only be declared inside a block." }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1 /* Error */, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, + let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: 1 /* Error */, key: "'let' declarations are only available when targeting ECMAScript 6 and higher.", isEarly: true }, + const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: 1 /* Error */, key: "'const' declarations are only available when targeting ECMAScript 6 and higher.", isEarly: true }, + const_declarations_must_be_initialized: { code: 1155, category: 1 /* Error */, key: "'const' declarations must be initialized", isEarly: true }, + const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1 /* Error */, key: "'const' declarations can only be declared inside a block.", isEarly: true }, + let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1 /* Error */, key: "'let' declarations can only be declared inside a block.", isEarly: true }, + Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1 /* Error */, key: "Tagged templates are only available when targeting ECMAScript 6 and higher.", isEarly: true }, Unterminated_template_literal: { code: 1160, category: 1 /* Error */, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: 1 /* Error */, key: "Unterminated regular expression literal." }, - An_object_member_cannot_be_declared_optional: { code: 1162, category: 1 /* Error */, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1 /* Error */, key: "'yield' expression must be contained_within a generator declaration." }, - Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: 1 /* Error */, key: "Computed property names are not allowed in enums." }, - Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: 1 /* Error */, key: "Computed property names are not allowed in an ambient context." }, - Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: 1 /* Error */, key: "Computed property names are not allowed in class property declarations." }, - Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: 1 /* Error */, key: "Computed property names are only available when targeting ECMAScript 6 and higher." }, - Computed_property_names_are_not_allowed_in_method_overloads: { code: 1168, category: 1 /* Error */, key: "Computed property names are not allowed in method overloads." }, - Computed_property_names_are_not_allowed_in_interfaces: { code: 1169, category: 1 /* Error */, key: "Computed property names are not allowed in interfaces." }, - Computed_property_names_are_not_allowed_in_type_literals: { code: 1170, category: 1 /* Error */, key: "Computed property names are not allowed in type literals." }, + An_object_member_cannot_be_declared_optional: { code: 1162, category: 1 /* Error */, key: "An object member cannot be declared optional.", isEarly: true }, + yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1 /* Error */, key: "'yield' expression must be contained_within a generator declaration.", isEarly: true }, + Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: 1 /* Error */, key: "Computed property names are not allowed in enums.", isEarly: true }, + Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: 1 /* Error */, key: "Computed property names are not allowed in an ambient context.", isEarly: true }, + Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: 1 /* Error */, key: "Computed property names are not allowed in class property declarations.", isEarly: true }, + Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: 1 /* Error */, key: "Computed property names are only available when targeting ECMAScript 6 and higher.", isEarly: true }, + Computed_property_names_are_not_allowed_in_method_overloads: { code: 1168, category: 1 /* Error */, key: "Computed property names are not allowed in method overloads.", isEarly: true }, + Computed_property_names_are_not_allowed_in_interfaces: { code: 1169, category: 1 /* Error */, key: "Computed property names are not allowed in interfaces.", isEarly: true }, + Computed_property_names_are_not_allowed_in_type_literals: { code: 1170, category: 1 /* Error */, key: "Computed property names are not allowed in type literals.", isEarly: true }, A_comma_expression_is_not_allowed_in_a_computed_property_name: { code: 1171, category: 1 /* Error */, key: "A comma expression is not allowed in a computed property name." }, - extends_clause_already_seen: { code: 1172, category: 1 /* Error */, key: "'extends' clause already seen." }, - extends_clause_must_precede_implements_clause: { code: 1173, category: 1 /* Error */, key: "'extends' clause must precede 'implements' clause." }, - Classes_can_only_extend_a_single_class: { code: 1174, category: 1 /* Error */, key: "Classes can only extend a single class." }, - implements_clause_already_seen: { code: 1175, category: 1 /* Error */, key: "'implements' clause already seen." }, - Interface_declaration_cannot_have_implements_clause: { code: 1176, category: 1 /* Error */, key: "Interface declaration cannot have 'implements' clause." }, + extends_clause_already_seen: { code: 1172, category: 1 /* Error */, key: "'extends' clause already seen.", isEarly: true }, + extends_clause_must_precede_implements_clause: { code: 1173, category: 1 /* Error */, key: "'extends' clause must precede 'implements' clause.", isEarly: true }, + Classes_can_only_extend_a_single_class: { code: 1174, category: 1 /* Error */, key: "Classes can only extend a single class.", isEarly: true }, + implements_clause_already_seen: { code: 1175, category: 1 /* Error */, key: "'implements' clause already seen.", isEarly: true }, + Interface_declaration_cannot_have_implements_clause: { code: 1176, category: 1 /* Error */, key: "Interface declaration cannot have 'implements' clause.", isEarly: true }, Binary_digit_expected: { code: 1177, category: 1 /* Error */, key: "Binary digit expected." }, Octal_digit_expected: { code: 1178, category: 1 /* Error */, key: "Octal digit expected." }, Unexpected_token_expected: { code: 1179, category: 1 /* Error */, key: "Unexpected token. '{' expected." }, Property_destructuring_pattern_expected: { code: 1180, category: 1 /* Error */, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: 1 /* Error */, key: "Array element destructuring pattern expected." }, - A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1 /* Error */, key: "A destructuring declaration must have an initializer." }, - Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1 /* Error */, key: "Destructuring declarations are not allowed in ambient contexts." }, + A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1 /* Error */, key: "A destructuring declaration must have an initializer.", isEarly: true }, + Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1 /* Error */, key: "Destructuring declarations are not allowed in ambient contexts.", isEarly: true }, + An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: 1 /* Error */, key: "An implementation cannot be declared in ambient contexts.", isEarly: true }, Merge_conflict_marker_encountered: { code: 1184, category: 1 /* Error */, key: "Merge conflict marker encountered." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, @@ -1235,9 +1234,9 @@ var 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: 1 /* 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: 1 /* 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: 1 /* Error */, key: "You cannot rename this element." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported." }, - Computed_property_names_are_not_currently_supported: { code: 9002, category: 1 /* Error */, key: "Computed property names are not currently supported." } + yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported.", isEarly: true }, + Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported.", isEarly: true }, + Computed_property_names_are_not_currently_supported: { code: 9002, category: 1 /* Error */, key: "Computed property names are not currently supported.", isEarly: true } }; })(ts || (ts = {})); var ts; @@ -2396,18 +2395,20 @@ var ts; function hasFlag(val, flag) { return (val & flag) !== 0; } - ts.hasFlag = hasFlag; function containsParseError(node) { - if (!hasFlag(node.parserContextFlags, 64 /* HasComputedThisNodeOrAnySubNodesHasError */)) { - var val = hasFlag(node.parserContextFlags, 16 /* ThisNodeHasError */) || ts.forEachChild(node, containsParseError); - if (val) { - node.parserContextFlags |= 32 /* ThisNodeOrAnySubNodesHasError */; - } - node.parserContextFlags |= 64 /* HasComputedThisNodeOrAnySubNodesHasError */; - } + aggregateChildData(node); return hasFlag(node.parserContextFlags, 32 /* ThisNodeOrAnySubNodesHasError */); } ts.containsParseError = containsParseError; + function aggregateChildData(node) { + if (!hasFlag(node.parserContextFlags, 64 /* HasAggregatedChildData */)) { + var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, 16 /* ThisNodeHasError */) || ts.forEachChild(node, containsParseError); + if (thisNodeOrAnySubNodesHasError) { + node.parserContextFlags |= 32 /* ThisNodeOrAnySubNodesHasError */; + } + node.parserContextFlags |= 64 /* HasAggregatedChildData */; + } + } function getSourceFileOfNode(node) { while (node && node.kind !== 207 /* SourceFile */) { node = node.parent; @@ -3034,7 +3035,7 @@ var ts; case 121 /* QualifiedName */: return child(node.left) || child(node.right); case 123 /* TypeParameter */: - return child(node.name) || child(node.constraint); + return child(node.name) || child(node.constraint) || child(node.expression); case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -3274,6 +3275,7 @@ var ts; } return 0; } + ts.modifierToFlag = modifierToFlag; function fixupParentReferences(sourceFile) { var parent = sourceFile; function walk(n) { @@ -3290,6 +3292,7 @@ var ts; function isEvalOrArgumentsIdentifier(node) { return node.kind === 64 /* Identifier */ && (node.text === "eval" || node.text === "arguments"); } + ts.isEvalOrArgumentsIdentifier = isEvalOrArgumentsIdentifier; function isUseStrictPrologueDirective(sourceFile, node) { ts.Debug.assert(ts.isPrologueDirective(node)); var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); @@ -5155,42 +5158,40 @@ var ts; parseSemicolon(ts.Diagnostics.or_expected); return undefined; } - function parseBindingElement(context) { - if (context === 11 /* ArrayBindingElements */ && token === 23 /* CommaToken */) { + function parseArrayBindingElement() { + if (token === 23 /* CommaToken */) { return createNode(167 /* OmittedExpression */); } var node = createNode(146 /* BindingElement */); - if (context === 10 /* ObjectBindingElements */) { - var id = parsePropertyName(); - if (id.kind === 64 /* Identifier */ && token !== 51 /* ColonToken */) { - node.name = id; - } - else { - parseExpected(51 /* ColonToken */); - node.propertyName = id; - node.name = parseIdentifierOrPattern(); - } + node.name = parseIdentifierOrPattern(); + node.initializer = parseInitializer(false); + return finishNode(node); + } + function parseObjectBindingElement() { + var node = createNode(146 /* BindingElement */); + var id = parsePropertyName(); + if (id.kind === 64 /* Identifier */ && token !== 51 /* ColonToken */) { + node.name = id; } else { + parseExpected(51 /* ColonToken */); + node.propertyName = id; node.name = parseIdentifierOrPattern(); } node.initializer = parseInitializer(false); return finishNode(node); } - function parseBindingList(context) { - return parseDelimitedList(context, function () { return parseBindingElement(context); }); - } function parseObjectBindingPattern() { var node = createNode(144 /* ObjectBindingPattern */); parseExpected(14 /* OpenBraceToken */); - node.elements = parseBindingList(10 /* ObjectBindingElements */); + node.elements = parseDelimitedList(10 /* ObjectBindingElements */, parseObjectBindingElement); parseExpected(15 /* CloseBraceToken */); return finishNode(node); } function parseArrayBindingPattern() { var node = createNode(145 /* ArrayBindingPattern */); parseExpected(18 /* OpenBracketToken */); - node.elements = parseBindingList(11 /* ArrayBindingElements */); + node.elements = parseDelimitedList(11 /* ArrayBindingElements */, parseArrayBindingElement); parseExpected(19 /* CloseBracketToken */); return finishNode(node); } @@ -5669,13 +5670,7 @@ var ts; var syntacticDiagnostics; function getSyntacticDiagnostics() { if (syntacticDiagnostics === undefined) { - if (sourceFile.parseDiagnostics.length > 0) { - syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); - } - else { - checkGrammar(sourceText, languageVersion, sourceFile); - syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.grammarDiagnostics); - } + syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); } ts.Debug.assert(syntacticDiagnostics !== undefined); return syntacticDiagnostics; @@ -5710,1028 +5705,11 @@ var ts; } return false; } + ts.isLeftHandSideExpression = isLeftHandSideExpression; function isAssignmentOperator(token) { return token >= 52 /* FirstAssignment */ && token <= 63 /* LastAssignment */; } - function checkGrammar(sourceText, languageVersion, file) { - var grammarDiagnostics = file.grammarDiagnostics; - var scanner = ts.createScanner(languageVersion, true, sourceText); - var inAmbientContext = ts.fileExtensionIs(file.filename, ".d.ts"); - var inFunctionBlock = false; - var parent; - visitNode(file); - function visitNode(node) { - var savedParent = parent; - node.parent = parent; - parent = node; - if (!checkModifiers(node)) { - var savedInFunctionBlock = inFunctionBlock; - if (ts.isFunctionBlock(node)) { - inFunctionBlock = true; - } - var savedInAmbientContext = inAmbientContext; - if (node.flags & 2 /* Ambient */) { - inAmbientContext = true; - } - checkNodeAndChildren(node); - inAmbientContext = savedInAmbientContext; - inFunctionBlock = savedInFunctionBlock; - } - parent = savedParent; - } - function checkNodeAndChildren(node) { - var nodeKind = node.kind; - if (inAmbientContext && checkForStatementInAmbientContext(node, nodeKind)) { - return; - } - if (checkNode(node, nodeKind)) { - return; - } - forEachChild(node, visitNode); - } - function checkNode(node, nodeKind) { - switch (nodeKind) { - case 157 /* ArrowFunction */: - case 132 /* CallSignature */: - case 137 /* ConstructorType */: - case 133 /* ConstructSignature */: - case 136 /* FunctionType */: - return checkAnySignatureDeclaration(node); - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: - return checkBreakOrContinueStatement(node); - case 151 /* CallExpression */: - case 152 /* NewExpression */: - return checkCallOrNewExpression(node); - case 194 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 163 /* BinaryExpression */: return checkBinaryExpression(node); - case 146 /* BindingElement */: return checkBindingElement(node); - case 203 /* CatchClause */: return checkCatchClause(node); - case 191 /* ClassDeclaration */: return checkClassDeclaration(node); - case 122 /* ComputedPropertyName */: return checkComputedPropertyName(node); - case 129 /* Constructor */: return checkConstructor(node); - case 158 /* DeleteExpression */: return checkDeleteExpression(node); - case 150 /* ElementAccessExpression */: return checkElementAccessExpression(node); - case 198 /* ExportAssignment */: return checkExportAssignment(node); - case 199 /* ExternalModuleReference */: return checkExternalModuleReference(node); - case 177 /* ForInStatement */: return checkForInStatement(node); - case 176 /* ForStatement */: return checkForStatement(node); - case 190 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 156 /* FunctionExpression */: return checkFunctionExpression(node); - case 130 /* GetAccessor */: return checkGetAccessor(node); - case 202 /* HeritageClause */: return checkHeritageClause(node); - case 134 /* IndexSignature */: return checkIndexSignature(node); - case 192 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 183 /* LabeledStatement */: return checkLabeledStatement(node); - case 204 /* PropertyAssignment */: return checkPropertyAssignment(node); - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - return checkMethod(node); - case 195 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 148 /* ObjectLiteralExpression */: return checkObjectLiteralExpression(node); - case 7 /* NumericLiteral */: return checkNumericLiteral(node); - case 124 /* Parameter */: return checkParameter(node); - case 162 /* PostfixUnaryExpression */: return checkPostfixUnaryExpression(node); - case 161 /* PrefixUnaryExpression */: return checkPrefixUnaryExpression(node); - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - return checkProperty(node); - case 180 /* ReturnStatement */: return checkReturnStatement(node); - case 131 /* SetAccessor */: return checkSetAccessor(node); - case 207 /* SourceFile */: return checkSourceFile(node); - case 205 /* ShorthandPropertyAssignment */: return checkShorthandPropertyAssignment(node); - case 182 /* SwitchStatement */: return checkSwitchStatement(node); - case 153 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node); - case 184 /* ThrowStatement */: return checkThrowStatement(node); - case 141 /* TupleType */: return checkTupleType(node); - case 123 /* TypeParameter */: return checkTypeParameter(node); - case 135 /* TypeReference */: return checkTypeReference(node); - case 189 /* VariableDeclaration */: return checkVariableDeclaration(node); - case 170 /* VariableStatement */: return checkVariableStatement(node); - case 181 /* WithStatement */: return checkWithStatement(node); - case 166 /* YieldExpression */: return checkYieldExpression(node); - } - } - function scanToken(pos) { - var start = ts.skipTrivia(sourceText, pos); - scanner.setTextPos(start); - scanner.scan(); - return start; - } - function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { - var start = scanToken(node.pos); - grammarDiagnostics.push(ts.createFileDiagnostic(file, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); - return true; - } - function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { - scanToken(node.pos); - grammarDiagnostics.push(ts.createFileDiagnostic(file, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); - return true; - } - function grammarErrorOnNode(node, message, arg0, arg1, arg2) { - var span = ts.getErrorSpanForNode(node); - var start = span.end > span.pos ? ts.skipTrivia(file.text, span.pos) : span.pos; - var length = span.end - start; - grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); - return true; - } - function grammarErrorAtPos(start, length, message, arg0, arg1, arg2) { - grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); - return true; - } - function reportInvalidUseInStrictMode(node) { - var name = sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); - return grammarErrorOnNode(node, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); - } - function checkForStatementInAmbientContext(node, kind) { - switch (kind) { - case 169 /* Block */: - case 171 /* EmptyStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - case 180 /* ReturnStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: - case 184 /* ThrowStatement */: - case 185 /* TryStatement */: - case 188 /* DebuggerStatement */: - case 183 /* LabeledStatement */: - case 172 /* ExpressionStatement */: - return grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); - } - } - function checkAnySignatureDeclaration(node) { - return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); - } - function checkBinaryExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */) { - if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operator)) { - if (isEvalOrArgumentsIdentifier(node.left)) { - return reportInvalidUseInStrictMode(node.left); - } - } - } - } - function isIterationStatement(node, lookInLabeledStatements) { - switch (node.kind) { - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - return true; - case 183 /* LabeledStatement */: - return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); - } - return false; - } - function checkLabeledStatement(node) { - var current = node.parent; - while (current) { - if (ts.isAnyFunction(current)) { - break; - } - if (current.kind === 183 /* LabeledStatement */ && current.label.text === node.label.text) { - return grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceText, node.label)); - } - current = current.parent; - } - } - function checkBreakOrContinueStatement(node) { - var current = node; - while (current) { - if (ts.isAnyFunction(current)) { - return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); - } - switch (current.kind) { - case 183 /* LabeledStatement */: - if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 178 /* ContinueStatement */ && !isIterationStatement(current.statement, true); - if (isMisplacedContinueLabel) { - return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); - } - return false; - } - break; - case 182 /* SwitchStatement */: - if (node.kind === 179 /* BreakStatement */ && !node.label) { - return false; - } - break; - default: - if (isIterationStatement(current, false) && !node.label) { - return false; - } - break; - } - current = current.parent; - } - if (node.label) { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; - return grammarErrorOnNode(node, message); - } - else { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; - return grammarErrorOnNode(node, message); - } - } - function checkCallOrNewExpression(node) { - return checkTypeArguments(node.typeArguments) || checkArguments(node.arguments); - } - function checkArguments(arguments) { - return checkForDisallowedTrailingComma(arguments) || checkForOmittedArgument(arguments); - } - function checkTypeArguments(typeArguments) { - return checkForDisallowedTrailingComma(typeArguments) || checkForAtLeastOneTypeArgument(typeArguments); - } - function checkForOmittedArgument(arguments) { - if (arguments) { - for (var i = 0, n = arguments.length; i < n; i++) { - var arg = arguments[i]; - if (arg.kind === 167 /* OmittedExpression */) { - return grammarErrorAtPos(arg.pos, 0, ts.Diagnostics.Argument_expression_expected); - } - } - } - } - function checkForAtLeastOneTypeArgument(typeArguments) { - if (typeArguments && typeArguments.length === 0) { - var start = typeArguments.pos - "<".length; - var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); - } - } - function checkForDisallowedTrailingComma(list) { - if (list && list.hasTrailingComma) { - var start = list.end - ",".length; - var end = list.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Trailing_comma_not_allowed); - } - } - function checkCatchClause(node) { - if (node.type) { - var colonStart = ts.skipTrivia(sourceText, node.name.end); - return grammarErrorAtPos(colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); - } - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkClassDeclaration(node) { - return checkClassDeclarationHeritageClauses(node); - } - function checkClassDeclarationHeritageClauses(node) { - var seenExtendsClause = false; - var seenImplementsClause = false; - if (node.heritageClauses) { - for (var i = 0, n = node.heritageClauses.length; i < n; i++) { - ts.Debug.assert(i <= 2); - var heritageClause = node.heritageClauses[i]; - if (heritageClause.token === 78 /* ExtendsKeyword */) { - if (seenExtendsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); - } - if (seenImplementsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause); - } - if (heritageClause.types.length > 1) { - return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class); - } - seenExtendsClause = true; - } - else { - ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); - if (seenImplementsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); - } - seenImplementsClause = true; - } - } - } - return false; - } - function checkForAtLeastOneHeritageClause(types, listType) { - if (types && types.length === 0) { - return grammarErrorAtPos(types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType); - } - } - function checkConstructor(node) { - return checkAnySignatureDeclaration(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, true); - } - function checkConstructorTypeParameters(node) { - if (node.typeParameters) { - return grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); - } - } - function checkConstructorTypeAnnotation(node) { - if (node.type) { - return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration); - } - } - function checkDeleteExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && node.expression.kind === 64 /* Identifier */) { - return grammarErrorOnNode(node.expression, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); - } - } - function checkEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 4096 /* Const */) !== 0; - var hasError = false; - if (!enumIsConst) { - var inConstantEnumMemberSection = true; - for (var i = 0, n = enumDecl.members.length; i < n; i++) { - var node = enumDecl.members[i]; - if (node.name.kind === 122 /* ComputedPropertyName */) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); - } - else if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer)) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; - } - } - } - return hasError; - } - function isIntegerLiteral(expression) { - function isInteger(literalExpression) { - return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); - } - if (expression.kind === 161 /* PrefixUnaryExpression */) { - var unaryExpression = expression; - if (unaryExpression.operator === 33 /* PlusToken */ || unaryExpression.operator === 34 /* MinusToken */) { - expression = unaryExpression.operand; - } - } - if (expression.kind === 7 /* NumericLiteral */) { - return isInteger(expression); - } - return false; - } - function checkExportAssignment(node) { - if (node.flags & 243 /* Modifier */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); - } - } - function checkExternalModuleReference(node) { - if (node.expression.kind !== 8 /* StringLiteral */) { - return grammarErrorOnNode(node.expression, ts.Diagnostics.String_literal_expected); - } - } - function checkForInStatement(node) { - return checkVariableDeclarations(node.declarations) || checkForMoreThanOneDeclaration(node.declarations); - } - function checkForStatement(node) { - return checkVariableDeclarations(node.declarations); - } - function checkForMoreThanOneDeclaration(declarations) { - if (declarations && declarations.length > 1) { - return grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); - } - } - function checkFunctionDeclaration(node) { - return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, false) || checkForGenerator(node); - } - function checkForGenerator(node) { - if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); - } - } - function checkFunctionExpression(node) { - return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForGenerator(node); - } - function checkFunctionName(name) { - if (name && name.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(name)) { - return reportInvalidUseInStrictMode(name); - } - } - function checkGetAccessor(node) { - return checkAnySignatureDeclaration(node) || checkAccessor(node); - } - function checkElementAccessExpression(node) { - if (!node.argumentExpression) { - if (node.parent.kind === 152 /* NewExpression */ && node.parent.expression === node) { - var start = ts.skipTrivia(sourceText, node.expression.end); - var end = node.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); - } - else { - var start = node.end - "]".length; - var end = node.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Expression_expected); - } - } - } - function checkHeritageClause(node) { - return checkForDisallowedTrailingComma(node.types) || checkForAtLeastOneHeritageClause(node.types, ts.tokenToString(node.token)); - } - function checkIndexSignature(node) { - return checkIndexSignatureParameters(node) || checkForIndexSignatureModifiers(node); - } - function checkForIndexSignatureModifiers(node) { - if (node.flags & 243 /* Modifier */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); - } - } - function checkIndexSignatureParameters(node) { - var parameter = node.parameters[0]; - if (node.parameters.length !== 1) { - if (parameter) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); - } - else { - return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); - } - } - else if (parameter.dotDotDotToken) { - return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); - } - else if (parameter.flags & 243 /* Modifier */) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); - } - else if (parameter.questionToken) { - return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); - } - else if (parameter.initializer) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); - } - else if (!parameter.type) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); - } - else if (parameter.type.kind !== 119 /* StringKeyword */ && parameter.type.kind !== 117 /* NumberKeyword */) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); - } - else if (!node.type) { - return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation); - } - } - function checkInterfaceDeclaration(node) { - return checkInterfaceDeclarationHeritageClauses(node); - } - function checkInterfaceDeclarationHeritageClauses(node) { - var seenExtendsClause = false; - if (node.heritageClauses) { - for (var i = 0, n = node.heritageClauses.length; i < n; i++) { - ts.Debug.assert(i <= 1); - var heritageClause = node.heritageClauses[i]; - if (heritageClause.token === 78 /* ExtendsKeyword */) { - if (seenExtendsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); - } - seenExtendsClause = true; - } - else { - ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); - } - } - } - return false; - } - function checkMethod(node) { - if (checkAnySignatureDeclaration(node) || checkForBodyInAmbientContext(node.body, false) || checkForGenerator(node)) { - return true; - } - if (node.parent.kind === 191 /* ClassDeclaration */) { - if (checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { - return true; - } - if (inAmbientContext) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_an_ambient_context); - } - else if (!node.body) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); - } - } - else if (node.parent.kind === 192 /* InterfaceDeclaration */) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces); - } - else if (node.parent.kind === 139 /* TypeLiteral */) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals); - } - } - function checkForBodyInAmbientContext(body, isConstructor) { - if (inAmbientContext && body && body.kind === 169 /* Block */) { - var diagnostic = isConstructor ? ts.Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : ts.Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; - return grammarErrorOnFirstToken(body, diagnostic); - } - } - function checkModuleDeclaration(node) { - return checkModuleDeclarationName(node) || checkModuleDeclarationStatements(node); - } - function checkModuleDeclarationName(node) { - if (!inAmbientContext && node.name.kind === 8 /* StringLiteral */) { - return grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); - } - } - function checkModuleDeclarationStatements(node) { - if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 198 /* ExportAssignment */) { - return grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - else if (ts.isExternalModuleImportDeclaration(statement)) { - return grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); - } - } - } - } - function checkObjectLiteralExpression(node) { - var seen = {}; - var Property = 1; - var GetAccessor = 2; - var SetAccesor = 4; - var GetOrSetAccessor = GetAccessor | SetAccesor; - var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; - for (var i = 0, n = node.properties.length; i < n; i++) { - var prop = node.properties[i]; - var name = prop.name; - if (prop.kind === 167 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { - continue; - } - var currentKind; - if (prop.kind === 204 /* PropertyAssignment */ || prop.kind === 205 /* ShorthandPropertyAssignment */ || prop.kind === 128 /* MethodDeclaration */) { - currentKind = Property; - } - else if (prop.kind === 130 /* GetAccessor */) { - currentKind = GetAccessor; - } - else if (prop.kind === 131 /* SetAccessor */) { - currentKind = SetAccesor; - } - else { - ts.Debug.fail("Unexpected syntax kind:" + prop.kind); - } - if (!ts.hasProperty(seen, name.text)) { - seen[name.text] = currentKind; - } - else { - var existingKind = seen[name.text]; - if (currentKind === Property && existingKind === Property) { - if (inStrictMode) { - grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); - } - } - else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { - if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name.text] = currentKind | existingKind; - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); - } - } - } - } - function checkNumericLiteral(node) { - if (node.flags & 8192 /* OctalLiteral */) { - if (node.parserContextFlags & 1 /* StrictMode */) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); - } - else if (languageVersion >= 1 /* ES5 */) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); - } - } - } - function checkModifiers(node) { - switch (node.kind) { - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - case 129 /* Constructor */: - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - case 134 /* IndexSignature */: - case 191 /* ClassDeclaration */: - case 192 /* InterfaceDeclaration */: - case 195 /* ModuleDeclaration */: - case 194 /* EnumDeclaration */: - case 198 /* ExportAssignment */: - case 170 /* VariableStatement */: - case 190 /* FunctionDeclaration */: - case 193 /* TypeAliasDeclaration */: - case 197 /* ImportDeclaration */: - case 124 /* Parameter */: - break; - default: - return false; - } - if (!node.modifiers) { - return; - } - var lastStatic, lastPrivate, lastProtected, lastDeclare; - var flags = 0; - for (var i = 0, n = node.modifiers.length; i < n; i++) { - var modifier = node.modifiers[i]; - switch (modifier.kind) { - case 107 /* PublicKeyword */: - case 106 /* ProtectedKeyword */: - case 105 /* PrivateKeyword */: - var text; - if (modifier.kind === 107 /* PublicKeyword */) { - text = "public"; - } - else if (modifier.kind === 106 /* ProtectedKeyword */) { - text = "protected"; - lastProtected = modifier; - } - else { - text = "private"; - lastPrivate = modifier; - } - if (flags & 112 /* AccessibilityModifier */) { - return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen); - } - else if (flags & 128 /* Static */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); - } - else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); - } - flags |= modifierToFlag(modifier.kind); - break; - case 108 /* StaticKeyword */: - if (flags & 128 /* Static */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); - } - else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); - } - else if (node.kind === 124 /* Parameter */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); - } - flags |= 128 /* Static */; - lastStatic = modifier; - break; - case 77 /* ExportKeyword */: - if (flags & 1 /* Export */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); - } - else if (flags & 2 /* Ambient */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); - } - else if (node.parent.kind === 191 /* ClassDeclaration */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); - } - else if (node.kind === 124 /* Parameter */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); - } - flags |= 1 /* Export */; - break; - case 113 /* DeclareKeyword */: - if (flags & 2 /* Ambient */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); - } - else if (node.parent.kind === 191 /* ClassDeclaration */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); - } - else if (node.kind === 124 /* Parameter */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); - } - else if (inAmbientContext && node.parent.kind === 196 /* ModuleBlock */) { - return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); - } - flags |= 2 /* Ambient */; - lastDeclare = modifier; - break; - } - } - if (node.kind === 129 /* Constructor */) { - if (flags & 128 /* Static */) { - return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); - } - else if (flags & 64 /* Protected */) { - return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); - } - else if (flags & 32 /* Private */) { - return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); - } - } - else if (node.kind === 197 /* ImportDeclaration */ && flags & 2 /* Ambient */) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); - } - else if (node.kind === 192 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } - } - function checkParameter(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkTypeParameterList(typeParameters) { - if (checkForDisallowedTrailingComma(typeParameters)) { - return true; - } - if (typeParameters && typeParameters.length === 0) { - var start = typeParameters.pos - "<".length; - var end = ts.skipTrivia(sourceText, typeParameters.end) + ">".length; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty); - } - } - function checkParameterList(parameters) { - if (checkForDisallowedTrailingComma(parameters)) { - return true; - } - var seenOptionalParameter = false; - var parameterCount = parameters.length; - for (var i = 0; i < parameterCount; i++) { - var parameter = parameters[i]; - if (parameter.dotDotDotToken) { - if (i !== (parameterCount - 1)) { - return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); - } - if (parameter.questionToken) { - return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional); - } - if (parameter.initializer) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer); - } - } - else if (parameter.questionToken || parameter.initializer) { - seenOptionalParameter = true; - if (parameter.questionToken && parameter.initializer) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer); - } - } - else { - if (seenOptionalParameter) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); - } - } - } - } - function checkPostfixUnaryExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.operand)) { - return reportInvalidUseInStrictMode(node.operand); - } - } - function checkPrefixUnaryExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */) { - if ((node.operator === 38 /* PlusPlusToken */ || node.operator === 39 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(node.operand)) { - return reportInvalidUseInStrictMode(node.operand); - } - } - } - function checkProperty(node) { - if (node.parent.kind === 191 /* ClassDeclaration */) { - if (checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_class_property_declarations)) { - return true; - } - } - else if (node.parent.kind === 192 /* InterfaceDeclaration */) { - if (checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces)) { - return true; - } - } - else if (node.parent.kind === 139 /* TypeLiteral */) { - if (checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals)) { - return true; - } - } - return checkForInitializerInAmbientContext(node); - } - function checkComputedPropertyName(node) { - return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_not_currently_supported); - if (languageVersion < 2 /* ES6 */) { - return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (node.expression.kind === 163 /* BinaryExpression */ && node.expression.operator === 23 /* CommaToken */) { - return grammarErrorOnNode(node.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); - } - } - function checkForDisallowedComputedProperty(node, message) { - if (node.kind === 122 /* ComputedPropertyName */) { - return grammarErrorOnNode(node, message); - } - } - function checkForInitializerInAmbientContext(node) { - if (inAmbientContext && node.initializer) { - return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - function checkPropertyAssignment(node) { - return checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - } - function checkForInvalidQuestionMark(node, questionToken, message) { - if (questionToken) { - return grammarErrorOnNode(questionToken, message); - } - } - function checkReturnStatement(node) { - if (!inFunctionBlock) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); - } - } - function checkSetAccessor(node) { - return checkAnySignatureDeclaration(node) || checkAccessor(node); - } - function checkAccessor(accessor) { - var kind = accessor.kind; - if (languageVersion < 1 /* ES5 */) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (inAmbientContext) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); - } - else if (accessor.body === undefined) { - return grammarErrorAtPos(accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); - } - else if (accessor.typeParameters) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); - } - else if (kind === 130 /* GetAccessor */ && accessor.parameters.length) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); - } - else if (kind === 131 /* SetAccessor */) { - if (accessor.type) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); - } - else if (accessor.parameters.length !== 1) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter); - } - else { - var parameter = accessor.parameters[0]; - if (parameter.dotDotDotToken) { - return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter); - } - else if (parameter.flags & 243 /* Modifier */) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); - } - else if (parameter.questionToken) { - return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); - } - else if (parameter.initializer) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer); - } - } - } - } - function checkSourceFile(node) { - return inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file); - } - function checkTopLevelElementsForRequiredDeclareModifier(file) { - for (var i = 0, n = file.statements.length; i < n; i++) { - var decl = file.statements[i]; - if (ts.isDeclaration(decl) || decl.kind === 170 /* VariableStatement */) { - if (checkTopLevelElementForRequiredDeclareModifier(decl)) { - return true; - } - } - } - } - function checkTopLevelElementForRequiredDeclareModifier(node) { - if (node.kind === 192 /* InterfaceDeclaration */ || node.kind === 197 /* ImportDeclaration */ || node.kind === 198 /* ExportAssignment */ || (node.flags & 2 /* Ambient */)) { - return false; - } - return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); - } - function checkShorthandPropertyAssignment(node) { - return checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - } - function checkSwitchStatement(node) { - var firstDefaultClause; - for (var i = 0, n = node.clauses.length; i < n; i++) { - var clause = node.clauses[i]; - if (clause.kind === 201 /* DefaultClause */) { - if (firstDefaultClause === undefined) { - firstDefaultClause = clause; - } - else { - var start = ts.skipTrivia(file.text, clause.pos); - var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); - } - } - } - } - function checkTaggedTemplateExpression(node) { - if (languageVersion < 2 /* ES6 */) { - return grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } - function checkThrowStatement(node) { - if (node.expression === undefined) { - return grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here); - } - } - function checkTupleType(node) { - return checkForDisallowedTrailingComma(node.elementTypes) || checkForAtLeastOneType(node); - } - function checkForAtLeastOneType(node) { - if (node.elementTypes.length === 0) { - return grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty); - } - } - function checkTypeParameter(node) { - if (node.expression) { - return grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); - } - } - function checkTypeReference(node) { - return checkTypeArguments(node.typeArguments); - } - function checkBindingElement(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkVariableDeclaration(node) { - if (inAmbientContext) { - if (ts.isBindingPattern(node.name)) { - return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); - } - if (node.initializer) { - return grammarErrorAtPos(node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - else { - if (!node.initializer) { - if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { - return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); - } - if (ts.isConst(node)) { - return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized); - } - } - } - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkVariableDeclarations(declarations) { - if (declarations) { - if (checkForDisallowedTrailingComma(declarations)) { - return true; - } - if (!declarations.length) { - return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); - } - var decl = declarations[0]; - if (languageVersion < 2 /* ES6 */) { - if (ts.isLet(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } - } - } - function checkVariableStatement(node) { - return checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node); - } - function checkForDisallowedLetOrConstStatement(node) { - if (!allowLetAndConstDeclarations(node.parent)) { - if (ts.isLet(node)) { - return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block); - } - else if (ts.isConst(node)) { - return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block); - } - } - } - function allowLetAndConstDeclarations(parent) { - switch (parent.kind) { - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 181 /* WithStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - return false; - case 183 /* LabeledStatement */: - return allowLetAndConstDeclarations(parent.parent); - } - return true; - } - function checkWithStatement(node) { - if (node.parserContextFlags & 1 /* StrictMode */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode); - } - } - function checkYieldExpression(node) { - if (!(node.parserContextFlags & 4 /* Yield */)) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); - } - return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); - } - } + ts.isAssignmentOperator = isAssignmentOperator; function createProgram(rootNames, options, host) { var program; var files = []; @@ -6816,7 +5794,12 @@ var ts; return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); } var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { - errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + if (refFile) { + errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } }); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; @@ -7121,12 +6104,12 @@ var ts; parent = node; if (symbolKind & 262128 /* IsContainer */) { container = node; - if (lastContainer !== container && !container.nextContainer) { - if (lastContainer) { - lastContainer.nextContainer = container; - } - lastContainer = container; + ts.Debug.assert(container.nextContainer === undefined); + if (lastContainer) { + ts.Debug.assert(lastContainer.nextContainer === undefined); + lastContainer.nextContainer = container; } + lastContainer = container; } if (isBlockScopeContainer) { blockScopeContainer = node; @@ -7177,14 +6160,6 @@ var ts; } bindChildren(node, symbolKind, isBlockScopeContainer); } - function bindConstructorDeclaration(node) { - bindDeclaration(node, 16384 /* Constructor */, 0, true); - ts.forEach(node.parameters, function (p) { - if (p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { - bindDeclaration(p, 4 /* Property */, 107455 /* PropertyExcludes */, false); - } - }); - } function bindModuleDeclaration(node) { if (node.name.kind === 8 /* StringLiteral */) { bindDeclaration(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */, true); @@ -7257,12 +6232,7 @@ var ts; bindDeclaration(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */, false); break; case 124 /* Parameter */: - if (ts.isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node), false); - } - else { - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); - } + bindParameter(node); break; case 189 /* VariableDeclaration */: case 146 /* BindingElement */: @@ -7300,7 +6270,7 @@ var ts; bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true); break; case 129 /* Constructor */: - bindConstructorDeclaration(node); + bindDeclaration(node, 16384 /* Constructor */, 0, true); break; case 130 /* GetAccessor */: bindDeclaration(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); @@ -7369,6 +6339,18 @@ var ts; parent = saveParent; } } + function bindParameter(node) { + if (ts.isBindingPattern(node.name)) { + bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node), false); + } + else { + bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); + } + if (node.flags & 112 /* AccessibilityModifier */ && node.parent.kind === 129 /* Constructor */ && node.parent.parent.kind === 191 /* ClassDeclaration */) { + var classDeclaration = node.parent.parent; + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); + } + } } ts.bindSourceFile = bindSourceFile; })(ts || (ts = {})); @@ -11150,6 +10132,11 @@ var ts; if (!links.target) { links.target = resolvingSymbol; var node = ts.getDeclarationOfKind(symbol, 197 /* ImportDeclaration */); + if (node.moduleReference.kind === 199 /* ExternalModuleReference */) { + if (node.moduleReference.expression.kind !== 8 /* StringLiteral */) { + grammarErrorOnNode(node.moduleReference.expression, ts.Diagnostics.String_literal_expected); + } + } var target = node.moduleReference.kind === 199 /* ExternalModuleReference */ ? resolveExternalModuleName(node, ts.getExternalModuleImportDeclarationExpression(node)) : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -14759,10 +13746,34 @@ var ts; return type; } } + function markLinkedImportsAsReferenced(node) { + var nodeLinks = getNodeLinks(node); + while (nodeLinks.importOnRightSide) { + var rightSide = nodeLinks.importOnRightSide; + nodeLinks.importOnRightSide = undefined; + getSymbolLinks(rightSide).referenced = true; + ts.Debug.assert((rightSide.flags & 8388608 /* Import */) !== 0); + nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 197 /* ImportDeclaration */)); + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); if (symbol.flags & 8388608 /* Import */) { - getSymbolLinks(symbol).referenced = getSymbolLinks(symbol).referenced || (!isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol))); + var symbolLinks = getSymbolLinks(symbol); + if (!symbolLinks.referenced) { + var importOrExportAssignment = getLeftSideOfImportOrExportAssignment(node); + if (!importOrExportAssignment || (importOrExportAssignment.flags & 1 /* Export */) || (importOrExportAssignment.kind === 198 /* ExportAssignment */)) { + symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); + } + else { + var nodeLinks = getNodeLinks(importOrExportAssignment); + ts.Debug.assert(!nodeLinks.importOnRightSide); + nodeLinks.importOnRightSide = symbol; + } + } + if (symbolLinks.referenced) { + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197 /* ImportDeclaration */)); + } } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); @@ -15164,6 +14175,7 @@ var ts; return (+name).toString() === name; } function checkObjectLiteral(node, contextualMapper) { + checkGrammarObjectLiteralExpression(node); var members = node.symbol.members; var properties = {}; var contextualType = getContextualType(node); @@ -15318,6 +14330,19 @@ var ts; return true; } function checkIndexedAccess(node) { + if (!node.argumentExpression) { + var sourceFile = getSourceFile(node); + if (node.parent.kind === 152 /* NewExpression */ && node.parent.expression === node) { + var start = ts.skipTrivia(sourceFile.text, node.expression.end); + var end = node.end; + grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); + } + else { + var start = node.end - "]".length; + var end = node.end; + grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Expression_expected); + } + } var objectType = getApparentType(checkExpression(node.expression)); var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType; if (objectType === unknownType) { @@ -15764,6 +14789,7 @@ var ts; return links.resolvedSignature; } function checkCallExpression(node) { + checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); if (node.expression.kind === 90 /* SuperKeyword */) { return voidType; @@ -15780,6 +14806,9 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { + if (compilerOptions.target < 2 /* ES6 */) { + grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); + } return getReturnTypeOfSignature(getResolvedSignature(node)); } function checkTypeAssertion(node) { @@ -15872,6 +14901,10 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 128 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + if (!hasGrammarError && node.kind === 156 /* FunctionExpression */) { + checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); + } if (contextualMapper === identityMapper) { return anyFunctionType; } @@ -15981,6 +15014,9 @@ var ts; return true; } function checkDeleteExpression(node) { + if (node.parserContextFlags & 1 /* StrictMode */ && node.expression.kind === 64 /* Identifier */) { + grammarErrorOnNode(node.expression, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); + } var operandType = checkExpression(node.expression); return booleanType; } @@ -15993,6 +15029,9 @@ var ts; return undefinedType; } function checkPrefixUnaryExpression(node) { + if ((node.operator === 38 /* PlusPlusToken */ || node.operator === 39 /* MinusMinusToken */)) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.operand); + } var operandType = checkExpression(node.operand); switch (node.operator) { case 33 /* PlusToken */: @@ -16012,6 +15051,7 @@ var ts; return unknownType; } function checkPostfixUnaryExpression(node) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.operand); var operandType = checkExpression(node.operand); var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { @@ -16108,6 +15148,9 @@ var ts; return sourceType; } function checkBinaryExpression(node, contextualMapper) { + if (ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operator)) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.left); + } var operator = node.operator; if (operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); @@ -16228,6 +15271,14 @@ var ts; error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operator), typeToString(leftType), typeToString(rightType)); } } + function checkYieldExpression(node) { + if (!(node.parserContextFlags & 4 /* Yield */)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + } + else { + grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); + } + } function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); @@ -16255,6 +15306,7 @@ var ts; return links.resolvedType; } function checkObjectLiteralMethod(node, contextualMapper) { + checkGrammarMethod(node); var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } @@ -16293,6 +15345,10 @@ var ts; } return type; } + function checkNumericLiteral(node) { + checkGrammarNumbericLiteral(node); + return numberType; + } function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { case 64 /* Identifier */: @@ -16307,7 +15363,7 @@ var ts; case 79 /* FalseKeyword */: return booleanType; case 7 /* NumericLiteral */: - return numberType; + return checkNumericLiteral(node); case 165 /* TemplateExpression */: return checkTemplateExpression(node); case 8 /* StringLiteral */: @@ -16351,10 +15407,16 @@ var ts; return checkConditionalExpression(node, contextualMapper); case 167 /* OmittedExpression */: return undefinedType; + case 166 /* YieldExpression */: + checkYieldExpression(node); + return unknownType; } return unknownType; } function checkTypeParameter(node) { + if (node.expression) { + grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); + } checkSourceElement(node.constraint); if (fullTypeCheck) { checkTypeParameterHasIllegalReferencesInConstraint(node); @@ -16362,6 +15424,7 @@ var ts; } } function checkParameter(node) { + checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); if (node.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { @@ -16377,6 +15440,12 @@ var ts; } } function checkSignatureDeclaration(node) { + if (node.kind === 134 /* IndexSignature */) { + checkGrammarIndexSignature(node); + } + else if (node.kind === 136 /* FunctionType */ || node.kind === 190 /* FunctionDeclaration */ || node.kind === 137 /* ConstructorType */ || node.kind === 132 /* CallSignature */ || node.kind === 129 /* Constructor */ || node.kind === 133 /* ConstructSignature */) { + checkGrammarFunctionLikeDeclaration(node); + } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { @@ -16434,13 +15503,16 @@ var ts; } } function checkPropertyDeclaration(node) { + checkGrammarModifiers(node) || checkGrammarProperty(node); checkVariableLikeDeclaration(node); } function checkMethodDeclaration(node) { + checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); checkFunctionLikeDeclaration(node); } function checkConstructorDeclaration(node) { checkSignatureDeclaration(node); + checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); @@ -16498,6 +15570,7 @@ var ts; } } function checkAccessorDeclaration(node) { + checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); if (fullTypeCheck) { if (node.kind === 130 /* GetAccessor */) { if (!ts.isInAmbientContext(node) && node.body && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { @@ -16525,6 +15598,7 @@ var ts; checkFunctionLikeDeclaration(node); } function checkTypeReference(node) { + checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReferenceNode(node); if (type !== unknownType && node.typeArguments) { var len = node.typeArguments.length; @@ -16553,6 +15627,10 @@ var ts; checkSourceElement(node.elementType); } function checkTupleType(node) { + var hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes); + if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) { + grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty); + } ts.forEach(node.elementTypes, checkSourceElement); } function checkUnionType(node) { @@ -16815,6 +15893,7 @@ var ts; } function checkFunctionDeclaration(node) { checkFunctionLikeDeclaration(node); + checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); @@ -16845,6 +15924,9 @@ var ts; } } function checkBlock(node) { + if (node.kind === 169 /* Block */) { + checkGrammarForStatementInAmbientContext(node); + } ts.forEach(node.statements, checkSourceElement); if (ts.isFunctionBlock(node) || node.kind === 196 /* ModuleBlock */) { checkFunctionExpressionBodies(node); @@ -16973,6 +16055,12 @@ var ts; } } function checkVariableLikeDeclaration(node) { + if (node.kind === 146 /* BindingElement */) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + } + else if (node.kind === 189 /* VariableDeclaration */) { + checkGrammarVariableDeclaration(node); + } checkSourceElement(node.type); if (ts.hasComputedNameButNotSymbol(node)) { if (node.initializer) { @@ -17020,25 +16108,31 @@ var ts; } } function checkVariableStatement(node) { + checkGrammarModifiers(node) || checkGrammarVariableDeclarations(node, node.declarations) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarations, checkSourceElement); } function checkExpressionStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkExpression(node.expression); } function checkIfStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkExpression(node.expression); checkSourceElement(node.thenStatement); checkSourceElement(node.elseStatement); } function checkDoStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkSourceElement(node.statement); checkExpression(node.expression); } function checkWhileStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkExpression(node.expression); checkSourceElement(node.statement); } function checkForStatement(node) { + checkGrammarForStatementInAmbientContext(node) || checkGrammarVariableDeclarations(node, node.declarations); if (node.declarations) ts.forEach(node.declarations, checkVariableLikeDeclaration); if (node.initializer) @@ -17050,6 +16144,14 @@ var ts; checkSourceElement(node.statement); } function checkForInStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + var declarations = node.declarations; + if (!checkGrammarVariableDeclarations(node, declarations)) { + if (declarations && declarations.length > 1) { + grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + } + } + } if (node.declarations) { if (node.declarations.length >= 1) { var decl = node.declarations[0]; @@ -17075,11 +16177,18 @@ var ts; checkSourceElement(node.statement); } function checkBreakOrContinueStatement(node) { + checkGrammarForStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } function isGetAccessorWithAnnotatatedSetAccessor(node) { return !!(node.kind === 130 /* GetAccessor */ && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 131 /* SetAccessor */))); } function checkReturnStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + var functionBlock = ts.getContainingFunction(node); + if (!functionBlock) { + grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); + } + } if (node.expression) { var func = ts.getContainingFunction(node); if (func) { @@ -17102,12 +16211,32 @@ var ts; } } function checkWithStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + if (node.parserContextFlags & 1 /* StrictMode */) { + grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode); + } + } checkExpression(node.expression); error(node.expression, ts.Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any); } function checkSwitchStatement(node) { + checkGrammarForStatementInAmbientContext(node); + var firstDefaultClause; + var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); ts.forEach(node.clauses, function (clause) { + if (clause.kind === 201 /* DefaultClause */ && !hasDuplicateDefaultClause) { + if (firstDefaultClause === undefined) { + firstDefaultClause = clause; + } + else { + var sourceFile = ts.getSourceFileOfNode(node); + var start = ts.skipTrivia(sourceFile.text, clause.pos); + var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; + grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); + hasDuplicateDefaultClause = true; + } + } if (fullTypeCheck && clause.kind === 200 /* CaseClause */) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); @@ -17119,17 +16248,45 @@ var ts; }); } function checkLabeledStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + var current = node.parent; + while (current) { + if (ts.isAnyFunction(current)) { + break; + } + if (current.kind === 183 /* LabeledStatement */ && current.label.text === node.label.text) { + var sourceFile = ts.getSourceFileOfNode(node); + grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); + break; + } + current = current.parent; + } + } checkSourceElement(node.statement); } function checkThrowStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + if (node.expression === undefined) { + grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here); + } + } if (node.expression) { checkExpression(node.expression); } } function checkTryStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkBlock(node.tryBlock); - if (node.catchClause) - checkBlock(node.catchClause.block); + var catchClause = node.catchClause; + if (catchClause) { + if (catchClause.type) { + var sourceFile = ts.getSourceFileOfNode(node); + var colonStart = ts.skipTrivia(sourceFile.text, catchClause.name.end); + grammarErrorAtPos(sourceFile, colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + } + checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.name); + checkBlock(catchClause.block); + } if (node.finallyBlock) checkBlock(node.finallyBlock); } @@ -17206,6 +16363,7 @@ var ts; } } function checkClassDeclaration(node) { + checkGrammarClassDeclarationHeritageClauses(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); @@ -17364,6 +16522,7 @@ var ts; return ok; } function checkInterfaceDeclaration(node) { + checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (fullTypeCheck) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); @@ -17392,6 +16551,7 @@ var ts; } } function checkTypeAliasDeclaration(node) { + checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_alias_name_cannot_be_0); checkSourceElement(node.type); } @@ -17531,6 +16691,7 @@ var ts; } } function checkEnumDeclaration(node) { + checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); if (!fullTypeCheck) { return; } @@ -17582,6 +16743,23 @@ var ts; return undefined; } function checkModuleDeclaration(node) { + if (!checkGrammarModifiers(node)) { + if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { + grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); + } + else if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { + var statements = node.body.statements; + for (var i = 0, n = statements.length; i < n; i++) { + var statement = statements[i]; + if (statement.kind === 198 /* ExportAssignment */) { + grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + } + else if (ts.isExternalModuleImportDeclaration(statement)) { + grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + } + } + } + } if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -17616,6 +16794,7 @@ var ts; return node; } function checkImportDeclaration(node) { + checkGrammarModifiers(node); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); @@ -17667,6 +16846,9 @@ var ts; } } function checkExportAssignment(node) { + if (!checkGrammarModifiers(node) && (node.flags & 243 /* Modifier */)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); + } var container = node.parent; if (container.kind !== 207 /* SourceFile */) { container = container.parent; @@ -17688,6 +16870,7 @@ var ts; case 137 /* ConstructorType */: case 132 /* CallSignature */: case 133 /* ConstructSignature */: + return checkSignatureDeclaration(node); case 134 /* IndexSignature */: return checkSignatureDeclaration(node); case 128 /* MethodDeclaration */: @@ -17763,6 +16946,12 @@ var ts; return checkImportDeclaration(node); case 198 /* ExportAssignment */: return checkExportAssignment(node); + case 171 /* EmptyStatement */: + checkGrammarForStatementInAmbientContext(node); + return; + case 188 /* DebuggerStatement */: + checkGrammarForStatementInAmbientContext(node); + return; } } function checkFunctionExpressionBodies(node) { @@ -17844,6 +17033,7 @@ var ts; function checkSourceFile(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { + checkGrammarSourceFile(node); emitExtends = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); @@ -17852,6 +17042,7 @@ var ts; var symbol = getExportAssignmentSymbol(node.symbol); if (symbol && symbol.flags & 8388608 /* Import */) { getSymbolLinks(symbol).referenced = true; + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197 /* ImportDeclaration */)); } } if (potentialThisCollisions.length) { @@ -18038,17 +17229,20 @@ var ts; } return false; } + function getLeftSideOfImportOrExportAssignment(nodeOnRightSide) { + while (nodeOnRightSide.parent.kind === 121 /* QualifiedName */) { + nodeOnRightSide = nodeOnRightSide.parent; + } + if (nodeOnRightSide.parent.kind === 197 /* ImportDeclaration */) { + return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; + } + if (nodeOnRightSide.parent.kind === 198 /* ExportAssignment */) { + return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; + } + return undefined; + } function isInRightSideOfImportOrExportAssignment(node) { - while (node.parent.kind === 121 /* QualifiedName */) { - node = node.parent; - } - if (node.parent.kind === 197 /* ImportDeclaration */) { - return node.parent.moduleReference === node; - } - if (node.parent.kind === 198 /* ExportAssignment */) { - return node.parent.exportName === node; - } - return false; + return getLeftSideOfImportOrExportAssignment(node) !== undefined; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { return (node.parent.kind === 121 /* QualifiedName */ && node.parent.right === node) || (node.parent.kind === 149 /* PropertyAccessExpression */ && node.parent.name === node); @@ -18395,6 +17589,740 @@ var ts; globalTemplateStringsArrayType = compilerOptions.target >= 2 /* ES6 */ ? getGlobalType("TemplateStringsArray") : unknownType; anyArrayType = createArrayType(anyType); } + function checkGrammarModifiers(node) { + switch (node.kind) { + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + case 129 /* Constructor */: + case 126 /* PropertyDeclaration */: + case 125 /* PropertySignature */: + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + case 134 /* IndexSignature */: + case 191 /* ClassDeclaration */: + case 192 /* InterfaceDeclaration */: + case 195 /* ModuleDeclaration */: + case 194 /* EnumDeclaration */: + case 198 /* ExportAssignment */: + case 170 /* VariableStatement */: + case 190 /* FunctionDeclaration */: + case 193 /* TypeAliasDeclaration */: + case 197 /* ImportDeclaration */: + case 124 /* Parameter */: + break; + default: + return false; + } + if (!node.modifiers) { + return; + } + var lastStatic, lastPrivate, lastProtected, lastDeclare; + var flags = 0; + for (var i = 0, n = node.modifiers.length; i < n; i++) { + var modifier = node.modifiers[i]; + switch (modifier.kind) { + case 107 /* PublicKeyword */: + case 106 /* ProtectedKeyword */: + case 105 /* PrivateKeyword */: + var text; + if (modifier.kind === 107 /* PublicKeyword */) { + text = "public"; + } + else if (modifier.kind === 106 /* ProtectedKeyword */) { + text = "protected"; + lastProtected = modifier; + } + else { + text = "private"; + lastPrivate = modifier; + } + if (flags & 112 /* AccessibilityModifier */) { + return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen); + } + else if (flags & 128 /* Static */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); + } + else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); + } + flags |= ts.modifierToFlag(modifier.kind); + break; + case 108 /* StaticKeyword */: + if (flags & 128 /* Static */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); + } + else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); + } + else if (node.kind === 124 /* Parameter */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); + } + flags |= 128 /* Static */; + lastStatic = modifier; + break; + case 77 /* ExportKeyword */: + if (flags & 1 /* Export */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); + } + else if (flags & 2 /* Ambient */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); + } + else if (node.parent.kind === 191 /* ClassDeclaration */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); + } + else if (node.kind === 124 /* Parameter */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); + } + flags |= 1 /* Export */; + break; + case 113 /* DeclareKeyword */: + if (flags & 2 /* Ambient */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); + } + else if (node.parent.kind === 191 /* ClassDeclaration */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); + } + else if (node.kind === 124 /* Parameter */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); + } + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 196 /* ModuleBlock */) { + return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); + } + flags |= 2 /* Ambient */; + lastDeclare = modifier; + break; + } + } + if (node.kind === 129 /* Constructor */) { + if (flags & 128 /* Static */) { + return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); + } + else if (flags & 64 /* Protected */) { + return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); + } + else if (flags & 32 /* Private */) { + return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); + } + } + else if (node.kind === 197 /* ImportDeclaration */ && flags & 2 /* Ambient */) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); + } + else if (node.kind === 192 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); + } + } + function checkGrammarForDisallowedTrailingComma(list) { + if (list && list.hasTrailingComma) { + var start = list.end - ",".length; + var end = list.end; + var sourceFile = ts.getSourceFileOfNode(list[0]); + return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + function checkGrammarTypeParameterList(node, typeParameters) { + if (checkGrammarForDisallowedTrailingComma(typeParameters)) { + return true; + } + if (typeParameters && typeParameters.length === 0) { + var start = typeParameters.pos - "<".length; + var sourceFile = ts.getSourceFileOfNode(node); + var end = ts.skipTrivia(sourceFile.text, typeParameters.end) + ">".length; + return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty); + } + } + function checkGrammarParameterList(parameters) { + if (checkGrammarForDisallowedTrailingComma(parameters)) { + return true; + } + var seenOptionalParameter = false; + var parameterCount = parameters.length; + for (var i = 0; i < parameterCount; i++) { + var parameter = parameters[i]; + if (parameter.dotDotDotToken) { + if (i !== (parameterCount - 1)) { + return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); + } + if (parameter.questionToken) { + return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional); + } + if (parameter.initializer) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer); + } + } + else if (parameter.questionToken || parameter.initializer) { + seenOptionalParameter = true; + if (parameter.questionToken && parameter.initializer) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer); + } + } + else { + if (seenOptionalParameter) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); + } + } + } + } + function checkGrammarFunctionLikeDeclaration(node) { + return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters); + } + function checkGrammarIndexSignatureParameters(node) { + var parameter = node.parameters[0]; + if (node.parameters.length !== 1) { + if (parameter) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); + } + else { + return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); + } + } + else if (parameter.dotDotDotToken) { + return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); + } + else if (parameter.flags & 243 /* Modifier */) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); + } + else if (parameter.questionToken) { + return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); + } + else if (parameter.initializer) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); + } + else if (!parameter.type) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); + } + else if (parameter.type.kind !== 119 /* StringKeyword */ && parameter.type.kind !== 117 /* NumberKeyword */) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); + } + else if (!node.type) { + return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation); + } + } + function checkGrammarForIndexSignatureModifier(node) { + if (node.flags & 243 /* Modifier */) { + grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); + } + } + function checkGrammarIndexSignature(node) { + checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + } + function checkGrammarForAtLeastOneTypeArgument(node, typeArguments) { + if (typeArguments && typeArguments.length === 0) { + var sourceFile = ts.getSourceFileOfNode(node); + var start = typeArguments.pos - "<".length; + var end = ts.skipTrivia(sourceFile.text, typeArguments.end) + ">".length; + return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function checkGrammarTypeArguments(node, typeArguments) { + return checkGrammarForDisallowedTrailingComma(typeArguments) || checkGrammarForAtLeastOneTypeArgument(node, typeArguments); + } + function checkGrammarForOmittedArgument(node, arguments) { + if (arguments) { + var sourceFile = ts.getSourceFileOfNode(node); + for (var i = 0, n = arguments.length; i < n; i++) { + var arg = arguments[i]; + if (arg.kind === 167 /* OmittedExpression */) { + return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); + } + } + } + } + function checkGrammarArguments(node, arguments) { + return checkGrammarForDisallowedTrailingComma(arguments) || checkGrammarForOmittedArgument(node, arguments); + } + function checkGrammarHeritageClause(node) { + var types = node.types; + if (checkGrammarForDisallowedTrailingComma(types)) { + return true; + } + if (types && types.length === 0) { + var listType = ts.tokenToString(node.token); + var sourceFile = ts.getSourceFileOfNode(node); + return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType); + } + } + function checkGrammarClassDeclarationHeritageClauses(node) { + var seenExtendsClause = false; + var seenImplementsClause = false; + if (!checkGrammarModifiers(node) && node.heritageClauses) { + for (var i = 0, n = node.heritageClauses.length; i < n; i++) { + ts.Debug.assert(i <= 2); + var heritageClause = node.heritageClauses[i]; + if (heritageClause.token === 78 /* ExtendsKeyword */) { + if (seenExtendsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); + } + if (seenImplementsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause); + } + if (heritageClause.types.length > 1) { + return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class); + } + seenExtendsClause = true; + } + else { + ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); + if (seenImplementsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); + } + seenImplementsClause = true; + } + checkGrammarHeritageClause(heritageClause); + } + } + } + function checkGrammarInterfaceDeclaration(node) { + var seenExtendsClause = false; + if (node.heritageClauses) { + for (var i = 0, n = node.heritageClauses.length; i < n; i++) { + ts.Debug.assert(i <= 1); + var heritageClause = node.heritageClauses[i]; + if (heritageClause.token === 78 /* ExtendsKeyword */) { + if (seenExtendsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); + } + seenExtendsClause = true; + } + else { + ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); + } + checkGrammarHeritageClause(heritageClause); + } + } + return false; + } + function checkGrammarComputedPropertyName(node) { + if (node.kind !== 122 /* ComputedPropertyName */) { + return; + } + grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_not_currently_supported); + return; + var computedPropertyName = node; + if (compilerOptions.target < 2 /* ES6 */) { + grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (computedPropertyName.expression.kind === 163 /* BinaryExpression */ && computedPropertyName.expression.operator === 23 /* CommaToken */) { + grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); + } + } + function checkGrammarForGenerator(node) { + if (node.asteriskToken) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); + } + } + function checkGrammarFunctionName(name) { + return checkGrammarEvalOrArgumentsInStrictMode(name, name); + } + function checkGrammarForInvalidQuestionMark(node, questionToken, message) { + if (questionToken) { + return grammarErrorOnNode(questionToken, message); + } + } + function checkGrammarObjectLiteralExpression(node) { + var seen = {}; + var Property = 1; + var GetAccessor = 2; + var SetAccesor = 4; + var GetOrSetAccessor = GetAccessor | SetAccesor; + var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; + for (var i = 0, n = node.properties.length; i < n; i++) { + var prop = node.properties[i]; + var name = prop.name; + if (prop.kind === 167 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { + checkGrammarComputedPropertyName(name); + continue; + } + var currentKind; + if (prop.kind === 204 /* PropertyAssignment */ || prop.kind === 205 /* ShorthandPropertyAssignment */) { + checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); + if (name.kind === 7 /* NumericLiteral */) { + checkGrammarNumbericLiteral(name); + } + currentKind = Property; + } + else if (prop.kind === 128 /* MethodDeclaration */) { + currentKind = Property; + } + else if (prop.kind === 130 /* GetAccessor */) { + currentKind = GetAccessor; + } + else if (prop.kind === 131 /* SetAccessor */) { + currentKind = SetAccesor; + } + else { + ts.Debug.fail("Unexpected syntax kind:" + prop.kind); + } + if (!ts.hasProperty(seen, name.text)) { + seen[name.text] = currentKind; + } + else { + var existingKind = seen[name.text]; + if (currentKind === Property && existingKind === Property) { + if (inStrictMode) { + grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + } + } + else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { + if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { + seen[name.text] = currentKind | existingKind; + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } + } + } + } + function checkGrammarAccessor(accessor) { + var kind = accessor.kind; + if (compilerOptions.target < 1 /* ES5 */) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (ts.isInAmbientContext(accessor)) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); + } + else if (accessor.body === undefined) { + return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); + } + else if (accessor.typeParameters) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); + } + else if (kind === 130 /* GetAccessor */ && accessor.parameters.length) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); + } + else if (kind === 131 /* SetAccessor */) { + if (accessor.type) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); + } + else if (accessor.parameters.length !== 1) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter); + } + else { + var parameter = accessor.parameters[0]; + if (parameter.dotDotDotToken) { + return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter); + } + else if (parameter.flags & 243 /* Modifier */) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); + } + else if (parameter.questionToken) { + return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); + } + else if (parameter.initializer) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer); + } + } + } + } + function checkGrammarForDisallowedComputedProperty(node, message) { + if (node.kind === 122 /* ComputedPropertyName */) { + return grammarErrorOnNode(node, message); + } + } + function checkGrammarMethod(node) { + if (checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { + return true; + } + if (node.parent.kind === 191 /* ClassDeclaration */) { + if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { + return true; + } + if (ts.isInAmbientContext(node)) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_an_ambient_context); + } + else if (!node.body) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); + } + } + else if (node.parent.kind === 192 /* InterfaceDeclaration */) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces); + } + else if (node.parent.kind === 139 /* TypeLiteral */) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals); + } + } + function isIterationStatement(node, lookInLabeledStatements) { + switch (node.kind) { + case 176 /* ForStatement */: + case 177 /* ForInStatement */: + case 174 /* DoStatement */: + case 175 /* WhileStatement */: + return true; + case 183 /* LabeledStatement */: + return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); + } + return false; + } + function checkGrammarBreakOrContinueStatement(node) { + var current = node; + while (current) { + if (ts.isAnyFunction(current)) { + return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); + } + switch (current.kind) { + case 183 /* LabeledStatement */: + if (node.label && current.label.text === node.label.text) { + var isMisplacedContinueLabel = node.kind === 178 /* ContinueStatement */ && !isIterationStatement(current.statement, true); + if (isMisplacedContinueLabel) { + return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); + } + return false; + } + break; + case 182 /* SwitchStatement */: + if (node.kind === 179 /* BreakStatement */ && !node.label) { + return false; + } + break; + default: + if (isIterationStatement(current, false) && !node.label) { + return false; + } + break; + } + current = current.parent; + } + if (node.label) { + var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + return grammarErrorOnNode(node, message); + } + else { + var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + return grammarErrorOnNode(node, message); + } + } + function checkGrammarVariableDeclaration(node) { + if (ts.isInAmbientContext(node)) { + if (ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + else { + if (!node.initializer) { + if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { + return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); + } + if (ts.isConst(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized); + } + } + } + return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + } + function checkGrammarVariableDeclarations(container, declarations) { + if (declarations) { + if (checkGrammarForDisallowedTrailingComma(declarations)) { + return true; + } + if (!declarations.length) { + return grammarErrorAtPos(ts.getSourceFileOfNode(container), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); + } + var decl = declarations[0]; + if (compilerOptions.target < 2 /* ES6 */) { + if (ts.isLet(decl)) { + return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (ts.isConst(decl)) { + return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + } + } + function allowLetAndConstDeclarations(parent) { + switch (parent.kind) { + case 173 /* IfStatement */: + case 174 /* DoStatement */: + case 175 /* WhileStatement */: + case 181 /* WithStatement */: + case 176 /* ForStatement */: + case 177 /* ForInStatement */: + return false; + case 183 /* LabeledStatement */: + return allowLetAndConstDeclarations(parent.parent); + } + return true; + } + function checkGrammarForDisallowedLetOrConstStatement(node) { + if (!allowLetAndConstDeclarations(node.parent)) { + if (ts.isLet(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block); + } + else if (ts.isConst(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block); + } + } + } + function isIntegerLiteral(expression) { + if (expression.kind === 161 /* PrefixUnaryExpression */) { + var unaryExpression = expression; + if (unaryExpression.operator === 33 /* PlusToken */ || unaryExpression.operator === 34 /* MinusToken */) { + expression = unaryExpression.operand; + } + } + if (expression.kind === 7 /* NumericLiteral */) { + return /^[0-9]+([eE]\+?[0-9]+)?$/.test(expression.text); + } + return false; + } + function checkGrammarEnumDeclaration(enumDecl) { + var enumIsConst = (enumDecl.flags & 4096 /* Const */) !== 0; + var hasError = false; + if (!enumIsConst) { + var inConstantEnumMemberSection = true; + var inAmbientContext = ts.isInAmbientContext(enumDecl); + for (var i = 0, n = enumDecl.members.length; i < n; i++) { + var node = enumDecl.members[i]; + if (node.name.kind === 122 /* ComputedPropertyName */) { + hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); + } + else if (inAmbientContext) { + if (node.initializer && !isIntegerLiteral(node.initializer)) { + hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; + } + } + else if (node.initializer) { + inConstantEnumMemberSection = isIntegerLiteral(node.initializer); + } + else if (!inConstantEnumMemberSection) { + hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; + } + } + } + return hasError; + } + function hasParseDiagnostics(sourceFile) { + return sourceFile.parseDiagnostics.length > 0; + } + function scanToken(scanner, pos) { + scanner.setTextPos(pos); + scanner.scan(); + var start = scanner.getTokenPos(); + return start; + } + function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { + var sourceFile = ts.getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + var start = scanToken(scanner, node.pos); + diagnostics.push(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); + return true; + } + } + function grammarErrorAtPos(sourceFile, start, length, message, arg0, arg1, arg2) { + if (!hasParseDiagnostics(sourceFile)) { + diagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2)); + return true; + } + } + function grammarErrorOnNode(node, message, arg0, arg1, arg2) { + var sourceFile = ts.getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + var span = ts.getErrorSpanForNode(node); + var start = span.end > span.pos ? ts.skipTrivia(sourceFile.text, span.pos) : span.pos; + diagnostics.push(ts.createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2)); + return true; + } + } + function checkGrammarEvalOrArgumentsInStrictMode(contextNode, identifier) { + if (contextNode && (contextNode.parserContextFlags & 1 /* StrictMode */) && ts.isEvalOrArgumentsIdentifier(identifier)) { + var name = ts.declarationNameToString(identifier); + return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); + } + } + function checkGrammarConstructorTypeParameters(node) { + if (node.typeParameters) { + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); + } + } + function checkGrammarConstructorTypeAnnotation(node) { + if (node.type) { + return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration); + } + } + function checkGrammarProperty(node) { + if (node.parent.kind === 191 /* ClassDeclaration */) { + if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_class_property_declarations)) { + return true; + } + } + else if (node.parent.kind === 192 /* InterfaceDeclaration */) { + if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces)) { + return true; + } + } + else if (node.parent.kind === 139 /* TypeLiteral */) { + if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals)) { + return true; + } + } + if (ts.isInAmbientContext(node) && node.initializer) { + return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + function checkGrammarTopLevelElementForRequiredDeclareModifier(node) { + if (node.kind === 192 /* InterfaceDeclaration */ || node.kind === 197 /* ImportDeclaration */ || node.kind === 198 /* ExportAssignment */ || (node.flags & 2 /* Ambient */)) { + return false; + } + return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); + } + function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { + for (var i = 0, n = file.statements.length; i < n; i++) { + var decl = file.statements[i]; + if (ts.isDeclaration(decl) || decl.kind === 170 /* VariableStatement */) { + if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { + return true; + } + } + } + } + function checkGrammarSourceFile(node) { + return ts.isInAmbientContext(node) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node); + } + function checkGrammarForStatementInAmbientContext(node) { + if (ts.isInAmbientContext(node)) { + if (isAccessor(node.parent.kind)) { + return getNodeLinks(node).hasReportedStatementInAmbientContext = true; + } + var links = getNodeLinks(node); + if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { + return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); + } + if (node.parent.kind === 169 /* Block */ || node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + var links = getNodeLinks(node.parent); + if (!links.hasReportedStatementInAmbientContext) { + return links.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); + } + } + else { + } + } + } + function checkGrammarNumbericLiteral(node) { + if (node.flags & 8192 /* OctalLiteral */) { + if (node.parserContextFlags & 1 /* StrictMode */) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); + } + else if (compilerOptions.target >= 1 /* ES5 */) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + } + } + } + function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { + var sourceFile = ts.getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + scanToken(scanner, node.pos); + diagnostics.push(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); + return true; + } + } initializeTypeChecker(); return checker; } diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 6df15a572a7..0cb7ac8775c 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -284,7 +284,7 @@ declare module "typescript" { ThisNodeHasError = 16, ParserGeneratedFlags = 31, ThisNodeOrAnySubNodesHasError = 32, - HasComputedThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 64, } interface Node extends TextRange { kind: SyntaxKind; @@ -964,6 +964,8 @@ declare module "typescript" { isVisible?: boolean; localModuleName?: string; assignmentChecks?: Map; + hasReportedStatementInAmbientContext?: boolean; + importOnRightSide?: Symbol; } const enum TypeFlags { Any = 1, @@ -1355,7 +1357,11 @@ declare module "typescript" { function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodes?: (nodes: Node[]) => T): T; function createCompilerHost(options: CompilerOptions): CompilerHost; + function modifierToFlag(token: SyntaxKind): NodeFlags; + function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; + function isLeftHandSideExpression(expr: Expression): boolean; + function isAssignmentOperator(token: SyntaxKind): boolean; function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; } declare module "typescript" { diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 2fd17ddf8b4..24ea4aebd31 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -284,7 +284,7 @@ declare module ts { ThisNodeHasError = 16, ParserGeneratedFlags = 31, ThisNodeOrAnySubNodesHasError = 32, - HasComputedThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 64, } interface Node extends TextRange { kind: SyntaxKind; @@ -964,6 +964,8 @@ declare module ts { isVisible?: boolean; localModuleName?: string; assignmentChecks?: Map; + hasReportedStatementInAmbientContext?: boolean; + importOnRightSide?: Symbol; } const enum TypeFlags { Any = 1, @@ -1355,7 +1357,11 @@ declare module ts { function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodes?: (nodes: Node[]) => T): T; function createCompilerHost(options: CompilerOptions): CompilerHost; + function modifierToFlag(token: SyntaxKind): NodeFlags; + function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; + function isLeftHandSideExpression(expr: Expression): boolean; + function isAssignmentOperator(token: SyntaxKind): boolean; function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program; } declare module ts { diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 95d17a7f0f2..11bce678504 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -804,89 +804,87 @@ var ts; ts.Diagnostics = { Unterminated_string_literal: { code: 1002, category: 1 /* Error */, key: "Unterminated string literal." }, Identifier_expected: { code: 1003, category: 1 /* Error */, key: "Identifier expected." }, - _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected." }, + _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected.", isEarly: true }, A_file_cannot_have_a_reference_to_itself: { code: 1006, category: 1 /* Error */, key: "A file cannot have a reference to itself." }, - Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed." }, + Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed.", isEarly: true }, Asterisk_Slash_expected: { code: 1010, category: 1 /* Error */, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1 /* Error */, key: "Unexpected token." }, - Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1 /* Error */, key: "Catch clause parameter cannot have a type annotation." }, - A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1 /* Error */, key: "A rest parameter must be last in a parameter list." }, - Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1 /* Error */, key: "Parameter cannot have question mark and initializer." }, - A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1 /* Error */, key: "A required parameter cannot follow an optional parameter." }, - An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: 1 /* Error */, key: "An index signature cannot have a rest parameter." }, - An_index_signature_parameter_cannot_have_an_accessibility_modifier: { code: 1018, category: 1 /* Error */, key: "An index signature parameter cannot have an accessibility modifier." }, - An_index_signature_parameter_cannot_have_a_question_mark: { code: 1019, category: 1 /* Error */, key: "An index signature parameter cannot have a question mark." }, - An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: 1 /* Error */, key: "An index signature parameter cannot have an initializer." }, - An_index_signature_must_have_a_type_annotation: { code: 1021, category: 1 /* Error */, key: "An index signature must have a type annotation." }, - An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: 1 /* Error */, key: "An index signature parameter must have a type annotation." }, - An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: 1 /* Error */, key: "An index signature parameter type must be 'string' or 'number'." }, + Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1 /* Error */, key: "Catch clause parameter cannot have a type annotation.", isEarly: true }, + A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1 /* Error */, key: "A rest parameter must be last in a parameter list.", isEarly: true }, + Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1 /* Error */, key: "Parameter cannot have question mark and initializer.", isEarly: true }, + A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1 /* Error */, key: "A required parameter cannot follow an optional parameter.", isEarly: true }, + An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: 1 /* Error */, key: "An index signature cannot have a rest parameter.", isEarly: true }, + An_index_signature_parameter_cannot_have_an_accessibility_modifier: { code: 1018, category: 1 /* Error */, key: "An index signature parameter cannot have an accessibility modifier.", isEarly: true }, + An_index_signature_parameter_cannot_have_a_question_mark: { code: 1019, category: 1 /* Error */, key: "An index signature parameter cannot have a question mark.", isEarly: true }, + An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: 1 /* Error */, key: "An index signature parameter cannot have an initializer.", isEarly: true }, + An_index_signature_must_have_a_type_annotation: { code: 1021, category: 1 /* Error */, key: "An index signature must have a type annotation.", isEarly: true }, + An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: 1 /* Error */, key: "An index signature parameter must have a type annotation.", isEarly: true }, + An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: 1 /* Error */, key: "An index signature parameter type must be 'string' or 'number'.", isEarly: true }, A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: 1 /* Error */, key: "A class or interface declaration can only have one 'extends' clause." }, An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: 1 /* Error */, key: "An 'extends' clause must precede an 'implements' clause." }, A_class_can_only_extend_a_single_class: { code: 1026, category: 1 /* Error */, key: "A class can only extend a single class." }, A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: 1 /* Error */, key: "A class declaration can only have one 'implements' clause." }, - Accessibility_modifier_already_seen: { code: 1028, category: 1 /* Error */, key: "Accessibility modifier already seen." }, - _0_modifier_must_precede_1_modifier: { code: 1029, category: 1 /* Error */, key: "'{0}' modifier must precede '{1}' modifier." }, - _0_modifier_already_seen: { code: 1030, category: 1 /* Error */, key: "'{0}' modifier already seen." }, - _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a class element." }, + Accessibility_modifier_already_seen: { code: 1028, category: 1 /* Error */, key: "Accessibility modifier already seen.", isEarly: true }, + _0_modifier_must_precede_1_modifier: { code: 1029, category: 1 /* Error */, key: "'{0}' modifier must precede '{1}' modifier.", isEarly: true }, + _0_modifier_already_seen: { code: 1030, category: 1 /* Error */, key: "'{0}' modifier already seen.", isEarly: true }, + _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a class element.", isEarly: true }, An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: 1 /* Error */, key: "An interface declaration cannot have an 'implements' clause." }, super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: 1 /* Error */, key: "'super' must be followed by an argument list or member access." }, - Only_ambient_modules_can_use_quoted_names: { code: 1035, category: 1 /* Error */, key: "Only ambient modules can use quoted names." }, - Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: 1 /* Error */, key: "Statements are not allowed in ambient contexts." }, - A_function_implementation_cannot_be_declared_in_an_ambient_context: { code: 1037, category: 1 /* Error */, key: "A function implementation cannot be declared in an ambient context." }, - A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: 1 /* Error */, key: "A 'declare' modifier cannot be used in an already ambient context." }, - Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: 1 /* Error */, key: "Initializers are not allowed in ambient contexts." }, - _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a module element." }, - A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an interface declaration." }, + Only_ambient_modules_can_use_quoted_names: { code: 1035, category: 1 /* Error */, key: "Only ambient modules can use quoted names.", isEarly: true }, + Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: 1 /* Error */, key: "Statements are not allowed in ambient contexts.", isEarly: true }, + A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: 1 /* Error */, key: "A 'declare' modifier cannot be used in an already ambient context.", isEarly: true }, + Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: 1 /* Error */, key: "Initializers are not allowed in ambient contexts.", isEarly: true }, + _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a module element.", isEarly: true }, + A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an interface declaration.", isEarly: true }, A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: 1 /* Error */, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." }, - A_rest_parameter_cannot_be_optional: { code: 1047, category: 1 /* Error */, key: "A rest parameter cannot be optional." }, - A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: 1 /* Error */, key: "A rest parameter cannot have an initializer." }, - A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: 1 /* Error */, key: "A 'set' accessor must have exactly one parameter." }, - A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: 1 /* Error */, key: "A 'set' accessor cannot have an optional parameter." }, - A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: 1 /* Error */, key: "A 'set' accessor parameter cannot have an initializer." }, - A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: 1 /* Error */, key: "A 'set' accessor cannot have rest parameter." }, - A_get_accessor_cannot_have_parameters: { code: 1054, category: 1 /* Error */, key: "A 'get' accessor cannot have parameters." }, - Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: 1 /* Error */, key: "Accessors are only available when targeting ECMAScript 5 and higher." }, - Enum_member_must_have_initializer: { code: 1061, category: 1 /* Error */, key: "Enum member must have initializer." }, - An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: 1 /* Error */, key: "An export assignment cannot be used in an internal module." }, - Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: 1 /* Error */, key: "Ambient enum elements can only have integer literal initializers." }, + A_rest_parameter_cannot_be_optional: { code: 1047, category: 1 /* Error */, key: "A rest parameter cannot be optional.", isEarly: true }, + A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: 1 /* Error */, key: "A rest parameter cannot have an initializer.", isEarly: true }, + A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: 1 /* Error */, key: "A 'set' accessor must have exactly one parameter.", isEarly: true }, + A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: 1 /* Error */, key: "A 'set' accessor cannot have an optional parameter.", isEarly: true }, + A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: 1 /* Error */, key: "A 'set' accessor parameter cannot have an initializer.", isEarly: true }, + A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: 1 /* Error */, key: "A 'set' accessor cannot have rest parameter.", isEarly: true }, + A_get_accessor_cannot_have_parameters: { code: 1054, category: 1 /* Error */, key: "A 'get' accessor cannot have parameters.", isEarly: true }, + Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: 1 /* Error */, key: "Accessors are only available when targeting ECMAScript 5 and higher.", isEarly: true }, + Enum_member_must_have_initializer: { code: 1061, category: 1 /* Error */, key: "Enum member must have initializer.", isEarly: true }, + An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: 1 /* Error */, key: "An export assignment cannot be used in an internal module.", isEarly: true }, + Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: 1 /* Error */, key: "Ambient enum elements can only have integer literal initializers.", isEarly: true }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: 1 /* Error */, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, - A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an import declaration." }, + A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1 /* Error */, key: "A 'declare' modifier cannot be used with an import declaration.", isEarly: true }, Invalid_reference_directive_syntax: { code: 1084, category: 1 /* Error */, key: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: 1 /* Error */, key: "Octal literals are not available when targeting ECMAScript 5 and higher." }, - An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: 1 /* Error */, key: "An accessor cannot be declared in an ambient context." }, - _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a constructor declaration." }, - _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a parameter." }, - Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: { code: 1091, category: 1 /* Error */, key: "Only a single variable declaration is allowed in a 'for...in' statement." }, - Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: 1 /* Error */, key: "Type parameters cannot appear on a constructor declaration." }, - Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: 1 /* Error */, key: "Type annotation cannot appear on a constructor declaration." }, - An_accessor_cannot_have_type_parameters: { code: 1094, category: 1 /* Error */, key: "An accessor cannot have type parameters." }, - A_set_accessor_cannot_have_a_return_type_annotation: { code: 1095, category: 1 /* Error */, key: "A 'set' accessor cannot have a return type annotation." }, - An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: 1 /* Error */, key: "An index signature must have exactly one parameter." }, - _0_list_cannot_be_empty: { code: 1097, category: 1 /* Error */, key: "'{0}' list cannot be empty." }, - Type_parameter_list_cannot_be_empty: { code: 1098, category: 1 /* Error */, key: "Type parameter list cannot be empty." }, - Type_argument_list_cannot_be_empty: { code: 1099, category: 1 /* Error */, key: "Type argument list cannot be empty." }, - Invalid_use_of_0_in_strict_mode: { code: 1100, category: 1 /* Error */, key: "Invalid use of '{0}' in strict mode." }, - with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: 1 /* Error */, key: "'with' statements are not allowed in strict mode." }, - delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: 1 /* Error */, key: "'delete' cannot be called on an identifier in strict mode." }, - A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: { code: 1104, category: 1 /* Error */, key: "A 'continue' statement can only be used within an enclosing iteration statement." }, - A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: { code: 1105, category: 1 /* Error */, key: "A 'break' statement can only be used within an enclosing iteration or switch statement." }, - Jump_target_cannot_cross_function_boundary: { code: 1107, category: 1 /* Error */, key: "Jump target cannot cross function boundary." }, - A_return_statement_can_only_be_used_within_a_function_body: { code: 1108, category: 1 /* Error */, key: "A 'return' statement can only be used within a function body." }, - Expression_expected: { code: 1109, category: 1 /* Error */, key: "Expression expected." }, - Type_expected: { code: 1110, category: 1 /* Error */, key: "Type expected." }, - A_constructor_implementation_cannot_be_declared_in_an_ambient_context: { code: 1111, category: 1 /* Error */, key: "A constructor implementation cannot be declared in an ambient context." }, - A_class_member_cannot_be_declared_optional: { code: 1112, category: 1 /* Error */, key: "A class member cannot be declared optional." }, - A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: 1 /* Error */, key: "A 'default' clause cannot appear more than once in a 'switch' statement." }, - Duplicate_label_0: { code: 1114, category: 1 /* Error */, key: "Duplicate label '{0}'" }, - A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: 1 /* Error */, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement." }, - A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: 1 /* Error */, key: "A 'break' statement can only jump to a label of an enclosing statement." }, - An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: 1 /* Error */, key: "An object literal cannot have multiple properties with the same name in strict mode." }, - An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: 1 /* Error */, key: "An object literal cannot have multiple get/set accessors with the same name." }, - An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: 1 /* Error */, key: "An object literal cannot have property and accessor with the same name." }, - An_export_assignment_cannot_have_modifiers: { code: 1120, category: 1 /* Error */, key: "An export assignment cannot have modifiers." }, - Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: 1 /* Error */, key: "Octal literals are not allowed in strict mode." }, - A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: 1 /* Error */, key: "A tuple type element list cannot be empty." }, - Variable_declaration_list_cannot_be_empty: { code: 1123, category: 1 /* Error */, key: "Variable declaration list cannot be empty." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: 1 /* Error */, key: "Octal literals are not available when targeting ECMAScript 5 and higher.", isEarly: true }, + An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: 1 /* Error */, key: "An accessor cannot be declared in an ambient context.", isEarly: true }, + _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a constructor declaration.", isEarly: true }, + _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: 1 /* Error */, key: "'{0}' modifier cannot appear on a parameter.", isEarly: true }, + Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: { code: 1091, category: 1 /* Error */, key: "Only a single variable declaration is allowed in a 'for...in' statement.", isEarly: true }, + Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: 1 /* Error */, key: "Type parameters cannot appear on a constructor declaration.", isEarly: true }, + Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: 1 /* Error */, key: "Type annotation cannot appear on a constructor declaration.", isEarly: true }, + An_accessor_cannot_have_type_parameters: { code: 1094, category: 1 /* Error */, key: "An accessor cannot have type parameters.", isEarly: true }, + A_set_accessor_cannot_have_a_return_type_annotation: { code: 1095, category: 1 /* Error */, key: "A 'set' accessor cannot have a return type annotation.", isEarly: true }, + An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: 1 /* Error */, key: "An index signature must have exactly one parameter.", isEarly: true }, + _0_list_cannot_be_empty: { code: 1097, category: 1 /* Error */, key: "'{0}' list cannot be empty.", isEarly: true }, + Type_parameter_list_cannot_be_empty: { code: 1098, category: 1 /* Error */, key: "Type parameter list cannot be empty.", isEarly: true }, + Type_argument_list_cannot_be_empty: { code: 1099, category: 1 /* Error */, key: "Type argument list cannot be empty.", isEarly: true }, + Invalid_use_of_0_in_strict_mode: { code: 1100, category: 1 /* Error */, key: "Invalid use of '{0}' in strict mode.", isEarly: true }, + with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: 1 /* Error */, key: "'with' statements are not allowed in strict mode.", isEarly: true }, + delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: 1 /* Error */, key: "'delete' cannot be called on an identifier in strict mode.", isEarly: true }, + A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: { code: 1104, category: 1 /* Error */, key: "A 'continue' statement can only be used within an enclosing iteration statement.", isEarly: true }, + A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: { code: 1105, category: 1 /* Error */, key: "A 'break' statement can only be used within an enclosing iteration or switch statement.", isEarly: true }, + Jump_target_cannot_cross_function_boundary: { code: 1107, category: 1 /* Error */, key: "Jump target cannot cross function boundary.", isEarly: true }, + A_return_statement_can_only_be_used_within_a_function_body: { code: 1108, category: 1 /* Error */, key: "A 'return' statement can only be used within a function body.", isEarly: true }, + Expression_expected: { code: 1109, category: 1 /* Error */, key: "Expression expected.", isEarly: true }, + Type_expected: { code: 1110, category: 1 /* Error */, key: "Type expected.", isEarly: true }, + A_class_member_cannot_be_declared_optional: { code: 1112, category: 1 /* Error */, key: "A class member cannot be declared optional.", isEarly: true }, + A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: 1 /* Error */, key: "A 'default' clause cannot appear more than once in a 'switch' statement.", isEarly: true }, + Duplicate_label_0: { code: 1114, category: 1 /* Error */, key: "Duplicate label '{0}'", isEarly: true }, + A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: 1 /* Error */, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement.", isEarly: true }, + A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: 1 /* Error */, key: "A 'break' statement can only jump to a label of an enclosing statement.", isEarly: true }, + An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: 1 /* Error */, key: "An object literal cannot have multiple properties with the same name in strict mode.", isEarly: true }, + An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: 1 /* Error */, key: "An object literal cannot have multiple get/set accessors with the same name.", isEarly: true }, + An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: 1 /* Error */, key: "An object literal cannot have property and accessor with the same name.", isEarly: true }, + An_export_assignment_cannot_have_modifiers: { code: 1120, category: 1 /* Error */, key: "An export assignment cannot have modifiers.", isEarly: true }, + Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: 1 /* Error */, key: "Octal literals are not allowed in strict mode.", isEarly: true }, + A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: 1 /* Error */, key: "A tuple type element list cannot be empty.", isEarly: true }, + Variable_declaration_list_cannot_be_empty: { code: 1123, category: 1 /* Error */, key: "Variable declaration list cannot be empty.", isEarly: true }, Digit_expected: { code: 1124, category: 1 /* Error */, key: "Digit expected." }, Hexadecimal_digit_expected: { code: 1125, category: 1 /* Error */, key: "Hexadecimal digit expected." }, Unexpected_end_of_text: { code: 1126, category: 1 /* Error */, key: "Unexpected end of text." }, @@ -898,52 +896,53 @@ var ts; Enum_member_expected: { code: 1132, category: 1 /* Error */, key: "Enum member expected." }, Type_reference_expected: { code: 1133, category: 1 /* Error */, key: "Type reference expected." }, Variable_declaration_expected: { code: 1134, category: 1 /* Error */, key: "Variable declaration expected." }, - Argument_expression_expected: { code: 1135, category: 1 /* Error */, key: "Argument expression expected." }, + Argument_expression_expected: { code: 1135, category: 1 /* Error */, key: "Argument expression expected.", isEarly: true }, Property_assignment_expected: { code: 1136, category: 1 /* Error */, key: "Property assignment expected." }, Expression_or_comma_expected: { code: 1137, category: 1 /* Error */, key: "Expression or comma expected." }, Parameter_declaration_expected: { code: 1138, category: 1 /* Error */, key: "Parameter declaration expected." }, Type_parameter_declaration_expected: { code: 1139, category: 1 /* Error */, key: "Type parameter declaration expected." }, Type_argument_expected: { code: 1140, category: 1 /* Error */, key: "Type argument expected." }, - String_literal_expected: { code: 1141, category: 1 /* Error */, key: "String literal expected." }, - Line_break_not_permitted_here: { code: 1142, category: 1 /* Error */, key: "Line break not permitted here." }, + String_literal_expected: { code: 1141, category: 1 /* Error */, key: "String literal expected.", isEarly: true }, + Line_break_not_permitted_here: { code: 1142, category: 1 /* Error */, key: "Line break not permitted here.", isEarly: true }, or_expected: { code: 1144, category: 1 /* Error */, key: "'{' or ';' expected." }, - Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: 1 /* Error */, key: "Modifiers not permitted on index signature members." }, + Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: 1 /* Error */, key: "Modifiers not permitted on index signature members.", isEarly: true }, Declaration_expected: { code: 1146, category: 1 /* Error */, key: "Declaration expected." }, - Import_declarations_in_an_internal_module_cannot_reference_an_external_module: { code: 1147, category: 1 /* Error */, key: "Import declarations in an internal module cannot reference an external module." }, + Import_declarations_in_an_internal_module_cannot_reference_an_external_module: { code: 1147, category: 1 /* Error */, key: "Import declarations in an internal module cannot reference an external module.", isEarly: true }, Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: 1 /* Error */, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: 1 /* Error */, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, - new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead.", isEarly: true }, var_let_or_const_expected: { code: 1152, category: 1 /* Error */, key: "'var', 'let' or 'const' expected." }, - let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: 1 /* Error */, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, - const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: 1 /* Error */, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, - const_declarations_must_be_initialized: { code: 1155, category: 1 /* Error */, key: "'const' declarations must be initialized" }, - const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1 /* Error */, key: "'const' declarations can only be declared inside a block." }, - let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1 /* Error */, key: "'let' declarations can only be declared inside a block." }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1 /* Error */, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, + let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: 1 /* Error */, key: "'let' declarations are only available when targeting ECMAScript 6 and higher.", isEarly: true }, + const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: 1 /* Error */, key: "'const' declarations are only available when targeting ECMAScript 6 and higher.", isEarly: true }, + const_declarations_must_be_initialized: { code: 1155, category: 1 /* Error */, key: "'const' declarations must be initialized", isEarly: true }, + const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1 /* Error */, key: "'const' declarations can only be declared inside a block.", isEarly: true }, + let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1 /* Error */, key: "'let' declarations can only be declared inside a block.", isEarly: true }, + Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1 /* Error */, key: "Tagged templates are only available when targeting ECMAScript 6 and higher.", isEarly: true }, Unterminated_template_literal: { code: 1160, category: 1 /* Error */, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: 1 /* Error */, key: "Unterminated regular expression literal." }, - An_object_member_cannot_be_declared_optional: { code: 1162, category: 1 /* Error */, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1 /* Error */, key: "'yield' expression must be contained_within a generator declaration." }, - Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: 1 /* Error */, key: "Computed property names are not allowed in enums." }, - Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: 1 /* Error */, key: "Computed property names are not allowed in an ambient context." }, - Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: 1 /* Error */, key: "Computed property names are not allowed in class property declarations." }, - Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: 1 /* Error */, key: "Computed property names are only available when targeting ECMAScript 6 and higher." }, - Computed_property_names_are_not_allowed_in_method_overloads: { code: 1168, category: 1 /* Error */, key: "Computed property names are not allowed in method overloads." }, - Computed_property_names_are_not_allowed_in_interfaces: { code: 1169, category: 1 /* Error */, key: "Computed property names are not allowed in interfaces." }, - Computed_property_names_are_not_allowed_in_type_literals: { code: 1170, category: 1 /* Error */, key: "Computed property names are not allowed in type literals." }, + An_object_member_cannot_be_declared_optional: { code: 1162, category: 1 /* Error */, key: "An object member cannot be declared optional.", isEarly: true }, + yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1 /* Error */, key: "'yield' expression must be contained_within a generator declaration.", isEarly: true }, + Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: 1 /* Error */, key: "Computed property names are not allowed in enums.", isEarly: true }, + Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: 1 /* Error */, key: "Computed property names are not allowed in an ambient context.", isEarly: true }, + Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: 1 /* Error */, key: "Computed property names are not allowed in class property declarations.", isEarly: true }, + Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: 1 /* Error */, key: "Computed property names are only available when targeting ECMAScript 6 and higher.", isEarly: true }, + Computed_property_names_are_not_allowed_in_method_overloads: { code: 1168, category: 1 /* Error */, key: "Computed property names are not allowed in method overloads.", isEarly: true }, + Computed_property_names_are_not_allowed_in_interfaces: { code: 1169, category: 1 /* Error */, key: "Computed property names are not allowed in interfaces.", isEarly: true }, + Computed_property_names_are_not_allowed_in_type_literals: { code: 1170, category: 1 /* Error */, key: "Computed property names are not allowed in type literals.", isEarly: true }, A_comma_expression_is_not_allowed_in_a_computed_property_name: { code: 1171, category: 1 /* Error */, key: "A comma expression is not allowed in a computed property name." }, - extends_clause_already_seen: { code: 1172, category: 1 /* Error */, key: "'extends' clause already seen." }, - extends_clause_must_precede_implements_clause: { code: 1173, category: 1 /* Error */, key: "'extends' clause must precede 'implements' clause." }, - Classes_can_only_extend_a_single_class: { code: 1174, category: 1 /* Error */, key: "Classes can only extend a single class." }, - implements_clause_already_seen: { code: 1175, category: 1 /* Error */, key: "'implements' clause already seen." }, - Interface_declaration_cannot_have_implements_clause: { code: 1176, category: 1 /* Error */, key: "Interface declaration cannot have 'implements' clause." }, + extends_clause_already_seen: { code: 1172, category: 1 /* Error */, key: "'extends' clause already seen.", isEarly: true }, + extends_clause_must_precede_implements_clause: { code: 1173, category: 1 /* Error */, key: "'extends' clause must precede 'implements' clause.", isEarly: true }, + Classes_can_only_extend_a_single_class: { code: 1174, category: 1 /* Error */, key: "Classes can only extend a single class.", isEarly: true }, + implements_clause_already_seen: { code: 1175, category: 1 /* Error */, key: "'implements' clause already seen.", isEarly: true }, + Interface_declaration_cannot_have_implements_clause: { code: 1176, category: 1 /* Error */, key: "Interface declaration cannot have 'implements' clause.", isEarly: true }, Binary_digit_expected: { code: 1177, category: 1 /* Error */, key: "Binary digit expected." }, Octal_digit_expected: { code: 1178, category: 1 /* Error */, key: "Octal digit expected." }, Unexpected_token_expected: { code: 1179, category: 1 /* Error */, key: "Unexpected token. '{' expected." }, Property_destructuring_pattern_expected: { code: 1180, category: 1 /* Error */, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: 1 /* Error */, key: "Array element destructuring pattern expected." }, - A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1 /* Error */, key: "A destructuring declaration must have an initializer." }, - Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1 /* Error */, key: "Destructuring declarations are not allowed in ambient contexts." }, + A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1 /* Error */, key: "A destructuring declaration must have an initializer.", isEarly: true }, + Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1 /* Error */, key: "Destructuring declarations are not allowed in ambient contexts.", isEarly: true }, + An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: 1 /* Error */, key: "An implementation cannot be declared in ambient contexts.", isEarly: true }, Merge_conflict_marker_encountered: { code: 1184, category: 1 /* Error */, key: "Merge conflict marker encountered." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, @@ -1235,9 +1234,9 @@ var 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: 1 /* 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: 1 /* 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: 1 /* Error */, key: "You cannot rename this element." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported." }, - Computed_property_names_are_not_currently_supported: { code: 9002, category: 1 /* Error */, key: "Computed property names are not currently supported." } + yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported.", isEarly: true }, + Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported.", isEarly: true }, + Computed_property_names_are_not_currently_supported: { code: 9002, category: 1 /* Error */, key: "Computed property names are not currently supported.", isEarly: true } }; })(ts || (ts = {})); var ts; @@ -2396,18 +2395,20 @@ var ts; function hasFlag(val, flag) { return (val & flag) !== 0; } - ts.hasFlag = hasFlag; function containsParseError(node) { - if (!hasFlag(node.parserContextFlags, 64 /* HasComputedThisNodeOrAnySubNodesHasError */)) { - var val = hasFlag(node.parserContextFlags, 16 /* ThisNodeHasError */) || ts.forEachChild(node, containsParseError); - if (val) { - node.parserContextFlags |= 32 /* ThisNodeOrAnySubNodesHasError */; - } - node.parserContextFlags |= 64 /* HasComputedThisNodeOrAnySubNodesHasError */; - } + aggregateChildData(node); return hasFlag(node.parserContextFlags, 32 /* ThisNodeOrAnySubNodesHasError */); } ts.containsParseError = containsParseError; + function aggregateChildData(node) { + if (!hasFlag(node.parserContextFlags, 64 /* HasAggregatedChildData */)) { + var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, 16 /* ThisNodeHasError */) || ts.forEachChild(node, containsParseError); + if (thisNodeOrAnySubNodesHasError) { + node.parserContextFlags |= 32 /* ThisNodeOrAnySubNodesHasError */; + } + node.parserContextFlags |= 64 /* HasAggregatedChildData */; + } + } function getSourceFileOfNode(node) { while (node && node.kind !== 207 /* SourceFile */) { node = node.parent; @@ -3034,7 +3035,7 @@ var ts; case 121 /* QualifiedName */: return child(node.left) || child(node.right); case 123 /* TypeParameter */: - return child(node.name) || child(node.constraint); + return child(node.name) || child(node.constraint) || child(node.expression); case 124 /* Parameter */: case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: @@ -3274,6 +3275,7 @@ var ts; } return 0; } + ts.modifierToFlag = modifierToFlag; function fixupParentReferences(sourceFile) { var parent = sourceFile; function walk(n) { @@ -3290,6 +3292,7 @@ var ts; function isEvalOrArgumentsIdentifier(node) { return node.kind === 64 /* Identifier */ && (node.text === "eval" || node.text === "arguments"); } + ts.isEvalOrArgumentsIdentifier = isEvalOrArgumentsIdentifier; function isUseStrictPrologueDirective(sourceFile, node) { ts.Debug.assert(ts.isPrologueDirective(node)); var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); @@ -5155,42 +5158,40 @@ var ts; parseSemicolon(ts.Diagnostics.or_expected); return undefined; } - function parseBindingElement(context) { - if (context === 11 /* ArrayBindingElements */ && token === 23 /* CommaToken */) { + function parseArrayBindingElement() { + if (token === 23 /* CommaToken */) { return createNode(167 /* OmittedExpression */); } var node = createNode(146 /* BindingElement */); - if (context === 10 /* ObjectBindingElements */) { - var id = parsePropertyName(); - if (id.kind === 64 /* Identifier */ && token !== 51 /* ColonToken */) { - node.name = id; - } - else { - parseExpected(51 /* ColonToken */); - node.propertyName = id; - node.name = parseIdentifierOrPattern(); - } + node.name = parseIdentifierOrPattern(); + node.initializer = parseInitializer(false); + return finishNode(node); + } + function parseObjectBindingElement() { + var node = createNode(146 /* BindingElement */); + var id = parsePropertyName(); + if (id.kind === 64 /* Identifier */ && token !== 51 /* ColonToken */) { + node.name = id; } else { + parseExpected(51 /* ColonToken */); + node.propertyName = id; node.name = parseIdentifierOrPattern(); } node.initializer = parseInitializer(false); return finishNode(node); } - function parseBindingList(context) { - return parseDelimitedList(context, function () { return parseBindingElement(context); }); - } function parseObjectBindingPattern() { var node = createNode(144 /* ObjectBindingPattern */); parseExpected(14 /* OpenBraceToken */); - node.elements = parseBindingList(10 /* ObjectBindingElements */); + node.elements = parseDelimitedList(10 /* ObjectBindingElements */, parseObjectBindingElement); parseExpected(15 /* CloseBraceToken */); return finishNode(node); } function parseArrayBindingPattern() { var node = createNode(145 /* ArrayBindingPattern */); parseExpected(18 /* OpenBracketToken */); - node.elements = parseBindingList(11 /* ArrayBindingElements */); + node.elements = parseDelimitedList(11 /* ArrayBindingElements */, parseArrayBindingElement); parseExpected(19 /* CloseBracketToken */); return finishNode(node); } @@ -5669,13 +5670,7 @@ var ts; var syntacticDiagnostics; function getSyntacticDiagnostics() { if (syntacticDiagnostics === undefined) { - if (sourceFile.parseDiagnostics.length > 0) { - syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); - } - else { - checkGrammar(sourceText, languageVersion, sourceFile); - syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.grammarDiagnostics); - } + syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); } ts.Debug.assert(syntacticDiagnostics !== undefined); return syntacticDiagnostics; @@ -5710,1028 +5705,11 @@ var ts; } return false; } + ts.isLeftHandSideExpression = isLeftHandSideExpression; function isAssignmentOperator(token) { return token >= 52 /* FirstAssignment */ && token <= 63 /* LastAssignment */; } - function checkGrammar(sourceText, languageVersion, file) { - var grammarDiagnostics = file.grammarDiagnostics; - var scanner = ts.createScanner(languageVersion, true, sourceText); - var inAmbientContext = ts.fileExtensionIs(file.filename, ".d.ts"); - var inFunctionBlock = false; - var parent; - visitNode(file); - function visitNode(node) { - var savedParent = parent; - node.parent = parent; - parent = node; - if (!checkModifiers(node)) { - var savedInFunctionBlock = inFunctionBlock; - if (ts.isFunctionBlock(node)) { - inFunctionBlock = true; - } - var savedInAmbientContext = inAmbientContext; - if (node.flags & 2 /* Ambient */) { - inAmbientContext = true; - } - checkNodeAndChildren(node); - inAmbientContext = savedInAmbientContext; - inFunctionBlock = savedInFunctionBlock; - } - parent = savedParent; - } - function checkNodeAndChildren(node) { - var nodeKind = node.kind; - if (inAmbientContext && checkForStatementInAmbientContext(node, nodeKind)) { - return; - } - if (checkNode(node, nodeKind)) { - return; - } - forEachChild(node, visitNode); - } - function checkNode(node, nodeKind) { - switch (nodeKind) { - case 157 /* ArrowFunction */: - case 132 /* CallSignature */: - case 137 /* ConstructorType */: - case 133 /* ConstructSignature */: - case 136 /* FunctionType */: - return checkAnySignatureDeclaration(node); - case 179 /* BreakStatement */: - case 178 /* ContinueStatement */: - return checkBreakOrContinueStatement(node); - case 151 /* CallExpression */: - case 152 /* NewExpression */: - return checkCallOrNewExpression(node); - case 194 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 163 /* BinaryExpression */: return checkBinaryExpression(node); - case 146 /* BindingElement */: return checkBindingElement(node); - case 203 /* CatchClause */: return checkCatchClause(node); - case 191 /* ClassDeclaration */: return checkClassDeclaration(node); - case 122 /* ComputedPropertyName */: return checkComputedPropertyName(node); - case 129 /* Constructor */: return checkConstructor(node); - case 158 /* DeleteExpression */: return checkDeleteExpression(node); - case 150 /* ElementAccessExpression */: return checkElementAccessExpression(node); - case 198 /* ExportAssignment */: return checkExportAssignment(node); - case 199 /* ExternalModuleReference */: return checkExternalModuleReference(node); - case 177 /* ForInStatement */: return checkForInStatement(node); - case 176 /* ForStatement */: return checkForStatement(node); - case 190 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 156 /* FunctionExpression */: return checkFunctionExpression(node); - case 130 /* GetAccessor */: return checkGetAccessor(node); - case 202 /* HeritageClause */: return checkHeritageClause(node); - case 134 /* IndexSignature */: return checkIndexSignature(node); - case 192 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 183 /* LabeledStatement */: return checkLabeledStatement(node); - case 204 /* PropertyAssignment */: return checkPropertyAssignment(node); - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - return checkMethod(node); - case 195 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 148 /* ObjectLiteralExpression */: return checkObjectLiteralExpression(node); - case 7 /* NumericLiteral */: return checkNumericLiteral(node); - case 124 /* Parameter */: return checkParameter(node); - case 162 /* PostfixUnaryExpression */: return checkPostfixUnaryExpression(node); - case 161 /* PrefixUnaryExpression */: return checkPrefixUnaryExpression(node); - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - return checkProperty(node); - case 180 /* ReturnStatement */: return checkReturnStatement(node); - case 131 /* SetAccessor */: return checkSetAccessor(node); - case 207 /* SourceFile */: return checkSourceFile(node); - case 205 /* ShorthandPropertyAssignment */: return checkShorthandPropertyAssignment(node); - case 182 /* SwitchStatement */: return checkSwitchStatement(node); - case 153 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node); - case 184 /* ThrowStatement */: return checkThrowStatement(node); - case 141 /* TupleType */: return checkTupleType(node); - case 123 /* TypeParameter */: return checkTypeParameter(node); - case 135 /* TypeReference */: return checkTypeReference(node); - case 189 /* VariableDeclaration */: return checkVariableDeclaration(node); - case 170 /* VariableStatement */: return checkVariableStatement(node); - case 181 /* WithStatement */: return checkWithStatement(node); - case 166 /* YieldExpression */: return checkYieldExpression(node); - } - } - function scanToken(pos) { - var start = ts.skipTrivia(sourceText, pos); - scanner.setTextPos(start); - scanner.scan(); - return start; - } - function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { - var start = scanToken(node.pos); - grammarDiagnostics.push(ts.createFileDiagnostic(file, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); - return true; - } - function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { - scanToken(node.pos); - grammarDiagnostics.push(ts.createFileDiagnostic(file, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); - return true; - } - function grammarErrorOnNode(node, message, arg0, arg1, arg2) { - var span = ts.getErrorSpanForNode(node); - var start = span.end > span.pos ? ts.skipTrivia(file.text, span.pos) : span.pos; - var length = span.end - start; - grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); - return true; - } - function grammarErrorAtPos(start, length, message, arg0, arg1, arg2) { - grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); - return true; - } - function reportInvalidUseInStrictMode(node) { - var name = sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); - return grammarErrorOnNode(node, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); - } - function checkForStatementInAmbientContext(node, kind) { - switch (kind) { - case 169 /* Block */: - case 171 /* EmptyStatement */: - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 178 /* ContinueStatement */: - case 179 /* BreakStatement */: - case 180 /* ReturnStatement */: - case 181 /* WithStatement */: - case 182 /* SwitchStatement */: - case 184 /* ThrowStatement */: - case 185 /* TryStatement */: - case 188 /* DebuggerStatement */: - case 183 /* LabeledStatement */: - case 172 /* ExpressionStatement */: - return grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); - } - } - function checkAnySignatureDeclaration(node) { - return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); - } - function checkBinaryExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */) { - if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operator)) { - if (isEvalOrArgumentsIdentifier(node.left)) { - return reportInvalidUseInStrictMode(node.left); - } - } - } - } - function isIterationStatement(node, lookInLabeledStatements) { - switch (node.kind) { - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - return true; - case 183 /* LabeledStatement */: - return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); - } - return false; - } - function checkLabeledStatement(node) { - var current = node.parent; - while (current) { - if (ts.isAnyFunction(current)) { - break; - } - if (current.kind === 183 /* LabeledStatement */ && current.label.text === node.label.text) { - return grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceText, node.label)); - } - current = current.parent; - } - } - function checkBreakOrContinueStatement(node) { - var current = node; - while (current) { - if (ts.isAnyFunction(current)) { - return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); - } - switch (current.kind) { - case 183 /* LabeledStatement */: - if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 178 /* ContinueStatement */ && !isIterationStatement(current.statement, true); - if (isMisplacedContinueLabel) { - return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); - } - return false; - } - break; - case 182 /* SwitchStatement */: - if (node.kind === 179 /* BreakStatement */ && !node.label) { - return false; - } - break; - default: - if (isIterationStatement(current, false) && !node.label) { - return false; - } - break; - } - current = current.parent; - } - if (node.label) { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; - return grammarErrorOnNode(node, message); - } - else { - var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; - return grammarErrorOnNode(node, message); - } - } - function checkCallOrNewExpression(node) { - return checkTypeArguments(node.typeArguments) || checkArguments(node.arguments); - } - function checkArguments(arguments) { - return checkForDisallowedTrailingComma(arguments) || checkForOmittedArgument(arguments); - } - function checkTypeArguments(typeArguments) { - return checkForDisallowedTrailingComma(typeArguments) || checkForAtLeastOneTypeArgument(typeArguments); - } - function checkForOmittedArgument(arguments) { - if (arguments) { - for (var i = 0, n = arguments.length; i < n; i++) { - var arg = arguments[i]; - if (arg.kind === 167 /* OmittedExpression */) { - return grammarErrorAtPos(arg.pos, 0, ts.Diagnostics.Argument_expression_expected); - } - } - } - } - function checkForAtLeastOneTypeArgument(typeArguments) { - if (typeArguments && typeArguments.length === 0) { - var start = typeArguments.pos - "<".length; - var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); - } - } - function checkForDisallowedTrailingComma(list) { - if (list && list.hasTrailingComma) { - var start = list.end - ",".length; - var end = list.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Trailing_comma_not_allowed); - } - } - function checkCatchClause(node) { - if (node.type) { - var colonStart = ts.skipTrivia(sourceText, node.name.end); - return grammarErrorAtPos(colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); - } - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkClassDeclaration(node) { - return checkClassDeclarationHeritageClauses(node); - } - function checkClassDeclarationHeritageClauses(node) { - var seenExtendsClause = false; - var seenImplementsClause = false; - if (node.heritageClauses) { - for (var i = 0, n = node.heritageClauses.length; i < n; i++) { - ts.Debug.assert(i <= 2); - var heritageClause = node.heritageClauses[i]; - if (heritageClause.token === 78 /* ExtendsKeyword */) { - if (seenExtendsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); - } - if (seenImplementsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause); - } - if (heritageClause.types.length > 1) { - return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class); - } - seenExtendsClause = true; - } - else { - ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); - if (seenImplementsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); - } - seenImplementsClause = true; - } - } - } - return false; - } - function checkForAtLeastOneHeritageClause(types, listType) { - if (types && types.length === 0) { - return grammarErrorAtPos(types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType); - } - } - function checkConstructor(node) { - return checkAnySignatureDeclaration(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, true); - } - function checkConstructorTypeParameters(node) { - if (node.typeParameters) { - return grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); - } - } - function checkConstructorTypeAnnotation(node) { - if (node.type) { - return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration); - } - } - function checkDeleteExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && node.expression.kind === 64 /* Identifier */) { - return grammarErrorOnNode(node.expression, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); - } - } - function checkEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 4096 /* Const */) !== 0; - var hasError = false; - if (!enumIsConst) { - var inConstantEnumMemberSection = true; - for (var i = 0, n = enumDecl.members.length; i < n; i++) { - var node = enumDecl.members[i]; - if (node.name.kind === 122 /* ComputedPropertyName */) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); - } - else if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer)) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; - } - } - } - return hasError; - } - function isIntegerLiteral(expression) { - function isInteger(literalExpression) { - return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); - } - if (expression.kind === 161 /* PrefixUnaryExpression */) { - var unaryExpression = expression; - if (unaryExpression.operator === 33 /* PlusToken */ || unaryExpression.operator === 34 /* MinusToken */) { - expression = unaryExpression.operand; - } - } - if (expression.kind === 7 /* NumericLiteral */) { - return isInteger(expression); - } - return false; - } - function checkExportAssignment(node) { - if (node.flags & 243 /* Modifier */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); - } - } - function checkExternalModuleReference(node) { - if (node.expression.kind !== 8 /* StringLiteral */) { - return grammarErrorOnNode(node.expression, ts.Diagnostics.String_literal_expected); - } - } - function checkForInStatement(node) { - return checkVariableDeclarations(node.declarations) || checkForMoreThanOneDeclaration(node.declarations); - } - function checkForStatement(node) { - return checkVariableDeclarations(node.declarations); - } - function checkForMoreThanOneDeclaration(declarations) { - if (declarations && declarations.length > 1) { - return grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); - } - } - function checkFunctionDeclaration(node) { - return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, false) || checkForGenerator(node); - } - function checkForGenerator(node) { - if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); - } - } - function checkFunctionExpression(node) { - return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForGenerator(node); - } - function checkFunctionName(name) { - if (name && name.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(name)) { - return reportInvalidUseInStrictMode(name); - } - } - function checkGetAccessor(node) { - return checkAnySignatureDeclaration(node) || checkAccessor(node); - } - function checkElementAccessExpression(node) { - if (!node.argumentExpression) { - if (node.parent.kind === 152 /* NewExpression */ && node.parent.expression === node) { - var start = ts.skipTrivia(sourceText, node.expression.end); - var end = node.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); - } - else { - var start = node.end - "]".length; - var end = node.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Expression_expected); - } - } - } - function checkHeritageClause(node) { - return checkForDisallowedTrailingComma(node.types) || checkForAtLeastOneHeritageClause(node.types, ts.tokenToString(node.token)); - } - function checkIndexSignature(node) { - return checkIndexSignatureParameters(node) || checkForIndexSignatureModifiers(node); - } - function checkForIndexSignatureModifiers(node) { - if (node.flags & 243 /* Modifier */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); - } - } - function checkIndexSignatureParameters(node) { - var parameter = node.parameters[0]; - if (node.parameters.length !== 1) { - if (parameter) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); - } - else { - return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); - } - } - else if (parameter.dotDotDotToken) { - return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); - } - else if (parameter.flags & 243 /* Modifier */) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); - } - else if (parameter.questionToken) { - return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); - } - else if (parameter.initializer) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); - } - else if (!parameter.type) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); - } - else if (parameter.type.kind !== 119 /* StringKeyword */ && parameter.type.kind !== 117 /* NumberKeyword */) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); - } - else if (!node.type) { - return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation); - } - } - function checkInterfaceDeclaration(node) { - return checkInterfaceDeclarationHeritageClauses(node); - } - function checkInterfaceDeclarationHeritageClauses(node) { - var seenExtendsClause = false; - if (node.heritageClauses) { - for (var i = 0, n = node.heritageClauses.length; i < n; i++) { - ts.Debug.assert(i <= 1); - var heritageClause = node.heritageClauses[i]; - if (heritageClause.token === 78 /* ExtendsKeyword */) { - if (seenExtendsClause) { - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); - } - seenExtendsClause = true; - } - else { - ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); - return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); - } - } - } - return false; - } - function checkMethod(node) { - if (checkAnySignatureDeclaration(node) || checkForBodyInAmbientContext(node.body, false) || checkForGenerator(node)) { - return true; - } - if (node.parent.kind === 191 /* ClassDeclaration */) { - if (checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { - return true; - } - if (inAmbientContext) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_an_ambient_context); - } - else if (!node.body) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); - } - } - else if (node.parent.kind === 192 /* InterfaceDeclaration */) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces); - } - else if (node.parent.kind === 139 /* TypeLiteral */) { - return checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals); - } - } - function checkForBodyInAmbientContext(body, isConstructor) { - if (inAmbientContext && body && body.kind === 169 /* Block */) { - var diagnostic = isConstructor ? ts.Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : ts.Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; - return grammarErrorOnFirstToken(body, diagnostic); - } - } - function checkModuleDeclaration(node) { - return checkModuleDeclarationName(node) || checkModuleDeclarationStatements(node); - } - function checkModuleDeclarationName(node) { - if (!inAmbientContext && node.name.kind === 8 /* StringLiteral */) { - return grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); - } - } - function checkModuleDeclarationStatements(node) { - if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 198 /* ExportAssignment */) { - return grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - else if (ts.isExternalModuleImportDeclaration(statement)) { - return grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); - } - } - } - } - function checkObjectLiteralExpression(node) { - var seen = {}; - var Property = 1; - var GetAccessor = 2; - var SetAccesor = 4; - var GetOrSetAccessor = GetAccessor | SetAccesor; - var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; - for (var i = 0, n = node.properties.length; i < n; i++) { - var prop = node.properties[i]; - var name = prop.name; - if (prop.kind === 167 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { - continue; - } - var currentKind; - if (prop.kind === 204 /* PropertyAssignment */ || prop.kind === 205 /* ShorthandPropertyAssignment */ || prop.kind === 128 /* MethodDeclaration */) { - currentKind = Property; - } - else if (prop.kind === 130 /* GetAccessor */) { - currentKind = GetAccessor; - } - else if (prop.kind === 131 /* SetAccessor */) { - currentKind = SetAccesor; - } - else { - ts.Debug.fail("Unexpected syntax kind:" + prop.kind); - } - if (!ts.hasProperty(seen, name.text)) { - seen[name.text] = currentKind; - } - else { - var existingKind = seen[name.text]; - if (currentKind === Property && existingKind === Property) { - if (inStrictMode) { - grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); - } - } - else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { - if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name.text] = currentKind | existingKind; - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); - } - } - } - } - function checkNumericLiteral(node) { - if (node.flags & 8192 /* OctalLiteral */) { - if (node.parserContextFlags & 1 /* StrictMode */) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); - } - else if (languageVersion >= 1 /* ES5 */) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); - } - } - } - function checkModifiers(node) { - switch (node.kind) { - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - case 129 /* Constructor */: - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - case 134 /* IndexSignature */: - case 191 /* ClassDeclaration */: - case 192 /* InterfaceDeclaration */: - case 195 /* ModuleDeclaration */: - case 194 /* EnumDeclaration */: - case 198 /* ExportAssignment */: - case 170 /* VariableStatement */: - case 190 /* FunctionDeclaration */: - case 193 /* TypeAliasDeclaration */: - case 197 /* ImportDeclaration */: - case 124 /* Parameter */: - break; - default: - return false; - } - if (!node.modifiers) { - return; - } - var lastStatic, lastPrivate, lastProtected, lastDeclare; - var flags = 0; - for (var i = 0, n = node.modifiers.length; i < n; i++) { - var modifier = node.modifiers[i]; - switch (modifier.kind) { - case 107 /* PublicKeyword */: - case 106 /* ProtectedKeyword */: - case 105 /* PrivateKeyword */: - var text; - if (modifier.kind === 107 /* PublicKeyword */) { - text = "public"; - } - else if (modifier.kind === 106 /* ProtectedKeyword */) { - text = "protected"; - lastProtected = modifier; - } - else { - text = "private"; - lastPrivate = modifier; - } - if (flags & 112 /* AccessibilityModifier */) { - return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen); - } - else if (flags & 128 /* Static */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); - } - else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); - } - flags |= modifierToFlag(modifier.kind); - break; - case 108 /* StaticKeyword */: - if (flags & 128 /* Static */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); - } - else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); - } - else if (node.kind === 124 /* Parameter */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); - } - flags |= 128 /* Static */; - lastStatic = modifier; - break; - case 77 /* ExportKeyword */: - if (flags & 1 /* Export */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); - } - else if (flags & 2 /* Ambient */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); - } - else if (node.parent.kind === 191 /* ClassDeclaration */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); - } - else if (node.kind === 124 /* Parameter */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); - } - flags |= 1 /* Export */; - break; - case 113 /* DeclareKeyword */: - if (flags & 2 /* Ambient */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); - } - else if (node.parent.kind === 191 /* ClassDeclaration */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); - } - else if (node.kind === 124 /* Parameter */) { - return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); - } - else if (inAmbientContext && node.parent.kind === 196 /* ModuleBlock */) { - return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); - } - flags |= 2 /* Ambient */; - lastDeclare = modifier; - break; - } - } - if (node.kind === 129 /* Constructor */) { - if (flags & 128 /* Static */) { - return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); - } - else if (flags & 64 /* Protected */) { - return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); - } - else if (flags & 32 /* Private */) { - return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); - } - } - else if (node.kind === 197 /* ImportDeclaration */ && flags & 2 /* Ambient */) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); - } - else if (node.kind === 192 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } - } - function checkParameter(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkTypeParameterList(typeParameters) { - if (checkForDisallowedTrailingComma(typeParameters)) { - return true; - } - if (typeParameters && typeParameters.length === 0) { - var start = typeParameters.pos - "<".length; - var end = ts.skipTrivia(sourceText, typeParameters.end) + ">".length; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty); - } - } - function checkParameterList(parameters) { - if (checkForDisallowedTrailingComma(parameters)) { - return true; - } - var seenOptionalParameter = false; - var parameterCount = parameters.length; - for (var i = 0; i < parameterCount; i++) { - var parameter = parameters[i]; - if (parameter.dotDotDotToken) { - if (i !== (parameterCount - 1)) { - return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); - } - if (parameter.questionToken) { - return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional); - } - if (parameter.initializer) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer); - } - } - else if (parameter.questionToken || parameter.initializer) { - seenOptionalParameter = true; - if (parameter.questionToken && parameter.initializer) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer); - } - } - else { - if (seenOptionalParameter) { - return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); - } - } - } - } - function checkPostfixUnaryExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.operand)) { - return reportInvalidUseInStrictMode(node.operand); - } - } - function checkPrefixUnaryExpression(node) { - if (node.parserContextFlags & 1 /* StrictMode */) { - if ((node.operator === 38 /* PlusPlusToken */ || node.operator === 39 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(node.operand)) { - return reportInvalidUseInStrictMode(node.operand); - } - } - } - function checkProperty(node) { - if (node.parent.kind === 191 /* ClassDeclaration */) { - if (checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_class_property_declarations)) { - return true; - } - } - else if (node.parent.kind === 192 /* InterfaceDeclaration */) { - if (checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces)) { - return true; - } - } - else if (node.parent.kind === 139 /* TypeLiteral */) { - if (checkForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals)) { - return true; - } - } - return checkForInitializerInAmbientContext(node); - } - function checkComputedPropertyName(node) { - return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_not_currently_supported); - if (languageVersion < 2 /* ES6 */) { - return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (node.expression.kind === 163 /* BinaryExpression */ && node.expression.operator === 23 /* CommaToken */) { - return grammarErrorOnNode(node.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); - } - } - function checkForDisallowedComputedProperty(node, message) { - if (node.kind === 122 /* ComputedPropertyName */) { - return grammarErrorOnNode(node, message); - } - } - function checkForInitializerInAmbientContext(node) { - if (inAmbientContext && node.initializer) { - return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - function checkPropertyAssignment(node) { - return checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - } - function checkForInvalidQuestionMark(node, questionToken, message) { - if (questionToken) { - return grammarErrorOnNode(questionToken, message); - } - } - function checkReturnStatement(node) { - if (!inFunctionBlock) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); - } - } - function checkSetAccessor(node) { - return checkAnySignatureDeclaration(node) || checkAccessor(node); - } - function checkAccessor(accessor) { - var kind = accessor.kind; - if (languageVersion < 1 /* ES5 */) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (inAmbientContext) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); - } - else if (accessor.body === undefined) { - return grammarErrorAtPos(accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); - } - else if (accessor.typeParameters) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); - } - else if (kind === 130 /* GetAccessor */ && accessor.parameters.length) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); - } - else if (kind === 131 /* SetAccessor */) { - if (accessor.type) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); - } - else if (accessor.parameters.length !== 1) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter); - } - else { - var parameter = accessor.parameters[0]; - if (parameter.dotDotDotToken) { - return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter); - } - else if (parameter.flags & 243 /* Modifier */) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); - } - else if (parameter.questionToken) { - return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); - } - else if (parameter.initializer) { - return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer); - } - } - } - } - function checkSourceFile(node) { - return inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file); - } - function checkTopLevelElementsForRequiredDeclareModifier(file) { - for (var i = 0, n = file.statements.length; i < n; i++) { - var decl = file.statements[i]; - if (ts.isDeclaration(decl) || decl.kind === 170 /* VariableStatement */) { - if (checkTopLevelElementForRequiredDeclareModifier(decl)) { - return true; - } - } - } - } - function checkTopLevelElementForRequiredDeclareModifier(node) { - if (node.kind === 192 /* InterfaceDeclaration */ || node.kind === 197 /* ImportDeclaration */ || node.kind === 198 /* ExportAssignment */ || (node.flags & 2 /* Ambient */)) { - return false; - } - return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); - } - function checkShorthandPropertyAssignment(node) { - return checkForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - } - function checkSwitchStatement(node) { - var firstDefaultClause; - for (var i = 0, n = node.clauses.length; i < n; i++) { - var clause = node.clauses[i]; - if (clause.kind === 201 /* DefaultClause */) { - if (firstDefaultClause === undefined) { - firstDefaultClause = clause; - } - else { - var start = ts.skipTrivia(file.text, clause.pos); - var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; - return grammarErrorAtPos(start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); - } - } - } - } - function checkTaggedTemplateExpression(node) { - if (languageVersion < 2 /* ES6 */) { - return grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } - function checkThrowStatement(node) { - if (node.expression === undefined) { - return grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here); - } - } - function checkTupleType(node) { - return checkForDisallowedTrailingComma(node.elementTypes) || checkForAtLeastOneType(node); - } - function checkForAtLeastOneType(node) { - if (node.elementTypes.length === 0) { - return grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty); - } - } - function checkTypeParameter(node) { - if (node.expression) { - return grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); - } - } - function checkTypeReference(node) { - return checkTypeArguments(node.typeArguments); - } - function checkBindingElement(node) { - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkVariableDeclaration(node) { - if (inAmbientContext) { - if (ts.isBindingPattern(node.name)) { - return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); - } - if (node.initializer) { - return grammarErrorAtPos(node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - else { - if (!node.initializer) { - if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { - return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); - } - if (ts.isConst(node)) { - return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized); - } - } - } - if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); - } - } - function checkVariableDeclarations(declarations) { - if (declarations) { - if (checkForDisallowedTrailingComma(declarations)) { - return true; - } - if (!declarations.length) { - return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); - } - var decl = declarations[0]; - if (languageVersion < 2 /* ES6 */) { - if (ts.isLet(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(decl)) { - return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } - } - } - function checkVariableStatement(node) { - return checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node); - } - function checkForDisallowedLetOrConstStatement(node) { - if (!allowLetAndConstDeclarations(node.parent)) { - if (ts.isLet(node)) { - return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block); - } - else if (ts.isConst(node)) { - return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block); - } - } - } - function allowLetAndConstDeclarations(parent) { - switch (parent.kind) { - case 173 /* IfStatement */: - case 174 /* DoStatement */: - case 175 /* WhileStatement */: - case 181 /* WithStatement */: - case 176 /* ForStatement */: - case 177 /* ForInStatement */: - return false; - case 183 /* LabeledStatement */: - return allowLetAndConstDeclarations(parent.parent); - } - return true; - } - function checkWithStatement(node) { - if (node.parserContextFlags & 1 /* StrictMode */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode); - } - } - function checkYieldExpression(node) { - if (!(node.parserContextFlags & 4 /* Yield */)) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); - } - return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); - } - } + ts.isAssignmentOperator = isAssignmentOperator; function createProgram(rootNames, options, host) { var program; var files = []; @@ -6816,7 +5794,12 @@ var ts; return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); } var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) { - errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + if (refFile) { + errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage)); + } }); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; @@ -7121,12 +6104,12 @@ var ts; parent = node; if (symbolKind & 262128 /* IsContainer */) { container = node; - if (lastContainer !== container && !container.nextContainer) { - if (lastContainer) { - lastContainer.nextContainer = container; - } - lastContainer = container; + ts.Debug.assert(container.nextContainer === undefined); + if (lastContainer) { + ts.Debug.assert(lastContainer.nextContainer === undefined); + lastContainer.nextContainer = container; } + lastContainer = container; } if (isBlockScopeContainer) { blockScopeContainer = node; @@ -7177,14 +6160,6 @@ var ts; } bindChildren(node, symbolKind, isBlockScopeContainer); } - function bindConstructorDeclaration(node) { - bindDeclaration(node, 16384 /* Constructor */, 0, true); - ts.forEach(node.parameters, function (p) { - if (p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { - bindDeclaration(p, 4 /* Property */, 107455 /* PropertyExcludes */, false); - } - }); - } function bindModuleDeclaration(node) { if (node.name.kind === 8 /* StringLiteral */) { bindDeclaration(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */, true); @@ -7257,12 +6232,7 @@ var ts; bindDeclaration(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */, false); break; case 124 /* Parameter */: - if (ts.isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node), false); - } - else { - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); - } + bindParameter(node); break; case 189 /* VariableDeclaration */: case 146 /* BindingElement */: @@ -7300,7 +6270,7 @@ var ts; bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true); break; case 129 /* Constructor */: - bindConstructorDeclaration(node); + bindDeclaration(node, 16384 /* Constructor */, 0, true); break; case 130 /* GetAccessor */: bindDeclaration(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); @@ -7369,6 +6339,18 @@ var ts; parent = saveParent; } } + function bindParameter(node) { + if (ts.isBindingPattern(node.name)) { + bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node), false); + } + else { + bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); + } + if (node.flags & 112 /* AccessibilityModifier */ && node.parent.kind === 129 /* Constructor */ && node.parent.parent.kind === 191 /* ClassDeclaration */) { + var classDeclaration = node.parent.parent; + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); + } + } } ts.bindSourceFile = bindSourceFile; })(ts || (ts = {})); @@ -11150,6 +10132,11 @@ var ts; if (!links.target) { links.target = resolvingSymbol; var node = ts.getDeclarationOfKind(symbol, 197 /* ImportDeclaration */); + if (node.moduleReference.kind === 199 /* ExternalModuleReference */) { + if (node.moduleReference.expression.kind !== 8 /* StringLiteral */) { + grammarErrorOnNode(node.moduleReference.expression, ts.Diagnostics.String_literal_expected); + } + } var target = node.moduleReference.kind === 199 /* ExternalModuleReference */ ? resolveExternalModuleName(node, ts.getExternalModuleImportDeclarationExpression(node)) : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -14759,10 +13746,34 @@ var ts; return type; } } + function markLinkedImportsAsReferenced(node) { + var nodeLinks = getNodeLinks(node); + while (nodeLinks.importOnRightSide) { + var rightSide = nodeLinks.importOnRightSide; + nodeLinks.importOnRightSide = undefined; + getSymbolLinks(rightSide).referenced = true; + ts.Debug.assert((rightSide.flags & 8388608 /* Import */) !== 0); + nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 197 /* ImportDeclaration */)); + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); if (symbol.flags & 8388608 /* Import */) { - getSymbolLinks(symbol).referenced = getSymbolLinks(symbol).referenced || (!isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol))); + var symbolLinks = getSymbolLinks(symbol); + if (!symbolLinks.referenced) { + var importOrExportAssignment = getLeftSideOfImportOrExportAssignment(node); + if (!importOrExportAssignment || (importOrExportAssignment.flags & 1 /* Export */) || (importOrExportAssignment.kind === 198 /* ExportAssignment */)) { + symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); + } + else { + var nodeLinks = getNodeLinks(importOrExportAssignment); + ts.Debug.assert(!nodeLinks.importOnRightSide); + nodeLinks.importOnRightSide = symbol; + } + } + if (symbolLinks.referenced) { + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197 /* ImportDeclaration */)); + } } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); @@ -15164,6 +14175,7 @@ var ts; return (+name).toString() === name; } function checkObjectLiteral(node, contextualMapper) { + checkGrammarObjectLiteralExpression(node); var members = node.symbol.members; var properties = {}; var contextualType = getContextualType(node); @@ -15318,6 +14330,19 @@ var ts; return true; } function checkIndexedAccess(node) { + if (!node.argumentExpression) { + var sourceFile = getSourceFile(node); + if (node.parent.kind === 152 /* NewExpression */ && node.parent.expression === node) { + var start = ts.skipTrivia(sourceFile.text, node.expression.end); + var end = node.end; + grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); + } + else { + var start = node.end - "]".length; + var end = node.end; + grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Expression_expected); + } + } var objectType = getApparentType(checkExpression(node.expression)); var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType; if (objectType === unknownType) { @@ -15764,6 +14789,7 @@ var ts; return links.resolvedSignature; } function checkCallExpression(node) { + checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); if (node.expression.kind === 90 /* SuperKeyword */) { return voidType; @@ -15780,6 +14806,9 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { + if (compilerOptions.target < 2 /* ES6 */) { + grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); + } return getReturnTypeOfSignature(getResolvedSignature(node)); } function checkTypeAssertion(node) { @@ -15872,6 +14901,10 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 128 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + if (!hasGrammarError && node.kind === 156 /* FunctionExpression */) { + checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); + } if (contextualMapper === identityMapper) { return anyFunctionType; } @@ -15981,6 +15014,9 @@ var ts; return true; } function checkDeleteExpression(node) { + if (node.parserContextFlags & 1 /* StrictMode */ && node.expression.kind === 64 /* Identifier */) { + grammarErrorOnNode(node.expression, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); + } var operandType = checkExpression(node.expression); return booleanType; } @@ -15993,6 +15029,9 @@ var ts; return undefinedType; } function checkPrefixUnaryExpression(node) { + if ((node.operator === 38 /* PlusPlusToken */ || node.operator === 39 /* MinusMinusToken */)) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.operand); + } var operandType = checkExpression(node.operand); switch (node.operator) { case 33 /* PlusToken */: @@ -16012,6 +15051,7 @@ var ts; return unknownType; } function checkPostfixUnaryExpression(node) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.operand); var operandType = checkExpression(node.operand); var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { @@ -16108,6 +15148,9 @@ var ts; return sourceType; } function checkBinaryExpression(node, contextualMapper) { + if (ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operator)) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.left); + } var operator = node.operator; if (operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); @@ -16228,6 +15271,14 @@ var ts; error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operator), typeToString(leftType), typeToString(rightType)); } } + function checkYieldExpression(node) { + if (!(node.parserContextFlags & 4 /* Yield */)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + } + else { + grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); + } + } function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); @@ -16255,6 +15306,7 @@ var ts; return links.resolvedType; } function checkObjectLiteralMethod(node, contextualMapper) { + checkGrammarMethod(node); var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } @@ -16293,6 +15345,10 @@ var ts; } return type; } + function checkNumericLiteral(node) { + checkGrammarNumbericLiteral(node); + return numberType; + } function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { case 64 /* Identifier */: @@ -16307,7 +15363,7 @@ var ts; case 79 /* FalseKeyword */: return booleanType; case 7 /* NumericLiteral */: - return numberType; + return checkNumericLiteral(node); case 165 /* TemplateExpression */: return checkTemplateExpression(node); case 8 /* StringLiteral */: @@ -16351,10 +15407,16 @@ var ts; return checkConditionalExpression(node, contextualMapper); case 167 /* OmittedExpression */: return undefinedType; + case 166 /* YieldExpression */: + checkYieldExpression(node); + return unknownType; } return unknownType; } function checkTypeParameter(node) { + if (node.expression) { + grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); + } checkSourceElement(node.constraint); if (fullTypeCheck) { checkTypeParameterHasIllegalReferencesInConstraint(node); @@ -16362,6 +15424,7 @@ var ts; } } function checkParameter(node) { + checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); if (node.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { @@ -16377,6 +15440,12 @@ var ts; } } function checkSignatureDeclaration(node) { + if (node.kind === 134 /* IndexSignature */) { + checkGrammarIndexSignature(node); + } + else if (node.kind === 136 /* FunctionType */ || node.kind === 190 /* FunctionDeclaration */ || node.kind === 137 /* ConstructorType */ || node.kind === 132 /* CallSignature */ || node.kind === 129 /* Constructor */ || node.kind === 133 /* ConstructSignature */) { + checkGrammarFunctionLikeDeclaration(node); + } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { @@ -16434,13 +15503,16 @@ var ts; } } function checkPropertyDeclaration(node) { + checkGrammarModifiers(node) || checkGrammarProperty(node); checkVariableLikeDeclaration(node); } function checkMethodDeclaration(node) { + checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); checkFunctionLikeDeclaration(node); } function checkConstructorDeclaration(node) { checkSignatureDeclaration(node); + checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); @@ -16498,6 +15570,7 @@ var ts; } } function checkAccessorDeclaration(node) { + checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); if (fullTypeCheck) { if (node.kind === 130 /* GetAccessor */) { if (!ts.isInAmbientContext(node) && node.body && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { @@ -16525,6 +15598,7 @@ var ts; checkFunctionLikeDeclaration(node); } function checkTypeReference(node) { + checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReferenceNode(node); if (type !== unknownType && node.typeArguments) { var len = node.typeArguments.length; @@ -16553,6 +15627,10 @@ var ts; checkSourceElement(node.elementType); } function checkTupleType(node) { + var hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes); + if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) { + grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty); + } ts.forEach(node.elementTypes, checkSourceElement); } function checkUnionType(node) { @@ -16815,6 +15893,7 @@ var ts; } function checkFunctionDeclaration(node) { checkFunctionLikeDeclaration(node); + checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); @@ -16845,6 +15924,9 @@ var ts; } } function checkBlock(node) { + if (node.kind === 169 /* Block */) { + checkGrammarForStatementInAmbientContext(node); + } ts.forEach(node.statements, checkSourceElement); if (ts.isFunctionBlock(node) || node.kind === 196 /* ModuleBlock */) { checkFunctionExpressionBodies(node); @@ -16973,6 +16055,12 @@ var ts; } } function checkVariableLikeDeclaration(node) { + if (node.kind === 146 /* BindingElement */) { + checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + } + else if (node.kind === 189 /* VariableDeclaration */) { + checkGrammarVariableDeclaration(node); + } checkSourceElement(node.type); if (ts.hasComputedNameButNotSymbol(node)) { if (node.initializer) { @@ -17020,25 +16108,31 @@ var ts; } } function checkVariableStatement(node) { + checkGrammarModifiers(node) || checkGrammarVariableDeclarations(node, node.declarations) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarations, checkSourceElement); } function checkExpressionStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkExpression(node.expression); } function checkIfStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkExpression(node.expression); checkSourceElement(node.thenStatement); checkSourceElement(node.elseStatement); } function checkDoStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkSourceElement(node.statement); checkExpression(node.expression); } function checkWhileStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkExpression(node.expression); checkSourceElement(node.statement); } function checkForStatement(node) { + checkGrammarForStatementInAmbientContext(node) || checkGrammarVariableDeclarations(node, node.declarations); if (node.declarations) ts.forEach(node.declarations, checkVariableLikeDeclaration); if (node.initializer) @@ -17050,6 +16144,14 @@ var ts; checkSourceElement(node.statement); } function checkForInStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + var declarations = node.declarations; + if (!checkGrammarVariableDeclarations(node, declarations)) { + if (declarations && declarations.length > 1) { + grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + } + } + } if (node.declarations) { if (node.declarations.length >= 1) { var decl = node.declarations[0]; @@ -17075,11 +16177,18 @@ var ts; checkSourceElement(node.statement); } function checkBreakOrContinueStatement(node) { + checkGrammarForStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } function isGetAccessorWithAnnotatatedSetAccessor(node) { return !!(node.kind === 130 /* GetAccessor */ && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 131 /* SetAccessor */))); } function checkReturnStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + var functionBlock = ts.getContainingFunction(node); + if (!functionBlock) { + grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); + } + } if (node.expression) { var func = ts.getContainingFunction(node); if (func) { @@ -17102,12 +16211,32 @@ var ts; } } function checkWithStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + if (node.parserContextFlags & 1 /* StrictMode */) { + grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode); + } + } checkExpression(node.expression); error(node.expression, ts.Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any); } function checkSwitchStatement(node) { + checkGrammarForStatementInAmbientContext(node); + var firstDefaultClause; + var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); ts.forEach(node.clauses, function (clause) { + if (clause.kind === 201 /* DefaultClause */ && !hasDuplicateDefaultClause) { + if (firstDefaultClause === undefined) { + firstDefaultClause = clause; + } + else { + var sourceFile = ts.getSourceFileOfNode(node); + var start = ts.skipTrivia(sourceFile.text, clause.pos); + var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; + grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); + hasDuplicateDefaultClause = true; + } + } if (fullTypeCheck && clause.kind === 200 /* CaseClause */) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); @@ -17119,17 +16248,45 @@ var ts; }); } function checkLabeledStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + var current = node.parent; + while (current) { + if (ts.isAnyFunction(current)) { + break; + } + if (current.kind === 183 /* LabeledStatement */ && current.label.text === node.label.text) { + var sourceFile = ts.getSourceFileOfNode(node); + grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); + break; + } + current = current.parent; + } + } checkSourceElement(node.statement); } function checkThrowStatement(node) { + if (!checkGrammarForStatementInAmbientContext(node)) { + if (node.expression === undefined) { + grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here); + } + } if (node.expression) { checkExpression(node.expression); } } function checkTryStatement(node) { + checkGrammarForStatementInAmbientContext(node); checkBlock(node.tryBlock); - if (node.catchClause) - checkBlock(node.catchClause.block); + var catchClause = node.catchClause; + if (catchClause) { + if (catchClause.type) { + var sourceFile = ts.getSourceFileOfNode(node); + var colonStart = ts.skipTrivia(sourceFile.text, catchClause.name.end); + grammarErrorAtPos(sourceFile, colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + } + checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.name); + checkBlock(catchClause.block); + } if (node.finallyBlock) checkBlock(node.finallyBlock); } @@ -17206,6 +16363,7 @@ var ts; } } function checkClassDeclaration(node) { + checkGrammarClassDeclarationHeritageClauses(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); @@ -17364,6 +16522,7 @@ var ts; return ok; } function checkInterfaceDeclaration(node) { + checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (fullTypeCheck) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); @@ -17392,6 +16551,7 @@ var ts; } } function checkTypeAliasDeclaration(node) { + checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_alias_name_cannot_be_0); checkSourceElement(node.type); } @@ -17531,6 +16691,7 @@ var ts; } } function checkEnumDeclaration(node) { + checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); if (!fullTypeCheck) { return; } @@ -17582,6 +16743,23 @@ var ts; return undefined; } function checkModuleDeclaration(node) { + if (!checkGrammarModifiers(node)) { + if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { + grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); + } + else if (node.name.kind === 64 /* Identifier */ && node.body.kind === 196 /* ModuleBlock */) { + var statements = node.body.statements; + for (var i = 0, n = statements.length; i < n; i++) { + var statement = statements[i]; + if (statement.kind === 198 /* ExportAssignment */) { + grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + } + else if (ts.isExternalModuleImportDeclaration(statement)) { + grammarErrorOnNode(ts.getExternalModuleImportDeclarationExpression(statement), ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + } + } + } + } if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -17616,6 +16794,7 @@ var ts; return node; } function checkImportDeclaration(node) { + checkGrammarModifiers(node); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); @@ -17667,6 +16846,9 @@ var ts; } } function checkExportAssignment(node) { + if (!checkGrammarModifiers(node) && (node.flags & 243 /* Modifier */)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); + } var container = node.parent; if (container.kind !== 207 /* SourceFile */) { container = container.parent; @@ -17688,6 +16870,7 @@ var ts; case 137 /* ConstructorType */: case 132 /* CallSignature */: case 133 /* ConstructSignature */: + return checkSignatureDeclaration(node); case 134 /* IndexSignature */: return checkSignatureDeclaration(node); case 128 /* MethodDeclaration */: @@ -17763,6 +16946,12 @@ var ts; return checkImportDeclaration(node); case 198 /* ExportAssignment */: return checkExportAssignment(node); + case 171 /* EmptyStatement */: + checkGrammarForStatementInAmbientContext(node); + return; + case 188 /* DebuggerStatement */: + checkGrammarForStatementInAmbientContext(node); + return; } } function checkFunctionExpressionBodies(node) { @@ -17844,6 +17033,7 @@ var ts; function checkSourceFile(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { + checkGrammarSourceFile(node); emitExtends = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); @@ -17852,6 +17042,7 @@ var ts; var symbol = getExportAssignmentSymbol(node.symbol); if (symbol && symbol.flags & 8388608 /* Import */) { getSymbolLinks(symbol).referenced = true; + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197 /* ImportDeclaration */)); } } if (potentialThisCollisions.length) { @@ -18038,17 +17229,20 @@ var ts; } return false; } + function getLeftSideOfImportOrExportAssignment(nodeOnRightSide) { + while (nodeOnRightSide.parent.kind === 121 /* QualifiedName */) { + nodeOnRightSide = nodeOnRightSide.parent; + } + if (nodeOnRightSide.parent.kind === 197 /* ImportDeclaration */) { + return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; + } + if (nodeOnRightSide.parent.kind === 198 /* ExportAssignment */) { + return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; + } + return undefined; + } function isInRightSideOfImportOrExportAssignment(node) { - while (node.parent.kind === 121 /* QualifiedName */) { - node = node.parent; - } - if (node.parent.kind === 197 /* ImportDeclaration */) { - return node.parent.moduleReference === node; - } - if (node.parent.kind === 198 /* ExportAssignment */) { - return node.parent.exportName === node; - } - return false; + return getLeftSideOfImportOrExportAssignment(node) !== undefined; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { return (node.parent.kind === 121 /* QualifiedName */ && node.parent.right === node) || (node.parent.kind === 149 /* PropertyAccessExpression */ && node.parent.name === node); @@ -18395,6 +17589,740 @@ var ts; globalTemplateStringsArrayType = compilerOptions.target >= 2 /* ES6 */ ? getGlobalType("TemplateStringsArray") : unknownType; anyArrayType = createArrayType(anyType); } + function checkGrammarModifiers(node) { + switch (node.kind) { + case 130 /* GetAccessor */: + case 131 /* SetAccessor */: + case 129 /* Constructor */: + case 126 /* PropertyDeclaration */: + case 125 /* PropertySignature */: + case 128 /* MethodDeclaration */: + case 127 /* MethodSignature */: + case 134 /* IndexSignature */: + case 191 /* ClassDeclaration */: + case 192 /* InterfaceDeclaration */: + case 195 /* ModuleDeclaration */: + case 194 /* EnumDeclaration */: + case 198 /* ExportAssignment */: + case 170 /* VariableStatement */: + case 190 /* FunctionDeclaration */: + case 193 /* TypeAliasDeclaration */: + case 197 /* ImportDeclaration */: + case 124 /* Parameter */: + break; + default: + return false; + } + if (!node.modifiers) { + return; + } + var lastStatic, lastPrivate, lastProtected, lastDeclare; + var flags = 0; + for (var i = 0, n = node.modifiers.length; i < n; i++) { + var modifier = node.modifiers[i]; + switch (modifier.kind) { + case 107 /* PublicKeyword */: + case 106 /* ProtectedKeyword */: + case 105 /* PrivateKeyword */: + var text; + if (modifier.kind === 107 /* PublicKeyword */) { + text = "public"; + } + else if (modifier.kind === 106 /* ProtectedKeyword */) { + text = "protected"; + lastProtected = modifier; + } + else { + text = "private"; + lastPrivate = modifier; + } + if (flags & 112 /* AccessibilityModifier */) { + return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen); + } + else if (flags & 128 /* Static */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); + } + else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); + } + flags |= ts.modifierToFlag(modifier.kind); + break; + case 108 /* StaticKeyword */: + if (flags & 128 /* Static */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); + } + else if (node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); + } + else if (node.kind === 124 /* Parameter */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); + } + flags |= 128 /* Static */; + lastStatic = modifier; + break; + case 77 /* ExportKeyword */: + if (flags & 1 /* Export */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); + } + else if (flags & 2 /* Ambient */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); + } + else if (node.parent.kind === 191 /* ClassDeclaration */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); + } + else if (node.kind === 124 /* Parameter */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); + } + flags |= 1 /* Export */; + break; + case 113 /* DeclareKeyword */: + if (flags & 2 /* Ambient */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); + } + else if (node.parent.kind === 191 /* ClassDeclaration */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); + } + else if (node.kind === 124 /* Parameter */) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); + } + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 196 /* ModuleBlock */) { + return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); + } + flags |= 2 /* Ambient */; + lastDeclare = modifier; + break; + } + } + if (node.kind === 129 /* Constructor */) { + if (flags & 128 /* Static */) { + return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); + } + else if (flags & 64 /* Protected */) { + return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); + } + else if (flags & 32 /* Private */) { + return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); + } + } + else if (node.kind === 197 /* ImportDeclaration */ && flags & 2 /* Ambient */) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); + } + else if (node.kind === 192 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); + } + } + function checkGrammarForDisallowedTrailingComma(list) { + if (list && list.hasTrailingComma) { + var start = list.end - ",".length; + var end = list.end; + var sourceFile = ts.getSourceFileOfNode(list[0]); + return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + function checkGrammarTypeParameterList(node, typeParameters) { + if (checkGrammarForDisallowedTrailingComma(typeParameters)) { + return true; + } + if (typeParameters && typeParameters.length === 0) { + var start = typeParameters.pos - "<".length; + var sourceFile = ts.getSourceFileOfNode(node); + var end = ts.skipTrivia(sourceFile.text, typeParameters.end) + ">".length; + return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty); + } + } + function checkGrammarParameterList(parameters) { + if (checkGrammarForDisallowedTrailingComma(parameters)) { + return true; + } + var seenOptionalParameter = false; + var parameterCount = parameters.length; + for (var i = 0; i < parameterCount; i++) { + var parameter = parameters[i]; + if (parameter.dotDotDotToken) { + if (i !== (parameterCount - 1)) { + return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); + } + if (parameter.questionToken) { + return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional); + } + if (parameter.initializer) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer); + } + } + else if (parameter.questionToken || parameter.initializer) { + seenOptionalParameter = true; + if (parameter.questionToken && parameter.initializer) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer); + } + } + else { + if (seenOptionalParameter) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); + } + } + } + } + function checkGrammarFunctionLikeDeclaration(node) { + return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters); + } + function checkGrammarIndexSignatureParameters(node) { + var parameter = node.parameters[0]; + if (node.parameters.length !== 1) { + if (parameter) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); + } + else { + return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter); + } + } + else if (parameter.dotDotDotToken) { + return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); + } + else if (parameter.flags & 243 /* Modifier */) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); + } + else if (parameter.questionToken) { + return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); + } + else if (parameter.initializer) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); + } + else if (!parameter.type) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); + } + else if (parameter.type.kind !== 119 /* StringKeyword */ && parameter.type.kind !== 117 /* NumberKeyword */) { + return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); + } + else if (!node.type) { + return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation); + } + } + function checkGrammarForIndexSignatureModifier(node) { + if (node.flags & 243 /* Modifier */) { + grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); + } + } + function checkGrammarIndexSignature(node) { + checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + } + function checkGrammarForAtLeastOneTypeArgument(node, typeArguments) { + if (typeArguments && typeArguments.length === 0) { + var sourceFile = ts.getSourceFileOfNode(node); + var start = typeArguments.pos - "<".length; + var end = ts.skipTrivia(sourceFile.text, typeArguments.end) + ">".length; + return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function checkGrammarTypeArguments(node, typeArguments) { + return checkGrammarForDisallowedTrailingComma(typeArguments) || checkGrammarForAtLeastOneTypeArgument(node, typeArguments); + } + function checkGrammarForOmittedArgument(node, arguments) { + if (arguments) { + var sourceFile = ts.getSourceFileOfNode(node); + for (var i = 0, n = arguments.length; i < n; i++) { + var arg = arguments[i]; + if (arg.kind === 167 /* OmittedExpression */) { + return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); + } + } + } + } + function checkGrammarArguments(node, arguments) { + return checkGrammarForDisallowedTrailingComma(arguments) || checkGrammarForOmittedArgument(node, arguments); + } + function checkGrammarHeritageClause(node) { + var types = node.types; + if (checkGrammarForDisallowedTrailingComma(types)) { + return true; + } + if (types && types.length === 0) { + var listType = ts.tokenToString(node.token); + var sourceFile = ts.getSourceFileOfNode(node); + return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType); + } + } + function checkGrammarClassDeclarationHeritageClauses(node) { + var seenExtendsClause = false; + var seenImplementsClause = false; + if (!checkGrammarModifiers(node) && node.heritageClauses) { + for (var i = 0, n = node.heritageClauses.length; i < n; i++) { + ts.Debug.assert(i <= 2); + var heritageClause = node.heritageClauses[i]; + if (heritageClause.token === 78 /* ExtendsKeyword */) { + if (seenExtendsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); + } + if (seenImplementsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause); + } + if (heritageClause.types.length > 1) { + return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class); + } + seenExtendsClause = true; + } + else { + ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); + if (seenImplementsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); + } + seenImplementsClause = true; + } + checkGrammarHeritageClause(heritageClause); + } + } + } + function checkGrammarInterfaceDeclaration(node) { + var seenExtendsClause = false; + if (node.heritageClauses) { + for (var i = 0, n = node.heritageClauses.length; i < n; i++) { + ts.Debug.assert(i <= 1); + var heritageClause = node.heritageClauses[i]; + if (heritageClause.token === 78 /* ExtendsKeyword */) { + if (seenExtendsClause) { + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); + } + seenExtendsClause = true; + } + else { + ts.Debug.assert(heritageClause.token === 101 /* ImplementsKeyword */); + return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); + } + checkGrammarHeritageClause(heritageClause); + } + } + return false; + } + function checkGrammarComputedPropertyName(node) { + if (node.kind !== 122 /* ComputedPropertyName */) { + return; + } + grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_not_currently_supported); + return; + var computedPropertyName = node; + if (compilerOptions.target < 2 /* ES6 */) { + grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (computedPropertyName.expression.kind === 163 /* BinaryExpression */ && computedPropertyName.expression.operator === 23 /* CommaToken */) { + grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); + } + } + function checkGrammarForGenerator(node) { + if (node.asteriskToken) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); + } + } + function checkGrammarFunctionName(name) { + return checkGrammarEvalOrArgumentsInStrictMode(name, name); + } + function checkGrammarForInvalidQuestionMark(node, questionToken, message) { + if (questionToken) { + return grammarErrorOnNode(questionToken, message); + } + } + function checkGrammarObjectLiteralExpression(node) { + var seen = {}; + var Property = 1; + var GetAccessor = 2; + var SetAccesor = 4; + var GetOrSetAccessor = GetAccessor | SetAccesor; + var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; + for (var i = 0, n = node.properties.length; i < n; i++) { + var prop = node.properties[i]; + var name = prop.name; + if (prop.kind === 167 /* OmittedExpression */ || name.kind === 122 /* ComputedPropertyName */) { + checkGrammarComputedPropertyName(name); + continue; + } + var currentKind; + if (prop.kind === 204 /* PropertyAssignment */ || prop.kind === 205 /* ShorthandPropertyAssignment */) { + checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); + if (name.kind === 7 /* NumericLiteral */) { + checkGrammarNumbericLiteral(name); + } + currentKind = Property; + } + else if (prop.kind === 128 /* MethodDeclaration */) { + currentKind = Property; + } + else if (prop.kind === 130 /* GetAccessor */) { + currentKind = GetAccessor; + } + else if (prop.kind === 131 /* SetAccessor */) { + currentKind = SetAccesor; + } + else { + ts.Debug.fail("Unexpected syntax kind:" + prop.kind); + } + if (!ts.hasProperty(seen, name.text)) { + seen[name.text] = currentKind; + } + else { + var existingKind = seen[name.text]; + if (currentKind === Property && existingKind === Property) { + if (inStrictMode) { + grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + } + } + else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { + if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { + seen[name.text] = currentKind | existingKind; + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } + } + } + } + function checkGrammarAccessor(accessor) { + var kind = accessor.kind; + if (compilerOptions.target < 1 /* ES5 */) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (ts.isInAmbientContext(accessor)) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); + } + else if (accessor.body === undefined) { + return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); + } + else if (accessor.typeParameters) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); + } + else if (kind === 130 /* GetAccessor */ && accessor.parameters.length) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); + } + else if (kind === 131 /* SetAccessor */) { + if (accessor.type) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); + } + else if (accessor.parameters.length !== 1) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter); + } + else { + var parameter = accessor.parameters[0]; + if (parameter.dotDotDotToken) { + return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter); + } + else if (parameter.flags & 243 /* Modifier */) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); + } + else if (parameter.questionToken) { + return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); + } + else if (parameter.initializer) { + return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer); + } + } + } + } + function checkGrammarForDisallowedComputedProperty(node, message) { + if (node.kind === 122 /* ComputedPropertyName */) { + return grammarErrorOnNode(node, message); + } + } + function checkGrammarMethod(node) { + if (checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { + return true; + } + if (node.parent.kind === 191 /* ClassDeclaration */) { + if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { + return true; + } + if (ts.isInAmbientContext(node)) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_an_ambient_context); + } + else if (!node.body) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); + } + } + else if (node.parent.kind === 192 /* InterfaceDeclaration */) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces); + } + else if (node.parent.kind === 139 /* TypeLiteral */) { + return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals); + } + } + function isIterationStatement(node, lookInLabeledStatements) { + switch (node.kind) { + case 176 /* ForStatement */: + case 177 /* ForInStatement */: + case 174 /* DoStatement */: + case 175 /* WhileStatement */: + return true; + case 183 /* LabeledStatement */: + return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); + } + return false; + } + function checkGrammarBreakOrContinueStatement(node) { + var current = node; + while (current) { + if (ts.isAnyFunction(current)) { + return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); + } + switch (current.kind) { + case 183 /* LabeledStatement */: + if (node.label && current.label.text === node.label.text) { + var isMisplacedContinueLabel = node.kind === 178 /* ContinueStatement */ && !isIterationStatement(current.statement, true); + if (isMisplacedContinueLabel) { + return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); + } + return false; + } + break; + case 182 /* SwitchStatement */: + if (node.kind === 179 /* BreakStatement */ && !node.label) { + return false; + } + break; + default: + if (isIterationStatement(current, false) && !node.label) { + return false; + } + break; + } + current = current.parent; + } + if (node.label) { + var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + return grammarErrorOnNode(node, message); + } + else { + var message = node.kind === 179 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + return grammarErrorOnNode(node, message); + } + } + function checkGrammarVariableDeclaration(node) { + if (ts.isInAmbientContext(node)) { + if (ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + else { + if (!node.initializer) { + if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { + return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); + } + if (ts.isConst(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized); + } + } + } + return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + } + function checkGrammarVariableDeclarations(container, declarations) { + if (declarations) { + if (checkGrammarForDisallowedTrailingComma(declarations)) { + return true; + } + if (!declarations.length) { + return grammarErrorAtPos(ts.getSourceFileOfNode(container), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); + } + var decl = declarations[0]; + if (compilerOptions.target < 2 /* ES6 */) { + if (ts.isLet(decl)) { + return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (ts.isConst(decl)) { + return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + } + } + function allowLetAndConstDeclarations(parent) { + switch (parent.kind) { + case 173 /* IfStatement */: + case 174 /* DoStatement */: + case 175 /* WhileStatement */: + case 181 /* WithStatement */: + case 176 /* ForStatement */: + case 177 /* ForInStatement */: + return false; + case 183 /* LabeledStatement */: + return allowLetAndConstDeclarations(parent.parent); + } + return true; + } + function checkGrammarForDisallowedLetOrConstStatement(node) { + if (!allowLetAndConstDeclarations(node.parent)) { + if (ts.isLet(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block); + } + else if (ts.isConst(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block); + } + } + } + function isIntegerLiteral(expression) { + if (expression.kind === 161 /* PrefixUnaryExpression */) { + var unaryExpression = expression; + if (unaryExpression.operator === 33 /* PlusToken */ || unaryExpression.operator === 34 /* MinusToken */) { + expression = unaryExpression.operand; + } + } + if (expression.kind === 7 /* NumericLiteral */) { + return /^[0-9]+([eE]\+?[0-9]+)?$/.test(expression.text); + } + return false; + } + function checkGrammarEnumDeclaration(enumDecl) { + var enumIsConst = (enumDecl.flags & 4096 /* Const */) !== 0; + var hasError = false; + if (!enumIsConst) { + var inConstantEnumMemberSection = true; + var inAmbientContext = ts.isInAmbientContext(enumDecl); + for (var i = 0, n = enumDecl.members.length; i < n; i++) { + var node = enumDecl.members[i]; + if (node.name.kind === 122 /* ComputedPropertyName */) { + hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); + } + else if (inAmbientContext) { + if (node.initializer && !isIntegerLiteral(node.initializer)) { + hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; + } + } + else if (node.initializer) { + inConstantEnumMemberSection = isIntegerLiteral(node.initializer); + } + else if (!inConstantEnumMemberSection) { + hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; + } + } + } + return hasError; + } + function hasParseDiagnostics(sourceFile) { + return sourceFile.parseDiagnostics.length > 0; + } + function scanToken(scanner, pos) { + scanner.setTextPos(pos); + scanner.scan(); + var start = scanner.getTokenPos(); + return start; + } + function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { + var sourceFile = ts.getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + var start = scanToken(scanner, node.pos); + diagnostics.push(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); + return true; + } + } + function grammarErrorAtPos(sourceFile, start, length, message, arg0, arg1, arg2) { + if (!hasParseDiagnostics(sourceFile)) { + diagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2)); + return true; + } + } + function grammarErrorOnNode(node, message, arg0, arg1, arg2) { + var sourceFile = ts.getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + var span = ts.getErrorSpanForNode(node); + var start = span.end > span.pos ? ts.skipTrivia(sourceFile.text, span.pos) : span.pos; + diagnostics.push(ts.createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2)); + return true; + } + } + function checkGrammarEvalOrArgumentsInStrictMode(contextNode, identifier) { + if (contextNode && (contextNode.parserContextFlags & 1 /* StrictMode */) && ts.isEvalOrArgumentsIdentifier(identifier)) { + var name = ts.declarationNameToString(identifier); + return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); + } + } + function checkGrammarConstructorTypeParameters(node) { + if (node.typeParameters) { + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); + } + } + function checkGrammarConstructorTypeAnnotation(node) { + if (node.type) { + return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration); + } + } + function checkGrammarProperty(node) { + if (node.parent.kind === 191 /* ClassDeclaration */) { + if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_class_property_declarations)) { + return true; + } + } + else if (node.parent.kind === 192 /* InterfaceDeclaration */) { + if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces)) { + return true; + } + } + else if (node.parent.kind === 139 /* TypeLiteral */) { + if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals)) { + return true; + } + } + if (ts.isInAmbientContext(node) && node.initializer) { + return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + function checkGrammarTopLevelElementForRequiredDeclareModifier(node) { + if (node.kind === 192 /* InterfaceDeclaration */ || node.kind === 197 /* ImportDeclaration */ || node.kind === 198 /* ExportAssignment */ || (node.flags & 2 /* Ambient */)) { + return false; + } + return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); + } + function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { + for (var i = 0, n = file.statements.length; i < n; i++) { + var decl = file.statements[i]; + if (ts.isDeclaration(decl) || decl.kind === 170 /* VariableStatement */) { + if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { + return true; + } + } + } + } + function checkGrammarSourceFile(node) { + return ts.isInAmbientContext(node) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node); + } + function checkGrammarForStatementInAmbientContext(node) { + if (ts.isInAmbientContext(node)) { + if (isAccessor(node.parent.kind)) { + return getNodeLinks(node).hasReportedStatementInAmbientContext = true; + } + var links = getNodeLinks(node); + if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { + return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); + } + if (node.parent.kind === 169 /* Block */ || node.parent.kind === 196 /* ModuleBlock */ || node.parent.kind === 207 /* SourceFile */) { + var links = getNodeLinks(node.parent); + if (!links.hasReportedStatementInAmbientContext) { + return links.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); + } + } + else { + } + } + } + function checkGrammarNumbericLiteral(node) { + if (node.flags & 8192 /* OctalLiteral */) { + if (node.parserContextFlags & 1 /* StrictMode */) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); + } + else if (compilerOptions.target >= 1 /* ES5 */) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + } + } + } + function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { + var sourceFile = ts.getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + scanToken(scanner, node.pos); + diagnostics.push(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); + return true; + } + } initializeTypeChecker(); return checker; } diff --git a/bin/typescriptServices_internal.d.ts b/bin/typescriptServices_internal.d.ts new file mode 100644 index 00000000000..260c1b1c679 --- /dev/null +++ b/bin/typescriptServices_internal.d.ts @@ -0,0 +1,261 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +declare module ts { + const enum Ternary { + False = 0, + Maybe = 1, + True = -1, + } + const enum Comparison { + LessThan = -1, + EqualTo = 0, + GreaterThan = 1, + } + interface StringSet extends Map { + } + function forEach(array: T[], callback: (element: T) => U): U; + function contains(array: T[], value: T): boolean; + function indexOf(array: T[], value: T): number; + function countWhere(array: T[], predicate: (x: T) => boolean): number; + function filter(array: T[], f: (x: T) => boolean): T[]; + function map(array: T[], f: (x: T) => U): U[]; + function concatenate(array1: T[], array2: T[]): T[]; + function deduplicate(array: T[]): T[]; + function sum(array: any[], prop: string): number; + /** + * Returns the last element of an array if non-empty, undefined otherwise. + */ + function lastOrUndefined(array: T[]): T; + function binarySearch(array: number[], value: number): number; + function hasProperty(map: Map, key: string): boolean; + function getProperty(map: Map, key: string): T; + function isEmpty(map: Map): boolean; + function clone(object: T): T; + function forEachValue(map: Map, callback: (value: T) => U): U; + function forEachKey(map: Map, callback: (key: string) => U): U; + function lookUp(map: Map, key: string): T; + function mapToArray(map: Map): T[]; + /** + * Creates a map from the elements of an array. + * + * @param array the array of input elements. + * @param makeKey a function that produces a key for a given element. + * + * This function makes no effort to avoid collisions; if any two elements produce + * the same key with the given 'makeKey' function, then the element with the higher + * index in the array will be the one associated with the produced key. + */ + function arrayToMap(array: T[], makeKey: (value: T) => string): Map; + var localizedDiagnosticMessages: Map; + function getLocaleSpecificMessage(message: string): string; + function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic; + function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic; + function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain; + function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain; + function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic; + function compareValues(a: T, b: T): Comparison; + function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): number; + function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[]; + function normalizeSlashes(path: string): string; + function getRootLength(path: string): number; + var directorySeparator: string; + function normalizePath(path: string): string; + function getDirectoryPath(path: string): string; + function isUrl(path: string): boolean; + function isRootedDiskPath(path: string): boolean; + function getNormalizedPathComponents(path: string, currentDirectory: string): string[]; + function getNormalizedAbsolutePath(filename: string, currentDirectory: string): string; + function getNormalizedPathFromPathComponents(pathComponents: string[]): string; + function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean): string; + function getBaseFilename(path: string): string; + function combinePaths(path1: string, path2: string): string; + function fileExtensionIs(path: string, extension: string): boolean; + function removeFileExtension(path: string): string; + /** + * Based heavily on the abstract 'Quote' operation from ECMA-262 (24.3.2.2), + * but augmented for a few select characters. + * Note that this doesn't actually wrap the input in double quotes. + */ + function escapeString(s: string): string; + interface ObjectAllocator { + getNodeConstructor(kind: SyntaxKind): new () => Node; + getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; + getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; + getSignatureConstructor(): new (checker: TypeChecker) => Signature; + } + var objectAllocator: ObjectAllocator; + const enum AssertionLevel { + None = 0, + Normal = 1, + Aggressive = 2, + VeryAggressive = 3, + } + module Debug { + function shouldAssert(level: AssertionLevel): boolean; + function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void; + function fail(message?: string): void; + } +} +declare module ts { + interface System { + args: string[]; + newLine: string; + useCaseSensitiveFileNames: boolean; + write(s: string): void; + readFile(fileName: string, encoding?: string): string; + writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void; + watchFile?(fileName: string, callback: (fileName: string) => void): FileWatcher; + resolvePath(path: string): string; + fileExists(path: string): boolean; + directoryExists(path: string): boolean; + createDirectory(directoryName: string): void; + getExecutingFilePath(): string; + getCurrentDirectory(): string; + getMemoryUsage?(): number; + exit(exitCode?: number): void; + } + interface FileWatcher { + close(): void; + } + var sys: System; +} +declare module ts { + interface ReferencePathMatchResult { + fileReference?: FileReference; + diagnosticMessage?: DiagnosticMessage; + isNoDefaultLib?: boolean; + } + function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration; + interface StringSymbolWriter extends SymbolWriter { + string(): string; + } + function getSingleLineStringWriter(): StringSymbolWriter; + function releaseStringWriter(writer: StringSymbolWriter): void; + function getFullWidth(node: Node): number; + function containsParseError(node: Node): boolean; + function getSourceFileOfNode(node: Node): SourceFile; + function nodePosToString(node: Node): string; + function getStartPosOfNode(node: Node): number; + function isMissingNode(node: Node): boolean; + function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number; + function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string; + function getTextOfNodeFromSourceText(sourceText: string, node: Node): string; + function getTextOfNode(node: Node): string; + function escapeIdentifier(identifier: string): string; + function unescapeIdentifier(identifier: string): string; + function declarationNameToString(name: DeclarationName): string; + function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic; + function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic; + function getErrorSpanForNode(node: Node): Node; + function isExternalModule(file: SourceFile): boolean; + function isDeclarationFile(file: SourceFile): boolean; + function isConstEnumDeclaration(node: Node): boolean; + function isConst(node: Node): boolean; + function isLet(node: Node): boolean; + function isPrologueDirective(node: Node): boolean; + function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile): CommentRange[]; + function getJsDocComments(node: Node, sourceFileOfNode: SourceFile): CommentRange[]; + var fullTripleSlashReferencePathRegEx: RegExp; + function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T; + function isAnyFunction(node: Node): boolean; + function isFunctionBlock(node: Node): boolean; + function isObjectLiteralMethod(node: Node): boolean; + function getContainingFunction(node: Node): FunctionLikeDeclaration; + function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; + function getSuperContainer(node: Node): Node; + function getInvokedExpression(node: CallLikeExpression): Expression; + function isExpression(node: Node): boolean; + function isExternalModuleImportDeclaration(node: Node): boolean; + function getExternalModuleImportDeclarationExpression(node: Node): Expression; + function isInternalModuleImportDeclaration(node: Node): boolean; + function hasDotDotDotToken(node: Node): boolean; + function hasQuestionToken(node: Node): boolean; + function hasRestParameters(s: SignatureDeclaration): boolean; + function isLiteralKind(kind: SyntaxKind): boolean; + function isTextualLiteralKind(kind: SyntaxKind): boolean; + function isTemplateLiteralKind(kind: SyntaxKind): boolean; + function isBindingPattern(node: Node): boolean; + function isInAmbientContext(node: Node): boolean; + function isDeclaration(node: Node): boolean; + function isStatement(n: Node): boolean; + function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean; + function getClassBaseTypeNode(node: ClassDeclaration): TypeReferenceNode; + function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; + function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; + function getHeritageClause(clauses: NodeArray, kind: SyntaxKind): HeritageClause; + function tryResolveScriptReference(program: Program, sourceFile: SourceFile, reference: FileReference): SourceFile; + function getAncestor(node: Node, kind: SyntaxKind): Node; + function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult; + function isKeyword(token: SyntaxKind): boolean; + function isTrivia(token: SyntaxKind): boolean; + function isModifier(token: SyntaxKind): boolean; +} +declare module ts { + interface ListItemInfo { + listItemIndex: number; + list: Node; + } + function getEndLinePosition(line: number, sourceFile: SourceFile): number; + function getStartPositionOfLine(line: number, sourceFile: SourceFile): number; + function getStartLinePositionForPosition(position: number, sourceFile: SourceFile): number; + function rangeContainsRange(r1: TextRange, r2: TextRange): boolean; + function startEndContainsRange(start: number, end: number, range: TextRange): boolean; + function rangeContainsStartEnd(range: TextRange, start: number, end: number): boolean; + function rangeOverlapsWithStartEnd(r1: TextRange, start: number, end: number): boolean; + function startEndOverlapsWithStartEnd(start1: number, end1: number, start2: number, end2: number): boolean; + function findListItemInfo(node: Node): ListItemInfo; + function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node; + function findContainingList(node: Node): Node; + function getTouchingWord(sourceFile: SourceFile, position: number): Node; + function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node; + /** Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true */ + function getTouchingToken(sourceFile: SourceFile, position: number, includeItemAtEndPosition?: (n: Node) => boolean): Node; + /** Returns a token if position is in [start-of-leading-trivia, end) */ + function getTokenAtPosition(sourceFile: SourceFile, position: number): Node; + /** + * The token on the left of the position is the token that strictly includes the position + * or sits to the left of the cursor if it is on a boundary. For example + * + * fo|o -> will return foo + * foo |bar -> will return foo + * + */ + function findTokenOnLeftOfPosition(file: SourceFile, position: number): Node; + function findNextToken(previousToken: Node, parent: Node): Node; + function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node): Node; + function getNodeModifiers(node: Node): string; + function getTypeArgumentOrTypeParameterList(node: Node): NodeArray; + function isToken(n: Node): boolean; + function isComment(kind: SyntaxKind): boolean; + function isPunctuation(kind: SyntaxKind): boolean; + function isInsideTemplateLiteral(node: LiteralExpression, position: number): boolean; + function compareDataObjects(dst: any, src: any): boolean; +} +declare module ts { + function isFirstDeclarationOfSymbolParameter(symbol: Symbol): boolean; + function symbolPart(text: string, symbol: Symbol): SymbolDisplayPart; + function displayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart; + function spacePart(): SymbolDisplayPart; + function keywordPart(kind: SyntaxKind): SymbolDisplayPart; + function punctuationPart(kind: SyntaxKind): SymbolDisplayPart; + function operatorPart(kind: SyntaxKind): SymbolDisplayPart; + function textPart(text: string): SymbolDisplayPart; + function lineBreakPart(): SymbolDisplayPart; + function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[]; + function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]; + function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[]; + function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]; +} diff --git a/bin/typescript_internal.d.ts b/bin/typescript_internal.d.ts new file mode 100644 index 00000000000..37ab4b4da64 --- /dev/null +++ b/bin/typescript_internal.d.ts @@ -0,0 +1,261 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +declare module "typescript" { + const enum Ternary { + False = 0, + Maybe = 1, + True = -1, + } + const enum Comparison { + LessThan = -1, + EqualTo = 0, + GreaterThan = 1, + } + interface StringSet extends Map { + } + function forEach(array: T[], callback: (element: T) => U): U; + function contains(array: T[], value: T): boolean; + function indexOf(array: T[], value: T): number; + function countWhere(array: T[], predicate: (x: T) => boolean): number; + function filter(array: T[], f: (x: T) => boolean): T[]; + function map(array: T[], f: (x: T) => U): U[]; + function concatenate(array1: T[], array2: T[]): T[]; + function deduplicate(array: T[]): T[]; + function sum(array: any[], prop: string): number; + /** + * Returns the last element of an array if non-empty, undefined otherwise. + */ + function lastOrUndefined(array: T[]): T; + function binarySearch(array: number[], value: number): number; + function hasProperty(map: Map, key: string): boolean; + function getProperty(map: Map, key: string): T; + function isEmpty(map: Map): boolean; + function clone(object: T): T; + function forEachValue(map: Map, callback: (value: T) => U): U; + function forEachKey(map: Map, callback: (key: string) => U): U; + function lookUp(map: Map, key: string): T; + function mapToArray(map: Map): T[]; + /** + * Creates a map from the elements of an array. + * + * @param array the array of input elements. + * @param makeKey a function that produces a key for a given element. + * + * This function makes no effort to avoid collisions; if any two elements produce + * the same key with the given 'makeKey' function, then the element with the higher + * index in the array will be the one associated with the produced key. + */ + function arrayToMap(array: T[], makeKey: (value: T) => string): Map; + var localizedDiagnosticMessages: Map; + function getLocaleSpecificMessage(message: string): string; + function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic; + function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic; + function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain; + function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain; + function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic; + function compareValues(a: T, b: T): Comparison; + function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): number; + function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[]; + function normalizeSlashes(path: string): string; + function getRootLength(path: string): number; + var directorySeparator: string; + function normalizePath(path: string): string; + function getDirectoryPath(path: string): string; + function isUrl(path: string): boolean; + function isRootedDiskPath(path: string): boolean; + function getNormalizedPathComponents(path: string, currentDirectory: string): string[]; + function getNormalizedAbsolutePath(filename: string, currentDirectory: string): string; + function getNormalizedPathFromPathComponents(pathComponents: string[]): string; + function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean): string; + function getBaseFilename(path: string): string; + function combinePaths(path1: string, path2: string): string; + function fileExtensionIs(path: string, extension: string): boolean; + function removeFileExtension(path: string): string; + /** + * Based heavily on the abstract 'Quote' operation from ECMA-262 (24.3.2.2), + * but augmented for a few select characters. + * Note that this doesn't actually wrap the input in double quotes. + */ + function escapeString(s: string): string; + interface ObjectAllocator { + getNodeConstructor(kind: SyntaxKind): new () => Node; + getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; + getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; + getSignatureConstructor(): new (checker: TypeChecker) => Signature; + } + var objectAllocator: ObjectAllocator; + const enum AssertionLevel { + None = 0, + Normal = 1, + Aggressive = 2, + VeryAggressive = 3, + } + module Debug { + function shouldAssert(level: AssertionLevel): boolean; + function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void; + function fail(message?: string): void; + } +} +declare module "typescript" { + interface System { + args: string[]; + newLine: string; + useCaseSensitiveFileNames: boolean; + write(s: string): void; + readFile(fileName: string, encoding?: string): string; + writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void; + watchFile?(fileName: string, callback: (fileName: string) => void): FileWatcher; + resolvePath(path: string): string; + fileExists(path: string): boolean; + directoryExists(path: string): boolean; + createDirectory(directoryName: string): void; + getExecutingFilePath(): string; + getCurrentDirectory(): string; + getMemoryUsage?(): number; + exit(exitCode?: number): void; + } + interface FileWatcher { + close(): void; + } + var sys: System; +} +declare module "typescript" { + interface ReferencePathMatchResult { + fileReference?: FileReference; + diagnosticMessage?: DiagnosticMessage; + isNoDefaultLib?: boolean; + } + function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration; + interface StringSymbolWriter extends SymbolWriter { + string(): string; + } + function getSingleLineStringWriter(): StringSymbolWriter; + function releaseStringWriter(writer: StringSymbolWriter): void; + function getFullWidth(node: Node): number; + function containsParseError(node: Node): boolean; + function getSourceFileOfNode(node: Node): SourceFile; + function nodePosToString(node: Node): string; + function getStartPosOfNode(node: Node): number; + function isMissingNode(node: Node): boolean; + function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number; + function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string; + function getTextOfNodeFromSourceText(sourceText: string, node: Node): string; + function getTextOfNode(node: Node): string; + function escapeIdentifier(identifier: string): string; + function unescapeIdentifier(identifier: string): string; + function declarationNameToString(name: DeclarationName): string; + function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic; + function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic; + function getErrorSpanForNode(node: Node): Node; + function isExternalModule(file: SourceFile): boolean; + function isDeclarationFile(file: SourceFile): boolean; + function isConstEnumDeclaration(node: Node): boolean; + function isConst(node: Node): boolean; + function isLet(node: Node): boolean; + function isPrologueDirective(node: Node): boolean; + function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile): CommentRange[]; + function getJsDocComments(node: Node, sourceFileOfNode: SourceFile): CommentRange[]; + var fullTripleSlashReferencePathRegEx: RegExp; + function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T; + function isAnyFunction(node: Node): boolean; + function isFunctionBlock(node: Node): boolean; + function isObjectLiteralMethod(node: Node): boolean; + function getContainingFunction(node: Node): FunctionLikeDeclaration; + function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; + function getSuperContainer(node: Node): Node; + function getInvokedExpression(node: CallLikeExpression): Expression; + function isExpression(node: Node): boolean; + function isExternalModuleImportDeclaration(node: Node): boolean; + function getExternalModuleImportDeclarationExpression(node: Node): Expression; + function isInternalModuleImportDeclaration(node: Node): boolean; + function hasDotDotDotToken(node: Node): boolean; + function hasQuestionToken(node: Node): boolean; + function hasRestParameters(s: SignatureDeclaration): boolean; + function isLiteralKind(kind: SyntaxKind): boolean; + function isTextualLiteralKind(kind: SyntaxKind): boolean; + function isTemplateLiteralKind(kind: SyntaxKind): boolean; + function isBindingPattern(node: Node): boolean; + function isInAmbientContext(node: Node): boolean; + function isDeclaration(node: Node): boolean; + function isStatement(n: Node): boolean; + function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean; + function getClassBaseTypeNode(node: ClassDeclaration): TypeReferenceNode; + function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; + function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; + function getHeritageClause(clauses: NodeArray, kind: SyntaxKind): HeritageClause; + function tryResolveScriptReference(program: Program, sourceFile: SourceFile, reference: FileReference): SourceFile; + function getAncestor(node: Node, kind: SyntaxKind): Node; + function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult; + function isKeyword(token: SyntaxKind): boolean; + function isTrivia(token: SyntaxKind): boolean; + function isModifier(token: SyntaxKind): boolean; +} +declare module "typescript" { + interface ListItemInfo { + listItemIndex: number; + list: Node; + } + function getEndLinePosition(line: number, sourceFile: SourceFile): number; + function getStartPositionOfLine(line: number, sourceFile: SourceFile): number; + function getStartLinePositionForPosition(position: number, sourceFile: SourceFile): number; + function rangeContainsRange(r1: TextRange, r2: TextRange): boolean; + function startEndContainsRange(start: number, end: number, range: TextRange): boolean; + function rangeContainsStartEnd(range: TextRange, start: number, end: number): boolean; + function rangeOverlapsWithStartEnd(r1: TextRange, start: number, end: number): boolean; + function startEndOverlapsWithStartEnd(start1: number, end1: number, start2: number, end2: number): boolean; + function findListItemInfo(node: Node): ListItemInfo; + function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node; + function findContainingList(node: Node): Node; + function getTouchingWord(sourceFile: SourceFile, position: number): Node; + function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node; + /** Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true */ + function getTouchingToken(sourceFile: SourceFile, position: number, includeItemAtEndPosition?: (n: Node) => boolean): Node; + /** Returns a token if position is in [start-of-leading-trivia, end) */ + function getTokenAtPosition(sourceFile: SourceFile, position: number): Node; + /** + * The token on the left of the position is the token that strictly includes the position + * or sits to the left of the cursor if it is on a boundary. For example + * + * fo|o -> will return foo + * foo |bar -> will return foo + * + */ + function findTokenOnLeftOfPosition(file: SourceFile, position: number): Node; + function findNextToken(previousToken: Node, parent: Node): Node; + function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node): Node; + function getNodeModifiers(node: Node): string; + function getTypeArgumentOrTypeParameterList(node: Node): NodeArray; + function isToken(n: Node): boolean; + function isComment(kind: SyntaxKind): boolean; + function isPunctuation(kind: SyntaxKind): boolean; + function isInsideTemplateLiteral(node: LiteralExpression, position: number): boolean; + function compareDataObjects(dst: any, src: any): boolean; +} +declare module "typescript" { + function isFirstDeclarationOfSymbolParameter(symbol: Symbol): boolean; + function symbolPart(text: string, symbol: Symbol): SymbolDisplayPart; + function displayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart; + function spacePart(): SymbolDisplayPart; + function keywordPart(kind: SyntaxKind): SymbolDisplayPart; + function punctuationPart(kind: SyntaxKind): SymbolDisplayPart; + function operatorPart(kind: SyntaxKind): SymbolDisplayPart; + function textPart(text: string): SymbolDisplayPart; + function lineBreakPart(): SymbolDisplayPart; + function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[]; + function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]; + function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[]; + function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]; +}