Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eb28e20

Browse files
sandersnmprobst
authored andcommittedJan 10, 2022
Add 12 more grammar errors (microsoft#47075)
These are the last ones that I know of. They come from calls to `grammarErrorOnFirstToken`. Fixes part of microsoft#45349 Follow-up to microsoft#47067
1 parent 67f9895 commit eb28e20

File tree

6 files changed

+477
-207
lines changed

6 files changed

+477
-207
lines changed
 

‎src/compiler/program.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,14 @@ namespace ts {
839839
// grammar errors
840840
Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement.code,
841841
Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement.code,
842+
Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name.code,
842843
Diagnostics.A_class_member_cannot_have_the_0_keyword.code,
843844
Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name.code,
844845
Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement.code,
845846
Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement.code,
846847
Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement.code,
847848
Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement.code,
849+
Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration.code,
848850
Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context.code,
849851
Diagnostics.A_destructuring_declaration_must_have_an_initializer.code,
850852
Diagnostics.A_get_accessor_cannot_have_parameters.code,
@@ -855,13 +857,21 @@ namespace ts {
855857
Diagnostics.A_rest_parameter_cannot_have_an_initializer.code,
856858
Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list.code,
857859
Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma.code,
860+
Diagnostics.A_return_statement_can_only_be_used_within_a_function_body.code,
861+
Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
858862
Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
859863
Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
864+
Diagnostics.An_export_declaration_can_only_be_used_in_a_module.code,
865+
Diagnostics.An_export_declaration_cannot_have_modifiers.code,
866+
Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module.code,
867+
Diagnostics.An_import_declaration_cannot_have_modifiers.code,
860868
Diagnostics.An_object_member_cannot_be_declared_optional.code,
861869
Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
862870
Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable.code,
863871
Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause.code,
872+
Diagnostics.Catch_clause_variable_cannot_have_an_initializer.code,
864873
Diagnostics.Class_decorators_can_t_be_used_with_static_private_identifier_Consider_removing_the_experimental_decorator.code,
874+
Diagnostics.Classes_can_only_extend_a_single_class.code,
865875
Diagnostics.Classes_may_not_have_a_field_named_constructor.code,
866876
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,
867877
Diagnostics.Duplicate_label_0.code,
@@ -873,6 +883,7 @@ namespace ts {
873883
Diagnostics.JSX_property_access_expressions_cannot_include_JSX_namespace_names.code,
874884
Diagnostics.Jump_target_cannot_cross_function_boundary.code,
875885
Diagnostics.Line_terminator_not_permitted_before_arrow.code,
886+
Diagnostics.Modifiers_cannot_appear_here.code,
876887
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement.code,
877888
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement.code,
878889
Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies.code,
@@ -897,6 +908,7 @@ namespace ts {
897908
Diagnostics._0_modifier_must_precede_1_modifier.code,
898909
Diagnostics.const_declarations_can_only_be_declared_inside_a_block.code,
899910
Diagnostics.const_declarations_must_be_initialized.code,
911+
Diagnostics.extends_clause_already_seen.code,
900912
Diagnostics.let_declarations_can_only_be_declared_inside_a_block.code,
901913
Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
902914
]);

‎tests/baselines/reference/plainJSGrammarErrors.errors.txt

Lines changed: 151 additions & 82 deletions
Large diffs are not rendered by default.

‎tests/baselines/reference/plainJSGrammarErrors.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class C {
1515
for await (const x of [1,2,3]) {
1616
console.log(x)
1717
}
18+
return null
1819
}
1920
// modifier mistakes
2021
static constructor() { }
@@ -40,6 +41,11 @@ class C {
4041
// other
4142
"constructor" = 16
4243
}
44+
class {
45+
missingName = true
46+
}
47+
class Doubler extends C extends C { }
48+
class Trebler extends C,C,C { }
4349
// #private mistakes
4450
#unrelated
4551
junk.#m
@@ -59,6 +65,20 @@ async class CantAsyncClass {
5965
async const cantAsyncConst = 2
6066
async import 'assert'
6167
async export { CantAsyncClass }
68+
export import 'fs'
69+
export export { C }
70+
function nestedExports() {
71+
export { staticParam }
72+
import 'fs'
73+
export default 12
74+
}
75+
function outerStaticFunction() {
76+
static function staticFunction() { }
77+
}
78+
const noStaticLiteralMethods = {
79+
static m() {
80+
}
81+
}
6282

6383
// rest parameters
6484
function restMustBeLast(...x, y) {
@@ -142,6 +162,11 @@ catch (e) {
142162
const e = 1
143163
console.log(e)
144164
}
165+
try {
166+
throw 20
167+
}
168+
catch (e = 0) {
169+
}
145170
label: for (const x in [1,2,3]) {
146171
label: for (const y in [1,2,3]) {
147172
break label;
@@ -179,6 +204,8 @@ function foo() { new.targe }
179204
const nullaryDynamicImport = import()
180205
const trinaryDynamicImport = import('1', '2', '3')
181206
const spreadDynamicImport = import(...[])
207+
208+
return
182209
183210
184211
//// [plainJSGrammarErrors.js]
@@ -198,6 +225,7 @@ class C {
198225
for await (const x of [1, 2, 3]) {
199226
console.log(x);
200227
}
228+
return null;
201229
}
202230
// modifier mistakes
203231
static constructor() { }
@@ -221,6 +249,13 @@ class C {
221249
// other
222250
"constructor" = 16;
223251
}
252+
class {
253+
missingName = true;
254+
}
255+
class Doubler extends C extends C {
256+
}
257+
class Trebler extends C, C, C {
258+
}
224259
// #private mistakes
225260
#unrelated;
226261
junk.#m;
@@ -239,6 +274,20 @@ async class CantAsyncClass {
239274
async const cantAsyncConst = 2;
240275
async import 'assert';
241276
export { CantAsyncClass };
277+
export import 'fs';
278+
export { C };
279+
function nestedExports() {
280+
export { staticParam };
281+
import 'fs';
282+
export default 12;
283+
}
284+
function outerStaticFunction() {
285+
static function staticFunction() { }
286+
}
287+
const noStaticLiteralMethods = {
288+
static m() {
289+
}
290+
};
242291
// rest parameters
243292
function restMustBeLast(...x, y) {
244293
}
@@ -318,6 +367,11 @@ catch (e) {
318367
const e = 1;
319368
console.log(e);
320369
}
370+
try {
371+
throw 20;
372+
}
373+
catch (e = 0) {
374+
}
321375
label: for (const x in [1, 2, 3]) {
322376
label: for (const y in [1, 2, 3]) {
323377
break label;
@@ -353,3 +407,4 @@ function foo() { new.targe; }
353407
const nullaryDynamicImport = import();
354408
const trinaryDynamicImport = import('1', '2', '3');
355409
const spreadDynamicImport = import(...[]);
410+
return;

‎tests/baselines/reference/plainJSGrammarErrors.symbols

Lines changed: 176 additions & 125 deletions
Large diffs are not rendered by default.

‎tests/baselines/reference/plainJSGrammarErrors.types

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class C {
4141
>log : (...data: any[]) => void
4242
>x : number
4343
}
44+
return null
45+
>null : null
4446
}
4547
// modifier mistakes
4648
static constructor() { }
@@ -95,6 +97,22 @@ class C {
9597
>"constructor" : number
9698
>16 : 16
9799
}
100+
class {
101+
missingName = true
102+
>missingName : boolean
103+
>true : true
104+
}
105+
class Doubler extends C extends C { }
106+
>Doubler : Doubler
107+
>C : C
108+
>C : C
109+
110+
class Trebler extends C,C,C { }
111+
>Trebler : Trebler
112+
>C : C
113+
>C : C
114+
>C : C
115+
98116
// #private mistakes
99117
#unrelated
100118
junk.#m
@@ -157,6 +175,34 @@ async import 'assert'
157175
async export { CantAsyncClass }
158176
>CantAsyncClass : typeof CantAsyncClass
159177

178+
export import 'fs'
179+
export export { C }
180+
>C : typeof C
181+
182+
function nestedExports() {
183+
>nestedExports : () => void
184+
185+
export { staticParam }
186+
>staticParam : any
187+
188+
import 'fs'
189+
export default 12
190+
}
191+
function outerStaticFunction() {
192+
>outerStaticFunction : () => void
193+
194+
static function staticFunction() { }
195+
>staticFunction : () => void
196+
}
197+
const noStaticLiteralMethods = {
198+
>noStaticLiteralMethods : { m(): void; }
199+
>{ static m() { }} : { m(): void; }
200+
201+
static m() {
202+
>m : () => void
203+
}
204+
}
205+
160206
// rest parameters
161207
function restMustBeLast(...x, y) {
162208
>restMustBeLast : (...x: any[], y: any) => void
@@ -471,6 +517,14 @@ catch (e) {
471517
>log : (...data: any[]) => void
472518
>e : 1
473519
}
520+
try {
521+
throw 20
522+
>20 : 20
523+
}
524+
catch (e = 0) {
525+
>e : any
526+
>0 : 0
527+
}
474528
label: for (const x in [1,2,3]) {
475529
>label : any
476530
>x : string
@@ -570,3 +624,5 @@ const spreadDynamicImport = import(...[])
570624
>...[] : undefined
571625
>[] : undefined[]
572626

627+
return
628+

‎tests/cases/conformance/salsa/plainJSGrammarErrors.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class C {
1919
for await (const x of [1,2,3]) {
2020
console.log(x)
2121
}
22+
return null
2223
}
2324
// modifier mistakes
2425
static constructor() { }
@@ -44,6 +45,11 @@ class C {
4445
// other
4546
"constructor" = 16
4647
}
48+
class {
49+
missingName = true
50+
}
51+
class Doubler extends C extends C { }
52+
class Trebler extends C,C,C { }
4753
// #private mistakes
4854
#unrelated
4955
junk.#m
@@ -63,6 +69,20 @@ async class CantAsyncClass {
6369
async const cantAsyncConst = 2
6470
async import 'assert'
6571
async export { CantAsyncClass }
72+
export import 'fs'
73+
export export { C }
74+
function nestedExports() {
75+
export { staticParam }
76+
import 'fs'
77+
export default 12
78+
}
79+
function outerStaticFunction() {
80+
static function staticFunction() { }
81+
}
82+
const noStaticLiteralMethods = {
83+
static m() {
84+
}
85+
}
6686

6787
// rest parameters
6888
function restMustBeLast(...x, y) {
@@ -146,6 +166,11 @@ catch (e) {
146166
const e = 1
147167
console.log(e)
148168
}
169+
try {
170+
throw 20
171+
}
172+
catch (e = 0) {
173+
}
149174
label: for (const x in [1,2,3]) {
150175
label: for (const y in [1,2,3]) {
151176
break label;
@@ -183,3 +208,5 @@ function foo() { new.targe }
183208
const nullaryDynamicImport = import()
184209
const trinaryDynamicImport = import('1', '2', '3')
185210
const spreadDynamicImport = import(...[])
211+
212+
return

0 commit comments

Comments
 (0)
Please sign in to comment.