-
Notifications
You must be signed in to change notification settings - Fork 47
Parse ES2015 (aka ES6) export
Declarations (partial support)
#79
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
Conversation
This fixes the messaging as LHS is actual and RHS expected test result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| JSWhile !JSAnnot !JSAnnot !JSExpression !JSAnnot !JSStatement -- ^while,lb,expr,rb,stmt | ||
| JSWith !JSAnnot !JSAnnot !JSExpression !JSAnnot !JSStatement !JSSemi -- ^with,lb,expr,rb,stmt list | ||
| JSExport !JSAnnot !JSExportBody !JSSemi -- ^export, body, autosemi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is introducing JSExportBody
to support the following variants the right abstraction?
-- ExportDeclaration : See 15.2.3
-- [ ] export * FromClause ;
-- [ ] export ExportClause FromClause ;
-- [x] export ExportClause ;
-- [x] export VariableStatement
-- [ ] export Declaration
-- [ ] export default HoistableDeclaration[Default]
-- [ ] export default ClassDeclaration[Default]
-- [ ] export default [lookahead ∉ { function, class }] AssignmentExpression[In] ;
Q: What makes for the right AST abstraction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. You decide :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to revisit this a bit and opened #80. Let me know what you think.
@@ -887,6 +897,7 @@ StatementNoEmpty : StatementBlock { $1 {- 'StatementNoEmpty1' -} } | |||
| ThrowStatement { $1 {- 'StatementNoEmpty13' -} } | |||
| TryStatement { $1 {- 'StatementNoEmpty14' -} } | |||
| DebuggerStatement { $1 {- 'StatementNoEmpty15' -} } | |||
| ExportDeclaration { $1 {- 'StatementNoEmpty16' -} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t align with the ECMAScript 2015 spec but it seems the approach that #64 has taken:
https://github.com/erikd/language-javascript/pull/64/files#diff-843804451967a2b03f95fbef01a330d1R905
My first attempt created a separate JSDeclaration
data type 9330863 but then I reverted to align with the existing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My maintenance of this has focused more on parsing real world JS rather than following the spec. This is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. If not following the spec, how do you decide whether a program should pass or fail parsing? I thought most modern JS engines follow the spec but as I said, I don’t have a lot of background in this space.
You happy with this as it is now? |
@gasi ❤️, been meaning to complete this just not had the time to doing it really happy you are taking it on. Let me know if I can be of help as this has given me motivation! |
Don't blame me, all the credit goes to @gasi :) . |
@ totally the wrong person hahaha will amend! |
Closed in favor of #80 |
First of all, thanks for creating and maintaining this wonderful library! 😄
Motivation
I am a passionate PureScript user and would like to see the project adopt ES2015 (aka ES6) for better bundling and interop with the rest of the JavaScript ecosystem. See:
As a first step, I’d like to support parsing
export
declarations (statements) that could be used to write hand-written PureScript FFI files with ES2015 modules instead of CommonJS, e.g. https://github.com/purescript/purescript-prelude/blob/dc1069417b04896a1fb8b90175e67f91e1d9051a/src/Record/Unsafe.jsPrior Art
@Cmdv started this PR #78 but it had a few compile errors, so I decided to start with a new branch based on
new-ast
:Implementation Notes
The implementation follows the Exports specification in section 15.2.3 of the ECMAScript 2015 specification: http://www.ecma-international.org/ecma-262/6.0/ECMA-262.pdf#page=304
Current Support
ExportDeclaration
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export VariableStatement
export Declaration
export default HoistableDeclaration[Default]
export default ClassDeclaration[Default]
export default [lookahead ∉ { function, class }] AssignmentExpression[In] ;
Examples
export {}
export const a = 1;
export { a };
export { X as Y };
Feedback
Since I don’t have a background in compilers (minus a college class long-time ago), I’d love to get some feedback on my current approach before I continue.
Questions
JSExport
be part ofJSStatement
or should we createJSDeclaration
(or similar)? In the specExportDeclaration
is part of:and statements are defined as:
but I’m not sure what the ideal relationship between the AST and the grammar should be.
stack
besides justcabal
? I couldn’t get the project to build usingcabal-install
:as
make sense as binary operator? I modelled it afterin
which can be used both for'foo' in {foo: 2}
(binary operator) as well asfor (var x in xs) {...}
(not really a binary operator?).