Skip to content

Commit ea041da

Browse files
committed
diff: Fix default options not applied for diffFiles()
1 parent e4233de commit ea041da

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/diff.coffee

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,7 @@ readGraph = (contents, type, options) ->
305305

306306
# diff two graphs
307307
exports.diff = (from, to, options) ->
308-
options.format = 'object' if not options.format?
309-
options.fromFormat = options.format if not options.fromFormat?
310-
options.toFormat = options.format if not options.toFormat?
311-
options.caseSensitive = true if not options.caseSensitive?
308+
options = normalizeOptions options
312309

313310
f = readGraph from, options.fromFormat, options
314311
t = readGraph to, options.toFormat, options
@@ -318,6 +315,14 @@ exports.diff = (from, to, options) ->
318315

319316
return out
320317

318+
normalizeOptions = (options) ->
319+
options = clone options
320+
options.format = 'object' if not options.format?
321+
options.fromFormat = options.format if not options.fromFormat?
322+
options.toFormat = options.format if not options.toFormat?
323+
options.caseSensitive = true if not options.caseSensitive?
324+
return options
325+
321326
# node.js only
322327
readGraphFile = (filepath, options, callback) ->
323328
fs = require 'fs'
@@ -327,7 +332,7 @@ readGraphFile = (filepath, options, callback) ->
327332
fs.readFile filepath, { encoding: 'utf-8' }, (err, contents) ->
328333
return callback err if err
329334
try
330-
graph = readGraph contents, type
335+
graph = readGraph contents, type, options
331336
catch e
332337
return callback e
333338
return callback null, graph
@@ -352,5 +357,6 @@ exports.main = main = () ->
352357
console.log output
353358

354359
options = {}
360+
options = normalizeOptions options
355361
return diffFiles from, to, options, callback
356362

0 commit comments

Comments
 (0)