@@ -9,9 +9,12 @@ import {
9
9
CommentRange ,
10
10
compareValues ,
11
11
Debug ,
12
+ DiagnosticArguments ,
12
13
DiagnosticMessage ,
13
14
Diagnostics ,
15
+ DiagnosticWithDetachedLocation ,
14
16
forEach ,
17
+ getSpellingSuggestion ,
15
18
identity ,
16
19
JSDocSyntaxKind ,
17
20
JsxTokenSyntaxKind ,
@@ -31,7 +34,7 @@ import {
31
34
TokenFlags ,
32
35
} from "./_namespaces/ts" ;
33
36
34
- export type ErrorCallback = ( message : DiagnosticMessage , length : number , arg0 ?: any ) => void ;
37
+ export type ErrorCallback = ( message : DiagnosticMessage , pos : number , length : number , ... args : DiagnosticArguments ) => DiagnosticWithDetachedLocation | undefined ;
35
38
36
39
/** @internal */
37
40
export function tokenIsIdentifierOrKeyword ( token : SyntaxKind ) : boolean {
@@ -1119,15 +1122,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
1119
1122
1120
1123
return scanner ;
1121
1124
1122
- function error ( message : DiagnosticMessage ) : void ;
1123
- function error ( message : DiagnosticMessage , errPos : number , length : number , arg0 ?: any ) : void ;
1124
- function error ( message : DiagnosticMessage , errPos : number = pos , length ?: number , arg0 ?: any ) : void {
1125
- if ( onError ) {
1126
- const oldPos = pos ;
1127
- pos = errPos ;
1128
- onError ( message , length || 0 , arg0 ) ;
1129
- pos = oldPos ;
1130
- }
1125
+ function error ( message : DiagnosticMessage , errPos = pos , length = 0 , ...args : DiagnosticArguments ) : DiagnosticWithDetachedLocation | undefined {
1126
+ return onError ?.( message , errPos , length , ...args ) ;
1131
1127
}
1132
1128
1133
1129
function scanNumberFragment ( ) : string {
@@ -3290,6 +3286,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
3290
3286
}
3291
3287
else if ( propertyName === undefined ) {
3292
3288
error ( Diagnostics . Unknown_Unicode_property_name , propertyNameOrValueStart , pos - propertyNameOrValueStart ) ;
3289
+ const suggestion = getSpellingSuggestion ( propertyNameOrValue , nonBinaryUnicodeProperties . keys ( ) , identity ) ;
3290
+ if ( suggestion ) {
3291
+ error ( Diagnostics . Did_you_mean_0 , propertyNameOrValueStart , pos - propertyNameOrValueStart , suggestion ) ;
3292
+ }
3293
3293
}
3294
3294
pos ++ ;
3295
3295
const propertyValueStart = pos ;
@@ -3299,6 +3299,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
3299
3299
}
3300
3300
else if ( propertyName !== undefined && ! valuesOfNonBinaryUnicodeProperties [ propertyName ] . has ( propertyValue ) ) {
3301
3301
error ( Diagnostics . Unknown_Unicode_property_value , propertyValueStart , pos - propertyValueStart ) ;
3302
+ const suggestion = getSpellingSuggestion ( propertyValue , valuesOfNonBinaryUnicodeProperties [ propertyName ] , identity ) ;
3303
+ if ( suggestion ) {
3304
+ error ( Diagnostics . Did_you_mean_0 , propertyValueStart , pos - propertyValueStart , suggestion ) ;
3305
+ }
3302
3306
}
3303
3307
}
3304
3308
else {
@@ -3318,6 +3322,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
3318
3322
}
3319
3323
else if ( ! valuesOfNonBinaryUnicodeProperties . General_Category . has ( propertyNameOrValue ) && ! binaryUnicodeProperties . has ( propertyNameOrValue ) ) {
3320
3324
error ( Diagnostics . Unknown_Unicode_property_name_or_value , propertyNameOrValueStart , pos - propertyNameOrValueStart ) ;
3325
+ const suggestion = getSpellingSuggestion ( propertyNameOrValue , [ ...valuesOfNonBinaryUnicodeProperties . General_Category , ...binaryUnicodeProperties , ...binaryUnicodePropertiesOfStrings ] , identity ) ;
3326
+ if ( suggestion ) {
3327
+ error ( Diagnostics . Did_you_mean_0 , propertyNameOrValueStart , pos - propertyNameOrValueStart , suggestion ) ;
3328
+ }
3321
3329
}
3322
3330
}
3323
3331
scanExpectedChar ( CharacterCodes . closeBrace ) ;
0 commit comments