Use let instead of var in script.js

This commit is contained in:
Christoph Diehl 2017-05-02 17:01:32 +03:00
parent 2ed3e76ab2
commit b55264b24f

View file

@ -7,9 +7,9 @@ utils.script = {
if (isNaN(numOptional)) { if (isNaN(numOptional)) {
numOptional = 0 numOptional = 0
} }
var arity = list.length - random.number(numOptional) let arity = list.length - random.number(numOptional)
var params = [] let params = []
for (var i = 0; i < arity; i++) { for (let i = 0; i < arity; i++) {
params.push(random.pick([list[i]])) params.push(random.pick([list[i]]))
} }
return '(' + params.join(', ') + ')' return '(' + params.join(', ') + ')'
@ -18,8 +18,8 @@ utils.script = {
if (!utils.common.getKeysFromHash(methodHash).length || !objectName) { if (!utils.common.getKeysFromHash(methodHash).length || !objectName) {
return '' return ''
} }
var methodName = random.key(methodHash) let methodName = random.key(methodHash)
var methodArgs = methodHash[methodName] let methodArgs = methodHash[methodName]
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm.. if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
return methodArgs() return methodArgs()
} }
@ -29,9 +29,9 @@ utils.script = {
if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) { if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
return '' return ''
} }
var attributeName = random.key(attributeHash) let attributeName = random.key(attributeHash)
var attributeValue = random.pick(attributeHash[attributeName]) let attributeValue = random.pick(attributeHash[attributeName])
var operator = ' = ' let operator = ' = '
/* /*
if (typeof(attributeValue) == "number" && Random.chance(8)) { if (typeof(attributeValue) == "number" && Random.chance(8)) {
operator = " " + Make.randomAssignmentOperator() + " "; operator = " " + Make.randomAssignmentOperator() + " ";
@ -43,17 +43,17 @@ utils.script = {
return objectName + '.' + attributeName + operator + attributeValue + ';' return objectName + '.' + attributeName + operator + attributeValue + ';'
}, },
makeConstraint: function (keys, values) { makeConstraint: function (keys, values) {
var o = {} let o = {}
var n = random.range(0, keys.length) let n = random.range(0, keys.length)
while (n--) { while (n--) {
o[random.pick(keys)] = random.pick(values) o[random.pick(keys)] = random.pick(values)
} }
return o return o
}, },
makeRandomOptions: function (baseObject) { makeRandomOptions: function (baseObject) {
var o = {} let o = {}
var unique = random.some(Object.keys(baseObject)) let unique = random.some(Object.keys(baseObject))
for (var i = 0; i < unique.length; i++) { for (let i = 0; i < unique.length; i++) {
o[unique[i]] = random.pick(baseObject[unique[i]]) o[unique[i]] = random.pick(baseObject[unique[i]])
} }
return JSON.stringify(o) return JSON.stringify(o)
@ -65,7 +65,7 @@ utils.script = {
return 'try { ' + s + ' } catch(e) { }' return 'try { ' + s + ' } catch(e) { }'
}, },
makeLoop: function (s, max) { makeLoop: function (s, max) {
return 'for (var i = 0; i < ' + (max || make.number.rangeNumber()) + '; i++) {' + s + '}' return 'for (let i = 0; i < ' + (max || make.number.rangeNumber()) + '; i++) {' + s + '}'
}, },
makeArray: function (type, arrayLength, cb) { makeArray: function (type, arrayLength, cb) {
if (type === null || type === undefined) { if (type === null || type === undefined) {
@ -73,7 +73,7 @@ utils.script = {
} }
switch (random.number(8)) { switch (random.number(8)) {
case 0: case 0:
var src = 'function() { var buffer = new ' + type + 'Array(' + arrayLength + ');' let src = 'function() { let buffer = new ' + type + 'Array(' + arrayLength + ');'
src += utils.script.makeLoop('buffer[i] = ' + cb() + ';', arrayLength) src += utils.script.makeLoop('buffer[i] = ' + cb() + ';', arrayLength)
src += 'return buffer;}()' src += 'return buffer;}()'
return src return src