Use for-of in more places.

This commit is contained in:
Cyrus Najmabadi
2015-03-13 10:36:29 -07:00
parent 5f89a8e3f6
commit d10a54c6b0
4 changed files with 30 additions and 30 deletions

View File

@@ -4624,8 +4624,8 @@ module ts {
else if (source.flags & TypeFlags.Union) {
// Source is a union type, infer from each consituent type
var sourceTypes = (<UnionType>source).types;
for (var i = 0; i < sourceTypes.length; i++) {
inferFromTypes(sourceTypes[i], target);
for (let sourceType of sourceTypes) {
inferFromTypes(sourceType, target);
}
}
else if (source.flags & TypeFlags.ObjectType && (target.flags & (TypeFlags.Reference | TypeFlags.Tuple) ||
@@ -5451,8 +5451,8 @@ module ts {
var types = (<UnionType>type).types;
var mappedType: Type;
var mappedTypes: Type[];
for (var i = 0; i < types.length; i++) {
var t = mapper(types[i]);
for (let current of types) {
var t = mapper(current);
if (t) {
if (!mappedType) {
mappedType = t;
@@ -5628,15 +5628,15 @@ module ts {
}
var signatureList: Signature[];
var types = (<UnionType>type).types;
for (var i = 0; i < types.length; i++) {
for (let current of types) {
// The signature set of all constituent type with call signatures should match
// So number of signatures allowed is either 0 or 1
if (signatureList &&
getSignaturesOfObjectOrUnionType(types[i], SignatureKind.Call).length > 1) {
getSignaturesOfObjectOrUnionType(current, SignatureKind.Call).length > 1) {
return undefined;
}
var signature = getNonGenericSignature(types[i]);
var signature = getNonGenericSignature(current);
if (signature) {
if (!signatureList) {
// This signature will contribute to contextual union signature
@@ -6586,12 +6586,12 @@ module ts {
return resolveErrorCall(node);
function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>) {
for (var i = 0; i < candidates.length; i++) {
if (!hasCorrectArity(node, args, candidates[i])) {
for (let current of candidates) {
if (!hasCorrectArity(node, args, current)) {
continue;
}
var originalCandidate = candidates[i];
var originalCandidate = current;
var inferenceResult: InferenceContext;
while (true) {
@@ -7198,8 +7198,8 @@ module ts {
}
if (type.flags & TypeFlags.Union) {
var types = (<UnionType>type).types;
for (var i = 0; i < types.length; i++) {
if (types[i].flags & kind) {
for (let current of types) {
if (current.flags & kind) {
return true;
}
}
@@ -7215,8 +7215,8 @@ module ts {
}
if (type.flags & TypeFlags.Union) {
var types = (<UnionType>type).types;
for (var i = 0; i < types.length; i++) {
if (!(types[i].flags & kind)) {
for (let current of types) {
if (!(current.flags & kind)) {
return false;
}
}
@@ -8219,8 +8219,8 @@ module ts {
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
var duplicateFunctionDeclaration = false;
var multipleConstructorImplementation = false;
for (var i = 0; i < declarations.length; i++) {
var node = <FunctionLikeDeclaration>declarations[i];
for (let current of declarations) {
var node = <FunctionLikeDeclaration>current;
var inAmbientContext = isInAmbientContext(node);
var inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
if (inAmbientContextOrInterface) {
@@ -10046,8 +10046,8 @@ module ts {
function hasExportedMembers(moduleSymbol: Symbol) {
var declarations = moduleSymbol.declarations;
for (var i = 0; i < declarations.length; i++) {
var statements = getModuleStatements(declarations[i]);
for (let current of declarations) {
var statements = getModuleStatements(current);
for (let node of statements) {
if (node.kind === SyntaxKind.ExportDeclaration) {
var exportClause = (<ExportDeclaration>node).exportClause;
@@ -11840,8 +11840,8 @@ module ts {
}
else {
var elements = (<BindingPattern>name).elements;
for (var i = 0; i < elements.length; ++i) {
checkGrammarNameInLetOrConstDeclarations(elements[i].name);
for (let element of elements) {
checkGrammarNameInLetOrConstDeclarations(element.name);
}
}
}

View File

@@ -112,8 +112,8 @@ module ts {
export function sum(array: any[], prop: string): number {
var result = 0;
for (var i = 0; i < array.length; i++) {
result += array[i][prop];
for (let v of array) {
result += v[prop];
}
return result;
}

View File

@@ -130,8 +130,8 @@ module ts {
}
}
var subfolders = getNames(folder.subfolders);
for (var i = 0; i < subfolders.length; i++) {
visitDirectory(combinePaths(path, subfolders[i]));
for (let current of subfolders) {
visitDirectory(combinePaths(path, current));
}
}
}
@@ -229,8 +229,8 @@ module ts {
function visitDirectory(path: string) {
var files = _fs.readdirSync(path || ".").sort();
var directories: string[] = [];
for (var i = 0; i < files.length; i++) {
var name = combinePaths(path, files[i]);
for (let current of files) {
var name = combinePaths(path, current);
var stat = _fs.lstatSync(name);
if (stat.isFile()) {
if (!extension || fileExtensionIs(name, extension)) {
@@ -241,8 +241,8 @@ module ts {
directories.push(name);
}
}
for (var i = 0; i < directories.length; i++) {
visitDirectory(directories[i]);
for (let current of directories) {
visitDirectory(current);
}
}
}

View File

@@ -5674,8 +5674,8 @@ module ts {
// Disallow rename for elements that are defined in the standard TypeScript library.
var defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings());
if (defaultLibFileName) {
for (var i = 0; i < declarations.length; i++) {
var sourceFile = declarations[i].getSourceFile();
for (let current of declarations) {
var sourceFile = current.getSourceFile();
if (sourceFile && getCanonicalFileName(ts.normalizePath(sourceFile.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key));
}