Compare commits
13 Commits
2021-10-de
...
initialize
| Author | SHA1 | Date | |
|---|---|---|---|
| 41fd81a8f5 | |||
| bfa97fe782 | |||
| 1518210ee6 | |||
| b1facb18de | |||
| 2c38b52ffb | |||
| 44e7cf615c | |||
| 983ab3bbc0 | |||
| 05dfb60683 | |||
|
|
a8e859bb05 | ||
| f3c530b2c9 | |||
| a12f1771c8 | |||
| fad999bf52 | |||
| 2707780f7e |
@@ -1,13 +1,23 @@
|
||||
version: 2.1
|
||||
|
||||
aliases:
|
||||
- &restore-node-modules-cache
|
||||
keys:
|
||||
- v1-yarn-deps-{{ checksum "yarn.lock" }}
|
||||
|
||||
- &restore-yarn-cache
|
||||
key: v2-yarn-cache-{{ checksum "yarn.lock" }}
|
||||
keys:
|
||||
- v1-yarn-cache
|
||||
|
||||
- &save-node-modules-cache
|
||||
paths:
|
||||
- node_modules
|
||||
key: v1-yarn-deps-{{ checksum "yarn.lock" }}
|
||||
|
||||
- &save-yarn-cache
|
||||
paths:
|
||||
- ~/.yarn/berry/cache
|
||||
key: v2-yarn-cache-{{ checksum "yarn.lock" }}
|
||||
- ~/.yarn-cache
|
||||
key: v1-yarn-cache
|
||||
|
||||
- &artifact_babel
|
||||
path: ~/babel/packages/babel-standalone/babel.js
|
||||
@@ -15,6 +25,12 @@ aliases:
|
||||
- &artifact_babel_min
|
||||
path: ~/babel/packages/babel-standalone/babel.min.js
|
||||
|
||||
- &artifact_env
|
||||
path: ~/babel/packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
|
||||
- &artifact_env_min
|
||||
path: ~/babel/packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
|
||||
- &test262_workdir
|
||||
working_directory: ~/babel/babel-test262-runner
|
||||
|
||||
@@ -30,17 +46,12 @@ aliases:
|
||||
executors:
|
||||
node-executor:
|
||||
docker:
|
||||
- image: cimg/node:current
|
||||
- image: circleci/node:13
|
||||
working_directory: ~/babel
|
||||
# e2e-vue-cli test requires chromium
|
||||
node-browsers-executor:
|
||||
docker:
|
||||
- image: cimg/node:current-browsers
|
||||
working_directory: ~/babel
|
||||
# e2e-jest test requires python
|
||||
node-python-executor:
|
||||
docker:
|
||||
- image: cimg/python:3.9-node
|
||||
- image: circleci/node:13-browsers
|
||||
working_directory: ~/babel
|
||||
|
||||
jobs:
|
||||
@@ -49,6 +60,7 @@ jobs:
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache: *restore-yarn-cache
|
||||
- restore_cache: *restore-node-modules-cache
|
||||
# Builds babel-standalone with the regular Babel config
|
||||
# test-ci-coverage doesn't test babel-standalone, as trying to gather coverage
|
||||
- run: IS_PUBLISH=true make -j build-standalone-ci
|
||||
@@ -57,6 +69,9 @@ jobs:
|
||||
- run: yarn jest "\-standalone/test"
|
||||
- store_artifacts: *artifact_babel
|
||||
- store_artifacts: *artifact_babel_min
|
||||
- store_artifacts: *artifact_env
|
||||
- store_artifacts: *artifact_env_min
|
||||
- save_cache: *save-node-modules-cache
|
||||
- save_cache: *save-yarn-cache
|
||||
|
||||
test262:
|
||||
@@ -64,30 +79,29 @@ jobs:
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Sync with latest main branch (only on PRs)
|
||||
name: Sync with latest master branch (only on PRs)
|
||||
command: |
|
||||
if [ -n "$CIRCLE_PULL_REQUEST" ]
|
||||
then
|
||||
# $CIRCLE_PR_NUMBER is not always defined:
|
||||
# https://support.circleci.com/hc/en-us/articles/360047521451-Why-is-CIRCLE-PR-NUMBER-empty-
|
||||
git fetch origin refs/pull/${CIRCLE_PULL_REQUEST##*/}/merge
|
||||
git fetch origin refs/pull/$CIRCLE_PR_NUMBER/merge
|
||||
git checkout -qf FETCH_HEAD
|
||||
fi
|
||||
- restore_cache: *restore-yarn-cache
|
||||
- restore_cache: *restore-node-modules-cache
|
||||
- run:
|
||||
name: Build Babel
|
||||
command: BABEL_ENV=test make bootstrap
|
||||
- run:
|
||||
name: Setup Test Runner
|
||||
command: |
|
||||
git clone --depth=1 --recurse-submodules https://github.com/babel/babel-test262-runner
|
||||
git clone --recurse-submodules https://github.com/babel/babel-test262-runner
|
||||
cd babel-test262-runner
|
||||
npm ci
|
||||
npm i tap-mocha-reporter --save-dev
|
||||
yarn
|
||||
yarn add tap-mocha-reporter --dev
|
||||
node lib/download-node
|
||||
- run:
|
||||
name: Download main branch Test262 artifact
|
||||
command: node lib/download-main-artifact ~/test262-main.tap
|
||||
name: Download master branch Test262 artifact
|
||||
command: node lib/download-master-artifact ~/master.tap
|
||||
<<: *test262_workdir
|
||||
- run:
|
||||
name: Run Test262
|
||||
@@ -100,159 +114,95 @@ jobs:
|
||||
cat ~/test262.tap | $(npm bin)/tap-mocha-reporter spec || true
|
||||
<<: *test262_workdir
|
||||
- run:
|
||||
name: Compare previous main branch & current job results
|
||||
name: Compare previous master branch & current job results
|
||||
command: |
|
||||
mkdir -p ~/test-results/test262
|
||||
node lib/compare-results ~/test262-main.tap ~/test262.tap | tee ~/diff.tap
|
||||
node lib/compare-results ~/master.tap ~/test262.tap | tee ~/diff.tap
|
||||
<<: *test262_workdir
|
||||
- store_artifacts: *artifact_test262_diff_tap
|
||||
- run:
|
||||
name: Output comparison results and report to CircleCI
|
||||
name: Output comparision results and report to CircleCI
|
||||
command: |
|
||||
mkdir -p ~/test-results/test262
|
||||
cat ~/diff.tap | $(npm bin)/tap-merge | $(npm bin)/tap-mocha-reporter xunit | tee ~/test-results/test262/results.xml
|
||||
<<: *test262_workdir
|
||||
- store_test_results: *artifact_test262_xunit
|
||||
- save_cache: *save-node-modules-cache
|
||||
- save_cache: *save-yarn-cache
|
||||
|
||||
publish-verdaccio-babel-8-breaking:
|
||||
publish-verdaccio:
|
||||
executor: node-executor
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache: *restore-yarn-cache
|
||||
- run: BABEL_8_BREAKING=true ./scripts/integration-tests/publish-local.sh
|
||||
- run: yarn install
|
||||
- run: ./scripts/integration-tests/publish-local.sh
|
||||
- persist_to_workspace:
|
||||
root: /tmp/verdaccio-workspace
|
||||
paths:
|
||||
- storage
|
||||
- htpasswd
|
||||
- save_cache: *save-yarn-cache
|
||||
|
||||
e2e-breaking-babel:
|
||||
e2e-babel:
|
||||
executor: node-executor
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: /tmp/verdaccio-workspace
|
||||
- run: BABEL_8_BREAKING=true ./scripts/integration-tests/e2e-babel.sh
|
||||
- run: ./scripts/integration-tests/e2e-babel.sh
|
||||
|
||||
e2e-breaking-create-react-app:
|
||||
e2e-create-react-app:
|
||||
executor: node-executor
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: /tmp/verdaccio-workspace
|
||||
- run: BABEL_8_BREAKING=true ./scripts/integration-tests/e2e-create-react-app.sh
|
||||
- run: ./scripts/integration-tests/e2e-create-react-app.sh
|
||||
|
||||
e2e-breaking-vue-cli:
|
||||
e2e-vue-cli:
|
||||
executor: node-browsers-executor
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: /tmp/verdaccio-workspace
|
||||
- run:
|
||||
# - vue-cli uses puppeteer, and it depends on the libXss.so.1 shared library
|
||||
# - We use fuser (psmisc) in local-registry.sh, and for some reason it's
|
||||
# missing in this Docker image
|
||||
name: Install Headless Chrome dependencies
|
||||
command: sudo apt-get update && sudo apt-get install -yq libxss1 psmisc
|
||||
- run: BABEL_8_BREAKING=true ./scripts/integration-tests/e2e-vue-cli.sh
|
||||
|
||||
e2e-breaking-jest:
|
||||
executor: node-python-executor
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: /tmp/verdaccio-workspace
|
||||
- run: BABEL_8_BREAKING=true ./scripts/integration-tests/e2e-jest.sh
|
||||
|
||||
e2e-breaking-prettier:
|
||||
executor: node-executor
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: /tmp/verdaccio-workspace
|
||||
- run: BABEL_8_BREAKING=true ./scripts/integration-tests/e2e-prettier.sh
|
||||
- run: ./scripts/integration-tests/e2e-vue-cli.sh
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
build-standalone:
|
||||
jobs:
|
||||
- build-standalone
|
||||
# test262:
|
||||
# jobs:
|
||||
# - test262:
|
||||
# filters:
|
||||
# branches:
|
||||
# only:
|
||||
# - main
|
||||
# - next-8-dev
|
||||
# - next-8-rebased
|
||||
# context: babel-test262
|
||||
# test262-pr:
|
||||
# jobs:
|
||||
# - approve-test262-run:
|
||||
# type: approval
|
||||
# filters:
|
||||
# branches:
|
||||
# ignore:
|
||||
# - main
|
||||
# - master
|
||||
# - next-8-dev
|
||||
# - next-8-rebased
|
||||
# - test262:
|
||||
# requires:
|
||||
# - approve-test262-run
|
||||
# filters:
|
||||
# branches:
|
||||
# ignore:
|
||||
# - main
|
||||
# - master
|
||||
# - next-8-dev
|
||||
# - next-8-rebased
|
||||
# context: babel-test262
|
||||
|
||||
e2e-breaking:
|
||||
test262-master:
|
||||
jobs:
|
||||
- publish-verdaccio-babel-8-breaking:
|
||||
- test262:
|
||||
filters:
|
||||
branches:
|
||||
only: [main, next-8-dev, next-8-rebased]
|
||||
- e2e-breaking-babel:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-create-react-app:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-vue-cli:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-jest:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
|
||||
e2e-breaking-pr:
|
||||
only:
|
||||
- master
|
||||
test262:
|
||||
jobs:
|
||||
- approve-e2e-breaking-run:
|
||||
- approve-test262-run:
|
||||
type: approval
|
||||
filters:
|
||||
branches:
|
||||
ignore: [main, next-8-dev, next-8-rebased]
|
||||
- publish-verdaccio-babel-8-breaking:
|
||||
ignore:
|
||||
- master
|
||||
- test262:
|
||||
requires:
|
||||
- approve-e2e-breaking-run
|
||||
- e2e-breaking-babel:
|
||||
- approve-test262-run
|
||||
filters:
|
||||
branches:
|
||||
ignore:
|
||||
- master
|
||||
e2e:
|
||||
jobs:
|
||||
- publish-verdaccio
|
||||
- e2e-babel:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-create-react-app:
|
||||
- publish-verdaccio
|
||||
- e2e-create-react-app:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-vue-cli:
|
||||
- publish-verdaccio
|
||||
- e2e-vue-cli:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-jest:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- e2e-breaking-prettier:
|
||||
requires:
|
||||
- publish-verdaccio-babel-8-breaking
|
||||
- publish-verdaccio
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"buildCommand": "codesandbox:build",
|
||||
"sandboxes": ["7s08o", "vhm64"],
|
||||
"packages": ["packages/*"],
|
||||
"node": "14"
|
||||
"installCommand": "bootstrap",
|
||||
"buildCommand": false,
|
||||
"sandboxes": ["kypop"]
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/build
|
||||
/.git
|
||||
package.json
|
||||
lerna.json
|
||||
packages/babel-runtime
|
||||
!packages/babel-plugin-transform-runtime/scripts
|
||||
packages/babel-runtime-corejs2
|
||||
@@ -16,16 +17,15 @@ codemods/*/lib
|
||||
codemods/*/dist
|
||||
codemods/*/test/fixtures
|
||||
codemods/*/test/tmp
|
||||
packages/babel-compat-data/build
|
||||
packages/babel-preset-env/data/[^(plugin-features|shipped-proposals).js]
|
||||
packages/babel-preset-env/test/debug-fixtures
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-standalone/babel.min.js
|
||||
packages/babel-parser/test/expressions
|
||||
|
||||
eslint/*/lib
|
||||
eslint/*/node_modules
|
||||
eslint/*/test/fixtures
|
||||
|
||||
test/runtime-integration/*/output.js
|
||||
test/runtime-integration/*/output-absolute.js
|
||||
eslint/*/test
|
||||
eslint/*/tests
|
||||
|
||||
163
.eslintrc.cjs
163
.eslintrc.cjs
@@ -1,163 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const cjsGlobals = ["__dirname", "__filename", "require", "module", "exports"];
|
||||
|
||||
const testFiles = [
|
||||
"packages/*/test/**/*.js",
|
||||
"codemods/*/test/**/*.js",
|
||||
"eslint/*/test/**/*.js",
|
||||
];
|
||||
const sourceFiles = exts => [
|
||||
`packages/*/src/**/*.{${exts}}`,
|
||||
`codemods/*/src/**/*.{${exts}}`,
|
||||
`eslint/*/src/**/*.{${exts}}`,
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
plugins: [
|
||||
"import",
|
||||
"node",
|
||||
"jest",
|
||||
"prettier",
|
||||
"@babel/development",
|
||||
"@babel/development-internal",
|
||||
],
|
||||
extends: "@babel/internal",
|
||||
rules: {
|
||||
"prettier/prettier": "error",
|
||||
"import/no-extraneous-dependencies": "error",
|
||||
},
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ["**/*.ts"],
|
||||
parser: "@typescript-eslint/parser",
|
||||
plugins: ["@typescript-eslint"],
|
||||
rules: {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"no-dupe-class-members": "off",
|
||||
"@typescript-eslint/no-dupe-class-members": "error",
|
||||
"no-undef": "off",
|
||||
"no-redeclare": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: sourceFiles("js,ts,cjs,mjs"),
|
||||
rules: {
|
||||
"@babel/development/no-undefined-identifier": "error",
|
||||
"@babel/development/no-deprecated-clone": "error",
|
||||
"guard-for-in": "error",
|
||||
"import/extensions": ["error", { json: "always", cjs: "always" }],
|
||||
},
|
||||
globals: { PACKAGE_JSON: "readonly" },
|
||||
},
|
||||
{
|
||||
files: [
|
||||
...testFiles,
|
||||
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
|
||||
"test/**/*.js",
|
||||
],
|
||||
env: {
|
||||
jest: true,
|
||||
},
|
||||
extends: "plugin:jest/recommended",
|
||||
rules: {
|
||||
"jest/expect-expect": "off",
|
||||
"jest/no-identical-title": "off",
|
||||
"jest/no-standalone-expect": "off",
|
||||
"jest/no-test-callback": "off",
|
||||
"jest/valid-describe": "off",
|
||||
"import/extensions": ["error", "always"],
|
||||
"import/no-extraneous-dependencies": "off",
|
||||
"no-restricted-imports": ["error", { patterns: ["**/src/**"] }],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: testFiles,
|
||||
rules: {
|
||||
"node/no-unsupported-features": [
|
||||
"error",
|
||||
{ version: "12.17.0", ignores: ["modules"] },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [...sourceFiles("js,ts,mjs"), ...testFiles, "test/**/*.js"],
|
||||
excludedFiles: [
|
||||
// @babel/register is the require() hook, so it will always be CJS-based
|
||||
"packages/babel-register/**/*.{js,ts}",
|
||||
],
|
||||
rules: {
|
||||
"no-restricted-globals": ["error", ...cjsGlobals],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["packages/babel-plugin-*/src/index.{js,ts}"],
|
||||
excludedFiles: ["packages/babel-plugin-transform-regenerator/**/*.js"],
|
||||
rules: {
|
||||
"@babel/development/plugin-name": "error",
|
||||
eqeqeq: ["error", "always", { null: "ignore" }],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["packages/babel-parser/src/**/*.{js,ts}"],
|
||||
rules: {
|
||||
"@babel/development-internal/dry-error-messages": [
|
||||
"error",
|
||||
{
|
||||
errorModule: path.resolve(
|
||||
__dirname,
|
||||
"packages/babel-parser/src/parser/error.js"
|
||||
),
|
||||
},
|
||||
],
|
||||
"@babel/development-internal/report-error-message-format": "error",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["packages/babel-helpers/src/helpers/**.js"],
|
||||
rules: {
|
||||
"no-var": "off",
|
||||
"comma-dangle": "off",
|
||||
"no-func-assign": "off",
|
||||
"import/no-extraneous-dependencies": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["packages/babel-traverse/scripts/**/*.js"],
|
||||
rules: {
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{ packageDir: "./packages/babel-traverse" },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["eslint/babel-eslint-parser/src/**/*.js"],
|
||||
rules: {
|
||||
"no-restricted-imports": ["error", "@babel/core"],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["packages/babel-plugin-transform-runtime/scripts/**/*.js"],
|
||||
rules: {
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{ packageDir: "./packages/babel-plugin-transform-runtime" },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["scripts/**/*.js"],
|
||||
rules: {
|
||||
"import/no-extraneous-dependencies": ["error", { packageDir: "." }],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
48
.eslintrc.js
Normal file
48
.eslintrc.js
Normal file
@@ -0,0 +1,48 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
plugins: ["prettier", "@babel/development", "import"],
|
||||
extends: "babel",
|
||||
rules: {
|
||||
"prettier/prettier": "error",
|
||||
// TODO: remove after babel-eslint-config-internal is fully integrated into this repository.
|
||||
"max-len": "off",
|
||||
},
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: [
|
||||
"packages/*/src/**/*.js",
|
||||
"codemods/*/src/**/*.js",
|
||||
"eslint/*/src/**/*.js",
|
||||
],
|
||||
rules: {
|
||||
"@babel/development/no-undefined-identifier": "error",
|
||||
"@babel/development/no-deprecated-clone": "error",
|
||||
"import/no-extraneous-dependencies": "error",
|
||||
"guard-for-in": "error",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
"packages/*/test/**/*.js",
|
||||
"codemods/*/test/**/*.js",
|
||||
"eslint/*/test/**/*.js",
|
||||
"packages/babel-helper-transform-fixture-test-runner/src/helpers.js",
|
||||
"test/**/*.js",
|
||||
],
|
||||
env: {
|
||||
jest: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["packages/babel-plugin-*/src/index.js"],
|
||||
excludedFiles: ["packages/babel-plugin-transform-regenerator/**/*.js"],
|
||||
rules: {
|
||||
"@babel/development/plugin-name": "error",
|
||||
eqeqeq: ["error", "always", { null: "ignore" }],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
11
.flowconfig
11
.flowconfig
@@ -5,8 +5,6 @@
|
||||
<PROJECT_ROOT>/codemods/.*/lib
|
||||
<PROJECT_ROOT>/codemods/.*/test
|
||||
<PROJECT_ROOT>/node_modules/module-deps/
|
||||
<PROJECT_ROOT>/node_modules/webpack-cli/
|
||||
<PROJECT_ROOT>/test/runtime-integration/
|
||||
|
||||
[include]
|
||||
packages/*/src
|
||||
@@ -16,11 +14,7 @@ codemods/*/src
|
||||
lib/file.js
|
||||
lib/parser.js
|
||||
lib/third-party-libs.js.flow
|
||||
lib/preset-modules.js.flow
|
||||
lib/babel-polyfills.js.flow
|
||||
packages/babel-types/lib/index.js.flow
|
||||
lib/babel-packages.js.flow
|
||||
lib/package-json.js.flow
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
@@ -32,7 +26,4 @@ suppress_type=$FlowSubtype
|
||||
esproposal.export_star_as=enable
|
||||
esproposal.optional_chaining=enable
|
||||
esproposal.nullish_coalescing=enable
|
||||
module.name_mapper='^@babel/\([a-zA-Z0-9_-]+\)$' -> '<PROJECT_ROOT>/packages/babel-\1/src/index'
|
||||
; Todo: can not make it works, 🤷♂️
|
||||
; module.name_mapper='^@babel/plugin-syntax-import-meta$' -> '<PROJECT_ROOT>/packages/babel-standalone/node_modules/@babel/plugin-syntax-import-meta/lib/index'
|
||||
module.ignore_non_literal_requires=true
|
||||
module.name_mapper='^@babel\/\([a-zA-Z0-9_\-]+\)$' -> '<PROJECT_ROOT>/packages/babel-\1/src/index'
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
# git-blame ignored revisions
|
||||
# To configure, run
|
||||
# git config blame.ignoreRevsFile .git-blame-ignore-revs
|
||||
# Requires Git > 2.23
|
||||
# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt
|
||||
|
||||
# Use prettier (#600)
|
||||
5180ecdca48e486b4b0f347fcbd752f865df5e55
|
||||
|
||||
# Update prettier to v2 (#11579)
|
||||
41085248560b1403b8d0f99f108491e679531c6c
|
||||
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1,2 +1 @@
|
||||
* text eol=lf
|
||||
/.yarn/** linguist-vendored
|
||||
|
||||
6
.github/ISSUE_TEMPLATE.md
vendored
Normal file
6
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
<!---
|
||||
Thanks for filing an issue 😄 ! Before you submit, please read the following:
|
||||
|
||||
Check the other issue templates if you are trying to submit a bug report, feature request, or question
|
||||
Search open/closed issues before submitting since someone might have asked the same thing before!
|
||||
-->
|
||||
57
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
57
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
name: "\U0001F41B Bug Report"
|
||||
about: "If something isn't working as expected \U0001F914."
|
||||
title: ''
|
||||
labels: 'i: bug, i: needs triage'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## Bug Report
|
||||
|
||||
<!-- Check this if you would like to implement a PR, we are more than happy to help you go through the process !-->
|
||||
- [ ] I would like to work on a fix!
|
||||
|
||||
<!--
|
||||
@babel/eslint-parser:
|
||||
If you are having issues with JSX you might want to check out eslint-plugin-react. If there's an issue with new experimental syntax you might need check if it's supported by @babel/eslint-plugin.
|
||||
-->
|
||||
|
||||
**Current Behavior**
|
||||
A clear and concise description of the behavior.
|
||||
|
||||
**Input Code**
|
||||
- REPL or Repo link if applicable:
|
||||
|
||||
```js
|
||||
var your => (code) => here;
|
||||
```
|
||||
|
||||
**Expected behavior/code**
|
||||
A clear and concise description of what you expected to happen (or code).
|
||||
|
||||
**Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)**
|
||||
- Filename: `babel.config.js`
|
||||
|
||||
```js
|
||||
{
|
||||
"your": { "config": "here" }
|
||||
}
|
||||
```
|
||||
|
||||
**Environment**
|
||||
<!--- Tip: Instead of filling out the questions below, you can run `npx envinfo --preset babel` and paste the result below ``` -->
|
||||
```
|
||||
|
||||
```
|
||||
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
|
||||
- Node/npm version: [e.g. Node 8/npm 5]
|
||||
- OS: [e.g. OSX 10.13.4, Windows 10]
|
||||
- Monorepo: [e.g. yes/no/Lerna]
|
||||
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
|
||||
|
||||
**Possible Solution**
|
||||
<!--- If you have suggestions on a fix for the bug -->
|
||||
|
||||
**Additional context/Screenshots**
|
||||
Add any other context about the problem here. If applicable, add screenshots to help explain.
|
||||
26
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: "\U0001F680 Feature Request"
|
||||
about: "I have a suggestion (and may want to implement it \U0001F642)!"
|
||||
title: ''
|
||||
labels: 'i: enhancement, i: needs triage'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## Feature Request
|
||||
|
||||
<!-- Check this if you would like to implement a PR, we are more than happy to help you go through the process !-->
|
||||
- [ ] I would like to work on this feature!
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I have an issue when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen. Add any considered drawbacks.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Teachability, Documentation, Adoption, Migration Strategy**
|
||||
If you can, explain how users will be able to use this and possibly write out a version the docs.
|
||||
Maybe a screenshot or design?
|
||||
52
.github/ISSUE_TEMPLATE/Regression-v7.md
vendored
Normal file
52
.github/ISSUE_TEMPLATE/Regression-v7.md
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: "\U0001F4A5 v7 Regression"
|
||||
about: Report an unexpected behavior in v7 from v6 (Check the upgrade guide first
|
||||
✌️)
|
||||
title: ''
|
||||
labels: 'i: bug, 7.x: regression, i: needs triage'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
# v7 Regression
|
||||
|
||||
<!-- Check this if you would like to implement a PR, we are more than happy to help you go through the process !-->
|
||||
- [ ] I would like to work on a fix!
|
||||
|
||||
> First check out: https://babeljs.io/docs/en/v7-migration
|
||||
> Also a partial upgrade tool: https://github.com/babel/babel-upgrade
|
||||
|
||||
**Potential Commit/PR that introduced the regression**
|
||||
If you have time to investigate, what PR/date introduced this issue.
|
||||
|
||||
**Describe the regression**
|
||||
A clear and concise description of what the regression is.
|
||||
|
||||
**Input Code**
|
||||
<!--- If you have link to our REPL or a standalone repo please link that! -->
|
||||
|
||||
```js
|
||||
var your => (code) => here;
|
||||
```
|
||||
|
||||
**Expected behavior/code**
|
||||
A clear and concise description of what you expected to happen (or code).
|
||||
|
||||
**Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command)**
|
||||
|
||||
```js
|
||||
{
|
||||
"your": { "config": "here" }
|
||||
}
|
||||
```
|
||||
|
||||
**Environment**
|
||||
<!--- Tip: Instead of filling out the questions below, you can run `npx envinfo --preset babel` and paste the result below ``` -->
|
||||
```
|
||||
|
||||
```
|
||||
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
|
||||
- Node/npm version: [e.g. Node 8/npm 5]
|
||||
- OS: [e.g. OSX 10.13.4, Windows 10]
|
||||
- Monorepo [e.g. yes/no/Lerna]
|
||||
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
|
||||
19
.github/ISSUE_TEMPLATE/Support_question.md
vendored
Normal file
19
.github/ISSUE_TEMPLATE/Support_question.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: "\U0001F917 Support Question"
|
||||
about: "If you have a question \U0001F4AC, please check out our Slack or StackOverflow!"
|
||||
title: ''
|
||||
labels: 'i: question, i: needs triage'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
--------------^ Click "Preview" for a nicer view!
|
||||
We primarily use GitHub as an issue tracker; for usage and support questions, please check out these resources below. Thanks! 😁.
|
||||
|
||||
---
|
||||
|
||||
* Slack Community Chat: https://babeljs.slack.com (you can sign-up at https://slack.babeljs.io/ for an invite)
|
||||
* StackOverflow: https://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`
|
||||
* Twitter: If it's just a quick question you can ping our Twitter: https://twitter.com/babeljs
|
||||
* Also have a look at the readme for more information on how to get support:
|
||||
https://github.com/babel/babel/blob/master/README.md
|
||||
28
.github/ISSUE_TEMPLATE/Support_us.md
vendored
Normal file
28
.github/ISSUE_TEMPLATE/Support_us.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: "\U0001F91D Support us on Babel"
|
||||
about: "If you would like to support our efforts in maintaining this community-driven
|
||||
project \U0001F64C!"
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
--------------^ Click "Preview" for a nicer view!
|
||||
> Open Collective: https://opencollective.com/babel
|
||||
> Henry's Patreon: https://www.patreon.com/henryzhu
|
||||
|
||||
Help support Babel!
|
||||
|
||||
Babel has always been a community project, not really backed or owned by any single (or group) of companies. While some maintainers used to work at Facebook (and Henry at Adobe) no one was working on it full time and there certainly isn't a huge company or team anywhere doing all this work.
|
||||
|
||||
---
|
||||
|
||||
As a group of volunteers you can help us in a few ways
|
||||
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/) for guidance). Companies should be paying their employees to contribute back to the open source projects they use everyday.
|
||||
- Giving funds by becoming one of our sponsors/donators!
|
||||
|
||||
If you'd like to sustain the future of the project as a whole, we have an [Open Collective](https://opencollective.com/babel) that you can donate to. This is a way for funds to be allocated to the core team.
|
||||
|
||||
You can also support [Henry](https://github.com/hzoo) directly since I [left my job to work on Babel and Open Source full time](https://twitter.com/left_pad/status/969793227862790144) at my [Patreon](https://www.patreon.com/henryzhu).
|
||||
109
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
109
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -1,109 +0,0 @@
|
||||
name: "🐛 Bug Report"
|
||||
description: "If something isn't working as expected 🤔."
|
||||
title: "[Bug]: "
|
||||
labels: ["i: needs triage"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: Thanks for taking the time to file a bug report! Please fill out this form as completely as possible.
|
||||
|
||||
- type: checkboxes
|
||||
id: input1
|
||||
attributes:
|
||||
label: "💻"
|
||||
options:
|
||||
- label: Would you like to work on a fix?
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: How are you using Babel?
|
||||
options:
|
||||
- babel-loader (webpack)
|
||||
- "@rollup/plugin-babel"
|
||||
- "@babel/eslint-parser"
|
||||
- "@babel/cli"
|
||||
- "@babel/register or @babel/node"
|
||||
- Programmatic API (`babel.transform`, `babel.parse`)
|
||||
- Other (Next.js, Gatsby, vue-cli, ...)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Input code
|
||||
description: |
|
||||
You must write here the minimal input code necessary to reproduce the bug.
|
||||
Even better, you can share a link to the Babel [REPL](https://babel.dev/repl):
|
||||
this will make it easier for us to reproduce the issue, and it may help fixing
|
||||
the bug sooner.
|
||||
If it's not possible to reproduce the bug with a single file, a GitHub Repository
|
||||
is also ok.
|
||||
placeholder: |
|
||||
```js
|
||||
var your => (code) => here;
|
||||
```
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Configuration file name
|
||||
description: |
|
||||
**NOTE**: If it's possible that Babel is not correctly loading your config, it's probably because you are using
|
||||
`.babelrc`/`package.json` instead of `babel.config.json`.
|
||||
multiple: true
|
||||
options:
|
||||
- babel.config.json
|
||||
- babel.config.js
|
||||
- babel.config.cjs
|
||||
- babel.config.mjs
|
||||
- .babelrc.json
|
||||
- .babelrc.js
|
||||
- .babelrc.cjs
|
||||
- .babelrc.mjs
|
||||
- .babelrc
|
||||
- package.json
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Configuration
|
||||
description: |
|
||||
**Tip:** You can also run Babel with the environment variable SHOW_CONFIG_FOR=your_file_path to print all configs associated with a path.
|
||||
See https://babeljs.io/docs/en/configuration#print-effective-configs for more information
|
||||
placeholder: |
|
||||
```json
|
||||
{
|
||||
"your": { "config": "here" }
|
||||
}
|
||||
```
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Current and expected behavior
|
||||
description: A clear and concise description of what Babel is doing and what you would expect.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Environment
|
||||
description: |
|
||||
**Tip:** you can run `npx envinfo --preset babel` and paste the result below
|
||||
placeholder: |
|
||||
- Babel version(s): [e.g. v7.12.0]
|
||||
- Node: [e.g. Node 15]
|
||||
- npm/Yarn version: [e.g. npm 7/Yarn 2.3]
|
||||
- OS: [e.g. macOS 10.15.4, Windows 10]
|
||||
- Monorepo: [e.g. yes/no/Lerna]
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Possible solution
|
||||
description: "If you have suggestions on a fix for the bug."
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: "Add any other context about the problem here. Or a screenshot if applicable."
|
||||
14
.github/ISSUE_TEMPLATE/config.yml
vendored
14
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,14 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 📦 "No matching version found"
|
||||
url: https://gist.github.com/hzoo/df94af2d2ec48696e683b772c775aa67
|
||||
about: You may have an npm error related to proxies/caching.
|
||||
- name: 🗣 Ask a Question, Discuss
|
||||
url: https://github.com/babel/babel/discussions
|
||||
about: How does X work 🤔? I made this! I have an idea...
|
||||
- name: 💡 Propose an RFC
|
||||
url: https://github.com/babel/rfcs
|
||||
about: To suggest a new option or substantial change.
|
||||
- name: 🤗 Support the Project
|
||||
url: https://github.com/sponsors/babel
|
||||
about: Support the Babel team financially.
|
||||
44
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
44
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@@ -1,44 +0,0 @@
|
||||
name: "🚀 Feature Request"
|
||||
description: "I have a specific suggestion for Babel!"
|
||||
labels: ["i: needs triage", "i: enhancement"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: Thanks for taking the time to suggest a new feature! Please fill out this form as completely as possible.
|
||||
|
||||
- type: checkboxes
|
||||
id: input1
|
||||
attributes:
|
||||
label: "💻"
|
||||
description: |
|
||||
Check this if you would like to implement a PR, we are more than happy to help you go through the process
|
||||
options:
|
||||
- label: Would you like to work on this feature?
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: What problem are you trying to solve?
|
||||
description: |
|
||||
A concise description of what the problem is.
|
||||
placeholder: |
|
||||
I have an issue when [...]
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe the solution you'd like
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Documentation, Adoption, Migration Strategy
|
||||
description: |
|
||||
If you can, explain how users will be able to use this and how it might be documented. Maybe a mock-up?
|
||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,6 +1,6 @@
|
||||
<!--
|
||||
Before making a PR, please read our contributing guidelines
|
||||
https://github.com/babel/babel/blob/main/CONTRIBUTING.md
|
||||
https://github.com/babel/babel/blob/master/CONTRIBUTING.md
|
||||
|
||||
Please note that the Babel Team requires two approvals before merging most PRs.
|
||||
|
||||
|
||||
12
.github/lock.yml
vendored
Normal file
12
.github/lock.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# Configuration for lock-threads - https://github.com/dessant/lock-threads
|
||||
|
||||
# Number of days of inactivity before a closed issue or pull request is locked
|
||||
daysUntilLock: 91
|
||||
# Comment to post before locking. Set to `false` to disable
|
||||
lockComment: false
|
||||
# The label to be applied when an issue is locked
|
||||
lockLabel: 'outdated'
|
||||
|
||||
# Issues or pull requests with these labels will not be locked
|
||||
# exemptLabels:
|
||||
# - no-locking
|
||||
462
.github/workflows/ci.yml
vendored
462
.github/workflows/ci.yml
vendored
@@ -1,462 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
prepare-yarn-cache:
|
||||
name: Prepare Cache
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
yarn-
|
||||
- name: 'Check or update Yarn cache (fix w/ "yarn install")'
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false # disable post-install scripts
|
||||
YARN_NODE_LINKER: pnp # use pnp linker for better linking performance: it's meant to update yarn cache only
|
||||
run: |
|
||||
yarn install --mode=skip-build
|
||||
|
||||
yarn-validate:
|
||||
name: Validate Yarn dependencies and constraints
|
||||
needs: prepare-yarn-cache
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- name: 'Check for unmet constraints (fix w/ "yarn constraints --fix")'
|
||||
run: |
|
||||
yarn constraints
|
||||
- name: 'Check for duplicate dependencies (fix w/ "yarn dedupe")'
|
||||
if: steps.yarn-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
yarn dedupe --check
|
||||
- name: Check for dependency cycles
|
||||
run: |
|
||||
yarn release-tool check-cycles
|
||||
|
||||
test-coverage:
|
||||
name: Test on Node.js Latest
|
||||
needs: prepare-yarn-cache
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 17
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
make -j test-ci-coverage
|
||||
yarn test:esm
|
||||
- name: Upload coverage report
|
||||
uses: codecov/codecov-action@v1
|
||||
|
||||
build:
|
||||
name: Build Babel Artifacts
|
||||
needs: prepare-yarn-cache
|
||||
runs-on: ubuntu-latest
|
||||
# Yarn PnP does not support native ESM yet (https://github.com/yarnpkg/berry/issues/638)
|
||||
# env:
|
||||
# YARN_NODE_LINKER: pnp # use pnp linker for better linking performance and stricter checks
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
yarn-
|
||||
- name: Build babel artifacts
|
||||
run: |
|
||||
BABEL_ENV=test-legacy make -j build-standalone-ci
|
||||
env:
|
||||
BABEL_8_BREAKING: false
|
||||
STRIP_BABEL_8_FLAG: true
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
path: |
|
||||
codemods/*/lib/**/*
|
||||
eslint/*/lib/**/*
|
||||
packages/*/lib/**/*
|
||||
packages/babel-standalone/*.js
|
||||
!**/node_modules/**
|
||||
|
||||
lint:
|
||||
name: Lint
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Install
|
||||
run: yarn install
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
- name: Lint
|
||||
run: make -j tscheck flowcheck-ci lint-ci
|
||||
|
||||
test:
|
||||
name: Test on Node.js # GitHub will add ${{ matrix.node-version }} to this title
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16, 14, 12, 10, 8, 6]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest # Run yarn on latest node
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*" # Build Babel on latest node LTS versions
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Install
|
||||
run: |
|
||||
yarn install
|
||||
- name: Downgrade Jest for node <= 8
|
||||
if: matrix.node-version == '6' || matrix.node-version == '8'
|
||||
run: |
|
||||
yarn remove jest
|
||||
yarn add --dev jest@24
|
||||
# Deduplicate dependencies, because duplicate copies of graceful-fs cause
|
||||
# problems with the "path" module: https://github.com/facebook/jest/issues/9656
|
||||
yarn dedupe
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
- name: Generate runtime helpers
|
||||
run: |
|
||||
make build-plugin-transform-runtime-dist
|
||||
- name: Use Node.js ${{ matrix.node-version }} # Checkout node version for test executor
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Test on node.js ${{ matrix.node-version }}
|
||||
# Hack: --color has supports-color@5 returned true for GitHub CI
|
||||
# Remove once `chalk` is bumped to 4.0.
|
||||
|
||||
# Todo(Babel 8): Jest execution path is hardcoded because Yarn 2 does not support node 6
|
||||
run: |
|
||||
BABEL_ENV=test node ./node_modules/.bin/jest --ci --color
|
||||
|
||||
test-babel-8-breaking:
|
||||
name: Test Babel 8 breaking changes
|
||||
needs: prepare-yarn-cache
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js 12
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 12 # Node.js 12 is the first LTS supported by Babel 8
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Install and build
|
||||
run: make -j bootstrap
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
BABEL_8_BREAKING: true
|
||||
STRIP_BABEL_8_FLAG: true
|
||||
- name: Lint
|
||||
run: make lint
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
BABEL_8_BREAKING: true
|
||||
BABEL_TYPES_8_BREAKING: true
|
||||
- name: Test
|
||||
# Hack: --color has supports-color@5 returned true for GitHub CI
|
||||
# Remove once `chalk` is bumped to 4.0.
|
||||
run: |
|
||||
yarn jest --ci --color
|
||||
yarn test:esm
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
BABEL_8_BREAKING: true
|
||||
BABEL_TYPES_8_BREAKING: true
|
||||
|
||||
test-windows:
|
||||
name: Test on Windows
|
||||
needs: build
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Install
|
||||
run: yarn install
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
- name: Generate runtime helpers
|
||||
run: |
|
||||
make build-plugin-transform-runtime-dist
|
||||
- name: Test on Windows
|
||||
# Hack: --color has supports-color@5 returned true for GitHub CI
|
||||
# Remove once `chalk` is bumped to 4.0.
|
||||
run: yarn jest --ci --color
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
|
||||
external-parser-tests:
|
||||
name: Third-party Parser Tests
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Install
|
||||
run: yarn install
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
- name: Download tests
|
||||
run: make -j bootstrap-flow bootstrap-typescript bootstrap-test262
|
||||
- name: Run Test262 Tests
|
||||
run: make test-test262
|
||||
- name: Run Flow Tests
|
||||
run: make test-flow
|
||||
- name: Run TypeScript Tests
|
||||
run: make test-typescript
|
||||
|
||||
runtime-interop:
|
||||
name: Test @babel/runtime integrations
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
# See https://github.com/babel/babel/pull/12906
|
||||
- name: Support self-references on old Node.js
|
||||
run: |
|
||||
echo '{
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@babel/runtime": "workspace:*",
|
||||
"@babel/runtime-corejs3": "workspace:*"
|
||||
}
|
||||
}' > packages/package.json
|
||||
node -e "
|
||||
const pkg = require('./package.json');
|
||||
pkg.workspaces.push('packages');
|
||||
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))
|
||||
"
|
||||
- name: Install
|
||||
run: yarn install
|
||||
env:
|
||||
# The "Support self-references on old Node.js" step mutates the
|
||||
# package.json file, causing a yarn.lock update.
|
||||
YARN_ENABLE_IMMUTABLE_INSTALLS: false
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
- name: Generate runtime helpers
|
||||
run: |
|
||||
make build-plugin-transform-runtime-dist
|
||||
- name: Generate absoluteRuntime tests
|
||||
run: yarn test:runtime:generate-absolute-runtime
|
||||
- name: Test bundlers
|
||||
run: yarn test:runtime:bundlers
|
||||
- name: Test Node.js
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 10
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 10
|
||||
- name: Test Node.js 10
|
||||
run: node test/runtime-integration/node.cjs
|
||||
- name: Use Node.js 12.0
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "12.0" # quoted, otherwise it's just 13
|
||||
- name: Test Node.js 12.0
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 12.17
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 12.17
|
||||
- name: Test Node.js 12.17
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 13.0
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "13.0" # quoted, otherwise it's just 13
|
||||
- name: Test Node.js 13.0
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 13.2
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 13.2
|
||||
- name: Test Node.js 13.2
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 13.6
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 13.6
|
||||
- name: Test Node.js 13.6
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 13.7
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 13.7
|
||||
- name: Test Node.js 13.7
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 14.2
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 14.2
|
||||
- name: Test Node.js 14.2
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 16.5
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 16.5
|
||||
- name: Test Node.js 16.5
|
||||
run: yarn test:runtime:node
|
||||
- name: Use Node.js 16.6
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 16.6
|
||||
- name: Test Node.js 16.6
|
||||
run: yarn test:runtime:node
|
||||
|
||||
e2e-publish:
|
||||
name: Publish to local Verdaccio registry
|
||||
needs: prepare-yarn-cache
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- name: Setup Yarn cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Publish
|
||||
run: ./scripts/integration-tests/publish-local.sh
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: verdaccio-workspace
|
||||
path: /tmp/verdaccio-workspace
|
||||
|
||||
e2e-tests:
|
||||
name: E2E
|
||||
needs: e2e-publish
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
project:
|
||||
- babel
|
||||
- babel-old-version
|
||||
- create-react-app
|
||||
- vue-cli
|
||||
- jest
|
||||
- react-native
|
||||
- prettier
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: verdaccio-workspace
|
||||
path: /tmp/verdaccio-workspace
|
||||
- name: Test
|
||||
run: ./scripts/integration-tests/e2e-${{ matrix.project }}.sh
|
||||
29
.github/workflows/coverage.yml
vendored
Normal file
29
.github/workflows/coverage.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: Report Coverage
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [13.x]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Environment log
|
||||
id: env
|
||||
run: |
|
||||
yarn --version
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
yarn --version
|
||||
make -j test-ci-coverage
|
||||
- name: Upload coverage report
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
2
.github/workflows/issue-triage.yml
vendored
2
.github/workflows/issue-triage.yml
vendored
@@ -35,7 +35,7 @@ jobs:
|
||||
|
||||
If you need any help, or just have general Babel or JavaScript questions, we have a
|
||||
vibrant [Slack community](https://babeljs.slack.com) that typically always has someone
|
||||
willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite.
|
||||
willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite."
|
||||
|
||||
needs_info:
|
||||
name: Needs Info
|
||||
|
||||
17
.github/workflows/lock.yml
vendored
17
.github/workflows/lock.yml
vendored
@@ -1,17 +0,0 @@
|
||||
name: Lock Threads
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 4 * * *'
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v2
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-lock-inactive-days: '91'
|
||||
issue-lock-labels: 'outdated'
|
||||
pr-lock-inactive-days: '91'
|
||||
pr-lock-labels: 'outdated'
|
||||
143
.github/workflows/release.yml
vendored
143
.github/workflows/release.yml
vendored
@@ -3,116 +3,14 @@ name: Release
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
# This input isn't actually used as an input, but it's a reminder that
|
||||
# this workflow can only automatically push patch versions.
|
||||
# This is because often minor versions require human intervention, so
|
||||
# it's safer if we force ourselves to always create them locally.
|
||||
description: ⚠️ This workflow can only automatically release patch versions
|
||||
required: true
|
||||
default: patch
|
||||
|
||||
jobs:
|
||||
log-updates:
|
||||
name: Log packages to publish
|
||||
github_release:
|
||||
name: Trigger GitHub release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the new tag
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: This release will publish the following packages
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
yarn release-tool version --dry patch
|
||||
else
|
||||
git diff --name-only HEAD^..HEAD
|
||||
fi;
|
||||
|
||||
git-version:
|
||||
name: Create git tag and commit
|
||||
runs-on: ubuntu-latest
|
||||
needs: log-updates
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
outputs:
|
||||
branch: ${{ steps.push.outputs.branch }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set @babel-bot as committer
|
||||
run: |
|
||||
git config user.name "Babel Bot"
|
||||
git config user.email "babel-bot@users.noreply.github.com"
|
||||
|
||||
- name: Create new version
|
||||
run: |
|
||||
make new-version-checklist
|
||||
yarn release-tool version -f @babel/standalone --yes patch
|
||||
|
||||
- name: Push to GitHub
|
||||
id: push
|
||||
run: |
|
||||
branch="release/temp/$(git describe --abbrev=0)"
|
||||
echo $branch
|
||||
echo "::set-output name=branch::$branch"
|
||||
|
||||
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:"$branch" --follow-tags
|
||||
|
||||
npm-release:
|
||||
name: Build, Test and Publish
|
||||
runs-on: ubuntu-latest
|
||||
needs: git-version
|
||||
environment: npm
|
||||
# The default condition is success(), but this is false when one of the previous jobs is skipped
|
||||
if: |
|
||||
always() &&
|
||||
(needs.git-version.result == 'success' || needs.git-version.result == 'skipped')
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Checkout the temporary branch
|
||||
if: needs.git-version.result == 'success'
|
||||
run: git checkout ${{ needs.git-version.outputs.branch }}
|
||||
|
||||
- name: Build and Test
|
||||
run: make prepublish
|
||||
|
||||
- name: Publish to npm
|
||||
run: yarn release-tool publish --yes
|
||||
env:
|
||||
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
github-release:
|
||||
name: Create GitHub release draft
|
||||
runs-on: ubuntu-latest
|
||||
needs: git-version
|
||||
# The default condition is success(), but this is false when one of the previous jobs is skipped
|
||||
if: |
|
||||
always() &&
|
||||
(needs.git-version.result == 'success' || needs.git-version.result == 'skipped')
|
||||
outputs:
|
||||
is-main: ${{ steps.is-main.outputs.result == 1 }}
|
||||
changelog: ${{ steps.changelog.outputs.changelog }}
|
||||
version: ${{ steps.tags.outputs.new }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check if releasing from main
|
||||
id: is-main
|
||||
uses: babel/actions/ref-matches-branch@v2
|
||||
with:
|
||||
name: main
|
||||
|
||||
- name: Checkout the temporary branch
|
||||
if: needs.git-version.result == 'success'
|
||||
run: git checkout ${{ needs.git-version.outputs.branch }}
|
||||
uses: actions/checkout@v1.0.0
|
||||
|
||||
- name: Get tag info
|
||||
id: tags
|
||||
@@ -134,39 +32,22 @@ jobs:
|
||||
changelog: ${{ steps.changelog.outputs.changelog }}
|
||||
token: ${{ secrets.BOT_TOKEN }}
|
||||
|
||||
github-push:
|
||||
name: Push release commit to "main"
|
||||
runs-on: ubuntu-latest
|
||||
needs: [npm-release, github-release, git-version]
|
||||
# The default condition is success(), but this is false when one of the previous jobs is skipped
|
||||
if: |
|
||||
always() &&
|
||||
needs.npm-release.result == 'success' &&
|
||||
needs.github-release.result == 'success' &&
|
||||
needs.github-release.outputs.is-main
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Check if releasing from master
|
||||
id: is_master
|
||||
uses: babel/actions/ref-matches-branch@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Checkout the temporary branch
|
||||
if: needs.git-version.result == 'success'
|
||||
run: git checkout ${{ needs.git-version.outputs.branch }}
|
||||
name: master
|
||||
|
||||
- name: Update CHANGELOG.md
|
||||
if: steps.is_master.outputs.result == 1
|
||||
uses: babel/actions/update-changelog@v2
|
||||
with:
|
||||
changelog: ${{ needs.github-release.outputs.changelog }}
|
||||
changelog: ${{ steps.changelog.outputs.changelog }}
|
||||
|
||||
- name: Commit CHANGELOG.md
|
||||
if: steps.is_master.outputs.result == 1
|
||||
run: |
|
||||
git add CHANGELOG.md
|
||||
git -c user.name="Babel Bot" -c user.email="babel-bot@users.noreply.github.com" \
|
||||
commit -m "Add ${{ needs.github-release.outputs.version }} to CHANGELOG.md [skip ci]" --no-verify --quiet
|
||||
|
||||
- name: Push to GitHub
|
||||
run: |
|
||||
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:main --follow-tags
|
||||
|
||||
- name: Delete temporary branch from GitHub
|
||||
if: needs.git-version.result == 'success'
|
||||
run: git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" :${{ needs.git-version.outputs.branch }}
|
||||
commit -m "Add ${{ steps.tags.outputs.new }} to CHANGELOG.md [skip ci]" --no-verify --quiet
|
||||
git push "https://babel-bot:${{ secrets.BOT_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" master
|
||||
|
||||
90
.github/workflows/update-parser-tests.yml
vendored
90
.github/workflows/update-parser-tests.yml
vendored
@@ -1,90 +0,0 @@
|
||||
name: Update Test262 parser tests
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false # disable post-install scripts
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs: {}
|
||||
schedule:
|
||||
- cron: "0 0 * * 5"
|
||||
|
||||
jobs:
|
||||
createPullRequest:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
repository: tc39/test262
|
||||
path: build/test262
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: "*"
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
yarn-
|
||||
- name: Get latest test262 version
|
||||
id: test262
|
||||
run: echo "::set-output name=sha1::$(sh ./scripts/parser-tests/get-test262-version.sh)"
|
||||
- name: Update test262 commit
|
||||
run: |
|
||||
echo ${{ steps.test262.outputs.sha1 }} | ./scripts/parser-tests/bump-test262-version.sh
|
||||
- name: Build babel parser
|
||||
run: |
|
||||
yarn install --immutable --mode=skip-build
|
||||
yarn gulp build-rollup
|
||||
- name: Update test262 allow list
|
||||
run: |
|
||||
make test-test262-update-allowlist
|
||||
- name: Commit changes
|
||||
run: |
|
||||
git config user.name "Babel Bot"
|
||||
git config user.email "babel-bot@users.noreply.github.com"
|
||||
git checkout -b update-test262-parser
|
||||
git commit -am "chore: update test262 to ${{ steps.test262.outputs.sha1 }}"
|
||||
git push --force origin update-test262-parser
|
||||
- name: Create Pull Request
|
||||
uses: actions/github-script@v4
|
||||
with:
|
||||
github-token: ${{ secrets.BOT_TOKEN }}
|
||||
script: |
|
||||
const base = process.env.GITHUB_REF.replace("refs/heads/", "");
|
||||
const requestParam = {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
head: context.repo.owner + ":update-test262-parser",
|
||||
base: base,
|
||||
state: "open"
|
||||
};
|
||||
const result = await github.pulls.list(requestParam);
|
||||
console.log("Open PR request: ", requestParam);
|
||||
console.log("Open PR response: ", result);
|
||||
const prs = result.data;
|
||||
if (prs.length === 0) {
|
||||
const requestParam = {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
head: "update-test262-parser",
|
||||
base: base,
|
||||
maintainer_can_modify: true,
|
||||
title: "Update test262",
|
||||
body: "Update test262 to [${{ steps.test262.outputs.sha1 }}](https://github.com/tc39/test262/commit/${{ steps.test262.outputs.sha1 }}).",
|
||||
};
|
||||
const result = await github.pulls.create(requestParam);
|
||||
console.log("Create PR request: ", requestParam)
|
||||
console.log("Create PR response: ", result);
|
||||
|
||||
github.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: result.data.number,
|
||||
labels: ["area: test262", "repo automation :robot:"]
|
||||
})
|
||||
}
|
||||
75
.github/workflows/update-windows-fixtures.yml
vendored
75
.github/workflows/update-windows-fixtures.yml
vendored
@@ -1,75 +0,0 @@
|
||||
name: Update Windows Fixtures
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
pull_request:
|
||||
description: Pull Request number
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
update-windows-fixtures:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Get Pull Request branch
|
||||
uses: actions/github-script@v4
|
||||
id: pr-meta
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const { data: pullRequest } = await github.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: ${{ github.event.inputs.pull_request }},
|
||||
});
|
||||
|
||||
const {
|
||||
ref: branch,
|
||||
repo: { full_name: repository }
|
||||
} = pullRequest.head;
|
||||
|
||||
console.log(`::set-output name=branch::${branch}`);
|
||||
console.log(`::set-output name=repository::${repository}`);
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: ${{ steps.pr-meta.outputs.repository }}
|
||||
ref: ${{ steps.pr-meta.outputs.branch }}
|
||||
fetch-depth: 0 # Otherwise we cannot push
|
||||
persist-credentials: false # So that we can push with BOT_TOKEN, otherwise it doesn't trigger CI
|
||||
|
||||
- name: Use Node.js latest
|
||||
uses: actions/setup-node@v2-beta
|
||||
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
id: cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
|
||||
- name: Install and build
|
||||
# make bootstrap modifies some files (babel-runtime-*/package.json), so we reset them
|
||||
run: |
|
||||
make -j bootstrap
|
||||
git reset --hard HEAD
|
||||
|
||||
- name: Regenerate fixtures
|
||||
# Hack: --color has supports-color@5 returned true for GitHub CI
|
||||
# Remove once `chalk` is bumped to 4.0.
|
||||
run: |
|
||||
yarn jest -u --ci --color || true
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
OVERWRITE: true
|
||||
|
||||
- name: Commit updates
|
||||
run: |
|
||||
git config user.name "Babel Bot"
|
||||
git config user.email "babel-bot@users.noreply.github.com"
|
||||
git add .
|
||||
git commit -m "Update fixtures (Windows)" --no-verify --quiet
|
||||
git push "https://babel-bot:${{ secrets.BOT_TOKEN }}@github.com/${{ steps.pr-meta.outputs.repository }}.git" ${{ steps.pr-meta.outputs.branch }}
|
||||
37
.gitignore
vendored
37
.gitignore
vendored
@@ -1,14 +1,9 @@
|
||||
.npmrc
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.js
|
||||
|
||||
.DS_Store
|
||||
**/node_modules
|
||||
!**/test/fixtures/**/node_modules
|
||||
/node_modules
|
||||
/.github/actions/*/node_modules
|
||||
/packages/*/node_modules
|
||||
/packages/*/LICENSE
|
||||
!/packages/babel-parser/LICENSE
|
||||
!/packages/babel-plugin-transform-object-assign/LICENSE
|
||||
@@ -16,6 +11,8 @@
|
||||
*.cache
|
||||
/build
|
||||
/.eslintcache
|
||||
/browser.js
|
||||
/browser-polyfill.js
|
||||
/runtime.js
|
||||
coverage
|
||||
dist
|
||||
@@ -28,38 +25,29 @@ package-lock.json
|
||||
/packages/babel-runtime/helpers/*.js
|
||||
!/packages/babel-runtime/helpers/toArray.js
|
||||
!/packages/babel-runtime/helpers/iterableToArray.js
|
||||
!/packages/babel-runtime/helpers/possibleConstructorReturn.js
|
||||
!/packages/babel-runtime/helpers/temporalRef.js
|
||||
!/packages/babel-runtime/helpers/typeof.js
|
||||
/packages/babel-runtime/helpers/esm/*.js
|
||||
!/packages/babel-runtime/helpers/esm/toArray.js
|
||||
!/packages/babel-runtime/helpers/esm/iterableToArray.js
|
||||
!/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js
|
||||
!/packages/babel-runtime/helpers/esm/temporalRef.js
|
||||
|
||||
/packages/babel-runtime-corejs2/helpers/*.js
|
||||
!/packages/babel-runtime-corejs2/helpers/toArray.js
|
||||
!/packages/babel-runtime-corejs2/helpers/iterableToArray.js
|
||||
!/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js
|
||||
!/packages/babel-runtime-corejs2/helpers/temporalRef.js
|
||||
!/packages/babel-runtime-corejs2/helpers/typeof.js
|
||||
/packages/babel-runtime-corejs2/helpers/esm/*.js
|
||||
!/packages/babel-runtime-corejs2/helpers/esm/toArray.js
|
||||
!/packages/babel-runtime-corejs2/helpers/esm/iterableToArray.js
|
||||
!/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js
|
||||
!/packages/babel-runtime-corejs2/helpers/esm/temporalRef.js
|
||||
/packages/babel-runtime-corejs2/core-js/**/*.js
|
||||
!/packages/babel-runtime-corejs2/core-js/map.js
|
||||
|
||||
/packages/babel-runtime-corejs3/helpers/*.js
|
||||
!/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js
|
||||
/packages/babel-runtime-corejs3/helpers/esm/*.js
|
||||
!/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js
|
||||
/packages/babel-runtime-corejs3/core-js/**/*.js
|
||||
/packages/babel-runtime-corejs3/core-js-stable/**/*.js
|
||||
|
||||
/packages/babel-register/test/.cache.babel
|
||||
/packages/babel-register/test/.index.babel
|
||||
/packages/babel-register/test/.babel
|
||||
/packages/babel-cli/test/tmp
|
||||
/packages/babel-node/test/tmp
|
||||
/packages/*/lib
|
||||
@@ -68,19 +56,16 @@ package-lock.json
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-standalone/babel.js.map
|
||||
packages/babel-standalone/babel.min.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js.map
|
||||
packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
/codemods/*/lib
|
||||
/codemods/*/node_modules
|
||||
/packages/babel-parser/build
|
||||
.idea/
|
||||
/.changelog
|
||||
|
||||
/eslint/*/lib
|
||||
/eslint/*/node_modules
|
||||
/eslint/*/LICENSE
|
||||
!/packages/babel-eslint-plugin/LICENSE
|
||||
/.vscode
|
||||
# local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
|
||||
/.history
|
||||
|
||||
/dts
|
||||
|
||||
/test/runtime-integration/*/output.js
|
||||
/test/runtime-integration/*/absolute-output.js
|
||||
|
||||
40
.gitpod.yml
40
.gitpod.yml
@@ -1,40 +0,0 @@
|
||||
# List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/
|
||||
tasks:
|
||||
- init: make bootstrap
|
||||
command: make watch
|
||||
- openMode: split-right
|
||||
command: |-
|
||||
clear && echo '
|
||||
Welcome to Gitpod!
|
||||
|
||||
If you haven'\''t forked Babel yet and you want to prepare a PR, you can use
|
||||
the Ctrl+P (or ⌘P) shortcut, type `>Fork` and press ENTER: Gitpod\ will
|
||||
create the fork for you.
|
||||
|
||||
<-- The other terminal is building Babel. It should automatically rebuild
|
||||
when you change a file, so you don'\''t need to worry about it.
|
||||
If it'\''s still building, please wait until it'\''s finished!
|
||||
|
||||
If you want to run the tests, you can run `yarn jest` in this terminal,
|
||||
or filter by package name (for example, `yarn jest babel-parser`).
|
||||
'
|
||||
|
||||
#' # <-- This is just because the gitpod theme has broken syntax highlighting
|
||||
|
||||
github:
|
||||
# https://www.gitpod.io/docs/prebuilds/#configure-prebuilds
|
||||
prebuilds:
|
||||
master: true # enable for the default branch (even if it's not named "master")
|
||||
branches: true
|
||||
pullRequests: true
|
||||
pullRequestsFromForks: true
|
||||
addCheck: true
|
||||
addComment: false
|
||||
addBadge: true
|
||||
addLabel: false
|
||||
|
||||
vscode:
|
||||
extensions:
|
||||
- dbaeumer.vscode-eslint@2.1.5:9Wg0Glx/TwD8ElFBg+FKcQ==
|
||||
- esbenp.prettier-vscode@5.0.0:qca7d0cHbKkrkb5rvNlpcg==
|
||||
- flowtype.flow-for-vscode@1.5.0:AwOT6wgHTF43loZQCAUMLA==
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn lint-staged
|
||||
23
.prettierrc
23
.prettierrc
@@ -5,28 +5,21 @@
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"bracketSpacing": true,
|
||||
"bracketSameLine": false,
|
||||
"jsxBracketSameLine": false,
|
||||
"tabWidth": 2,
|
||||
"printWidth": 80,
|
||||
"overrides": [{
|
||||
"files": [
|
||||
"**/{codemods,eslint,packages}/*/{src,test}/**/*.{js,ts,cjs}"
|
||||
"**/codemods/*/src/**/*.js",
|
||||
"**/codemods/*/test/**/*.js",
|
||||
"**/packages/*/src/**/*.js",
|
||||
"**/packages/*/test/**/*.js",
|
||||
"**/eslint/*/src/**/*.js",
|
||||
"**/eslint/*/test/**/*.js"
|
||||
],
|
||||
"excludeFiles": ["**/packages/babel-helpers/src/helpers/**/*.js"],
|
||||
"options": {
|
||||
"parser": "babel",
|
||||
"trailingComma": "all"
|
||||
}
|
||||
}, {
|
||||
"files": "**/packages/babel-helpers/src/helpers/**/*.js",
|
||||
"options": {
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
}, {
|
||||
"files": [
|
||||
"**/{codemods,eslint,packages}/*/test/fixtures/**/*.{js,ts}"
|
||||
],
|
||||
"options": {
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
67
.travis.yml
Normal file
67
.travis.yml
Normal file
@@ -0,0 +1,67 @@
|
||||
git:
|
||||
depth: 5
|
||||
language: node_js
|
||||
cache:
|
||||
yarn: true
|
||||
|
||||
os: linux
|
||||
|
||||
env:
|
||||
global:
|
||||
- PATH=$HOME/.yarn/bin:$PATH
|
||||
- JOB=test
|
||||
|
||||
install: skip
|
||||
before_script:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install make; fi
|
||||
|
||||
script:
|
||||
- if [ "$JOB" = "test" ]; then make -j test-ci; fi
|
||||
- if [ "$JOB" = "lint" ]; then make -j code-quality-ci; fi
|
||||
- if [ "$JOB" = "babel-parser-flow-tests" ]; then make -j test-flow-ci; fi
|
||||
- if [ "$JOB" = "babel-parser-typescript-tests" ]; then make -j test-typescript-ci; fi
|
||||
- if [ "$JOB" = "babel-parser-test262-tests" ]; then make -j test-test262-ci; fi
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- node_js: "node"
|
||||
env: JOB=lint
|
||||
# We test the latest version on circleci
|
||||
- node_js: "12"
|
||||
# Move `windows` build to be the third since it is slow
|
||||
- os: windows
|
||||
node_js: "node"
|
||||
env:
|
||||
- JOB=test
|
||||
# https://travis-ci.community/t/build-doesnt-finish-after-completing-tests/288/9
|
||||
- YARN_GPG=no
|
||||
cache:
|
||||
yarn: true
|
||||
directories:
|
||||
- $HOME/AppData/Local/Temp/chocolatey
|
||||
# Continue node_js matrix
|
||||
- node_js: "6"
|
||||
- node_js: "10"
|
||||
- node_js: "8"
|
||||
- node_js: "node"
|
||||
env: JOB=babel-parser-flow-tests
|
||||
- node_js: "node"
|
||||
env: JOB=babel-parser-typescript-tests
|
||||
- node_js: "node"
|
||||
env: JOB=babel-parser-test262-tests
|
||||
|
||||
notifications:
|
||||
slack:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
rooms:
|
||||
# Generate with
|
||||
# travis encrypt "babeljs:<token>#activity" --add notifications.slack.rooms
|
||||
# where <token> is from the Slack integration settings.
|
||||
secure: SrwPKRe2AiNAKRo/+2yW/x4zxbWf2FBXuBuuPkdTJVTpWe++Jin1lXYJWTKP1a1i/IbmhffBO9YZcUFbeuXJpRM083vO8VYpyuBMQRqWD+Z3o+ttPlHGOJgnj0nkIcGRk6k7PpyHNnIkixfEJDvbbg9lN1Jswb3xkL8iYIHpuFE=
|
||||
|
||||
branches:
|
||||
except:
|
||||
- /^v\d+\.\d+\.\d+$/
|
||||
@@ -1,28 +0,0 @@
|
||||
See packages/babel-standalone/src/dynamic-require-entrypoint.cjs for the reason for this diff.
|
||||
|
||||
diff --git a/dist/index.es.js b/dist/index.es.js
|
||||
index 81cb408c8482fc7591a3381eb00b46abc9d21b14..1816113246e075ba7ae99638b64f004fd985ec74 100644
|
||||
--- a/dist/index.es.js
|
||||
+++ b/dist/index.es.js
|
||||
@@ -1641,7 +1641,7 @@ function commonjs(options = {}) {
|
||||
const sourceMap = options.sourceMap !== false;
|
||||
|
||||
function transformAndCheckExports(code, id) {
|
||||
- if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) {
|
||||
+ if (isDynamicRequireModulesEnabled && (this.getModuleInfo(id).isEntry || id.endsWith("/dynamic-require-entrypoint.cjs"))) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
code =
|
||||
getDynamicPackagesEntryIntro(dynamicRequireModuleDirPaths, dynamicRequireModuleSet) + code;
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 8ef2184001cb697c6fc2466e9b5fe084c7f1d08c..056ded21d0bb35b8a7c36d1ec50a6ddb5508d386 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -1650,7 +1650,7 @@ function commonjs(options = {}) {
|
||||
const sourceMap = options.sourceMap !== false;
|
||||
|
||||
function transformAndCheckExports(code, id) {
|
||||
- if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) {
|
||||
+ if (isDynamicRequireModulesEnabled && (this.getModuleInfo(id).isEntry || id.endsWith("/dynamic-require-entrypoint.cjs"))) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
code =
|
||||
getDynamicPackagesEntryIntro(dynamicRequireModuleDirPaths, dynamicRequireModuleSet) + code;
|
||||
File diff suppressed because one or more lines are too long
17
.yarn/plugins/@yarnpkg/plugin-conditions.cjs
vendored
17
.yarn/plugins/@yarnpkg/plugin-conditions.cjs
vendored
File diff suppressed because one or more lines are too long
52
.yarn/plugins/@yarnpkg/plugin-constraints.cjs
vendored
52
.yarn/plugins/@yarnpkg/plugin-constraints.cjs
vendored
File diff suppressed because one or more lines are too long
768
.yarn/releases/yarn-3.1.1.cjs
vendored
768
.yarn/releases/yarn-3.1.1.cjs
vendored
File diff suppressed because one or more lines are too long
3
.yarnrc
3
.yarnrc
@@ -1,3 +0,0 @@
|
||||
# Use Yarn 3
|
||||
# This path should always match the one in .yarnrc.yml
|
||||
yarn-path ".yarn/releases/yarn-3.0.2.cjs"
|
||||
38
.yarnrc.yml
38
.yarnrc.yml
@@ -1,38 +0,0 @@
|
||||
conditions:
|
||||
BABEL_8_BREAKING:
|
||||
default: false
|
||||
|
||||
enableGlobalCache: true
|
||||
|
||||
enableTransparentWorkspaces: false
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-babel-release-tool.cjs
|
||||
spec: "https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-babel-release-tool/main/bundles/%40yarnpkg/plugin-babel-release-tool.js"
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-conditions.cjs
|
||||
spec: "https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-conditions/main/bundles/%40yarnpkg/plugin-conditions.js"
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
|
||||
spec: "@yarnpkg/plugin-constraints"
|
||||
|
||||
releaseTool:
|
||||
ignoreChanges:
|
||||
- "*.md"
|
||||
- "*.txt"
|
||||
- test/**
|
||||
- "**/test/**"
|
||||
- codemods/**
|
||||
- "@(!(native-modules|built-ins|plugins|package)).json"
|
||||
implicitDependencies:
|
||||
"@babel/runtime":
|
||||
- "@babel/helpers"
|
||||
"@babel/runtime-corejs2":
|
||||
- "@babel/helpers"
|
||||
"@babel/runtime-corejs3":
|
||||
- "@babel/helpers"
|
||||
|
||||
unsafeHttpWhitelist:
|
||||
- localhost
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.1.1.cjs
|
||||
8636
CHANGELOG.md
8636
CHANGELOG.md
File diff suppressed because one or more lines are too long
@@ -55,9 +55,7 @@ further defined and clarified by project maintainers.
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the Core Team (<team@babeljs.io>), or one or more of the
|
||||
Core Team members (Brian Ng <bng412@gmail.com>, Henry Zhu <hi@henryzoo.com>,
|
||||
Huáng Jùnliàng <jlhwung@gmail.com>, Nicolò Ribaudo <nicolo.ribaudo@gmail.com>). All
|
||||
reported by contacting Henry Zhu <hi@henryzoo.com>, Logan Smyth <loganfsmyth@gmail.com> or one of the other [Babel core team members](https://babeljs.io/team). All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
|
||||
208
CONTRIBUTING.md
208
CONTRIBUTING.md
@@ -1,50 +1,50 @@
|
||||
---
|
||||
|
||||
<p align="center" class="toc">
|
||||
<strong><a href="#setup">Setup</a></strong>
|
||||
|
|
||||
<strong><a href="#running-lintingtests">Running linting/tests</a></strong>
|
||||
|
|
||||
<strong><a href="#writing-tests">Writing tests</a></strong>
|
||||
|
|
||||
<strong><a href="#debugging-code">Debugging code</a></strong>
|
||||
|
|
||||
<strong><a href="#internals">Internals</a></strong>
|
||||
<strong><a href="#setup">Setup</a></strong>
|
||||
|
|
||||
<strong><a href="#running-lintingtests">Running linting/tests</a></strong>
|
||||
|
|
||||
<strong><a href="#writing-tests">Writing tests</a></strong>
|
||||
|
|
||||
<strong><a href="#debugging-code">Debugging code</a></strong>
|
||||
|
|
||||
<strong><a href="#internals">Internals</a></strong>
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are always welcome, no matter how large or small! Before contributing, please read the [code of conduct](https://github.com/babel/babel/blob/main/CODE_OF_CONDUCT.md).
|
||||
|
||||
If you want an already configured online IDE to contribute to Babel, you can use [Gitpod](https://gitpod.io/#https://github.com/babel/babel)!
|
||||
Contributions are always welcome, no matter how large or small. Before
|
||||
contributing, please read the
|
||||
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
## Not sure where to start?
|
||||
|
||||
- If you aren't just making a documentation change, you'll probably want to learn a bit about a few topics.
|
||||
- [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://babeljs.io/docs/en/next/babel-parser.html#output).
|
||||
- Check out [`/doc`](https://github.com/babel/babel/tree/main/doc) for information about Babel's internals
|
||||
- [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://babeljs.io/docs/en/next/babel-parser.html#output).
|
||||
- Check out [`/doc`](https://github.com/babel/babel/tree/master/doc) for information about Babel's internals
|
||||
- Check out [the Babel Plugin Handbook](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-plugin-handbook) - core plugins are written the same way as any other plugin!
|
||||
- Check out [AST Explorer](http://astexplorer.net/#/scUfOmVOG5) to learn more about ASTs or make your own plugin in the browser
|
||||
- When you feel ready to jump into the Babel source code, a good place to start is to look for issues tagged with [help wanted](https://github.com/babel/babel/labels/help%20wanted) and/or [good first issue](https://github.com/babel/babel/labels/good%20first%20issue).
|
||||
- Follow along with what we are working on by joining our [Slack](https://babeljs.slack.com) (you can [sign up here](https://slack.babeljs.io/)
|
||||
- Follow along with what we are working on by joining our [Slack](https://babeljs.slack.com) (you can sign-up [here](https://slack.babeljs.io/)
|
||||
for an invite), following our announcements on [Twitter](https://twitter.com/babeljs), and reading (or participating!) in our [meeting notes](https://github.com/babel/notes).
|
||||
- Check out our [website](http://babeljs.io/) and the [repo](https://github.com/babel/website)
|
||||
- You can contribute by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to babel on CodeTriage](https://www.codetriage.com/babel/babel). [](https://www.codetriage.com/babel/babel)
|
||||
|
||||
## Chat
|
||||
|
||||
Feel free to check out the `#discussion`/`#development` channels on our [Slack](https://babeljs.slack.com) (you can [sign up here](https://slack.babeljs.io/) for an invite). Some of us are always online to chat!
|
||||
Feel free to check out the `#discussion`/`#development` channels on our [Slack](https://slack.babeljs.io) (you can sign-up [here](https://slack.babeljs.io/) for an invite). Some of us are always online to chat!
|
||||
|
||||
## Developing
|
||||
|
||||
_Node_: Check that Node is [installed](https://nodejs.org/en/download/) with version `^12.20 || >= 14.13`. You can check this with `node -v`.
|
||||
**Note:** Versions `< 5.1.10` can't be built.
|
||||
|
||||
_Yarn_: Make sure that Yarn 1 is [installed](https://classic.yarnpkg.com/en/docs/install) with version >= `1.19.0`.
|
||||
Babel is built for Node 6 and up but we develop using Node 8 and yarn. You can check this with `node -v`.
|
||||
|
||||
_Make_: If you are running Windows 10, you'll need to do one of the following:
|
||||
|
||||
- Clone the repository and run the commands inside [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
|
||||
- Install [Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm).
|
||||
Make sure that Yarn is installed with version >= `0.28.0`.
|
||||
Installation instructions can be found here: https://yarnpkg.com/en/docs/install.
|
||||
|
||||
### Setup
|
||||
|
||||
@@ -72,7 +72,7 @@ $ make watch
|
||||
|
||||
to have Babel build itself and incrementally build files on change.
|
||||
|
||||
> You can access the built files for individual packages from `packages/<package-name>/lib`.
|
||||
You can access the built files for individual packages from `packages/<package-name>/lib`.
|
||||
|
||||
If you wish to build a copy of Babel for distribution, then run:
|
||||
|
||||
@@ -82,59 +82,47 @@ $ make build-dist
|
||||
|
||||
### Running linting/tests
|
||||
|
||||
#### Lint
|
||||
You can run lint via:
|
||||
|
||||
```sh
|
||||
# ~6 sec on a MacBook Pro (Mid 2015)
|
||||
$ make lint
|
||||
```
|
||||
|
||||
- You can run eslint's autofix via:
|
||||
You can run eslint's autofix via:
|
||||
|
||||
```sh
|
||||
$ make fix
|
||||
```
|
||||
|
||||
#### Tests + lint for all packages (slow) via:
|
||||
You can run tests + lint for all packages (slow) via:
|
||||
|
||||
```sh
|
||||
# ~46 sec on a MacBook Pro (Mid 2015)
|
||||
$ make test
|
||||
```
|
||||
|
||||
#### All tests:
|
||||
If you just want to run all tests:
|
||||
|
||||
```sh
|
||||
# ~40 sec on a MacBook Pro (Mid 2015)
|
||||
$ make test-only
|
||||
```
|
||||
|
||||
#### Run tests for a specific package
|
||||
Most likely you'll want to focus in on a specific issue.
|
||||
|
||||
When working on an issue, you will most likely want to focus on a particular [packages](https://github.com/babel/babel/tree/main/packages). Using `TEST_ONLY` will only run tests for that specific package.
|
||||
To run tests for a specific package in [packages](https://github.com/babel/babel/tree/master/packages), you can use the `TEST_ONLY` environment variable:
|
||||
|
||||
```sh
|
||||
$ TEST_ONLY=babel-cli make test
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>More options</summary>
|
||||
<code>TEST_ONLY</code> will also match substrings of the package name:
|
||||
`TEST_ONLY` will also match substrings of the package name:
|
||||
|
||||
```sh
|
||||
# Run tests for the @babel/plugin-transform-classes package.
|
||||
$ TEST_ONLY=babel-plugin-transform-classes make test
|
||||
```
|
||||
|
||||
Or you can use Yarn:
|
||||
|
||||
```sh
|
||||
$ yarn jest babel-cli
|
||||
```
|
||||
</details>
|
||||
<br>
|
||||
|
||||
#### Run a subset of tests
|
||||
```sh
|
||||
# Run tests for the @babel/plugin-transform-classes package.
|
||||
$ TEST_ONLY=babel-plugin-transform-classes make test
|
||||
```
|
||||
|
||||
Use the `TEST_GREP` variable to run a subset of tests by name:
|
||||
|
||||
@@ -144,40 +132,17 @@ $ TEST_GREP=transformation make test
|
||||
|
||||
Substitute spaces for hyphens and forward slashes when targeting specific test names:
|
||||
|
||||
For example, for the following path:
|
||||
```sh
|
||||
packages/babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/destructuring-parameters
|
||||
```
|
||||
|
||||
You can use:
|
||||
```sh
|
||||
$ TEST_GREP="arrow functions destructuring parameters" make test
|
||||
```
|
||||
|
||||
Or you can directly use Yarn:
|
||||
```sh
|
||||
$ yarn jest -t "arrow functions destructuring parameters"
|
||||
```
|
||||
|
||||
#### Run test with Node debugger
|
||||
|
||||
To enable the Node.js debugger, set the <code>TEST_DEBUG</code> environment variable:
|
||||
To enable the Node.js debugger added in v6.3.0, set the `TEST_DEBUG` environment variable:
|
||||
|
||||
```sh
|
||||
$ TEST_DEBUG=true make test
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>More options</summary>
|
||||
Or you can directly use Yarn
|
||||
|
||||
```sh
|
||||
$ yarn node --inspect-brk node_modules/jest/bin/jest.js --runInBand
|
||||
```
|
||||
</details>
|
||||
<br>
|
||||
|
||||
You can combine `TEST_DEBUG` with `TEST_GREP` or `TEST_ONLY` to debug a subset of tests. If you plan to stay long in the debugger (which you'll likely do!), you may increase the test timeout by editing [test/testSetupFile.js](https://github.com/babel/babel/blob/main/test/testSetupFile.js).
|
||||
You can combine `TEST_DEBUG` with `TEST_GREP` or `TEST_ONLY` to debug a subset of tests. If you plan to stay long in the debugger (which you'll likely do!), you may increase the test timeout by editing [test/mocha.opts](https://github.com/babel/babel/blob/master/test/mocha.opts).
|
||||
|
||||
To overwrite any test fixtures when fixing a bug or anything, add the env variable `OVERWRITE=true`
|
||||
|
||||
@@ -185,8 +150,6 @@ To overwrite any test fixtures when fixing a bug or anything, add the env variab
|
||||
$ OVERWRITE=true TEST_ONLY=babel-plugin-transform-classes make test-only
|
||||
```
|
||||
|
||||
#### Test coverage
|
||||
|
||||
To test the code coverage, use:
|
||||
|
||||
```sh
|
||||
@@ -207,26 +170,26 @@ In case you're locally getting errors which are not on the CI, it may be due to
|
||||
|
||||
### Writing tests
|
||||
|
||||
Most packages in [`/packages`](https://github.com/babel/babel/tree/main/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](https://github.com/babel/babel/tree/main/packages/babel-core/test/fixtures).
|
||||
Most packages in [`/packages`](https://github.com/babel/babel/tree/master/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](https://github.com/babel/babel/tree/master/packages/babel-core/test/fixtures).
|
||||
|
||||
#### `@babel/plugin-x`
|
||||
|
||||
All the Babel plugins (and other packages) that have a `/test/fixtures` are written in a similar way.
|
||||
|
||||
For example, in [`@babel/plugin-transform-exponentiation-operator/test`](https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-exponentiation-operator/test):
|
||||
For example, in [`@babel/plugin-transform-exponentiation-operator/test`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test):
|
||||
|
||||
- There is an `index.js` file. It imports our [test helper](https://github.com/babel/babel/tree/main/packages/babel-helper-plugin-test-runner). (You don't have to worry about this).
|
||||
- There can be multiple folders under [`/fixtures`](https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-exponentiation-operator/test/fixtures)
|
||||
- There is an `index.js` file. It imports our [test helper](https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner). (You don't have to worry about this).
|
||||
- There can be multiple folders under [`/fixtures`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures)
|
||||
|
||||
- There is an [`options.json`](https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests.
|
||||
- There is an [`options.json`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests.
|
||||
- For this test, we only need the relevant plugin, so it's just `{ "plugins": ["@babel/plugin-transform-exponentiation-operator"] }`.
|
||||
- If necessary, you can have an `options.json` with different options in each subfolder.
|
||||
|
||||
- In each subfolder, you can organize your directory structure by categories of tests. (Example: these folders can be named after the feature you are testing or can reference the issue number they fix)
|
||||
- Generally, there are two kinds of tests for plugins
|
||||
- The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`input.js`](https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/input.js) file and an [`output.js`](https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/output.js) file. This kind of test only works in sub-subdirectories of `/fixtures`, i.e. `/fixtures/exponentian-operator/binary/input.js` and **not** `/fixtures/exponentian-operator/input.js`.
|
||||
- The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`input.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/input.js) file and an [`output.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/output.js) file. This kind of test only works in sub-subdirectories of `/fixtures`, i.e. `/fixtures/exponentian-operator/binary/input.js` and **not** `/fixtures/exponentian-operator/input.js`.
|
||||
- If you need to expect an error, you can ignore creating the `output.js` file and pass a new `throws` key to the `options.json` that contains the error string that is created.
|
||||
- The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file.
|
||||
- The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file.
|
||||
|
||||
In a fixture test, you simply write out the code you want to transform in `input.js`.
|
||||
|
||||
@@ -250,48 +213,24 @@ expect(2 ** 3).toBe(8);
|
||||
expect(3 * 2 ** 3).toBe(24);
|
||||
```
|
||||
|
||||
##### `options.json` settings
|
||||
If you need to check for an error that is thrown you can add to the `options.json`
|
||||
|
||||
Other than normal Babel options, `options.json` can contain other properties to configure the test behavior:
|
||||
```js
|
||||
// options.json example
|
||||
{
|
||||
"plugins": [["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": "invalidOption" }]],
|
||||
"throws": "@babel/plugin-proposal-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)"
|
||||
}
|
||||
```
|
||||
|
||||
- **`throws`** (string)
|
||||
If the test requires a minimum Node version, you can add `minNodeVersion` (must be in semver format).
|
||||
|
||||
If you need to check for an error that is thrown you can add to the `options.json`
|
||||
|
||||
```jsonc
|
||||
// options.json example
|
||||
{
|
||||
"plugins": [
|
||||
[
|
||||
"@babel/plugin-proposal-object-rest-spread",
|
||||
{ "useBuiltIns": "invalidOption" }
|
||||
]
|
||||
],
|
||||
"throws": "@babel/plugin-proposal-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)"
|
||||
}
|
||||
```
|
||||
|
||||
- **`minNodeVersion`** (string)
|
||||
|
||||
If the test requires a minimum Node version, you can add `minNodeVersion` (must be in semver format).
|
||||
|
||||
```jsonc
|
||||
// options.json example
|
||||
{
|
||||
"minNodeVersion": "5.0.0"
|
||||
}
|
||||
```
|
||||
|
||||
- **`externalHelpers`** (boolean)
|
||||
|
||||
By default, all the tests run with the [`@babel/plugin-external-helpers`](https://babel.dev/docs/en/babel-plugin-external-helpers) enabled. You can disable this behavior with
|
||||
|
||||
```jsonc
|
||||
// options.json example
|
||||
{
|
||||
"externalHelpers": false
|
||||
}
|
||||
```
|
||||
```js
|
||||
// options.json example
|
||||
{
|
||||
"minNodeVersion": "5.0.0"
|
||||
}
|
||||
```
|
||||
|
||||
#### `@babel/parser` (babylon)
|
||||
|
||||
@@ -372,27 +311,20 @@ Note that the code shown in Chrome DevTools is compiled code and therefore diffe
|
||||
|
||||
## Creating a new plugin (`spec-new`)
|
||||
|
||||
> Example: https://github.com/babel/babel/pull/11640
|
||||
> Example: https://github.com/babel/babylon/pull/541
|
||||
|
||||
- Create a new PR that describes the proposed AST shape in [ESTree](https://github.com/estree/estree) (ex: [Decimal AST](https://github.com/estree/estree/pull/220)). The new AST should follow ESTree's [design philosophy](https://github.com/estree/estree#philosophy).
|
||||
- After the ESTree PR is accepted, update [ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md). Note that there are differences between Babel AST and ESTree. In these cases, consistency with current Babel AST outweighs alignment to ESTree. Otherwise it should follow ESTree.
|
||||
|
||||
- [ ] Implement parser plugins based on the new AST. The parser plugin name should be the unprefixed slug of the TC39 proposal URL in _camelcase_, i.e. `exportDefaultFrom` from `https://github.com/tc39/proposal-export-default-from`.
|
||||
- [ ] Use the `this.expectPlugin("pluginName")` check within `@babel/parser` to ensure your new plugin code only runs when that flag is turned on (not default behavior), and a friendly error is thrown if users forget to enable a plugin. You can also supply an array pair to require certain configuration options, e.g., `this.expectPlugin(["pluginName", { configOption: value }])`.
|
||||
- Create a new issue that describes the proposal (ex: [#538](https://github.com/babel/babylon/issues/538)). Include any relevant information like proposal repo/author, examples, parsing approaches, meeting notes, presentation slides, and more.
|
||||
- The pull request should include:
|
||||
- [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babel-parser#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal)
|
||||
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md)
|
||||
- [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in the babel parser so that your new plugin code only runs when that flag is turned on (not default behavior)
|
||||
- [ ] Add failing/passing tests according to spec behavior
|
||||
- [ ] Add `@babel/syntax-new-syntax` package. You can copy `packages/babel-plugin-syntax-decimal` and replace `decimal` to `new-syntax`.
|
||||
- [ ] Add `@babel/syntax-new-syntax` to `@babel/standalone`.
|
||||
- [ ] Add `@babel/syntax-new-syntax` to `package.json`
|
||||
- [ ] Add `@babel/syntax-new-syntax` to [`pluginsConfig.json`](https://github.com/babel/babel/blob/master/packages/babel-standalone/scripts/pluginConfig.json), run `make build-standalone`.
|
||||
- [ ] Add `@babel/syntax-new-syntax` to `src/preset-stage-x`.
|
||||
- [ ] Add `"newSyntax"` to parser [typings](https://github.com/babel/babel/blob/master/packages/babel-parser/typings/babel-parser.d.ts)
|
||||
- [ ] Implement generator support in `packages/babel-generator/src/generators`. The generator converts AST to source code.
|
||||
- [ ] If this feature can be transpiled, start working on the Babel transform.
|
||||
- Start working about the Babel transform itself!
|
||||
|
||||
## Internals
|
||||
|
||||
- AST spec ([babel-parser/ast/spec.md](https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md))
|
||||
- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/main/doc/design/versioning.md))
|
||||
- Monorepo ([doc/design/monorepo.md](https://github.com/babel/babel/blob/main/doc/design/monorepo.md))
|
||||
- Compiler environment support ([doc/design/compiler-environment-support.md](https://github.com/babel/babel/blob/main/doc/design/compiler-environment-support.md))
|
||||
- Compiler assumptions ([doc/design/compiler-assumptions.md](https://github.com/babel/babel/blob/main/doc/design/compiler-assumptions.md))
|
||||
- AST spec ([babel-parser/ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md))
|
||||
- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/master/doc/design/versioning.md))
|
||||
- Monorepo ([doc/design/monorepo.md](https://github.com/babel/babel/blob/master/doc/design/monorepo.md))
|
||||
- Compiler environment support ([doc/design/compiler-environment-support.md](https://github.com/babel/babel/blob/master/doc/design/compiler-environment-support.md))
|
||||
- Compiler assumptions ([doc/design/compiler-assumptions.md](https://github.com/babel/babel/blob/master/doc/design/compiler-assumptions.md))
|
||||
|
||||
302
Gulpfile.js
Normal file
302
Gulpfile.js
Normal file
@@ -0,0 +1,302 @@
|
||||
"use strict";
|
||||
|
||||
const plumber = require("gulp-plumber");
|
||||
const through = require("through2");
|
||||
const chalk = require("chalk");
|
||||
const newer = require("gulp-newer");
|
||||
const babel = require("gulp-babel");
|
||||
const gulpWatch = require("gulp-watch");
|
||||
const fancyLog = require("fancy-log");
|
||||
const filter = require("gulp-filter");
|
||||
const gulp = require("gulp");
|
||||
const path = require("path");
|
||||
const rollup = require("rollup");
|
||||
const rollupAlias = require("@rollup/plugin-alias");
|
||||
const rollupBabel = require("rollup-plugin-babel");
|
||||
const rollupBabelSource = require("./scripts/rollup-plugin-babel-source");
|
||||
const rollupCommonJs = require("rollup-plugin-commonjs");
|
||||
const rollupJson = require("@rollup/plugin-json");
|
||||
const rollupNodeBuiltins = require("rollup-plugin-node-builtins");
|
||||
const rollupNodeGlobals = require("rollup-plugin-node-globals");
|
||||
const rollupNodeResolve = require("rollup-plugin-node-resolve");
|
||||
const rollupReplace = require("rollup-plugin-replace");
|
||||
const { terser: rollupTerser } = require("rollup-plugin-terser");
|
||||
|
||||
const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.js";
|
||||
|
||||
function swapSrcWithLib(srcPath) {
|
||||
const parts = srcPath.split(path.sep);
|
||||
parts[2] = "lib";
|
||||
return parts.join(path.sep);
|
||||
}
|
||||
|
||||
function getIndexFromPackage(name) {
|
||||
return `${name}/src/index.js`;
|
||||
}
|
||||
|
||||
function compilationLogger() {
|
||||
return through.obj(function(file, enc, callback) {
|
||||
fancyLog(`Compiling '${chalk.cyan(file.relative)}'...`);
|
||||
callback(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
function errorsLogger() {
|
||||
return plumber({
|
||||
errorHandler(err) {
|
||||
fancyLog(err.stack);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function rename(fn) {
|
||||
return through.obj(function(file, enc, callback) {
|
||||
file.path = fn(file);
|
||||
callback(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
function buildBabel(exclude, sourcesGlob = defaultSourcesGlob) {
|
||||
const base = __dirname;
|
||||
|
||||
let stream = gulp.src(sourcesGlob, { base: __dirname });
|
||||
|
||||
if (exclude) {
|
||||
const filters = exclude.map(p => `!**/${p}/**`);
|
||||
filters.unshift("**");
|
||||
stream = stream.pipe(filter(filters));
|
||||
}
|
||||
|
||||
return stream
|
||||
.pipe(errorsLogger())
|
||||
.pipe(newer({ dest: base, map: swapSrcWithLib }))
|
||||
.pipe(compilationLogger())
|
||||
.pipe(babel())
|
||||
.pipe(
|
||||
// Passing 'file.relative' because newer() above uses a relative
|
||||
// path and this keeps it consistent.
|
||||
rename(file => path.resolve(file.base, swapSrcWithLib(file.relative)))
|
||||
)
|
||||
.pipe(gulp.dest(base));
|
||||
}
|
||||
|
||||
let babelVersion = require("./packages/babel-core/package.json").version;
|
||||
function buildRollup(packages) {
|
||||
const sourcemap = process.env.NODE_ENV === "production";
|
||||
const minify = !!process.env.IS_PUBLISH;
|
||||
return Promise.all(
|
||||
packages.map(
|
||||
({ src, format, dest, name, filename, version = babelVersion }) => {
|
||||
const extraPlugins = [];
|
||||
let inputExternal = undefined,
|
||||
outputGlobals = undefined,
|
||||
nodeResolveBrowser = false,
|
||||
babelEnvName = "rollup";
|
||||
switch (src) {
|
||||
case "packages/babel-standalone":
|
||||
nodeResolveBrowser = true;
|
||||
babelEnvName = "standalone";
|
||||
if (minify) {
|
||||
extraPlugins.push(
|
||||
rollupTerser({
|
||||
include: /^.+\.min\.js$/,
|
||||
})
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "packages/babel-preset-env-standalone":
|
||||
nodeResolveBrowser = true;
|
||||
babelEnvName = "standalone";
|
||||
if (minify) {
|
||||
extraPlugins.push(
|
||||
rollupTerser({
|
||||
include: /^.+\.min\.js$/,
|
||||
})
|
||||
);
|
||||
}
|
||||
inputExternal = ["@babel/standalone"];
|
||||
outputGlobals = {
|
||||
"@babel/standalone": "Babel",
|
||||
};
|
||||
extraPlugins.push(
|
||||
rollupAlias({
|
||||
entries: [
|
||||
{
|
||||
find: "./available-plugins",
|
||||
replacement: require.resolve(
|
||||
path.join(__dirname, src, "./src/available-plugins")
|
||||
),
|
||||
},
|
||||
{
|
||||
find: "caniuse-lite/data/regions",
|
||||
replacement: require.resolve(
|
||||
path.join(__dirname, src, "./src/caniuse-lite-regions")
|
||||
),
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
// If this build is part of a pull request, include the pull request number in
|
||||
// the version number.
|
||||
if (process.env.CIRCLE_PR_NUMBER) {
|
||||
const prVersion = "+pr." + process.env.CIRCLE_PR_NUMBER;
|
||||
babelVersion += prVersion;
|
||||
version += prVersion;
|
||||
}
|
||||
const input = getIndexFromPackage(src);
|
||||
fancyLog(`Compiling '${chalk.cyan(input)}' with rollup ...`);
|
||||
return rollup
|
||||
.rollup({
|
||||
input,
|
||||
external: inputExternal,
|
||||
plugins: [
|
||||
...extraPlugins,
|
||||
rollupBabelSource(),
|
||||
rollupReplace({
|
||||
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
|
||||
BABEL_VERSION: JSON.stringify(babelVersion),
|
||||
VERSION: JSON.stringify(version),
|
||||
}),
|
||||
rollupBabel({
|
||||
envName: babelEnvName,
|
||||
babelrc: false,
|
||||
extends: "./babel.config.js",
|
||||
}),
|
||||
rollupNodeResolve({
|
||||
browser: nodeResolveBrowser,
|
||||
preferBuiltins: true,
|
||||
//todo: When Yarn workspaces is enabled, remove `dedupe` option
|
||||
dedupe(importee) {
|
||||
return (
|
||||
importee.startsWith("lodash/") ||
|
||||
[
|
||||
"babel-plugin-dynamic-import-node/utils",
|
||||
"esutils",
|
||||
"semver",
|
||||
"source-map",
|
||||
].includes(importee)
|
||||
);
|
||||
},
|
||||
}),
|
||||
rollupCommonJs({
|
||||
include: [
|
||||
/node_modules/,
|
||||
"packages/babel-runtime/regenerator/**",
|
||||
"packages/babel-preset-env/data/*.js",
|
||||
// Rollup doesn't read export maps, so it loads the cjs fallback
|
||||
"packages/babel-compat-data/*.js",
|
||||
],
|
||||
namedExports: {
|
||||
"babel-plugin-dynamic-import-node/utils.js": [
|
||||
"createDynamicImportTransform",
|
||||
"getImportSource",
|
||||
],
|
||||
"@babel/standalone": ["availablePlugins", "registerPlugin"],
|
||||
},
|
||||
}),
|
||||
rollupJson(),
|
||||
rollupNodeBuiltins(),
|
||||
rollupNodeGlobals({ sourceMap: sourcemap }),
|
||||
],
|
||||
})
|
||||
.then(bundle => {
|
||||
const outputFile = path.resolve(src, dest, filename || "index.js");
|
||||
return bundle
|
||||
.write({
|
||||
file: outputFile,
|
||||
format,
|
||||
name,
|
||||
globals: outputGlobals,
|
||||
sourcemap: sourcemap,
|
||||
})
|
||||
.then(() => {
|
||||
if (!process.env.IS_PUBLISH) {
|
||||
fancyLog(
|
||||
chalk.yellow(
|
||||
`Skipped minification of '${chalk.cyan(
|
||||
path.relative(path.join(__dirname, ".."), outputFile)
|
||||
)}' because not publishing`
|
||||
)
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
fancyLog(
|
||||
`Minifying '${chalk.cyan(
|
||||
path.relative(path.join(__dirname, ".."), outputFile)
|
||||
)}'...`
|
||||
);
|
||||
|
||||
return bundle.write({
|
||||
file: outputFile.replace(/\.js$/, ".min.js"),
|
||||
format,
|
||||
name,
|
||||
globals: outputGlobals,
|
||||
sourcemap: sourcemap,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const libBundles = [
|
||||
{
|
||||
src: "packages/babel-parser",
|
||||
format: "cjs",
|
||||
dest: "lib",
|
||||
version: require("./packages/babel-parser/package").version,
|
||||
},
|
||||
];
|
||||
|
||||
const standaloneBundle = [
|
||||
{
|
||||
src: "packages/babel-standalone",
|
||||
format: "umd",
|
||||
name: "Babel",
|
||||
filename: "babel.js",
|
||||
dest: "",
|
||||
version: require("./packages/babel-core/package").version,
|
||||
},
|
||||
];
|
||||
|
||||
const presetEnvStandaloneBundle = [
|
||||
{
|
||||
src: "packages/babel-preset-env-standalone",
|
||||
format: "umd",
|
||||
name: "BabelPresetEnv",
|
||||
filename: "babel-preset-env.js",
|
||||
dest: "",
|
||||
version: require("./packages/babel-preset-env/package").version,
|
||||
},
|
||||
];
|
||||
|
||||
gulp.task("build-rollup", () => buildRollup(libBundles));
|
||||
gulp.task("build-babel-standalone", () => buildRollup(standaloneBundle));
|
||||
|
||||
gulp.task("build-babel-preset-env-standalone", () =>
|
||||
buildRollup(presetEnvStandaloneBundle)
|
||||
);
|
||||
|
||||
gulp.task("build-babel", () => buildBabel(/* exclude */ libBundles));
|
||||
gulp.task("build-babel-types", () =>
|
||||
buildBabel(/* exclude */ libBundles, "packages/babel-types/src/**/*.js")
|
||||
);
|
||||
gulp.task("build", gulp.parallel("build-rollup", "build-babel"));
|
||||
|
||||
gulp.task("default", gulp.series("build"));
|
||||
|
||||
gulp.task("build-no-bundle", () => buildBabel());
|
||||
|
||||
gulp.task(
|
||||
"watch",
|
||||
gulp.series("build-no-bundle", function watch() {
|
||||
gulpWatch(
|
||||
defaultSourcesGlob,
|
||||
{ debounceDelay: 200 },
|
||||
gulp.task("build-no-bundle")
|
||||
);
|
||||
})
|
||||
);
|
||||
581
Gulpfile.mjs
581
Gulpfile.mjs
@@ -1,581 +0,0 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { createRequire } from "module";
|
||||
import { fileURLToPath } from "url";
|
||||
import plumber from "gulp-plumber";
|
||||
import through from "through2";
|
||||
import chalk from "chalk";
|
||||
import fancyLog from "fancy-log";
|
||||
import filter from "gulp-filter";
|
||||
import gulp from "gulp";
|
||||
import { rollup } from "rollup";
|
||||
import { babel as rollupBabel } from "@rollup/plugin-babel";
|
||||
import rollupCommonJs from "@rollup/plugin-commonjs";
|
||||
import rollupJson from "@rollup/plugin-json";
|
||||
import rollupNodePolyfills from "rollup-plugin-node-polyfills";
|
||||
import rollupNodeResolve from "@rollup/plugin-node-resolve";
|
||||
import rollupReplace from "@rollup/plugin-replace";
|
||||
import { terser as rollupTerser } from "rollup-plugin-terser";
|
||||
import _rollupDts from "rollup-plugin-dts";
|
||||
const { default: rollupDts } = _rollupDts;
|
||||
import { Worker as JestWorker } from "jest-worker";
|
||||
import glob from "glob";
|
||||
|
||||
import rollupBabelSource from "./scripts/rollup-plugin-babel-source.js";
|
||||
import formatCode from "./scripts/utils/formatCode.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const monorepoRoot = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const defaultPackagesGlob = "./@(codemods|packages|eslint)/*";
|
||||
const defaultSourcesGlob = `${defaultPackagesGlob}/src/**/{*.js,*.cjs,!(*.d).ts}`;
|
||||
|
||||
const babelStandalonePluginConfigGlob =
|
||||
"./packages/babel-standalone/scripts/pluginConfig.json";
|
||||
|
||||
const buildTypingsWatchGlob = [
|
||||
"./packages/babel-types/lib/definitions/**/*.js",
|
||||
"./packages/babel-types/scripts/generators/*.js",
|
||||
];
|
||||
|
||||
/**
|
||||
* map source code path to the generated artifacts path
|
||||
* @example
|
||||
* mapSrcToLib("packages/babel-core/src/index.js")
|
||||
* // returns "packages/babel-core/lib/index.js"
|
||||
* @example
|
||||
* mapSrcToLib("packages/babel-template/src/index.ts")
|
||||
* // returns "packages/babel-template/lib/index.js"
|
||||
* @example
|
||||
* mapSrcToLib("packages/babel-template/src/index.d.ts")
|
||||
* // returns "packages/babel-template/lib/index.d.ts"
|
||||
* @param {string} srcPath
|
||||
* @returns {string}
|
||||
*/
|
||||
function mapSrcToLib(srcPath) {
|
||||
const parts = srcPath.replace(/(?<!\.d)\.ts$/, ".js").split("/");
|
||||
parts[2] = "lib";
|
||||
return parts.join("/");
|
||||
}
|
||||
|
||||
function mapToDts(packageName) {
|
||||
return packageName.replace(
|
||||
/(?<=\\|\/|^)(packages|eslint|codemods)(?=\\|\/)/,
|
||||
"dts/$1"
|
||||
);
|
||||
}
|
||||
|
||||
function getIndexFromPackage(name) {
|
||||
try {
|
||||
fs.statSync(`./${name}/src/index.ts`);
|
||||
return `${name}/src/index.ts`;
|
||||
} catch {
|
||||
return `${name}/src/index.js`;
|
||||
}
|
||||
}
|
||||
|
||||
function errorsLogger() {
|
||||
return plumber({
|
||||
errorHandler(err) {
|
||||
fancyLog(err.stack);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function rename(fn) {
|
||||
return through.obj(function (file, enc, callback) {
|
||||
file.path = fn(file);
|
||||
callback(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} generator
|
||||
* @param {string} pkg
|
||||
* @param {string} filename
|
||||
* @param {string} message
|
||||
*/
|
||||
function generateHelpers(generator, dest, filename, message) {
|
||||
const stream = gulp
|
||||
.src(".", { base: monorepoRoot })
|
||||
.pipe(errorsLogger())
|
||||
.pipe(
|
||||
through.obj(async (file, enc, callback) => {
|
||||
const { default: generateCode } = await import(generator);
|
||||
|
||||
file.path = filename;
|
||||
file.contents = Buffer.from(
|
||||
formatCode(await generateCode(filename), dest + file.path)
|
||||
);
|
||||
fancyLog(`${chalk.green("✔")} Generated ${message}`);
|
||||
callback(null, file);
|
||||
})
|
||||
)
|
||||
.pipe(gulp.dest(dest, { mode: 0o644 }));
|
||||
|
||||
return finish(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @typedef {("asserts" | "builders" | "constants" | "validators")} TypesHelperKind
|
||||
* @param {TypesHelperKind} helperKind
|
||||
* @param {string} filename
|
||||
*/
|
||||
async function generateTypeHelpers(helperKind, filename = "index.ts") {
|
||||
return generateHelpers(
|
||||
`./packages/babel-types/scripts/generators/${helperKind}.js`,
|
||||
`./packages/babel-types/src/${helperKind}/generated/`,
|
||||
filename,
|
||||
`@babel/types -> ${helperKind}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @typedef {("asserts" | "validators" | "virtual-types")} TraverseHelperKind
|
||||
* @param {TraverseHelperKind} helperKind
|
||||
*/
|
||||
async function generateTraverseHelpers(helperKind) {
|
||||
return generateHelpers(
|
||||
`./packages/babel-traverse/scripts/generators/${helperKind}.js`,
|
||||
`./packages/babel-traverse/src/path/generated/`,
|
||||
`${helperKind}.ts`,
|
||||
`@babel/traverse -> ${helperKind}`
|
||||
);
|
||||
}
|
||||
|
||||
async function generateRuntimeHelpers() {
|
||||
return generateHelpers(
|
||||
`./packages/babel-helpers/scripts/generate-helpers.js`,
|
||||
`./packages/babel-helpers/src/`,
|
||||
"helpers-generated.ts",
|
||||
"@babel/helpers"
|
||||
);
|
||||
}
|
||||
|
||||
function generateStandalone() {
|
||||
const dest = "./packages/babel-standalone/src/generated/";
|
||||
return gulp
|
||||
.src(babelStandalonePluginConfigGlob, { base: monorepoRoot })
|
||||
.pipe(
|
||||
through.obj((file, enc, callback) => {
|
||||
fancyLog("Generating @babel/standalone files");
|
||||
const pluginConfig = JSON.parse(file.contents);
|
||||
let imports = "";
|
||||
let list = "";
|
||||
let allList = "";
|
||||
|
||||
for (const plugin of pluginConfig) {
|
||||
const camelPlugin = plugin.replace(/-[a-z]/g, c =>
|
||||
c[1].toUpperCase()
|
||||
);
|
||||
imports += `import ${camelPlugin} from "@babel/plugin-${plugin}";`;
|
||||
list += `${camelPlugin},`;
|
||||
allList += `"${plugin}": ${camelPlugin},`;
|
||||
}
|
||||
|
||||
const fileContents = `/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'yarn gulp generate-standalone'
|
||||
*/
|
||||
${imports}
|
||||
export {${list}};
|
||||
export const all: { [k: string]: any } = {${allList}};`;
|
||||
file.path = "plugins.ts";
|
||||
file.contents = Buffer.from(formatCode(fileContents, dest));
|
||||
callback(null, file);
|
||||
})
|
||||
)
|
||||
.pipe(gulp.dest(dest));
|
||||
}
|
||||
|
||||
function finish(stream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("end", resolve);
|
||||
stream.on("finish", resolve);
|
||||
stream.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
function getFiles(glob, { include, exclude }) {
|
||||
let stream = gulp.src(glob, { base: monorepoRoot });
|
||||
|
||||
if (exclude) {
|
||||
const filters = exclude.map(p => `!**/${p}/**`);
|
||||
filters.unshift("**");
|
||||
stream = stream.pipe(filter(filters));
|
||||
}
|
||||
if (include) {
|
||||
const filters = include.map(p => `**/${p}/**`);
|
||||
stream = stream.pipe(filter(filters));
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
function createWorker(useWorker) {
|
||||
const numWorkers = require("os").cpus().length / 2 - 1;
|
||||
if (numWorkers === 0 || !useWorker) {
|
||||
return require("./babel-worker.cjs");
|
||||
}
|
||||
const worker = new JestWorker(require.resolve("./babel-worker.cjs"), {
|
||||
numWorkers,
|
||||
exposedMethods: ["transform"],
|
||||
});
|
||||
worker.getStdout().pipe(process.stdout);
|
||||
worker.getStderr().pipe(process.stderr);
|
||||
return worker;
|
||||
}
|
||||
|
||||
async function buildBabel(useWorker, ignore = []) {
|
||||
const worker = createWorker(useWorker);
|
||||
const files = await new Promise((resolve, reject) => {
|
||||
glob(
|
||||
defaultSourcesGlob,
|
||||
{
|
||||
ignore: ignore.map(p => `./${p.src}/**`),
|
||||
},
|
||||
(err, files) => {
|
||||
if (err) reject(err);
|
||||
resolve(files);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const promises = [];
|
||||
for (const file of files) {
|
||||
// @example ./packages/babel-parser/src/index.js
|
||||
const dest = "./" + mapSrcToLib(file.slice(2));
|
||||
promises.push(worker.transform(file, dest));
|
||||
}
|
||||
return Promise.all(promises).finally(() => {
|
||||
if (worker.end !== undefined) {
|
||||
worker.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a nested dependency starting from the given file
|
||||
*/
|
||||
function resolveChain(baseUrl, ...packages) {
|
||||
const require = createRequire(baseUrl);
|
||||
|
||||
return packages.reduce(
|
||||
(base, pkg) =>
|
||||
path.dirname(require.resolve(pkg + "/package.json", { paths: [base] })),
|
||||
path.dirname(fileURLToPath(baseUrl))
|
||||
);
|
||||
}
|
||||
|
||||
// If this build is part of a pull request, include the pull request number in
|
||||
// the version number.
|
||||
let versionSuffix = "";
|
||||
if (process.env.CIRCLE_PR_NUMBER) {
|
||||
versionSuffix = "+pr." + process.env.CIRCLE_PR_NUMBER;
|
||||
}
|
||||
|
||||
const babelVersion =
|
||||
require("./packages/babel-core/package.json").version + versionSuffix;
|
||||
function buildRollup(packages, targetBrowsers) {
|
||||
const sourcemap = process.env.NODE_ENV === "production";
|
||||
return Promise.all(
|
||||
packages.map(
|
||||
async ({ src, format, dest, name, filename, envName = "rollup" }) => {
|
||||
const pkgJSON = require("./" + src + "/package.json");
|
||||
const version = pkgJSON.version + versionSuffix;
|
||||
const { dependencies = {}, peerDependencies = {} } = pkgJSON;
|
||||
const external = Object.keys(dependencies).concat(
|
||||
Object.keys(peerDependencies)
|
||||
);
|
||||
|
||||
const input = getIndexFromPackage(src);
|
||||
fancyLog(`Compiling '${chalk.cyan(input)}' with rollup ...`);
|
||||
const bundle = await rollup({
|
||||
input,
|
||||
external,
|
||||
onwarn(warning, warn) {
|
||||
if (warning.code === "CIRCULAR_DEPENDENCY") return;
|
||||
if (warning.code === "UNUSED_EXTERNAL_IMPORT") {
|
||||
warn(warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Rollup warns about using babel.default at
|
||||
// https://github.com/babel/babel-polyfills/blob/4ac92be5b70b13e3d8a34614d8ecd900eb3f40e4/packages/babel-helper-define-polyfill-provider/src/types.js#L5
|
||||
// We can safely ignore this warning, and let Rollup replace it with undefined.
|
||||
if (
|
||||
warning.code === "MISSING_EXPORT" &&
|
||||
warning.exporter === "packages/babel-core/src/index.ts" &&
|
||||
warning.missing === "default" &&
|
||||
[
|
||||
"@babel/helper-define-polyfill-provider",
|
||||
"babel-plugin-polyfill-corejs2",
|
||||
"babel-plugin-polyfill-corejs3",
|
||||
"babel-plugin-polyfill-regenerator",
|
||||
].some(pkg => warning.importer.includes(pkg))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We use console.warn here since it prints more info than just "warn",
|
||||
// in case we want to stop throwing for a specific message.
|
||||
console.warn(warning);
|
||||
|
||||
// https://github.com/babel/babel/pull/12011#discussion_r540434534
|
||||
throw new Error("Rollup aborted due to warnings above");
|
||||
},
|
||||
plugins: [
|
||||
rollupBabelSource(),
|
||||
rollupReplace({
|
||||
preventAssignment: true,
|
||||
values: {
|
||||
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
|
||||
BABEL_VERSION: JSON.stringify(babelVersion),
|
||||
VERSION: JSON.stringify(version),
|
||||
},
|
||||
}),
|
||||
rollupCommonJs({
|
||||
include: [
|
||||
/node_modules/,
|
||||
"packages/babel-runtime/regenerator/**",
|
||||
"packages/babel-preset-env/data/*.js",
|
||||
// Rollup doesn't read export maps, so it loads the cjs fallback
|
||||
"packages/babel-compat-data/*.js",
|
||||
"packages/*/src/**/*.cjs",
|
||||
// See the comment in this file for the reason to include it
|
||||
"packages/babel-standalone/src/dynamic-require-entrypoint.cjs",
|
||||
],
|
||||
dynamicRequireTargets: [
|
||||
// https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L48
|
||||
resolveChain(
|
||||
import.meta.url,
|
||||
"./packages/babel-helper-create-regexp-features-plugin",
|
||||
"regexpu-core",
|
||||
"regenerate-unicode-properties"
|
||||
) + "/**/*.js",
|
||||
],
|
||||
// Never delegate to the native require()
|
||||
ignoreDynamicRequires: true,
|
||||
// Align with the Node.js behavior
|
||||
defaultIsModuleExports: true,
|
||||
}),
|
||||
rollupBabel({
|
||||
envName,
|
||||
babelrc: false,
|
||||
babelHelpers: "bundled",
|
||||
extends: "./babel.config.js",
|
||||
extensions: [".ts", ".js", ".mjs", ".cjs"],
|
||||
}),
|
||||
rollupNodeResolve({
|
||||
extensions: [".ts", ".js", ".mjs", ".cjs", ".json"],
|
||||
browser: targetBrowsers,
|
||||
exportConditions: targetBrowsers ? ["browser"] : [],
|
||||
// It needs to be set to 'false' when using rollupNodePolyfills
|
||||
// https://github.com/rollup/plugins/issues/772
|
||||
preferBuiltins: !targetBrowsers,
|
||||
}),
|
||||
rollupJson(),
|
||||
targetBrowsers &&
|
||||
rollupNodePolyfills({
|
||||
sourceMap: sourcemap,
|
||||
include: "**/*.{js,cjs,ts}",
|
||||
}),
|
||||
].filter(Boolean),
|
||||
});
|
||||
|
||||
const outputFile = path.join(src, dest, filename || "index.js");
|
||||
await bundle.write({
|
||||
file: outputFile,
|
||||
format,
|
||||
name,
|
||||
sourcemap: sourcemap,
|
||||
exports: "named",
|
||||
});
|
||||
|
||||
if (!process.env.IS_PUBLISH) {
|
||||
fancyLog(
|
||||
chalk.yellow(
|
||||
`Skipped minification of '${chalk.cyan(
|
||||
outputFile
|
||||
)}' because not publishing`
|
||||
)
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
fancyLog(`Minifying '${chalk.cyan(outputFile)}'...`);
|
||||
|
||||
await bundle.write({
|
||||
file: outputFile.replace(/\.js$/, ".min.js"),
|
||||
format,
|
||||
name,
|
||||
sourcemap: sourcemap,
|
||||
exports: "named",
|
||||
plugins: [
|
||||
rollupTerser({
|
||||
// workaround https://bugs.webkit.org/show_bug.cgi?id=212725
|
||||
output: {
|
||||
ascii_only: true,
|
||||
},
|
||||
numWorkers: process.env.CIRCLECI ? 1 : undefined,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function buildRollupDts(packages) {
|
||||
const sourcemap = process.env.NODE_ENV === "production";
|
||||
return Promise.all(
|
||||
packages.map(async packageName => {
|
||||
const input = `${mapToDts(packageName)}/src/index.d.ts`;
|
||||
const output = `${packageName}/lib/index.d.ts`;
|
||||
fancyLog(`Bundling '${chalk.cyan(output)}' with rollup ...`);
|
||||
|
||||
const bundle = await rollup({
|
||||
input,
|
||||
plugins: [rollupDts()],
|
||||
onwarn(warning, warn) {
|
||||
if (warning.code !== "CIRCULAR_DEPENDENCY") warn(warning);
|
||||
},
|
||||
});
|
||||
|
||||
await bundle.write({
|
||||
file: output,
|
||||
format: "es",
|
||||
sourcemap: sourcemap,
|
||||
exports: "named",
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function copyDts(packages) {
|
||||
return getFiles(`${defaultPackagesGlob}/src/**/*.d.ts`, { include: packages })
|
||||
.pipe(rename(file => path.resolve(file.base, mapToDts(file.relative))))
|
||||
.pipe(gulp.dest(monorepoRoot));
|
||||
}
|
||||
|
||||
const libBundles = [
|
||||
"packages/babel-parser",
|
||||
"packages/babel-plugin-proposal-object-rest-spread",
|
||||
"packages/babel-plugin-proposal-optional-chaining",
|
||||
"packages/babel-preset-react",
|
||||
"packages/babel-preset-typescript",
|
||||
"packages/babel-helper-member-expression-to-functions",
|
||||
"packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining",
|
||||
"packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression",
|
||||
].map(src => ({
|
||||
src,
|
||||
format: "cjs",
|
||||
dest: "lib",
|
||||
}));
|
||||
|
||||
const dtsBundles = ["packages/babel-types"];
|
||||
|
||||
const standaloneBundle = [
|
||||
{
|
||||
src: "packages/babel-standalone",
|
||||
format: "umd",
|
||||
name: "Babel",
|
||||
filename: "babel.js",
|
||||
dest: "",
|
||||
version: babelVersion,
|
||||
envName: "standalone",
|
||||
},
|
||||
];
|
||||
|
||||
gulp.task("generate-type-helpers", () => {
|
||||
fancyLog("Generating @babel/types and @babel/traverse dynamic functions");
|
||||
|
||||
return Promise.all([
|
||||
generateTypeHelpers("asserts"),
|
||||
generateTypeHelpers("builders"),
|
||||
generateTypeHelpers("builders", "uppercase.js"),
|
||||
generateTypeHelpers("constants"),
|
||||
generateTypeHelpers("validators"),
|
||||
generateTypeHelpers("ast-types"),
|
||||
generateTraverseHelpers("asserts"),
|
||||
generateTraverseHelpers("validators"),
|
||||
generateTraverseHelpers("virtual-types"),
|
||||
]);
|
||||
});
|
||||
|
||||
gulp.task("generate-runtime-helpers", () => {
|
||||
fancyLog("Generating @babel/helpers runtime helpers");
|
||||
|
||||
return generateRuntimeHelpers();
|
||||
});
|
||||
|
||||
gulp.task("generate-standalone", () => generateStandalone());
|
||||
|
||||
gulp.task("build-rollup", () => buildRollup(libBundles));
|
||||
gulp.task("rollup-babel-standalone", () => buildRollup(standaloneBundle, true));
|
||||
gulp.task(
|
||||
"build-babel-standalone",
|
||||
gulp.series("generate-standalone", "rollup-babel-standalone")
|
||||
);
|
||||
|
||||
gulp.task("copy-dts", () => copyDts(dtsBundles));
|
||||
gulp.task(
|
||||
"bundle-dts",
|
||||
gulp.series("copy-dts", () => buildRollupDts(dtsBundles))
|
||||
);
|
||||
|
||||
gulp.task("build-babel", () => buildBabel(true, /* exclude */ libBundles));
|
||||
|
||||
gulp.task(
|
||||
"build",
|
||||
gulp.series(
|
||||
gulp.parallel("build-rollup", "build-babel", "generate-runtime-helpers"),
|
||||
gulp.parallel(
|
||||
"generate-standalone",
|
||||
gulp.series(
|
||||
"generate-type-helpers",
|
||||
// rebuild @babel/types since type-helpers may be changed
|
||||
"build-babel"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
gulp.task("default", gulp.series("build"));
|
||||
|
||||
// First build on worker processes for compilation speed
|
||||
gulp.task("build-no-bundle", () => buildBabel(true));
|
||||
// Incremental builds take place in main process
|
||||
gulp.task("build-no-bundle-watch", () => buildBabel(false));
|
||||
|
||||
gulp.task(
|
||||
"build-dev",
|
||||
gulp.series(
|
||||
"build-no-bundle",
|
||||
gulp.parallel(
|
||||
"generate-standalone",
|
||||
gulp.series(
|
||||
"generate-type-helpers",
|
||||
// rebuild @babel/types since type-helpers may be changed
|
||||
"build-no-bundle"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
gulp.task(
|
||||
"watch",
|
||||
gulp.series("build-dev", function watch() {
|
||||
gulp.watch(defaultSourcesGlob, gulp.task("build-no-bundle-watch"));
|
||||
gulp.watch(
|
||||
babelStandalonePluginConfigGlob,
|
||||
gulp.task("generate-standalone")
|
||||
);
|
||||
gulp.watch(buildTypingsWatchGlob, gulp.task("generate-type-helpers"));
|
||||
gulp.watch(
|
||||
"./packages/babel-helpers/src/helpers/*.js",
|
||||
gulp.task("generate-runtime-helpers")
|
||||
);
|
||||
})
|
||||
);
|
||||
267
Makefile
267
Makefile
@@ -1,6 +1,8 @@
|
||||
FLOW_COMMIT = 92bbb5e9dacb8185aa73ea343954d0434b42c40b
|
||||
TEST262_COMMIT = 46f165ae490de7f1343165ab8d228db81eaa02c5
|
||||
TYPESCRIPT_COMMIT = b53073bf66571b4c99f0a93b8f76fb06b36d8991
|
||||
FLOW_COMMIT = a1f9a4c709dcebb27a5084acf47755fbae699c25
|
||||
TEST262_COMMIT = 28b4fcca4b1b1d278dfe0cc0e69c7d9d59b31aab
|
||||
TYPESCRIPT_COMMIT = 5fc917be2e4dd64c8e9504d36615cd7fbfdd4cd3
|
||||
|
||||
FORCE_PUBLISH = "@babel/runtime,@babel/runtime-corejs2,@babel/runtime-corejs3,@babel/standalone,@babel/preset-env-standalone"
|
||||
|
||||
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||
export FORCE_COLOR = true
|
||||
@@ -12,118 +14,137 @@ EMPTY :=
|
||||
SPACE := $(EMPTY) $(EMPTY)
|
||||
COMMA_SEPARATED_SOURCES = $(subst $(SPACE),$(COMMA),$(SOURCES))
|
||||
|
||||
YARN := yarn
|
||||
NODE := $(YARN) node
|
||||
|
||||
|
||||
.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap
|
||||
|
||||
build: build-no-bundle
|
||||
build: build-bundle
|
||||
ifneq ("$(BABEL_COVERAGE)", "true")
|
||||
$(MAKE) build-standalone
|
||||
endif
|
||||
|
||||
build-bundle: clean clean-lib
|
||||
$(YARN) gulp build
|
||||
$(MAKE) build-flow-typings
|
||||
yarn gulp build
|
||||
$(MAKE) generate-standalone generate-type-helpers
|
||||
# call build again as the generated files might need to be compiled again.
|
||||
yarn gulp build
|
||||
$(MAKE) build-typings
|
||||
$(MAKE) build-dist
|
||||
|
||||
build-no-bundle-ci: bootstrap-only
|
||||
$(YARN) gulp build-dev
|
||||
$(MAKE) build-flow-typings
|
||||
$(MAKE) build-dist
|
||||
build-bundle-ci: bootstrap-only
|
||||
$(MAKE) build-bundle
|
||||
|
||||
build-no-bundle: clean clean-lib
|
||||
BABEL_ENV=development $(YARN) gulp build-dev
|
||||
$(MAKE) build-flow-typings
|
||||
$(MAKE) build-dist
|
||||
|
||||
generate-tsconfig:
|
||||
$(NODE) scripts/generators/tsconfig.js
|
||||
generate-standalone:
|
||||
node packages/babel-standalone/scripts/generate.js
|
||||
|
||||
generate-type-helpers:
|
||||
$(YARN) gulp generate-type-helpers
|
||||
node packages/babel-types/scripts/generateTypeHelpers.js
|
||||
|
||||
build-typings: build-flow-typings build-typescript-typings
|
||||
|
||||
build-flow-typings:
|
||||
$(NODE) packages/babel-types/scripts/generators/flow.js > packages/babel-types/lib/index.js.flow
|
||||
node packages/babel-types/scripts/generators/flow.js > packages/babel-types/lib/index.js.flow
|
||||
|
||||
# For TypeScript older than 3.7
|
||||
build-typescript-legacy-typings:
|
||||
$(NODE) packages/babel-types/scripts/generators/typescript-legacy.js > packages/babel-types/lib/index-legacy.d.ts
|
||||
build-typescript-typings:
|
||||
node packages/babel-types/scripts/generators/typescript.js > packages/babel-types/lib/index.d.ts
|
||||
|
||||
build-standalone: build-babel-standalone
|
||||
build-standalone: build-babel-standalone build-preset-env-standalone
|
||||
|
||||
build-standalone-ci: build-no-bundle-ci
|
||||
build-standalone-ci: build-bundle-ci
|
||||
$(MAKE) build-standalone
|
||||
|
||||
build-babel-standalone:
|
||||
$(YARN) gulp build-babel-standalone
|
||||
yarn gulp build-babel-standalone
|
||||
|
||||
build-preset-env-standalone:
|
||||
yarn gulp build-babel-preset-env-standalone
|
||||
|
||||
prepublish-build-standalone:
|
||||
BABEL_ENV=production IS_PUBLISH=true $(YARN) gulp build-babel-standalone
|
||||
BABEL_ENV=production IS_PUBLISH=true yarn gulp build-babel-standalone
|
||||
|
||||
build-dist: build-plugin-transform-runtime-dist
|
||||
prepublish-build-preset-env-standalone:
|
||||
BABEL_ENV=production IS_PUBLISH=true yarn gulp build-babel-preset-env-standalone
|
||||
|
||||
build-dist: build-polyfill-dist build-plugin-transform-runtime-dist
|
||||
|
||||
build-polyfill-dist:
|
||||
cd packages/babel-polyfill; \
|
||||
scripts/build-dist.sh
|
||||
|
||||
build-plugin-transform-runtime-dist:
|
||||
cd packages/babel-plugin-transform-runtime; \
|
||||
$(NODE) scripts/build-dist.js
|
||||
node scripts/build-dist.js
|
||||
|
||||
build-no-bundle: clean clean-lib
|
||||
BABEL_ENV=development yarn gulp build-no-bundle
|
||||
# Ensure that build artifacts for types are created during local
|
||||
# development too.
|
||||
$(MAKE) generate-type-helpers
|
||||
$(MAKE) build-typings
|
||||
|
||||
watch: build-no-bundle
|
||||
BABEL_ENV=development $(YARN) gulp watch
|
||||
BABEL_ENV=development yarn gulp watch
|
||||
|
||||
flowcheck-ci:
|
||||
code-quality-ci: flowcheck-ci lint-ci
|
||||
|
||||
flowcheck-ci: bootstrap-flowcheck
|
||||
$(MAKE) flow
|
||||
|
||||
code-quality: tscheck flow lint
|
||||
code-quality: flow lint
|
||||
|
||||
tscheck: generate-tsconfig
|
||||
rm -rf dts
|
||||
$(YARN) tsc -b .
|
||||
flow:
|
||||
yarn flow check --strip-root
|
||||
|
||||
flow: build-flow-typings
|
||||
$(YARN) flow check --strip-root
|
||||
bootstrap-flowcheck: bootstrap-only
|
||||
yarn gulp build-babel-types
|
||||
$(MAKE) build-typings
|
||||
|
||||
lint-ci: lint check-compat-data-ci
|
||||
lint-ci: lint-js-ci lint-ts-ci
|
||||
|
||||
check-compat-data-ci:
|
||||
$(MAKE) check-compat-data
|
||||
lint-js-ci: bootstrap-only
|
||||
$(MAKE) lint-js
|
||||
|
||||
lint:
|
||||
BABEL_ENV=test $(YARN) eslint scripts benchmark $(SOURCES) '*.{js,cjs,mjs,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts
|
||||
lint-ts-ci: bootstrap-flowcheck
|
||||
$(MAKE) lint-ts
|
||||
|
||||
lint: lint-js lint-ts
|
||||
|
||||
lint-js:
|
||||
yarn eslint scripts $(SOURCES) '*.js' --format=codeframe
|
||||
|
||||
lint-ts:
|
||||
scripts/lint-ts-typings.sh
|
||||
|
||||
fix: fix-json fix-js
|
||||
|
||||
fix-js:
|
||||
$(YARN) eslint scripts benchmark $(SOURCES) '*.{js,cjs,mjs,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts --fix
|
||||
yarn eslint scripts $(SOURCES) '*.js' --format=codeframe --fix
|
||||
|
||||
fix-json:
|
||||
$(YARN) prettier "{$(COMMA_SEPARATED_SOURCES)}/*/test/fixtures/**/options.json" --write --loglevel warn
|
||||
|
||||
check-compat-data:
|
||||
cd packages/babel-compat-data; CHECK_COMPAT_DATA=true $(YARN) run build-data
|
||||
|
||||
build-compat-data:
|
||||
cd packages/babel-compat-data; $(YARN) run build-data
|
||||
yarn prettier "{$(COMMA_SEPARATED_SOURCES)}/*/test/fixtures/**/options.json" --write --loglevel warn
|
||||
|
||||
clean: test-clean
|
||||
rm -f .npmrc
|
||||
rm -rf packages/babel-polyfill/browser*
|
||||
rm -rf packages/babel-polyfill/dist
|
||||
rm -rf coverage
|
||||
rm -rf packages/*/npm-debug*
|
||||
rm -rf node_modules/.cache
|
||||
|
||||
test-clean:
|
||||
$(foreach source, $(SOURCES), \
|
||||
$(call clean-source-test, $(source)))
|
||||
|
||||
# Does not work on Windows; use "$(YARN) jest" instead
|
||||
# Does not work on Windows; use "yarn jest" instead
|
||||
test-only:
|
||||
BABEL_ENV=test ./scripts/test.sh
|
||||
$(MAKE) test-clean
|
||||
YARN jest
|
||||
#$(MAKE) test-clean
|
||||
|
||||
test: lint test-only
|
||||
|
||||
test-ci: build-standalone-ci
|
||||
BABEL_ENV=test $(YARN) jest --maxWorkers=4 --ci
|
||||
test-ci: jest-ci
|
||||
|
||||
jest-ci: build-standalone-ci
|
||||
BABEL_ENV=test yarn jest --maxWorkers=4 --ci
|
||||
$(MAKE) test-clean
|
||||
|
||||
# Does not work on Windows
|
||||
@@ -131,86 +152,90 @@ test-ci-coverage: SHELL:=/bin/bash
|
||||
test-ci-coverage:
|
||||
BABEL_COVERAGE=true BABEL_ENV=test $(MAKE) bootstrap
|
||||
BABEL_ENV=test TEST_TYPE=cov ./scripts/test-cov.sh
|
||||
bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json
|
||||
|
||||
bootstrap-flow:
|
||||
rm -rf build/flow
|
||||
mkdir -p build
|
||||
git clone --single-branch --shallow-since=2021-05-01 https://github.com/facebook/flow.git build/flow
|
||||
cd build/flow && git checkout -q $(FLOW_COMMIT)
|
||||
git clone --branch=master --single-branch --shallow-since=2018-11-01 https://github.com/facebook/flow.git build/flow
|
||||
cd build/flow && git checkout $(FLOW_COMMIT)
|
||||
|
||||
test-flow:
|
||||
$(NODE) scripts/parser-tests/flow
|
||||
node scripts/parser-tests/flow
|
||||
|
||||
test-flow-update-allowlist:
|
||||
$(NODE) scripts/parser-tests/flow --update-allowlist
|
||||
test-flow-ci: build-bundle-ci bootstrap-flow
|
||||
$(MAKE) test-flow
|
||||
|
||||
test-flow-update-whitelist:
|
||||
node scripts/parser-tests/flow --update-whitelist
|
||||
|
||||
bootstrap-typescript:
|
||||
rm -rf ./build/typescript
|
||||
mkdir -p ./build
|
||||
git clone --single-branch --shallow-since=2021-05-01 https://github.com/microsoft/TypeScript.git ./build/typescript
|
||||
cd build/typescript && git checkout -q $(TYPESCRIPT_COMMIT)
|
||||
git clone --branch=master --single-branch --shallow-since=2019-09-01 https://github.com/microsoft/TypeScript.git ./build/typescript
|
||||
cd build/typescript && git checkout $(TYPESCRIPT_COMMIT)
|
||||
|
||||
test-typescript:
|
||||
$(NODE) scripts/parser-tests/typescript
|
||||
node scripts/parser-tests/typescript
|
||||
|
||||
test-typescript-update-allowlist:
|
||||
$(NODE) scripts/parser-tests/typescript --update-allowlist
|
||||
test-typescript-ci: build-bundle-ci bootstrap-typescript
|
||||
$(MAKE) test-typescript
|
||||
|
||||
test-typescript-update-whitelist:
|
||||
node scripts/parser-tests/typescript --update-whitelist
|
||||
|
||||
bootstrap-test262:
|
||||
rm -rf build/test262
|
||||
mkdir -p build
|
||||
git clone --single-branch --shallow-since=2021-05-01 https://github.com/tc39/test262.git build/test262
|
||||
cd build/test262 && git checkout -q $(TEST262_COMMIT)
|
||||
git clone --branch=master --single-branch --shallow-since=2019-12-01 https://github.com/tc39/test262.git build/test262
|
||||
cd build/test262 && git checkout $(TEST262_COMMIT)
|
||||
|
||||
test-test262:
|
||||
$(NODE) scripts/parser-tests/test262
|
||||
node scripts/parser-tests/test262
|
||||
|
||||
test-test262-update-allowlist:
|
||||
$(NODE) scripts/parser-tests/test262 --update-allowlist
|
||||
test-test262-ci: build-bundle-ci bootstrap-test262
|
||||
$(MAKE) test-test262
|
||||
|
||||
test-test262-update-whitelist:
|
||||
node scripts/parser-tests/test262 --update-whitelist
|
||||
|
||||
# Does not work on Windows
|
||||
clone-license:
|
||||
./scripts/clone-license.sh
|
||||
|
||||
prepublish-build: clean-lib clean-runtime-helpers
|
||||
NODE_ENV=production BABEL_ENV=production STRIP_BABEL_8_FLAG=true $(MAKE) build-bundle
|
||||
STRIP_BABEL_8_FLAG=true $(MAKE) prepublish-build-standalone clone-license prepublish-prepare-dts
|
||||
|
||||
prepublish-prepare-dts:
|
||||
$(MAKE) tscheck
|
||||
$(YARN) gulp bundle-dts
|
||||
$(MAKE) build-typescript-legacy-typings
|
||||
NODE_ENV=production BABEL_ENV=production $(MAKE) build
|
||||
$(MAKE) clone-license
|
||||
|
||||
prepublish:
|
||||
$(MAKE) bootstrap-only
|
||||
$(MAKE) prepublish-build
|
||||
IS_PUBLISH=true $(MAKE) test
|
||||
|
||||
new-version-checklist:
|
||||
# @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
# @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
# @echo "!!!!!! !!!!!!"
|
||||
# @echo "!!!!!! Update the version of the "identity" !!!!!!"
|
||||
# @echo "!!!!!! and "applyDecs" helpers to 7.17.0 !!!!!!"
|
||||
# @echo "!!!!!! !!!!!!"
|
||||
# @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
# @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
# @exit 1
|
||||
#$(MAKE) test #fuck your tests babel...
|
||||
|
||||
new-version:
|
||||
$(MAKE) new-version-checklist
|
||||
git pull --rebase
|
||||
$(YARN) release-tool version -f @babel/standalone
|
||||
yarn lerna version --force-publish=$(FORCE_PUBLISH)
|
||||
|
||||
version-cerxes:
|
||||
yarn lerna version prerelease --allow-branch initializers-fix --preid csx
|
||||
|
||||
publish-cerxes: prepublish
|
||||
yarn lerna publish --registry="https://npm.cerxes.net" --force-publish --allow-branch initializer-fix-v7.8.3 --dist-tag csx --skip-git --exact
|
||||
|
||||
# NOTE: Run make new-version first
|
||||
publish:
|
||||
@echo "Please confirm you have stopped make watch. (y)es, [N]o:"; \
|
||||
read CLEAR; \
|
||||
if [ "_$$CLEAR" != "_y" ]; then \
|
||||
exit 1; \
|
||||
fi
|
||||
$(MAKE) prepublish
|
||||
$(YARN) release-tool publish
|
||||
publish: prepublish
|
||||
yarn lerna publish from-git
|
||||
$(MAKE) clean
|
||||
|
||||
publish-ci: prepublish
|
||||
ifneq ("$(NPM_TOKEN)", "")
|
||||
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
|
||||
else
|
||||
echo "Missing NPM_TOKEN env var"
|
||||
exit 1
|
||||
endif
|
||||
yarn lerna publish from-git --yes
|
||||
rm -f .npmrc
|
||||
$(MAKE) clean
|
||||
|
||||
publish-test:
|
||||
@@ -218,28 +243,38 @@ ifneq ("$(I_AM_USING_VERDACCIO)", "I_AM_SURE")
|
||||
echo "You probably don't know what you are doing"
|
||||
exit 1
|
||||
endif
|
||||
$(YARN) release-tool version $(VERSION) --all --yes --tag-version-prefix="version-e2e-test-"
|
||||
$(MAKE) prepublish-build
|
||||
YARN_NPM_PUBLISH_REGISTRY=http://localhost:4873 $(YARN) release-tool publish --yes --tag-version-prefix="version-e2e-test-"
|
||||
yarn lerna version patch --force-publish=$(FORCE_PUBLISH) --no-push --yes --tag-version-prefix="version-e2e-test-"
|
||||
yarn lerna publish from-git --registry http://localhost:4873 --yes --tag-version-prefix="version-e2e-test-"
|
||||
$(MAKE) clean
|
||||
|
||||
bootstrap-only: clean-all
|
||||
$(YARN) install
|
||||
publish-eslint:
|
||||
$(call set-json-field, ./eslint/$(PKG)/package.json, private, false)
|
||||
cd eslint/$(PKG); yarn publish
|
||||
$(call set-json-field, ./eslint/$(PKG)/package.json, private, true)
|
||||
|
||||
bootstrap-only: lerna-bootstrap
|
||||
|
||||
yarn-install: clean-all
|
||||
yarn --ignore-engines
|
||||
|
||||
lerna-bootstrap: yarn-install
|
||||
# todo: remove `-- -- --ignore-engines` in Babel 8
|
||||
yarn lerna bootstrap -- -- --ignore-engines
|
||||
|
||||
bootstrap: bootstrap-only
|
||||
$(MAKE) generate-tsconfig build
|
||||
$(MAKE) build
|
||||
|
||||
clean-lib:
|
||||
# TODO: Don't delete eslint/*/lib when they use src
|
||||
$(foreach source, $(SOURCES), \
|
||||
$(call clean-source-lib, $(source)))
|
||||
$(if $(filter-out $(source), eslint), \
|
||||
$(call clean-source-lib, $(source))))
|
||||
|
||||
clean-runtime-helpers:
|
||||
rm -f packages/babel-runtime/helpers/**/*.js
|
||||
rm -f packages/babel-runtime-corejs2/helpers/**/*.js
|
||||
rm -f packages/babel-runtime-corejs3/helpers/**/*.js
|
||||
rm -f packages/babel-runtime/helpers/**/*.mjs
|
||||
rm -f packages/babel-runtime-corejs2/helpers/**/*.mjs
|
||||
rm -f packages/babel-runtime-corejs3/helpers/**/*.mjs
|
||||
rm -rf packages/babel-runtime-corejs2/core-js
|
||||
|
||||
clean-all:
|
||||
@@ -254,7 +289,7 @@ clean-all:
|
||||
|
||||
update-env-corejs-fixture:
|
||||
rm -rf packages/babel-preset-env/node_modules/core-js-compat
|
||||
$(YARN)
|
||||
$(YARN) lerna bootstrap
|
||||
$(MAKE) build-bundle
|
||||
OVERWRITE=true $(YARN) jest packages/babel-preset-env
|
||||
|
||||
@@ -270,8 +305,16 @@ define clean-source-test
|
||||
endef
|
||||
|
||||
define clean-source-all
|
||||
$(call clean-source-lib, $1)
|
||||
# TODO: Don't delete eslint/*/lib when they use src
|
||||
$(if $(filter-out $1, eslint), $(call clean-source-lib, $1))
|
||||
rm -rf $(1)/*/node_modules
|
||||
rm -rf $(1)/*/package-lock.json
|
||||
|
||||
endef
|
||||
|
||||
define set-json-field
|
||||
node -e "\
|
||||
require('fs').writeFileSync('$1'.trim(), \
|
||||
JSON.stringify({ ...require('$1'.trim()), $2: $3 }, null, 2) + '\\n' \
|
||||
)"
|
||||
endef
|
||||
|
||||
28
README.md
28
README.md
@@ -8,16 +8,14 @@
|
||||
The compiler for writing next generation JavaScript.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://gitpod.io/#https://github.com/babel/babel"><img alt="Gitpod ready-to-code" src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod"></a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/@babel/core"><img alt="v7 npm Downloads" src="https://img.shields.io/npm/dm/@babel/core.svg?maxAge=43200&label=v7%20downloads"></a>
|
||||
<a href="https://www.npmjs.com/package/babel-core"><img alt="v6 npm Downloads" src="https://img.shields.io/npm/dm/babel-core.svg?maxAge=43200&label=v6%20downloads"></a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://github.com/babel/babel/actions/workflows/ci.yml"><img alt="GitHub CI Status" src="https://github.com/babel/babel/actions/workflows/ci.yml/badge.svg?branch=main"></a>
|
||||
<a href="https://codecov.io/github/babel/babel"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/babel/babel/main.svg?maxAge=43200"></a>
|
||||
<a href="https://travis-ci.com/babel/babel"><img alt="Travis Status" src="https://img.shields.io/travis/com/babel/babel/master.svg?label=travis&maxAge=43200"></a>
|
||||
<a href="https://circleci.com/gh/babel/babel"><img alt="CircleCI Status" src="https://img.shields.io/circleci/project/github/babel/babel/master.svg?label=circle&maxAge=43200"></a>
|
||||
<a href="https://codecov.io/github/babel/babel"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/babel/babel/master.svg?maxAge=43200"></a>
|
||||
<a href="https://slack.babeljs.io/"><img alt="Slack Status" src="https://slack.babeljs.io/badge.svg"></a>
|
||||
<a href="https://twitter.com/intent/follow?screen_name=babeljs"><img alt="Follow on Twitter" src="https://img.shields.io/twitter/follow/babeljs.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
@@ -33,7 +31,7 @@
|
||||
Babel (pronounced ["babble"](https://soundcloud.com/sebmck/how-to-pronounce-babel)) is a community-driven project used by many companies and projects, and is maintained by a group of [volunteers](https://babeljs.io/team). If you'd like to help support the future of the project, please consider:
|
||||
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/) for guidance!)
|
||||
- Giving funds by becoming a sponsor on [Open Collective](https://opencollective.com/babel) or [GitHub](https://github.com/sponsors/babel/) (which goes to our Open Collective account)!
|
||||
- Giving funds by becoming a sponsor on [Open Collective](https://opencollective.com/babel) or [Patreon](https://www.patreon.com/henryzhu)!
|
||||
|
||||
## Sponsors
|
||||
|
||||
@@ -62,21 +60,19 @@ Babel is a tool that helps you write code in the latest version of JavaScript. W
|
||||
**In**
|
||||
|
||||
```js
|
||||
// ES2020 nullish coalescing
|
||||
function greet(input) {
|
||||
return input ?? "Hello world";
|
||||
}
|
||||
// ES2015 arrow function
|
||||
[1, 2, 3].map((n) => n + 1);
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```js
|
||||
function greet(input) {
|
||||
return input != null ? input : "Hello world";
|
||||
}
|
||||
[1, 2, 3].map(function(n) {
|
||||
return n + 1;
|
||||
});
|
||||
```
|
||||
|
||||
Try it out at our [REPL](https://babel.dev/repl#?browsers=defaults%2C%20not%20ie%2011&loose=true&code_lz=GYVwdgxgLglg9mABAcwE4FN1QBQzABxCgEpEBvAKEUQyhFST0KkQH5XEAiACXQBs-cRAHc4qPgBNOAbgoBfIA&shippedProposals=true&sourceType=script&lineWrap=true&presets=env%2Cenv&prettier=true).
|
||||
Try it out at our [REPL](https://babeljs.io/repl/build/master#?code_lz=NoRgNATGDMC6B0BbAhgBwBQDsAEBeAfNjgNTYgCUA3EA&lineWrap=true&presets=es2015%2Ces2016%2Ces2017&version=7.0.0-beta.2).
|
||||
|
||||
## FAQ
|
||||
|
||||
@@ -90,7 +86,7 @@ I'm so glad you asked: [Hallelujah —— In Praise of Babel](SONG.md) by [@angu
|
||||
|
||||
### Looking for support?
|
||||
|
||||
For questions and support please join our [Slack Community](https://slack.babeljs.io/) (you can [sign up here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
||||
For questions and support please join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
||||
|
||||
### Where are the docs?
|
||||
|
||||
@@ -104,7 +100,7 @@ Please read through our [CONTRIBUTING.md](CONTRIBUTING.md) and fill out the issu
|
||||
|
||||
Check out:
|
||||
|
||||
- Our [#development](https://babeljs.slack.com/messages/development) Slack channel and say hi! ([sign-up](https://slack.babeljs.io))
|
||||
- Our [#development](https://babeljs.slack.com/messages/development) Slack channel and say hi ([signup](https://slack.babeljs.io))!
|
||||
- Issues with the [good first issue](https://github.com/babel/babel/labels/good%20first%20issue) and [help wanted](https://github.com/babel/babel/labels/help%20wanted) label. We suggest also looking at the [closed ones](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aclosed+label%3A%22good+first+issue%22) to get a sense of the kinds of issues you can tackle.
|
||||
|
||||
Some resources:
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
const { transformSync } = require("@babel/core");
|
||||
const { mkdirSync, statSync, readFileSync, writeFileSync } = require("fs");
|
||||
const { dirname } = require("path");
|
||||
const chalk = require("chalk");
|
||||
const fancyLog = require("fancy-log");
|
||||
|
||||
function needCompile(src, dest) {
|
||||
let destStat;
|
||||
try {
|
||||
destStat = statSync(dest);
|
||||
} catch (err) {
|
||||
if (err.code === "ENOENT") {
|
||||
return true;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const srcStat = statSync(src);
|
||||
return srcStat.mtimeMs > destStat.mtimeMs;
|
||||
}
|
||||
|
||||
exports.transform = function (src, dest) {
|
||||
mkdirSync(dirname(dest), { recursive: true });
|
||||
if (!needCompile(src, dest)) {
|
||||
return;
|
||||
}
|
||||
fancyLog(`Compiling '${chalk.cyan(src)}'...`);
|
||||
const content = readFileSync(src, { encoding: "utf8" });
|
||||
const { code } = transformSync(content, {
|
||||
filename: src,
|
||||
caller: {
|
||||
// We have wrapped packages/babel-core/src/config/files/configuration.js with feature detection
|
||||
supportsDynamicImport: true,
|
||||
name: "babel-worker",
|
||||
},
|
||||
});
|
||||
|
||||
writeFileSync(dest, code, "utf8");
|
||||
};
|
||||
682
babel.config.js
682
babel.config.js
@@ -1,64 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
const pathUtils = require("path");
|
||||
const fs = require("fs");
|
||||
const { parseSync } = require("@babel/core");
|
||||
|
||||
function normalize(src) {
|
||||
return src.replace(/\//, pathUtils.sep);
|
||||
}
|
||||
|
||||
module.exports = function (api) {
|
||||
module.exports = function(api) {
|
||||
const env = api.env();
|
||||
|
||||
const sources = ["packages/*/src", "codemods/*/src", "eslint/*/src"];
|
||||
|
||||
const includeCoverage = process.env.BABEL_COVERAGE === "true";
|
||||
|
||||
const envOpts = {
|
||||
shippedProposals: true,
|
||||
const envOptsNoTargets = {
|
||||
loose: true,
|
||||
modules: false,
|
||||
exclude: [
|
||||
"transform-typeof-symbol",
|
||||
// We need to enable useBuiltIns
|
||||
"proposal-object-rest-spread",
|
||||
],
|
||||
exclude: ["transform-typeof-symbol"],
|
||||
};
|
||||
const envOpts = Object.assign({}, envOptsNoTargets);
|
||||
|
||||
// These are "safe" assumptions, that we can enable globally
|
||||
const assumptions = {
|
||||
constantSuper: true,
|
||||
ignoreFunctionLength: true,
|
||||
ignoreToPrimitiveHint: true,
|
||||
mutableTemplateObject: true,
|
||||
noClassCalls: true,
|
||||
noDocumentAll: true,
|
||||
noNewArrows: true,
|
||||
setClassMethods: true,
|
||||
setComputedProperties: true,
|
||||
setSpreadProperties: true,
|
||||
skipForOfIteratorClosing: true,
|
||||
superIsCallableConstructor: true,
|
||||
};
|
||||
|
||||
// These are "less safe": we only enable them on our own code
|
||||
// and not when compiling dependencies.
|
||||
const sourceAssumptions = {
|
||||
objectRestNoSymbols: true,
|
||||
pureGetters: true,
|
||||
setPublicClassFields: true,
|
||||
};
|
||||
|
||||
const parserAssumptions = {
|
||||
iterableIsArray: true,
|
||||
};
|
||||
|
||||
let targets = {};
|
||||
let convertESM = true;
|
||||
let ignoreLib = true;
|
||||
let includeRegeneratorRuntime = false;
|
||||
let needsPolyfillsForOldNode = false;
|
||||
let dynamicESLintVersionCheck = false;
|
||||
|
||||
let transformRuntimeOptions;
|
||||
|
||||
@@ -67,67 +23,47 @@ module.exports = function (api) {
|
||||
// unambiguous to keep things simple until we get around to renaming
|
||||
// the modules to be more easily distinguished from CommonJS
|
||||
const unambiguousSources = [
|
||||
...sources,
|
||||
"packages/*/src",
|
||||
"packages/*/test",
|
||||
"codemods/*/src",
|
||||
"codemods/*/test",
|
||||
"eslint/*/src",
|
||||
"eslint/*/test",
|
||||
];
|
||||
|
||||
const lazyRequireSources = [
|
||||
"./packages/babel-cli",
|
||||
"./packages/babel-core",
|
||||
"./packages/babel-preset-env/src/available-plugins.js",
|
||||
];
|
||||
|
||||
switch (env) {
|
||||
// Configs used during bundling builds.
|
||||
case "standalone":
|
||||
includeRegeneratorRuntime = true;
|
||||
convertESM = false;
|
||||
ignoreLib = false;
|
||||
// rollup-commonjs will converts node_modules to ESM
|
||||
unambiguousSources.push(
|
||||
"/**/node_modules",
|
||||
"packages/babel-preset-env/data",
|
||||
"packages/babel-compat-data",
|
||||
"packages/babel-runtime/regenerator"
|
||||
);
|
||||
break;
|
||||
unambiguousSources.push("packages/babel-runtime/regenerator");
|
||||
case "rollup":
|
||||
convertESM = false;
|
||||
ignoreLib = false;
|
||||
// rollup-commonjs will converts node_modules to ESM
|
||||
unambiguousSources.push(
|
||||
"/**/node_modules",
|
||||
"**/node_modules",
|
||||
"packages/babel-preset-env/data",
|
||||
"packages/babel-compat-data"
|
||||
);
|
||||
targets = { node: nodeVersion };
|
||||
needsPolyfillsForOldNode = true;
|
||||
if (env === "rollup") envOpts.targets = { node: nodeVersion };
|
||||
break;
|
||||
case "test-legacy": // In test-legacy environment, we build babel on latest node but test on minimum supported legacy versions
|
||||
dynamicESLintVersionCheck = true;
|
||||
// fall through
|
||||
case "production":
|
||||
// Config during builds before publish.
|
||||
targets = { node: nodeVersion };
|
||||
needsPolyfillsForOldNode = true;
|
||||
break;
|
||||
case "test":
|
||||
targets = { node: "current" };
|
||||
needsPolyfillsForOldNode = true;
|
||||
dynamicESLintVersionCheck = true;
|
||||
envOpts.targets = {
|
||||
node: nodeVersion,
|
||||
};
|
||||
break;
|
||||
case "development":
|
||||
envOpts.debug = true;
|
||||
targets = { node: "current" };
|
||||
dynamicESLintVersionCheck = true;
|
||||
envOpts.targets = {
|
||||
node: "current",
|
||||
};
|
||||
break;
|
||||
case "test":
|
||||
envOpts.targets = {
|
||||
node: "current",
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
if (process.env.STRIP_BABEL_8_FLAG && bool(process.env.BABEL_8_BREAKING)) {
|
||||
// Never apply polyfills when compiling for Babel 8
|
||||
needsPolyfillsForOldNode = false;
|
||||
}
|
||||
|
||||
if (includeRegeneratorRuntime) {
|
||||
@@ -141,9 +77,6 @@ module.exports = function (api) {
|
||||
}
|
||||
|
||||
const config = {
|
||||
targets,
|
||||
assumptions,
|
||||
|
||||
// Our dependencies are all standard CommonJS, along with all sorts of
|
||||
// other random files in Babel's codebase, so we use script as the default,
|
||||
// and then mark actual modules as modules farther down.
|
||||
@@ -156,101 +89,58 @@ module.exports = function (api) {
|
||||
"packages/*/test/fixtures",
|
||||
ignoreLib ? "packages/*/lib" : null,
|
||||
"packages/babel-standalone/babel.js",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.map(normalize),
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-typescript",
|
||||
{ onlyRemoveTypeImports: true, allowDeclareFields: true },
|
||||
],
|
||||
["@babel/env", envOpts],
|
||||
["@babel/preset-flow", { allowDeclareFields: true }],
|
||||
],
|
||||
"packages/babel-preset-env-standalone/babel-preset-env.js",
|
||||
].filter(Boolean),
|
||||
presets: [["@babel/env", envOpts]],
|
||||
plugins: [
|
||||
["@babel/proposal-object-rest-spread", { useBuiltIns: true }],
|
||||
|
||||
convertESM ? "@babel/proposal-export-namespace-from" : null,
|
||||
convertESM ? pluginImportMetaUrl : null,
|
||||
|
||||
pluginPackageJsonMacro,
|
||||
|
||||
process.env.STRIP_BABEL_8_FLAG && [
|
||||
pluginToggleBabel8Breaking,
|
||||
{ breaking: bool(process.env.BABEL_8_BREAKING) },
|
||||
// TODO: Use @babel/preset-flow when
|
||||
// https://github.com/babel/babel/issues/7233 is fixed
|
||||
"@babel/plugin-transform-flow-strip-types",
|
||||
["@babel/proposal-class-properties", { loose: true }],
|
||||
"@babel/proposal-export-namespace-from",
|
||||
"@babel/proposal-numeric-separator",
|
||||
[
|
||||
"@babel/proposal-object-rest-spread",
|
||||
{ useBuiltIns: true, loose: true },
|
||||
],
|
||||
needsPolyfillsForOldNode && pluginPolyfillsOldNode,
|
||||
["@babel/plugin-proposal-optional-chaining", { loose: true }],
|
||||
["@babel/plugin-proposal-nullish-coalescing-operator", { loose: true }],
|
||||
|
||||
convertESM ? "@babel/transform-modules-commonjs" : null,
|
||||
// Until Jest supports native mjs, we must simulate it 🤷
|
||||
env === "test" || env === "development"
|
||||
? "@babel/plugin-proposal-dynamic-import"
|
||||
: null,
|
||||
].filter(Boolean),
|
||||
overrides: [
|
||||
{
|
||||
test: [
|
||||
"packages/babel-parser",
|
||||
"packages/babel-helper-validator-identifier",
|
||||
].map(normalize),
|
||||
test: "packages/babel-parser",
|
||||
plugins: [
|
||||
"babel-plugin-transform-charcodes",
|
||||
pluginBabelParserTokenType,
|
||||
["@babel/transform-for-of", { assumeArray: true }],
|
||||
],
|
||||
assumptions: parserAssumptions,
|
||||
},
|
||||
{
|
||||
test: [
|
||||
"packages/babel-generator",
|
||||
"packages/babel-plugin-proposal-decorators",
|
||||
].map(normalize),
|
||||
plugins: ["babel-plugin-transform-charcodes"],
|
||||
},
|
||||
convertESM && {
|
||||
test: ["./packages/babel-node/src"].map(normalize),
|
||||
// Used to conditionally import kexec
|
||||
plugins: ["@babel/plugin-proposal-dynamic-import"],
|
||||
},
|
||||
{
|
||||
test: sources.map(normalize),
|
||||
assumptions: sourceAssumptions,
|
||||
plugins: [transformNamedBabelTypesImportToDestructuring],
|
||||
},
|
||||
convertESM && {
|
||||
test: lazyRequireSources.map(normalize),
|
||||
test: ["./packages/babel-cli", "./packages/babel-core"],
|
||||
plugins: [
|
||||
// Explicitly use the lazy version of CommonJS modules.
|
||||
[
|
||||
"@babel/transform-modules-commonjs",
|
||||
{ importInterop: importInteropSrc, lazy: true },
|
||||
],
|
||||
],
|
||||
},
|
||||
convertESM && {
|
||||
test: sources.map(normalize),
|
||||
exclude: lazyRequireSources.map(normalize),
|
||||
plugins: [
|
||||
[
|
||||
"@babel/transform-modules-commonjs",
|
||||
{ importInterop: importInteropSrc },
|
||||
],
|
||||
],
|
||||
convertESM
|
||||
? ["@babel/transform-modules-commonjs", { lazy: true }]
|
||||
: null,
|
||||
].filter(Boolean),
|
||||
},
|
||||
{
|
||||
test: sources.map(source => normalize(source.replace("/src", "/test"))),
|
||||
plugins: [
|
||||
[
|
||||
"@babel/transform-modules-commonjs",
|
||||
{ importInterop: importInteropTest },
|
||||
],
|
||||
],
|
||||
test: "./packages/babel-polyfill",
|
||||
presets: [["@babel/env", envOptsNoTargets]],
|
||||
},
|
||||
{
|
||||
test: unambiguousSources.map(normalize),
|
||||
test: unambiguousSources,
|
||||
sourceType: "unambiguous",
|
||||
},
|
||||
includeRegeneratorRuntime && {
|
||||
exclude: /regenerator-runtime/,
|
||||
plugins: [["@babel/transform-runtime", transformRuntimeOptions]],
|
||||
},
|
||||
dynamicESLintVersionCheck && {
|
||||
test: ["./eslint/*/src"].map(normalize),
|
||||
plugins: [pluginDynamicESLintVersionCheck],
|
||||
},
|
||||
].filter(Boolean),
|
||||
};
|
||||
|
||||
@@ -262,471 +152,3 @@ module.exports = function (api) {
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
const monorepoPackages = ["codemods", "eslint", "packages"]
|
||||
.map(folder => fs.readdirSync(__dirname + "/" + folder))
|
||||
.reduce((a, b) => a.concat(b))
|
||||
.map(name => name.replace(/^babel-/, "@babel/"));
|
||||
|
||||
function importInteropSrc(source) {
|
||||
if (
|
||||
// These internal files are "real CJS" (whose default export is
|
||||
// on module.exports) and not compiled ESM.
|
||||
source.startsWith("@babel/compat-data/") ||
|
||||
source.includes("babel-eslint-shared-fixtures/utils")
|
||||
) {
|
||||
return "node";
|
||||
}
|
||||
if (
|
||||
source[0] === "." ||
|
||||
monorepoPackages.some(name => source.startsWith(name))
|
||||
) {
|
||||
// We don't need to worry about interop for internal files, since we know
|
||||
// for sure that they are ESM modules compiled to CJS
|
||||
return "none";
|
||||
}
|
||||
|
||||
// For external modules, we want to match the Node.js behavior
|
||||
return "node";
|
||||
}
|
||||
|
||||
function importInteropTest(source) {
|
||||
// This file will soon have an esm entrypoint
|
||||
if (source === "@babel/helper-plugin-test-runner") {
|
||||
return "none";
|
||||
}
|
||||
if (
|
||||
// non-test files
|
||||
!source.startsWith(".") ||
|
||||
// lib files
|
||||
/(?:\.\.\/)+(?:babel-[a-z-]+\/)?lib/.test(source)
|
||||
) {
|
||||
return "node";
|
||||
}
|
||||
return "babel";
|
||||
}
|
||||
|
||||
// env vars from the cli are always strings, so !!ENV_VAR returns true for "false"
|
||||
function bool(value) {
|
||||
return value && value !== "false" && value !== "0";
|
||||
}
|
||||
|
||||
// A minimum semver GTE implementation
|
||||
// Limitation:
|
||||
// - it only supports comparing major and minor version, assuming Node.js will never ship
|
||||
// features in patch release so we will never need to compare a version with "1.2.3"
|
||||
//
|
||||
// @example
|
||||
// semverGte("8.10", "8.9") // true
|
||||
// semverGte("8.9", "8.9") // true
|
||||
// semverGte("9.0", "8.9") // true
|
||||
// semverGte("8.9", "8.10") // false
|
||||
// TODO: figure out how to inject it to the `@babel/template` usage so we don't need to
|
||||
// copy and paste it.
|
||||
// `((v,w)=>(v=v.split("."),w=w.split("."),+v[0]>+w[0]||v[0]==w[0]&&+v[1]>=+w[1]))`;
|
||||
|
||||
// TODO(Babel 8) This polyfills are only needed for Node.js 6 and 8
|
||||
/** @param {import("@babel/core")} api */
|
||||
function pluginPolyfillsOldNode({ template, types: t }) {
|
||||
const polyfills = [
|
||||
{
|
||||
name: "require.resolve",
|
||||
necessary({ node, parent }) {
|
||||
return (
|
||||
t.isCallExpression(parent, { callee: node }) &&
|
||||
parent.arguments.length > 1
|
||||
);
|
||||
},
|
||||
supported({ parent: { arguments: args } }) {
|
||||
return (
|
||||
t.isObjectExpression(args[1]) &&
|
||||
args[1].properties.length === 1 &&
|
||||
t.isIdentifier(args[1].properties[0].key, { name: "paths" }) &&
|
||||
t.isArrayExpression(args[1].properties[0].value) &&
|
||||
args[1].properties[0].value.elements.length === 1
|
||||
);
|
||||
},
|
||||
// require.resolve's paths option has been introduced in Node.js 8.9
|
||||
// https://nodejs.org/api/modules.html#modules_require_resolve_request_options
|
||||
replacement: template({ syntacticPlaceholders: true })`
|
||||
((v,w)=>(v=v.split("."),w=w.split("."),+v[0]>+w[0]||v[0]==w[0]&&+v[1]>=+w[1]))(process.versions.node, "8.9")
|
||||
? require.resolve
|
||||
: (/* request */ r, { paths: [/* base */ b] }, M = require("module")) => {
|
||||
let /* filename */ f = M._findPath(r, M._nodeModulePaths(b).concat(b));
|
||||
if (f) return f;
|
||||
f = new Error(\`Cannot resolve module '\${r}'\`);
|
||||
f.code = "MODULE_NOT_FOUND";
|
||||
throw f;
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
// NOTE: This polyfills depends on the "make-dir" library. Any package
|
||||
// using fs.mkdirSync must have "make-dir" as a dependency.
|
||||
name: "fs.mkdirSync",
|
||||
necessary({ node, parent }) {
|
||||
return (
|
||||
t.isCallExpression(parent, { callee: node }) &&
|
||||
parent.arguments.length > 1
|
||||
);
|
||||
},
|
||||
supported({ parent: { arguments: args } }) {
|
||||
return (
|
||||
t.isObjectExpression(args[1]) &&
|
||||
args[1].properties.length === 1 &&
|
||||
t.isIdentifier(args[1].properties[0].key, { name: "recursive" }) &&
|
||||
t.isBooleanLiteral(args[1].properties[0].value, { value: true })
|
||||
);
|
||||
},
|
||||
// fs.mkdirSync's recursive option has been introduced in Node.js 10.12
|
||||
// https://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_options
|
||||
replacement: template`
|
||||
((v,w)=>(v=v.split("."),w=w.split("."),+v[0]>+w[0]||v[0]==w[0]&&+v[1]>=+w[1]))(process.versions.node, "10.12")
|
||||
? fs.mkdirSync
|
||||
: require("make-dir").sync
|
||||
`,
|
||||
},
|
||||
{
|
||||
// NOTE: This polyfills depends on the "node-environment-flags"
|
||||
// library. Any package using process.allowedNodeEnvironmentFlags
|
||||
// must have "node-environment-flags" as a dependency.
|
||||
name: "process.allowedNodeEnvironmentFlags",
|
||||
necessary({ parent, node }) {
|
||||
// To avoid infinite replacement loops
|
||||
return !t.isLogicalExpression(parent, { operator: "||", left: node });
|
||||
},
|
||||
supported: () => true,
|
||||
// process.allowedNodeEnvironmentFlags has been introduced in Node.js 10.10
|
||||
// https://nodejs.org/api/process.html#process_process_allowednodeenvironmentflags
|
||||
replacement: template`
|
||||
process.allowedNodeEnvironmentFlags || require("node-environment-flags")
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
MemberExpression(path) {
|
||||
for (const polyfill of polyfills) {
|
||||
if (!path.matchesPattern(polyfill.name)) continue;
|
||||
|
||||
if (!polyfill.necessary(path)) return;
|
||||
if (!polyfill.supported(path)) {
|
||||
throw path.buildCodeFrameError(
|
||||
`This '${polyfill.name}' usage is not supported by the inline polyfill.`
|
||||
);
|
||||
}
|
||||
|
||||
path.replaceWith(polyfill.replacement());
|
||||
|
||||
break;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function pluginToggleBabel8Breaking({ types: t }, { breaking }) {
|
||||
return {
|
||||
visitor: {
|
||||
"IfStatement|ConditionalExpression"(path) {
|
||||
let test = path.get("test");
|
||||
let keepConsequent = breaking;
|
||||
|
||||
if (test.isUnaryExpression({ operator: "!" })) {
|
||||
test = test.get("argument");
|
||||
keepConsequent = !keepConsequent;
|
||||
}
|
||||
|
||||
// yarn-plugin-conditions inject bool(process.env.BABEL_8_BREAKING)
|
||||
// tests, to properly cast the env variable to a boolean.
|
||||
if (
|
||||
test.isCallExpression() &&
|
||||
test.get("callee").isIdentifier({ name: "bool" }) &&
|
||||
test.get("arguments").length === 1
|
||||
) {
|
||||
test = test.get("arguments")[0];
|
||||
}
|
||||
|
||||
if (!test.matchesPattern("process.env.BABEL_8_BREAKING")) return;
|
||||
|
||||
path.replaceWith(
|
||||
keepConsequent
|
||||
? path.node.consequent
|
||||
: path.node.alternate || t.emptyStatement()
|
||||
);
|
||||
},
|
||||
MemberExpression(path) {
|
||||
if (path.matchesPattern("process.env.BABEL_8_BREAKING")) {
|
||||
throw path.buildCodeFrameError("This check could not be stripped.");
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function pluginPackageJsonMacro({ types: t }) {
|
||||
const fnName = "PACKAGE_JSON";
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
ReferencedIdentifier(path) {
|
||||
if (path.isIdentifier({ name: fnName })) {
|
||||
throw path.buildCodeFrameError(
|
||||
`"${fnName}" is only supported in member expressions.`
|
||||
);
|
||||
}
|
||||
},
|
||||
MemberExpression(path) {
|
||||
if (!path.get("object").isIdentifier({ name: fnName })) return;
|
||||
|
||||
if (path.node.computed) {
|
||||
throw path.buildCodeFrameError(
|
||||
`"${fnName}" does not support computed properties.`
|
||||
);
|
||||
}
|
||||
const field = path.node.property.name;
|
||||
|
||||
// TODO: When dropping old Node.js versions, use require.resolve
|
||||
// instead of looping through the folders hierarchy
|
||||
|
||||
let pkg;
|
||||
for (let dir = pathUtils.dirname(this.filename); ; ) {
|
||||
try {
|
||||
pkg = fs.readFileSync(pathUtils.join(dir, "package.json"), "utf8");
|
||||
break;
|
||||
} catch (_) {}
|
||||
|
||||
const prev = dir;
|
||||
dir = pathUtils.resolve(dir, "..");
|
||||
|
||||
// We are in the root and didn't find a package.json file
|
||||
if (dir === prev) return;
|
||||
}
|
||||
|
||||
const value = JSON.parse(pkg)[field];
|
||||
path.replaceWith(t.valueToNode(value));
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// transform `import { x } from "@babel/types"` to `import * as _t from "@babel/types"; const { x } = _t;
|
||||
function transformNamedBabelTypesImportToDestructuring({
|
||||
types: {
|
||||
cloneNode,
|
||||
importNamespaceSpecifier,
|
||||
objectPattern,
|
||||
objectProperty,
|
||||
variableDeclarator,
|
||||
variableDeclaration,
|
||||
},
|
||||
}) {
|
||||
return {
|
||||
name: "transform-babel-types-named-imports",
|
||||
visitor: {
|
||||
ImportDeclaration(path) {
|
||||
const { node } = path;
|
||||
if (
|
||||
node.importKind === "value" &&
|
||||
node.source.value === "@babel/types" &&
|
||||
node.specifiers[0].type === "ImportSpecifier"
|
||||
) {
|
||||
const hoistedDestructuringProperties = [];
|
||||
for (const { imported, local } of node.specifiers) {
|
||||
hoistedDestructuringProperties.push(
|
||||
objectProperty(
|
||||
imported,
|
||||
local,
|
||||
false,
|
||||
imported.name === local.name
|
||||
)
|
||||
);
|
||||
}
|
||||
const babelTypeNsImport = path.scope.generateUidIdentifier("t");
|
||||
node.specifiers = [importNamespaceSpecifier(babelTypeNsImport)];
|
||||
path.insertAfter([
|
||||
variableDeclaration("const", [
|
||||
variableDeclarator(
|
||||
objectPattern(hoistedDestructuringProperties),
|
||||
cloneNode(babelTypeNsImport)
|
||||
),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function pluginImportMetaUrl({ types: t, template }) {
|
||||
const isImportMeta = node =>
|
||||
t.isMetaProperty(node) &&
|
||||
t.isIdentifier(node.meta, { name: "import" }) &&
|
||||
t.isIdentifier(node.property, { name: "meta" });
|
||||
|
||||
const isImportMetaUrl = node =>
|
||||
t.isMemberExpression(node, { computed: false }) &&
|
||||
t.isIdentifier(node.property, { name: "url" }) &&
|
||||
isImportMeta(node.object);
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
Program(programPath) {
|
||||
// We must be sure to run this before the instanbul plugins, because its
|
||||
// instrumentation breaks our detection.
|
||||
programPath.traverse({
|
||||
// fileURLToPath(import.meta.url)
|
||||
CallExpression(path) {
|
||||
const { node } = path;
|
||||
|
||||
if (
|
||||
!t.isIdentifier(node.callee, { name: "fileURLToPath" }) ||
|
||||
node.arguments.length !== 1
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const arg = node.arguments[0];
|
||||
|
||||
if (
|
||||
!t.isMemberExpression(arg, { computed: false }) ||
|
||||
!t.isIdentifier(arg.property, { name: "url" }) ||
|
||||
!isImportMeta(arg.object)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(t.identifier("__filename"));
|
||||
},
|
||||
|
||||
// const require = createRequire(import.meta.url)
|
||||
VariableDeclarator(path) {
|
||||
const { node } = path;
|
||||
|
||||
if (
|
||||
!t.isIdentifier(node.id, { name: "require" }) ||
|
||||
!t.isCallExpression(node.init) ||
|
||||
!t.isIdentifier(node.init.callee, { name: "createRequire" }) ||
|
||||
node.init.arguments.length !== 1 ||
|
||||
!isImportMetaUrl(node.init.arguments[0])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's just remove this declaration to unshadow the "global" cjs require.
|
||||
path.remove();
|
||||
},
|
||||
|
||||
// import.meta.url
|
||||
MemberExpression(path) {
|
||||
if (!isImportMetaUrl(path.node)) return;
|
||||
|
||||
path.replaceWith(
|
||||
template.expression
|
||||
.ast`\`file://\${__filename.replace(/\\\\/g, "/")}\``
|
||||
);
|
||||
},
|
||||
|
||||
MetaProperty(path) {
|
||||
if (isImportMeta(path.node)) {
|
||||
throw path.buildCodeFrameError("Unsupported import.meta");
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const tokenTypesMapping = new Map();
|
||||
const tokenTypeSourcePath = "./packages/babel-parser/src/tokenizer/types.js";
|
||||
|
||||
function pluginBabelParserTokenType({
|
||||
types: { isIdentifier, numericLiteral },
|
||||
}) {
|
||||
return {
|
||||
visitor: {
|
||||
MemberExpression(path) {
|
||||
const { node } = path;
|
||||
if (
|
||||
isIdentifier(node.object, { name: "tt" }) &&
|
||||
isIdentifier(node.property) &&
|
||||
!node.computed
|
||||
) {
|
||||
const tokenName = node.property.name;
|
||||
const tokenType = tokenTypesMapping.get(node.property.name);
|
||||
if (tokenType === undefined) {
|
||||
throw path.buildCodeFrameError(
|
||||
`${tokenName} is not defined in ${tokenTypeSourcePath}`
|
||||
);
|
||||
}
|
||||
path.replaceWith(numericLiteral(tokenType));
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
(function generateTokenTypesMapping() {
|
||||
const tokenTypesAst = parseSync(
|
||||
fs.readFileSync(tokenTypeSourcePath, {
|
||||
encoding: "utf-8",
|
||||
}),
|
||||
{
|
||||
configFile: false,
|
||||
parserOpts: { attachComments: false, plugins: ["flow"] },
|
||||
}
|
||||
);
|
||||
|
||||
let typesDeclaration;
|
||||
for (const n of tokenTypesAst.program.body) {
|
||||
if (n.type === "ExportNamedDeclaration" && n.exportKind === "value") {
|
||||
const declarations = n.declaration.declarations;
|
||||
if (declarations !== undefined) typesDeclaration = declarations[0];
|
||||
if (
|
||||
typesDeclaration !== undefined &&
|
||||
typesDeclaration.id.name === "types"
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typesDeclaration === undefined) {
|
||||
throw new Error(
|
||||
"The plugin can not find TokenType definition in " + tokenTypeSourcePath
|
||||
);
|
||||
}
|
||||
|
||||
const tokenTypesDefinition = typesDeclaration.init.properties;
|
||||
for (let i = 0; i < tokenTypesDefinition.length; i++) {
|
||||
tokenTypesMapping.set(tokenTypesDefinition[i].key.name, i);
|
||||
}
|
||||
})();
|
||||
|
||||
// Transforms
|
||||
// ESLINT_VERSION
|
||||
// to
|
||||
// process.env.ESLINT_VERSION_FOR_BABEL
|
||||
// ? parseInt(process.env.ESLINT_VERSION_FOR_BABEL, 10)
|
||||
// : ESLINT_VERSION
|
||||
function pluginDynamicESLintVersionCheck({ template }) {
|
||||
const transformed = new WeakSet();
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
ReferencedIdentifier(path) {
|
||||
if (path.node.name !== "ESLINT_VERSION") return;
|
||||
|
||||
if (transformed.has(path.node)) return;
|
||||
transformed.add(path.node);
|
||||
|
||||
path.replaceWith(template.expression.ast`
|
||||
process.env.ESLINT_VERSION_FOR_BABEL
|
||||
? parseInt(process.env.ESLINT_VERSION_FOR_BABEL, 10)
|
||||
: ${path.node}
|
||||
`);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/core";
|
||||
import current from "@babel/core";
|
||||
import parser from "@babel-baseline/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
const fixtureName = "babel-parser-expression.txt";
|
||||
|
||||
function createInput() {
|
||||
return parser.parse(
|
||||
readFileSync(new URL("./" + fixtureName, import.meta.url), {
|
||||
encoding: "utf-8",
|
||||
}),
|
||||
{ sourceType: "module", plugins: ["flow"] }
|
||||
);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
const input = createInput();
|
||||
suite.add(
|
||||
`${name} ${fixtureName}`,
|
||||
() => {
|
||||
implementation(input, {
|
||||
plugins: ["@babel/preset-env", "@babel/preset-flow"],
|
||||
targets: "ie 11",
|
||||
configFile: false,
|
||||
babelrc: false,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
{
|
||||
// increase minSamples for accuracy
|
||||
minSamples: 100,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.transformFromAstSync, {});
|
||||
benchCases("current", current.transformFromAstSync, {});
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "@babel/generator";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse(";".repeat(length));
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} empty statements`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "@babel/generator";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse("a;".repeat(length));
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} 1-length identifiers`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "@babel/generator";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse("parseMaybeImportAssertion;".repeat(length));
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} 25-length identifiers`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "@babel/generator";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse(
|
||||
readFileSync(new URL("./jquery-3.6.txt", import.meta.url), {
|
||||
encoding: "utf-8",
|
||||
}).repeat(length)
|
||||
);
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [1, 2]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} jquery 3.6`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,3 +0,0 @@
|
||||
import "./isIdentifierChar.bench.mjs";
|
||||
import "./isIdentifierStart.bench.mjs";
|
||||
import "./isIdentifierName.bench.mjs";
|
||||
@@ -1,31 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/helper-validator-identifier";
|
||||
import current from "@babel/helper-validator-identifier";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isIdentifierChar on 4 ASCII characters", () => {
|
||||
implementation.isIdentifierChar(0x61);
|
||||
implementation.isIdentifierChar(0x7b);
|
||||
implementation.isIdentifierChar(0x5f);
|
||||
implementation.isIdentifierChar(0x24);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierChar on 4 non-ASCII characters", () => {
|
||||
implementation.isIdentifierChar(0x80);
|
||||
implementation.isIdentifierChar(0x4e00);
|
||||
implementation.isIdentifierChar(0xffff);
|
||||
implementation.isIdentifierChar(0x10000);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierChar on TIP character", () => {
|
||||
implementation.isIdentifierChar(0x30000);
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,30 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/helper-validator-identifier";
|
||||
import current from "@babel/helper-validator-identifier";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isIdentifierName on 2 short ASCII words", () => {
|
||||
implementation.isIdentifierName("aforementioned");
|
||||
implementation.isIdentifierName("zap cannon");
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierName on 1 long ASCII words", () => {
|
||||
implementation.isIdentifierName(
|
||||
"Pneumonoultramicroscopicsilicovolcanoconiosis"
|
||||
);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierName on 3 non-ASCII words", () => {
|
||||
implementation.isIdentifierName("مذكور أعلاه");
|
||||
implementation.isIdentifierName("cañón de zap");
|
||||
implementation.isIdentifierName("𠡦𠧋𡆠囝〇𠁈𢘑𤯔𠀑埊");
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,31 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/helper-validator-identifier";
|
||||
import current from "@babel/helper-validator-identifier";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isIdentifierStart on 4 ASCII characters", () => {
|
||||
implementation.isIdentifierStart(0x61);
|
||||
implementation.isIdentifierStart(0x7b);
|
||||
implementation.isIdentifierStart(0x5f);
|
||||
implementation.isIdentifierStart(0x24);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierStart on 4 non-ASCII characters", () => {
|
||||
implementation.isIdentifierStart(0x80);
|
||||
implementation.isIdentifierStart(0x4e00);
|
||||
implementation.isIdentifierStart(0xffff);
|
||||
implementation.isIdentifierStart(0x10000);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierStart on TIP character", () => {
|
||||
implementation.isIdentifierStart(0x30000);
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,27 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/helper-validator-identifier";
|
||||
import current from "@babel/helper-validator-identifier";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isKeyword on 4 keywords", () => {
|
||||
implementation.isKeyword("debugger");
|
||||
implementation.isKeyword("throw");
|
||||
implementation.isKeyword("extends");
|
||||
implementation.isKeyword("instanceof");
|
||||
});
|
||||
|
||||
suite.add(name + "#isKeyword on 4 non-keywords", () => {
|
||||
implementation.isKeyword("debuggerr");
|
||||
implementation.isKeyword("threw");
|
||||
implementation.isKeyword("extend");
|
||||
implementation.isKeyword("instanceOf");
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,27 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/helper-validator-identifier";
|
||||
import current from "@babel/helper-validator-identifier";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isStrictBindReservedWord on 4 keywords", () => {
|
||||
implementation.isStrictBindReservedWord("arguments");
|
||||
implementation.isStrictBindReservedWord("eval");
|
||||
implementation.isStrictBindReservedWord("implements");
|
||||
implementation.isStrictBindReservedWord("instanceof");
|
||||
});
|
||||
|
||||
suite.add(name + "#isStrictBindReservedWord on 4 non-keywords", () => {
|
||||
implementation.isStrictBindReservedWord("argumentss");
|
||||
implementation.isStrictBindReservedWord("evals");
|
||||
implementation.isStrictBindReservedWord("implement");
|
||||
implementation.isStrictBindReservedWord("instanceOf");
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run({ async: false });
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "const a = /" + "[/\\\\]".repeat(length / 4) + "/igsudm";
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length}-size RegExp literal `, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "type A = " + "| (x) => void".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} arrow function types`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { plugins: ["flow"] });
|
||||
benchCases("current", current, { plugins: ["flow"] });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "async () => {};".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} async arrow functions`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,34 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13
|
||||
function createInput(length) {
|
||||
if (length > 0x9ffc - 0x4e00) {
|
||||
throw new Error(
|
||||
`Length greater than ${
|
||||
0x9ffc - 0x4e00
|
||||
} is not supported! Consider modify the \`createInput\`.`
|
||||
);
|
||||
}
|
||||
let source = "class C { ";
|
||||
for (let i = 0; i < length; i++) {
|
||||
source += "#" + String.fromCharCode(0x4e00 + i) + ";";
|
||||
}
|
||||
return source + " }";
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-1 private properties`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,20 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = ";".repeat(length);
|
||||
suite.add(`${name} ${length} empty statement`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { attachComment: true });
|
||||
benchCases("current + attachComment: false", current, { attachComment: false });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "a;".repeat(length);
|
||||
}
|
||||
current.parse("a");
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-1 identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "../../lib/index-main.js";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "abcde12345z;".repeat(length);
|
||||
}
|
||||
current.parse("a");
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-11 identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "aa;".repeat(length);
|
||||
}
|
||||
current.parse("a");
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-2 identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "../../lib/index-main.js";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "await;".repeat(length);
|
||||
}
|
||||
current.parse("a");
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} await identifier`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "[,\n// c\n".repeat(length) + "\n]".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested inner comments`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "[" + "// c\n".repeat(length) + "]";
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} inner comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "// c\n{\n".repeat(length) + "}".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} nested leading comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "// c\n".repeat(length) + "{}";
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} leading comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,28 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return "\n// c\na".repeat(length);
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(
|
||||
`${name} ${length} leading comments + ${length - 1} trailing comments`,
|
||||
() => {
|
||||
parse(input, options);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { attachComment: true });
|
||||
benchCases("current + attachComment: false", current, { attachComment: false });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,27 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "\n// c\na".repeat(length);
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(
|
||||
`${name} ${length} leading comments + ${length - 1} trailing comments`,
|
||||
() => {
|
||||
parse(input, options);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{ let foecnatsni };".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} let and length-10 binding identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,34 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13
|
||||
function createInput(length) {
|
||||
if (length > 0x9ffc - 0x4e00) {
|
||||
throw new Error(
|
||||
`Length greater than ${
|
||||
0x9ffc - 0x4e00
|
||||
} is not supported! Consider modify the \`createInput\`.`
|
||||
);
|
||||
}
|
||||
let source = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
source += "let " + String.fromCharCode(0x4e00 + i) + ";";
|
||||
}
|
||||
return source;
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-1 let bindings`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,34 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13
|
||||
function createInput(length) {
|
||||
if (length > 0x9ffc - 0x4e00) {
|
||||
throw new Error(
|
||||
`Length greater than ${
|
||||
0x9ffc - 0x4e00
|
||||
} is not supported! Consider modify the \`createInput\`.`
|
||||
);
|
||||
}
|
||||
let source = "export { ";
|
||||
for (let i = 0; i < length; i++) {
|
||||
source += String.fromCharCode(0x4e00 + i) + ",";
|
||||
}
|
||||
return source + " } from './foo'";
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-1 named export`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { sourceType: "module" });
|
||||
benchCases("current", current, { sourceType: "module" });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{".repeat(length) + "0" + "}".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested template elements`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "<t a={x}>{y}".repeat(length) + "</t>".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(
|
||||
`${name} ${length} nested jsx elements with one attribute and text`,
|
||||
() => {
|
||||
implementation.parse(input, options);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { plugins: ["jsx"] });
|
||||
benchCases("current", current, { plugins: ["jsx"] });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "` ${".repeat(length) + "0" + "}`".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested template elements`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "../../lib/index-v2.js";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "/x/dgimsuy;".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} small regexp literal with all flags`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "`" + " ${0}".repeat(length) + "`";
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} template elements`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
current.parse(createInput(1));
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{".repeat(length) + "} // c\n".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested trailing comments`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{}" + "// c\n".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} trailing comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,37 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/traverse";
|
||||
import current from "@babel/traverse";
|
||||
import parser from "@babel-baseline/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return parser.parse(";".repeat(length));
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} empty statements`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default, {
|
||||
enter() {},
|
||||
});
|
||||
benchCases("baseline mutating context", baseline.default, {
|
||||
enter(path) {
|
||||
path.context = undefined;
|
||||
},
|
||||
});
|
||||
benchCases("current", current.default, {
|
||||
enter() {},
|
||||
});
|
||||
benchCases("current mutating context", current.default, {
|
||||
enter(path) {
|
||||
path.context = undefined;
|
||||
},
|
||||
});
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/types";
|
||||
import current from "@babel/types";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementations) {
|
||||
const funcName = "memberExpression";
|
||||
for (const version in implementations) {
|
||||
const t = implementations[version];
|
||||
const func = t[funcName];
|
||||
const idObj = t.identifier("obj");
|
||||
const idProp = t.identifier("prop");
|
||||
suite.add(`${version} ${funcName} builder`, () => {
|
||||
func(idObj, idProp, /*computed?*/ false /*, optional? missing*/);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases({ baseline, current });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,21 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/types";
|
||||
import current from "@babel/types";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementations) {
|
||||
const funcName = "stringLiteral";
|
||||
for (const version in implementations) {
|
||||
const t = implementations[version];
|
||||
const func = t[funcName];
|
||||
suite.add(`${version} ${funcName} builder`, () => {
|
||||
func("bar");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases({ baseline, current });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "@babel/benchmark",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@babel-baseline/core": "npm:@babel/core@7.15.8",
|
||||
"@babel-baseline/generator": "npm:@babel/generator@7.14.5",
|
||||
"@babel-baseline/helper-validator-identifier": "npm:@babel/helper-validator-identifier@7.10.4",
|
||||
"@babel-baseline/parser": "npm:@babel/parser@7.14.8",
|
||||
"@babel-baseline/traverse": "npm:@babel/traverse@7.15.4",
|
||||
"@babel-baseline/types": "npm:@babel/types@7.15.6",
|
||||
"@babel/core": "workspace:^",
|
||||
"@babel/generator": "workspace:^",
|
||||
"@babel/helper-validator-identifier": "workspace:^",
|
||||
"@babel/parser": "workspace:^",
|
||||
"@babel/preset-env": "workspace:^",
|
||||
"@babel/preset-flow": "workspace:^",
|
||||
"@babel/traverse": "workspace:^",
|
||||
"@babel/types": "workspace:^",
|
||||
"benchmark": "^2.1.4"
|
||||
},
|
||||
"version": "7.16.5"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
export function report(event) {
|
||||
const bench = event.target;
|
||||
const timeMs = bench.stats.mean * 1000;
|
||||
const time =
|
||||
timeMs < 10
|
||||
? `${Math.round(timeMs * 1000) / 1000}ms`
|
||||
: `${Math.round(timeMs)}ms`;
|
||||
const msg = `${bench.name}: ${formatNumber(bench.hz)} ops/sec ±${
|
||||
Math.round(bench.stats.rme * 100) / 100
|
||||
}% (${time})`;
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
function formatNumber(x) {
|
||||
if (x < 100) return `${Math.round(x * 100) / 100}`;
|
||||
return `${Math.round(x)}`.replace(/\d(?=(?:\d{3})+$)/g, "$&_");
|
||||
}
|
||||
@@ -9,4 +9,4 @@ coverage:
|
||||
patch:
|
||||
enabled: false
|
||||
ignore:
|
||||
- packages/babel-types/src/*/generated/*
|
||||
- packages/babel-types/src/*/generated/index.js
|
||||
|
||||
@@ -1,45 +1,25 @@
|
||||
{
|
||||
"name": "@babel/plugin-codemod-object-assign-to-object-spread",
|
||||
"version": "7.10.4",
|
||||
"version": "7.7.4",
|
||||
"description": "Transforms Object.assign into object spread syntax",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "codemods/babel-plugin-codemod-object-assign-to-object-spread"
|
||||
},
|
||||
"repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-object-assign-to-object-spread",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"@babel/codemod",
|
||||
"@babel/plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-object-rest-spread": "^7.8.3"
|
||||
"@babel/plugin-syntax-object-rest-spread": "^7.7.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
"@babel/core": "^7.0.0-0 || csx"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "workspace:^",
|
||||
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"conditions": {
|
||||
"BABEL_8_BREAKING": [
|
||||
null,
|
||||
{
|
||||
"exports": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"exports": {
|
||||
".": "./lib/index.js",
|
||||
"./package.json": "./package.json"
|
||||
"@babel/core": "^7.7.4",
|
||||
"@babel/helper-plugin-test-runner": "^7.7.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
||||
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
inherits: syntaxObjectRestSpread,
|
||||
|
||||
visitor: {
|
||||
CallExpression(path) {
|
||||
if (!path.get("callee").matchesPattern("Object.assign")) return;
|
||||
|
||||
const args = path.get("arguments");
|
||||
if (args.length === 0) return;
|
||||
|
||||
const [objPath] = args;
|
||||
if (!objPath.isObjectExpression()) return;
|
||||
|
||||
const obj = objPath.node;
|
||||
const { properties } = obj;
|
||||
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
const { node } = arg;
|
||||
|
||||
if (arg.isObjectExpression()) {
|
||||
properties.push(...node.properties);
|
||||
} else {
|
||||
properties.push(t.spreadElement(node));
|
||||
}
|
||||
}
|
||||
|
||||
path.replaceWith(obj);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
||||
|
||||
export default function ({ types: t }) {
|
||||
return {
|
||||
inherits: syntaxObjectRestSpread.default,
|
||||
|
||||
visitor: {
|
||||
CallExpression(path) {
|
||||
if (!path.get("callee").matchesPattern("Object.assign")) return;
|
||||
|
||||
const args = path.get("arguments");
|
||||
if (args.length === 0) return;
|
||||
|
||||
const [objPath] = args;
|
||||
if (!objPath.isObjectExpression()) return;
|
||||
|
||||
const obj = objPath.node;
|
||||
const { properties } = obj;
|
||||
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
const { node } = arg;
|
||||
|
||||
if (arg.isObjectExpression()) {
|
||||
properties.push(...node.properties);
|
||||
} else {
|
||||
properties.push(t.spreadElement(node));
|
||||
}
|
||||
}
|
||||
|
||||
path.replaceWith(obj);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"plugins": ["codemod-object-assign-to-object-spread"]
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"plugins": ["codemod-object-assign-to-object-spread"]
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"plugins": ["codemod-object-assign-to-object-spread"]
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"plugins": ["codemod-object-assign-to-object-spread"]
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(import.meta.url);
|
||||
runner(__dirname);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{ "type": "module" }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user