From fd0edfbdb902907d79d69faf4e525c571e3e0434 Mon Sep 17 00:00:00 2001 From: Valekh Bayramov Date: Tue, 26 Sep 2023 21:42:34 +0300 Subject: [PATCH] fix: renamed functions, improved diag messages --- docs/errors/E0713.md | 4 ++-- docs/errors/E0714.md | 4 ++-- po/messages.pot | 2 +- .../diag/diagnostic-metadata-generated.cpp | 4 ++-- src/quick-lint-js/diag/diagnostic-types-2.h | 8 +++---- src/quick-lint-js/fe/parse-class.cpp | 17 +++++--------- .../i18n/translation-table-generated.cpp | 6 ++--- .../i18n/translation-table-generated.h | 4 ++-- .../i18n/translation-table-test-generated.h | 22 +++++++++---------- test/test-parse-class.cpp | 18 +++++---------- 10 files changed, 38 insertions(+), 51 deletions(-) diff --git a/docs/errors/E0713.md b/docs/errors/E0713.md index 772191ead4..32c9e3e6d3 100644 --- a/docs/errors/E0713.md +++ b/docs/errors/E0713.md @@ -1,4 +1,4 @@ -# E0713: '*' keyword is not allowed on getters or setters +# E0713: getters and setters cannot be generators Use of the '*' character, defining generator functions, is not allowed on getters or setters. Getters and setters are synchronous operations and do not support the generator functionality. @@ -18,7 +18,7 @@ class C { } ``` -To fix this error define with a getter or setter, using regular function syntax. +To fix this error define a getter or setter, using regular function syntax. ```javascript class C { diff --git a/docs/errors/E0714.md b/docs/errors/E0714.md index a63a9679c3..1d3e3f9a72 100644 --- a/docs/errors/E0714.md +++ b/docs/errors/E0714.md @@ -21,7 +21,7 @@ class C { ``` To fix this error simply remove 'async' keyword from getters and setters, -so they can function properly as synchronous operations +so they can function properly as synchronous operations. ```javascript @@ -41,7 +41,7 @@ class C { ``` However, if you require asynchronous behavior within getters or setters, -you can achieve this by implementing separate asynchronous methods +you can achieve this by implementing separate asynchronous methods. ```javascript diff --git a/po/messages.pot b/po/messages.pot index 8e13d5e2a0..a3c37737ed 100644 --- a/po/messages.pot +++ b/po/messages.pot @@ -2058,7 +2058,7 @@ msgid "missing ',' between array elements" msgstr "" #: src/quick-lint-js/diag/diagnostic-metadata-generated.cpp -msgid "'*' keyword is not allowed on getters or setters" +msgid "getters and setters cannot be generators" msgstr "" #: src/quick-lint-js/diag/diagnostic-metadata-generated.cpp diff --git a/src/quick-lint-js/diag/diagnostic-metadata-generated.cpp b/src/quick-lint-js/diag/diagnostic-metadata-generated.cpp index 23936abce7..ce89b6a7d3 100644 --- a/src/quick-lint-js/diag/diagnostic-metadata-generated.cpp +++ b/src/quick-lint-js/diag/diagnostic-metadata-generated.cpp @@ -6331,12 +6331,12 @@ const QLJS_CONSTINIT Diagnostic_Info all_diagnostic_infos[] = { .code = 713, .severity = Diagnostic_Severity::error, .message_formats = { - QLJS_TRANSLATABLE("'*' keyword is not allowed on getters or setters"), + QLJS_TRANSLATABLE("getters and setters cannot be generators"), QLJS_TRANSLATABLE("'{0}' here"), }, .message_args = { { - Diagnostic_Message_Arg_Info(offsetof(Diag_Class_Generator_On_Getter_Or_Setter, generator_keyword), Diagnostic_Arg_Type::source_code_span), + Diagnostic_Message_Arg_Info(offsetof(Diag_Class_Generator_On_Getter_Or_Setter, star_token), Diagnostic_Arg_Type::source_code_span), }, { Diagnostic_Message_Arg_Info(offsetof(Diag_Class_Generator_On_Getter_Or_Setter, getter_setter_keyword), Diagnostic_Arg_Type::source_code_span), diff --git a/src/quick-lint-js/diag/diagnostic-types-2.h b/src/quick-lint-js/diag/diagnostic-types-2.h index b5d23fe372..3fec098609 100644 --- a/src/quick-lint-js/diag/diagnostic-types-2.h +++ b/src/quick-lint-js/diag/diagnostic-types-2.h @@ -3264,11 +3264,10 @@ struct Diag_Missing_Comma_Between_Array_Elements { struct Diag_Class_Generator_On_Getter_Or_Setter { [[qljs::diag("E0713", Diagnostic_Severity::error)]] // - [[qljs::message("'*' keyword is not allowed on getters or setters", - ARG(generator_keyword))]] // + [[qljs::message("getters and setters cannot be generators", + ARG(star_token))]] // [[qljs::message("'{0}' here", ARG(getter_setter_keyword))]] // - Source_Code_Span method_start; - Source_Code_Span generator_keyword; + Source_Code_Span star_token; Source_Code_Span getter_setter_keyword; }; @@ -3277,7 +3276,6 @@ struct Diag_Class_Async_On_Getter_Or_Setter { [[qljs::message("'async' keyword is not allowed on getters or setters", ARG(async_keyword))]] // [[qljs::message("'{0}' here", ARG(getter_setter_keyword))]] // - Source_Code_Span method_start; Source_Code_Span async_keyword; Source_Code_Span getter_setter_keyword; }; diff --git a/src/quick-lint-js/fe/parse-class.cpp b/src/quick-lint-js/fe/parse-class.cpp index 7018d57d8f..e882398c6e 100644 --- a/src/quick-lint-js/fe/parse-class.cpp +++ b/src/quick-lint-js/fe/parse-class.cpp @@ -1155,8 +1155,8 @@ void Parser::parse_and_visit_class_or_interface_member( void check_modifiers_for_method() { error_if_accessor_method(); error_if_declare_method(); - error_if_generator_method(); - error_if_async_method(); + error_if_generator_getter_or_setter(); + error_if_async_getter_or_setter(); error_if_readonly_method(); error_if_async_or_generator_without_method_body(); error_if_invalid_access_specifier(); @@ -1326,40 +1326,35 @@ void Parser::parse_and_visit_class_or_interface_member( } } - void error_if_generator_method() { + void error_if_generator_getter_or_setter() { if (const Modifier *star_modifier = find_modifier(Token_Type::star)) { - Source_Code_Span method_start = p->peek().span(); if (const Modifier *get_modifier = find_modifier(Token_Type::kw_get)) { p->diag_reporter_->report(Diag_Class_Generator_On_Getter_Or_Setter{ - .method_start = method_start, - .generator_keyword = star_modifier->span, + .star_token = star_modifier->span, .getter_setter_keyword = get_modifier->span, }); } else if (const Modifier *set_modifier = find_modifier(Token_Type::kw_set)) { p->diag_reporter_->report(Diag_Class_Generator_On_Getter_Or_Setter{ - .method_start = method_start, - .generator_keyword = star_modifier->span, + .star_token = star_modifier->span, .getter_setter_keyword = set_modifier->span, }); } } } - void error_if_async_method() { + void error_if_async_getter_or_setter() { if (const Modifier *async_modifier = find_modifier(Token_Type::kw_async)) { Source_Code_Span method_start = p->peek().span(); if (const Modifier *get_modifier = find_modifier(Token_Type::kw_get)) { p->diag_reporter_->report(Diag_Class_Async_On_Getter_Or_Setter{ - .method_start = method_start, .async_keyword = async_modifier->span, .getter_setter_keyword = get_modifier->span, }); } else if (const Modifier *set_modifier = find_modifier(Token_Type::kw_set)) { p->diag_reporter_->report(Diag_Class_Async_On_Getter_Or_Setter{ - .method_start = method_start, .async_keyword = async_modifier->span, .getter_setter_keyword = set_modifier->span, }); diff --git a/src/quick-lint-js/i18n/translation-table-generated.cpp b/src/quick-lint-js/i18n/translation-table-generated.cpp index e78f4ab231..0216c2f0b2 100644 --- a/src/quick-lint-js/i18n/translation-table-generated.cpp +++ b/src/quick-lint-js/i18n/translation-table-generated.cpp @@ -18,8 +18,7 @@ const Translation_Table translation_data = { {74, 87, 79, 56, 0, 59}, // {71, 80, 60, 58, 0, 52}, // {0, 0, 0, 0, 0, 28}, // - {0, 0, 0, 0, 0, 63}, // - {31, 56, 0, 32, 0, 49}, // + {31, 56, 0, 32, 0, 63}, // {0, 0, 0, 0, 0, 67}, // {0, 0, 0, 70, 0, 26}, // {79, 25, 30, 63, 49593, 66}, // @@ -284,6 +283,7 @@ const Translation_Table translation_data = { {84, 28, 66, 75, 25, 54}, // {0, 0, 0, 70, 0, 52}, // {0, 0, 0, 0, 0, 45}, // + {0, 0, 0, 0, 0, 41}, // {70, 27, 0, 57, 0, 52}, // {0, 0, 0, 5, 0, 5}, // {5, 11, 66, 52, 54, 42}, // @@ -1807,7 +1807,6 @@ const Translation_Table translation_data = { u8"\"globals\" descriptor must be a boolean or an object\0" u8"\"globals\" must be an object\0" u8"'!' here treated as the TypeScript non-null assertion operator\0" - u8"'*' keyword is not allowed on getters or setters\0" u8"'**' operator cannot be used after unary '{1}' without parentheses\0" u8"',' should be ';' instead\0" u8"'.' is not allowed after generic arguments; write [\"{1}\"] instead\0" @@ -2072,6 +2071,7 @@ const Translation_Table translation_data = { u8"generator function '*' belongs after keyword function\0" u8"generator function '*' belongs before function name\0" u8"generic arrow function needs ',' here in TSX\0" + u8"getters and setters cannot be generators\0" u8"getters and setters cannot have overload signatures\0" u8"here\0" u8"here is the assignment assertion operator\0" diff --git a/src/quick-lint-js/i18n/translation-table-generated.h b/src/quick-lint-js/i18n/translation-table-generated.h index 4c471c8337..7c6c1d8612 100644 --- a/src/quick-lint-js/i18n/translation-table-generated.h +++ b/src/quick-lint-js/i18n/translation-table-generated.h @@ -19,7 +19,7 @@ using namespace std::literals::string_view_literals; constexpr std::uint32_t translation_table_locale_count = 5; constexpr std::uint16_t translation_table_mapping_table_size = 518; -constexpr std::size_t translation_table_string_table_size = 79741; +constexpr std::size_t translation_table_string_table_size = 79733; constexpr std::size_t translation_table_locale_table_size = 35; QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up( @@ -33,7 +33,6 @@ QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up( "\"globals\" descriptor must be a boolean or an object"sv, "\"globals\" must be an object"sv, "'!' here treated as the TypeScript non-null assertion operator"sv, - "'*' keyword is not allowed on getters or setters"sv, "'**' operator cannot be used after unary '{1}' without parentheses"sv, "',' should be ';' instead"sv, "'.' is not allowed after generic arguments; write [\"{1}\"] instead"sv, @@ -298,6 +297,7 @@ QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up( "generator function '*' belongs after keyword function"sv, "generator function '*' belongs before function name"sv, "generic arrow function needs ',' here in TSX"sv, + "getters and setters cannot be generators"sv, "getters and setters cannot have overload signatures"sv, "here"sv, "here is the assignment assertion operator"sv, diff --git a/src/quick-lint-js/i18n/translation-table-test-generated.h b/src/quick-lint-js/i18n/translation-table-test-generated.h index 1603ad9954..f8c4c73f5a 100644 --- a/src/quick-lint-js/i18n/translation-table-test-generated.h +++ b/src/quick-lint-js/i18n/translation-table-test-generated.h @@ -105,17 +105,6 @@ inline const Translated_String test_translation_table[517] = { u8"'!' here treated as the TypeScript non-null assertion operator", }, }, - { - "'*' keyword is not allowed on getters or setters"_translatable, - u8"'*' keyword is not allowed on getters or setters", - { - u8"'*' keyword is not allowed on getters or setters", - u8"'*' keyword is not allowed on getters or setters", - u8"'*' keyword is not allowed on getters or setters", - u8"'*' keyword is not allowed on getters or setters", - u8"'*' keyword is not allowed on getters or setters", - }, - }, { "'**' operator cannot be used after unary '{1}' without parentheses"_translatable, u8"'**' operator cannot be used after unary '{1}' without parentheses", @@ -3020,6 +3009,17 @@ inline const Translated_String test_translation_table[517] = { u8"generic arrow function needs ',' here in TSX", }, }, + { + "getters and setters cannot be generators"_translatable, + u8"getters and setters cannot be generators", + { + u8"getters and setters cannot be generators", + u8"getters and setters cannot be generators", + u8"getters and setters cannot be generators", + u8"getters and setters cannot be generators", + u8"getters and setters cannot be generators", + }, + }, { "getters and setters cannot have overload signatures"_translatable, u8"getters and setters cannot have overload signatures", diff --git a/test/test-parse-class.cpp b/test/test-parse-class.cpp index b76a6dce7e..3e86be02c0 100644 --- a/test/test-parse-class.cpp +++ b/test/test-parse-class.cpp @@ -839,26 +839,22 @@ TEST_F(Test_Parse_Class, accessor_cannot_be_method) { TEST_F(Test_Parse_Class, async_keyword_on_getters_and_setters) { test_parse_and_visit_statement( u8"class C { get async myMethod() { } }"_sv, // - u8" ^ Diag_Class_Async_On_Getter_Or_Setter.method_start\n"_diag - u8" ^^^^^ .async_keyword\n"_diag + u8" ^^^^^ Diag_Class_Async_On_Getter_Or_Setter.async_keyword\n"_diag u8" ^^^ .getter_setter_keyword"_diag, javascript_options); test_parse_and_visit_statement( u8"class C { set async myMethod() { } }"_sv, // - u8" ^ Diag_Class_Async_On_Getter_Or_Setter.method_start\n"_diag - u8" ^^^^^ .async_keyword\n"_diag + u8" ^^^^^ Diag_Class_Async_On_Getter_Or_Setter.async_keyword\n"_diag u8" ^^^ .getter_setter_keyword"_diag, javascript_options); test_parse_and_visit_statement( u8"class C { async get myMethod() { } }"_sv, // - u8" ^ Diag_Class_Async_On_Getter_Or_Setter.method_start\n"_diag - u8" ^^^ .getter_setter_keyword\n"_diag + u8" ^^^ Diag_Class_Async_On_Getter_Or_Setter.getter_setter_keyword\n"_diag u8" ^^^^^ .async_keyword"_diag, javascript_options); test_parse_and_visit_statement( u8"class C { async set myMethod() { } }"_sv, // - u8" ^ Diag_Class_Async_On_Getter_Or_Setter.method_start\n"_diag - u8" ^^^ .getter_setter_keyword\n"_diag + u8" ^^^ Diag_Class_Async_On_Getter_Or_Setter.getter_setter_keyword\n"_diag u8" ^^^^^ .async_keyword"_diag, javascript_options); } @@ -866,14 +862,12 @@ TEST_F(Test_Parse_Class, async_keyword_on_getters_and_setters) { TEST_F(Test_Parse_Class, getters_and_setters_cannot_be_generator) { test_parse_and_visit_statement( u8"class C { get *myMethod() { } }"_sv, // - u8" ^ Diag_Class_Generator_On_Getter_Or_Setter.method_start\n"_diag - u8" ^ .generator_keyword\n"_diag + u8" ^ Diag_Class_Generator_On_Getter_Or_Setter.star_token\n"_diag u8" ^^^ .getter_setter_keyword"_diag, javascript_options); test_parse_and_visit_statement( u8"class C { set *myMethod() { } }"_sv, // - u8" ^ Diag_Class_Generator_On_Getter_Or_Setter.method_start\n"_diag - u8" ^ .generator_keyword\n"_diag + u8" ^ Diag_Class_Generator_On_Getter_Or_Setter.star_token\n"_diag u8" ^^^ .getter_setter_keyword"_diag, javascript_options); }