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

Commit 542c143

Browse files
committedJan 9, 2019
Merge branch 'master' into custom-builder
# Conflicts: # test/test.js
2 parents 0a764c0 + ba2559a commit 542c143

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed
 

‎src/helperPlugin.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ export default function importHelperPlugin() {
66
pre(file) {
77
const cachedHelpers = {};
88
file.set('helperGenerator', name => {
9+
if (!file.availableHelper(name)) {
10+
return;
11+
}
12+
913
if (cachedHelpers[name]) {
1014
return cachedHelpers[name];
1115
}
16+
1217
return (cachedHelpers[name] = addNamed(file.path, name, HELPERS));
1318
});
1419
},

‎test/test.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,29 @@ describe('rollup-plugin-babel', function() {
256256
});
257257
});
258258

259+
it('throws when trying to add babel helper unavailable in used @babel/core version', () => {
260+
return bundle('samples/basic/main.js', {
261+
plugins: [
262+
function() {
263+
return {
264+
visitor: {
265+
Program(path, state) {
266+
state.file.addHelper('__nonexistentHelper');
267+
},
268+
},
269+
};
270+
},
271+
],
272+
}).then(
273+
() => {
274+
assert.ok(false);
275+
},
276+
err => {
277+
assert.equal(err.message, 'Unknown helper __nonexistentHelper');
278+
},
279+
);
280+
});
281+
259282
it('supports customizing the loader', () => {
260283
const customBabelPlugin = babelPlugin.custom(() => {
261284
return {
@@ -275,10 +298,7 @@ describe('rollup-plugin-babel', function() {
275298
};
276299
});
277300
return rollup
278-
.rollup({
279-
input: 'samples/basic/main.js',
280-
plugins: [customBabelPlugin()],
281-
})
301+
.rollup({ input: 'samples/basic/main.js', plugins: [customBabelPlugin()] })
282302
.then(bundle => {
283303
return bundle.generate({ format: 'cjs' });
284304
})
@@ -310,10 +330,7 @@ describe('rollup-plugin-babel', function() {
310330
};
311331
});
312332
return rollup
313-
.rollup({
314-
input: 'samples/basic/main.js',
315-
plugins: [customBabelPlugin()],
316-
})
333+
.rollup({ input: 'samples/basic/main.js', plugins: [customBabelPlugin()] })
317334
.then(bundle => {
318335
return bundle.generate({ format: 'cjs' });
319336
})

0 commit comments

Comments
 (0)
This repository has been archived.