Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/neat-candies-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"marko": patch
"@marko/runtime-tags": patch
"@marko/compiler": patch
---

Remove direct dependency on babel, refactor to use internal copy.
3 changes: 1 addition & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ module.exports = (api) => ({
{
loose: true,
targets: {
node: "18",
node: "20",
},
},
],
],
plugins: ["@babel/transform-runtime"],
overrides: [
{
test: "./packages/runtime-class/src/**/*",
Expand Down
796 changes: 554 additions & 242 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,33 @@
"compile": "node -r ~ts scripts/inspect-compiled-output.ts",
"format": "eslint --format unix --fix .; prettier . --write --with-node-modules --log-level=warn",
"lint": "eslint --format unix . && prettier . --check --with-node-modules --log-level=warn",
"prepare": "husky",
"prepare": "husky && patch-package && npm run build-babel-types -w @marko/compiler",
"report": "open ./coverage/lcov-report/index.html",
"test": "mocha",
"test:update": "UPDATE_EXPECTATIONS=1 mocha --update"
},
"devDependencies": {
"@babel/cli": "^7.28.6",
"@babel/code-frame": "^7.29.0",
"@babel/core": "^7.29.0",
"@babel/generator": "^7.29.1",
"@babel/parser": "^7.29.0",
"@babel/plugin-syntax-typescript": "^7.28.6",
"@babel/plugin-transform-modules-commonjs": "^7.28.6",
"@babel/plugin-transform-runtime": "^7.29.0",
"@babel/plugin-transform-typescript": "^7.28.6",
"@babel/preset-env": "^7.29.0",
"@babel/preset-typescript": "^7.28.5",
"@babel/register": "^7.28.6",
"@babel/traverse": "^7.29.0",
"@babel/types": "^7.29.0",
"@changesets/changelog-github": "^0.5.2",
"@changesets/cli": "^2.29.8",
"@ebay/browserslist-config": "^2.13.0",
"@eslint/js": "^9.39.2",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-virtual": "^3.0.2",
"@types/babel__code-frame": "^7.27.0",
"@types/babel__core": "^7.20.5",
"@types/babel__generator": "^7.27.0",
"@types/babel__traverse": "^7.28.0",
"@types/js-beautify": "^1.14.3",
Expand Down Expand Up @@ -67,6 +74,7 @@
"mocha": "^11.7.5",
"mocha-autotest": "^1.1.3",
"mocha-snap": "^5.0.1",
"patch-package": "^8.0.1",
"prettier": "^3.8.1",
"prettier-plugin-packagejson": "^3.0.0",
"pretty-format": "^30.2.0",
Expand Down
22 changes: 22 additions & 0 deletions packages/compiler/internal/babel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./modules.d.ts" />

declare module "@babel/core" {
export const File: any;
}

export { codeFrameColumns } from "@babel/code-frame";
export {
File,
loadPartialConfig,
loadPartialConfigAsync,
transformAsync,
transformSync,
} from "@babel/core";
export { default as generator } from "@babel/generator";
export { parse, parseExpression } from "@babel/parser";
export { default as pluginSyntaxTypeScript } from "@babel/plugin-syntax-typescript";
export { default as pluginTransformModulesCommonjs } from "@babel/plugin-transform-modules-commonjs";
export { default as pluginTransformTypeScript } from "@babel/plugin-transform-typescript";
export { default as traverse } from "@babel/traverse";
export * as types from "@babel/types";
3 changes: 3 additions & 0 deletions packages/compiler/internal/babel/modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "@babel/plugin-syntax-typescript";
declare module "@babel/plugin-transform-modules-commonjs";
declare module "@babel/plugin-transform-typescript";
5 changes: 5 additions & 0 deletions packages/compiler/internal/babel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "index.ts",
"types": "index.ts",
"main:override": "../../dist/babel.js"
}
17 changes: 5 additions & 12 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"types": "./modules.d.ts",
"default": "./modules.js"
},
"./internal/babel": "./internal/babel/index.ts",
"./babel-types": "./babel-types.d.ts",
"./dist/types": "./dist/types.d.ts",
"./package": "./package.json",
Expand All @@ -50,6 +51,7 @@
"types": "index.d.ts",
"files": [
"dist",
"internal",
"config.js",
"config.d.ts",
"modules.js",
Expand All @@ -61,20 +63,10 @@
"register.d.ts"
],
"scripts": {
"build": "babel ./src --out-dir ./dist --copy-files --config-file ../../babel.config.js --env-name=production",
"prepare": "node -r ~ts scripts/types"
"build": "babel ./src --out-dir ./dist --copy-files --config-file ../../babel.config.js --env-name=production && node -r ~ts scripts/build-babel",
"build-babel-types": "node -r ~ts scripts/types"
},
"dependencies": {
"@babel/code-frame": "^7.29.0",
"@babel/core": "^7.29.0",
"@babel/generator": "^7.29.1",
"@babel/parser": "^7.29.0",
"@babel/plugin-syntax-typescript": "^7.28.6",
"@babel/plugin-transform-modules-commonjs": "^7.28.6",
"@babel/plugin-transform-typescript": "^7.28.6",
"@babel/runtime": "^7.28.6",
"@babel/traverse": "^7.29.0",
"@babel/types": "^7.29.0",
"@luxass/strip-json-comments": "^1.4.0",
"complain": "^1.6.1",
"he": "^1.2.0",
Expand Down Expand Up @@ -116,6 +108,7 @@
"default": "./dist/register.js"
},
"./modules": "./modules.js",
"./internal/babel": "./dist/babel.js",
"./babel-types": "./babel-types.d.ts",
"./dist/types": "./dist/types.d.ts",
"./package": "./package.json",
Expand Down
18 changes: 18 additions & 0 deletions packages/compiler/scripts/build-babel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { build } from "esbuild";
import path from "path";

const absWorkingDir = path.join(__dirname, "..");

build({
format: "cjs",
bundle: true,
absWorkingDir,
outfile: "dist/babel.js",
sourcemap: false,
platform: "node",
external: ["browserslist"],
entryPoints: ["internal/babel/index.ts"],
}).catch((err) => {
console.error(err);
process.exit(1);
});
2 changes: 0 additions & 2 deletions packages/compiler/scripts/types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "../src/babel-types/types/patch";

import fs from "fs";

import babelTraverseCode from "./types/babel-traverse";
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler/scripts/types/babel-traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

***********************************************************************************************/

import { MARKO_TYPES } from "@babel/types";
import fs from "fs";

import { MARKO_TYPES } from "../../src/babel-types/types/definitions";

const HUB_INTERFACE = "export interface HubInterface {";
const HUB_CLASS =
"export class Hub implements HubInterface {\n constructor();";
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/babel-plugin/file.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "@babel/core";
import { File } from "@marko/compiler/internal/babel";

import { buildCodeFrameError } from "../util/build-code-frame";

Expand Down
10 changes: 6 additions & 4 deletions packages/compiler/src/babel-plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import tsTransformPlugin from "@babel/plugin-transform-typescript";
import traverse from "@babel/traverse";
import {
pluginTransformTypeScript,
traverse,
types as t,
} from "@marko/compiler/internal/babel";
import path from "path";

import * as t from "../babel-types";
import { diagnosticError } from "../babel-utils/diagnostics";
import { getFileInternal, setFileInternal } from "../babel-utils/get-file";
import { getTemplateId } from "../babel-utils/tags";
Expand Down Expand Up @@ -49,7 +51,7 @@ export default (api, markoOpts) => {
}

if (markoOpts.stripTypes) {
stripTypesVisitor ||= tsTransformPlugin(api, {
stripTypesVisitor ||= pluginTransformTypeScript(api, {
isTSX: false,
allowNamespaces: true,
allowDeclareFields: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/babel-plugin/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
parseTypeParams,
parseVar,
} from "@marko/compiler/babel-utils";
import { types as t } from "@marko/compiler/internal/babel";
import { createParser, TagType } from "htmljs-parser";

import * as t from "../babel-types";
import { buildCodeFrameError } from "../util/build-code-frame";
import throwAggregateError from "../util/merge-errors";

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/babel-plugin/plugins/migrate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTagDef, getTagDefForTagName } from "@marko/compiler/babel-utils";
import { types as t } from "@marko/compiler/internal/babel";

import * as t from "../../babel-types";
import { enter, exit } from "../util/plugin-hooks";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/babel-plugin/plugins/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTagDef, getTagDefForTagName } from "@marko/compiler/babel-utils";
import { types as t } from "@marko/compiler/internal/babel";

import * as t from "../../babel-types";
import { enter, exit } from "../util/plugin-hooks";

/**
Expand Down
Loading