Skip to content

Commit f924bbb

Browse files
committed
Refactored lib code to let/const
- this was supported from Node v6 and we support Node v10 so there shouldn't be a problem there
1 parent a235752 commit f924bbb

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

lib/sqlite3-binding.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var binary = require('@mapbox/node-pre-gyp');
2-
var path = require('path');
3-
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
4-
var binding = require(binding_path);
1+
const binary = require('@mapbox/node-pre-gyp');
2+
const path = require('path');
3+
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
4+
const binding = require(binding_path);
55
module.exports = exports = binding;

lib/sqlite3.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
var path = require('path');
2-
var sqlite3 = require('./sqlite3-binding.js');
3-
var EventEmitter = require('events').EventEmitter;
1+
const path = require('path');
2+
const sqlite3 = require('./sqlite3-binding.js');
3+
const EventEmitter = require('events').EventEmitter;
44
module.exports = exports = sqlite3;
55

66
function normalizeMethod (fn) {
77
return function (sql) {
8-
var errBack;
9-
var args = Array.prototype.slice.call(arguments, 1);
8+
let errBack;
9+
const args = Array.prototype.slice.call(arguments, 1);
10+
1011
if (typeof args[args.length - 1] === 'function') {
11-
var callback = args[args.length - 1];
12+
const callback = args[args.length - 1];
1213
errBack = function(err) {
1314
if (err) {
1415
callback(err);
1516
}
1617
};
1718
}
18-
var statement = new Statement(this, sql, errBack);
19+
const statement = new Statement(this, sql, errBack);
1920
return fn.call(this, statement, args);
2021
};
2122
}
2223

2324
function inherits(target, source) {
24-
for (var k in source.prototype)
25+
for (const k in source.prototype)
2526
target.prototype[k] = source.prototype[k];
2627
}
2728

@@ -32,18 +33,18 @@ sqlite3.cached = {
3233
return new Database(file, a, b);
3334
}
3435

35-
var db;
36+
let db;
3637
file = path.resolve(file);
37-
function cb() { callback.call(db, null); }
3838

3939
if (!sqlite3.cached.objects[file]) {
4040
db = sqlite3.cached.objects[file] = new Database(file, a, b);
4141
}
4242
else {
4343
// Make sure the callback is called.
4444
db = sqlite3.cached.objects[file];
45-
var callback = (typeof a === 'number') ? b : a;
45+
const callback = (typeof a === 'number') ? b : a;
4646
if (typeof callback === 'function') {
47+
function cb() { callback.call(db, null); }
4748
if (db.open) process.nextTick(cb);
4849
else db.once('open', cb);
4950
}
@@ -55,9 +56,9 @@ sqlite3.cached = {
5556
};
5657

5758

58-
var Database = sqlite3.Database;
59-
var Statement = sqlite3.Statement;
60-
var Backup = sqlite3.Backup;
59+
const Database = sqlite3.Database;
60+
const Statement = sqlite3.Statement;
61+
const Backup = sqlite3.Backup;
6162

6263
inherits(Database, EventEmitter);
6364
inherits(Statement, EventEmitter);
@@ -102,7 +103,7 @@ Database.prototype.map = normalizeMethod(function(statement, params) {
102103
// Database#backup(filename, [callback])
103104
// Database#backup(filename, destName, sourceName, filenameIsDest, [callback])
104105
Database.prototype.backup = function() {
105-
var backup;
106+
let backup;
106107
if (arguments.length <= 2) {
107108
// By default, we write the main database out to the main database of the named file.
108109
// This is the most likely use of the backup api.
@@ -117,22 +118,23 @@ Database.prototype.backup = function() {
117118
};
118119

119120
Statement.prototype.map = function() {
120-
var params = Array.prototype.slice.call(arguments);
121-
var callback = params.pop();
121+
const params = Array.prototype.slice.call(arguments);
122+
const callback = params.pop();
122123
params.push(function(err, rows) {
123124
if (err) return callback(err);
124-
var result = {};
125+
const result = {};
125126
if (rows.length) {
126-
var keys = Object.keys(rows[0]), key = keys[0];
127+
const keys = Object.keys(rows[0]);
128+
const key = keys[0];
127129
if (keys.length > 2) {
128130
// Value is an object
129-
for (var i = 0; i < rows.length; i++) {
131+
for (let i = 0; i < rows.length; i++) {
130132
result[rows[i][key]] = rows[i];
131133
}
132134
} else {
133-
var value = keys[1];
135+
const value = keys[1];
134136
// Value is a plain value
135-
for (i = 0; i < rows.length; i++) {
137+
for (let i = 0; i < rows.length; i++) {
136138
result[rows[i][key]] = rows[i][value];
137139
}
138140
}
@@ -142,28 +144,28 @@ Statement.prototype.map = function() {
142144
return this.all.apply(this, params);
143145
};
144146

145-
var isVerbose = false;
147+
let isVerbose = false;
146148

147-
var supportedEvents = [ 'trace', 'profile', 'insert', 'update', 'delete' ];
149+
const supportedEvents = [ 'trace', 'profile', 'insert', 'update', 'delete' ];
148150

149151
Database.prototype.addListener = Database.prototype.on = function(type) {
150-
var val = EventEmitter.prototype.addListener.apply(this, arguments);
152+
const val = EventEmitter.prototype.addListener.apply(this, arguments);
151153
if (supportedEvents.indexOf(type) >= 0) {
152154
this.configure(type, true);
153155
}
154156
return val;
155157
};
156158

157159
Database.prototype.removeListener = function(type) {
158-
var val = EventEmitter.prototype.removeListener.apply(this, arguments);
160+
const val = EventEmitter.prototype.removeListener.apply(this, arguments);
159161
if (supportedEvents.indexOf(type) >= 0 && !this._events[type]) {
160162
this.configure(type, false);
161163
}
162164
return val;
163165
};
164166

165167
Database.prototype.removeAllListeners = function(type) {
166-
var val = EventEmitter.prototype.removeAllListeners.apply(this, arguments);
168+
const val = EventEmitter.prototype.removeAllListeners.apply(this, arguments);
167169
if (supportedEvents.indexOf(type) >= 0) {
168170
this.configure(type, false);
169171
}
@@ -173,7 +175,7 @@ Database.prototype.removeAllListeners = function(type) {
173175
// Save the stack trace over EIO callbacks.
174176
sqlite3.verbose = function() {
175177
if (!isVerbose) {
176-
var trace = require('./trace');
178+
const trace = require('./trace');
177179
[
178180
'prepare',
179181
'get',

lib/trace.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Inspired by https://github.com/tlrobinson/long-stack-traces
2-
var util = require('util');
2+
const util = require('util');
33

44
function extendTrace(object, property, pos) {
5-
var old = object[property];
5+
const old = object[property];
66
object[property] = function() {
7-
var error = new Error();
8-
var name = object.constructor.name + '#' + property + '(' +
7+
const error = new Error();
8+
const name = object.constructor.name + '#' + property + '(' +
99
Array.prototype.slice.call(arguments).map(function(el) {
1010
return util.inspect(el, false, 0);
1111
}).join(', ') + ')';
1212

1313
if (typeof pos === 'undefined') pos = -1;
1414
if (pos < 0) pos += arguments.length;
15-
var cb = arguments[pos];
15+
const cb = arguments[pos];
1616
if (typeof arguments[pos] === 'function') {
1717
arguments[pos] = function replacement() {
18-
var err = arguments[0];
18+
const err = arguments[0];
1919
if (err && err.stack && !err.__augmented) {
2020
err.stack = filter(err).join('\n');
2121
err.stack += '\n--> in ' + name;

0 commit comments

Comments
 (0)