Skip to content

Commit bddbef9

Browse files
committed
Add grammarErrorAtPos errors
Also remove checkGrammarArguments; it's blocked entirely by the same parser error.
1 parent 4e07074 commit bddbef9

File tree

7 files changed

+283
-128
lines changed

7 files changed

+283
-128
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31013,7 +31013,7 @@ namespace ts {
3101331013
* @returns On success, the expression's signature's return type. On failure, anyType.
3101431014
*/
3101531015
function checkCallExpression(node: CallExpression | NewExpression, checkMode?: CheckMode): Type {
31016-
if (!checkGrammarTypeArguments(node, node.typeArguments)) checkGrammarArguments(node.arguments);
31016+
checkGrammarTypeArguments(node, node.typeArguments);
3101731017

3101831018
const signature = getResolvedSignature(node, /*candidatesOutArray*/ undefined, checkMode);
3101931019
if (signature === resolvingSignature) {
@@ -31133,7 +31133,7 @@ namespace ts {
3113331133

3113431134
function checkImportCallExpression(node: ImportCall): Type {
3113531135
// Check grammar of dynamic import
31136-
if (!checkGrammarArguments(node.arguments)) checkGrammarImportCallExpression(node);
31136+
checkGrammarImportCallExpression(node);
3113731137

3113831138
if (node.arguments.length === 0) {
3113931139
return createPromiseReturnType(node, anyType);
@@ -42917,21 +42917,6 @@ namespace ts {
4291742917
return false;
4291842918
}
4291942919

42920-
function checkGrammarForOmittedArgument(args: NodeArray<Expression> | undefined): boolean {
42921-
if (args) {
42922-
for (const arg of args) {
42923-
if (arg.kind === SyntaxKind.OmittedExpression) {
42924-
return grammarErrorAtPos(arg, arg.pos, 0, Diagnostics.Argument_expression_expected);
42925-
}
42926-
}
42927-
}
42928-
return false;
42929-
}
42930-
42931-
function checkGrammarArguments(args: NodeArray<Expression> | undefined): boolean {
42932-
return checkGrammarForOmittedArgument(args);
42933-
}
42934-
4293542920
function checkGrammarHeritageClause(node: HeritageClause): boolean {
4293642921
const types = node.types;
4293742922
if (checkGrammarForDisallowedTrailingComma(types)) {

src/compiler/program.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,11 @@ namespace ts {
850850
Diagnostics.A_get_accessor_cannot_have_parameters.code,
851851
Diagnostics.A_rest_element_cannot_contain_a_binding_pattern.code,
852852
Diagnostics.A_rest_element_cannot_have_a_property_name.code,
853+
Diagnostics.A_rest_element_cannot_have_an_initializer.code,
853854
Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern.code,
854855
Diagnostics.A_rest_parameter_cannot_have_an_initializer.code,
855856
Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list.code,
857+
Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma.code,
856858
Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
857859
Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
858860
Diagnostics.An_object_member_cannot_be_declared_optional.code,
@@ -871,16 +873,21 @@ namespace ts {
871873
Diagnostics.JSX_property_access_expressions_cannot_include_JSX_namespace_names.code,
872874
Diagnostics.Jump_target_cannot_cross_function_boundary.code,
873875
Diagnostics.Line_terminator_not_permitted_before_arrow.code,
876+
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement.code,
877+
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement.code,
874878
Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies.code,
875879
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,
876880
Diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier.code,
877881
Diagnostics.Tagged_template_expressions_are_not_permitted_in_an_optional_chain.code,
878882
Diagnostics.The_left_hand_side_of_a_for_of_statement_may_not_be_async.code,
879883
Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer.code,
880884
Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer.code,
881-
Diagnostics._0_expected.code,
885+
Diagnostics.Trailing_comma_not_allowed.code,
886+
Diagnostics.Variable_declaration_list_cannot_be_empty.code,
882887
Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses.code,
888+
Diagnostics._0_expected.code,
883889
Diagnostics._0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2.code,
890+
Diagnostics._0_list_cannot_be_empty.code,
884891
Diagnostics._0_modifier_already_seen.code,
885892
Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration.code,
886893
Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element.code,

tests/baselines/reference/plainJSGrammarErrors.errors.txt

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,56 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(59,1): error TS1042: 'asyn
4040
tests/cases/conformance/salsa/plainJSGrammarErrors.js(60,1): error TS1042: 'async' modifier cannot be used here.
4141
tests/cases/conformance/salsa/plainJSGrammarErrors.js(63,25): error TS1014: A rest parameter must be last in a parameter list.
4242
tests/cases/conformance/salsa/plainJSGrammarErrors.js(65,37): error TS1048: A rest parameter cannot have an initializer.
43-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(67,8): error TS2501: A rest element cannot contain a binding pattern.
44-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(69,12): error TS2462: A rest element must be last in a destructuring pattern.
45-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(70,33): error TS2566: A rest element cannot have a property name.
46-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(73,9): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
47-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(74,14): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
48-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(76,3): error TS1200: Line terminator not permitted before arrow.
49-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(78,4): error TS1358: Tagged template expressions are not permitted in an optional chain.
50-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(80,6): error TS1171: A comma expression is not allowed in a computed property name.
51-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(81,5): error TS18016: Private identifiers are not allowed outside class bodies.
52-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(82,5): error TS1042: 'export' modifier cannot be used here.
53-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(84,25): error TS1162: An object member cannot be declared optional.
54-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(85,6): error TS1162: An object member cannot be declared optional.
55-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(85,6): error TS8009: The '?' modifier can only be used in TypeScript files.
56-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(86,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
57-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(87,19): error TS1255: A definite assignment assertion '!' is not permitted in this context.
58-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(90,16): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
59-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(94,7): error TS1182: A destructuring declaration must have an initializer.
60-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(95,7): error TS1155: 'const' declarations must be initialized.
61-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(96,5): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
62-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(96,5): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
63-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(98,5): error TS1157: 'let' declarations can only be declared inside a block.
64-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(100,5): error TS1156: 'const' declarations can only be declared inside a block.
65-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(105,6): error TS1106: The left-hand side of a 'for...of' statement may not be 'async'.
66-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(108,12): error TS1190: The variable declaration of a 'for...of' statement cannot have an initializer.
67-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(111,12): error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer.
68-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(121,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement.
69-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(128,11): error TS2492: Cannot redeclare identifier 'e' in catch clause.
70-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(132,5): error TS1114: Duplicate label 'label'.
71-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(141,13): error TS1107: Jump target cannot cross function boundary.
72-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(149,13): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement.
73-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(153,5): error TS1107: Jump target cannot cross function boundary.
74-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(156,5): error TS1116: A 'break' statement can only jump to a label of an enclosing statement.
75-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(157,5): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement.
76-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(159,1): error TS1105: A 'break' statement can only be used within an enclosing iteration or switch statement.
77-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(160,1): error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
78-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(163,28): error TS17012: 'metal' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
79-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(164,22): error TS17012: 'targe' is not a valid meta-property for keyword 'new'. Did you mean 'target'?
80-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(165,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
81-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(166,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
82-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(167,36): error TS1325: Argument of dynamic import cannot be spread element.
43+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(67,41): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
44+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(69,8): error TS2501: A rest element cannot contain a binding pattern.
45+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(71,12): error TS2462: A rest element must be last in a destructuring pattern.
46+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(72,33): error TS2566: A rest element cannot have a property name.
47+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(73,42): error TS1186: A rest element cannot have an initializer.
48+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(76,4): error TS1123: Variable declaration list cannot be empty.
49+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(77,9): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
50+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(78,14): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
51+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(80,3): error TS1200: Line terminator not permitted before arrow.
52+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(82,4): error TS1358: Tagged template expressions are not permitted in an optional chain.
53+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(84,6): error TS1171: A comma expression is not allowed in a computed property name.
54+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(85,5): error TS18016: Private identifiers are not allowed outside class bodies.
55+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(86,5): error TS1042: 'export' modifier cannot be used here.
56+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(88,25): error TS1162: An object member cannot be declared optional.
57+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(89,6): error TS1162: An object member cannot be declared optional.
58+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(89,6): error TS8009: The '?' modifier can only be used in TypeScript files.
59+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(90,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
60+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(91,19): error TS1255: A definite assignment assertion '!' is not permitted in this context.
61+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(94,16): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
62+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(96,24): error TS1009: Trailing comma not allowed.
63+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(97,29): error TS1097: 'extends' list cannot be empty.
64+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(100,7): error TS1182: A destructuring declaration must have an initializer.
65+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(101,7): error TS1155: 'const' declarations must be initialized.
66+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(102,5): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
67+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(102,5): error TS2480: 'let' is not allowed to be used as a name in 'let' or 'const' declarations.
68+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(104,5): error TS1157: 'let' declarations can only be declared inside a block.
69+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(106,5): error TS1156: 'const' declarations can only be declared inside a block.
70+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(111,6): error TS1106: The left-hand side of a 'for...of' statement may not be 'async'.
71+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(114,12): error TS1190: The variable declaration of a 'for...of' statement cannot have an initializer.
72+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(117,12): error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer.
73+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(120,13): error TS1188: Only a single variable declaration is allowed in a 'for...of' statement.
74+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(123,13): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement.
75+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(134,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement.
76+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(141,11): error TS2492: Cannot redeclare identifier 'e' in catch clause.
77+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(145,5): error TS1114: Duplicate label 'label'.
78+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(154,13): error TS1107: Jump target cannot cross function boundary.
79+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(162,13): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement.
80+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(166,5): error TS1107: Jump target cannot cross function boundary.
81+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(169,5): error TS1116: A 'break' statement can only jump to a label of an enclosing statement.
82+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(170,5): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement.
83+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(172,1): error TS1105: A 'break' statement can only be used within an enclosing iteration or switch statement.
84+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(173,1): error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
85+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(176,28): error TS17012: 'metal' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
86+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(177,22): error TS17012: 'targe' is not a valid meta-property for keyword 'new'. Did you mean 'target'?
87+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(178,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
88+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(179,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
89+
tests/cases/conformance/salsa/plainJSGrammarErrors.js(180,36): error TS1325: Argument of dynamic import cannot be spread element.
8390

8491

85-
==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (82 errors) ====
92+
==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (89 errors) ====
8693
class C {
8794
// #private mistakes
8895
q = #unbound
@@ -232,6 +239,10 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(167,36): error TS1325: Arg
232239
function restCantHaveInitialiser(...x = [1,2,3]) {
233240
~
234241
!!! error TS1048: A rest parameter cannot have an initializer.
242+
}
243+
function restCantHaveTrailingComma (...x,) {
244+
~
245+
!!! error TS1013: A rest parameter or binding pattern may not have a trailing comma.
235246
}
236247
;({ ...{} } = {})
237248
~~
@@ -243,8 +254,14 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(167,36): error TS1325: Arg
243254
const { e: eep, m: em, ...rest: noRestAllowed } = doom
244255
~~~~~~~~~~~~~
245256
!!! error TS2566: A rest element cannot have a property name.
257+
const { e: erp, m: erm, ...noInitialiser = true } = doom
258+
~
259+
!!! error TS1186: A rest element cannot have an initializer.
246260

247261
// left-over parsing
262+
var;
263+
264+
!!! error TS1123: Variable declaration list cannot be empty.
248265
var x = 1 || 2 ?? 3
249266
~~~~~~
250267
!!! error TS5076: '||' and '??' operations cannot be mixed without parentheses.
@@ -290,6 +307,12 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(167,36): error TS1325: Arg
290307
~
291308
!!! error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
292309
}
310+
var noTrailingComma = 1,;
311+
~
312+
!!! error TS1009: Trailing comma not allowed.
313+
class MissingExtends extends { }
314+
315+
!!! error TS1097: 'extends' list cannot be empty.
293316

294317
// let/const mistakes
295318
const { e: ee };
@@ -330,6 +353,17 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(167,36): error TS1325: Arg
330353
!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer.
331354
console.log(cantHaveInit)
332355
}
356+
for (let y, x of [1,2,3]) {
357+
~
358+
!!! error TS1188: Only a single variable declaration is allowed in a 'for...of' statement.
359+
console.log(x)
360+
}
361+
for (let y, x in [1,2,3]) {
362+
~
363+
!!! error TS1091: Only a single variable declaration is allowed in a 'for...in' statement.
364+
console.log(x)
365+
}
366+
333367
// duplication mistakes
334368
var b
335369
switch (b) {

0 commit comments

Comments
 (0)