Work after babel upgrade to v8.0.0-rc1 (#18823)
This commit is contained in:
1 parent
88ee8a5b3e
commit
8d74ddeccd
4 files changed
+25
-33
No files matched your search
@@ -189,21 +189,6 @@ function massageAstNode(original, cloned, parent) {
|
||||
if (original.type === "TemplateLiteral") {
|
||||
removeTemplateElementsValue(cloned);
|
||||
}
|
||||
|
||||
// https://github.com/babel/babel/issues/17719
|
||||
if (
|
||||
(original.type === "ClassDeclaration" ||
|
||||
original.type === "ClassExpression") &&
|
||||
!original.superTypeArguments &&
|
||||
original.superClass?.type === "TSInstantiationExpression" &&
|
||||
original.superClass.typeArguments
|
||||
) {
|
||||
const {
|
||||
superClass: { typeArguments, expression },
|
||||
} = cloned;
|
||||
cloned.superTypeArguments = typeArguments;
|
||||
cloned.superClass = expression;
|
||||
}
|
||||
}
|
||||
|
||||
massageAstNode.ignoredProperties = ignoredProperties;
|
||||
|
||||
@@ -14,7 +14,7 @@ import wrapExpression from "./utilities/wrap-expression.js";
|
||||
|
||||
const createBabelParser = (options) => createParser(createParse(options));
|
||||
|
||||
/** @import {ParserOptions, ParserPlugin} from "@babel/parser" */
|
||||
/** @import {ParserOptions, ParserPlugin, ParseError} from "@babel/parser" */
|
||||
|
||||
/**
|
||||
* @typedef {typeof babelParse | typeof parseExpression} Parse
|
||||
@@ -39,7 +39,7 @@ const parseOptions = {
|
||||
"functionBind",
|
||||
"functionSent",
|
||||
"throwExpressions",
|
||||
"partialApplication",
|
||||
["partialApplication", { version: "2018-07" }],
|
||||
"decorators",
|
||||
"moduleBlocks",
|
||||
"asyncDoExpressions",
|
||||
@@ -59,12 +59,17 @@ const parseOptions = {
|
||||
/** @type {ParserPlugin} */
|
||||
const v8intrinsicPlugin = "v8intrinsic";
|
||||
|
||||
/** @type {Array<ParserPlugin>} */
|
||||
/** @type {ParserPlugin[]} */
|
||||
const pipelineOperatorPlugins = [
|
||||
["pipelineOperator", { proposal: "hack", topicToken: "%" }],
|
||||
["pipelineOperator", { proposal: "fsharp" }],
|
||||
];
|
||||
|
||||
/**
|
||||
@param {ParserPlugin[]} plugins
|
||||
@param {ParserOptions} options
|
||||
@returns {ParserOptions}
|
||||
*/
|
||||
const appendPlugins = (plugins, options = parseOptions) => ({
|
||||
...options,
|
||||
plugins: [...options.plugins, ...plugins],
|
||||
@@ -104,7 +109,13 @@ function parseWithOptions(parse, text, options) {
|
||||
return ast;
|
||||
}
|
||||
|
||||
/**
|
||||
@param {{isExpression: boolean, optionsCombinations: ParserOptions[]}} param0
|
||||
*/
|
||||
function createParse({ isExpression = false, optionsCombinations }) {
|
||||
/**
|
||||
@param {string} text
|
||||
*/
|
||||
return (text, options = {}) => {
|
||||
let { filepath } = options;
|
||||
if (typeof filepath !== "string") {
|
||||
@@ -177,12 +188,8 @@ function createParse({ isExpression = false, optionsCombinations }) {
|
||||
};
|
||||
}
|
||||
|
||||
// Error codes are defined in
|
||||
// - https://github.com/babel/babel/tree/v7.23.6/packages/babel-parser/src/parse-error
|
||||
// - https://github.com/babel/babel/blob/v7.23.6/packages/babel-parser/src/plugins/typescript/index.ts#L73-L223
|
||||
// - https://github.com/babel/babel/blob/v7.23.6/packages/babel-parser/src/plugins/flow/index.ts#L47-L224
|
||||
// - https://github.com/babel/babel/blob/v7.23.6/packages/babel-parser/src/plugins/jsx/index.ts#L23-L44
|
||||
const allowedReasonCodes = new Set([
|
||||
/** @type {ParseError["reasonCode"][]} */
|
||||
const allowedReasonCodesArray = [
|
||||
"StrictNumericEscape",
|
||||
"StrictWith",
|
||||
"StrictOctalLiteral",
|
||||
@@ -192,9 +199,7 @@ const allowedReasonCodes = new Set([
|
||||
"StrictFunction",
|
||||
"ForInOfLoopInitializer",
|
||||
|
||||
"DecoratorExportClass",
|
||||
"ParamDupe",
|
||||
"InvalidDecimal",
|
||||
"RestTrailingComma",
|
||||
"UnsupportedParameterDecorator",
|
||||
"UnterminatedJsxContent",
|
||||
@@ -218,7 +223,8 @@ const allowedReasonCodes = new Set([
|
||||
```
|
||||
*/
|
||||
"DeclarationMissingInitializer",
|
||||
]);
|
||||
];
|
||||
const allowedReasonCodes = new Set(allowedReasonCodesArray);
|
||||
|
||||
const babelParserOptionsCombinations = [appendPlugins(["jsx"])];
|
||||
const babel = /* @__PURE__ */ createBabelParser({
|
||||
|
||||
@@ -13,7 +13,7 @@ import { mergeNestledJsdocComments } from "./merge-nestled-jsdoc-comments.js";
|
||||
import visitNode from "./visit-node.js";
|
||||
|
||||
/**
|
||||
@import {Node, Comment} from "../../types/estree.js"
|
||||
@import {Node, Comment, NodeMap} from "../../types/estree.js"
|
||||
*/
|
||||
|
||||
const isNodeWithRaw = createTypeCheckFunction([
|
||||
@@ -38,11 +38,11 @@ const isNodeWithRaw = createTypeCheckFunction([
|
||||
]);
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* text: string,
|
||||
* astType?: "espree" | "flow" | "hermes" | "meriyah" | "oxc-js" | "oxc-ts" | "typescript",
|
||||
* }} options
|
||||
*/
|
||||
@param {{
|
||||
text: string,
|
||||
astType?: "espree" | "flow" | "hermes" | "meriyah" | "oxc-js" | "oxc-ts" | "typescript",
|
||||
}} options
|
||||
*/
|
||||
function postprocess(ast, options) {
|
||||
const { text, astType } = options;
|
||||
const isOxcTs = astType === "oxc-ts";
|
||||
|
||||
Vendored
+1
@@ -30,6 +30,7 @@ type FlowAdditionalNode = {
|
||||
type PrettierNode = { type: "JsExpressionRoot"; node: Babel.Expression };
|
||||
|
||||
export type Comment = (
|
||||
| Babel.InterpreterDirective
|
||||
| Babel.Comment
|
||||
| TSESTree.Comment
|
||||
| MeriyahESTree.Comment
|
||||
|
||||
Reference in new issue
Block a user