mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Provide Syntax Checking for Regular Expressions (#55600)
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
co-authored by
Daniel Rosenwasser
Jake Bailey
parent
8e8c1b6a64
commit
42f238bfbb
@@ -62,6 +62,7 @@ import {
|
||||
DeleteExpression,
|
||||
Diagnostic,
|
||||
DiagnosticArguments,
|
||||
DiagnosticCategory,
|
||||
DiagnosticMessage,
|
||||
Diagnostics,
|
||||
DiagnosticWithDetachedLocation,
|
||||
@@ -113,6 +114,7 @@ import {
|
||||
HasModifiers,
|
||||
HeritageClause,
|
||||
Identifier,
|
||||
identity,
|
||||
idText,
|
||||
IfStatement,
|
||||
ImportAttribute,
|
||||
@@ -2142,7 +2144,11 @@ namespace Parser {
|
||||
// Don't report another error if it would just be at the same position as the last error.
|
||||
const lastError = lastOrUndefined(parseDiagnostics);
|
||||
let result: DiagnosticWithDetachedLocation | undefined;
|
||||
if (!lastError || start !== lastError.start) {
|
||||
if (message.category === DiagnosticCategory.Message && lastError && start === lastError.start && length === lastError.length) {
|
||||
result = createDetachedDiagnostic(fileName, sourceText, start, length, message, ...args);
|
||||
addRelatedInfo(lastError, result);
|
||||
}
|
||||
else if (!lastError || start !== lastError.start) {
|
||||
result = createDetachedDiagnostic(fileName, sourceText, start, length, message, ...args);
|
||||
parseDiagnostics.push(result);
|
||||
}
|
||||
@@ -2398,7 +2404,7 @@ namespace Parser {
|
||||
}
|
||||
|
||||
// The user alternatively might have misspelled or forgotten to add a space after a common keyword.
|
||||
const suggestion = getSpellingSuggestion(expressionText, viableKeywordSuggestions, n => n) ?? getSpaceSuggestion(expressionText);
|
||||
const suggestion = getSpellingSuggestion(expressionText, viableKeywordSuggestions, identity) ?? getSpaceSuggestion(expressionText);
|
||||
if (suggestion) {
|
||||
parseErrorAt(pos, node.end, Diagnostics.Unknown_keyword_or_identifier_Did_you_mean_0, suggestion);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user