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

Export babel tooling in @babel/standalone and @babel/core #11599

Closed
1 task done
ajihyf opened this issue May 23, 2020 · 3 comments · Fixed by #11696
Closed
1 task done

Export babel tooling in @babel/standalone and @babel/core #11599

ajihyf opened this issue May 23, 2020 · 3 comments · Fixed by #11696

Comments

@ajihyf
Copy link
Contributor

ajihyf commented May 23, 2020

Feature Request

  • I would like to work on this feature!

Is your feature request related to a problem? Please describe.
I am implementing a tool to transform an expression using parser.parseExpression, traverse, types.X and generate(exp). This tool should be directly used on the web however @babel/standalone doesn't export these toolings.

Describe the solution you'd like
Directly export babel tooling in @babel/standalone(and @babel/core, since @babel/standalone just imports from it).

Describe alternatives you've considered
I tried to use babel.transform from @babel/standalone. But an expression will be treated as a statement by babel or trigger a parsing error(like { a, b: 3, ...obj }).

@babel-bot
Copy link
Collaborator

Hey @ajihyf! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

You could wrap it in parentheses to disambiguate between a block statement and an object expression:

function transformExpression(code) {
  return babel.transformSync("(" + code + ")");
}

@ajihyf
Copy link
Contributor Author

ajihyf commented May 23, 2020

@nicolo-ribaudo The wrapped statement generates code as a statement, eg. (3) -> 3; and ({ a, b: 3, ...obj }) -> ({ a, b: 3, ...obj });. I've tried to use string manipulation functions to remove these punctuations but seems tricky and error prune.

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