Skip to content

Commit 6d06db4

Browse files
committed
feat(typescript): error on 'declare import ...'
1 parent ae792da commit 6d06db4

14 files changed

+106
-8
lines changed

po/de.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,11 @@ msgstr ""
14241424
msgid "move the 'extends' clause before 'implements' here"
14251425
msgstr ""
14261426

1427+
#: src/quick-lint-js/diag/diagnostic-types.h
1428+
#, fuzzy
1429+
msgid "cannot use 'declare' keyword with 'import'"
1430+
msgstr "Kann keine Variable namens 'let' deklarieren und exportieren"
1431+
14271432
#: src/quick-lint-js/diag/diagnostic-types.h
14281433
#, fuzzy
14291434
msgid "TypeScript import aliases are not allowed in JavaScript"

po/[email protected]

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,11 @@ msgstr ""
13511351
msgid "move the 'extends' clause before 'implements' here"
13521352
msgstr ""
13531353

1354+
#: src/quick-lint-js/diag/diagnostic-types.h
1355+
#, fuzzy
1356+
msgid "cannot use 'declare' keyword with 'import'"
1357+
msgstr "variables don't belong here"
1358+
13541359
#: src/quick-lint-js/diag/diagnostic-types.h
13551360
#, fuzzy
13561361
msgid "TypeScript import aliases are not allowed in JavaScript"

po/fr_FR.po

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,12 @@ msgstr ""
14401440
msgid "move the 'extends' clause before 'implements' here"
14411441
msgstr ""
14421442

1443+
#: src/quick-lint-js/diag/diagnostic-types.h
1444+
#, fuzzy
1445+
msgid "cannot use 'declare' keyword with 'import'"
1446+
msgstr ""
1447+
"impossible de déclarer et d'exporter une variable avec 'export default'"
1448+
14431449
#: src/quick-lint-js/diag/diagnostic-types.h
14441450
#, fuzzy
14451451
msgid "TypeScript import aliases are not allowed in JavaScript"

po/messages.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,10 @@ msgstr ""
12431243
msgid "move the 'extends' clause before 'implements' here"
12441244
msgstr ""
12451245

1246+
#: src/quick-lint-js/diag/diagnostic-types.h
1247+
msgid "cannot use 'declare' keyword with 'import'"
1248+
msgstr ""
1249+
12461250
#: src/quick-lint-js/diag/diagnostic-types.h
12471251
msgid "TypeScript import aliases are not allowed in JavaScript"
12481252
msgstr ""

po/pt_BR.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,11 @@ msgstr "'extends' precisa ficar antes do 'implements'"
12891289
msgid "move the 'extends' clause before 'implements' here"
12901290
msgstr "mova a cláusula 'extends' para antes do 'implements' aqui"
12911291

1292+
#: src/quick-lint-js/diag/diagnostic-types.h
1293+
#, fuzzy
1294+
msgid "cannot use 'declare' keyword with 'import'"
1295+
msgstr "não é possível declarar e exportar variável com 'export default'"
1296+
12921297
#: src/quick-lint-js/diag/diagnostic-types.h
12931298
msgid "TypeScript import aliases are not allowed in JavaScript"
12941299
msgstr "apelidos de importação do TypeScript não são permitidos em JavaScript"

po/sv_SE.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,11 @@ msgstr ""
13441344
msgid "move the 'extends' clause before 'implements' here"
13451345
msgstr ""
13461346

1347+
#: src/quick-lint-js/diag/diagnostic-types.h
1348+
#, fuzzy
1349+
msgid "cannot use 'declare' keyword with 'import'"
1350+
msgstr "kan inte deklarera och exportera variabel med 'export default'"
1351+
13471352
#: src/quick-lint-js/diag/diagnostic-types.h
13481353
#, fuzzy
13491354
msgid "TypeScript import aliases are not allowed in JavaScript"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,12 @@
26902690
use) \
26912691
MESSAGE(QLJS_TRANSLATABLE("function declared here"), declaration)) \
26922692
\
2693+
QLJS_DIAG_TYPE( \
2694+
diag_import_cannot_have_declare_keyword, "E0360", \
2695+
diagnostic_severity::error, { source_code_span declare_keyword; }, \
2696+
MESSAGE(QLJS_TRANSLATABLE("cannot use 'declare' keyword with 'import'"), \
2697+
declare_keyword)) \
2698+
\
26932699
QLJS_DIAG_TYPE( \
26942700
diag_interface_fields_cannot_have_initializers, "E0221", \
26952701
diagnostic_severity::error, { source_code_span equal; }, \

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4602,16 +4602,23 @@ parser::parse_and_visit_possible_declare_statement(parse_visitor_base &v) {
46024602
case token_type::kw_const:
46034603
case token_type::kw_enum:
46044604
case token_type::kw_interface:
4605+
case token_type::kw_function:
46054606
case token_type::kw_let:
4607+
case token_type::kw_module:
46064608
case token_type::kw_type:
46074609
case token_type::kw_var:
4608-
case token_type::kw_function:
4609-
case token_type::kw_module:
46104610
case token_type::kw_namespace:
4611+
parse_as_declare_statement:
46114612
this->lexer_.commit_transaction(std::move(transaction));
46124613
this->parse_and_visit_declare_statement(v, declare_keyword_span);
46134614
return parse_possible_declare_result::parsed;
46144615

4616+
case token_type::kw_import:
4617+
this->diag_reporter_->report(diag_import_cannot_have_declare_keyword{
4618+
.declare_keyword = declare_keyword_span,
4619+
});
4620+
goto parse_as_declare_statement;
4621+
46154622
// declare: // Label.
46164623
// declare();
46174624
case token_type::colon:

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ const translation_table translation_data = {
164164
{45, 67, 67, 54, 58, 43}, //
165165
{74, 45, 80, 74, 69, 63}, //
166166
{0, 0, 0, 67, 0, 53}, //
167-
{0, 0, 0, 50, 0, 37}, //
167+
{0, 0, 0, 0, 0, 37}, //
168+
{0, 0, 0, 50, 0, 43}, //
168169
{72, 31, 71, 68, 56, 61}, //
169170
{34, 30, 0, 46, 0, 40}, //
170171
{0, 0, 0, 20, 0, 18}, //
@@ -1875,6 +1876,7 @@ const translation_table translation_data = {
18751876
u8"cannot reference private variables without object; use 'this.'\0"
18761877
u8"cannot update variable with '{0}' while declaring it\0"
18771878
u8"cannot use '...' on 'this' parameter\0"
1879+
u8"cannot use 'declare' keyword with 'import'\0"
18781880
u8"catch variable can only be typed as '*', 'any', or 'unknown'\0"
18791881
u8"character is not allowed in identifiers\0"
18801882
u8"children end here\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 = 431;
24-
constexpr std::size_t translation_table_string_table_size = 75850;
23+
constexpr std::uint16_t translation_table_mapping_table_size = 432;
24+
constexpr std::size_t translation_table_string_table_size = 75893;
2525
constexpr std::size_t translation_table_locale_table_size = 35;
2626

2727
QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up(
@@ -181,6 +181,7 @@ QLJS_CONSTEVAL std::uint16_t translation_table_const_look_up(
181181
"cannot reference private variables without object; use 'this.'"sv,
182182
"cannot update variable with '{0}' while declaring it"sv,
183183
"cannot use '...' on 'this' parameter"sv,
184+
"cannot use 'declare' keyword with 'import'"sv,
184185
"catch variable can only be typed as '*', 'any', or 'unknown'"sv,
185186
"character is not allowed in identifiers"sv,
186187
"children end here"sv,

0 commit comments

Comments
 (0)