Skip to content

Commit 0872567

Browse files
Merge pull request #146 from browserify/fix/syntax-file-event
Also emit 'file' event for files with syntax errors
2 parents fe0e6e4 + c58128a commit 0872567

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ Deps.prototype.walk = function (id, parent, cb) {
417417
.on('error', cb)
418418
.pipe(concat(function (body) {
419419
var src = body.toString('utf8');
420-
var deps = getDeps(file, src);
420+
try { var deps = getDeps(file, src); }
421+
catch (err) { cb(err); }
421422
if (deps) {
422423
cb(null, {
423424
source: src,
@@ -434,7 +435,6 @@ Deps.prototype.walk = function (id, parent, cb) {
434435

435436
function getDeps (file, src) {
436437
var deps = rec.noparse ? [] : self.parseDeps(file, src);
437-
if (!deps) return;
438438
// dependencies emitted by transforms
439439
if (self._transformDeps[file]) deps = deps.concat(self._transformDeps[file]);
440440
return deps;
@@ -504,10 +504,9 @@ Deps.prototype.parseDeps = function (file, src, cb) {
504504
try { var deps = detective(src) }
505505
catch (ex) {
506506
var message = ex && ex.message ? ex.message : ex;
507-
this.emit('error', new Error(
507+
throw new Error(
508508
'Parsing file ' + file + ': ' + message
509-
));
510-
return;
509+
);
511510
}
512511
return deps;
513512
};

test/syntax.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ var through = require('through2');
66
var path = require('path');
77

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

0 commit comments

Comments
 (0)