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
16 changes: 0 additions & 16 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 22.x
cache: yarn
- name: Install
run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent
Expand Down
5 changes: 5 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
["@babel/preset-env", { "targets": { "node": 22 } }]
]
}
36 changes: 21 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.6",
"description": "A Babel preset that targets modern browsers by fixing engine bugs.",
"main": "lib/index.js",
"type": "module",
"license": "MIT",
"scripts": {
"start": "concurrently -r 'npm:watch:* -s'",
Expand Down Expand Up @@ -43,6 +44,7 @@
}
},
"jest": {
"runner": "jest-light-runner",
"testEnvironment": "node",
"roots": [
"src",
Expand All @@ -64,19 +66,19 @@
"Jason Miller <jason@developit.ca>"
],
"peerDependencies": {
"@babel/core": "^7.0.0-0 || ^8.0.0-0 <8.0.0"
"@babel/core": "^8.0.0"
},
"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/helper-fixtures": "^7.6.3",
"@babel/helper-plugin-test-runner": "^7.14.5",
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
"@babel/plugin-transform-react-jsx": "^7.7.0",
"@babel/preset-env": "^7.9.6",
"@babel/cli": "^8.0.1",
"@babel/core": "^8.0.1",
"@babel/helper-fixtures": "^8.0.1",
"@babel/helper-plugin-test-runner": "^8.0.0",
"@babel/plugin-transform-modules-commonjs": "^8.0.1",
"@babel/plugin-transform-react-jsx": "^8.0.1",
"@babel/preset-env": "^8.0.1",
"acorn-jsx": "^5.0.1",
"babel-eslint": "^10.0.3",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-external-helpers": "npm:@babel/plugin-external-helpers@^8.0.1",
"chalk": "^2.4.2",
"concurrently": "^4.1.0",
"eslint": "^6.6.0",
Expand All @@ -86,21 +88,25 @@
"eslint-plugin-prettier": "^3.1.1",
"gzip-size": "^5.1.1",
"if-env": "^1.0.4",
"jest": "^24.8.0",
"jest": "^30.4.2",
"jest-light-runner": "^0.7.12",
"karmatic": "^1.4.0",
"prettier": "^1.19.1",
"pretty-bytes": "^5.2.0",
"@rollup/plugin-babel": "^5.3.1",
"rollup": "^1.16.3",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-node-resolve": "^5.2.0",
"terser": "^4.0.2",
"webpack": "^4.35.0"
},
"dependencies": {
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/plugin-proposal-unicode-property-regex": "^7.4.4",
"@babel/plugin-transform-dotall-regex": "^7.4.4",
"@babel/types": "^7.4.4",
"@babel/helper-plugin-utils": "^8.0.1",
"@babel/plugin-transform-unicode-property-regex": "^8.0.1",
"@babel/plugin-transform-dotall-regex": "^8.0.1",
"@babel/types": "^8.0.0",
"esutils": "^2.0.2"
},
"resolutions": {
"chokidar": "npm:@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3"
}
}
29 changes: 15 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import path from "path";
import { declare } from "@babel/helper-plugin-utils";
import { fileURLToPath } from "url";

// import.meta.resolve returns a file:// URL, but Babel resolves plugins with
// require.resolve when transforming synchronously, which only accepts paths.
const resolve = specifier => fileURLToPath(import.meta.resolve(specifier));

/**
* @babel/preset-modules produces clean, minimal output for ES Modules-supporting browsers.
* @param {Object} [options]
* @param {boolean} [options.loose=false] Loose mode skips seldom-needed transforms that increase output size.
*/
export default declare((api, opts) => {
api.assertVersion(7);
api.assertVersion("^8.0.0");

const loose = opts.loose === true;

return {
plugins: [
path.resolve(__dirname, "./plugins/transform-edge-default-parameters"),
path.resolve(__dirname, "./plugins/transform-tagged-template-caching"),
path.resolve(__dirname, "./plugins/transform-jsx-spread"),
path.resolve(__dirname, "./plugins/transform-safari-for-shadowing"),
path.resolve(__dirname, "./plugins/transform-safari-block-shadowing"),
path.resolve(__dirname, "./plugins/transform-async-arrows-in-class"),
!loose &&
path.resolve(__dirname, "./plugins/transform-edge-function-name"),

// Proposals
require.resolve("@babel/plugin-proposal-unicode-property-regex"),
require.resolve("@babel/plugin-transform-dotall-regex"),
resolve("./plugins/transform-edge-default-parameters/index.js"),
resolve("./plugins/transform-tagged-template-caching/index.js"),
resolve("./plugins/transform-jsx-spread/index.js"),
resolve("./plugins/transform-safari-for-shadowing/index.js"),
resolve("./plugins/transform-safari-block-shadowing/index.js"),
resolve("./plugins/transform-async-arrows-in-class/index.js"),
!loose && resolve("./plugins/transform-edge-function-name/index.js"),
resolve("@babel/plugin-transform-unicode-property-regex"),
resolve("@babel/plugin-transform-dotall-regex"),
].filter(Boolean),
};
});
2 changes: 1 addition & 1 deletion test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`@babel/preset-modules should pass a smoke test 1`] = `
"const foo = async (tag, { a: _a = 1 }, { data: { props: _props = 1 } }, ...children) => {
Expand Down
4 changes: 2 additions & 2 deletions test/_util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promisify } from "util";
import fs, { mkdir } from "fs";
import path from "path";
import { transform } from "@babel/core";
import { transformSync } from "@babel/core";
import gzipSize from "gzip-size";
import terser from "terser";
import chalk from "chalk";
Expand All @@ -23,7 +23,7 @@ export function dent(...args) {
}

export function babel(code, config) {
return transform(code, {
return transformSync(code, {
...options,
...config,
})
Expand Down
6 changes: 3 additions & 3 deletions test/external/safari-await-negation.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { transform } from "@babel/core";
import preset from "../..";
import { transformSync } from "@babel/core";
import preset from "../../lib/index.js";

const CONFIG = {
babelrc: false,
Expand All @@ -10,7 +10,7 @@ const CONFIG = {
};

function babel(code) {
return transform(code, CONFIG).code;
return transformSync(code, CONFIG).code;
}

// https://bugs.webkit.org/show_bug.cgi?id=176685
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import runner from "@babel/helper-plugin-test-runner";

runner(__dirname);
runner(import.meta.url);
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class Foo {
constructor() {
var _arguments = arguments;

this.x = async function () {
return await _arguments[0];
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class Foo {
return await 1;
};
}

bar() {
(async function () {})();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ class Foo {
return await 1;
});
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class Foo {
constructor() {
var _this = this;

this.x = () => async function () {
return await _this;
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ class Foo {
constructor() {
this.x = () => {};
}

}
2 changes: 0 additions & 2 deletions test/fixtures/transform-async-arrows-in-class/this/output.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class Foo {
constructor() {
var _this = this;

this.x = async function () {
return await _this;
};
}

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
const a = function a() {
a;
};

const _b = function b() {
_b = 1;
};

const _c = function c() {
_c;
};

_c = 1;

const _d = function d() {
return function () {
return () => {
_d = 1;
};
};
};

const _e = function e() {
_e;
};

() => {
_e = 1;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
h("div", { ...props,
h("div", {
...props,
b: "hi"
}, "a");
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
h("div", { ...a,
h("div", {
...a,
...b
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
h("div", { ...props
});
h("div", props);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/transform-jsx-spread/leading/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/transform-jsx-spread/lone/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/transform-jsx-spread/middle/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/transform-jsx-spread/multiple/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/transform-jsx-spread/nested/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "classic",
"pragma": "h"
}
]
Expand Down
Loading
Loading