anko / eslisp

un-opinionated S-expression syntax and macro system for JavaScript
ISC License
528 stars 31 forks source link

ES6 / ES7 support via BabelJS #11

Open idibidiart opened 8 years ago

idibidiart commented 8 years ago

Is it possible to use ES6/7 features like async/await ? Can you show a working example?

anko commented 8 years ago

Not yet.

I've been targeting ES5 only so far, because the estree spec and related tooling are still catching up with ES6 (e.g. estools/esvalid#7). So if it existed, it would have to be behind an --experimental flag.

However, it should be quite possible to add even now: All the built-in macros just emit estree objects that are compiled by escodegen. There is an experimental estree spec for async/await and escodegen seems to support it!

I'll try it sometime soonish—PR welcome too.

lhorie commented 8 years ago

It looks like as of version 6.0, Babel is no longer ESTree compliant. I opened an issue over there but the author said he's not willing to support the standard format anymore.

anko commented 8 years ago

Perhaps we should altogether move to target Babel's AST spec?

Pros:

Cons:

lhorie commented 8 years ago

That's a possible solution. Another solution is to write a compatibility layer that takes a estree ast as input and outputs a babel ast.

hzoo commented 8 years ago

@lhorie not sure if you saw my comment in the issue (maybe missed it since it was right before yours) but basically I'l be doing a compatibility layer

lhorie commented 8 years ago

Ooh nice. That's awesome to hear. I totally did miss your comment. @hzoo

hzoo commented 8 years ago

@lhorie https://github.com/babel/acorn-to-esprima/pull/3 - I'l need to add a lot more tests since I know some of the loc/range info is wrong now.

dead-claudia commented 8 years ago

Update: escodegen fully supports ES6 AFAICT, and I've already started some of this process in #41.

11111000000 commented 8 years ago

41 merged, any news here?

anko commented 8 years ago

@11111000000

41 isn't merged, and so the macros that eslisp comes with don't support ES6 yet. The current approach in #41 still introduces ambiguity, as outlined in the description of my PR https://github.com/isiahmeadows/eslisp/pull/1. I think that path isn't going to work out, since most of ES6 changes are at the syntactic level.

I'd bet on an eventual solution coming through #24.

For now, if you're desperate, with #34 merged you can write macros that return ES6 estree objects. If you like, you could try returning such an object from your own macros, like this.

11111000000 commented 8 years ago

@anko: thanks, watch closely

dead-claudia commented 8 years ago

May I also point out that the isExpression, etc. are part of Babel, anyways (and they've been that way since at least 5)? I'm not a huge fan of Babel, but I just thought I'd point that out.