Skip to content

Commit

Permalink
[js] eslint --fix a lot of vars into lets
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Oct 23, 2017
1 parent ce098e2 commit 8fe3f8e
Show file tree
Hide file tree
Showing 28 changed files with 705 additions and 705 deletions.
52 changes: 26 additions & 26 deletions src/vm/js/nqp-runtime/bignum.js
@@ -1,26 +1,26 @@
'use strict';
var bignum = require('bignum-browserify');
let bignum = require('bignum-browserify');

var sslBignum = require('bignum');
let sslBignum = require('bignum');

var core = require('./core.js');
let core = require('./core.js');

var hll = require('./hll.js');
let hll = require('./hll.js');

var op = {};
let op = {};
exports.op = op;
function intishBool(b) {
return b ? 1 : 0;
}

function makeNum(type, num) {
var instance = type._STable.REPR.allocate(type._STable);
let instance = type._STable.REPR.allocate(type._STable);
instance.$$setNum(num);
return instance;
}

function makeBI(type, num) {
var instance = type._STable.REPR.allocate(type._STable);
let instance = type._STable.REPR.allocate(type._STable);
instance.$$setBignum(num);
return instance;
}
Expand All @@ -45,9 +45,9 @@ op.base_I = function(n, base) {
return orig.toString(base).toUpperCase().replace(/^(-?)0+/, '$1');
} else if (1 < base && base <= 36) {
var orig = getBI(n);
var num = orig.abs();
var string = '';
var letters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let num = orig.abs();
let string = '';
let letters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

while (num.gt(0)) {
string = letters[num.mod(base).toNumber()] + string;
Expand Down Expand Up @@ -94,8 +94,8 @@ op.div_I = function(a, b, type) {
};

op.pow_I = function(a, b, numType, biType) {
var base = getBI(a);
var exponent = getBI(b);
let base = getBI(a);
let exponent = getBI(b);
if (exponent.lt(0)) {
return makeNum(numType, Math.pow(base.toNumber(), exponent.toNumber()));
} else {
Expand All @@ -115,11 +115,11 @@ op.mod_I = function(n, m, type) {
/* TODO - think if this can be optimized. */
/* We are doing this in complicated way because,
bignum returns the module with the sign equal to the dividend not the divisor. */
var a = getBI(n);
var b = getBI(m);
let a = getBI(n);
let b = getBI(m);
if ((a.lt(0) && b.gt(0)) || (a.gt(0) && b.lt(0))) {
var x = a.div(b).sub(1);
var ret = a.sub(b.mul(x));
let x = a.div(b).sub(1);
let ret = a.sub(b.mul(x));
return makeBI(type, (ret.eq(b) ? bignum(0) : ret));
}
return makeBI(type, a.mod(b));
Expand Down Expand Up @@ -170,7 +170,7 @@ op.isgt_I = function(a, b) {
};

op.cmp_I = function(a, b) {
var result = getBI(a).cmp(getBI(b));
let result = getBI(a).cmp(getBI(b));
return result == 0 ? 0 : (result < 0 ? -1 : 1);
};

Expand Down Expand Up @@ -203,8 +203,8 @@ op.bitneg_I = function(a, type) {
};

op.lcm_I = function(n, m, type) {
var a = getBI(n);
var b = getBI(m);
let a = getBI(n);
let b = getBI(m);
return makeBI(type, (a.abs().div(a.gcd(b)).mul(b.abs())));
};

Expand Down Expand Up @@ -234,21 +234,21 @@ op.bool_I = function(n) {
};

op.radix_I = function(currentHLL, radix, str, zpos, flags, type) {
var extracted = core.radixHelper(radix, str, zpos, flags);
let extracted = core.radixHelper(radix, str, zpos, flags);
if (extracted == null) {
return hll.slurpyArray(currentHLL, [makeBI(type, bignum(0)), makeBI(type, bignum(1)), -1]);
}

if (radix == 10 || radix == 16) {
var pow = bignum(radix).pow(extracted.power);
let pow = bignum(radix).pow(extracted.power);
return hll.slurpyArray(currentHLL, [makeBI(type, bignum(extracted.number, radix)), makeBI(type, pow), extracted.offset]);
} else {
var n = extracted.number;
var base = bignum(1);
var result = bignum(0);
let n = extracted.number;
let base = bignum(1);
let result = bignum(0);

for (var i = n.length - 1; i >= 0; i--) {
var digit = n.charCodeAt(i);
for (let i = n.length - 1; i >= 0; i--) {
let digit = n.charCodeAt(i);
if (digit >= 48 && digit <= 57) digit -= 48; // 0-9
else if (digit >= 97 && digit <= 122) digit = digit - 97 + 10; // a-z
else if (digit >= 65 && digit <= 90) digit = digit - 65 + 10; // A-Z
Expand Down
66 changes: 33 additions & 33 deletions src/vm/js/nqp-runtime/bootstrap.js
@@ -1,21 +1,21 @@
'use strict';
var SerializationContext = require('./serialization-context.js');
var reprs = require('./reprs.js');
let SerializationContext = require('./serialization-context.js');
let reprs = require('./reprs.js');

var Hash = require('./hash.js');
var STable = require('./sixmodel.js').STable;
let Hash = require('./hash.js');
let STable = require('./sixmodel.js').STable;

var repr = new reprs.KnowHOWREPR();
let repr = new reprs.KnowHOWREPR();

var CodeRef = require('./code-ref.js');
let CodeRef = require('./code-ref.js');

var constants = require('./constants.js');
let constants = require('./constants.js');

var BOOT = require('./BOOT.js');
let BOOT = require('./BOOT.js');

var Null = require('./null.js');
let Null = require('./null.js');

var core = new SerializationContext('__6MODEL_CORE__');
let core = new SerializationContext('__6MODEL_CORE__');
core.description = 'core SC';

function addToScWithSt(obj) {
Expand All @@ -27,17 +27,17 @@ function addToScWithSt(obj) {

/* Creates and installs the KnowHOWAttribute type. */
function createKnowHOWAttribute() {
var metaObj = KnowHowHOW._STable.REPR.allocate(KnowHowHOW._STable);
let metaObj = KnowHowHOW._STable.REPR.allocate(KnowHowHOW._STable);

var r = new reprs.KnowHOWAttribute();
var typeObj = r.typeObjectFor(metaObj);
let r = new reprs.KnowHOWAttribute();
let typeObj = r.typeObjectFor(metaObj);

var methods = {};
let methods = {};
methods.name = function(ctx, _NAMED, self) {
return self.__name;
};
methods['new'] = function(ctx, _NAMED, self) {
var attr = r.allocate(self._STable);
let attr = r.allocate(self._STable);
attr.__name = _NAMED.name.$$getStr();
attr.__type = _NAMED.type;
attr.__boxTarget = _NAMED.box_target ? _NAMED.box_target.$$getInt() : 0;
Expand All @@ -57,11 +57,11 @@ function createKnowHOWAttribute() {

/* Create our KnowHOW type object. Note we don't have a HOW just yet, so
* pass in null. */
var KnowHOW = repr.typeObjectFor(null);
let KnowHOW = repr.typeObjectFor(null);

addToScWithSt(KnowHOW);

var st = new STable(repr, null);
let st = new STable(repr, null);

var KnowHowHOW = repr.allocate(st);
KnowHowHOW.__name = 'KnowHOW';
Expand All @@ -76,7 +76,7 @@ KnowHowHOW._STable.methodCache = new Map();
KnowHowHOW._STable.modeFlags = constants.METHOD_CACHE_AUTHORITATIVE;

function wrapMethod(name, method) {
var codeRef = new CodeRef(name, undefined);
let codeRef = new CodeRef(name, undefined);
codeRef.$$call = method;
return codeRef;
}
Expand All @@ -86,7 +86,7 @@ function addKnowhowHowMethod(name, method) {
KnowHowHOW._STable.ObjConstructor.prototype[name] = method;
KnowHOW._STable.ObjConstructor.prototype[name] = method;

var wrapped = wrapMethod(name, method);
let wrapped = wrapMethod(name, method);
KnowHOW._STable.methodCache.set(name, wrapped);
KnowHowHOW._STable.methodCache.set(name, wrapped);
}
Expand All @@ -105,15 +105,15 @@ addKnowhowHowMethod('methods', function(ctx, _NAMED, self) {

addKnowhowHowMethod('new_type', function(ctx, _NAMED, self) {
/* We first create a new HOW instance. */
var HOW = self._STable.REPR.allocate(self._STable);
let HOW = self._STable.REPR.allocate(self._STable);

/* See if we have a representation name; if not default to P6opaque. */
var reprName = (_NAMED && _NAMED.repr) ? _NAMED.repr.$$getStr() : 'P6opaque';
let reprName = (_NAMED && _NAMED.repr) ? _NAMED.repr.$$getStr() : 'P6opaque';

/* Create a new type object of the desired REPR. (Note that we can't
* default to KnowHOWREPR here, since it doesn't know how to actually
* store attributes, it's just for bootstrapping knowhow's. */
var typeObject = (new reprs[reprName]).typeObjectFor(HOW);
let typeObject = (new reprs[reprName]).typeObjectFor(HOW);

/* See if we were given a name; put it into the meta-object if so. */
if (_NAMED && _NAMED.name) {
Expand Down Expand Up @@ -147,23 +147,23 @@ addKnowhowHowMethod('compose', function(ctx, _NAMED, self, typeObject) {

/* Use any attribute information to produce attribute protocol
* data. The protocol consists of an array... */
var reprInfo = [];
let reprInfo = [];

/* ...which contains an array per MRO entry... */
var typeInfo = [];
let typeInfo = [];
reprInfo.push(BOOT.createArray(typeInfo));

/* ...which in turn contains this type... */
typeInfo.push(typeObject);

/* ...then an array of hashes per attribute... */
var attrInfoList = [];
let attrInfoList = [];
typeInfo.push(BOOT.createArray(attrInfoList));

/* ...then an array of hashes per attribute... */
for (var i = 0; i < self.__attributes.length; i++) {
var attrInfo = new Hash();
var attr = self.__attributes[i];
for (let i = 0; i < self.__attributes.length; i++) {
let attrInfo = new Hash();
let attr = self.__attributes[i];
attrInfo.content.set('name', attr.__name);
attrInfo.content.set('type', attr.__type);
if (attr.__boxTarget) {
Expand All @@ -173,11 +173,11 @@ addKnowhowHowMethod('compose', function(ctx, _NAMED, self, typeObject) {
}

/* ...followed by a list of parents (none). */
var parentInfo = [];
let parentInfo = [];
typeInfo.push(BOOT.createArray(parentInfo));

/* All of this goes in a hash. */
var reprInfoHash = new Hash();
let reprInfoHash = new Hash();
reprInfoHash.content.set('attribute', BOOT.createArray(reprInfo));


Expand All @@ -191,18 +191,18 @@ addKnowhowHowMethod('compose', function(ctx, _NAMED, self, typeObject) {
module.exports.knowhow = KnowHOW;


var KnowHOWAttribute = createKnowHOWAttribute();
let KnowHOWAttribute = createKnowHOWAttribute();

module.exports.knowhowattr = KnowHOWAttribute;

/* KnowHOWAttribute */
addToScWithSt(KnowHOWAttribute);

function bootType(typeName, reprName) {
var metaObj = KnowHowHOW._STable.REPR.allocate(KnowHowHOW._STable);
let metaObj = KnowHowHOW._STable.REPR.allocate(KnowHowHOW._STable);
metaObj.__name = typeName;

var typeObj = (new reprs[reprName]).typeObjectFor(metaObj);
let typeObj = (new reprs[reprName]).typeObjectFor(metaObj);

core.rootObjects.push(metaObj);
metaObj._SC = core;
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/nqp-runtime/capture.js
@@ -1,4 +1,4 @@
var NQPObject = require('./nqp-object.js');
let NQPObject = require('./nqp-object.js');

class Capture extends NQPObject {
constructor(named, pos) {
Expand Down
12 changes: 6 additions & 6 deletions src/vm/js/nqp-runtime/cclass.js
@@ -1,6 +1,6 @@
'use strict';
var xregexp = require('xregexp');
var op = {};
let xregexp = require('xregexp');
let op = {};
exports.op = op;

function boolish(bool) {
Expand Down Expand Up @@ -65,10 +65,10 @@ op.iscclass = function(cclass, target, offset) {
};

op.findcclass = function(cclass, target, offset, count) {
var end = offset + count;
let end = offset + count;
end = target.length < end ? target.length : end;

for (var pos = offset; pos < end; pos++) {
for (let pos = offset; pos < end; pos++) {
if (iscclass(cclass, target, pos) > 0) {
return pos;
}
Expand All @@ -78,10 +78,10 @@ op.findcclass = function(cclass, target, offset, count) {
};

op.findnotcclass = function(cclass, target, offset, count) {
var end = offset + count;
let end = offset + count;
end = target.length < end ? target.length : end;

for (var pos = offset; pos < end; pos++) {
for (let pos = offset; pos < end; pos++) {
if (iscclass(cclass, target, pos) == 0) {
return pos;
}
Expand Down
8 changes: 4 additions & 4 deletions src/vm/js/nqp-runtime/code-ref-with-statevars.js
@@ -1,11 +1,11 @@
var CodeRef = require('./code-ref.js');
let CodeRef = require('./code-ref.js');
class CodeRefWithStateVars extends CodeRef {
freshBlock() {
return this.closureTemplate();
}

$$clone() {
var clone = new CodeRefWithStateVars(this.name, undefined);
let clone = new CodeRefWithStateVars(this.name, undefined);
clone.$$call = this.freshBlock();
clone.codeObj = this.codeObj;
clone.staticCode = this.staticCode;
Expand All @@ -20,7 +20,7 @@ class CodeRefWithStateVars extends CodeRef {
}

closureCtx(outerCtx) {
var closure = new CodeRefWithStateVars(this.name, this.cuid);
let closure = new CodeRefWithStateVars(this.name, this.cuid);
closure.codeObj = this.codeObj;
closure.$$call = this.freshBlock();
closure.closureTemplate = this.closureTemplate;
Expand All @@ -33,7 +33,7 @@ class CodeRefWithStateVars extends CodeRef {

captureAndClosureCtx(outerCtx) {
this.capture(this.freshBlock());
var closure = this.closureCtx(outerCtx);
let closure = this.closureCtx(outerCtx);

if (outerCtx !== null) {
this.outerCtx = outerCtx;
Expand Down

0 comments on commit 8fe3f8e

Please sign in to comment.