diff --git a/internal/core/core.go b/internal/core/core.go index 2552a194fb..1ce98a8c74 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -557,17 +557,17 @@ func GetScriptKindFromFileName(fileName string) ScriptKind { // // @internal func GetSpellingSuggestion[T any](name string, candidates iter.Seq[T], getName func(T) string, compare func(T, T) int) T { - maximumLengthDifference := max(2, int(float64(len(name))*0.34)) - bestDistance := math.Floor(float64(len(name))*0.4) + 0.9 // If the best result is worse than this, don't bother. runeName := []rune(name) + maximumLengthDifference := max(2, int(float64(len(runeName))*0.34)) + bestDistance := math.Floor(float64(len(runeName))*0.4) + 0.9 // If the best result is worse than this, don't bother. buffers := levenshteinBuffersPool.Get().(*levenshteinBuffers) defer levenshteinBuffersPool.Put(buffers) var bestCandidate T hasBest := false for candidate := range candidates { candidateName := getName(candidate) - maxLen := max(len(candidateName), len(name)) - minLen := min(len(candidateName), len(name)) + maxLen := max(len(candidateName), len(runeName)) + minLen := min(len(candidateName), len(runeName)) if candidateName != "" && maxLen-minLen <= maximumLengthDifference { if candidateName == name { continue diff --git a/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.errors.txt b/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.errors.txt new file mode 100644 index 0000000000..e6564c0333 --- /dev/null +++ b/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.errors.txt @@ -0,0 +1,32 @@ +unicodeSpellingSuggestions.ts(3,1): error TS1435: Unknown keyword or identifier. Did you mean 'class'? +unicodeSpellingSuggestions.ts(3,1): error TS2304: Cannot find name 'classAé'. +unicodeSpellingSuggestions.ts(6,1): error TS1435: Unknown keyword or identifier. Did you mean 'class Aéé'? +unicodeSpellingSuggestions.ts(6,1): error TS2304: Cannot find name 'classAéé'. +unicodeSpellingSuggestions.ts(9,1): error TS1435: Unknown keyword or identifier. Did you mean 'class Aééé'? +unicodeSpellingSuggestions.ts(9,1): error TS2304: Cannot find name 'classAééé'. + + +==== unicodeSpellingSuggestions.ts (6 errors) ==== + // https://github.com/microsoft/typescript-go/issues/4223 + + classAé { + ~~~~~~~ +!!! error TS1435: Unknown keyword or identifier. Did you mean 'class'? + ~~~~~~~ +!!! error TS2304: Cannot find name 'classAé'. + } + + classAéé { + ~~~~~~~~ +!!! error TS1435: Unknown keyword or identifier. Did you mean 'class Aéé'? + ~~~~~~~~ +!!! error TS2304: Cannot find name 'classAéé'. + } + + classAééé { + ~~~~~~~~~ +!!! error TS1435: Unknown keyword or identifier. Did you mean 'class Aééé'? + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'classAééé'. + } + \ No newline at end of file diff --git a/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.symbols b/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.symbols new file mode 100644 index 0000000000..0c79700914 --- /dev/null +++ b/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.symbols @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/unicodeSpellingSuggestions.ts] //// + +=== unicodeSpellingSuggestions.ts === + +// https://github.com/microsoft/typescript-go/issues/4223 + +classAé { +} + +classAéé { +} + +classAééé { +} + diff --git a/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.types b/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.types new file mode 100644 index 0000000000..bac9cf61c8 --- /dev/null +++ b/testdata/baselines/reference/compiler/unicodeSpellingSuggestions.types @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/unicodeSpellingSuggestions.ts] //// + +=== unicodeSpellingSuggestions.ts === +// https://github.com/microsoft/typescript-go/issues/4223 + +classAé { +>classAé : any +} + +classAéé { +>classAéé : any +} + +classAééé { +>classAééé : any +} + diff --git a/testdata/tests/cases/compiler/unicodeSpellingSuggestions.ts b/testdata/tests/cases/compiler/unicodeSpellingSuggestions.ts new file mode 100644 index 0000000000..c4d58e6802 --- /dev/null +++ b/testdata/tests/cases/compiler/unicodeSpellingSuggestions.ts @@ -0,0 +1,12 @@ +// @noEmit: true + +// https://github.com/microsoft/typescript-go/issues/4223 + +classAé { +} + +classAéé { +} + +classAééé { +}