Skip to content

Commit 366b64c

Browse files
committed
feat(fe): disallow commas in class fields
Fixes #835
1 parent 5171b88 commit 366b64c

13 files changed

+75
-6
lines changed

po/de.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,10 @@ msgstr ""
18521852
"Das 'enum' Feature aus TypeScript ist noch nicht in quick-lint-js "
18531853
"implementiert"
18541854

1855+
#: src/quick-lint-js/fe/diagnostic-types.h
1856+
msgid "',' should be ';' instead"
1857+
msgstr ""
1858+
18551859
#: test/test-diagnostic-formatter.cpp
18561860
#: test/test-vim-qflist-json-diag-reporter.cpp
18571861
msgid "something happened"

po/[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,10 @@ msgstr ""
17331733
msgid "function parameter cannot be parenthesized"
17341734
msgstr "TypeScript's 'interface' feature is not allowed in JavaScript code"
17351735

1736+
#: src/quick-lint-js/fe/diagnostic-types.h
1737+
msgid "',' should be ';' instead"
1738+
msgstr ""
1739+
17361740
#: test/test-diagnostic-formatter.cpp
17371741
#: test/test-vim-qflist-json-diag-reporter.cpp
17381742
msgid "something happened"

po/fr_FR.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,10 @@ msgstr ""
18691869
"la fonctionnalité 'enum' de TypeScript n'est pas encore implémentée dans "
18701870
"quick-lint-js"
18711871

1872+
#: src/quick-lint-js/fe/diagnostic-types.h
1873+
msgid "',' should be ';' instead"
1874+
msgstr ""
1875+
18721876
#: test/test-diagnostic-formatter.cpp
18731877
#: test/test-vim-qflist-json-diag-reporter.cpp
18741878
msgid "something happened"

po/messages.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,10 @@ msgstr ""
16141614
msgid "function parameter cannot be parenthesized"
16151615
msgstr ""
16161616

1617+
#: src/quick-lint-js/fe/diagnostic-types.h
1618+
msgid "',' should be ';' instead"
1619+
msgstr ""
1620+
16171621
#: test/test-diagnostic-formatter.cpp
16181622
#: test/test-vim-qflist-json-diag-reporter.cpp
16191623
msgid "something happened"

po/pt_BR.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,10 @@ msgstr "usar '{0}' com uma expressão regular sempre retorna '{1}'"
16691669
msgid "function parameter cannot be parenthesized"
16701670
msgstr "parâmetros opcionais do TypeScript requerem parênteses"
16711671

1672+
#: src/quick-lint-js/fe/diagnostic-types.h
1673+
msgid "',' should be ';' instead"
1674+
msgstr ""
1675+
16721676
#: test/test-diagnostic-formatter.cpp
16731677
#: test/test-vim-qflist-json-diag-reporter.cpp
16741678
msgid "something happened"

po/sv_SE.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,10 @@ msgstr ""
17411741
msgid "function parameter cannot be parenthesized"
17421742
msgstr "TypeScripts 'enum' är inte ännu implementerad av quick-lint-js"
17431743

1744+
#: src/quick-lint-js/fe/diagnostic-types.h
1745+
msgid "',' should be ';' instead"
1746+
msgstr ""
1747+
17441748
#: test/test-diagnostic-formatter.cpp
17451749
#: test/test-vim-qflist-json-diag-reporter.cpp
17461750
msgid "something happened"

src/quick-lint-js/fe/diagnostic-types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,11 @@
26592659
{ source_code_span left_paren_to_right_paren; }, \
26602660
MESSAGE(QLJS_TRANSLATABLE("function parameter cannot be parenthesized"), \
26612661
left_paren_to_right_paren)) \
2662+
\
2663+
QLJS_DIAG_TYPE( \
2664+
diag_unexpected_comma_after_field_initialization, "E0330", \
2665+
diagnostic_severity::error, { source_code_span comma; }, \
2666+
MESSAGE(QLJS_TRANSLATABLE("',' should be ';' instead"), comma)) \
26622667
/* END */
26632668

26642669
// QLJS_X_RESERVED_DIAG_TYPES lists reserved error codes. These codes were used

src/quick-lint-js/fe/parse-class.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,15 @@ void parser::parse_and_visit_class_or_interface_member(
752752
check_modifiers_for_field_without_type_annotation();
753753
this->parse_field_initializer();
754754
v.visit_property_declaration(property_name);
755-
p->consume_semicolon<diag_missing_semicolon_after_field>();
755+
if (p->peek().type == token_type::comma) {
756+
p->diag_reporter_->report(
757+
diag_unexpected_comma_after_field_initialization{
758+
.comma = p->peek().span(),
759+
});
760+
p->skip();
761+
} else {
762+
p->consume_semicolon<diag_missing_semicolon_after_field>();
763+
}
756764
break;
757765

758766
case token_type::identifier:
@@ -857,7 +865,7 @@ void parser::parse_and_visit_class_or_interface_member(
857865
});
858866
}
859867
p->skip();
860-
p->parse_and_visit_expression(v);
868+
p->parse_and_visit_expression(v, precedence{.commas = false});
861869
}
862870

863871
function_attributes function_attributes_from_modifiers(

src/quick-lint-js/i18n/translation-table-generated.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const translation_table translation_data = {
1818
{74, 87, 79, 56, 0, 59}, //
1919
{71, 80, 60, 58, 0, 52}, //
2020
{31, 56, 0, 32, 0, 28}, //
21-
{0, 0, 0, 70, 0, 67}, //
21+
{0, 0, 0, 0, 0, 67}, //
22+
{0, 0, 0, 70, 0, 26}, //
2223
{79, 25, 30, 63, 49857, 66}, //
2324
{0, 0, 0, 0, 0, 97}, //
2425
{0, 0, 0, 0, 0, 65}, //
@@ -1701,6 +1702,7 @@ const translation_table translation_data = {
17011702
u8"\"globals\" descriptor must be a boolean or an object\0"
17021703
u8"\"globals\" must be an object\0"
17031704
u8"'**' operator cannot be used after unary '{1}' without parentheses\0"
1705+
u8"',' should be ';' instead\0"
17041706
u8"'.' is not allowed after generic arguments; write [\"{1}\"] instead\0"
17051707
u8"'.' operator needs a key name; use + to concatenate strings; use [] to access with a dynamic key\0"
17061708
u8"'...' belongs before the tuple element name, not before the type\0"

src/quick-lint-js/i18n/translation-table-generated.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace quick_lint_js {
2020
using namespace std::literals::string_view_literals;
2121

2222
constexpr std::uint32_t translation_table_locale_count = 5;
23-
constexpr std::uint16_t translation_table_mapping_table_size = 402;
24-
constexpr std::size_t translation_table_string_table_size = 74596;
23+
constexpr std::uint16_t translation_table_mapping_table_size = 403;
24+
constexpr std::size_t translation_table_string_table_size = 74622;
2525
constexpr std::size_t translation_table_locale_table_size = 35;
2626

2727
QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up(
@@ -35,6 +35,7 @@ QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up(
3535
"\"globals\" descriptor must be a boolean or an object"sv,
3636
"\"globals\" must be an object"sv,
3737
"'**' operator cannot be used after unary '{1}' without parentheses"sv,
38+
"',' should be ';' instead"sv,
3839
"'.' is not allowed after generic arguments; write [\"{1}\"] instead"sv,
3940
"'.' operator needs a key name; use + to concatenate strings; use [] to access with a dynamic key"sv,
4041
"'...' belongs before the tuple element name, not before the type"sv,

0 commit comments

Comments
 (0)