Skip to content

Commit

Permalink
Merge pull request #143 from gabegorelick/dont-swallow-parse-errors
Browse files Browse the repository at this point in the history
Output error message on espree error
  • Loading branch information
rubenv committed May 25, 2016
2 parents ddc7bda + d80313f commit a65a64b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ var Extractor = (function () {
}
});
} catch (err) {
var errMsg = 'Error parsing';
if (filename) {
errMsg += ' ' + filename;
}
if (err.lineNumber) {
errMsg += ' at line ' + err.lineNumber;
errMsg += ' column ' + err.column;
}

console.warn(errMsg);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"grunt-contrib-jshint": "~0.11.2",
"grunt-contrib-watch": "~0.6.1",
"grunt-jscs": "^1.8.0",
"grunt-mocha-cli": "^1.13.1"
"grunt-mocha-cli": "^1.13.1",
"sinon": "^1.17.4"
},
"keywords": [
"angular",
Expand Down
23 changes: 18 additions & 5 deletions test/extract_javascript.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var assert = require('assert');
var sinon = require('sinon');
var testExtract = require('./utils').testExtract;

describe('Extracting from Javascript', function () {
Expand Down Expand Up @@ -78,11 +79,23 @@ describe('Extracting from Javascript', function () {
assert.deepEqual(catalog.items[1].references, ['test/fixtures/deeppath_catalog.js:4']);
});

it('supports invalid javascript syntax without exception', function () {
var files = [
'test/fixtures/deeppath_catalog_invalid.js'
];
testExtract(files);
describe('invalid javascript', function () {
beforeEach(function () {
sinon.stub(console, 'warn', function () {
// respect the rule of silence
});
});

afterEach(function () {
console.warn.restore();
});

it('should not throw an exception', function () {
var files = [
'test/fixtures/deeppath_catalog_invalid.js'
];
testExtract(files);
});
});

describe('from HTML <script> tags', function () {
Expand Down

0 comments on commit a65a64b

Please sign in to comment.