Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 12 more grammar errors #47075

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,14 @@ namespace ts {
// grammar errors
Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement.code,
Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement.code,
Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name.code,
Diagnostics.A_class_member_cannot_have_the_0_keyword.code,
Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name.code,
Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement.code,
Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement.code,
Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement.code,
Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement.code,
Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration.code,
Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context.code,
Diagnostics.A_destructuring_declaration_must_have_an_initializer.code,
Diagnostics.A_get_accessor_cannot_have_parameters.code,
Expand All @@ -855,13 +857,21 @@ namespace ts {
Diagnostics.A_rest_parameter_cannot_have_an_initializer.code,
Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list.code,
Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma.code,
Diagnostics.A_return_statement_can_only_be_used_within_a_function_body.code,
Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
Diagnostics.An_export_declaration_can_only_be_used_in_a_module.code,
Diagnostics.An_export_declaration_cannot_have_modifiers.code,
Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module.code,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording seems off, and we could probably improve it and make it friendlier to JS (which doesn’t have namespaces) at the same time. I think it means that an import declaration has to be at the top level of the file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how it's implemented, yes. Well, it also checks for parents like namespace N or declare module "m", neither of which apply to JS.
I'll open a bug proposing to split the current implementation into 2 messages and improve the wording.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diagnostics.An_import_declaration_cannot_have_modifiers.code,
Diagnostics.An_object_member_cannot_be_declared_optional.code,
Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable.code,
Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause.code,
Diagnostics.Catch_clause_variable_cannot_have_an_initializer.code,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

Diagnostics.Class_decorators_can_t_be_used_with_static_private_identifier_Consider_removing_the_experimental_decorator.code,
Diagnostics.Classes_can_only_extend_a_single_class.code,
Diagnostics.Classes_may_not_have_a_field_named_constructor.code,
Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern.code,
Diagnostics.Duplicate_label_0.code,
Expand All @@ -873,6 +883,7 @@ namespace ts {
Diagnostics.JSX_property_access_expressions_cannot_include_JSX_namespace_names.code,
Diagnostics.Jump_target_cannot_cross_function_boundary.code,
Diagnostics.Line_terminator_not_permitted_before_arrow.code,
Diagnostics.Modifiers_cannot_appear_here.code,
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement.code,
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement.code,
Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies.code,
Expand All @@ -897,6 +908,7 @@ namespace ts {
Diagnostics._0_modifier_must_precede_1_modifier.code,
Diagnostics.const_declarations_can_only_be_declared_inside_a_block.code,
Diagnostics.const_declarations_must_be_initialized.code,
Diagnostics.extends_clause_already_seen.code,
Diagnostics.let_declarations_can_only_be_declared_inside_a_block.code,
Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
]);
Expand Down
Loading