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;
}