Update flow-parser (#18474)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
1a3ef69056
commit
f16e059640
24 files changed
+227
-135
No files matched your search
+2
-2
@@ -73,11 +73,11 @@
|
||||
"fast-json-stable-stringify": "2.1.0",
|
||||
"file-entry-cache": "11.1.1",
|
||||
"find-cache-directory": "6.0.0",
|
||||
"flow-parser": "0.291.0",
|
||||
"flow-parser": "0.294.0",
|
||||
"get-east-asian-width": "1.4.0",
|
||||
"get-stdin": "9.0.0",
|
||||
"graphql": "16.12.0",
|
||||
"hermes-parser": "0.32.1",
|
||||
"hermes-parser": "0.33.0",
|
||||
"html-element-attributes": "3.5.0",
|
||||
"html-ua-styles": "0.2.0",
|
||||
"ignore": "7.0.5",
|
||||
|
||||
@@ -785,6 +785,7 @@ function handleUnionTypeComments({
|
||||
}
|
||||
|
||||
if (isUnionType(followingNode) && isPrettierIgnoreComment(comment)) {
|
||||
// @ts-expect-error -- Fix me
|
||||
followingNode.types[0].prettierIgnore = true;
|
||||
comment.unignore = true;
|
||||
}
|
||||
|
||||
@@ -165,6 +165,13 @@ function postprocess(ast, options) {
|
||||
node.options = node.attributes;
|
||||
}
|
||||
break;
|
||||
|
||||
// babel-flow
|
||||
case "TupleTypeAnnotation":
|
||||
if (node.types && !node.elementTypes) {
|
||||
node.elementTypes = node.types;
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
onLeave(node) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
isNumericLiteral,
|
||||
isObjectExpression,
|
||||
isSignedNumericLiteral,
|
||||
isTupleType,
|
||||
shouldPrintComma,
|
||||
} from "../utilities/index.js";
|
||||
import { printOptionalToken } from "./miscellaneous.js";
|
||||
@@ -55,13 +56,7 @@ function printArray(path, options, print) {
|
||||
|
||||
const openBracket = "[";
|
||||
const closeBracket = "]";
|
||||
const elementsProperty =
|
||||
// TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation`
|
||||
node.type === "TupleTypeAnnotation" && node.types
|
||||
? "types"
|
||||
: node.type === "TSTupleType" || node.type === "TupleTypeAnnotation"
|
||||
? "elementTypes"
|
||||
: "elements";
|
||||
const elementsProperty = isTupleType(node) ? "elementTypes" : "elements";
|
||||
const elements = node[elementsProperty];
|
||||
if (elements.length === 0) {
|
||||
parts.push(
|
||||
|
||||
@@ -92,10 +92,7 @@ function printClass(path, options, print) {
|
||||
if (node.superClass) {
|
||||
const printed = [
|
||||
printSuperClass(path, options, print),
|
||||
print(
|
||||
// TODO: Remove `superTypeParameters` when https://github.com/facebook/hermes/issues/1808#issuecomment-3413004377 get fixed
|
||||
node.superTypeArguments ? "superTypeArguments" : "superTypeParameters",
|
||||
),
|
||||
print("superTypeArguments"),
|
||||
];
|
||||
const printedWithComments = path.call(
|
||||
() => ["extends ", printComments(path, printed, options)],
|
||||
@@ -184,10 +181,7 @@ function shouldPrintClassInGroupModeWithoutCache(path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const superTypeArguments =
|
||||
node.superTypeArguments ?? node.superTypeParameters;
|
||||
|
||||
return !superTypeArguments && isMemberExpression(node.superClass);
|
||||
return !node.superTypeArguments && isMemberExpression(node.superClass);
|
||||
}
|
||||
|
||||
const heritage =
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
hasComment,
|
||||
hasLeadingOwnLineComment,
|
||||
isConditionalType,
|
||||
isTupleType,
|
||||
isTypeAlias,
|
||||
shouldUnionTypePrintOwnComments,
|
||||
} from "../utilities/index.js";
|
||||
@@ -47,8 +48,7 @@ function printUnionType(path, options, print) {
|
||||
parent.type !== "GenericTypeAnnotation" &&
|
||||
parent.type !== "TSTypeReference" &&
|
||||
parent.type !== "TSTypeAssertion" &&
|
||||
parent.type !== "TupleTypeAnnotation" &&
|
||||
parent.type !== "TSTupleType" &&
|
||||
!isTupleType(parent) &&
|
||||
!(
|
||||
parent.type === "FunctionTypeParam" &&
|
||||
!parent.name &&
|
||||
@@ -108,25 +108,15 @@ function printUnionType(path, options, print) {
|
||||
|
||||
const parts = [leading, group(mainParts)];
|
||||
|
||||
if (parent.type === "TupleTypeAnnotation" || parent.type === "TSTupleType") {
|
||||
const elementTypes =
|
||||
parent[
|
||||
// TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation`
|
||||
parent.type === "TupleTypeAnnotation" && parent.types
|
||||
? "types"
|
||||
: "elementTypes"
|
||||
];
|
||||
|
||||
if (elementTypes.length > 1) {
|
||||
return [
|
||||
group([
|
||||
indent([ifBreak(["(", softline]), parts]),
|
||||
softline,
|
||||
ifBreak(")"),
|
||||
]),
|
||||
trailing,
|
||||
];
|
||||
}
|
||||
if (isTupleType(parent) && parent.elementTypes.length > 1) {
|
||||
return [
|
||||
group([
|
||||
indent([ifBreak(["(", softline]), parts]),
|
||||
softline,
|
||||
ifBreak(")"),
|
||||
]),
|
||||
trailing,
|
||||
];
|
||||
}
|
||||
|
||||
return [group(shouldIndent ? indent(parts) : parts), trailing];
|
||||
|
||||
@@ -3,6 +3,7 @@ import { visitorKeys as tsVisitorKeys } from "@typescript-eslint/visitor-keys";
|
||||
import { visitorKeys as angularVisitorKeys } from "angular-estree-parser";
|
||||
import flowVisitorKeys from "hermes-parser/dist/generated/ESTreeVisitorKeys.js";
|
||||
import {
|
||||
addVisitorKeys,
|
||||
generateReferenceSharedVisitorKeys,
|
||||
removeNodeTypes,
|
||||
removeVisitorKeys,
|
||||
@@ -21,22 +22,12 @@ const additionalVisitorKeys = {
|
||||
TSJSDocNullableType: ["typeAnnotation"],
|
||||
TSJSDocNonNullableType: ["typeAnnotation"],
|
||||
|
||||
// Flow, missed in `flowVisitorKeys`
|
||||
NeverTypeAnnotation: [],
|
||||
// Flow
|
||||
// `SatisfiesExpression` is a private feature https://github.com/facebook/hermes/issues/1808#issuecomment-3392476828
|
||||
SatisfiesExpression: ["expression", "typeAnnotation"],
|
||||
TupleTypeAnnotation: ["elementTypes"],
|
||||
UndefinedTypeAnnotation: [],
|
||||
UnknownTypeAnnotation: [],
|
||||
};
|
||||
|
||||
const excludeVisitorKeys = {
|
||||
// From `flowVisitorKeys`
|
||||
ArrowFunctionExpression: ["id"],
|
||||
|
||||
// TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation`
|
||||
// Flow parser changed `.types` to `.elementTypes` https://github.com/facebook/flow/commit/5b60e6a81dc277dfab2e88fa3737a4dc9aafdcab
|
||||
// TupleTypeAnnotation: ["types"],
|
||||
|
||||
// Not supported yet.
|
||||
// https://github.com/facebook/hermes/commit/55a5f881361ef15fd4f7b558166d80e7b9086550
|
||||
DeclareOpaqueType: ["impltype"],
|
||||
@@ -45,6 +36,9 @@ const excludeVisitorKeys = {
|
||||
ExportAllDeclaration: ["assertions"],
|
||||
ImportDeclaration: ["assertions"],
|
||||
|
||||
// Flow node from Babel
|
||||
TupleTypeAnnotation: ["types"],
|
||||
|
||||
// https://github.com/babel/babel/issues/17506
|
||||
TSImportType: ["argument"],
|
||||
};
|
||||
@@ -61,6 +55,16 @@ const excludeNodeTypes = [
|
||||
// https://github.com/typescript-eslint/typescript-eslint/blob/d2d7ace4e52bedf07482fd879d8e31a52b38fc26/packages/visitor-keys/tests/visitor-keys.test.ts#L14-L18
|
||||
"ExperimentalRestProperty",
|
||||
"ExperimentalSpreadProperty",
|
||||
|
||||
// Unsupported flow features
|
||||
"MatchInstanceObjectPattern",
|
||||
"MatchInstancePattern",
|
||||
"RecordDeclaration",
|
||||
"RecordDeclarationBody",
|
||||
"RecordDeclarationImplements",
|
||||
"RecordDeclarationProperty",
|
||||
"RecordDeclarationStaticProperty",
|
||||
"RecordExpressionProperties",
|
||||
];
|
||||
|
||||
let visitorKeys = unionVisitorKeys(
|
||||
@@ -68,9 +72,9 @@ let visitorKeys = unionVisitorKeys(
|
||||
tsVisitorKeys,
|
||||
flowVisitorKeys,
|
||||
angularVisitorKeys,
|
||||
additionalVisitorKeys,
|
||||
);
|
||||
|
||||
visitorKeys = addVisitorKeys(visitorKeys, additionalVisitorKeys);
|
||||
visitorKeys = removeNodeTypes(visitorKeys, excludeNodeTypes);
|
||||
visitorKeys = removeVisitorKeys(visitorKeys, excludeVisitorKeys);
|
||||
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type * as Babel from "@babel/types";
|
||||
|
||||
export type * from "@babel/types";
|
||||
export type Node = Exclude<Babel.Node, Babel.TupleTypeAnnotation>;
|
||||
Vendored
+9
-12
@@ -1,8 +1,9 @@
|
||||
import type * as Babel from "@babel/types";
|
||||
import type { ESTree as MeriyahESTree } from "meriyah";
|
||||
import type * as Babel from "@babel/types";
|
||||
import type { NGTree } from "angular-estree-parser";
|
||||
import type * as TSESTree from "./typescript-estree.ts";
|
||||
import type * as FlowESTree from "./flow-estree.js";
|
||||
import type * as Babel from "./babel.js";
|
||||
|
||||
type PrettierNodeAdditionalProperties = {
|
||||
extra?: {
|
||||
@@ -19,15 +20,11 @@ type PrettierCommentAdditionalProperties = {
|
||||
leading?: boolean;
|
||||
};
|
||||
|
||||
type FlowAdditionalNode =
|
||||
| {
|
||||
type: "SatisfiesExpression";
|
||||
expression: FlowESTree.Expression;
|
||||
typeAnnotation: FlowESTree.TypeAnnotationType;
|
||||
}
|
||||
| { type: "NeverTypeAnnotation" }
|
||||
| { type: "UndefinedTypeAnnotation" }
|
||||
| { type: "UnknownTypeAnnotation" };
|
||||
type FlowAdditionalNode = {
|
||||
type: "SatisfiesExpression";
|
||||
expression: FlowESTree.Expression;
|
||||
typeAnnotation: FlowESTree.TypeAnnotationType;
|
||||
};
|
||||
|
||||
type PrettierNode = { type: "JsExpressionRoot"; node: Babel.Expression };
|
||||
|
||||
@@ -42,9 +39,9 @@ export type Comment = (
|
||||
|
||||
type _Node =
|
||||
| PrettierNode
|
||||
| Babel.Node
|
||||
| Exclude<Babel.Node, Babel.TupleTypeAnnotation>
|
||||
| TSESTree.Node
|
||||
| NGTree.NGNode
|
||||
| Exclude<NGTree.NGNode, Babel.Node>
|
||||
| FlowESTree.ESNode
|
||||
| FlowAdditionalNode;
|
||||
|
||||
|
||||
+103
-11
@@ -210,8 +210,17 @@ export type ESNode =
|
||||
| MatchPattern
|
||||
| MatchRestPattern
|
||||
| MatchObjectPatternProperty
|
||||
| MatchInstanceObjectPattern
|
||||
| MatchExpressionCase
|
||||
| MatchStatementCase
|
||||
// Records
|
||||
| RecordDeclaration
|
||||
| RecordDeclarationImplements
|
||||
| RecordDeclarationBody
|
||||
| RecordDeclarationProperty
|
||||
| RecordDeclarationStaticProperty
|
||||
| RecordExpression
|
||||
| RecordExpressionProperties
|
||||
// JSX
|
||||
| JSXNode;
|
||||
|
||||
@@ -279,7 +288,8 @@ export type Statement =
|
||||
| VariableDeclaration
|
||||
| WhileStatement
|
||||
| WithStatement
|
||||
| MatchStatement;
|
||||
| MatchStatement
|
||||
| RecordDeclaration;
|
||||
|
||||
// nodes that can be the direct parent of a statement
|
||||
export type StatementParentSingle =
|
||||
@@ -489,6 +499,7 @@ export type Expression =
|
||||
| AsExpression
|
||||
| AsConstExpression
|
||||
| MatchExpression
|
||||
| RecordExpression
|
||||
| JSXFragment
|
||||
| JSXElement;
|
||||
|
||||
@@ -513,18 +524,24 @@ export interface ObjectExpression extends BaseNode {
|
||||
// and object desturcturing properties.
|
||||
export type Property = ObjectProperty | DestructuringObjectProperty;
|
||||
|
||||
export type ObjectPropertyKey =
|
||||
| Identifier
|
||||
| StringLiteral
|
||||
| NumericLiteral
|
||||
| BigIntLiteral;
|
||||
|
||||
export type ObjectProperty =
|
||||
| ObjectPropertyWithNonShorthandStaticName
|
||||
| ObjectPropertyWithShorthandStaticName
|
||||
| ObjectPropertyWithComputedName;
|
||||
interface ObjectPropertyBase extends BaseNode {
|
||||
parent: ObjectExpression | ObjectPattern;
|
||||
parent: ObjectExpression | ObjectPattern | RecordExpressionProperties;
|
||||
}
|
||||
export interface ObjectPropertyWithNonShorthandStaticName extends ObjectPropertyBase {
|
||||
type: "Property";
|
||||
computed: false;
|
||||
// non-computed, non-shorthand names are constrained significantly
|
||||
key: Identifier | StringLiteral | NumericLiteral;
|
||||
key: ObjectPropertyKey;
|
||||
value: Expression;
|
||||
kind: "init" | "get" | "set";
|
||||
method: boolean;
|
||||
@@ -568,7 +585,7 @@ export interface DestructuringObjectPropertyWithNonShorthandStaticName extends D
|
||||
type: "Property";
|
||||
computed: false;
|
||||
// non-computed, non-shorthand names are constrained significantly
|
||||
key: Identifier | StringLiteral | NumericLiteral;
|
||||
key: ObjectPropertyKey;
|
||||
// destructuring properties cannot have any value
|
||||
value: DestructuringPattern;
|
||||
shorthand: false;
|
||||
@@ -912,7 +929,7 @@ interface BaseClass extends BaseNode {
|
||||
body: ClassBody;
|
||||
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
superTypeParameters: null | TypeParameterInstantiation;
|
||||
superTypeArguments: null | TypeParameterInstantiation;
|
||||
implements: ReadonlyArray<ClassImplements>;
|
||||
decorators: ReadonlyArray<Decorator>;
|
||||
}
|
||||
@@ -923,8 +940,7 @@ export type PropertyName =
|
||||
export type ClassPropertyNameComputed = Expression;
|
||||
export type ClassPropertyNameNonComputed =
|
||||
| PrivateIdentifier
|
||||
| Identifier
|
||||
| StringLiteral;
|
||||
| ObjectPropertyKey;
|
||||
|
||||
export type ClassMember = PropertyDefinition | MethodDefinition | StaticBlock;
|
||||
export type ClassMemberWithNonComputedName =
|
||||
@@ -1085,7 +1101,8 @@ export type NamedDeclaration =
|
||||
| TypeAlias
|
||||
| OpaqueType
|
||||
| InterfaceDeclaration
|
||||
| EnumDeclaration;
|
||||
| EnumDeclaration
|
||||
| RecordDeclaration;
|
||||
|
||||
interface ExportNamedDeclarationBase extends BaseNode {
|
||||
type: "ExportNamedDeclaration";
|
||||
@@ -1149,6 +1166,9 @@ export type TypeAnnotationType =
|
||||
| ThisTypeAnnotation
|
||||
| MixedTypeAnnotation
|
||||
| VoidTypeAnnotation
|
||||
| UnknownTypeAnnotation
|
||||
| NeverTypeAnnotation
|
||||
| UndefinedTypeAnnotation
|
||||
| StringLiteralTypeAnnotation
|
||||
| NumberLiteralTypeAnnotation
|
||||
| BigIntLiteralTypeAnnotation
|
||||
@@ -1243,6 +1263,15 @@ export interface MixedTypeAnnotation extends BaseNode {
|
||||
export interface VoidTypeAnnotation extends BaseNode {
|
||||
type: "VoidTypeAnnotation";
|
||||
}
|
||||
export interface UnknownTypeAnnotation extends BaseNode {
|
||||
type: "UnknownTypeAnnotation";
|
||||
}
|
||||
export interface NeverTypeAnnotation extends BaseNode {
|
||||
type: "NeverTypeAnnotation";
|
||||
}
|
||||
export interface UndefinedTypeAnnotation extends BaseNode {
|
||||
type: "UndefinedTypeAnnotation";
|
||||
}
|
||||
export interface StringLiteralTypeAnnotation extends BaseNode {
|
||||
type: "StringLiteralTypeAnnotation";
|
||||
value: string;
|
||||
@@ -1301,7 +1330,7 @@ export interface KeyofTypeAnnotation extends BaseNode {
|
||||
}
|
||||
export interface TupleTypeAnnotation extends BaseNode {
|
||||
type: "TupleTypeAnnotation";
|
||||
types: ReadonlyArray<TypeAnnotationType>;
|
||||
elementTypes: ReadonlyArray<TypeAnnotationType>;
|
||||
inexact: boolean;
|
||||
}
|
||||
export interface TupleTypeSpreadElement extends BaseNode {
|
||||
@@ -1448,7 +1477,7 @@ export interface ObjectTypeAnnotation extends BaseNode {
|
||||
}
|
||||
interface ObjectTypePropertyBase extends BaseNode {
|
||||
type: "ObjectTypeProperty";
|
||||
key: Identifier | StringLiteral;
|
||||
key: ObjectPropertyKey;
|
||||
value: TypeAnnotationType;
|
||||
method: boolean;
|
||||
optional: boolean;
|
||||
@@ -2042,6 +2071,7 @@ export type MatchPattern =
|
||||
| MatchMemberPattern
|
||||
| MatchBindingPattern
|
||||
| MatchObjectPattern
|
||||
| MatchInstancePattern
|
||||
| MatchArrayPattern;
|
||||
|
||||
export interface MatchOrPattern extends BaseNode {
|
||||
@@ -2086,10 +2116,20 @@ export interface MatchObjectPattern extends BaseNode {
|
||||
}
|
||||
export interface MatchObjectPatternProperty extends BaseNode {
|
||||
type: "MatchObjectPatternProperty";
|
||||
key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral;
|
||||
key: ObjectPropertyKey;
|
||||
pattern: MatchPattern;
|
||||
shorthand: boolean;
|
||||
}
|
||||
export interface MatchInstancePattern extends BaseNode {
|
||||
type: "MatchInstancePattern";
|
||||
targetConstructor: MatchIdentifierPattern | MatchMemberPattern;
|
||||
properties: MatchInstanceObjectPattern;
|
||||
}
|
||||
export interface MatchInstanceObjectPattern extends BaseNode {
|
||||
type: "MatchInstanceObjectPattern";
|
||||
properties: ReadonlyArray<MatchObjectPatternProperty>;
|
||||
rest: MatchRestPattern | null;
|
||||
}
|
||||
export interface MatchArrayPattern extends BaseNode {
|
||||
type: "MatchArrayPattern";
|
||||
elements: ReadonlyArray<MatchPattern>;
|
||||
@@ -2100,6 +2140,58 @@ export interface MatchRestPattern extends BaseNode {
|
||||
argument: MatchBindingPattern | null;
|
||||
}
|
||||
|
||||
/***********
|
||||
* Records *
|
||||
***********/
|
||||
export interface RecordDeclaration extends BaseNode {
|
||||
type: "RecordDeclaration";
|
||||
id: Identifier;
|
||||
typeParameters: TypeParameterDeclaration | null;
|
||||
implements: ReadonlyArray<RecordDeclarationImplements>;
|
||||
body: RecordDeclarationBody;
|
||||
}
|
||||
|
||||
export interface RecordDeclarationImplements extends BaseNode {
|
||||
type: "RecordDeclarationImplements";
|
||||
id: Identifier;
|
||||
typeArguments: TypeParameterInstantiation | null;
|
||||
}
|
||||
|
||||
export interface RecordDeclarationBody extends BaseNode {
|
||||
type: "RecordDeclarationBody";
|
||||
elements: ReadonlyArray<
|
||||
| RecordDeclarationProperty
|
||||
| RecordDeclarationStaticProperty
|
||||
| MethodDefinition
|
||||
>;
|
||||
}
|
||||
|
||||
export interface RecordDeclarationProperty extends BaseNode {
|
||||
type: "RecordDeclarationProperty";
|
||||
key: ObjectPropertyKey;
|
||||
typeAnnotation: TypeAnnotation;
|
||||
defaultValue: Expression | null;
|
||||
}
|
||||
|
||||
export interface RecordDeclarationStaticProperty extends BaseNode {
|
||||
type: "RecordDeclarationStaticProperty";
|
||||
key: ObjectPropertyKey;
|
||||
typeAnnotation: TypeAnnotation;
|
||||
value: Expression;
|
||||
}
|
||||
|
||||
export interface RecordExpression extends BaseNode {
|
||||
type: "RecordExpression";
|
||||
recordConstructor: Expression;
|
||||
typeArguments: TypeParameterInstantiation | null;
|
||||
properties: RecordExpressionProperties;
|
||||
}
|
||||
|
||||
export interface RecordExpressionProperties extends BaseNode {
|
||||
type: "RecordExpressionProperties";
|
||||
properties: ReadonlyArray<ObjectProperty | SpreadElement>;
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Deprecated spec nodes awaiting migration by Hermes *
|
||||
******************************************************/
|
||||
|
||||
File renamed without changes.
@@ -27,6 +27,7 @@ import {
|
||||
isObjectExpression,
|
||||
isObjectType,
|
||||
isReturnOrThrowStatement,
|
||||
isTupleType,
|
||||
isTypeAlias,
|
||||
isUnionType,
|
||||
} from "./node-types.js";
|
||||
@@ -1119,6 +1120,7 @@ export {
|
||||
isTemplateOnItsOwnLine,
|
||||
isTestCall,
|
||||
isTsAsConstExpression,
|
||||
isTupleType,
|
||||
isTypeAlias,
|
||||
isTypeAnnotationAFunction,
|
||||
isUnionType,
|
||||
|
||||
@@ -20,6 +20,11 @@ export const isIntersectionType = createTypeCheckFunction([
|
||||
"IntersectionTypeAnnotation",
|
||||
]);
|
||||
|
||||
export const isTupleType = createTypeCheckFunction([
|
||||
"TupleTypeAnnotation",
|
||||
"TSTupleType",
|
||||
]);
|
||||
|
||||
export const isConditionalType = createTypeCheckFunction([
|
||||
"TSConditionalType",
|
||||
"ConditionalTypeAnnotation",
|
||||
|
||||
@@ -12,9 +12,7 @@ function unionVisitorKeys(...all) {
|
||||
/** @type {VisitorKeys} */
|
||||
const result = {};
|
||||
|
||||
for (const [type, keys] of all
|
||||
.flatMap((keys) => Object.entries(keys))
|
||||
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))) {
|
||||
for (const [type, keys] of all.flatMap((keys) => Object.entries(keys))) {
|
||||
result[type] = unique([...(result[type] ?? []), ...keys]);
|
||||
}
|
||||
|
||||
@@ -47,6 +45,34 @@ function removeVisitorKeys(visitorKeys, keysToRemove) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@param {VisitorKeys} visitorKeys
|
||||
@param {VisitorKeys} keysToAdd
|
||||
@returns {VisitorKeys}
|
||||
*/
|
||||
function addVisitorKeys(visitorKeys, keysToAdd) {
|
||||
const result = { ...visitorKeys };
|
||||
|
||||
for (const [type, keys] of Object.entries(keysToAdd)) {
|
||||
if (keys.length === 0 && Object.hasOwn(result, type)) {
|
||||
throw new Error(`Node type "${type}" already exists in visitor keys.`);
|
||||
}
|
||||
|
||||
const existing = [...(result[type] ?? [])];
|
||||
|
||||
for (const key of keys) {
|
||||
if (existing.includes(key)) {
|
||||
throw new Error(`"${key}" already exists in "${type}" visitor keys.`);
|
||||
}
|
||||
existing.push(key);
|
||||
}
|
||||
|
||||
result[type] = existing;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@param {VisitorKeys} visitorKeys
|
||||
@param {string[]} nodeTypesToRemove
|
||||
@@ -88,6 +114,7 @@ function generateReferenceSharedVisitorKeys(visitorKeys) {
|
||||
}
|
||||
|
||||
export {
|
||||
addVisitorKeys,
|
||||
generateReferenceSharedVisitorKeys,
|
||||
removeNodeTypes,
|
||||
removeVisitorKeys,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
exports[`trailing-comma.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow"]
|
||||
parsers: ["flow", "babel-flow"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
runFormatTest(import.meta, ["flow"], { trailingComma: "none" });
|
||||
runFormatTest(import.meta, ["flow"], { trailingComma: "es5" });
|
||||
runFormatTest(import.meta, ["flow"], { trailingComma: "all" });
|
||||
runFormatTest(import.meta, ["flow", "babel-flow"], { trailingComma: "all" });
|
||||
@@ -1,12 +1,5 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`assertions.js [flow] format 1`] = `
|
||||
"Unexpected token \`,\`, expected the token \`)\` (1:20)
|
||||
> 1 | import("./foo.json", { assert: { type: "json" } });
|
||||
| ^
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`assertions.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
runFormatTest(import.meta, ["babel", "flow", "typescript"], {
|
||||
errors: {
|
||||
flow: ["assertions.js", "template-literal.js", "import-phase.js"],
|
||||
flow: ["template-literal.js", "import-phase.js"],
|
||||
hermes: ["template-literal.js", "import-phase.js"],
|
||||
acorn: ["import-phase.js"],
|
||||
espree: ["import-phase.js"],
|
||||
|
||||
@@ -839,15 +839,15 @@ exports[`valid-module-block-top-level-await-using-binding.js [flow] format 1`] =
|
||||
`;
|
||||
|
||||
exports[`valid-module-block-top-level-await-using-binding.js [hermes] format 1`] = `
|
||||
"';' expected (1:17)
|
||||
> 1 | const m = module {
|
||||
| ^
|
||||
2 | await using foo = bar();
|
||||
"':' expected in property initialization (2:8)
|
||||
1 | const m = module {
|
||||
> 2 | await using foo = bar();
|
||||
| ^
|
||||
3 | }
|
||||
4 |
|
||||
Cause: ';' expected (1:17)
|
||||
const m = module {
|
||||
^"
|
||||
Cause: ':' expected in property initialization (2:8)
|
||||
await using foo = bar();
|
||||
~~~~~~^"
|
||||
`;
|
||||
|
||||
exports[`valid-module-block-top-level-await-using-binding.js [meriyah] format 1`] = `
|
||||
@@ -936,15 +936,15 @@ exports[`valid-module-block-top-level-using-binding.js [flow] format 1`] = `
|
||||
`;
|
||||
|
||||
exports[`valid-module-block-top-level-using-binding.js [hermes] format 1`] = `
|
||||
"';' expected (1:7)
|
||||
> 1 | module {
|
||||
| ^
|
||||
2 | using foo = bar();
|
||||
"':' expected in property initialization (2:8)
|
||||
1 | module {
|
||||
> 2 | using foo = bar();
|
||||
| ^
|
||||
3 | }
|
||||
4 |
|
||||
Cause: ';' expected (1:7)
|
||||
module {
|
||||
^"
|
||||
Cause: ':' expected in property initialization (2:8)
|
||||
using foo = bar();
|
||||
~~~~~~^"
|
||||
`;
|
||||
|
||||
exports[`valid-module-block-top-level-using-binding.js [meriyah] format 1`] = `
|
||||
|
||||
@@ -8,13 +8,6 @@ exports[`async-arrow-invalid.js [flow] format 1`] = `
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`dynamic-import.js [flow] format 1`] = `
|
||||
"Unexpected token \`,\`, expected the token \`)\` (1:24)
|
||||
> 1 | import('./prettier.mjs', {})
|
||||
| ^
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`function-async.js [flow] format 1`] = `
|
||||
"Unexpected token \`;\`, expected the token \`=>\` (2:11)
|
||||
1 | // Flow can't parse this since \`v0.128.0\`, #8661
|
||||
@@ -29,13 +22,6 @@ exports[`invalid_keyword_symbol.js [flow] format 1`] = `
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`module-attributes-dynamic.js [flow] format 1`] = `
|
||||
"Unexpected token \`,\`, expected the token \`)\` (1:18)
|
||||
> 1 | import("foo.json", { with: { type: "json" } })
|
||||
| ^
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`module-attributes-static.js [flow] format 1`] = `
|
||||
"Unexpected token \`with\`, expected the token \`;\` (1:28)
|
||||
> 1 | import foo from "foo.json" with type: "json";
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import('./prettier.mjs', {})
|
||||
@@ -1 +0,0 @@
|
||||
import("foo.json", { with: { type: "json" } })
|
||||
@@ -98,7 +98,6 @@ exports[`visitor keys estree 1`] = `
|
||||
"mixins",
|
||||
"superClass",
|
||||
"superTypeArguments",
|
||||
"superTypeParameters",
|
||||
"typeParameters",
|
||||
],
|
||||
"ClassExpression": [
|
||||
@@ -109,7 +108,6 @@ exports[`visitor keys estree 1`] = `
|
||||
"mixins",
|
||||
"superClass",
|
||||
"superTypeArguments",
|
||||
"superTypeParameters",
|
||||
"typeParameters",
|
||||
],
|
||||
"ClassImplements": [
|
||||
@@ -1077,7 +1075,6 @@ exports[`visitor keys estree 1`] = `
|
||||
],
|
||||
"TupleTypeAnnotation": [
|
||||
"elementTypes",
|
||||
"types",
|
||||
],
|
||||
"TupleTypeLabeledElement": [
|
||||
"elementType",
|
||||
|
||||
@@ -4681,10 +4681,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"flow-parser@npm:0.291.0":
|
||||
version: 0.291.0
|
||||
resolution: "flow-parser@npm:0.291.0"
|
||||
checksum: 10/1961b1208385263efd7b1d03db2de0f1a93dc31453bacd5a482086add64189049e820af129982b0d848084e853310945c2d70b7ba83ebb811051325f85c19ce0
|
||||
"flow-parser@npm:0.294.0":
|
||||
version: 0.294.0
|
||||
resolution: "flow-parser@npm:0.294.0"
|
||||
checksum: 10/ad4e01355fa5719c98a158f3aa9c9acf181f8e973d81fa38e28bf7977d9c9b3be14f14bc36d1e54896d3532b3a91d1d65aba8f8fe8dc079073697726083464ee
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5003,19 +5003,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"hermes-estree@npm:0.32.1":
|
||||
version: 0.32.1
|
||||
resolution: "hermes-estree@npm:0.32.1"
|
||||
checksum: 10/6d0c03216c69fcabe6a534ffcffd4bc21b54de1e7ae3c81f1cafce36c33c4acafe334ee27e865f65549b78971dbdb3d78be9b40281365a162c6a23a6b8f1e06b
|
||||
"hermes-estree@npm:0.33.0":
|
||||
version: 0.33.0
|
||||
resolution: "hermes-estree@npm:0.33.0"
|
||||
checksum: 10/dff69960345cc3cf034a5f1cb92c0c87a8d5cd9e136d0840e92cfff9fe7453088b792661cbcdf0b4a087de9b1e5d208db740b5505b1d4bef9f1e2133cdf3b4cf
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"hermes-parser@npm:0.32.1":
|
||||
version: 0.32.1
|
||||
resolution: "hermes-parser@npm:0.32.1"
|
||||
"hermes-parser@npm:0.33.0":
|
||||
version: 0.33.0
|
||||
resolution: "hermes-parser@npm:0.33.0"
|
||||
dependencies:
|
||||
hermes-estree: "npm:0.32.1"
|
||||
checksum: 10/f392d309e3e9d01a01fd71bda83a488906b1182ebf4073768a6528b28c7a1b54f099a4170593dcfad886c434927dbedf93eff985ec6cf78af4c6eded10e26f03
|
||||
hermes-estree: "npm:0.33.0"
|
||||
checksum: 10/69da5c96459e9be53616045756be7a2b97ed40bdab66a0181fe783a68cba2fb21c2bd8e2177e8cb5369e7a120656d32d8d892b35438818b93e46dfcbfd99edee
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -7339,13 +7339,13 @@ __metadata:
|
||||
fast-json-stable-stringify: "npm:2.1.0"
|
||||
file-entry-cache: "npm:11.1.1"
|
||||
find-cache-directory: "npm:6.0.0"
|
||||
flow-parser: "npm:0.291.0"
|
||||
flow-parser: "npm:0.294.0"
|
||||
get-east-asian-width: "npm:1.4.0"
|
||||
get-stdin: "npm:9.0.0"
|
||||
gfm-test-suite: "npm:0.0.2"
|
||||
globals: "npm:16.5.0"
|
||||
graphql: "npm:16.12.0"
|
||||
hermes-parser: "npm:0.32.1"
|
||||
hermes-parser: "npm:0.33.0"
|
||||
html-element-attributes: "npm:3.5.0"
|
||||
html-ua-styles: "npm:0.2.0"
|
||||
ignore: "npm:7.0.5"
|
||||
|
||||
Reference in new issue
Block a user