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 packages in @babel/standalone #11696

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

ajihyf
Copy link
Contributor

@ajihyf ajihyf commented Jun 9, 2020

Q                       A
Fixed Issues? Fixes #11599
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link babel/website#2871
Any Dependency Changes?
License MIT

I am implementing a tool to transform an expression using parser.parseExpression, traverse, types.X and generate(exp). This tool is used on the web browser however @babel/standalone doesn't export these toolings. Thus I want to directly export babel tooling in @babel/standalone(and @babel/core, since @babel/standalone just imports from it).

@babel-bot
Copy link
Collaborator

babel-bot commented Jun 9, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56343

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 9, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4c0d45a:

Sandbox Source
white-butterfly-gemdo Configuration
hidden-thunder-5s2ty Configuration

@NullVoxPopuli
Copy link

I ran in to a need for this today :)

@nicolo-ribaudo nicolo-ribaudo added pkg: standalone PR: New Feature 🚀 A type of pull request used for our changelog categories labels Mar 30, 2021
@liuxingbaoyu liuxingbaoyu added this to the Babel 7.next milestone Sep 19, 2022
@liuxingbaoyu liuxingbaoyu changed the base branch from master to main November 6, 2023 12:23
@liuxingbaoyu liuxingbaoyu changed the base branch from main to master November 25, 2023 06:18
@liuxingbaoyu liuxingbaoyu changed the base branch from master to main November 25, 2023 06:19
@liuxingbaoyu

This comment was marked as outdated.

@liuxingbaoyu
Copy link
Member

Thanks!

@kungfooman
Copy link

This is very helpful and allows a better testing of all PRs directly in the console of babel-bot's web preview 🌈

image

@liuxingbaoyu liuxingbaoyu modified the milestones: Babel 7.next, v7.24.0 Dec 24, 2023
@nicolo-ribaudo
Copy link
Member

I dislike how this can create confusion between import { parse } from "@babel/core"; parse(...) and import { parser } from "@babel/core"; parser.parse(...), that do two completely different things.

Given that the need is only in @babel/standalone, how do you feel about only exposing them there as Babel.packages.parser, Babel.packages.generator, etc?

@liuxingbaoyu
Copy link
Member

liuxingbaoyu commented Feb 26, 2024

I agree with this!
Sorry I was wrong, I think this sounds good.

@liuxingbaoyu
Copy link
Member

Given that the need is only in @babel/standalone

Does this mean doing this in @babel/core as well?
import { packages } from "@babel/core"; doesn't seem very good.

@NullVoxPopuli
Copy link

NullVoxPopuli commented Feb 26, 2024

hm, I'm mostly hoping for a way to not using @babel/standalone, but would like to easily use @babel/core (and friends) to have a minimal browser-compiler with a set few plugins (rather than the all of them that standalone includes).

Last I tried this, it seemed some custom build was required (which isn't fun 😅 ), due to @babel/core assuming it's running in a node-like env (based on the access of process, etc)

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Feb 26, 2024

@liuxingbaoyu No, only for standalone. If you are using a bundler or running on Node.js, you can just import "@babel/parser" directly.

Last I tried this, it seemed some custom build was required (which isn't fun 😅 ), due to @babel/core assuming it's running in a node-like env (based on the access of process, etc)

@NullVoxPopuli We use browsers in package.json to provide alternatives to those files that use process&co. Do you have any suggestion of a better way to isolate Node.js-specific from browser-specific code? Would using imports as a semi-standard alternative to browsers be good enough?

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: standalone PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export babel tooling in @babel/standalone and @babel/core
6 participants