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

Improve import and export parsing with babel #399

Merged
merged 7 commits into from
Feb 14, 2019
Merged

Conversation

johno
Copy link
Member

@johno johno commented Feb 12, 2019

This introduces babel for better handling import and
export parsing. Anything that is an import/export block
will be parsed by babel and split up ensuring that
edge cases will no longer occur based on how the
JS is grouped. It also makes parsing the export default
nodes more robust.

This introduces babel for better handling import and
export parsing. Anything that is an import/export block
will be parsed by babel and split up ensuring that
edge cases will no longer occur based on how the
JS is grouped. It also makes parsing the export default
nodes more robust.

- #345
- #340
@vercel
Copy link

vercel bot commented Feb 12, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Copy link
Member

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dope! Looking forward to seeing this out

@vercel vercel bot temporarily deployed to staging February 14, 2019 16:01 Inactive
In order to maintain positional metadata for AST nodes
that are parsed, we need to ensure that each import/export
is eaten in order as a correct subvalue.

Since the remark eat function requires the string to be
consumed in order, with no missing characters, the babel
plugin now returns the start value which is used to sort
the nodes and partition the input string. They're then
combined again and returned as nodes that can be eaten
in order by the tokenizer.

This also comes with the benefit of no longer changing the
input code which occurs with the prior babel generator.
@vercel vercel bot temporarily deployed to staging February 14, 2019 16:58 Inactive
@vercel vercel bot temporarily deployed to staging February 14, 2019 16:59 Inactive
@johno johno mentioned this pull request Feb 14, 2019
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!! ✨ Few questions/nits

packages/remark-mdx/extract-imports-and-exports.js Outdated Show resolved Hide resolved
packages/remark-mdx/test/test.js Show resolved Hide resolved
@vercel vercel bot temporarily deployed to staging February 14, 2019 17:37 Inactive
@vercel vercel bot temporarily deployed to staging February 14, 2019 17:42 Inactive
@johno
Copy link
Member Author

johno commented Feb 14, 2019

Good calls @wooorm. Addressed in latest commits.

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! 🌈

@johno johno merged commit 39e95c5 into master Feb 14, 2019
@johno johno deleted the import-export-parsing branch February 14, 2019 19:26
johno added a commit that referenced this pull request Feb 18, 2019
* Improve import and export parsing with babel

This introduces babel for better handling import and
export parsing. Anything that is an import/export block
will be parsed by babel and split up ensuring that
edge cases will no longer occur based on how the
JS is grouped. It also makes parsing the export default
nodes more robust.

- #345
- #340

* Add multiline fixtures

* Preserve positional information for AST nodes

In order to maintain positional metadata for AST nodes
that are parsed, we need to ensure that each import/export
is eaten in order as a correct subvalue.

Since the remark eat function requires the string to be
consumed in order, with no missing characters, the babel
plugin now returns the start value which is used to sort
the nodes and partition the input string. They're then
combined again and returned as nodes that can be eaten
in order by the tokenizer.

This also comes with the benefit of no longer changing the
input code which occurs with the prior babel generator.

* Remove unneeded babel generator dep

* Simplify partition function

* Make naming consistent

* Add snapshot test to verify positional info
@johno johno mentioned this pull request Mar 7, 2019
31 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants