Skip to content

Commit

Permalink
Use Babel 8.0 alpha to build babel (#15846)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 11, 2023
1 parent 2887d4b commit 8dc81b1
Show file tree
Hide file tree
Showing 4 changed files with 884 additions and 670 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
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
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 8dc81b1

Please sign in to comment.