Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
+23
-23
@@ -1,9 +1,9 @@
|
||||
var fs = require('fs-extra');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
var async = require('async');
|
||||
var nomnom = require('nomnom');
|
||||
const async = require('async');
|
||||
const nomnom = require('nomnom');
|
||||
|
||||
var generateInfo = require('./generate-info');
|
||||
const generateInfo = require('./generate-info');
|
||||
|
||||
|
||||
/**
|
||||
@@ -21,19 +21,19 @@ function getConfig(configPath, callback) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
var obj;
|
||||
let obj;
|
||||
try {
|
||||
obj = JSON.parse(String(data));
|
||||
} catch (err2) {
|
||||
callback(new Error('Trouble parsing file as JSON: ' + configPath));
|
||||
return;
|
||||
}
|
||||
var patterns = obj.exports;
|
||||
const patterns = obj.exports;
|
||||
if (patterns && !Array.isArray(patterns)) {
|
||||
callback(new Error('Expected an exports array, got: ' + patterns));
|
||||
return;
|
||||
}
|
||||
var namespace = obj.namespace;
|
||||
const namespace = obj.namespace;
|
||||
if (namespace && typeof namespace !== 'string') {
|
||||
callback(new Error('Expected an namespace string, got: ' +
|
||||
namespace));
|
||||
@@ -61,7 +61,7 @@ function getSymbols(patterns, callback) {
|
||||
callback(new Error('Trouble generating info: ' + err.message));
|
||||
return;
|
||||
}
|
||||
var symbols = require('../build/info.json').symbols;
|
||||
const symbols = require('../build/info.json').symbols;
|
||||
callback(null, patterns, symbols);
|
||||
});
|
||||
}
|
||||
@@ -80,10 +80,10 @@ function getSymbols(patterns, callback) {
|
||||
* the filtered list of symbols and a list of all provides (or any error).
|
||||
*/
|
||||
function filterSymbols(patterns, symbols, callback) {
|
||||
var matches = [];
|
||||
const matches = [];
|
||||
|
||||
var provides = {};
|
||||
var lookup = {};
|
||||
const provides = {};
|
||||
const lookup = {};
|
||||
symbols.forEach(function(symbol) {
|
||||
lookup[symbol.name] = symbol;
|
||||
symbol.provides.forEach(function(provide) {
|
||||
@@ -92,8 +92,8 @@ function filterSymbols(patterns, symbols, callback) {
|
||||
});
|
||||
|
||||
patterns.forEach(function(name) {
|
||||
var match = false;
|
||||
var pattern = (name.substr(-1) === '*');
|
||||
let match = false;
|
||||
const pattern = (name.substr(-1) === '*');
|
||||
if (pattern) {
|
||||
name = name.substr(0, name.length - 1);
|
||||
symbols.forEach(function(symbol) {
|
||||
@@ -103,14 +103,14 @@ function filterSymbols(patterns, symbols, callback) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var symbol = lookup[name];
|
||||
const symbol = lookup[name];
|
||||
if (symbol) {
|
||||
matches.push(symbol);
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
var message = 'No matching symbol found: ' + name + (pattern ? '*' : '');
|
||||
const message = 'No matching symbol found: ' + name + (pattern ? '*' : '');
|
||||
callback(new Error(message));
|
||||
}
|
||||
});
|
||||
@@ -140,9 +140,9 @@ function formatSymbolExport(name, namespace) {
|
||||
* @return {string} Export code.
|
||||
*/
|
||||
function formatPropertyExport(name) {
|
||||
var parts = name.split('#');
|
||||
var prototype = parts[0] + '.prototype';
|
||||
var property = parts[1];
|
||||
const parts = name.split('#');
|
||||
const prototype = parts[0] + '.prototype';
|
||||
const property = parts[1];
|
||||
return 'goog.exportProperty(\n' +
|
||||
' ' + prototype + ',\n' +
|
||||
' \'' + property + '\',\n' +
|
||||
@@ -158,13 +158,13 @@ function formatPropertyExport(name) {
|
||||
* @return {string} Export code.
|
||||
*/
|
||||
function generateExports(symbols, namespace, provides) {
|
||||
var blocks = [];
|
||||
const blocks = [];
|
||||
provides.forEach(function(provide) {
|
||||
blocks.push('goog.require(\'' + provide + '\');');
|
||||
});
|
||||
blocks.push('\n\n');
|
||||
symbols.forEach(function(symbol) {
|
||||
var name = symbol.name;
|
||||
const name = symbol.name;
|
||||
if (name.indexOf('#') > 0) {
|
||||
blocks.push(formatPropertyExport(name));
|
||||
} else {
|
||||
@@ -172,7 +172,7 @@ function generateExports(symbols, namespace, provides) {
|
||||
}
|
||||
});
|
||||
blocks.unshift(
|
||||
'/**\n' +
|
||||
'/**\n' +
|
||||
' * @fileoverview Custom exports file.\n' +
|
||||
' * @suppress {checkVars,extraRequire}\n' +
|
||||
' */\n');
|
||||
@@ -192,7 +192,7 @@ function main(config, callback) {
|
||||
getSymbols.bind(null, config.exports),
|
||||
filterSymbols,
|
||||
function(symbols, provides, done) {
|
||||
var code, err;
|
||||
let code, err;
|
||||
try {
|
||||
code = generateExports(symbols, config.namespace, provides);
|
||||
} catch (e) {
|
||||
@@ -209,7 +209,7 @@ function main(config, callback) {
|
||||
* function, and write the output file.
|
||||
*/
|
||||
if (require.main === module) {
|
||||
var options = nomnom.options({
|
||||
const options = nomnom.options({
|
||||
output: {
|
||||
position: 0,
|
||||
required: true,
|
||||
|
||||
+18
-18
@@ -1,10 +1,10 @@
|
||||
var async = require('async');
|
||||
var fs = require('fs-extra');
|
||||
var nomnom = require('nomnom');
|
||||
const async = require('async');
|
||||
const fs = require('fs-extra');
|
||||
const nomnom = require('nomnom');
|
||||
|
||||
var generateInfo = require('./generate-info');
|
||||
const generateInfo = require('./generate-info');
|
||||
|
||||
var googRegEx = /^goog\..*$/;
|
||||
const googRegEx = /^goog\..*$/;
|
||||
|
||||
/**
|
||||
* Read the symbols from info file.
|
||||
@@ -17,7 +17,7 @@ function getInfo(callback) {
|
||||
callback(new Error('Trouble generating info: ' + err.message));
|
||||
return;
|
||||
}
|
||||
var info = require('../build/info.json');
|
||||
const info = require('../build/info.json');
|
||||
callback(null, info.typedefs, info.symbols, info.externs, info.base);
|
||||
});
|
||||
}
|
||||
@@ -33,18 +33,18 @@ function getInfo(callback) {
|
||||
* @return {string} Export code.
|
||||
*/
|
||||
function generateExterns(typedefs, symbols, externs, base) {
|
||||
var lines = [];
|
||||
var processedSymbols = {};
|
||||
var constructors = {};
|
||||
var constructorOptionsTypes = {};
|
||||
const lines = [];
|
||||
const processedSymbols = {};
|
||||
const constructors = {};
|
||||
const constructorOptionsTypes = {};
|
||||
|
||||
function addNamespaces(name) {
|
||||
var parts = name.split('.');
|
||||
const parts = name.split('.');
|
||||
parts.pop();
|
||||
var namespace = [];
|
||||
const namespace = [];
|
||||
parts.forEach(function(part) {
|
||||
namespace.push(part);
|
||||
var partialNamespace = namespace.join('.');
|
||||
const partialNamespace = namespace.join('.');
|
||||
if (!(partialNamespace in processedSymbols ||
|
||||
partialNamespace in constructors)) {
|
||||
lines.push('/**');
|
||||
@@ -77,10 +77,10 @@ function generateExterns(typedefs, symbols, externs, base) {
|
||||
function processSymbol(symbol) {
|
||||
addNamespaces(symbol.name.split('#')[0]);
|
||||
|
||||
var name = symbol.name;
|
||||
let name = symbol.name;
|
||||
if (name.indexOf('#') > 0) {
|
||||
name = symbol.name.replace('#', '.prototype.');
|
||||
var constructor = symbol.name.split('#')[0];
|
||||
const constructor = symbol.name.split('#')[0];
|
||||
if (!(constructor in constructors)) {
|
||||
constructors[constructor] = true;
|
||||
lines.push('/**');
|
||||
@@ -102,7 +102,7 @@ function generateExterns(typedefs, symbols, externs, base) {
|
||||
if (symbol.types) {
|
||||
lines.push(' * @type {' + symbol.types.join('|') + '}');
|
||||
}
|
||||
var args = [];
|
||||
const args = [];
|
||||
if (symbol.params) {
|
||||
symbol.params.forEach(function(param) {
|
||||
findConstructorOptionsTypes(param.types);
|
||||
@@ -183,7 +183,7 @@ function main(callback) {
|
||||
async.waterfall([
|
||||
getInfo,
|
||||
function(typedefs, symbols, externs, base, done) {
|
||||
var code, err;
|
||||
let code, err;
|
||||
try {
|
||||
code = generateExterns(typedefs, symbols, externs, base);
|
||||
} catch (e) {
|
||||
@@ -200,7 +200,7 @@ function main(callback) {
|
||||
* function, and write the output file.
|
||||
*/
|
||||
if (require.main === module) {
|
||||
var options = nomnom.options({
|
||||
const options = nomnom.options({
|
||||
output: {
|
||||
position: 0,
|
||||
required: true,
|
||||
|
||||
+34
-34
@@ -1,18 +1,18 @@
|
||||
var fs = require('fs-extra');
|
||||
var path = require('path');
|
||||
var spawn = require('child_process').spawn;
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
var async = require('async');
|
||||
var walk = require('walk').walk;
|
||||
var isWindows = process.platform.indexOf('win') === 0;
|
||||
const async = require('async');
|
||||
const walk = require('walk').walk;
|
||||
const isWindows = process.platform.indexOf('win') === 0;
|
||||
|
||||
var sourceDir = path.join(__dirname, '..', 'src');
|
||||
var externsDir = path.join(__dirname, '..', 'externs');
|
||||
var externsPaths = [
|
||||
const sourceDir = path.join(__dirname, '..', 'src');
|
||||
const externsDir = path.join(__dirname, '..', 'externs');
|
||||
const externsPaths = [
|
||||
path.join(externsDir, 'olx.js'),
|
||||
path.join(externsDir, 'geojson.js')
|
||||
];
|
||||
var infoPath = path.join(__dirname, '..', 'build', 'info.json');
|
||||
const infoPath = path.join(__dirname, '..', 'build', 'info.json');
|
||||
|
||||
/**
|
||||
* Get checked path of a binary.
|
||||
@@ -24,14 +24,14 @@ function getBinaryPath(binaryName) {
|
||||
binaryName += '.cmd';
|
||||
}
|
||||
|
||||
var jsdocResolved = require.resolve('jsdoc/jsdoc.js');
|
||||
var expectedPaths = [
|
||||
const jsdocResolved = require.resolve('jsdoc/jsdoc.js');
|
||||
const expectedPaths = [
|
||||
path.join(__dirname, '..', 'node_modules', '.bin', binaryName),
|
||||
path.resolve(path.join(path.dirname(jsdocResolved), '..', '.bin', binaryName))
|
||||
];
|
||||
|
||||
for (var i = 0; i < expectedPaths.length; i++) {
|
||||
var expectedPath = expectedPaths[i];
|
||||
for (let i = 0; i < expectedPaths.length; i++) {
|
||||
const expectedPath = expectedPaths[i];
|
||||
if (fs.existsSync(expectedPath)) {
|
||||
return expectedPath;
|
||||
}
|
||||
@@ -40,10 +40,10 @@ function getBinaryPath(binaryName) {
|
||||
throw Error('JsDoc binary was not found in any of the expected paths: ' + expectedPaths);
|
||||
}
|
||||
|
||||
var jsdoc = getBinaryPath('jsdoc');
|
||||
const jsdoc = getBinaryPath('jsdoc');
|
||||
|
||||
var jsdocConfig = path.join(
|
||||
__dirname, '..', 'config', 'jsdoc', 'info', 'conf.json');
|
||||
const jsdocConfig = path.join(
|
||||
__dirname, '..', 'config', 'jsdoc', 'info', 'conf.json');
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,10 +74,10 @@ function getInfoTime(callback) {
|
||||
* whether any externs are newer than that date.
|
||||
*/
|
||||
function getNewerExterns(date, callback) {
|
||||
var newer = false;
|
||||
var walker = walk(externsDir);
|
||||
let newer = false;
|
||||
const walker = walk(externsDir);
|
||||
walker.on('file', function(root, stats, next) {
|
||||
var sourcePath = path.join(root, stats.name);
|
||||
const sourcePath = path.join(root, stats.name);
|
||||
externsPaths.forEach(function(path) {
|
||||
if (sourcePath === path && stats.mtime > date) {
|
||||
newer = true;
|
||||
@@ -103,11 +103,11 @@ function getNewerExterns(date, callback) {
|
||||
* error and the array of source paths (empty if none newer).
|
||||
*/
|
||||
function getNewer(date, newer, callback) {
|
||||
var paths = [].concat(externsPaths);
|
||||
let paths = [].concat(externsPaths);
|
||||
|
||||
var walker = walk(sourceDir);
|
||||
const walker = walk(sourceDir);
|
||||
walker.on('file', function(root, stats, next) {
|
||||
var sourcePath = path.join(root, stats.name);
|
||||
const sourcePath = path.join(root, stats.name);
|
||||
if (/\.js$/.test(sourcePath)) {
|
||||
paths.push(sourcePath);
|
||||
if (stats.mtime > date) {
|
||||
@@ -146,7 +146,7 @@ function parseOutput(output) {
|
||||
throw new Error('Expected JSON output');
|
||||
}
|
||||
|
||||
var info;
|
||||
let info;
|
||||
try {
|
||||
info = JSON.parse(String(output));
|
||||
} catch (err) {
|
||||
@@ -178,10 +178,10 @@ function spawnJSDoc(paths, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
var output = '';
|
||||
var errors = '';
|
||||
var cwd = path.join(__dirname, '..');
|
||||
var child = spawn(jsdoc, ['-c', jsdocConfig].concat(paths), {cwd: cwd});
|
||||
let output = '';
|
||||
let errors = '';
|
||||
const cwd = path.join(__dirname, '..');
|
||||
const child = spawn(jsdoc, ['-c', jsdocConfig].concat(paths), {cwd: cwd});
|
||||
|
||||
child.stdout.on('data', function(data) {
|
||||
output += String(data);
|
||||
@@ -195,7 +195,7 @@ function spawnJSDoc(paths, callback) {
|
||||
if (code) {
|
||||
callback(new Error(errors || 'JSDoc failed with no output'));
|
||||
} else {
|
||||
var info;
|
||||
let info;
|
||||
try {
|
||||
info = parseOutput(output);
|
||||
} catch (err) {
|
||||
@@ -214,16 +214,16 @@ function spawnJSDoc(paths, callback) {
|
||||
* @param {function(Error, Array.<string>)} callback Called with a list of
|
||||
* provides or any error.
|
||||
*/
|
||||
var getProvides = async.memoize(function(srcPath, callback) {
|
||||
const getProvides = async.memoize(function(srcPath, callback) {
|
||||
fs.readFile(srcPath, function(err, data) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
var provides = [];
|
||||
var matcher = /goog\.provide\('(.*)'\)/;
|
||||
const provides = [];
|
||||
const matcher = /goog\.provide\('(.*)'\)/;
|
||||
String(data).split('\n').forEach(function(line) {
|
||||
var match = line.match(matcher);
|
||||
const match = line.match(matcher);
|
||||
if (match) {
|
||||
provides.push(match[1]);
|
||||
}
|
||||
@@ -271,7 +271,7 @@ function addSymbolProvides(info, callback) {
|
||||
*/
|
||||
function writeInfo(info, callback) {
|
||||
if (info) {
|
||||
var str = JSON.stringify(info, null, ' ');
|
||||
const str = JSON.stringify(info, null, ' ');
|
||||
fs.outputFile(infoPath, str, callback);
|
||||
} else {
|
||||
process.nextTick(function() {
|
||||
|
||||
+4
-4
@@ -25,17 +25,17 @@ function glsl_compress(s, shortNames) {
|
||||
s = s.replace(/\s+/g, ' ');
|
||||
// remove whitespace between non-word tokens
|
||||
s = s.replace(/(\S)\s+([^\w])/g, '$1$2')
|
||||
.replace(/([^\w])\s+(\S)/g, '$1$2');
|
||||
.replace(/([^\w])\s+(\S)/g, '$1$2');
|
||||
// replace original names with short names
|
||||
for (var originalName in shortNames) {
|
||||
for (const originalName in shortNames) {
|
||||
s = s.replace(new RegExp(originalName, 'gm'), shortNames[originalName]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function main(argv) {
|
||||
var options = {};
|
||||
for (var i = 2, ii = argv.length; i < ii; i += 2) {
|
||||
const options = {};
|
||||
for (let i = 2, ii = argv.length; i < ii; i += 2) {
|
||||
options[argv[i].replace(/^../, '')] = argv[i + 1];
|
||||
}
|
||||
if (!options.input) {
|
||||
|
||||
Reference in New Issue
Block a user