Skip to content

Instantly share code, notes, and snippets.

@shawnbot
Created August 27, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnbot/112766a656c6015d4da3 to your computer and use it in GitHub Desktop.
Save shawnbot/112766a656c6015d4da3 to your computer and use it in GitHub Desktop.
ES6 module weirdness
export default function foo() {
return 'foo';
};
export function bar() {
return 'bar';
};
{
"name": "blah",
"version": "0.0.1",
"scripts": {
"test": "mocha --compilers js:babel/register"
},
"devDependencies": {
"babel": "^6.2.0",
"mocha": "^2.2.5"
}
}
import lib from './lib';
import assert from 'assert';
describe('module layout', () => {
it('exports a top-level function', () => {
assert.equal(typeof lib, 'function', 'top-level export is not a function');
});
it('exports member functions', () => {
assert.equal(typeof lib.bar, 'function', 'module.bar is not a function');
});
});
@shawnbot
Copy link
Author

Can any ES6 wizards tell me why this doesn't work? Is there a more elegant way to export an ES6 module with a default function and named exports, that you can import in one go? E.g.

import lib from './lib';
var foo = lib();
var bar = lib.bar();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment