Change let into const (#457)

This patch:
- changes `let` into `const` throughout codebase
- adds eslint check to prefer const over let
This commit is contained in:
Eric Bidelman
2017-08-21 16:39:04 -07:00
committed by Andrey Lushnikov
parent 5d6d3e0a81
commit 1f9b4fb4c8
37 changed files with 495 additions and 494 deletions

View File

@@ -27,8 +27,8 @@ class JSOutline {
this._currentClassMembers = [];
this._text = text;
let ast = esprima.parseScript(this._text, {loc: true, range: true});
let walker = new ESTreeWalker(node => {
const ast = esprima.parseScript(this._text, {loc: true, range: true});
const walker = new ESTreeWalker(node => {
if (node.type === 'ClassDeclaration')
this._onClassDeclaration(node);
else if (node.type === 'MethodDefinition')
@@ -49,9 +49,9 @@ class JSOutline {
_onMethodDefinition(node) {
console.assert(this._currentClassName !== null);
console.assert(node.value.type === 'FunctionExpression');
let methodName = this._extractText(node.key);
const methodName = this._extractText(node.key);
if (node.kind === 'get') {
let property = Documentation.Member.createProperty(methodName);
const property = Documentation.Member.createProperty(methodName);
this._currentClassMembers.push(property);
return;
}
@@ -60,7 +60,7 @@ class JSOutline {
// Extract properties from constructor.
if (node.kind === 'constructor') {
// Extract properties from constructor.
let walker = new ESTreeWalker(node => {
const walker = new ESTreeWalker(node => {
if (node.type !== 'AssignmentExpression')
return;
node = node.left;
@@ -71,7 +71,7 @@ class JSOutline {
});
walker.walk(node);
} else if (!hasReturn) {
let walker = new ESTreeWalker(node => {
const walker = new ESTreeWalker(node => {
if (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression')
return ESTreeWalker.SkipSubtree;
if (node.type === 'ReturnStatement')
@@ -80,7 +80,7 @@ class JSOutline {
walker.walk(node.value.body);
}
const args = [];
for (let param of node.value.params) {
for (const param of node.value.params) {
if (param.type === 'AssignmentPattern')
args.push(new Documentation.Argument(param.left.name));
else if (param.type === 'RestElement')
@@ -92,7 +92,7 @@ class JSOutline {
else
this.errors.push(`JS Parsing issue: unsupported syntax to define parameter in ${this._currentClassName}.${methodName}(): ${this._extractText(param)}`);
}
let method = Documentation.Member.createMethod(methodName, args, hasReturn, node.value.async);
const method = Documentation.Member.createMethod(methodName, args, hasReturn, node.value.async);
this._currentClassMembers.push(method);
return ESTreeWalker.SkipSubtree;
}
@@ -108,7 +108,7 @@ class JSOutline {
events = [];
this._eventsByClassName.set(className, events);
}
for (let property of node.right.properties) {
for (const property of node.right.properties) {
if (property.type !== 'Property' || property.key.type !== 'Identifier' || property.value.type !== 'Literal')
continue;
events.push(Documentation.Member.createEvent(property.value.value));
@@ -118,7 +118,7 @@ class JSOutline {
_flushClassIfNeeded() {
if (this._currentClassName === null)
return;
let jsClass = new Documentation.Class(this._currentClassName, this._currentClassMembers);
const jsClass = new Documentation.Class(this._currentClassName, this._currentClassMembers);
this.classes.push(jsClass);
this._currentClassName = null;
this._currentClassMembers = [];
@@ -126,8 +126,8 @@ class JSOutline {
_recreateClassesWithEvents() {
this.classes = this.classes.map(cls => {
let events = this._eventsByClassName.get(cls.name) || [];
let members = cls.membersArray.concat(events);
const events = this._eventsByClassName.get(cls.name) || [];
const members = cls.membersArray.concat(events);
return new Documentation.Class(cls.name, members);
});
}
@@ -135,7 +135,7 @@ class JSOutline {
_extractText(node) {
if (!node)
return null;
let text = this._text.substring(node.range[0], node.range[1]).trim();
const text = this._text.substring(node.range[0], node.range[1]).trim();
return text;
}
}
@@ -145,10 +145,10 @@ class JSOutline {
* @return {!Promise<{documentation: !Documentation, errors: !Array<string>}>}
*/
module.exports = async function(sources) {
let classes = [];
let errors = [];
for (let source of sources) {
let outline = new JSOutline(source.text());
const classes = [];
const errors = [];
for (const source of sources) {
const outline = new JSOutline(source.text());
classes.push(...outline.classes);
errors.push(...outline.errors);
}