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

Commit

Permalink
Merge branch 'master' into custom-builder
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/test.js
  • Loading branch information
Andarist committed Jan 9, 2019
2 parents 0a764c0 + ba2559a commit 542c143
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 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
33 changes: 25 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,29 @@ describe('rollup-plugin-babel', function() {
});
});

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');
},
);
});

it('supports customizing the loader', () => {
const customBabelPlugin = babelPlugin.custom(() => {
return {
Expand All @@ -275,10 +298,7 @@ describe('rollup-plugin-babel', function() {
};
});
return rollup
.rollup({
input: 'samples/basic/main.js',
plugins: [customBabelPlugin()],
})
.rollup({ input: 'samples/basic/main.js', plugins: [customBabelPlugin()] })
.then(bundle => {
return bundle.generate({ format: 'cjs' });
})
Expand Down Expand Up @@ -310,10 +330,7 @@ describe('rollup-plugin-babel', function() {
};
});
return rollup
.rollup({
input: 'samples/basic/main.js',
plugins: [customBabelPlugin()],
})
.rollup({ input: 'samples/basic/main.js', plugins: [customBabelPlugin()] })
.then(bundle => {
return bundle.generate({ format: 'cjs' });
})
Expand Down

0 comments on commit 542c143

Please # to comment.