Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Babel 8.0 alpha to build babel #15846

Merged
merged 8 commits into from Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -209,9 +209,12 @@ jobs:
- name: Install
run: |
yarn install
- name: Downgrade Jest for node <= 10
- name: Downgrade Jest and Babel for node <= 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this? Don't we build compile on a modern Node.js version, and then downgrade Node.js to run Jest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest will invoke @babel/core to transpile the test code so that it can run on Node.js 6 - 10, which is not supported by Babel 8. If we pre compile the test code, we don't have to downgrade @babel/core here.

if: matrix.node-version == '6' || matrix.node-version == '8' || matrix.node-version == '10'
run: |
# It's a bit sarcastic that in this scenario bump-babel-dependencies.js
# actually downgrades the root `@babel/*` deps from 8.0 alpha to 7
node ./scripts/integration-tests/utils/bump-babel-dependencies.js
yarn up jest@24
# Deduplicate dependencies, because duplicate copies of graceful-fs cause
# problems with the "path" module: https://github.com/facebook/jest/issues/9656
Expand Down
39 changes: 19 additions & 20 deletions babel.config.js
Expand Up @@ -11,7 +11,6 @@ if (

const pathUtils = require("path");
const fs = require("fs");
const { parseSync } = require("@babel/core");

function normalize(src) {
return src.replace(/\//, pathUtils.sep);
Expand Down Expand Up @@ -40,6 +39,14 @@ module.exports = function (api) {
],
};

const presetTsOpts = {
onlyRemoveTypeImports: true,
optimizeConstEnums: true,
};
if (api.version.startsWith("7") && !bool(process.env.BABEL_8_BREAKING)) {
presetTsOpts.allowDeclareFields = true;
}

// These are "safe" assumptions, that we can enable globally
const assumptions = {
constantSuper: true,
Expand Down Expand Up @@ -178,14 +185,7 @@ module.exports = function (api) {
presets: [
// presets are applied from right to left
["@babel/env", envOpts],
[
"@babel/preset-typescript",
{
onlyRemoveTypeImports: true,
allowDeclareFields: true,
optimizeConstEnums: true,
},
],
["@babel/preset-typescript", presetTsOpts],
],
plugins: [
["@babel/transform-object-rest-spread", { useBuiltIns: true }],
Expand Down Expand Up @@ -829,11 +829,13 @@ function pluginAddImportExtension(api, { when }) {
};
}

const tokenTypesMapping = new Map();
const tokenTypeSourcePath = "./packages/babel-parser/src/tokenizer/types.ts";

function getTokenTypesMapping() {
if (tokenTypesMapping.size === 0) {
function pluginBabelParserTokenType({
parseSync,
types: { isIdentifier, numericLiteral },
}) {
const tokenTypeSourcePath = "./packages/babel-parser/src/tokenizer/types.ts";
function getTokenTypesMapping() {
const tokenTypesMapping = new Map();
const tokenTypesAst = parseSync(
fs.readFileSync(tokenTypeSourcePath, {
encoding: "utf-8",
Expand Down Expand Up @@ -867,13 +869,10 @@ function getTokenTypesMapping() {
for (let i = 0; i < tokenTypesDefinition.length; i++) {
tokenTypesMapping.set(tokenTypesDefinition[i].key.name, i);
}
return tokenTypesMapping;
}
return tokenTypesMapping;
}

function pluginBabelParserTokenType({
types: { isIdentifier, numericLiteral },
}) {
const tokenTypesMapping = getTokenTypesMapping();
return {
visitor: {
MemberExpression(path) {
Expand All @@ -884,7 +883,7 @@ function pluginBabelParserTokenType({
!node.computed
) {
const tokenName = node.property.name;
const tokenType = getTokenTypesMapping().get(node.property.name);
const tokenType = tokenTypesMapping.get(node.property.name);
if (tokenType === undefined) {
throw path.buildCodeFrameError(
`${tokenName} is not defined in ${tokenTypeSourcePath}`
Expand Down
20 changes: 10 additions & 10 deletions package.json
Expand Up @@ -21,20 +21,20 @@
"packageManager": "yarn@3.6.1",
"devDependencies": {
"$repo-utils": "link:./scripts/repo-utils",
"@babel/cli": "^7.22.9",
"@babel/core": "^7.22.9",
"@babel/cli": "8.0.0-alpha.2",
"@babel/core": "8.0.0-alpha.2",
"@babel/eslint-config-internal": "workspace:^",
"@babel/eslint-parser": "workspace:^",
"@babel/eslint-plugin-development": "workspace:^",
"@babel/eslint-plugin-development-internal": "workspace:^",
"@babel/plugin-transform-dynamic-import": "^7.22.5",
"@babel/plugin-transform-export-namespace-from": "^7.22.5",
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@babel/plugin-transform-object-rest-spread": "^7.22.5",
"@babel/plugin-transform-runtime": "^7.22.9",
"@babel/preset-env": "^7.22.9",
"@babel/preset-typescript": "^7.22.5",
"@babel/runtime": "^7.22.6",
"@babel/plugin-transform-dynamic-import": "8.0.0-alpha.2",
"@babel/plugin-transform-export-namespace-from": "8.0.0-alpha.2",
"@babel/plugin-transform-modules-commonjs": "8.0.0-alpha.2",
"@babel/plugin-transform-object-rest-spread": "8.0.0-alpha.2",
"@babel/plugin-transform-runtime": "8.0.0-alpha.2",
"@babel/preset-env": "8.0.0-alpha.2",
"@babel/preset-typescript": "8.0.0-alpha.2",
"@babel/runtime": "8.0.0-alpha.2",
"@eslint/eslintrc": "^2.1.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.1.0",
Expand Down