Skip to content

Commit

Permalink
Export babel tooling packages in @babel/standalone (#11696)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicol貌 Ribaudo <hello@nicr.dev>
  • Loading branch information
ajihyf and nicolo-ribaudo committed Feb 28, 2024
1 parent bd5abd5 commit 8e6c506
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/babel-standalone/package.json
Expand Up @@ -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:^",
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-standalone/src/index.ts
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions 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";
20 changes: 20 additions & 0 deletions packages/babel-standalone/test/babel.js
Expand Up @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -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:^"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e6c506

Please sign in to comment.