jlongster / es6-macros

A collection of sweet.js macros that implement ES6 features for ES5
BSD 2-Clause "Simplified" License
237 stars 18 forks source link

What's possible with `let` and `const` macros #8

Open Raynos opened 10 years ago

Raynos commented 10 years ago

I know there's a compiler for it ( https://github.com/olov/defs ) but it would be cool to have it as a macro as well.

jlongster commented 10 years ago

So sweet.js already is aware of the scopes of everything, and it handles let/const scoping properly. It even already renames all the variables because of the hygiene system. It's probably easiest to just add a flag to sweet.js to tell it to compile out everything to var statements instead of keeping the original type. Otherwise you'd have to do some pretty extensive expansion to imitate the let/const behavior.

Raynos commented 10 years ago

This is more about parsing ES5 with a macro for let/const then parsing ES6 with real let/const.