Skip to content

Commit acd68e6

Browse files
committed
Style updates
1 parent 54a326b commit acd68e6

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

diff.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ var JsDiff = (function() {
193193
function eofNL(curRange, i, current) {
194194
var last = diff[diff.length-2],
195195
isLast = i === diff.length-2,
196-
isLastOfType = i === diff.length-3 && (current.added === !last.added || current.removed === !last.removed);
196+
isLastOfType = i === diff.length-3 && (current.added !== last.added || current.removed !== last.removed);
197197

198198
// Figure out if this is the last line for the given file and missing NL
199199
if (!/\n$/.test(current.value) && (isLast || isLastOfType)) {
@@ -263,6 +263,7 @@ var JsDiff = (function() {
263263
var diff = [];
264264
var remEOFNL = false,
265265
addEOFNL = false;
266+
266267
for (var i = (diffstr[0][0]=="I"?4:0); i < diffstr.length; i++) {
267268
if(diffstr[i][0] == "@") {
268269
var meh = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
@@ -273,35 +274,41 @@ var JsDiff = (function() {
273274
newlength:meh[4],
274275
newlines:[]
275276
});
276-
} else
277-
if(diffstr[i][0] == "+") {
277+
} else if(diffstr[i][0] == '+') {
278278
diff[0].newlines.push(diffstr[i].substr(1));
279-
} else
280-
if(diffstr[i][0] == "-") {
279+
} else if(diffstr[i][0] == '-') {
281280
diff[0].oldlines.push(diffstr[i].substr(1));
282-
} else
283-
if(diffstr[i][0] == " ") {
281+
} else if(diffstr[i][0] == ' ') {
284282
diff[0].newlines.push(diffstr[i].substr(1));
285283
diff[0].oldlines.push(diffstr[i].substr(1));
286-
} else
287-
if(diffstr[i][0] == "\\") {
288-
if(diffstr[i-1][0] == "+") remEOFNL = true;
289-
if(diffstr[i-1][0] == "-") addEOFNL = true;
284+
} else if(diffstr[i][0] == '\\') {
285+
if (diffstr[i-1][0] == '+') {
286+
remEOFNL = true;
287+
} else if(diffstr[i-1][0] == '-') {
288+
addEOFNL = true;
289+
}
290290
}
291-
};
291+
}
292+
292293
var str = oldStr.split("\n");
293294
for (var i = diff.length - 1; i >= 0; i--) {
294295
var d = diff[i];
295296
for (var j = 0; j < d.oldlength; j++) {
296297
if(str[d.start-1+j] != d.oldlines[j]) {
297298
return false;
298299
}
299-
};
300+
}
300301
Array.prototype.splice.apply(str,[d.start-1,+d.oldlength].concat(d.newlines));
301302
}
302-
if(remEOFNL) while(str[str.length-1]=="") str.pop();
303-
else if(addEOFNL) str.push("");
304-
return str.join("\n");
303+
304+
if (remEOFNL) {
305+
while (!str[str.length-1]) {
306+
str.pop();
307+
}
308+
} else if (addEOFNL) {
309+
str.push('');
310+
}
311+
return str.join('\n');
305312
},
306313

307314
convertChangesToXML: function(changes){

0 commit comments

Comments
 (0)