Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Create an error with a code frame when parsing fails #288

Merged
merged 1 commit into from
Mar 5, 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
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export default function commonjs ( options = {} ) {

commonjsModules.set( id, true );
return transformed;
}).catch(err => {
this.error(err, err.loc);
});
}
};
Expand Down
1 change: 1 addition & 0 deletions test/samples/invalid-syntax/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 2,
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ^' );
}
});
});
});