From 2eec7f3565e234fe466f01f2a933d800e80d1950 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 30 Jun 2017 09:23:00 -0700 Subject: [PATCH] Dedupe some utility code 1. convertToArray is a duplicate of arrayFrom 2. inferFromParameterTypes delegates immediately to inferFromTypes 3. One usage of arrayFrom instantiated a whole iterator only to take the first element, which is the same as calling `next`. --- src/compiler/checker.ts | 8 ++------ src/compiler/commandLineParser.ts | 2 +- src/compiler/core.ts | 10 +--------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 514e8f401a9..bc2f859f8ec 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1930,7 +1930,7 @@ namespace ts { } function createTypeofType() { - return getUnionType(convertToArray(typeofEQFacts.keys(), getLiteralType)); + return getUnionType(arrayFrom(typeofEQFacts.keys(), getLiteralType)); } // A reserved member name starts with two underscores, but the third character cannot be an underscore @@ -10531,12 +10531,8 @@ namespace ts { } } - function inferFromParameterTypes(source: Type, target: Type) { - return inferFromTypes(source, target); - } - function inferFromSignature(source: Signature, target: Signature) { - forEachMatchingParameterType(source, target, inferFromParameterTypes); + forEachMatchingParameterType(source, target, inferFromTypes); if (source.typePredicate && target.typePredicate && source.typePredicate.kind === target.typePredicate.kind) { inferFromTypes(source.typePredicate.type, target.typePredicate.type); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 178578ec452..5da7e83655f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1290,7 +1290,7 @@ namespace ts { case "object": return {}; default: - return arrayFrom((option).type.keys())[0]; + return (option as CommandLineOptionOfCustomType).type.keys().next().value; } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 2eae414db66..5c7536a825e 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -996,14 +996,6 @@ namespace ts { return result; } - export function convertToArray(iterator: Iterator, f: (value: T) => U) { - const result: U[] = []; - for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) { - result.push(f(value)); - } - return result; - } - /** * Calls `callback` for each entry in the map, returning the first truthy result. * Use `map.forEach` instead for normal iteration. @@ -2527,4 +2519,4 @@ namespace ts { export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) { return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs; } -} \ No newline at end of file +}