@@ -415,6 +415,14 @@ func (p *Program) getSemanticDiagnosticsForFile(ctx context.Context, sourceFile
415
415
if ctx .Err () != nil {
416
416
return nil
417
417
}
418
+
419
+ isPlainJS := ast .IsPlainJSFile (sourceFile , p .compilerOptions .CheckJs )
420
+ if isPlainJS {
421
+ diags = core .Filter (diags , func (d * ast.Diagnostic ) bool {
422
+ return plainJSErrors .Has (d .Code ())
423
+ })
424
+ }
425
+
418
426
if len (sourceFile .CommentDirectives ) == 0 {
419
427
return diags
420
428
}
@@ -834,3 +842,100 @@ func (p *Program) GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReferenc
834
842
func (p * Program ) GetImportHelpersImportSpecifier (path tspath.Path ) * ast.Node {
835
843
return p .importHelpersImportSpecifiers [path ]
836
844
}
845
+
846
+ var plainJSErrors = core .NewSetFromItems (
847
+ // binder errors
848
+ diagnostics .Cannot_redeclare_block_scoped_variable_0 .Code (),
849
+ diagnostics .A_module_cannot_have_multiple_default_exports .Code (),
850
+ diagnostics .Another_export_default_is_here .Code (),
851
+ diagnostics .The_first_export_default_is_here .Code (),
852
+ diagnostics .Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module .Code (),
853
+ diagnostics .Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode .Code (),
854
+ diagnostics .Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here .Code (),
855
+ diagnostics .X_constructor_is_a_reserved_word .Code (),
856
+ diagnostics .X_delete_cannot_be_called_on_an_identifier_in_strict_mode .Code (),
857
+ diagnostics .Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode .Code (),
858
+ diagnostics .Invalid_use_of_0_Modules_are_automatically_in_strict_mode .Code (),
859
+ diagnostics .Invalid_use_of_0_in_strict_mode .Code (),
860
+ diagnostics .A_label_is_not_allowed_here .Code (),
861
+ diagnostics .X_with_statements_are_not_allowed_in_strict_mode .Code (),
862
+ // grammar errors
863
+ diagnostics .A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement .Code (),
864
+ diagnostics .A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement .Code (),
865
+ diagnostics .A_class_declaration_without_the_default_modifier_must_have_a_name .Code (),
866
+ diagnostics .A_class_member_cannot_have_the_0_keyword .Code (),
867
+ diagnostics .A_comma_expression_is_not_allowed_in_a_computed_property_name .Code (),
868
+ diagnostics .A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement .Code (),
869
+ diagnostics .A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement .Code (),
870
+ diagnostics .A_default_clause_cannot_appear_more_than_once_in_a_switch_statement .Code (),
871
+ diagnostics .A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration .Code (),
872
+ diagnostics .A_definite_assignment_assertion_is_not_permitted_in_this_context .Code (),
873
+ diagnostics .A_destructuring_declaration_must_have_an_initializer .Code (),
874
+ diagnostics .A_get_accessor_cannot_have_parameters .Code (),
875
+ diagnostics .A_rest_element_cannot_contain_a_binding_pattern .Code (),
876
+ diagnostics .A_rest_element_cannot_have_a_property_name .Code (),
877
+ diagnostics .A_rest_element_cannot_have_an_initializer .Code (),
878
+ diagnostics .A_rest_element_must_be_last_in_a_destructuring_pattern .Code (),
879
+ diagnostics .A_rest_parameter_cannot_have_an_initializer .Code (),
880
+ diagnostics .A_rest_parameter_must_be_last_in_a_parameter_list .Code (),
881
+ diagnostics .A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma .Code (),
882
+ diagnostics .A_return_statement_cannot_be_used_inside_a_class_static_block .Code (),
883
+ diagnostics .A_set_accessor_cannot_have_rest_parameter .Code (),
884
+ diagnostics .A_set_accessor_must_have_exactly_one_parameter .Code (),
885
+ diagnostics .An_export_declaration_can_only_be_used_at_the_top_level_of_a_module .Code (),
886
+ diagnostics .An_export_declaration_cannot_have_modifiers .Code (),
887
+ diagnostics .An_import_declaration_can_only_be_used_at_the_top_level_of_a_module .Code (),
888
+ diagnostics .An_import_declaration_cannot_have_modifiers .Code (),
889
+ diagnostics .An_object_member_cannot_be_declared_optional .Code (),
890
+ diagnostics .Argument_of_dynamic_import_cannot_be_spread_element .Code (),
891
+ diagnostics .Cannot_assign_to_private_method_0_Private_methods_are_not_writable .Code (),
892
+ diagnostics .Cannot_redeclare_identifier_0_in_catch_clause .Code (),
893
+ diagnostics .Catch_clause_variable_cannot_have_an_initializer .Code (),
894
+ diagnostics .Class_decorators_can_t_be_used_with_static_private_identifier_Consider_removing_the_experimental_decorator .Code (),
895
+ diagnostics .Classes_can_only_extend_a_single_class .Code (),
896
+ diagnostics .Classes_may_not_have_a_field_named_constructor .Code (),
897
+ 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 (),
898
+ diagnostics .Duplicate_label_0 .Code (),
899
+ diagnostics .Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_set_of_attributes_as_arguments .Code (),
900
+ diagnostics .X_for_await_loops_cannot_be_used_inside_a_class_static_block .Code (),
901
+ diagnostics .JSX_attributes_must_only_be_assigned_a_non_empty_expression .Code (),
902
+ diagnostics .JSX_elements_cannot_have_multiple_attributes_with_the_same_name .Code (),
903
+ diagnostics .JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array .Code (),
904
+ diagnostics .JSX_property_access_expressions_cannot_include_JSX_namespace_names .Code (),
905
+ diagnostics .Jump_target_cannot_cross_function_boundary .Code (),
906
+ diagnostics .Line_terminator_not_permitted_before_arrow .Code (),
907
+ diagnostics .Modifiers_cannot_appear_here .Code (),
908
+ diagnostics .Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement .Code (),
909
+ diagnostics .Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement .Code (),
910
+ diagnostics .Private_identifiers_are_not_allowed_outside_class_bodies .Code (),
911
+ diagnostics .Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression .Code (),
912
+ diagnostics .Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier .Code (),
913
+ diagnostics .Tagged_template_expressions_are_not_permitted_in_an_optional_chain .Code (),
914
+ diagnostics .The_left_hand_side_of_a_for_of_statement_may_not_be_async .Code (),
915
+ diagnostics .The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer .Code (),
916
+ diagnostics .The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer .Code (),
917
+ diagnostics .Trailing_comma_not_allowed .Code (),
918
+ diagnostics .Variable_declaration_list_cannot_be_empty .Code (),
919
+ diagnostics .X_0_and_1_operations_cannot_be_mixed_without_parentheses .Code (),
920
+ diagnostics .X_0_expected .Code (),
921
+ diagnostics .X_0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2 .Code (),
922
+ diagnostics .X_0_list_cannot_be_empty .Code (),
923
+ diagnostics .X_0_modifier_already_seen .Code (),
924
+ diagnostics .X_0_modifier_cannot_appear_on_a_constructor_declaration .Code (),
925
+ diagnostics .X_0_modifier_cannot_appear_on_a_module_or_namespace_element .Code (),
926
+ diagnostics .X_0_modifier_cannot_appear_on_a_parameter .Code (),
927
+ diagnostics .X_0_modifier_cannot_appear_on_class_elements_of_this_kind .Code (),
928
+ diagnostics .X_0_modifier_cannot_be_used_here .Code (),
929
+ diagnostics .X_0_modifier_must_precede_1_modifier .Code (),
930
+ diagnostics .X_0_declarations_can_only_be_declared_inside_a_block .Code (),
931
+ diagnostics .X_0_declarations_must_be_initialized .Code (),
932
+ diagnostics .X_extends_clause_already_seen .Code (),
933
+ diagnostics .X_let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations .Code (),
934
+ diagnostics .Class_constructor_may_not_be_a_generator .Code (),
935
+ diagnostics .Class_constructor_may_not_be_an_accessor .Code (),
936
+ diagnostics .X_await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules .Code (),
937
+ diagnostics .X_await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules .Code (),
938
+ diagnostics .Private_field_0_must_be_declared_in_an_enclosing_class .Code (),
939
+ // Type errors
940
+ diagnostics .This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value .Code (),
941
+ )
0 commit comments