Skip to content

Commit

Permalink
Update to TypeScript 5.5 (#16536)
Browse files Browse the repository at this point in the history
Co-authored-by: Babel Bot <30521560+liuxingbaoyu@users.noreply.github.com>
  • Loading branch information
nicolo-ribaudo and liuxingbaoyu authored Jun 11, 2024
1 parent 5ed73df commit 424fc90
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 43 deletions.
5 changes: 4 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ function pluginImportMetaUrl({ types: t, template }) {
};
}

/** @returns {import("@babel/core").PluginObj} */
function pluginReplaceTSImportExtension() {
return {
visitor: {
Expand All @@ -945,7 +946,9 @@ function pluginReplaceTSImportExtension() {
}
},
TSImportEqualsDeclaration({ node }) {
const { expression } = node.moduleReference;
const { moduleReference } = node;
if (moduleReference.type !== "TSExternalModuleReference") return;
const { expression } = moduleReference;
expression.value = expression.value.replace(/(\.[mc]?)ts$/, "$1js");
},
},
Expand Down
4 changes: 2 additions & 2 deletions eslint/babel-eslint-parser/src/experimental-worker.cts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import normalizeESLintConfig = require("./configuration.cts");
import analyzeScope = require("./analyze-scope.cts");
import baseParse = require("./parse.cts");

import { WorkerClient } from "./client.cts";
import Clients = require("./client.cts");

const client = new WorkerClient();
const client = new Clients.WorkerClient();

export const meta = {
name: "@babel/eslint-parser/experimental-worker",
Expand Down
22 changes: 10 additions & 12 deletions eslint/babel-eslint-parser/src/worker/handle-message.cts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import babel = require("./babel-core.cts");
import maybeParse = require("./maybeParse.cts");
import { getVisitorKeys, getTokLabels } from "./ast-info.cts";
import {
normalizeBabelParseConfig,
normalizeBabelParseConfigSync,
} from "./configuration.cts";
import astInfo = require("./ast-info.cts");
import config = require("./configuration.cts");

import { ACTIONS } from "../client.cts";
import Clients = require("../client.cts");
import ACTIONS = Clients.ACTIONS;

export = function handleMessage(action: ACTIONS, payload: any) {
switch (action) {
Expand All @@ -18,18 +16,18 @@ export = function handleMessage(action: ACTIONS, payload: any) {
VISITOR_KEYS: babel.types.VISITOR_KEYS,
};
case ACTIONS.GET_TOKEN_LABELS:
return getTokLabels();
return astInfo.getTokLabels();
case ACTIONS.GET_VISITOR_KEYS:
return getVisitorKeys();
return astInfo.getVisitorKeys();
case ACTIONS.MAYBE_PARSE:
return normalizeBabelParseConfig(payload.options).then(options =>
maybeParse(payload.code, options),
);
return config
.normalizeBabelParseConfig(payload.options)
.then(options => maybeParse(payload.code, options));
case ACTIONS.MAYBE_PARSE_SYNC:
if (!USE_ESM) {
return maybeParse(
payload.code,
normalizeBabelParseConfigSync(payload.options),
config.normalizeBabelParseConfigSync(payload.options),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"semver": "^6.3.1",
"shelljs": "^0.8.5",
"test262-stream": "^1.4.0",
"typescript": "^5.4.5",
"typescript": "5.5.1-rc",
"typescript-eslint": "^7.8.0"
},
"workspaces": [
Expand Down
4 changes: 1 addition & 3 deletions packages/babel-cli/src/babel/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ export default function parseArgv(args: Array<string>): CmdOptions | null {
? // glob 9+ no longer sorts the result, here we maintain the glob 7 behaviour
// https://github.com/isaacs/node-glob/blob/c3cd57ae128faa0e9190492acc743bb779ac4054/common.js#L151
glob.sync(input, { dotRelative: true }).sort(alphasort)
: // @ts-expect-error When USE_ESM is true and BABEL_8_BREAKING is off,
// the glob package is an ESM wrapper of the CJS glob 7
(USE_ESM ? glob.default.sync : glob.sync)(input);
: (USE_ESM ? glob.default.sync : glob.sync)(input);
if (!files.length) files = [input];
globbed.push(...files);
return globbed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-extraneous-dependencies */

import fs from "fs";
import { createRequire } from "module";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,7 @@ export default abstract class ExpressionParser extends LValParser {
this.expressionScope.exit();
}

isSimpleParameter(node: N.Pattern | N.TSParameterProperty) {
isSimpleParameter(node: N.Pattern | N.TSParameterProperty): boolean {
return node.type === "Identifier";
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/lval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export default abstract class LValParser extends NodeUtils {
}

// Overridden by the estree plugin
isOptionalMemberExpression(expression: Node) {
isOptionalMemberExpression(expression: Node): boolean {
return expression.type === "OptionalMemberExpression";
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
return elt;
}

isSimpleParameter(node: N.Pattern | N.TSParameterProperty) {
isSimpleParameter(node: N.Pattern | N.TSParameterProperty): boolean {
return (
(node.type === "TSParameterProperty" &&
super.isSimpleParameter(node.parameter)) ||
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-standalone/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{
"extends": [
"../../tsconfig.base.json",
"../../tsconfig.paths.json"
"../../tsconfig.paths.json",
"./tsconfig.overrides.json"
],
"include": [
"../../packages/babel-standalone/src/**/*.ts",
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-standalone/tsconfig.overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "ESNext"
}
}
10 changes: 5 additions & 5 deletions packages/babel-traverse/src/path/inference/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ export function createUnionType(
): t.FlowType | t.TSType | undefined {
if (process.env.BABEL_8_BREAKING) {
if (types.every(v => isFlowType(v))) {
return createFlowUnionType(types as t.FlowType[]);
return createFlowUnionType(types);
}
if (types.every(v => isTSType(v))) {
return createTSUnionType(types as t.TSType[]);
return createTSUnionType(types);
}
} else {
if (types.every(v => isFlowType(v))) {
if (createFlowUnionType) {
return createFlowUnionType(types as t.FlowType[]);
return createFlowUnionType(types);
}

return createUnionTypeAnnotation(types as t.FlowType[]);
return createUnionTypeAnnotation(types);
} else if (types.every(v => isTSType(v))) {
if (createTSUnionType) {
return createTSUnionType(types as t.TSType[]);
return createTSUnionType(types);
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions scripts/generators/tsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ for (let i = 0; i < topoSorted.length; i++) {
});
chunk.forEach(({ name }) => allDeps.delete(name));

const tsConfig = buildTSConfig(chunk, allDeps);
const tsConfig = buildTSConfig(
chunk,
allDeps,
fs.existsSync(new URL(root.relative + "/tsconfig.overrides.json", rootURL))
);

fs.writeFileSync(
new URL(root.relative + "/tsconfig.json", rootURL),
Expand All @@ -206,7 +210,7 @@ for (let i = 0; i < topoSorted.length; i++) {
);
}

function buildTSConfig(pkgs, allDeps) {
function buildTSConfig(pkgs, allDeps, hasOverrides) {
const paths = {};
const referencePaths = new Set();

Expand All @@ -219,7 +223,11 @@ function buildTSConfig(pkgs, allDeps) {
}

return {
extends: ["../../tsconfig.base.json", "../../tsconfig.paths.json"],
extends: [
"../../tsconfig.base.json",
"../../tsconfig.paths.json",
hasOverrides && "./tsconfig.overrides.json",
].filter(Boolean),
include: pkgs
.map(({ name, relative }) => {
return name === "@babel/eslint-parser"
Expand Down Expand Up @@ -293,7 +301,11 @@ fs.writeFileSync(
compilerOptions: {
skipLibCheck: false,
},
include: ["packages/babel-parser/typings/*.d.ts", "dts/**/*.d.ts"],
include: [
"./lib/libdom-minimal.d.ts",
"packages/babel-parser/typings/*.d.ts",
"dts/**/*.d.ts",
],
references: Array.from(new Set(projectsFolders.values()))
.sort()
.map(path => ({ path })),
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"skipLibCheck": false
},
"include": [
"./lib/libdom-minimal.d.ts",
"packages/babel-parser/typings/*.d.ts",
"dts/**/*.d.ts"
],
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7182,7 +7182,7 @@ __metadata:
semver: "npm:^6.3.1"
shelljs: "npm:^0.8.5"
test262-stream: "npm:^1.4.0"
typescript: "npm:^5.4.5"
typescript: "npm:5.5.1-rc"
typescript-eslint: "npm:^7.8.0"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -16863,23 +16863,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.4.5":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
"typescript@npm:5.5.1-rc":
version: 5.5.1-rc
resolution: "typescript@npm:5.5.1-rc"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10/d04a9e27e6d83861f2126665aa8d84847e8ebabcea9125b9ebc30370b98cb38b5dff2508d74e2326a744938191a83a69aa9fddab41f193ffa43eabfdf3f190a5
checksum: 10/c4412a2f9a351c0cd566464da8794c25f86dc1da087bf04776eb3a1ae16e1f9f52ec3f3b9e972bfd6bd7845af94f46de062b848e4e1001b7d58b4e02ccd61136
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.4.5#optional!builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
"typescript@patch:typescript@npm%3A5.5.1-rc#optional!builtin<compat/typescript>":
version: 5.5.1-rc
resolution: "typescript@patch:typescript@npm%3A5.5.1-rc#optional!builtin<compat/typescript>::version=5.5.1-rc&hash=b45daf"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10/760f7d92fb383dbf7dee2443bf902f4365db2117f96f875cf809167f6103d55064de973db9f78fe8f31ec08fff52b2c969aee0d310939c0a3798ec75d0bca2e1
checksum: 10/2f3cdded7c8c273e483f041a6dbd1bebb202403b2623d1e71242f530e6c927f37a1135a7069b3e7e038416b5b9db8bdd8ca8ab0c4493b11da8f32cd3d7c9829a
languageName: node
linkType: hard

Expand Down

0 comments on commit 424fc90

Please sign in to comment.