refactor(): use const and let instead of var

This commit is contained in:
Joao Dias
2016-11-12 14:08:58 +01:00
committed by Victor Berchet
parent 73593d4bf3
commit 77ee27c59e
435 changed files with 4637 additions and 4663 deletions

View File

@ -74,7 +74,7 @@ export class MetadataCollector {
}
function classMetadataOf(classDeclaration: ts.ClassDeclaration): ClassMetadata {
let result: ClassMetadata = {__symbolic: 'class'};
const result: ClassMetadata = {__symbolic: 'class'};
function getDecorators(decorators: ts.Decorator[]): MetadataSymbolicExpression[] {
if (decorators && decorators.length)
@ -102,7 +102,7 @@ export class MetadataCollector {
let members: MetadataMap = null;
function recordMember(name: string, metadata: MemberMetadata) {
if (!members) members = {};
let data = members.hasOwnProperty(name) ? members[name] : [];
const data = members.hasOwnProperty(name) ? members[name] : [];
data.push(metadata);
members[name] = data;
}
@ -279,7 +279,7 @@ export class MetadataCollector {
case ts.SyntaxKind.EnumDeclaration:
if (node.flags & ts.NodeFlags.Export) {
const enumDeclaration = <ts.EnumDeclaration>node;
let enumValueHolder: {[name: string]: MetadataValue} = {};
const enumValueHolder: {[name: string]: MetadataValue} = {};
const enumName = enumDeclaration.name.text;
let nextDefaultValue: MetadataValue = 0;
let writtenMembers = 0;
@ -321,9 +321,9 @@ export class MetadataCollector {
break;
case ts.SyntaxKind.VariableStatement:
const variableStatement = <ts.VariableStatement>node;
for (let variableDeclaration of variableStatement.declarationList.declarations) {
for (const variableDeclaration of variableStatement.declarationList.declarations) {
if (variableDeclaration.name.kind == ts.SyntaxKind.Identifier) {
let nameNode = <ts.Identifier>variableDeclaration.name;
const nameNode = <ts.Identifier>variableDeclaration.name;
let varValue: MetadataValue;
if (variableDeclaration.initializer) {
varValue = evaluator.evaluateNode(variableDeclaration.initializer);
@ -530,7 +530,7 @@ function validateMetadata(
const node = nodeMap.get(entry);
if (shouldReportNode(node)) {
if (node) {
let {line, character} = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const {line, character} = sourceFile.getLineAndCharacterOfPosition(node.getStart());
throw new Error(
`${sourceFile.fileName}:${line + 1}:${character + 1}: Error encountered in metadata generated for exported symbol '${name}': \n ${e.message}`);
}
@ -543,7 +543,7 @@ function validateMetadata(
// Collect parameter names from a function.
function namesOf(parameters: ts.NodeArray<ts.ParameterDeclaration>): string[] {
let result: string[] = [];
const result: string[] = [];
function addNamesOf(name: ts.Identifier | ts.BindingPattern) {
if (name.kind == ts.SyntaxKind.Identifier) {
@ -551,13 +551,13 @@ function namesOf(parameters: ts.NodeArray<ts.ParameterDeclaration>): string[] {
result.push(identifier.text);
} else {
const bindingPattern = <ts.BindingPattern>name;
for (let element of bindingPattern.elements) {
for (const element of bindingPattern.elements) {
addNamesOf(element.name);
}
}
}
for (let parameter of parameters) {
for (const parameter of parameters) {
addNamesOf(parameter.name);
}

View File

@ -78,7 +78,7 @@ export function errorSymbol(
if (node) {
sourceFile = sourceFile || getSourceFileOfNode(node);
if (sourceFile) {
let {line, character} =
const {line, character} =
ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
result = {__symbolic: 'error', message, line, character};
};
@ -260,7 +260,7 @@ export class Evaluator {
// Handle spread expressions
if (isMetadataSymbolicSpreadExpression(value)) {
if (Array.isArray(value.expression)) {
for (let spreadValue of value.expression) {
for (const spreadValue of value.expression) {
arr.push(spreadValue);
}
return;
@ -389,7 +389,7 @@ export class Evaluator {
return {__symbolic: 'select', expression: left, member: qualifiedName.right.text};
} else {
const identifier = <ts.Identifier>typeNameNode;
let symbol = this.symbols.resolve(identifier.text);
const symbol = this.symbols.resolve(identifier.text);
if (isMetadataError(symbol) || isMetadataSymbolicReferenceExpression(symbol)) {
return recordEntry(symbol, node);
}

View File

@ -32,7 +32,7 @@ export class Symbols {
}
private buildImports(): void {
let symbols = this._symbols;
const symbols = this._symbols;
// Collect the imported symbols into this.symbols
const stripQuotes = (s: string) => s.replace(/^['"]|['"]$/g, '');
const visit = (node: ts.Node) => {
@ -84,7 +84,7 @@ export class Symbols {
switch (bindings.kind) {
case ts.SyntaxKind.NamedImports:
// An `import { [<identifier> [, <identifier>] } from <module-specifier>` clause
for (let binding of (<ts.NamedImports>bindings).elements) {
for (const binding of (<ts.NamedImports>bindings).elements) {
symbols.set(binding.name.text, {
__symbolic: 'reference',
module: from,

View File

@ -80,7 +80,7 @@ export class Tsc implements CompilerInterface {
// The issue is that old typescript only has `readDirectory` while
// the newer TypeScript has additional `useCaseSensitiveFileNames` and
// `fileExists`. Inlining will trigger an error of extra parameters.
let host = {
const host = {
useCaseSensitiveFileNames: true,
fileExists: existsSync,
readDirectory: this.readDirectory
@ -103,10 +103,10 @@ export class Tsc implements CompilerInterface {
debug('Checking global diagnostics...');
check(program.getGlobalDiagnostics());
let diagnostics: ts.Diagnostic[] = [];
const diagnostics: ts.Diagnostic[] = [];
debug('Type checking...');
for (let sf of program.getSourceFiles()) {
for (const sf of program.getSourceFiles()) {
diagnostics.push(...ts.getPreEmitDiagnostics(program, sf));
}
check(diagnostics);
@ -117,7 +117,7 @@ export class Tsc implements CompilerInterface {
const program = ts.createProgram(this.parsed.fileNames, this.parsed.options, compilerHost);
debug('Emitting outputs...');
const emitResult = program.emit();
let diagnostics: ts.Diagnostic[] = [];
const diagnostics: ts.Diagnostic[] = [];
diagnostics.push(...emitResult.diagnostics);
check(compilerHost.diagnostics);