Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 2733e5c

Browse files
Convert var to const or let (#290)
PR-URL: #290
1 parent a0f9cc4 commit 2733e5c

File tree

8 files changed

+211
-211
lines changed

8 files changed

+211
-211
lines changed

src.ts/agent/debuglet.ts

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ import { StatusMessage } from '../status-message';
3535
import * as SourceMapper from './sourcemapper';
3636
const pjson = require('../../package.json');
3737

38-
var assert = require('assert');
38+
import * as assert from 'assert';
3939

40-
var ALLOW_EXPRESSIONS_MESSAGE = 'Expressions and conditions are not allowed' +
40+
const ALLOW_EXPRESSIONS_MESSAGE = 'Expressions and conditions are not allowed' +
4141
' by default. Please set the allowExpressions configuration option to true.' +
4242
' See the debug agent documentation at https://goo.gl/ShSm6r.';
43-
var NODE_VERSION_MESSAGE = 'Node.js version not supported. Node.js 5.2.0 and ' +
43+
const NODE_VERSION_MESSAGE = 'Node.js version not supported. Node.js 5.2.0 and ' +
4444
' versions older than 0.12 are not supported.';
45-
var BREAKPOINT_ACTION_MESSAGE = 'The only currently supported breakpoint actions' +
45+
const BREAKPOINT_ACTION_MESSAGE = 'The only currently supported breakpoint actions' +
4646
' are CAPTURE and LOG.';
4747

4848
/**
@@ -52,12 +52,12 @@ var BREAKPOINT_ACTION_MESSAGE = 'The only currently supported breakpoint actions
5252
* @param {Breakpoint} breakpoint The breakpoint to format.
5353
* @return {string} A formatted string.
5454
*/
55-
var formatBreakpoint = function(msg, breakpoint) {
56-
var text = msg + util.format('breakpoint id: %s,\n\tlocation: %s',
55+
const formatBreakpoint = function(msg, breakpoint) {
56+
let text = msg + util.format('breakpoint id: %s,\n\tlocation: %s',
5757
breakpoint.id, util.inspect(breakpoint.location));
5858
if (breakpoint.createdTime) {
59-
var unixTime = parseInt(breakpoint.createdTime.seconds, 10);
60-
var date = new Date(unixTime * 1000); // to milliseconds.
59+
const unixTime = parseInt(breakpoint.createdTime.seconds, 10);
60+
const date = new Date(unixTime * 1000); // to milliseconds.
6161
text += '\n\tcreatedTime: ' + date.toString();
6262
}
6363
if (breakpoint.condition) {
@@ -76,7 +76,7 @@ var formatBreakpoint = function(msg, breakpoint) {
7676
* @param {Object.<string, Breakpoint>} breakpoints A map of breakpoints.
7777
* @return {string} A formatted string.
7878
*/
79-
var formatBreakpoints = function(msg, breakpoints) {
79+
const formatBreakpoints = function(msg, breakpoints) {
8080
return msg + Object.keys(breakpoints).map(function (b) {
8181
return formatBreakpoint('', breakpoints[b]);
8282
}).join('\n');
@@ -151,7 +151,7 @@ export class Debuglet extends EventEmitter {
151151
}
152152

153153
static normalizeConfig_(config) {
154-
var envConfig = {
154+
const envConfig = {
155155
logLevel: process.env.GCLOUD_DEBUG_LOGLEVEL,
156156
serviceContext: {
157157
service: process.env.GAE_SERVICE || process.env.GAE_MODULE_NAME,
@@ -180,14 +180,14 @@ export class Debuglet extends EventEmitter {
180180
* @private
181181
*/
182182
start() {
183-
var that = this;
183+
const that = this;
184184
fs.stat(path.join(that.config_.workingDirectory, 'package.json'), function(err) {
185185
if (err && err.code === 'ENOENT') {
186186
that.logger_.error('No package.json located in working directory.');
187187
that.emit('initError', new Error('No package.json found.'));
188188
return;
189189
}
190-
var id;
190+
let id;
191191
if (process.env.GAE_MINOR_VERSION) {
192192
id = 'GAE-' + process.env.GAE_MINOR_VERSION;
193193
}
@@ -199,8 +199,8 @@ export class Debuglet extends EventEmitter {
199199
return;
200200
}
201201

202-
var jsStats = fileStats.selectStats(/.js$/);
203-
var mapFiles = fileStats.selectFiles(/.map$/, process.cwd());
202+
const jsStats = fileStats.selectStats(/.js$/);
203+
const mapFiles = fileStats.selectFiles(/.map$/, process.cwd());
204204
SourceMapper.create(mapFiles, function(err, mapper) {
205205
if (err) {
206206
that.logger_.error('Error processing the sourcemaps.', err);
@@ -257,15 +257,15 @@ export class Debuglet extends EventEmitter {
257257
* @private
258258
*/
259259
static createDebuggee(projectId, uid, serviceContext, sourceContext, description,
260-
errorMessage, onGCP) {
261-
var cwd = process.cwd();
262-
var mainScript = path.relative(cwd, process.argv[1]);
260+
errorMessage, onGCP) {
261+
const cwd = process.cwd();
262+
const mainScript = path.relative(cwd, process.argv[1]);
263263

264-
var version = 'google.com/node-' + (onGCP ? 'gcp' : 'standalone') + '/v' +
264+
const version = 'google.com/node-' + (onGCP ? 'gcp' : 'standalone') + '/v' +
265265
pjson.version;
266-
var desc = process.title + ' ' + mainScript;
266+
let desc = process.title + ' ' + mainScript;
267267

268-
var labels: any = {
268+
const labels: any = {
269269
'main script': mainScript,
270270
'process.title': process.title,
271271
'node version': process.versions.node,
@@ -303,15 +303,15 @@ export class Debuglet extends EventEmitter {
303303
desc += ' description:' + description;
304304
}
305305

306-
var uniquifier = Debuglet._createUniquifier(desc, version, uid, sourceContext,
306+
const uniquifier = Debuglet._createUniquifier(desc, version, uid, sourceContext,
307307
labels);
308308

309-
var statusMessage =
309+
const statusMessage =
310310
errorMessage ?
311311
new StatusMessage(StatusMessage.UNSPECIFIED, errorMessage, true) :
312312
null;
313313

314-
var properties = {
314+
const properties = {
315315
project: projectId,
316316
uniquifier: uniquifier,
317317
description: desc,
@@ -327,7 +327,7 @@ export class Debuglet extends EventEmitter {
327327
* @private
328328
*/
329329
getProjectId_(callback) {
330-
var that = this;
330+
const that = this;
331331

332332
// We need to figure out whether we are running on GCP. We can use our ability
333333
// to access the metadata service as a test for that.
@@ -337,11 +337,11 @@ export class Debuglet extends EventEmitter {
337337
metadata.project(
338338
'project-id', function(err, _, metadataProject) {
339339
// We should get an error if we are not on GCP.
340-
var onGCP = !err;
340+
const onGCP = !err;
341341

342342
// We perfer to use the locally available projectId as that is least
343343
// surprising to users.
344-
var project = that.debug_.options.projectId ||
344+
const project = that.debug_.options.projectId ||
345345
process.env.GCLOUD_PROJECT || metadataProject;
346346

347347
// We if don't have a projectId by now, we fail with an error.
@@ -354,7 +354,7 @@ export class Debuglet extends EventEmitter {
354354

355355
getSourceContext_(callback) {
356356
fs.readFile('source-context.json', 'utf8', function(err: any, data) {
357-
var sourceContext;
357+
let sourceContext;
358358
if (!err) {
359359
try {
360360
sourceContext = JSON.parse(data);
@@ -373,7 +373,7 @@ export class Debuglet extends EventEmitter {
373373
* @private
374374
*/
375375
scheduleRegistration_(seconds) {
376-
var that = this;
376+
const that = this;
377377

378378
function onError(err) {
379379
that.logger_.error('Failed to re-register debuggee ' +
@@ -416,7 +416,7 @@ export class Debuglet extends EventEmitter {
416416
* @private
417417
*/
418418
scheduleBreakpointFetch_(seconds) {
419-
var that = this;
419+
const that = this;
420420

421421
that.fetcherActive_ = true;
422422
setTimeout(function() {
@@ -456,8 +456,8 @@ export class Debuglet extends EventEmitter {
456456
that.scheduleBreakpointFetch_(0/*immediately*/);
457457
return;
458458
}
459-
var bps = (body.breakpoints || []).filter(function(bp) {
460-
var action = bp.action || 'CAPTURE';
459+
const bps = (body.breakpoints || []).filter(function(bp) {
460+
const action = bp.action || 'CAPTURE';
461461
if (action !== 'CAPTURE' && action !== 'LOG') {
462462
that.logger_.warn('Found breakpoint with invalid action:', action);
463463
bp.status = new StatusMessage(StatusMessage.UNSPECIFIED,
@@ -485,8 +485,8 @@ export class Debuglet extends EventEmitter {
485485
* @private
486486
*/
487487
updateActiveBreakpoints_(breakpoints) {
488-
var that = this;
489-
var updatedBreakpointMap = this.convertBreakpointListToMap_(breakpoints);
488+
const that = this;
489+
const updatedBreakpointMap = this.convertBreakpointListToMap_(breakpoints);
490490

491491
if (breakpoints.length) {
492492
that.logger_.info(formatBreakpoints('Server breakpoints: ',
@@ -528,7 +528,7 @@ export class Debuglet extends EventEmitter {
528528
* @private
529529
*/
530530
convertBreakpointListToMap_(breakpointList) {
531-
var map = {};
531+
const map = {};
532532
breakpointList.forEach(function(breakpoint) {
533533
map[breakpoint.id] = breakpoint;
534534
});
@@ -553,7 +553,7 @@ export class Debuglet extends EventEmitter {
553553
* @private
554554
*/
555555
addBreakpoint_(breakpoint, cb) {
556-
var that = this;
556+
const that = this;
557557

558558
if (!that.config_.allowExpressions &&
559559
(breakpoint.condition || breakpoint.expressions)) {
@@ -565,7 +565,7 @@ export class Debuglet extends EventEmitter {
565565
}
566566

567567
if (semver.satisfies(process.version, '5.2 || <4')) {
568-
var message = NODE_VERSION_MESSAGE;
568+
const message = NODE_VERSION_MESSAGE;
569569
that.logger_.error(message);
570570
breakpoint.status = new StatusMessage(StatusMessage.UNSPECIFIED,
571571
message, true);
@@ -612,7 +612,7 @@ export class Debuglet extends EventEmitter {
612612
* @private
613613
*/
614614
completeBreakpoint_(breakpoint) {
615-
var that = this;
615+
const that = this;
616616

617617
that.logger_.info('\tupdating breakpoint data on server', breakpoint.id);
618618
that.debugletApi_.updateBreakpoint(
@@ -632,7 +632,7 @@ export class Debuglet extends EventEmitter {
632632
* @private
633633
*/
634634
rejectBreakpoint_(breakpoint) {
635-
var that = this;
635+
const that = this;
636636

637637
that.debugletApi_.updateBreakpoint(
638638
that.debuggee_, breakpoint, function(err /*, body*/) {
@@ -651,12 +651,12 @@ export class Debuglet extends EventEmitter {
651651
* @private
652652
*/
653653
scheduleBreakpointExpiry_(breakpoint) {
654-
var that = this;
654+
const that = this;
655655

656-
var now = Date.now() / 1000;
657-
var createdTime = breakpoint.createdTime ?
656+
const now = Date.now() / 1000;
657+
const createdTime = breakpoint.createdTime ?
658658
parseInt(breakpoint.createdTime.seconds) : now;
659-
var expiryTime = createdTime + that.config_.breakpointExpirationSec;
659+
const expiryTime = createdTime + that.config_.breakpointExpirationSec;
660660

661661
setTimeout(function() {
662662
that.logger_.info('Expiring breakpoint ' + breakpoint.id);
@@ -690,8 +690,8 @@ export class Debuglet extends EventEmitter {
690690
* in B.
691691
*/
692692
static mapSubtract(A, B) {
693-
var removed = [];
694-
for (var key in A) {
693+
const removed = [];
694+
for (let key in A) {
695695
if (!B[key]) {
696696
removed.push(A[key]);
697697
}
@@ -705,16 +705,16 @@ export class Debuglet extends EventEmitter {
705705
* are given than placeholders extra expressions are dropped.
706706
*/
707707
static format(base, exprs) {
708-
var tokens = Debuglet._tokenize(base, exprs.length);
709-
for (var i = 0; i < tokens.length; i++) {
708+
const tokens = Debuglet._tokenize(base, exprs.length);
709+
for (let i = 0; i < tokens.length; i++) {
710710
if (!tokens[i].v) {
711711
continue;
712712
}
713713
if (tokens[i].v === '$$') {
714714
tokens[i] = '$';
715715
continue;
716716
}
717-
for (var j = 0; j < exprs.length; j++) {
717+
for (let j = 0; j < exprs.length; j++) {
718718
if (tokens[i].v === '$' + j) {
719719
tokens[i] = exprs[j];
720720
break;
@@ -725,10 +725,10 @@ export class Debuglet extends EventEmitter {
725725
}
726726

727727
static _tokenize(base, exprLength) {
728-
var acc = Debuglet._delimit(base, '$$');
729-
for (var i = exprLength - 1; i >= 0; i--) {
730-
var newAcc = [];
731-
for (var j = 0; j < acc.length; j++) {
728+
let acc = Debuglet._delimit(base, '$$');
729+
for (let i = exprLength - 1; i >= 0; i--) {
730+
const newAcc = [];
731+
for (let j = 0; j < acc.length; j++) {
732732
if (acc[j].v) {
733733
newAcc.push(acc[j]);
734734
} else {
@@ -741,18 +741,18 @@ export class Debuglet extends EventEmitter {
741741
}
742742

743743
static _delimit(source, delim) {
744-
var pieces = source.split(delim);
745-
var dest = [];
744+
const pieces = source.split(delim);
745+
const dest = [];
746746
dest.push(pieces[0]);
747-
for (var i = 1; i < pieces.length; i++) {
747+
for (let i = 1; i < pieces.length; i++) {
748748
dest.push({ v: delim }, pieces[i]);
749749
}
750750
return dest;
751751
}
752752

753753
static _createUniquifier(desc, version, uid, sourceContext,
754754
labels) {
755-
var uniquifier = desc + version + uid + JSON.stringify(sourceContext) +
755+
const uniquifier = desc + version + uid + JSON.stringify(sourceContext) +
756756
JSON.stringify(labels);
757757
return crypto.createHash('sha1').update(uniquifier).digest('hex');
758758
}

0 commit comments

Comments
 (0)