Closed Rich-Harris closed 9 years ago
Would it be possible to get the ast
option on getStandaloneModule
too? That'll be what Babel would use by default, at least for the time being.
Yep, that works too:
esperanto.toCjs({
code: '...',
ast: {...}
}, options );
Ah awesome! Was digging through the code but didn't see it anywhere. Thanks!
Alright, so I've basically got this integrated and it's working surprisingly well. The only issue so far is that esperanto will always put 'use strict';
at the top. Babel already does this so it leads to it being duplicated. I could make Babel not do that but there are some scenarios where people want modules but not strict mode (it's insane i know). A strictMode
option that defaults to true
that I can just set depending on whether it's required would be awesome.
Damn, you work fast.
there are some scenarios where people want modules but not strict mode (it's insane i know)
O_o I don't know what to say to that...
@thejameskyle raised a related issue recently (https://github.com/esperantojs/esperanto/issues/121) and the consensus was that it wasn't worth giving people the option, but I suppose this changes things. Will get onto it shortly and include it in this PR.
Released in 0.6.27. To disable the 'use strict' pragma, pass useStrict: false
First crack at #140. Would welcome feedback (cc @sebmck). It basically follows the proposal in #140, with one thing to be aware of - the properties of the
modules
option are paths relative to the base dir (whether specified asbase
or implicit, i.e.process.cwd()
.This is necessary because
import foo from './foo'
could refer tofoo/index.js
(esperanto works that way because CommonJS works that way... open for discussion - removing support forindex.js
would simplify some things, but I kinda like it), which means that relative paths infoo
need to know whether they're relative tofoo.js
orfoo/index.js
.So usage looks like this:
The supplied AST should have
start
andend
character offset properties on each node - acorn includes these by default.