Skip to content

Commit

Permalink
fix helper renaming (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored and Andarist committed Dec 25, 2019
1 parent b576449 commit 5931a93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/rollup-plugin-babel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function babel ( options ) {

return buildExternalHelpers( helpers, 'var' )
.replace( /var babelHelpers.+\n/, '' )
.replace( /babelHelpers\.(.+) = function/g, 'function babelHelpers_$1' )
.replace( /babelHelpers\.(.+) = function(?: \w+)?/g, 'function babelHelpers_$1' )
.replace( /babelHelpers\.(.+) = /g, 'var babelHelpers_$1 = ' )
.replace( 'babelHelpers;', '' ) // not sure where this comes from...
.trim() + '\n';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
solo: true,
description: 'correctly renames helpers'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Bar {
baz () {
alert( 'baz' );
}
}

export class Foo extends Bar {
baz () {
super.baz();
}
}
13 changes: 13 additions & 0 deletions packages/rollup-plugin-babel/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,17 @@ describe( 'rollup-plugin-babel', function () {
assert.ok( !~cjs.indexOf( 'babelHelpers' ) );
});
});

it( 'correctly renames helpers (#22)', () => {
return rollup.rollup({
entry: 'samples/named-function-helper/main.js',
plugins: [ babelPlugin() ],
onwarn: function ( msg ) {
assert.equal( msg, `Treating 'babel-runtime/helpers/classCallCheck' as external dependency` );
}
}).then( function ( bundle ) {
var cjs = bundle.generate({ format: 'cjs' }).code;
assert.ok( !~cjs.indexOf( 'babelHelpers_get get' ), 'helper was incorrectly renamed' );
});
});
});

0 comments on commit 5931a93

Please sign in to comment.