Skip to content

Commit 026cb81

Browse files
nicknisiblakeembrey
authored andcommitted
Refactor var to const and let (#429)
1 parent 63a7b35 commit 026cb81

File tree

112 files changed

+684
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+684
-670
lines changed

src/lib/application.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
113113
protected bootstrap(options?:Object):IOptionsReadResult {
114114
this.options.read(options, OptionsReadMode.Prefetch);
115115

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

148148

149149
public getTypeScriptVersion():string {
150-
var tsPath = this.getTypeScriptPath();
151-
var json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
150+
const tsPath = this.getTypeScriptPath();
151+
const json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
152152
return json.version;
153153
}
154154

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

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

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

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

256256
function add(dirname:string) {
257257
FS.readdirSync(dirname).forEach((file) => {
258-
var realpath = Path.join(dirname, file);
258+
const realpath = Path.join(dirname, file);
259259
if (FS.statSync(realpath).isDirectory()) {
260260
add(realpath);
261261
} else if (/\.tsx?$/.test(realpath)) {

src/lib/cli.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class CliApplication extends Application
5555
* Run TypeDoc from the command line.
5656
*/
5757
protected bootstrap(options?:Object):IOptionsReadResult {
58-
var result = super.bootstrap(options);
58+
const result = super.bootstrap(options);
5959
if (result.hasErrors) {
6060
process.exit(ExitCode.OptionError);
6161
return;
@@ -72,8 +72,8 @@ export class CliApplication extends Application
7272
this.logger.error("You must either specify the 'out' or 'json' option.");
7373
process.exit(ExitCode.NoOutput);
7474
} else {
75-
var src = this.expandInputFiles(result.inputFiles);
76-
var project = this.convert(src);
75+
const src = this.expandInputFiles(result.inputFiles);
76+
const project = this.convert(src);
7777
if (project) {
7878
if (this.out) this.generateDocs(project, this.out);
7979
if (this.json) this.generateJson(project, this.json);

src/lib/converter/context.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Context
113113
this.program = program;
114114
this.visitStack = [];
115115

116-
var project = new ProjectReflection(converter.name);
116+
const project = new ProjectReflection(converter.name);
117117
this.project = project;
118118
this.scope = project;
119119

@@ -138,7 +138,7 @@ export class Context
138138
* @returns The type declaration of the given node.
139139
*/
140140
getTypeAtLocation(node:ts.Node):ts.Type {
141-
var nodeType:ts.Type;
141+
let nodeType:ts.Type;
142142
try {
143143
nodeType = this.checker.getTypeAtLocation(node);
144144
} catch (error) {
@@ -195,7 +195,7 @@ export class Context
195195
registerReflection(reflection:Reflection, node:ts.Node, symbol?:ts.Symbol) {
196196
this.project.reflections[reflection.id] = reflection;
197197

198-
var id = this.getSymbolID(symbol ? symbol : (node ? node.symbol : null));
198+
const id = this.getSymbolID(symbol ? symbol : (node ? node.symbol : null));
199199
if (!this.isInherit && id && !this.project.symbolMapping[id]) {
200200
this.project.symbolMapping[id] = reflection.id;
201201
}
@@ -223,9 +223,9 @@ export class Context
223223
* @param callback The callback that should be executed.
224224
*/
225225
withSourceFile(node:ts.SourceFile, callback:Function) {
226-
var options = this.converter.application.options;
227-
var externalPattern = this.externalPattern;
228-
var isExternal = this.fileNames.indexOf(node.fileName) == -1;
226+
const options = this.converter.application.options;
227+
const externalPattern = this.externalPattern;
228+
let isExternal = this.fileNames.indexOf(node.fileName) == -1;
229229
if (externalPattern) {
230230
isExternal = isExternal || externalPattern.match(node.fileName);
231231
}
@@ -234,10 +234,10 @@ export class Context
234234
return;
235235
}
236236

237-
var isDeclaration = node.isDeclarationFile;
237+
let isDeclaration = node.isDeclarationFile;
238238
if (isDeclaration) {
239-
var lib = this.converter.getDefaultLib();
240-
var isLib = node.fileName.substr(-lib.length) == lib;
239+
const lib = this.converter.getDefaultLib();
240+
const isLib = node.fileName.substr(-lib.length) == lib;
241241
if (!this.converter.includeDeclarations || isLib) {
242242
return;
243243
}
@@ -279,12 +279,12 @@ export class Context
279279
*/
280280
public withScope(scope:Reflection, ...args:any[]):void {
281281
if (!scope || !args.length) return;
282-
var callback = args.pop();
283-
var parameters = args.shift();
282+
const callback = args.pop();
283+
const parameters = args.shift();
284284

285-
var oldScope = this.scope;
286-
var oldTypeArguments = this.typeArguments;
287-
var oldTypeParameters = this.typeParameters;
285+
const oldScope = this.scope;
286+
const oldTypeArguments = this.typeArguments;
287+
const oldTypeParameters = this.typeParameters;
288288

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

314314
this.isInherit = true;
315315
this.inheritParent = baseNode;
316316
this.inherited = [];
317317

318-
var target = <ContainerReflection>this.scope;
318+
const target = <ContainerReflection>this.scope;
319319
if (!(target instanceof ContainerReflection)) {
320320
throw new Error('Expected container reflection');
321321
}
322322

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

370370
if (preserve) {
371-
for (var key in this.typeParameters) {
371+
for (let key in this.typeParameters) {
372372
if (!this.typeParameters.hasOwnProperty(key)) continue;
373373
typeParameters[key] = this.typeParameters[key];
374374
}
375375
}
376376

377377
parameters.forEach((declaration:ts.TypeParameterDeclaration, index:number) => {
378-
var name = declaration.symbol.name;
378+
const name = declaration.symbol.name;
379379
if (this.typeArguments && this.typeArguments[index]) {
380380
typeParameters[name] = this.typeArguments[index];
381381
} else {

src/lib/converter/convert-expression.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function convertExpression(expression:ts.Expression):string
3030
case ts.SyntaxKind.FalseKeyword:
3131
return 'false';
3232
default:
33-
var source = _ts.getSourceFileOfNode(<ts.Node>expression);
33+
const source = _ts.getSourceFileOfNode(<ts.Node>expression);
3434
return source.text.substring(expression.pos, expression.end);
3535
}
3636
}

src/lib/converter/converter.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
249249

250250

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

262262

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

282282

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

294294

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

305305

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

339-
var program = ts.createProgram(fileNames, this.application.options.getCompilerOptions(), this.compilerHost);
340-
var checker = program.getTypeChecker();
341-
var context = new Context(this, fileNames, checker, program);
339+
const program = ts.createProgram(fileNames, this.application.options.getCompilerOptions(), this.compilerHost);
340+
const checker = program.getTypeChecker();
341+
const context = new Context(this, fileNames, checker, program);
342342

343343
this.trigger(Converter.EVENT_BEGIN, context);
344344

345-
var errors = this.compile(context);
346-
var project = this.resolve(context);
345+
const errors = this.compile(context);
346+
const project = this.resolve(context);
347347

348348
this.trigger(Converter.EVENT_END, context);
349349

@@ -368,11 +368,11 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
368368
return null;
369369
}
370370

371-
var oldVisitStack = context.visitStack;
371+
const oldVisitStack = context.visitStack;
372372
context.visitStack = oldVisitStack.slice();
373373
context.visitStack.push(node);
374374

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

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

455-
for (var id in project.reflections) {
455+
for (let id in project.reflections) {
456456
if (!project.reflections.hasOwnProperty(id)) continue;
457457
this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]);
458458
}

src/lib/converter/factories/comment.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Comment, CommentTag} from "../../models/comments/index";
1212
* no comment is present.
1313
*/
1414
export function createComment(node:ts.Node):Comment {
15-
var comment = getRawComment(node);
15+
const comment = getRawComment(node);
1616
if (comment == null) {
1717
return null;
1818
}
@@ -87,10 +87,10 @@ export function getRawComment(node:ts.Node):string {
8787
}
8888
}
8989

90-
var sourceFile = _ts.getSourceFileOfNode(node);
91-
var comments = _ts.getJSDocCommentRanges(node, sourceFile.text);
90+
const sourceFile = _ts.getSourceFileOfNode(node);
91+
const comments = _ts.getJSDocCommentRanges(node, sourceFile.text);
9292
if (comments && comments.length) {
93-
var comment:ts.CommentRange;
93+
let comment:ts.CommentRange;
9494
if (node.kind == ts.SyntaxKind.SourceFile) {
9595
if (comments.length == 1) return null;
9696
comment = comments[0];
@@ -113,8 +113,8 @@ export function getRawComment(node:ts.Node):string {
113113
* @returns A populated [[Models.Comment]] instance.
114114
*/
115115
export function parseComment(text:string, comment:Comment = new Comment()):Comment {
116-
var currentTag:CommentTag;
117-
var shortText:number = 0;
116+
let currentTag:CommentTag;
117+
let shortText:number = 0;
118118

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

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

146147
if (tagName == 'return') tagName = 'returns';
147148
if (tagName == 'param' || tagName == 'typeparam') {
148149
line = consumeTypeData(line);
149-
var param = /[^\s]+/.exec(line);
150+
const param = /[^\s]+/.exec(line);
150151
if (param) {
151-
var paramName = param[0];
152+
paramName = param[0];
152153
line = line.substr(paramName.length + 1).trim();
153154
}
154155
line = consumeTypeData(line);
@@ -166,7 +167,7 @@ export function parseComment(text:string, comment:Comment = new Comment()):Comme
166167
line = line.replace(/^\s*\*? ?/, '');
167168
line = line.replace(/\s*$/, '');
168169

169-
var tag = /^@(\w+)/.exec(line);
170+
const tag = /^@(\w+)/.exec(line);
170171
if (tag) {
171172
readTagLine(line, tag);
172173
} else {

0 commit comments

Comments
 (0)