Skip to content
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

Output error message on espree error #143

Merged
merged 2 commits into from
May 25, 2016
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
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