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

Commit

Permalink
Fail build when trying plugin tries to add non-existent helper (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Jan 2, 2019
1 parent 0752385 commit ba2559a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/helperPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ export default function importHelperPlugin() {
pre(file) {
const cachedHelpers = {};
file.set('helperGenerator', name => {
if (!file.availableHelper(name)) {
return;
}

if (cachedHelpers[name]) {
return cachedHelpers[name];
}

return (cachedHelpers[name] = addNamed(file.path, name, HELPERS));
});
},
Expand Down
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,27 @@ describe('rollup-plugin-babel', function() {
assert.ok(code.indexOf('class Other ') === -1, 'should transpile .other');
});
});

it('throws when trying to add babel helper unavailable in used @babel/core version', () => {
return bundle('samples/basic/main.js', {
plugins: [
function() {
return {
visitor: {
Program(path, state) {
state.file.addHelper('__nonexistentHelper');
},
},
};
},
],
}).then(
() => {
assert.ok(false);
},
err => {
assert.equal(err.message, 'Unknown helper __nonexistentHelper');
},
);
});
});

0 comments on commit ba2559a

Please sign in to comment.