Skip to content

ES2015: Modules: export declarations (partial) #80

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

Closed
wants to merge 10 commits into from

Conversation

gasi
Copy link
Contributor

@gasi gasi commented Nov 19, 2018

This is a follow-up to #79.

After reading the spec more and approaches such as Shift AST, I concluded we want to introduce Module as a top-level abstraction next to Program (and later replace Program with Script):

The top-level node returned from any successful parse is named Script, not Program, to ease upgrade to ECMAScript 6. ECMAScript 6 parsers need two modes: one mode that produces a Script and one mode that produces a Module. Modules allow import/export declarations at the top level and are always in strict mode.

https://blog.shapesecurity.com/2015/01/06/a-technical-comparison-of-the-shift-and-spidermonkey-ast-formats/

This makes it less likely for invalid programs to inhabit the AST, e.g. export in a Program (later: Script). I like their approach:

A good AST format…

  • minimizes the number of inhabitants that do not represent a program.
  • is at least partially homogenous to allow for a simple and efficient visitor.
  • does not impede moving, copying, or replacing subtrees.
  • discourages duplication in code that operates on it.

I found out about Shift AST in connection with this project somewhere (can’t find the reference anymore). What’s the approach for the new AST? Would it make sense to follow Shift AST spec if possible? Might make for some nice potential interop and learning opportunities.

Update: Found the reference: #41 (comment)

@gasi gasi force-pushed the new-ast-es2015-parse-module branch from 6598e83 to 25cf749 Compare November 19, 2018 00:54
@erikd
Copy link
Owner

erikd commented Nov 21, 2018

Manually squashed and merged. Thanks!

@erikd erikd closed this Nov 21, 2018
@gasi gasi deleted the new-ast-es2015-parse-module branch November 27, 2018 19:14
@gasi
Copy link
Contributor Author

gasi commented Nov 27, 2018

@erikd Just got back from vacation. Thanks for the review and merging 👍

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