diff --git a/src/index.js b/src/index.js index f9c4f60..d3b2a32 100644 --- a/src/index.js +++ b/src/index.js @@ -187,6 +187,8 @@ export default function commonjs ( options = {} ) { commonjsModules.set( id, true ); return transformed; + }).catch(err => { + this.error(err, err.loc); }); } }; diff --git a/test/samples/invalid-syntax/main.js b/test/samples/invalid-syntax/main.js new file mode 100644 index 0000000..aabc960 --- /dev/null +++ b/test/samples/invalid-syntax/main.js @@ -0,0 +1 @@ +export const foo = 2, \ No newline at end of file diff --git a/test/test.js b/test/test.js index f7f8723..647fff8 100644 --- a/test/test.js +++ b/test/test.js @@ -482,5 +482,16 @@ describe( 'rollup-plugin-commonjs', () => { }); assert.equal( warns.length, 0 ); }); + + it( 'creates an error with a code frame when parsing fails', async () => { + try { + await rollup({ + input: 'samples/invalid-syntax/main.js', + plugins: [ commonjs() ] + }); + } catch (error) { + assert.equal( error.frame, '1: export const foo = 2,\n ^' ); + } + }); }); });