sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 209 forks source link

Add import/export transforms #652

Closed disnet closed 7 years ago

disnet commented 7 years ago

Allows macros to bind on the import and export keywords. Previously this was an error:

syntax import = ctx => ...
gabejohnson commented 7 years ago

Should we be doing this in more places where we test for a specific keyword? enforestExportDeclaration for instance.

If default is bound to a macro, the transform isn't going to take place. There are a couple of places in enforestLeftHandSideExpression where this could be an issue as well.

disnet commented 7 years ago

Good call. I've updated the PR, let me know any place else I've missed.

gabejohnson commented 7 years ago

https://github.com/sweet-js/sweet.js/blob/5843ed5f8a1b6a62c09ce0e5dfd3b10289e2da74/src/enforester.js#L452

https://github.com/sweet-js/sweet.js/blob/5843ed5f8a1b6a62c09ce0e5dfd3b10289e2da74/src/enforester.js#L1214

https://github.com/sweet-js/sweet.js/blob/5843ed5f8a1b6a62c09ce0e5dfd3b10289e2da74/src/enforester.js#L1214

https://github.com/sweet-js/sweet.js/blob/5843ed5f8a1b6a62c09ce0e5dfd3b10289e2da74/src/enforester.js#L1245

But then we have the question: how atomic is an enforestation?

https://github.com/sweet-js/sweet.js/blob/5843ed5f8a1b6a62c09ce0e5dfd3b10289e2da74/src/enforester.js#L383

This is deep in the enforestation of a SwitchStatement.

disnet commented 7 years ago

Thanks for catching those. I think the ones in enforestAssignmentExpression and enforestStatement were technically "fine" because macros in the position are completely expanded before reaching the check, however doing the transform check is more correct anyway.

The one deep in the switch statement was a bug, if class was bound to a macro it needed to fall through to enforestStatement which triggers macro expansion.

gabejohnson commented 7 years ago

Found a few more: https://github.com/sweet-js/sweet.js/blob/678709944272837750117b86d1fe53127c36c6b0/src/enforester.js#L453 https://github.com/sweet-js/sweet.js/blob/678709944272837750117b86d1fe53127c36c6b0/src/enforester.js#L1246 https://github.com/sweet-js/sweet.js/blob/678709944272837750117b86d1fe53127c36c6b0/src/enforester.js#L1347

These would be purely for correctness though.