Don't provide spelling suggestion for module (#22805)

This commit is contained in:
Andy 2018-03-22 14:27:34 -07:00 committed by GitHub
parent 810b386c2a
commit 94570eedcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 1 deletions

View File

@ -16373,7 +16373,8 @@ namespace ts {
const nameLowerCase = name.toLowerCase();
for (const candidate of symbols) {
const candidateName = symbolName(candidate);
if (!(candidate.flags & meaning && Math.abs(candidateName.length - nameLowerCase.length) <= maximumLengthDifference)) {
if (candidateName.charCodeAt(0) === CharacterCodes.doubleQuote
|| !(candidate.flags & meaning && Math.abs(candidateName.length - nameLowerCase.length) <= maximumLengthDifference)) {
continue;
}
const candidateNameLowerCase = candidateName.toLowerCase();

View File

@ -0,0 +1,21 @@
tests/cases/compiler/spellingSuggestionModule.ts(2,1): error TS2304: Cannot find name 'foobar'.
tests/cases/compiler/spellingSuggestionModule.ts(5,1): error TS2304: Cannot find name 'barfoo'.
tests/cases/compiler/spellingSuggestionModule.ts(8,1): error TS2552: Cannot find name 'faroo'. Did you mean 'farboo'?
==== tests/cases/compiler/spellingSuggestionModule.ts (3 errors) ====
declare module "foobar" { export const x: number; }
foobar;
~~~~~~
!!! error TS2304: Cannot find name 'foobar'.
declare module 'barfoo' { export const x: number; }
barfoo;
~~~~~~
!!! error TS2304: Cannot find name 'barfoo'.
declare module farboo { export const x: number; }
faroo;
~~~~~
!!! error TS2552: Cannot find name 'faroo'. Did you mean 'farboo'?

View File

@ -0,0 +1,15 @@
//// [spellingSuggestionModule.ts]
declare module "foobar" { export const x: number; }
foobar;
declare module 'barfoo' { export const x: number; }
barfoo;
declare module farboo { export const x: number; }
faroo;
//// [spellingSuggestionModule.js]
foobar;
barfoo;
faroo;

View File

@ -0,0 +1,19 @@
=== tests/cases/compiler/spellingSuggestionModule.ts ===
declare module "foobar" { export const x: number; }
>"foobar" : Symbol("foobar", Decl(spellingSuggestionModule.ts, 0, 0))
>x : Symbol(x, Decl(spellingSuggestionModule.ts, 0, 38))
foobar;
declare module 'barfoo' { export const x: number; }
>'barfoo' : Symbol('barfoo', Decl(spellingSuggestionModule.ts, 1, 7))
>x : Symbol(x, Decl(spellingSuggestionModule.ts, 3, 38))
barfoo;
declare module farboo { export const x: number; }
>farboo : Symbol(farboo, Decl(spellingSuggestionModule.ts, 4, 7))
>x : Symbol(x, Decl(spellingSuggestionModule.ts, 6, 36))
faroo;

View File

@ -0,0 +1,22 @@
=== tests/cases/compiler/spellingSuggestionModule.ts ===
declare module "foobar" { export const x: number; }
>"foobar" : typeof "foobar"
>x : number
foobar;
>foobar : any
declare module 'barfoo' { export const x: number; }
>'barfoo' : typeof 'barfoo'
>x : number
barfoo;
>barfoo : any
declare module farboo { export const x: number; }
>farboo : typeof farboo
>x : number
faroo;
>faroo : any

View File

@ -0,0 +1,8 @@
declare module "foobar" { export const x: number; }
foobar;
declare module 'barfoo' { export const x: number; }
barfoo;
declare module farboo { export const x: number; }
faroo;