Replaced var with let and const in PrettyPrinter, DiffBuilder, and friends

This commit is contained in:
Steve Gravrock
2022-05-12 17:15:50 -07:00
parent bb4d18f959
commit 2fd76c954c
5 changed files with 146 additions and 198 deletions

View File

@@ -4926,11 +4926,12 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
getJasmineRequireObj().DiffBuilder = function(j$) { getJasmineRequireObj().DiffBuilder = function(j$) {
return function DiffBuilder(config) { return function DiffBuilder(config) {
var prettyPrinter = (config || {}).prettyPrinter || j$.makePrettyPrinter(), const prettyPrinter =
mismatches = new j$.MismatchTree(), (config || {}).prettyPrinter || j$.makePrettyPrinter();
path = new j$.ObjectPath(), const mismatches = new j$.MismatchTree();
actualRoot = undefined, let path = new j$.ObjectPath();
expectedRoot = undefined; let actualRoot = undefined;
let expectedRoot = undefined;
return { return {
setRoots: function(actual, expected) { setRoots: function(actual, expected) {
@@ -4943,29 +4944,24 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
}, },
getMessage: function() { getMessage: function() {
var messages = []; const messages = [];
mismatches.traverse(function(path, isLeaf, formatter) { mismatches.traverse(function(path, isLeaf, formatter) {
var actualCustom, const { actual, expected } = dereferencePath(
expectedCustom, path,
useCustom, actualRoot,
derefResult = dereferencePath( expectedRoot,
path, prettyPrinter
actualRoot, );
expectedRoot,
prettyPrinter
),
actual = derefResult.actual,
expected = derefResult.expected;
if (formatter) { if (formatter) {
messages.push(formatter(actual, expected, path, prettyPrinter)); messages.push(formatter(actual, expected, path, prettyPrinter));
return true; return true;
} }
actualCustom = prettyPrinter.customFormat_(actual); const actualCustom = prettyPrinter.customFormat_(actual);
expectedCustom = prettyPrinter.customFormat_(expected); const expectedCustom = prettyPrinter.customFormat_(expected);
useCustom = !( const useCustom = !(
j$.util.isUndefined(actualCustom) && j$.util.isUndefined(actualCustom) &&
j$.util.isUndefined(expectedCustom) j$.util.isUndefined(expectedCustom)
); );
@@ -4990,7 +4986,7 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
}, },
withPath: function(pathComponent, block) { withPath: function(pathComponent, block) {
var oldPath = path; const oldPath = path;
path = path.add(pathComponent); path = path.add(pathComponent);
block(); block();
path = oldPath; path = oldPath;
@@ -5024,18 +5020,17 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
j$.isAsymmetricEqualityTester_(expected) && j$.isAsymmetricEqualityTester_(expected) &&
j$.isFunction_(expected.valuesForDiff_) j$.isFunction_(expected.valuesForDiff_)
) { ) {
var asymmetricResult = expected.valuesForDiff_(actual, pp); const asymmetricResult = expected.valuesForDiff_(actual, pp);
expected = asymmetricResult.self; expected = asymmetricResult.self;
actual = asymmetricResult.other; actual = asymmetricResult.other;
} }
} }
var i;
handleAsymmetricExpected(); handleAsymmetricExpected();
for (i = 0; i < objectPath.components.length; i++) { for (const pc of objectPath.components) {
actual = actual[objectPath.components[i]]; actual = actual[pc];
expected = expected[objectPath.components[i]]; expected = expected[pc];
handleAsymmetricExpected(); handleAsymmetricExpected();
} }
@@ -5748,15 +5743,13 @@ getJasmineRequireObj().MismatchTree = function(j$) {
} }
MismatchTree.prototype.add = function(path, formatter) { MismatchTree.prototype.add = function(path, formatter) {
var key, child;
if (path.depth() === 0) { if (path.depth() === 0) {
this.formatter = formatter; this.formatter = formatter;
this.isMismatch = true; this.isMismatch = true;
} else { } else {
key = path.components[0]; const key = path.components[0];
path = path.shift(); path = path.shift();
child = this.child(key); let child = this.child(key);
if (!child) { if (!child) {
child = new MismatchTree(this.path.add(key)); child = new MismatchTree(this.path.add(key));
@@ -5768,27 +5761,22 @@ getJasmineRequireObj().MismatchTree = function(j$) {
}; };
MismatchTree.prototype.traverse = function(visit) { MismatchTree.prototype.traverse = function(visit) {
var i, const hasChildren = this.children.length > 0;
hasChildren = this.children.length > 0;
if (this.isMismatch || hasChildren) { if (this.isMismatch || hasChildren) {
if (visit(this.path, !hasChildren, this.formatter)) { if (visit(this.path, !hasChildren, this.formatter)) {
for (i = 0; i < this.children.length; i++) { for (const child of this.children) {
this.children[i].traverse(visit); child.traverse(visit);
} }
} }
} }
}; };
MismatchTree.prototype.child = function(key) { MismatchTree.prototype.child = function(key) {
var i, pathEls; return this.children.find(child => {
const pathEls = child.path.components;
for (i = 0; i < this.children.length; i++) { return pathEls[pathEls.length - 1] === key;
pathEls = this.children[i].path.components; });
if (pathEls[pathEls.length - 1] === key) {
return this.children[i];
}
}
}; };
return MismatchTree; return MismatchTree;
@@ -5835,7 +5823,7 @@ getJasmineRequireObj().ObjectPath = function(j$) {
ObjectPath.prototype.toString = function() { ObjectPath.prototype.toString = function() {
if (this.components.length) { if (this.components.length) {
return '$' + map(this.components, formatPropertyAccess).join(''); return '$' + this.components.map(formatPropertyAccess).join('');
} else { } else {
return ''; return '';
} }
@@ -5865,14 +5853,6 @@ getJasmineRequireObj().ObjectPath = function(j$) {
return "['" + prop + "']"; return "['" + prop + "']";
} }
function map(array, fn) {
var results = [];
for (var i = 0; i < array.length; i++) {
results.push(fn(array[i]));
}
return results;
}
function isValidIdentifier(string) { function isValidIdentifier(string) {
return /^[A-Za-z\$_][A-Za-z0-9\$_]*$/.test(string); return /^[A-Za-z\$_][A-Za-z0-9\$_]*$/.test(string);
} }
@@ -7568,7 +7548,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
SinglePrettyPrintRun.prototype.format = function(value) { SinglePrettyPrintRun.prototype.format = function(value) {
this.ppNestLevel_++; this.ppNestLevel_++;
try { try {
var customFormatResult = this.applyCustomFormatters_(value); const customFormatResult = this.applyCustomFormatters_(value);
if (customFormatResult) { if (customFormatResult) {
this.emitScalar(customFormatResult); this.emitScalar(customFormatResult);
@@ -7648,10 +7628,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) { SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) {
var objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj)); const objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj));
var length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
for (var i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
fn(objKeys[i]); fn(objKeys[i]);
} }
@@ -7671,9 +7651,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
this.append('Array'); this.append('Array');
return; return;
} }
var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
const length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
this.append('[ '); this.append('[ ');
for (var i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
if (i > 0) { if (i > 0) {
this.append(', '); this.append(', ');
} }
@@ -7683,19 +7665,18 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
this.append(', ...'); this.append(', ...');
} }
var self = this; let first = array.length === 0;
var first = array.length === 0; const wasTruncated = this.iterateObject(array, property => {
var truncated = this.iterateObject(array, function(property) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
self.append(', '); this.append(', ');
} }
self.formatProperty(array, property); this.formatProperty(array, property);
}); });
if (truncated) { if (wasTruncated) {
this.append(', ...'); this.append(', ...');
} }
@@ -7708,8 +7689,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return; return;
} }
this.append('Set( '); this.append('Set( ');
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); const size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
var i = 0; let i = 0;
set.forEach(function(value, key) { set.forEach(function(value, key) {
if (i >= size) { if (i >= size) {
return; return;
@@ -7733,8 +7714,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return; return;
} }
this.append('Map( '); this.append('Map( ');
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); const size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
var i = 0; let i = 0;
map.forEach(function(value, key) { map.forEach(function(value, key) {
if (i >= size) { if (i >= size) {
return; return;
@@ -7753,10 +7734,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.emitObject = function(obj) { SinglePrettyPrintRun.prototype.emitObject = function(obj) {
var ctor = obj.constructor, const ctor = obj.constructor;
constructorName; const constructorName =
constructorName =
typeof ctor === 'function' && obj instanceof ctor typeof ctor === 'function' && obj instanceof ctor
? j$.fnNameFor(obj.constructor) ? j$.fnNameFor(obj.constructor)
: 'null'; : 'null';
@@ -7767,21 +7746,20 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return; return;
} }
var self = this;
this.append('({ '); this.append('({ ');
var first = true; let first = true;
var truncated = this.iterateObject(obj, function(property) { const wasTruncated = this.iterateObject(obj, property => {
if (first) { if (first) {
first = false; first = false;
} else { } else {
self.append(', '); this.append(', ');
} }
self.formatProperty(obj, property); this.formatProperty(obj, property);
}); });
if (truncated) { if (wasTruncated) {
this.append(', ...'); this.append(', ...');
} }
@@ -7789,13 +7767,13 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) { SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) {
var constructorName = j$.fnNameFor(arr.constructor), const constructorName = j$.fnNameFor(arr.constructor);
limitedArray = Array.prototype.slice.call( const limitedArray = Array.prototype.slice.call(
arr, arr,
0, 0,
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH j$.MAX_PRETTY_PRINT_ARRAY_LENGTH
), );
itemsString = Array.prototype.join.call(limitedArray, ', '); let itemsString = Array.prototype.join.call(limitedArray, ', ');
if (limitedArray.length !== arr.length) { if (limitedArray.length !== arr.length) {
itemsString += ', ...'; itemsString += ', ...';
@@ -7805,15 +7783,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.emitDomElement = function(el) { SinglePrettyPrintRun.prototype.emitDomElement = function(el) {
var tagName = el.tagName.toLowerCase(), const tagName = el.tagName.toLowerCase();
attrs = el.attributes, let out = '<' + tagName;
i,
len = attrs.length,
out = '<' + tagName,
attr;
for (i = 0; i < len; i++) { for (const attr of el.attributes) {
attr = attrs[i];
out += ' ' + attr.name; out += ' ' + attr.name;
if (attr.value !== '') { if (attr.value !== '') {
@@ -7848,7 +7821,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
value = Object.prototype.toString.call(value); value = Object.prototype.toString.call(value);
} }
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length); const result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
this.length += result.value.length; this.length += result.value.length;
this.stringParts.push(result.value); this.stringParts.push(result.value);
@@ -7876,10 +7849,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
MaxCharsReachedError.prototype = new Error(); MaxCharsReachedError.prototype = new Error();
function customFormat(value, customObjectFormatters) { function customFormat(value, customObjectFormatters) {
var i, result; for (const formatter of customObjectFormatters) {
const result = formatter(value);
for (i = 0; i < customObjectFormatters.length; i++) {
result = customObjectFormatters[i](value);
if (result !== undefined) { if (result !== undefined) {
return result; return result;
@@ -7890,8 +7861,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return function(customObjectFormatters) { return function(customObjectFormatters) {
customObjectFormatters = customObjectFormatters || []; customObjectFormatters = customObjectFormatters || [];
var pp = function(value) { const pp = function(value) {
var prettyPrinter = new SinglePrettyPrintRun(customObjectFormatters, pp); const prettyPrinter = new SinglePrettyPrintRun(
customObjectFormatters,
pp
);
prettyPrinter.format(value); prettyPrinter.format(value);
return prettyPrinter.stringParts.join(''); return prettyPrinter.stringParts.join('');
}; };

View File

@@ -26,7 +26,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
SinglePrettyPrintRun.prototype.format = function(value) { SinglePrettyPrintRun.prototype.format = function(value) {
this.ppNestLevel_++; this.ppNestLevel_++;
try { try {
var customFormatResult = this.applyCustomFormatters_(value); const customFormatResult = this.applyCustomFormatters_(value);
if (customFormatResult) { if (customFormatResult) {
this.emitScalar(customFormatResult); this.emitScalar(customFormatResult);
@@ -106,10 +106,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) { SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) {
var objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj)); const objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj));
var length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
for (var i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
fn(objKeys[i]); fn(objKeys[i]);
} }
@@ -129,9 +129,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
this.append('Array'); this.append('Array');
return; return;
} }
var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
const length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
this.append('[ '); this.append('[ ');
for (var i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
if (i > 0) { if (i > 0) {
this.append(', '); this.append(', ');
} }
@@ -141,19 +143,18 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
this.append(', ...'); this.append(', ...');
} }
var self = this; let first = array.length === 0;
var first = array.length === 0; const wasTruncated = this.iterateObject(array, property => {
var truncated = this.iterateObject(array, function(property) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
self.append(', '); this.append(', ');
} }
self.formatProperty(array, property); this.formatProperty(array, property);
}); });
if (truncated) { if (wasTruncated) {
this.append(', ...'); this.append(', ...');
} }
@@ -166,8 +167,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return; return;
} }
this.append('Set( '); this.append('Set( ');
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); const size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
var i = 0; let i = 0;
set.forEach(function(value, key) { set.forEach(function(value, key) {
if (i >= size) { if (i >= size) {
return; return;
@@ -191,8 +192,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return; return;
} }
this.append('Map( '); this.append('Map( ');
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); const size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
var i = 0; let i = 0;
map.forEach(function(value, key) { map.forEach(function(value, key) {
if (i >= size) { if (i >= size) {
return; return;
@@ -211,10 +212,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.emitObject = function(obj) { SinglePrettyPrintRun.prototype.emitObject = function(obj) {
var ctor = obj.constructor, const ctor = obj.constructor;
constructorName; const constructorName =
constructorName =
typeof ctor === 'function' && obj instanceof ctor typeof ctor === 'function' && obj instanceof ctor
? j$.fnNameFor(obj.constructor) ? j$.fnNameFor(obj.constructor)
: 'null'; : 'null';
@@ -225,21 +224,20 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return; return;
} }
var self = this;
this.append('({ '); this.append('({ ');
var first = true; let first = true;
var truncated = this.iterateObject(obj, function(property) { const wasTruncated = this.iterateObject(obj, property => {
if (first) { if (first) {
first = false; first = false;
} else { } else {
self.append(', '); this.append(', ');
} }
self.formatProperty(obj, property); this.formatProperty(obj, property);
}); });
if (truncated) { if (wasTruncated) {
this.append(', ...'); this.append(', ...');
} }
@@ -247,13 +245,13 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) { SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) {
var constructorName = j$.fnNameFor(arr.constructor), const constructorName = j$.fnNameFor(arr.constructor);
limitedArray = Array.prototype.slice.call( const limitedArray = Array.prototype.slice.call(
arr, arr,
0, 0,
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH j$.MAX_PRETTY_PRINT_ARRAY_LENGTH
), );
itemsString = Array.prototype.join.call(limitedArray, ', '); let itemsString = Array.prototype.join.call(limitedArray, ', ');
if (limitedArray.length !== arr.length) { if (limitedArray.length !== arr.length) {
itemsString += ', ...'; itemsString += ', ...';
@@ -263,15 +261,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
}; };
SinglePrettyPrintRun.prototype.emitDomElement = function(el) { SinglePrettyPrintRun.prototype.emitDomElement = function(el) {
var tagName = el.tagName.toLowerCase(), const tagName = el.tagName.toLowerCase();
attrs = el.attributes, let out = '<' + tagName;
i,
len = attrs.length,
out = '<' + tagName,
attr;
for (i = 0; i < len; i++) { for (const attr of el.attributes) {
attr = attrs[i];
out += ' ' + attr.name; out += ' ' + attr.name;
if (attr.value !== '') { if (attr.value !== '') {
@@ -306,7 +299,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
value = Object.prototype.toString.call(value); value = Object.prototype.toString.call(value);
} }
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length); const result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
this.length += result.value.length; this.length += result.value.length;
this.stringParts.push(result.value); this.stringParts.push(result.value);
@@ -334,10 +327,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
MaxCharsReachedError.prototype = new Error(); MaxCharsReachedError.prototype = new Error();
function customFormat(value, customObjectFormatters) { function customFormat(value, customObjectFormatters) {
var i, result; for (const formatter of customObjectFormatters) {
const result = formatter(value);
for (i = 0; i < customObjectFormatters.length; i++) {
result = customObjectFormatters[i](value);
if (result !== undefined) { if (result !== undefined) {
return result; return result;
@@ -348,8 +339,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
return function(customObjectFormatters) { return function(customObjectFormatters) {
customObjectFormatters = customObjectFormatters || []; customObjectFormatters = customObjectFormatters || [];
var pp = function(value) { const pp = function(value) {
var prettyPrinter = new SinglePrettyPrintRun(customObjectFormatters, pp); const prettyPrinter = new SinglePrettyPrintRun(
customObjectFormatters,
pp
);
prettyPrinter.format(value); prettyPrinter.format(value);
return prettyPrinter.stringParts.join(''); return prettyPrinter.stringParts.join('');
}; };

View File

@@ -1,10 +1,11 @@
getJasmineRequireObj().DiffBuilder = function(j$) { getJasmineRequireObj().DiffBuilder = function(j$) {
return function DiffBuilder(config) { return function DiffBuilder(config) {
var prettyPrinter = (config || {}).prettyPrinter || j$.makePrettyPrinter(), const prettyPrinter =
mismatches = new j$.MismatchTree(), (config || {}).prettyPrinter || j$.makePrettyPrinter();
path = new j$.ObjectPath(), const mismatches = new j$.MismatchTree();
actualRoot = undefined, let path = new j$.ObjectPath();
expectedRoot = undefined; let actualRoot = undefined;
let expectedRoot = undefined;
return { return {
setRoots: function(actual, expected) { setRoots: function(actual, expected) {
@@ -17,29 +18,24 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
}, },
getMessage: function() { getMessage: function() {
var messages = []; const messages = [];
mismatches.traverse(function(path, isLeaf, formatter) { mismatches.traverse(function(path, isLeaf, formatter) {
var actualCustom, const { actual, expected } = dereferencePath(
expectedCustom, path,
useCustom, actualRoot,
derefResult = dereferencePath( expectedRoot,
path, prettyPrinter
actualRoot, );
expectedRoot,
prettyPrinter
),
actual = derefResult.actual,
expected = derefResult.expected;
if (formatter) { if (formatter) {
messages.push(formatter(actual, expected, path, prettyPrinter)); messages.push(formatter(actual, expected, path, prettyPrinter));
return true; return true;
} }
actualCustom = prettyPrinter.customFormat_(actual); const actualCustom = prettyPrinter.customFormat_(actual);
expectedCustom = prettyPrinter.customFormat_(expected); const expectedCustom = prettyPrinter.customFormat_(expected);
useCustom = !( const useCustom = !(
j$.util.isUndefined(actualCustom) && j$.util.isUndefined(actualCustom) &&
j$.util.isUndefined(expectedCustom) j$.util.isUndefined(expectedCustom)
); );
@@ -64,7 +60,7 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
}, },
withPath: function(pathComponent, block) { withPath: function(pathComponent, block) {
var oldPath = path; const oldPath = path;
path = path.add(pathComponent); path = path.add(pathComponent);
block(); block();
path = oldPath; path = oldPath;
@@ -98,18 +94,17 @@ getJasmineRequireObj().DiffBuilder = function(j$) {
j$.isAsymmetricEqualityTester_(expected) && j$.isAsymmetricEqualityTester_(expected) &&
j$.isFunction_(expected.valuesForDiff_) j$.isFunction_(expected.valuesForDiff_)
) { ) {
var asymmetricResult = expected.valuesForDiff_(actual, pp); const asymmetricResult = expected.valuesForDiff_(actual, pp);
expected = asymmetricResult.self; expected = asymmetricResult.self;
actual = asymmetricResult.other; actual = asymmetricResult.other;
} }
} }
var i;
handleAsymmetricExpected(); handleAsymmetricExpected();
for (i = 0; i < objectPath.components.length; i++) { for (const pc of objectPath.components) {
actual = actual[objectPath.components[i]]; actual = actual[pc];
expected = expected[objectPath.components[i]]; expected = expected[pc];
handleAsymmetricExpected(); handleAsymmetricExpected();
} }

View File

@@ -14,15 +14,13 @@ getJasmineRequireObj().MismatchTree = function(j$) {
} }
MismatchTree.prototype.add = function(path, formatter) { MismatchTree.prototype.add = function(path, formatter) {
var key, child;
if (path.depth() === 0) { if (path.depth() === 0) {
this.formatter = formatter; this.formatter = formatter;
this.isMismatch = true; this.isMismatch = true;
} else { } else {
key = path.components[0]; const key = path.components[0];
path = path.shift(); path = path.shift();
child = this.child(key); let child = this.child(key);
if (!child) { if (!child) {
child = new MismatchTree(this.path.add(key)); child = new MismatchTree(this.path.add(key));
@@ -34,27 +32,22 @@ getJasmineRequireObj().MismatchTree = function(j$) {
}; };
MismatchTree.prototype.traverse = function(visit) { MismatchTree.prototype.traverse = function(visit) {
var i, const hasChildren = this.children.length > 0;
hasChildren = this.children.length > 0;
if (this.isMismatch || hasChildren) { if (this.isMismatch || hasChildren) {
if (visit(this.path, !hasChildren, this.formatter)) { if (visit(this.path, !hasChildren, this.formatter)) {
for (i = 0; i < this.children.length; i++) { for (const child of this.children) {
this.children[i].traverse(visit); child.traverse(visit);
} }
} }
} }
}; };
MismatchTree.prototype.child = function(key) { MismatchTree.prototype.child = function(key) {
var i, pathEls; return this.children.find(child => {
const pathEls = child.path.components;
for (i = 0; i < this.children.length; i++) { return pathEls[pathEls.length - 1] === key;
pathEls = this.children[i].path.components; });
if (pathEls[pathEls.length - 1] === key) {
return this.children[i];
}
}
}; };
return MismatchTree; return MismatchTree;

View File

@@ -5,7 +5,7 @@ getJasmineRequireObj().ObjectPath = function(j$) {
ObjectPath.prototype.toString = function() { ObjectPath.prototype.toString = function() {
if (this.components.length) { if (this.components.length) {
return '$' + map(this.components, formatPropertyAccess).join(''); return '$' + this.components.map(formatPropertyAccess).join('');
} else { } else {
return ''; return '';
} }
@@ -35,14 +35,6 @@ getJasmineRequireObj().ObjectPath = function(j$) {
return "['" + prop + "']"; return "['" + prop + "']";
} }
function map(array, fn) {
var results = [];
for (var i = 0; i < array.length; i++) {
results.push(fn(array[i]));
}
return results;
}
function isValidIdentifier(string) { function isValidIdentifier(string) {
return /^[A-Za-z\$_][A-Za-z0-9\$_]*$/.test(string); return /^[A-Za-z\$_][A-Za-z0-9\$_]*$/.test(string);
} }