Skip to content

Also emit 'file' event for files with syntax errors #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ Deps.prototype.walk = function (id, parent, cb) {
.on('error', cb)
.pipe(concat(function (body) {
var src = body.toString('utf8');
var deps = getDeps(file, src);
try { var deps = getDeps(file, src); }
catch (err) { cb(err); }
if (deps) {
cb(null, {
source: src,
Expand All @@ -434,7 +435,6 @@ Deps.prototype.walk = function (id, parent, cb) {

function getDeps (file, src) {
var deps = rec.noparse ? [] : self.parseDeps(file, src);
if (!deps) return;
// dependencies emitted by transforms
if (self._transformDeps[file]) deps = deps.concat(self._transformDeps[file]);
return deps;
Expand Down Expand Up @@ -504,10 +504,9 @@ Deps.prototype.parseDeps = function (file, src, cb) {
try { var deps = detective(src) }
catch (ex) {
var message = ex && ex.message ? ex.message : ex;
this.emit('error', new Error(
throw new Error(
'Parsing file ' + file + ': ' + message
));
return;
);
}
return deps;
};
Expand Down
8 changes: 6 additions & 2 deletions test/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ var through = require('through2');
var path = require('path');

test('syntax error', function (t) {
t.plan(1);
t.plan(2);
var input = path.join(__dirname, '/files/syntax_error.js');
// ensure transformDeps functionality does not break when parse errors happen
// see https://github.com/browserify/module-deps/commit/9fe46d5#commitcomment-28273437
var p = mdeps({
transform: function () { return through(); }
});
p.on('file', function (file) {
t.equal(file, input, 'should emit a file event even if there was an error');
});
p.on('error', function (err) {
t.ok(err);
});
p.end(path.join(__dirname, '/files/syntax_error.js'));
p.end(input);
});