diff --git a/packages/babel-standalone/package.json b/packages/babel-standalone/package.json index cdd6b98c441f..f49e682f9d55 100644 --- a/packages/babel-standalone/package.json +++ b/packages/babel-standalone/package.json @@ -11,6 +11,8 @@ ], "devDependencies": { "@babel/core": "workspace:^", + "@babel/generator": "workspace:^", + "@babel/parser": "workspace:^", "@babel/plugin-external-helpers": "workspace:^", "@babel/plugin-proposal-decorators": "workspace:^", "@babel/plugin-proposal-destructuring-private": "workspace:^", @@ -116,6 +118,9 @@ "@babel/preset-flow": "workspace:^", "@babel/preset-react": "workspace:^", "@babel/preset-typescript": "workspace:^", + "@babel/template": "workspace:^", + "@babel/traverse": "workspace:^", + "@babel/types": "workspace:^", "acorn": "^8.7.0", "jsdom": "^22.1.0" }, diff --git a/packages/babel-standalone/src/index.ts b/packages/babel-standalone/src/index.ts index 1433a74afed8..14dea3a36b33 100644 --- a/packages/babel-standalone/src/index.ts +++ b/packages/babel-standalone/src/index.ts @@ -30,6 +30,8 @@ import type { InputOptions } from "@babel/core"; import { runScripts } from "./transformScriptTags.ts"; +export * as packages from "./packages.ts"; + // We import this file from another package using a relative path because it's // meant to just be build-time script; it's ok because @babel/standalone is // bundled anyway. diff --git a/packages/babel-standalone/src/packages.ts b/packages/babel-standalone/src/packages.ts new file mode 100644 index 000000000000..93906be44b25 --- /dev/null +++ b/packages/babel-standalone/src/packages.ts @@ -0,0 +1,5 @@ +export * as generator from "@babel/generator"; +export * as parser from "@babel/parser"; +export * as template from "@babel/template"; +export * as traverse from "@babel/traverse"; +export * as types from "@babel/types"; diff --git a/packages/babel-standalone/test/babel.js b/packages/babel-standalone/test/babel.js index c9abc71c02a9..c40bd1921d85 100644 --- a/packages/babel-standalone/test/babel.js +++ b/packages/babel-standalone/test/babel.js @@ -8,6 +8,26 @@ describe("@babel/standalone", () => { Babel = require("../babel.js"); }); + describe("export packages", () => { + it("list", () => { + expect(Object.keys(Babel.packages)).toMatchInlineSnapshot(` + Array [ + "generator", + "parser", + "template", + "traverse", + "types", + ] + `); + }); + + it("they work", () => { + const generate = Babel.packages.generator.default; + const parser = Babel.packages.parser; + expect(generate(parser.parse("foo")).code).toBe("foo;"); + }); + }); + it("handles the es2015-no-commonjs preset", () => { const output = Babel.transform('const getMessage = () => "Hello World"', { presets: ["es2015-no-commonjs"], diff --git a/yarn.lock b/yarn.lock index cb74bd405751..b40e06267f80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4176,6 +4176,8 @@ __metadata: resolution: "@babel/standalone@workspace:packages/babel-standalone" dependencies: "@babel/core": "workspace:^" + "@babel/generator": "workspace:^" + "@babel/parser": "workspace:^" "@babel/plugin-external-helpers": "workspace:^" "@babel/plugin-proposal-decorators": "workspace:^" "@babel/plugin-proposal-destructuring-private": "workspace:^" @@ -4281,6 +4283,9 @@ __metadata: "@babel/preset-flow": "workspace:^" "@babel/preset-react": "workspace:^" "@babel/preset-typescript": "workspace:^" + "@babel/template": "workspace:^" + "@babel/traverse": "workspace:^" + "@babel/types": "workspace:^" acorn: "npm:^8.7.0" jsdom: "npm:^22.1.0" languageName: unknown