Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC - supply code and AST to esperanto #141

Merged
merged 7 commits into from
Apr 7, 2015
Merged

RFC - supply code and AST to esperanto #141

merged 7 commits into from
Apr 7, 2015

Conversation

Rich-Harris
Copy link
Contributor

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 as base or implicit, i.e. process.cwd().

This is necessary because import foo from './foo' could refer to foo/index.js (esperanto works that way because CommonJS works that way... open for discussion - removing support for index.js would simplify some things, but I kinda like it), which means that relative paths in foo need to know whether they're relative to foo.js or foo/index.js.

So usage looks like this:

esperanto.bundle({
  entry: 'main',
  base: 'src',
  modules: {
    'main.js': {
      code: '...',
      ast: {...}
    },
    'foo.js': '/* if no AST is supplied, esperanto generates a fresh one */'
  }
};

The supplied AST should have start and end character offset properties on each node - acorn includes these by default.

@sebmck
Copy link

sebmck commented Apr 1, 2015

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.

@Rich-Harris
Copy link
Contributor Author

Yep, that works too:

esperanto.toCjs({
  code: '...',
  ast: {...}
}, options );

@sebmck
Copy link

sebmck commented Apr 1, 2015

Ah awesome! Was digging through the code but didn't see it anywhere. Thanks!

@sebmck
Copy link

sebmck commented Apr 1, 2015

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.

@Rich-Harris
Copy link
Contributor Author

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 (#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.

Rich-Harris added a commit that referenced this pull request Apr 7, 2015
RFC - supply code and AST to esperanto
@Rich-Harris Rich-Harris merged commit cf9b5e6 into master Apr 7, 2015
@Rich-Harris Rich-Harris deleted the gh-140 branch April 7, 2015 14:53
@Rich-Harris
Copy link
Contributor Author

Released in 0.6.27. To disable the 'use strict' pragma, pass useStrict: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants