asapach / babel-plugin-rewire-exports

Babel plugin for stubbing [ES6, ES2015] module exports
MIT License
66 stars 7 forks source link

Enable rewiring for named constant exports #17

Closed sergei-startsev closed 5 years ago

sergei-startsev commented 5 years ago

At the moment named constant exports are just ignored:

export const foo = 'bar';

No rewire stubs are added for this export, so if you try import rewire$foo in your test, you get import is not defined error that is unexpected for plugin consumers.

The PR enables rewiring for named constant export.

In

export const foo = 'bar';

Out

const foo = 'bar';
var _foo = foo;
export { _foo as foo };
var _foo2 = _foo;
export function rewire$foo($stub) {
  _foo = $stub;
}
export function restore() {
  _foo = _foo2;
}