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.
This commit is contained in:
Nathan Shively-Sanders 2017-05-03 14:48:23 -07:00
parent 2a7398b12a
commit 5a7e967628
11 changed files with 45 additions and 35 deletions

View file

@ -1236,7 +1236,7 @@ namespace ts {
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: string, meaning: SymbolFlags): boolean {
if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) {
if (name === "any" || name === "string" || name === "number" || name === "boolean" || name === "void" || name === "never") {
if (name === "any" || name === "string" || name === "number" || name === "boolean" || name === "never") {
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, name);
return true;
}
@ -14224,14 +14224,24 @@ namespace ts {
if (candidateName === name) {
return candidate;
}
if (candidateName.length < 3 || name.length < 3) {
if (candidateName.length < 3 ||
name.length < 3 ||
candidateName === "eval" ||
candidateName === "Intl" ||
candidateName === "undefined" ||
candidateName === "Map" ||
candidateName === "NaN" ||
candidateName === "Set") {
continue;
}
const distance = levenshtein(candidateName, name);
if (distance > worstDistance) {
continue;
}
if (distance < 3) {
return candidate;
}
else if (distance < bestDistance && distance < worstDistance) {
else if (distance < bestDistance) {
bestDistance = distance;
bestCandidate = candidate;
}

View file

@ -1,4 +1,4 @@
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(28,13): error TS2551: Property 'fn2' does not exist on type 'typeof A'. Did you mean 'fng'?
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(28,13): error TS2339: Property 'fn2' does not exist on type 'typeof A'.
tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedFunctions.ts(29,14): error TS2551: Property 'fng2' does not exist on type 'typeof A'. Did you mean 'fng'?
@ -32,7 +32,7 @@ tests/cases/conformance/internalModules/exportDeclarations/ModuleWithExportedAnd
// these should be errors since the functions are not exported
var fn2 = A.fn2;
~~~
!!! error TS2551: Property 'fn2' does not exist on type 'typeof A'. Did you mean 'fng'?
!!! error TS2339: Property 'fn2' does not exist on type 'typeof A'.
var fng2 = A.fng2;
~~~~
!!! error TS2551: Property 'fng2' does not exist on type 'typeof A'. Did you mean 'fng'?

View file

@ -1,5 +1,5 @@
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS1212: Identifier expected. 'let' is a reserved word in strict mode.
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS2552: Cannot find name 'let'. Did you mean 'Set'?
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS2304: Cannot find name 'let'.
==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts (2 errors) ====
@ -8,4 +8,4 @@ tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,
~~~
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode.
~~~
!!! error TS2552: Cannot find name 'let'. Did you mean 'Set'?
!!! error TS2304: Cannot find name 'let'.

View file

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

View file

@ -1,13 +1,13 @@
tests/cases/compiler/autoLift2.ts(5,14): error TS2339: Property 'foo' does not exist on type 'A'.
tests/cases/compiler/autoLift2.ts(5,17): error TS1005: ';' expected.
tests/cases/compiler/autoLift2.ts(5,19): error TS2693: 'any' only refers to a type, but is being used as a value here.
tests/cases/compiler/autoLift2.ts(6,14): error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
tests/cases/compiler/autoLift2.ts(6,14): error TS2339: Property 'bar' does not exist on type 'A'.
tests/cases/compiler/autoLift2.ts(6,17): error TS1005: ';' expected.
tests/cases/compiler/autoLift2.ts(6,19): error TS2693: 'any' only refers to a type, but is being used as a value here.
tests/cases/compiler/autoLift2.ts(12,11): error TS2339: Property 'foo' does not exist on type 'A'.
tests/cases/compiler/autoLift2.ts(14,11): error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
tests/cases/compiler/autoLift2.ts(14,11): error TS2339: Property 'bar' does not exist on type 'A'.
tests/cases/compiler/autoLift2.ts(16,33): error TS2339: Property 'foo' does not exist on type 'A'.
tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
tests/cases/compiler/autoLift2.ts(18,33): error TS2339: Property 'bar' does not exist on type 'A'.
==== tests/cases/compiler/autoLift2.ts (10 errors) ====
@ -24,7 +24,7 @@ tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not
!!! error TS2693: 'any' only refers to a type, but is being used as a value here.
this.bar: any;
~~~
!!! error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
!!! error TS2339: Property 'bar' does not exist on type 'A'.
~
!!! error TS1005: ';' expected.
~~~
@ -40,7 +40,7 @@ tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not
this.bar = "bar";
~~~
!!! error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
!!! error TS2339: Property 'bar' does not exist on type 'A'.
[1, 2].forEach((p) => this.foo);
~~~
@ -48,7 +48,7 @@ tests/cases/compiler/autoLift2.ts(18,33): error TS2551: Property 'bar' does not
[1, 2].forEach((p) => this.bar);
~~~
!!! error TS2551: Property 'bar' does not exist on type 'A'. Did you mean 'baz'?
!!! error TS2339: Property 'bar' does not exist on type 'A'.
}

View file

@ -50,7 +50,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(227,13): error T
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(234,14): error TS1005: '{' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,9): error TS1128: Declaration or statement expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,16): error TS2304: Cannot find name 'method1'.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,24): error TS2552: Cannot find name 'val'. Did you mean 'eval'?
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,24): error TS2304: Cannot find name 'val'.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,27): error TS1005: ',' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,28): error TS2693: 'number' only refers to a type, but is being used as a value here.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,36): error TS1005: ';' expected.
@ -431,7 +431,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
~~~~~~~
!!! error TS2304: Cannot find name 'method1'.
~~~
!!! error TS2552: Cannot find name 'val'. Did you mean 'eval'?
!!! error TS2304: Cannot find name 'val'.
~
!!! error TS1005: ',' expected.
~~~~~~

View file

@ -1,5 +1,5 @@
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(6,28): error TS2304: Cannot find name 'task'.
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(8,18): error TS2552: Cannot find name 'path'. Did you mean 'Math'?
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(8,18): error TS2304: Cannot find name 'path'.
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(9,19): error TS2347: Untyped function calls may not accept type arguments.
tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(10,50): error TS2304: Cannot find name 'moduleType'.
@ -16,7 +16,7 @@ tests/cases/compiler/crashIntypeCheckInvocationExpression.ts(10,50): error TS230
var folder = path.join(),
~~~~
!!! error TS2552: Cannot find name 'path'. Did you mean 'Math'?
!!! error TS2304: Cannot find name 'path'.
fileset = nake.fileSetSync<number, number, any>(folder)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2347: Untyped function calls may not accept type arguments.

View file

@ -1,6 +1,6 @@
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(1,4): error TS1123: Variable declaration list cannot be empty.
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.
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(2,1): error TS2552: Cannot find name 'let'. Did you mean 'Set'?
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(2,1): error TS2304: Cannot find name 'let'.
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(3,6): error TS1123: Variable declaration list cannot be empty.
@ -12,7 +12,7 @@ tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(3,6)
~~~
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2552: Cannot find name 'let'. Did you mean 'Set'?
!!! error TS2304: Cannot find name 'let'.
const;
!!! error TS1123: Variable declaration list cannot be empty.

View file

@ -1,7 +1,7 @@
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(4,18): error TS2339: Property 'from' does not exist on type 'ArrayConstructor'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(10,13): error TS2304: Cannot find name 'Map'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(17,5): error TS2339: Property 'name' does not exist on type '() => void'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(20,6): error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'asin'?
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(20,6): error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(25,6): error TS2304: Cannot find name 'Symbol'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(29,18): error TS2304: Cannot find name 'Symbol'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.ts(33,13): error TS2304: Cannot find name 'Proxy'.
@ -40,7 +40,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.t
// Using ES6 math
Math.sign(1);
~~~~
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'asin'?
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
// Using ES6 object
var o = {

View file

@ -1,13 +1,13 @@
tests/cases/conformance/jsx/file.tsx(10,8): error TS1003: Identifier expected.
tests/cases/conformance/jsx/file.tsx(10,10): error TS1005: ';' expected.
tests/cases/conformance/jsx/file.tsx(10,10): error TS2552: Cannot find name 'data'. Did you mean 'Date'?
tests/cases/conformance/jsx/file.tsx(10,10): error TS2304: Cannot find name 'data'.
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.
tests/cases/conformance/jsx/file.tsx(10,18): error TS1005: ':' expected.
tests/cases/conformance/jsx/file.tsx(10,21): error TS1109: Expression expected.
tests/cases/conformance/jsx/file.tsx(10,22): error TS1109: Expression expected.
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.
tests/cases/conformance/jsx/file.tsx(11,8): error TS1003: Identifier expected.
tests/cases/conformance/jsx/file.tsx(11,9): error TS2552: Cannot find name 'data'. Did you mean 'Date'?
tests/cases/conformance/jsx/file.tsx(11,9): error TS2304: Cannot find name 'data'.
tests/cases/conformance/jsx/file.tsx(11,13): error TS1005: ';' expected.
tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular expression literal.
@ -28,7 +28,7 @@ tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular
~~~~
!!! error TS1005: ';' expected.
~~~~
!!! error TS2552: Cannot find name 'data'. Did you mean 'Date'?
!!! error TS2304: Cannot find name 'data'.
~~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
~
@ -43,7 +43,7 @@ tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular
~
!!! error TS1003: Identifier expected.
~~~~
!!! error TS2552: Cannot find name 'data'. Did you mean 'Date'?
!!! error TS2304: Cannot find name 'data'.
~
!!! error TS1005: ';' expected.

View file

@ -3,14 +3,14 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type '"str"' is not assignable to type 'number'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B<number>'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(41,10): error TS2339: Property 'bar' does not exist on type 'B<any>'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2551: Property 'bar2' does not exist on type 'C1'. Did you mean 'bar1'?
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(72,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'.
Property 'bar1' does not exist on type 'C2'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(73,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'.
Property 'bar2' does not exist on type 'C1'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(85,10): error TS2339: Property 'bar' does not exist on type 'D'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(91,10): error TS2339: Property 'bar' does not exist on type 'D'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2551: Property 'bar2' does not exist on type 'E1'. Did you mean 'bar1'?
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(118,11): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'.
Property 'bar1' does not exist on type 'E2'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(119,11): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'.
@ -19,8 +19,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
Property 'foo' does not exist on type 'string'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'string | F'.
Property 'bar' does not exist on type 'string'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2551: Property 'foo2' does not exist on type 'G1'. Did you mean 'foo1'?
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(166,11): error TS2551: Property 'foo2' does not exist on type 'G1'. Did you mean 'foo1'?
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2339: Property 'foo2' does not exist on type 'G1'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(166,11): error TS2339: Property 'foo2' does not exist on type 'G1'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(182,11): error TS2339: Property 'bar' does not exist on type 'H'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(187,11): error TS2551: Property 'foo1' does not exist on type 'H'. Did you mean 'foo'?
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(188,11): error TS2551: Property 'foo2' does not exist on type 'H'. Did you mean 'foo'?
@ -104,7 +104,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
obj5.bar1;
obj5.bar2;
~~~~
!!! error TS2551: Property 'bar2' does not exist on type 'C1'. Did you mean 'bar1'?
!!! error TS2339: Property 'bar2' does not exist on type 'C1'.
}
var obj6: any;
@ -162,7 +162,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
obj9.bar1;
obj9.bar2;
~~~~
!!! error TS2551: Property 'bar2' does not exist on type 'E1'. Did you mean 'bar1'?
!!! error TS2339: Property 'bar2' does not exist on type 'E1'.
}
var obj10: any;
@ -224,7 +224,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
obj13.foo1;
obj13.foo2;
~~~~
!!! error TS2551: Property 'foo2' does not exist on type 'G1'. Did you mean 'foo1'?
!!! error TS2339: Property 'foo2' does not exist on type 'G1'.
}
var obj14: any;
@ -232,7 +232,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
obj14.foo1;
obj14.foo2;
~~~~
!!! error TS2551: Property 'foo2' does not exist on type 'G1'. Did you mean 'foo1'?
!!! error TS2339: Property 'foo2' does not exist on type 'G1'.
}
// a type with a prototype that has any type