Skip to content

refactor var usage to const/let #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
protected bootstrap(options?:Object):IOptionsReadResult {
this.options.read(options, OptionsReadMode.Prefetch);

var logger = this.loggerType;
const logger = this.loggerType;
if (typeof logger == 'function') {
this.logger = new CallbackLogger(<any>logger);
} else if (logger == 'none') {
Expand Down Expand Up @@ -147,8 +147,8 @@ export class Application extends ChildableComponent<Application, AbstractCompone


public getTypeScriptVersion():string {
var tsPath = this.getTypeScriptPath();
var json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
const tsPath = this.getTypeScriptPath();
const json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
return json.version;
}

Expand All @@ -162,7 +162,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
public convert(src:string[]):ProjectReflection {
this.logger.writeln('Using TypeScript %s from %s', this.getTypeScriptVersion(), this.getTypeScriptPath());

var result = this.converter.convert(src);
const result = this.converter.convert(src);
if (result.errors && result.errors.length) {
this.logger.diagnostics(result.errors);
if (this.ignoreCompilerErrors) {
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @returns TRUE if the documentation could be generated successfully, otherwise FALSE.
*/
public generateDocs(input:any, out:string):boolean {
var project = input instanceof ProjectReflection ? input : this.convert(input);
const project = input instanceof ProjectReflection ? input : this.convert(input);
if (!project) return false;

out = Path.resolve(out);
Expand Down Expand Up @@ -226,7 +226,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @returns TRUE if the json file could be written successfully, otherwise FALSE.
*/
public generateJson(input:any, out:string):boolean {
var project = input instanceof ProjectReflection ? input : this.convert(input);
const project = input instanceof ProjectReflection ? input : this.convert(input);
if (!project) return false;

out = Path.resolve(out);
Expand All @@ -248,14 +248,14 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @returns The list of input files with expanded directories.
*/
public expandInputFiles(inputFiles?:string[]):string[] {
var exclude:IMinimatch, files:string[] = [];
let exclude:IMinimatch, files:string[] = [];
if (this.exclude) {
exclude = new Minimatch(this.exclude);
}

function add(dirname:string) {
FS.readdirSync(dirname).forEach((file) => {
var realpath = Path.join(dirname, file);
const realpath = Path.join(dirname, file);
if (FS.statSync(realpath).isDirectory()) {
add(realpath);
} else if (/\.tsx?$/.test(realpath)) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CliApplication extends Application
* Run TypeDoc from the command line.
*/
protected bootstrap(options?:Object):IOptionsReadResult {
var result = super.bootstrap(options);
const result = super.bootstrap(options);
if (result.hasErrors) {
process.exit(ExitCode.OptionError);
return;
Expand All @@ -72,8 +72,8 @@ export class CliApplication extends Application
this.logger.error("You must either specify the 'out' or 'json' option.");
process.exit(ExitCode.NoOutput);
} else {
var src = this.expandInputFiles(result.inputFiles);
var project = this.convert(src);
const src = this.expandInputFiles(result.inputFiles);
const project = this.convert(src);
if (project) {
if (this.out) this.generateDocs(project, this.out);
if (this.json) this.generateJson(project, this.json);
Expand Down
46 changes: 23 additions & 23 deletions src/lib/converter/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Context
this.program = program;
this.visitStack = [];

var project = new ProjectReflection(converter.name);
const project = new ProjectReflection(converter.name);
this.project = project;
this.scope = project;

Expand All @@ -138,7 +138,7 @@ export class Context
* @returns The type declaration of the given node.
*/
getTypeAtLocation(node:ts.Node):ts.Type {
var nodeType:ts.Type;
let nodeType:ts.Type;
try {
nodeType = this.checker.getTypeAtLocation(node);
} catch (error) {
Expand Down Expand Up @@ -195,7 +195,7 @@ export class Context
registerReflection(reflection:Reflection, node:ts.Node, symbol?:ts.Symbol) {
this.project.reflections[reflection.id] = reflection;

var id = this.getSymbolID(symbol ? symbol : (node ? node.symbol : null));
const id = this.getSymbolID(symbol ? symbol : (node ? node.symbol : null));
if (!this.isInherit && id && !this.project.symbolMapping[id]) {
this.project.symbolMapping[id] = reflection.id;
}
Expand Down Expand Up @@ -223,9 +223,9 @@ export class Context
* @param callback The callback that should be executed.
*/
withSourceFile(node:ts.SourceFile, callback:Function) {
var options = this.converter.application.options;
var externalPattern = this.externalPattern;
var isExternal = this.fileNames.indexOf(node.fileName) == -1;
const options = this.converter.application.options;
const externalPattern = this.externalPattern;
let isExternal = this.fileNames.indexOf(node.fileName) == -1;
if (externalPattern) {
isExternal = isExternal || externalPattern.match(node.fileName);
}
Expand All @@ -234,10 +234,10 @@ export class Context
return;
}

var isDeclaration = node.isDeclarationFile;
let isDeclaration = node.isDeclarationFile;
if (isDeclaration) {
var lib = this.converter.getDefaultLib();
var isLib = node.fileName.substr(-lib.length) == lib;
const lib = this.converter.getDefaultLib();
const isLib = node.fileName.substr(-lib.length) == lib;
if (!this.converter.includeDeclarations || isLib) {
return;
}
Expand Down Expand Up @@ -279,12 +279,12 @@ export class Context
*/
public withScope(scope:Reflection, ...args:any[]):void {
if (!scope || !args.length) return;
var callback = args.pop();
var parameters = args.shift();
const callback = args.pop();
const parameters = args.shift();

var oldScope = this.scope;
var oldTypeArguments = this.typeArguments;
var oldTypeParameters = this.typeParameters;
const oldScope = this.scope;
const oldTypeArguments = this.typeArguments;
const oldTypeParameters = this.typeParameters;

this.scope = scope;
this.typeParameters = parameters ? this.extractTypeParameters(parameters, args.length > 0) : this.typeParameters;
Expand All @@ -306,22 +306,22 @@ export class Context
* @return The resulting reflection / the current scope.
*/
inherit(baseNode:ts.Node, typeArguments?:ts.NodeArray<ts.TypeNode>):Reflection {
var wasInherit = this.isInherit;
var oldInherited = this.inherited;
var oldInheritParent = this.inheritParent;
var oldTypeArguments = this.typeArguments;
const wasInherit = this.isInherit;
const oldInherited = this.inherited;
const oldInheritParent = this.inheritParent;
const oldTypeArguments = this.typeArguments;

this.isInherit = true;
this.inheritParent = baseNode;
this.inherited = [];

var target = <ContainerReflection>this.scope;
const target = <ContainerReflection>this.scope;
if (!(target instanceof ContainerReflection)) {
throw new Error('Expected container reflection');
}

if (baseNode.symbol) {
var id = this.getSymbolID(baseNode.symbol);
const id = this.getSymbolID(baseNode.symbol);
if (this.inheritedChildren && this.inheritedChildren.indexOf(id) != -1) {
return target;
} else {
Expand Down Expand Up @@ -365,17 +365,17 @@ export class Context
* @returns The resulting type mapping.
*/
private extractTypeParameters(parameters:ts.NodeArray<ts.TypeParameterDeclaration>, preserve?:boolean):ts.MapLike<Type> {
var typeParameters:ts.MapLike<Type> = {};
const typeParameters:ts.MapLike<Type> = {};

if (preserve) {
for (var key in this.typeParameters) {
for (let key in this.typeParameters) {
if (!this.typeParameters.hasOwnProperty(key)) continue;
typeParameters[key] = this.typeParameters[key];
}
}

parameters.forEach((declaration:ts.TypeParameterDeclaration, index:number) => {
var name = declaration.symbol.name;
const name = declaration.symbol.name;
if (this.typeArguments && this.typeArguments[index]) {
typeParameters[name] = this.typeArguments[index];
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/convert-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function convertExpression(expression:ts.Expression):string
case ts.SyntaxKind.FalseKeyword:
return 'false';
default:
var source = _ts.getSourceFileOfNode(<ts.Node>expression);
const source = _ts.getSourceFileOfNode(<ts.Node>expression);
return source.text.substring(expression.pos, expression.end);
}
}
36 changes: 18 additions & 18 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class Converter extends ChildableComponent<Application, ConverterComponen


addComponent(name:string, componentClass:IComponentClass<ConverterComponent>):ConverterComponent {
var component = super.addComponent(name, componentClass);
const component = super.addComponent(name, componentClass);
if (component instanceof ConverterNodeComponent) {
this.addNodeConverter(component);
} else if (component instanceof ConverterTypeComponent) {
Expand All @@ -261,7 +261,7 @@ export class Converter extends ChildableComponent<Application, ConverterComponen


private addNodeConverter(converter:ConverterNodeComponent<any>) {
for (var supports of converter.supports) {
for (let supports of converter.supports) {
this.nodeConverters[supports] = converter;
}
}
Expand All @@ -281,7 +281,7 @@ export class Converter extends ChildableComponent<Application, ConverterComponen


removeComponent(name:string):ConverterComponent {
var component = super.removeComponent(name);
const component = super.removeComponent(name);
if (component instanceof ConverterNodeComponent) {
this.removeNodeConverter(component);
} else if (component instanceof ConverterTypeComponent) {
Expand All @@ -293,9 +293,9 @@ export class Converter extends ChildableComponent<Application, ConverterComponen


private removeNodeConverter(converter:ConverterNodeComponent<any>) {
var converters = this.nodeConverters;
var keys = _.keys(this.nodeConverters);
for (var key of keys) {
const converters = this.nodeConverters;
const keys = _.keys(this.nodeConverters);
for (let key of keys) {
if (converters[key] === converter) {
delete converters[key];
}
Expand All @@ -304,7 +304,7 @@ export class Converter extends ChildableComponent<Application, ConverterComponen


private removeTypeConverter(converter:ConverterTypeComponent) {
var index = this.typeNodeConverters.indexOf(<any>converter);
let index = this.typeNodeConverters.indexOf(<any>converter);
if (index != -1) {
this.typeTypeConverters.splice(index, 1);
}
Expand Down Expand Up @@ -332,18 +332,18 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
* @param fileNames Array of the file names that should be compiled.
*/
convert(fileNames:string[]):IConverterResult {
for (var i = 0, c = fileNames.length; i < c; i++) {
for (let i = 0, c = fileNames.length; i < c; i++) {
fileNames[i] = normalizePath(_ts.normalizeSlashes(fileNames[i]));
}

var program = ts.createProgram(fileNames, this.application.options.getCompilerOptions(), this.compilerHost);
var checker = program.getTypeChecker();
var context = new Context(this, fileNames, checker, program);
const program = ts.createProgram(fileNames, this.application.options.getCompilerOptions(), this.compilerHost);
const checker = program.getTypeChecker();
const context = new Context(this, fileNames, checker, program);

this.trigger(Converter.EVENT_BEGIN, context);

var errors = this.compile(context);
var project = this.resolve(context);
const errors = this.compile(context);
const project = this.resolve(context);

this.trigger(Converter.EVENT_END, context);

Expand All @@ -368,11 +368,11 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
return null;
}

var oldVisitStack = context.visitStack;
const oldVisitStack = context.visitStack;
context.visitStack = oldVisitStack.slice();
context.visitStack.push(node);

var result:Reflection;
let result:Reflection;
if (node.kind in this.nodeConverters) {
result = this.nodeConverters[node.kind].convert(context, node);
}
Expand Down Expand Up @@ -420,7 +420,7 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
* @returns An array containing all errors generated by the TypeScript compiler.
*/
private compile(context:Context):ts.Diagnostic[] {
var program = context.program;
const program = context.program;

program.getSourceFiles().forEach((sourceFile) => {
this.convertNode(context, sourceFile);
Expand Down Expand Up @@ -450,9 +450,9 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
*/
private resolve(context:Context):ProjectReflection {
this.trigger(Converter.EVENT_RESOLVE_BEGIN, context);
var project = context.project;
const project = context.project;

for (var id in project.reflections) {
for (let id in project.reflections) {
if (!project.reflections.hasOwnProperty(id)) continue;
this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]);
}
Expand Down
21 changes: 11 additions & 10 deletions src/lib/converter/factories/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Comment, CommentTag} from "../../models/comments/index";
* no comment is present.
*/
export function createComment(node:ts.Node):Comment {
var comment = getRawComment(node);
const comment = getRawComment(node);
if (comment == null) {
return null;
}
Expand Down Expand Up @@ -87,10 +87,10 @@ export function getRawComment(node:ts.Node):string {
}
}

var sourceFile = _ts.getSourceFileOfNode(node);
var comments = _ts.getJSDocCommentRanges(node, sourceFile.text);
const sourceFile = _ts.getSourceFileOfNode(node);
const comments = _ts.getJSDocCommentRanges(node, sourceFile.text);
if (comments && comments.length) {
var comment:ts.CommentRange;
let comment:ts.CommentRange;
if (node.kind == ts.SyntaxKind.SourceFile) {
if (comments.length == 1) return null;
comment = comments[0];
Expand All @@ -113,8 +113,8 @@ export function getRawComment(node:ts.Node):string {
* @returns A populated [[Models.Comment]] instance.
*/
export function parseComment(text:string, comment:Comment = new Comment()):Comment {
var currentTag:CommentTag;
var shortText:number = 0;
let currentTag:CommentTag;
let shortText:number = 0;

function consumeTypeData(line:string):string {
line = line.replace(/^\{[^\}]*\}+/, '');
Expand All @@ -140,15 +140,16 @@ export function parseComment(text:string, comment:Comment = new Comment()):Comme
}

function readTagLine(line:string, tag:RegExpExecArray) {
var tagName = tag[1].toLowerCase();
let tagName = tag[1].toLowerCase();
let paramName: string;
line = line.substr(tagName.length + 1).trim();

if (tagName == 'return') tagName = 'returns';
if (tagName == 'param' || tagName == 'typeparam') {
line = consumeTypeData(line);
var param = /[^\s]+/.exec(line);
const param = /[^\s]+/.exec(line);
if (param) {
var paramName = param[0];
paramName = param[0];
line = line.substr(paramName.length + 1).trim();
}
line = consumeTypeData(line);
Expand All @@ -166,7 +167,7 @@ export function parseComment(text:string, comment:Comment = new Comment()):Comme
line = line.replace(/^\s*\*? ?/, '');
line = line.replace(/\s*$/, '');

var tag = /^@(\w+)/.exec(line);
const tag = /^@(\w+)/.exec(line);
if (tag) {
readTagLine(line, tag);
} else {
Expand Down
Loading