* Provides a better error message than the generic "';' expected" if possible for * known common variants of a missing semicolon, such as from a mispelled names. * * @param node Node preceding the expected semicolon location.
(node)
| 32130 | * @param node Node preceding the expected semicolon location. |
| 32131 | */ |
| 32132 | function parseErrorForMissingSemicolonAfter(node) { |
| 32133 | var _a; |
| 32134 | // Tagged template literals are sometimes used in places where only simple strings are allowed, i.e.: |
| 32135 | // module `M1` { |
| 32136 | // ^^^^^^^^^^^ This block is parsed as a template literal like module`M1`. |
| 32137 | if (ts.isTaggedTemplateExpression(node)) { |
| 32138 | parseErrorAt(ts.skipTrivia(sourceText, node.template.pos), node.template.end, ts.Diagnostics.Module_declaration_names_may_only_use_or_quoted_strings); |
| 32139 | return; |
| 32140 | } |
| 32141 | // Otherwise, if this isn't a well-known keyword-like identifier, give the generic fallback message. |
| 32142 | var expressionText = ts.isIdentifier(node) ? ts.idText(node) : undefined; |
| 32143 | if (!expressionText || !ts.isIdentifierText(expressionText, languageVersion)) { |
| 32144 | parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(26 /* SyntaxKind.SemicolonToken */)); |
| 32145 | return; |
| 32146 | } |
| 32147 | var pos = ts.skipTrivia(sourceText, node.pos); |
| 32148 | // Some known keywords are likely signs of syntax being used improperly. |
| 32149 | switch (expressionText) { |
| 32150 | case "const": |
| 32151 | case "let": |
| 32152 | case "var": |
| 32153 | parseErrorAt(pos, node.end, ts.Diagnostics.Variable_declaration_not_allowed_at_this_location); |
| 32154 | return; |
| 32155 | case "declare": |
| 32156 | // If a declared node failed to parse, it would have emitted a diagnostic already. |
| 32157 | return; |
| 32158 | case "interface": |
| 32159 | parseErrorForInvalidName(ts.Diagnostics.Interface_name_cannot_be_0, ts.Diagnostics.Interface_must_be_given_a_name, 18 /* SyntaxKind.OpenBraceToken */); |
| 32160 | return; |
| 32161 | case "is": |
| 32162 | parseErrorAt(pos, scanner.getTextPos(), ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); |
| 32163 | return; |
| 32164 | case "module": |
| 32165 | case "namespace": |
| 32166 | parseErrorForInvalidName(ts.Diagnostics.Namespace_name_cannot_be_0, ts.Diagnostics.Namespace_must_be_given_a_name, 18 /* SyntaxKind.OpenBraceToken */); |
| 32167 | return; |
| 32168 | case "type": |
| 32169 | parseErrorForInvalidName(ts.Diagnostics.Type_alias_name_cannot_be_0, ts.Diagnostics.Type_alias_must_be_given_a_name, 63 /* SyntaxKind.EqualsToken */); |
| 32170 | return; |
| 32171 | } |
| 32172 | // The user alternatively might have misspelled or forgotten to add a space after a common keyword. |
| 32173 | var suggestion = (_a = ts.getSpellingSuggestion(expressionText, viableKeywordSuggestions, function (n) { return n; })) !== null && _a !== void 0 ? _a : getSpaceSuggestion(expressionText); |
| 32174 | if (suggestion) { |
| 32175 | parseErrorAt(pos, node.end, ts.Diagnostics.Unknown_keyword_or_identifier_Did_you_mean_0, suggestion); |
| 32176 | return; |
| 32177 | } |
| 32178 | // Unknown tokens are handled with their own errors in the scanner |
| 32179 | if (token() === 0 /* SyntaxKind.Unknown */) { |
| 32180 | return; |
| 32181 | } |
| 32182 | // Otherwise, we know this some kind of unknown word, not just a missing expected semicolon. |
| 32183 | parseErrorAt(pos, node.end, ts.Diagnostics.Unexpected_keyword_or_identifier); |
| 32184 | } |
| 32185 | /** |
| 32186 | * Reports a diagnostic error for the current token being an invalid name. |
| 32187 | * |
no test coverage detected
searching dependent graphs…