Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: babylon parser to check default/named exports #27

Closed
wants to merge 6 commits into from

Conversation

laggingreflex
Copy link
Contributor

@laggingreflex laggingreflex commented Dec 7, 2016

Uses Babylon parser to parse the file to check if it contains a default export.

If a file now contains a default export, the behaviour will be the same as before.

But if the file doesn't contain any default exports, assuming it has only named exports, it uses * as when creating its index.

Eg. Default export: (same as before)

// foo.js

export default () => {}

will create ine the index:

import _foo from './foo'
export const foo = _foo
export {
  foo
}

Eg. Named exports:

// foo.js

export const foo1 = () => {}
export const foo2 = () => {}

will create ine the index:

import * as _foo from './foo'
export const foo = _foo
export {
  foo
}

Builds on #18, addresses #11

This adds a default export object containing all named exports.

Eg.:
```js
import _king from './king.js';
export const king = _king;

import _queen from './queen';
export const queen = _queen;

export default {
  king,
  queen
};
```
This adds support for `hyphenated-files`

The exported names are now also in camelCase
# Conflicts:
#	src/utilities/createIndexCode.js
Uses Babylon parse to actually parse the file to check if it contains a default export.

If a file now contains a default export, the behaviour will be the same as before.

But if the file doesn't contain any default exports, assuming it has only named exports, it uses `* as` when creating its index.


Eg. Default export: (same as before)
```js
// foo.js

export default () => {}
```
will create ine the index:
```
import _foo from './foo'
export const foo = _foo
export {
  foo
}
```


Eg. Named exports:
```js
// foo.js

export const foo1 = () => {}
export const foo2 = () => {}
```
will create ine the index:
```
import * as _foo from './foo'
export const foo = _foo
export {
  foo
}
```
@laggingreflex
Copy link
Contributor Author

PS: It contains a lot of previous commits (#16, #18, #23). I can rebase if needed.

@gajus
Copy link
Owner

gajus commented Dec 7, 2016

PS: It contains a lot of previous commits (#16, #18, #23). I can rebase if needed.

Yes, please.

@gajus
Copy link
Owner

gajus commented Dec 8, 2016

But if the file doesn't contain any default exports, assuming it has only named exports, it uses * as when creating its index.

Similar to #18

This promotes bad design.

Creating an index file that imports * as foo and requiring anything from that index will include all the files to the resulting bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants