From 5a6d476797023700705c9737785da8ccf46268cd Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 23 Jul 2015 15:18:48 -0700 Subject: [PATCH] Fix as many linter errors as possible --- src/compiler/checker.ts | 7 ++++--- src/compiler/core.ts | 12 ++++++------ src/compiler/emitter.ts | 19 ++++++++++--------- src/compiler/parser.ts | 4 ++-- src/compiler/sys.ts | 22 +++++++++++----------- src/harness/harness.ts | 5 ++++- src/harness/rwcRunner.ts | 5 +++-- 7 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c37189488bb..167c45500ff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -211,6 +211,9 @@ namespace ts { let assignableRelation: Map = {}; let identityRelation: Map = {}; + // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. + let _displayBuilder: SymbolDisplayBuilder; + type TypeSystemEntity = Symbol | Type | Signature; const enum TypeSystemPropertyName { @@ -1490,8 +1493,6 @@ namespace ts { return undefined; } - // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. - let _displayBuilder: SymbolDisplayBuilder; function getSymbolDisplayBuilder(): SymbolDisplayBuilder { function getNameOfSymbol(symbol: Symbol): string { @@ -3448,7 +3449,7 @@ namespace ts { // type, a property is considered known if it is known in any constituent type. function isKnownProperty(type: Type, name: string): boolean { if (type.flags & TypeFlags.ObjectType && type !== globalObjectType) { - var resolved = resolveStructuredTypeMembers(type); + const resolved = resolveStructuredTypeMembers(type); return !!(resolved.properties.length === 0 || resolved.stringIndexType || resolved.numberIndexType || diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ec171d4aee2..66e21adac3d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -219,10 +219,10 @@ namespace ts { export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial: U): U; export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial?: U): U { if (array) { - var count = array.length; + const count = array.length; if (count > 0) { - var pos = 0; - var result = arguments.length <= 2 ? array[pos++] : initial; + let pos = 0; + let result = arguments.length <= 2 ? array[pos++] : initial; while (pos < count) { result = f(result, array[pos++]); } @@ -236,9 +236,9 @@ namespace ts { export function reduceRight(array: T[], f: (a: U, x: T) => U, initial: U): U; export function reduceRight(array: T[], f: (a: U, x: T) => U, initial?: U): U { if (array) { - var pos = array.length - 1; + let pos = array.length - 1; if (pos >= 0) { - var result = arguments.length <= 2 ? array[pos--] : initial; + let result = arguments.length <= 2 ? array[pos--] : initial; while (pos >= 0) { result = f(result, array[pos--]); } @@ -805,4 +805,4 @@ namespace ts { Debug.assert(false, message); } } -} +} diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index cb5eb864660..b915bc3766f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1248,7 +1248,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Don't emit empty strings if (children[i].kind === SyntaxKind.JsxText) { let text = getTextToEmit(children[i]); - if(text !== undefined) { + if (text !== undefined) { write(', "'); write(text); write('"'); @@ -4255,11 +4255,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitDetachedComments(ctor.body.statements); } emitCaptureThisForNodeIfNecessary(node); + let superCall: ExpressionStatement; if (ctor) { emitDefaultValueAssignments(ctor); emitRestParameter(ctor); if (baseTypeElement) { - var superCall = findInitialSuperCall(ctor); + superCall = findInitialSuperCall(ctor); if (superCall) { writeLine(); emit(superCall); @@ -4936,7 +4937,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let temp = createAndRecordTempVariable(TempFlags.Auto); write("(typeof ("); emitNodeWithoutSourceMap(temp); - write(" = ") + write(" = "); emitEntityNameAsExpression(typeName, /*useFallback*/ true); write(") === 'function' && "); emitNodeWithoutSourceMap(temp); @@ -4995,7 +4996,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. if (node) { - var valueDeclaration: FunctionLikeDeclaration; + let valueDeclaration: FunctionLikeDeclaration; if (node.kind === SyntaxKind.ClassDeclaration) { valueDeclaration = getFirstConstructorWithBody(node); } @@ -5004,8 +5005,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } if (valueDeclaration) { - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; + const parameters = valueDeclaration.parameters; + const parameterCount = parameters.length; if (parameterCount > 0) { for (var i = 0; i < parameterCount; i++) { if (i > 0) { @@ -5013,7 +5014,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; + let parameterType = parameters[i].type; if (parameterType.kind === SyntaxKind.ArrayType) { parameterType = (parameterType).elementType; } @@ -5825,7 +5826,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi writeLine(); write("}"); writeLine(); - write(`${exportFunctionForFile}(exports);`) + write(`${exportFunctionForFile}(exports);`); decreaseIndent(); writeLine(); write("}"); @@ -6173,7 +6174,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // exports_(reexports); let reexportsVariableName = makeUniqueName("reexports"); writeLine(); - write(`var ${reexportsVariableName} = {};`) + write(`var ${reexportsVariableName} = {};`); writeLine(); for (let e of (importNode).exportClause.elements) { write(`${reexportsVariableName}["`); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 127d1b58ee4..088b5b09bfb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3148,7 +3148,7 @@ namespace ts { } function parseAwaitExpression() { - var node = createNode(SyntaxKind.AwaitExpression); + const node = createNode(SyntaxKind.AwaitExpression); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); @@ -5140,7 +5140,7 @@ namespace ts { // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. if (token === SyntaxKind.FromKeyword || (token === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) { - parseExpected(SyntaxKind.FromKeyword) + parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); } } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 228b9516de1..cb1dfd9187b 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -31,7 +31,7 @@ namespace ts { declare var __filename: string; declare var Buffer: { new (str: string, encoding ?: string): any; - } + }; declare class Enumerator { public atEnd(): boolean; @@ -188,13 +188,13 @@ namespace ts { }; } function getNodeSystem(): System { - var _fs = require("fs"); - var _path = require("path"); - var _os = require('os'); + const _fs = require("fs"); + const _path = require("path"); + const _os = require('os'); - var platform: string = _os.platform(); + const platform: string = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive - var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; + const useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; function readFile(fileName: string, encoding?: string): string { if (!_fs.existsSync(fileName)) { @@ -271,10 +271,10 @@ namespace ts { newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, write(s: string): void { - var buffer = new Buffer(s, 'utf8'); - var offset: number = 0; - var toWrite: number = buffer.length; - var written = 0; + const buffer = new Buffer(s, 'utf8'); + let offset: number = 0; + let toWrite: number = buffer.length; + let written = 0; // 1 is a standard descriptor for stdout while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) { offset += written; @@ -297,7 +297,7 @@ namespace ts { } callback(fileName); - }; + } }, resolvePath: function (path: string): string { return _path.resolve(path); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 47b388c494c..ac88e840b54 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -24,6 +24,8 @@ /// /// +// Block scoped definitions work poorly for global variables, temporarily enable var +/* tslint:disable:no-var-keyword */ var Buffer: BufferConstructor = require('buffer').Buffer; // this will work in the browser via browserify @@ -32,6 +34,7 @@ var assert: typeof _chai.assert = _chai.assert; var expect: typeof _chai.expect = _chai.expect; declare var __dirname: string; // Node-specific var global = Function("return this").call(null); +/* tslint:enable:no-var-keyword */ module Utils { // Setup some globals based on the current environment @@ -412,6 +415,7 @@ module Harness { log(text: string): void; getMemoryUsage?(): number; } + export var IO: IO; module IOImpl { declare class Enumerator { @@ -690,7 +694,6 @@ module Harness { } } - export var IO: IO; switch (Utils.getExecutionEnvironment()) { case Utils.ExecutionEnvironment.CScript: IO = IOImpl.CScript; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 54aeff18efd..2255147fa6a 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -74,10 +74,11 @@ module RWC { }); // Add files to compilation + let isInInputList = (resolvedPath: string) => (inputFile: { unitName: string; content: string; }) => inputFile.unitName === resolvedPath; for (let fileRead of ioLog.filesRead) { // Check if the file is already added into the set of input files. - var resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path)); - let inInputList = ts.forEach(inputFiles, inputFile => inputFile.unitName === resolvedPath); + const resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path)); + let inInputList = ts.forEach(inputFiles, isInInputList(resolvedPath)); if (!Harness.isLibraryFile(fileRead.path)) { if (inInputList) {