Skip to content

Commit 6473f52

Browse files
committed
Convert var to const/let in src files
``` npm install -g jscodeshift git clone https://github.com/cpojer/js-codemod.git jscodeshift -t js-codemod/transforms/no-vars.js ./src ```
1 parent 2beb93b commit 6473f52

16 files changed

+164
-164
lines changed

src/babel.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
'use strict';
22

3-
var crypto = require('crypto');
4-
var path = require('path');
5-
var defaultOptions = require('../static/babelrc.json');
3+
const crypto = require('crypto');
4+
const path = require('path');
5+
const defaultOptions = require('../static/babelrc.json');
66

7-
var babel = null;
8-
var babelVersionDirectory = null;
7+
let babel = null;
8+
let babelVersionDirectory = null;
99

10-
var PREFIXES = [
10+
const PREFIXES = [
1111
'/** @babel */',
1212
'"use babel"',
1313
"'use babel'",
1414
'/* @flow */',
1515
'// @flow'
1616
];
1717

18-
var PREFIX_LENGTH = Math.max.apply(
18+
const PREFIX_LENGTH = Math.max.apply(
1919
Math,
2020
PREFIXES.map(function(prefix) {
2121
return prefix.length;
2222
})
2323
);
2424

2525
exports.shouldCompile = function(sourceCode) {
26-
var start = sourceCode.substr(0, PREFIX_LENGTH);
26+
const start = sourceCode.substr(0, PREFIX_LENGTH);
2727
return PREFIXES.some(function(prefix) {
2828
return start.indexOf(prefix) === 0;
2929
});
3030
};
3131

3232
exports.getCachePath = function(sourceCode) {
3333
if (babelVersionDirectory == null) {
34-
var babelVersion = require('babel-core/package.json').version;
34+
const babelVersion = require('babel-core/package.json').version;
3535
babelVersionDirectory = path.join(
3636
'js',
3737
'babel',
@@ -51,8 +51,8 @@ exports.getCachePath = function(sourceCode) {
5151
exports.compile = function(sourceCode, filePath) {
5252
if (!babel) {
5353
babel = require('babel-core');
54-
var Logger = require('babel-core/lib/transformation/file/logger');
55-
var noop = function() {};
54+
const Logger = require('babel-core/lib/transformation/file/logger');
55+
const noop = function() {};
5656
Logger.prototype.debug = noop;
5757
Logger.prototype.verbose = noop;
5858
}
@@ -61,8 +61,8 @@ exports.compile = function(sourceCode, filePath) {
6161
filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/');
6262
}
6363

64-
var options = { filename: filePath };
65-
for (var key in defaultOptions) {
64+
const options = { filename: filePath };
65+
for (const key in defaultOptions) {
6666
options[key] = defaultOptions[key];
6767
}
6868
return babel.transform(sourceCode, options).code;

src/coffee-script.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
var crypto = require('crypto');
4-
var path = require('path');
5-
var CoffeeScript = null;
3+
const crypto = require('crypto');
4+
const path = require('path');
5+
let CoffeeScript = null;
66

77
exports.shouldCompile = function() {
88
return true;
@@ -20,7 +20,7 @@ exports.getCachePath = function(sourceCode) {
2020

2121
exports.compile = function(sourceCode, filePath) {
2222
if (!CoffeeScript) {
23-
var previousPrepareStackTrace = Error.prepareStackTrace;
23+
const previousPrepareStackTrace = Error.prepareStackTrace;
2424
CoffeeScript = require('coffee-script');
2525

2626
// When it loads, coffee-script reassigns Error.prepareStackTrace. We have
@@ -33,7 +33,7 @@ exports.compile = function(sourceCode, filePath) {
3333
filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/');
3434
}
3535

36-
var output = CoffeeScript.compile(sourceCode, {
36+
const output = CoffeeScript.compile(sourceCode, {
3737
filename: filePath,
3838
sourceFiles: [filePath],
3939
inlineMap: true

src/compile-cache.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
// Atom's compile-cache when installing or updating packages, using an older
66
// version of node.js
77

8-
var path = require('path');
9-
var fs = require('fs-plus');
10-
var sourceMapSupport = require('@atom/source-map-support');
8+
const path = require('path');
9+
const fs = require('fs-plus');
10+
const sourceMapSupport = require('@atom/source-map-support');
1111

12-
var PackageTranspilationRegistry = require('./package-transpilation-registry');
13-
var CSON = null;
12+
const PackageTranspilationRegistry = require('./package-transpilation-registry');
13+
let CSON = null;
1414

15-
var packageTranspilationRegistry = new PackageTranspilationRegistry();
15+
const packageTranspilationRegistry = new PackageTranspilationRegistry();
1616

17-
var COMPILERS = {
17+
const COMPILERS = {
1818
'.js': packageTranspilationRegistry.wrapTranspiler(require('./babel')),
1919
'.ts': packageTranspilationRegistry.wrapTranspiler(require('./typescript')),
2020
'.tsx': packageTranspilationRegistry.wrapTranspiler(require('./typescript')),
@@ -43,11 +43,11 @@ exports.removeTranspilerConfigForPath = function(packagePath) {
4343
packageTranspilationRegistry.removeTranspilerConfigForPath(packagePath);
4444
};
4545

46-
var cacheStats = {};
47-
var cacheDirectory = null;
46+
const cacheStats = {};
47+
let cacheDirectory = null;
4848

4949
exports.setAtomHomeDirectory = function(atomHome) {
50-
var cacheDir = path.join(atomHome, 'compile-cache');
50+
let cacheDir = path.join(atomHome, 'compile-cache');
5151
if (
5252
process.env.USER === 'root' &&
5353
process.env.SUDO_USER &&
@@ -68,7 +68,7 @@ exports.getCacheDirectory = function() {
6868

6969
exports.addPathToCache = function(filePath, atomHome) {
7070
this.setAtomHomeDirectory(atomHome);
71-
var extension = path.extname(filePath);
71+
const extension = path.extname(filePath);
7272

7373
if (extension === '.cson') {
7474
if (!CSON) {
@@ -77,7 +77,7 @@ exports.addPathToCache = function(filePath, atomHome) {
7777
}
7878
return CSON.readFileSync(filePath);
7979
} else {
80-
var compiler = COMPILERS[extension];
80+
const compiler = COMPILERS[extension];
8181
if (compiler) {
8282
return compileFileAtPath(compiler, filePath, extension);
8383
}
@@ -98,10 +98,10 @@ exports.resetCacheStats = function() {
9898
};
9999

100100
function compileFileAtPath(compiler, filePath, extension) {
101-
var sourceCode = fs.readFileSync(filePath, 'utf8');
101+
const sourceCode = fs.readFileSync(filePath, 'utf8');
102102
if (compiler.shouldCompile(sourceCode, filePath)) {
103-
var cachePath = compiler.getCachePath(sourceCode, filePath);
104-
var compiledCode = readCachedJavaScript(cachePath);
103+
const cachePath = compiler.getCachePath(sourceCode, filePath);
104+
let compiledCode = readCachedJavaScript(cachePath);
105105
if (compiledCode != null) {
106106
cacheStats[extension].hits++;
107107
} else {
@@ -115,7 +115,7 @@ function compileFileAtPath(compiler, filePath, extension) {
115115
}
116116

117117
function readCachedJavaScript(relativeCachePath) {
118-
var cachePath = path.join(cacheDirectory, relativeCachePath);
118+
const cachePath = path.join(cacheDirectory, relativeCachePath);
119119
if (fs.isFileSync(cachePath)) {
120120
try {
121121
return fs.readFileSync(cachePath, 'utf8');
@@ -125,11 +125,11 @@ function readCachedJavaScript(relativeCachePath) {
125125
}
126126

127127
function writeCachedJavaScript(relativeCachePath, code) {
128-
var cachePath = path.join(cacheDirectory, relativeCachePath);
128+
const cachePath = path.join(cacheDirectory, relativeCachePath);
129129
fs.writeFileSync(cachePath, code, 'utf8');
130130
}
131131

132-
var INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/gm;
132+
const INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/gm;
133133

134134
exports.install = function(resourcesPath, nodeRequire) {
135135
const snapshotSourceMapConsumer = {
@@ -166,7 +166,7 @@ exports.install = function(resourcesPath, nodeRequire) {
166166
return null;
167167
}
168168

169-
var compiler = COMPILERS[path.extname(filePath)];
169+
let compiler = COMPILERS[path.extname(filePath)];
170170
if (!compiler) compiler = COMPILERS['.js'];
171171

172172
try {
@@ -182,7 +182,7 @@ exports.install = function(resourcesPath, nodeRequire) {
182182
return null;
183183
}
184184

185-
var match, lastMatch;
185+
let match, lastMatch;
186186
INLINE_SOURCE_MAP_REGEXP.lastIndex = 0;
187187
while ((match = INLINE_SOURCE_MAP_REGEXP.exec(fileData))) {
188188
lastMatch = match;
@@ -191,8 +191,8 @@ exports.install = function(resourcesPath, nodeRequire) {
191191
return null;
192192
}
193193

194-
var sourceMappingURL = lastMatch[1];
195-
var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
194+
const sourceMappingURL = lastMatch[1];
195+
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
196196

197197
try {
198198
var sourceMap = JSON.parse(Buffer.from(rawData, 'base64'));
@@ -208,7 +208,7 @@ exports.install = function(resourcesPath, nodeRequire) {
208208
}
209209
});
210210

211-
var prepareStackTraceWithSourceMapping = Error.prepareStackTrace;
211+
const prepareStackTraceWithSourceMapping = Error.prepareStackTrace;
212212
var prepareStackTrace = prepareStackTraceWithSourceMapping;
213213

214214
function prepareStackTraceWithRawStackAssignment(error, frames) {
@@ -245,13 +245,13 @@ exports.install = function(resourcesPath, nodeRequire) {
245245
};
246246

247247
Object.keys(COMPILERS).forEach(function(extension) {
248-
var compiler = COMPILERS[extension];
248+
const compiler = COMPILERS[extension];
249249

250250
Object.defineProperty(nodeRequire.extensions, extension, {
251251
enumerable: true,
252252
writable: false,
253253
value: function(module, filePath) {
254-
var code = compileFileAtPath(compiler, filePath, extension);
254+
const code = compileFileAtPath(compiler, filePath, extension);
255255
return module._compile(code, filePath);
256256
}
257257
});

src/delegated-listener.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const EventKit = require('event-kit');
22

33
module.exports = function listen(element, eventName, selector, handler) {
4-
var innerHandler = function(event) {
4+
const innerHandler = function(event) {
55
if (selector) {
66
var currentTarget = event.target;
77
while (currentTarget) {

src/history-manager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class HistoryManager {
8989
}
9090

9191
getProject(paths) {
92-
for (var i = 0; i < this.projects.length; i++) {
92+
for (let i = 0; i < this.projects.length; i++) {
9393
if (arrayEquivalent(paths, this.projects[i].paths)) {
9494
return this.projects[i];
9595
}
@@ -121,7 +121,7 @@ class HistoryManager {
121121

122122
function arrayEquivalent(a, b) {
123123
if (a.length !== b.length) return false;
124-
for (var i = 0; i < a.length; i++) {
124+
for (let i = 0; i < a.length; i++) {
125125
if (a[i] !== b[i]) return false;
126126
}
127127
return true;

src/module-cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function loadDependencies(modulePath, rootPath, rootMetadata, moduleCache) {
7373

7474
const childMetadata = JSON.parse(fs.readFileSync(childMetadataPath));
7575
if (childMetadata && childMetadata.version) {
76-
var mainPath;
76+
let mainPath;
7777
try {
7878
mainPath = require.resolve(childPath);
7979
} catch (error) {

src/package-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ module.exports = class PackageManager {
531531
) => {
532532
for (const packageName of packageNames) {
533533
if (!disabledPackageNames.has(packageName)) {
534-
var pack = this.getLoadedPackage(packageName);
534+
const pack = this.getLoadedPackage(packageName);
535535
if (pack != null) {
536536
action(pack);
537537
}

src/package.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ module.exports = class Package {
11731173
return nativeModulePaths;
11741174
}
11751175

1176-
var traversePath = nodeModulesPath => {
1176+
const traversePath = nodeModulesPath => {
11771177
try {
11781178
for (let modulePath of fs.listSync(nodeModulesPath)) {
11791179
const modulePathNodeFiles = this.getModulePathNodeFiles(modulePath);

src/state-store.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = class StateStore {
4343
this.dbPromise.then(db => {
4444
if (db == null) return resolve();
4545

46-
var request = db
46+
const request = db
4747
.transaction(['states'], 'readwrite')
4848
.objectStore('states')
4949
.put({ value: value, storedAt: new Date().toString() }, key);
@@ -59,7 +59,7 @@ module.exports = class StateStore {
5959
if (!db) return;
6060

6161
return new Promise((resolve, reject) => {
62-
var request = db
62+
const request = db
6363
.transaction(['states'])
6464
.objectStore('states')
6565
.get(key);
@@ -83,7 +83,7 @@ module.exports = class StateStore {
8383
this.dbPromise.then(db => {
8484
if (db == null) return resolve();
8585

86-
var request = db
86+
const request = db
8787
.transaction(['states'], 'readwrite')
8888
.objectStore('states')
8989
.delete(key);
@@ -99,7 +99,7 @@ module.exports = class StateStore {
9999
if (!db) return;
100100

101101
return new Promise((resolve, reject) => {
102-
var request = db
102+
const request = db
103103
.transaction(['states'], 'readwrite')
104104
.objectStore('states')
105105
.clear();
@@ -115,7 +115,7 @@ module.exports = class StateStore {
115115
if (!db) return;
116116

117117
return new Promise((resolve, reject) => {
118-
var request = db
118+
const request = db
119119
.transaction(['states'])
120120
.objectStore('states')
121121
.count();

src/style-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ module.exports = class StyleManager {
254254
}
255255

256256
buildStylesElement() {
257-
var stylesElement = new StylesElement();
257+
const stylesElement = new StylesElement();
258258
stylesElement.initialize(this);
259259
return stylesElement;
260260
}

0 commit comments

Comments
 (0)