Skip to content

Commit 5a7e967

Browse files
committed
Blacklist some built-ins and improve max cutoff
The maximum distance cutoff was being checked after the close-enough early exit. Now it's checked before. Note that `null` doesn't show up in the globals list, so it's not part of the blacklist either.
1 parent 2a7398b commit 5a7e967

11 files changed

+45
-35
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ namespace ts {
12361236

12371237
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: string, meaning: SymbolFlags): boolean {
12381238
if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) {
1239-
if (name === "any" || name === "string" || name === "number" || name === "boolean" || name === "void" || name === "never") {
1239+
if (name === "any" || name === "string" || name === "number" || name === "boolean" || name === "never") {
12401240
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, name);
12411241
return true;
12421242
}
@@ -14224,14 +14224,24 @@ namespace ts {
1422414224
if (candidateName === name) {
1422514225
return candidate;
1422614226
}
14227-
if (candidateName.length < 3 || name.length < 3) {
14227+
if (candidateName.length < 3 ||
14228+
name.length < 3 ||
14229+
candidateName === "eval" ||
14230+
candidateName === "Intl" ||
14231+
candidateName === "undefined" ||
14232+
candidateName === "Map" ||
14233+
candidateName === "NaN" ||
14234+
candidateName === "Set") {
1422814235
continue;
1422914236
}
1423014237
const distance = levenshtein(candidateName, name);
14238+
if (distance > worstDistance) {
14239+
continue;
14240+
}
1423114241
if (distance < 3) {
1423214242
return candidate;
1423314243
}
14234-
else if (distance < bestDistance && distance < worstDistance) {
14244+
else if (distance < bestDistance) {
1423514245
bestDistance = distance;
1423614246
bestCandidate = candidate;
1423714247
}

tests/baselines/reference/ModuleWithExportedAndNonExportedFunctions.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(28,13): error TS2551: Property 'fn2' does not exist on type 'typeof A'. Did you mean 'fng'?
1+
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(28,13): error TS2339: Property 'fn2' does not exist on type 'typeof A'.
22
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(29,14): error TS2551: Property 'fng2' does not exist on type 'typeof A'. Did you mean 'fng'?
33

44

@@ -32,7 +32,7 @@ tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAnd
3232
// these should be errors since the functions are not exported
3333
var fn2 = A.fn2;
3434
~~~
35-
!!! error TS2551: Property 'fn2' does not exist on type 'typeof A'. Did you mean 'fng'?
35+
!!! error TS2339: Property 'fn2' does not exist on type 'typeof A'.
3636
var fng2 = A.fng2;
3737
~~~~
3838
!!! error TS2551: Property 'fng2' does not exist on type 'typeof A'. Did you mean 'fng'?
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS1212: Identifier expected. 'let' is a reserved word in strict mode.
2-
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS2552: Cannot find name 'let'. Did you mean 'Set'?
2+
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS2304: Cannot find name 'let'.
33

44

55
==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts (2 errors) ====
@@ -8,4 +8,4 @@ tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,
88
~~~
99
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode.
1010
~~~
11-
!!! error TS2552: Cannot find name 'let'. Did you mean 'Set'?
11+
!!! error TS2304: Cannot find name 'let'.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts(1,1): error TS2552: Cannot find name 'let'. Did you mean 'Set'?
1+
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts(1,1): error TS2304: Cannot find name 'let'.
22

33

44
==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts (1 errors) ====
55
let
66
~~~
7-
!!! error TS2552: Cannot find name 'let'. Did you mean 'Set'?
7+
!!! error TS2304: Cannot find name 'let'.

tests/baselines/reference/autoLift2.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
tests/cases/compiler/autoLift2.ts(5,14): error TS2339: Property 'foo' does not exist on type 'A'.
22
tests/cases/compiler/autoLift2.ts(5,17): error TS1005: ';' expected.
33
tests/cases/compiler/autoLift2.ts(5,19): error TS2693: 'any' only refers to a type, but is being used as a value here.
4-
tests/cases/compiler/autoLift2.ts(6,14): error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
4+
tests/cases/compiler/autoLift2.ts(6,14): error TS2339: Property 'bar' does not exist on type 'A'.
55
tests/cases/compiler/autoLift2.ts(6,17): error TS1005: ';' expected.
66
tests/cases/compiler/autoLift2.ts(6,19): error TS2693: 'any' only refers to a type, but is being used as a value here.
77
tests/cases/compiler/autoLift2.ts(12,11): error TS2339: Property 'foo' does not exist on type 'A'.
8-
tests/cases/compiler/autoLift2.ts(14,11): error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
8+
tests/cases/compiler/autoLift2.ts(14,11): error TS2339: Property 'bar' does not exist on type 'A'.
99
tests/cases/compiler/autoLift2.ts(16,33): error TS2339: Property 'foo' does not exist on type 'A'.
10-
tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
10+
tests/cases/compiler/autoLift2.ts(18,33): error TS2339: Property 'bar' does not exist on type 'A'.
1111

1212

1313
==== tests/cases/compiler/autoLift2.ts (10 errors) ====
@@ -24,7 +24,7 @@ tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not
2424
!!! error TS2693: 'any' only refers to a type, but is being used as a value here.
2525
this.bar: any;
2626
~~~
27-
!!! error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
27+
!!! error TS2339: Property 'bar' does not exist on type 'A'.
2828
~
2929
!!! error TS1005: ';' expected.
3030
~~~
@@ -40,15 +40,15 @@ tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not
4040

4141
this.bar = "bar";
4242
~~~
43-
!!! error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
43+
!!! error TS2339: Property 'bar' does not exist on type 'A'.
4444

4545
[1, 2].forEach((p) => this.foo);
4646
~~~
4747
!!! error TS2339: Property 'foo' does not exist on type 'A'.
4848

4949
[1, 2].forEach((p) => this.bar);
5050
~~~
51-
!!! error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
51+
!!! error TS2339: Property 'bar' does not exist on type 'A'.
5252

5353
}
5454

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(227,13): error T
5050
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(234,14): error TS1005: '{' expected.
5151
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,9): error TS1128: Declaration or statement expected.
5252
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,16): error TS2304: Cannot find name 'method1'.
53-
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,24): error TS2552: Cannot find name 'val'. Did you mean 'eval'?
53+
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,24): error TS2304: Cannot find name 'val'.
5454
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,27): error TS1005: ',' expected.
5555
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,28): error TS2693: 'number' only refers to a type, but is being used as a value here.
5656
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,36): error TS1005: ';' expected.
@@ -431,7 +431,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
431431
~~~~~~~
432432
!!! error TS2304: Cannot find name 'method1'.
433433
~~~
434-
!!! error TS2552: Cannot find name 'val'. Did you mean 'eval'?
434+
!!! error TS2304: Cannot find name 'val'.
435435
~
436436
!!! error TS1005: ',' expected.
437437
~~~~~~

tests/baselines/reference/crashIntypeCheckInvocationExpression.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(6,28): error TS2304: Cannot find name 'task'.
2-
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(8,18): error TS2552: Cannot find name 'path'. Did you mean 'Math'?
2+
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(8,18): error TS2304: Cannot find name 'path'.
33
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(9,19): error TS2347: Untyped function calls may not accept type arguments.
44
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(10,50): error TS2304: Cannot find name 'moduleType'.
55

@@ -16,7 +16,7 @@ tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(10,50): error TS230
1616

1717
var folder = path.join(),
1818
~~~~
19-
!!! error TS2552: Cannot find name 'path'. Did you mean 'Math'?
19+
!!! error TS2304: Cannot find name 'path'.
2020
fileset = nake.fileSetSync<number, number, any>(folder)
2121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2222
!!! error TS2347: Untyped function calls may not accept type arguments.

tests/baselines/reference/exportNonInitializedVariablesES6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(1,4): error TS1123: Variable declaration list cannot be empty.
22
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(2,1): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
3-
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(2,1): error TS2552: Cannot find name 'let'. Did you mean 'Set'?
3+
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(2,1): error TS2304: Cannot find name 'let'.
44
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(3,6): error TS1123: Variable declaration list cannot be empty.
55

66

@@ -12,7 +12,7 @@ tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(3,6)
1212
~~~
1313
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
1414
~~~
15-
!!! error TS2552: Cannot find name 'let'. Did you mean 'Set'?
15+
!!! error TS2304: Cannot find name 'let'.
1616
const;
1717

1818
!!! error TS1123: Variable declaration list cannot be empty.

tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(4,18): error TS2339: Property 'from' does not exist on type 'ArrayConstructor'.
22
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(10,13): error TS2304: Cannot find name 'Map'.
33
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(17,5): error TS2339: Property 'name' does not exist on type '() => void'.
4-
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(20,6): error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'asin'?
4+
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(20,6): error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
55
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(25,6): error TS2304: Cannot find name 'Symbol'.
66
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(29,18): error TS2304: Cannot find name 'Symbol'.
77
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(33,13): error TS2304: Cannot find name 'Proxy'.
@@ -40,7 +40,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.t
4040
// Using ES6 math
4141
Math.sign(1);
4242
~~~~
43-
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'asin'?
43+
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
4444

4545
// Using ES6 object
4646
var o = {

tests/baselines/reference/tsxAttributeInvalidNames.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
tests/cases/conformance/jsx/file.tsx(10,8): error TS1003: Identifier expected.
22
tests/cases/conformance/jsx/file.tsx(10,10): error TS1005: ';' expected.
3-
tests/cases/conformance/jsx/file.tsx(10,10): error TS2552: Cannot find name 'data'. Did you mean 'Date'?
3+
tests/cases/conformance/jsx/file.tsx(10,10): error TS2304: Cannot find name 'data'.
44
tests/cases/conformance/jsx/file.tsx(10,15): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
55
tests/cases/conformance/jsx/file.tsx(10,18): error TS1005: ':' expected.
66
tests/cases/conformance/jsx/file.tsx(10,21): error TS1109: Expression expected.
77
tests/cases/conformance/jsx/file.tsx(10,22): error TS1109: Expression expected.
88
tests/cases/conformance/jsx/file.tsx(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
99
tests/cases/conformance/jsx/file.tsx(11,8): error TS1003: Identifier expected.
10-
tests/cases/conformance/jsx/file.tsx(11,9): error TS2552: Cannot find name 'data'. Did you mean 'Date'?
10+
tests/cases/conformance/jsx/file.tsx(11,9): error TS2304: Cannot find name 'data'.
1111
tests/cases/conformance/jsx/file.tsx(11,13): error TS1005: ';' expected.
1212
tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular expression literal.
1313

@@ -28,7 +28,7 @@ tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular
2828
~~~~
2929
!!! error TS1005: ';' expected.
3030
~~~~
31-
!!! error TS2552: Cannot find name 'data'. Did you mean 'Date'?
31+
!!! error TS2304: Cannot find name 'data'.
3232
~~~~
3333
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
3434
~
@@ -43,7 +43,7 @@ tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular
4343
~
4444
!!! error TS1003: Identifier expected.
4545
~~~~
46-
!!! error TS2552: Cannot find name 'data'. Did you mean 'Date'?
46+
!!! error TS2304: Cannot find name 'data'.
4747
~
4848
!!! error TS1005: ';' expected.
4949

0 commit comments

Comments
 (0)