escomplex-js
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "escomplex-js", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Javascript wrapping library for escomplex.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/philbooth/escomplex-js", |
@@ -23,15 +23,30 @@ /*globals require, exports */ | ||
function analyseSources (sources, options) { | ||
return performAnalysis(sources.map(function (source) { | ||
try { | ||
return { | ||
path: source.path, | ||
ast: getSyntaxTree(source.code) | ||
}; | ||
} catch (error) { | ||
error.message = source.path + ': ' + error.message; | ||
throw error; | ||
return performAnalysis( | ||
sources.map( | ||
mapSource.bind(null, options) | ||
).filter(filterSource), | ||
options | ||
); | ||
} | ||
function mapSource (options, source) { | ||
try { | ||
return { | ||
path: source.path, | ||
ast: getSyntaxTree(source.code) | ||
}; | ||
} catch (error) { | ||
if (options.ignoreErrors) { | ||
return null; | ||
} | ||
}), options); | ||
error.message = source.path + ': ' + error.message; | ||
throw error; | ||
} | ||
} | ||
function filterSource (source) { | ||
return !!source; | ||
} | ||
function getSyntaxTree (source) { | ||
@@ -38,0 +53,0 @@ return esprima.parse(source, { loc: true }); |
@@ -165,2 +165,29 @@ 'use strict'; | ||
suite('array source with bad code:', function() { | ||
var code; | ||
setup(function () { | ||
mockery.deregisterMock('esprima'); | ||
mockery.disable(); | ||
code = [ { path: '/foo.js', code: 'foo foo' }, { path: '../bar.js', code: '"bar";' } ]; | ||
index = require(modulePath); | ||
}); | ||
teardown(function () { | ||
code = undefined; | ||
}); | ||
test('throws an error with default options', function() { | ||
assert.throws(function() { | ||
index.analyse(code, {}); | ||
}, '/foo.js: Line 1: Unexpected identifier'); | ||
}); | ||
test('swallows error with options.ignoreErrors', function() { | ||
assert.doesNotThrow(function() { | ||
index.analyse(code, { ignoreErrors: true }); | ||
}); | ||
}); | ||
}); | ||
suite('string source:', function () { | ||
@@ -167,0 +194,0 @@ var options, result; |
Sorry, the diff of this file is not supported yet
14793
306
4