opened
mattkime
username_0
i'm working with an existing codebase with a large number of javascript files and we'd like to start using es6 module definitions. all our modules use "define()" statements as we're using AMD/ requirejs. when the AMD module formatter comes across these files it simply wraps them in an additional define statement - not good. ideally it would recognize the define statement and do nothing. this way all our existing code can go through the same babel setup without concern for the contents of the file.
AMD module formatter shouldn't supply 'define' invocation if file already contains one
issue
created
thejameskyle
username_1
That's out of scope for the AMD formatter. You can write your own Babel plugin to do that though. See: http://babeljs.io/docs/advanced/plugins/
comment
closed
thejameskyle
username_1
issue
created
mattkime
username_0
@username_1 could you explain why its out of scope?
comment
created
loganfsmyth
username_2
@username_0 Babel expects all files to be ES6 modules. It isn't Babel's responsibility to try to deduce whether you were already using some other module system. By passing `amd` you are asking for a wrapper, the fact that you've already got a wrapper in there isn't something Babel is aware of or needs to be aware of.

It's also not clear what the expected behavior in the general case would be, do we have to somehow merge the two separate declarations? As @username_1 said, it should be pretty simple to write your own plugin to recognize the wrapper and I assume in your case it would be empty if you've got a manual wrapper in there, so you could delete the wrapper.
comment
created
thejameskyle
username_1
@username_2 is exactly right, besides nested AMD wrappers is technically valid so I'm not sure how we'd decide what the rules are for deduping them. Only you know enough about how your project is structured to make that call.
comment
created
mattkime
username_0
big thanks for the detailed explanations.
comment