Fix flow estree type definition (#18437)
This commit is contained in:
1 parent
94a8634300
commit
576f952997
4 files changed
+176
-91
No files matched your search
@@ -1,4 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import url from "node:url";
|
||||
import { codeFrameColumns } from "@babel/code-frame";
|
||||
import * as ts from "typescript";
|
||||
import * as prettier from "../index.js";
|
||||
|
||||
const PROJECT_ROOT = new URL("../", import.meta.url);
|
||||
@@ -12,11 +15,7 @@ const FLOW_TYPES_DTS = new URL(
|
||||
);
|
||||
|
||||
let text = await fs.readFile(FLOW_TYPES, "utf8");
|
||||
|
||||
text = text.replaceAll("'use strict';", " ");
|
||||
text = text.replaceAll(/(?<=\n) {2,}\+/gu, " ");
|
||||
text = text.replaceAll("interface {", "{");
|
||||
text = text.replaceAll(/: interface extends (\w+)/gu, ": $1 & ");
|
||||
text = toDts(text);
|
||||
|
||||
const getRelativePath = (url) =>
|
||||
new URL(url).href.slice(PROJECT_ROOT.href.length);
|
||||
@@ -36,3 +35,65 @@ text = await prettier.format(text, {
|
||||
});
|
||||
|
||||
await fs.writeFile(FLOW_TYPES_DTS, text);
|
||||
|
||||
const program = ts.createProgram([url.fileURLToPath(FLOW_TYPES_DTS)], {
|
||||
strict: true,
|
||||
});
|
||||
const diagnostics = ts.getPreEmitDiagnostics(program);
|
||||
|
||||
if (diagnostics.length > 0) {
|
||||
await fs.rm(FLOW_TYPES_DTS);
|
||||
const [diagnostic] = diagnostics;
|
||||
const { line, character: column } = ts.getLineAndCharacterOfPosition(
|
||||
diagnostic.file,
|
||||
diagnostic.start,
|
||||
);
|
||||
throw new Error(
|
||||
diagnostic.messageText +
|
||||
":\n" +
|
||||
codeFrameColumns(
|
||||
text,
|
||||
{ start: { line: line + 1, column } },
|
||||
{
|
||||
message: `TS${diagnostic.code}: ${diagnostic.messageText}`,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function toDts(text) {
|
||||
// Useless directive
|
||||
text = text.replaceAll("'use strict';", " ");
|
||||
|
||||
// `{+foo: string}` -> `{foo: string}`
|
||||
text = text.replaceAll(/(?<=\n)(?<indention>[ {2}]+)\+/gu, "$<indention>");
|
||||
|
||||
// `{foo: interface {}}` -> `{foo: {}}`
|
||||
text = text.replaceAll(": interface {", ": {");
|
||||
|
||||
// `{foo: interface extends T {}}` -> `{foo: T & {}}`
|
||||
text = text.replaceAll(
|
||||
/(?<=: )interface extends (?<type>\w+)(?= \{)/gu,
|
||||
"$<type> & ",
|
||||
);
|
||||
|
||||
// `$ReadOnlyArray<?T>` -> `ReadonlyArray<T | null>`
|
||||
text = text.replaceAll(
|
||||
/\$ReadOnlyArray<\?(\w+)>/gu,
|
||||
"ReadonlyArray<$1 | null>",
|
||||
);
|
||||
|
||||
// `$ReadOnlyArray<T>` -> `ReadonlyArray<T>`
|
||||
text = text.replaceAll("$ReadOnlyArray<", "ReadonlyArray<");
|
||||
|
||||
// `$ReadOnly<T>` -> `Readonly<T>`
|
||||
text = text.replaceAll("$ReadOnly<", "Readonly<");
|
||||
|
||||
// `{[string]: T}` -> `{[key: string]: T}`
|
||||
text = text.replaceAll(
|
||||
/(?<=\n)(?<indention>[ {2}]+)\[(?<type>string)\](?=: )/gu,
|
||||
"$<indention>[key: $<type>]",
|
||||
);
|
||||
|
||||
return text;
|
||||
}
|
||||
Vendored
+35
-20
@@ -4,6 +4,21 @@ import type { NGTree } from "angular-estree-parser";
|
||||
import type * as TSESTree from "./typescript-estree.ts";
|
||||
import type * as FlowESTree from "./flow-estree.js";
|
||||
|
||||
type PrettierNodeAdditionalProperties = {
|
||||
extra?: {
|
||||
parenthesized?: boolean;
|
||||
raw?: string;
|
||||
};
|
||||
comments?: Comment[];
|
||||
prettierIgnore?: boolean;
|
||||
};
|
||||
|
||||
type PrettierCommentAdditionalProperties = {
|
||||
printed?: boolean;
|
||||
trailing?: boolean;
|
||||
leading?: boolean;
|
||||
};
|
||||
|
||||
type FlowAdditionalNode =
|
||||
| {
|
||||
type: "SatisfiesExpression";
|
||||
@@ -16,32 +31,24 @@ type FlowAdditionalNode =
|
||||
|
||||
type PrettierNode = { type: "JsExpressionRoot"; node: Babel.Expression };
|
||||
|
||||
export type Node = (
|
||||
| PrettierNode
|
||||
| Babel.Node
|
||||
| TSESTree.Node
|
||||
| NGTree.NGNode
|
||||
| FlowESTree.ESNode
|
||||
| FlowAdditionalNode
|
||||
) & {
|
||||
extra?: {
|
||||
parenthesized?: boolean;
|
||||
raw?: string;
|
||||
};
|
||||
comments?: Comment[];
|
||||
};
|
||||
|
||||
export type Comment = (
|
||||
| Babel.Comment
|
||||
| TSESTree.Comment
|
||||
| MeriyahESTree.Comment
|
||||
| { type: "Hashbang"; value: string }
|
||||
| Babel.InterpreterDirective
|
||||
) & {
|
||||
printed?: boolean;
|
||||
trailing?: boolean;
|
||||
leading?: boolean;
|
||||
};
|
||||
) &
|
||||
PrettierCommentAdditionalProperties;
|
||||
|
||||
type _Node =
|
||||
| PrettierNode
|
||||
| Babel.Node
|
||||
| TSESTree.Node
|
||||
| NGTree.NGNode
|
||||
| FlowESTree.ESNode
|
||||
| FlowAdditionalNode;
|
||||
|
||||
export type Node = ExtendNode<_Node>;
|
||||
|
||||
export type NodeMap = CreateNodeMap<Node>;
|
||||
export type CommentMap = CreateNodeMap<Comment>;
|
||||
@@ -49,3 +56,11 @@ export type CommentMap = CreateNodeMap<Comment>;
|
||||
type CreateNodeMap<InputNode extends Node | Comment> = {
|
||||
[NodeType in InputNode["type"]]: Extract<InputNode, { type: NodeType }>;
|
||||
};
|
||||
|
||||
type ExtendNode<InputNode> = InputNode extends _Node
|
||||
? {
|
||||
[Key in keyof InputNode]: ExtendNode<InputNode[Key]>;
|
||||
} & PrettierNodeAdditionalProperties
|
||||
: InputNode extends readonly (_Node | any)[]
|
||||
? ExtendNode<InputNode[number]>[]
|
||||
: InputNode;
|
||||
+64
-64
@@ -117,16 +117,16 @@ export interface InterpreterDirective extends BaseNode {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export type DocblockDirectives = $ReadOnly<{
|
||||
export type DocblockDirectives = Readonly<{
|
||||
// some well-known tags
|
||||
flow?: $ReadOnlyArray<string> | void;
|
||||
format?: $ReadOnlyArray<string> | void;
|
||||
noflow?: $ReadOnlyArray<string> | void;
|
||||
noformat?: $ReadOnlyArray<string> | void;
|
||||
[string]: $ReadOnlyArray<string> | void;
|
||||
flow?: ReadonlyArray<string> | void;
|
||||
format?: ReadonlyArray<string> | void;
|
||||
noflow?: ReadonlyArray<string> | void;
|
||||
noformat?: ReadonlyArray<string> | void;
|
||||
[key: string]: ReadonlyArray<string> | void;
|
||||
}>;
|
||||
|
||||
export type DocblockMetadata = $ReadOnly<{
|
||||
export type DocblockMetadata = Readonly<{
|
||||
directives: DocblockDirectives;
|
||||
comment: BlockComment;
|
||||
}>;
|
||||
@@ -134,9 +134,9 @@ export type DocblockMetadata = $ReadOnly<{
|
||||
export interface Program extends BaseNode {
|
||||
type: "Program";
|
||||
sourceType: "script" | "module";
|
||||
body: $ReadOnlyArray<Statement | ModuleDeclaration>;
|
||||
tokens: $ReadOnlyArray<Token>;
|
||||
comments: $ReadOnlyArray<Comment>;
|
||||
body: ReadonlyArray<Statement | ModuleDeclaration>;
|
||||
tokens: ReadonlyArray<Token>;
|
||||
comments: ReadonlyArray<Comment>;
|
||||
loc: SourceLocation;
|
||||
interpreter: null | InterpreterDirective;
|
||||
docblock: null | DocblockMetadata;
|
||||
@@ -226,7 +226,7 @@ export type DestructuringPattern =
|
||||
| RestElement;
|
||||
|
||||
interface BaseFunction extends BaseNode {
|
||||
params: $ReadOnlyArray<FunctionParameter>;
|
||||
params: ReadonlyArray<FunctionParameter>;
|
||||
async: boolean;
|
||||
|
||||
predicate: null | InferredPredicate;
|
||||
@@ -305,12 +305,12 @@ export interface EmptyStatement extends BaseNode {
|
||||
|
||||
export interface BlockStatement extends BaseNode {
|
||||
type: "BlockStatement";
|
||||
body: $ReadOnlyArray<Statement>;
|
||||
body: ReadonlyArray<Statement>;
|
||||
}
|
||||
|
||||
export interface StaticBlock extends BaseNode {
|
||||
type: "StaticBlock";
|
||||
body: $ReadOnlyArray<Statement>;
|
||||
body: ReadonlyArray<Statement>;
|
||||
}
|
||||
|
||||
export interface ExpressionStatement extends BaseNode {
|
||||
@@ -351,7 +351,7 @@ export interface WithStatement extends BaseNode {
|
||||
export interface SwitchStatement extends BaseNode {
|
||||
type: "SwitchStatement";
|
||||
discriminant: Expression;
|
||||
cases: $ReadOnlyArray<SwitchCase>;
|
||||
cases: ReadonlyArray<SwitchCase>;
|
||||
}
|
||||
|
||||
export interface ReturnStatement extends BaseNode {
|
||||
@@ -423,7 +423,7 @@ export interface ComponentDeclaration extends BaseNode {
|
||||
type: "ComponentDeclaration";
|
||||
body: BlockStatement;
|
||||
id: Identifier;
|
||||
params: $ReadOnlyArray<ComponentParameterAndRestElement>;
|
||||
params: ReadonlyArray<ComponentParameterAndRestElement>;
|
||||
rendersType: null | RendersType;
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
}
|
||||
@@ -432,7 +432,7 @@ export interface HookDeclaration extends BaseNode {
|
||||
type: "HookDeclaration";
|
||||
id: Identifier;
|
||||
body: BlockStatement;
|
||||
params: $ReadOnlyArray<FunctionParameter>;
|
||||
params: ReadonlyArray<FunctionParameter>;
|
||||
returnType: null | TypeAnnotation;
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
}
|
||||
@@ -447,7 +447,7 @@ export interface FunctionDeclaration extends BaseFunction {
|
||||
|
||||
export interface VariableDeclaration extends BaseNode {
|
||||
type: "VariableDeclaration";
|
||||
declarations: $ReadOnlyArray<VariableDeclarator>;
|
||||
declarations: ReadonlyArray<VariableDeclarator>;
|
||||
kind: "var" | "let" | "const";
|
||||
}
|
||||
|
||||
@@ -498,14 +498,14 @@ export interface ThisExpression extends BaseNode {
|
||||
|
||||
export interface ArrayExpression extends BaseNode {
|
||||
type: "ArrayExpression";
|
||||
elements: $ReadOnlyArray<Expression | SpreadElement>;
|
||||
elements: ReadonlyArray<Expression | SpreadElement>;
|
||||
// this is not part of the ESTree spec, but hermes emits it
|
||||
trailingComma: boolean;
|
||||
}
|
||||
|
||||
export interface ObjectExpression extends BaseNode {
|
||||
type: "ObjectExpression";
|
||||
properties: $ReadOnlyArray<ObjectProperty | SpreadElement>;
|
||||
properties: ReadonlyArray<ObjectProperty | SpreadElement>;
|
||||
}
|
||||
|
||||
// This is the complete type of a "Property"
|
||||
@@ -602,7 +602,7 @@ export interface FunctionExpression extends BaseFunction {
|
||||
|
||||
export interface SequenceExpression extends BaseNode {
|
||||
type: "SequenceExpression";
|
||||
expressions: $ReadOnlyArray<Expression>;
|
||||
expressions: ReadonlyArray<Expression>;
|
||||
}
|
||||
|
||||
export interface UnaryExpression extends BaseNode {
|
||||
@@ -660,7 +660,7 @@ export interface ConditionalExpression extends BaseNode {
|
||||
|
||||
interface BaseCallExpression extends BaseNode {
|
||||
callee: Expression | Super;
|
||||
arguments: $ReadOnlyArray<Expression | SpreadElement>;
|
||||
arguments: ReadonlyArray<Expression | SpreadElement>;
|
||||
typeArguments: null | TypeParameterInstantiation;
|
||||
}
|
||||
export interface CallExpression extends BaseCallExpression {
|
||||
@@ -700,7 +700,7 @@ export interface ChainExpression extends BaseNode {
|
||||
export interface SwitchCase extends BaseNode {
|
||||
type: "SwitchCase";
|
||||
test?: Expression | null;
|
||||
consequent: $ReadOnlyArray<Statement>;
|
||||
consequent: ReadonlyArray<Statement>;
|
||||
}
|
||||
|
||||
export interface CatchClause extends BaseNode {
|
||||
@@ -861,8 +861,8 @@ export interface YieldExpression extends BaseNode {
|
||||
|
||||
export interface TemplateLiteral extends BaseNode {
|
||||
type: "TemplateLiteral";
|
||||
quasis: $ReadOnlyArray<TemplateElement>;
|
||||
expressions: $ReadOnlyArray<Expression>;
|
||||
quasis: ReadonlyArray<TemplateElement>;
|
||||
expressions: ReadonlyArray<Expression>;
|
||||
}
|
||||
|
||||
export interface TaggedTemplateExpression extends BaseNode {
|
||||
@@ -882,7 +882,7 @@ export interface TemplateElement extends BaseNode {
|
||||
|
||||
export interface ObjectPattern extends BaseNode {
|
||||
type: "ObjectPattern";
|
||||
properties: $ReadOnlyArray<DestructuringObjectProperty | RestElement>;
|
||||
properties: ReadonlyArray<DestructuringObjectProperty | RestElement>;
|
||||
// if used as a VariableDeclarator.id
|
||||
typeAnnotation: TypeAnnotation | null;
|
||||
}
|
||||
@@ -890,7 +890,7 @@ export interface ObjectPattern extends BaseNode {
|
||||
export interface ArrayPattern extends BaseNode {
|
||||
type: "ArrayPattern";
|
||||
// an element will be null if the pattern contains a hole: `[a,,b]`
|
||||
elements: $ReadOnlyArray<?DestructuringPattern>;
|
||||
elements: ReadonlyArray<DestructuringPattern | null>;
|
||||
typeAnnotation: TypeAnnotation | null;
|
||||
}
|
||||
|
||||
@@ -913,8 +913,8 @@ interface BaseClass extends BaseNode {
|
||||
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
superTypeParameters: null | TypeParameterInstantiation;
|
||||
implements: $ReadOnlyArray<ClassImplements>;
|
||||
decorators: $ReadOnlyArray<Decorator>;
|
||||
implements: ReadonlyArray<ClassImplements>;
|
||||
decorators: ReadonlyArray<Decorator>;
|
||||
}
|
||||
|
||||
export type PropertyName =
|
||||
@@ -933,7 +933,7 @@ export type ClassMemberWithNonComputedName =
|
||||
| MethodDefinitionWithNonComputedName;
|
||||
export interface ClassBody extends BaseNode {
|
||||
type: "ClassBody";
|
||||
body: $ReadOnlyArray<ClassMember>;
|
||||
body: ReadonlyArray<ClassMember>;
|
||||
|
||||
parent: AClass;
|
||||
}
|
||||
@@ -1029,11 +1029,11 @@ export type ModuleSpecifier =
|
||||
|
||||
export interface ImportDeclaration extends BaseNode {
|
||||
type: "ImportDeclaration";
|
||||
specifiers: $ReadOnlyArray<
|
||||
specifiers: ReadonlyArray<
|
||||
ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier
|
||||
>;
|
||||
source: StringLiteral;
|
||||
assertions: $ReadOnlyArray<ImportAttribute>;
|
||||
assertions: ReadonlyArray<ImportAttribute>;
|
||||
|
||||
importKind: "value" | "type" | "typeof";
|
||||
}
|
||||
@@ -1090,7 +1090,7 @@ export type NamedDeclaration =
|
||||
interface ExportNamedDeclarationBase extends BaseNode {
|
||||
type: "ExportNamedDeclaration";
|
||||
declaration?: NamedDeclaration | null;
|
||||
specifiers: $ReadOnlyArray<ExportSpecifier>;
|
||||
specifiers: ReadonlyArray<ExportSpecifier>;
|
||||
source?: StringLiteral | null;
|
||||
exportKind: "value" | "type";
|
||||
}
|
||||
@@ -1098,7 +1098,7 @@ export interface ExportNamedDeclarationWithSpecifiers extends ExportNamedDeclara
|
||||
type: "ExportNamedDeclaration";
|
||||
declaration: null;
|
||||
source?: StringLiteral | null;
|
||||
specifiers: $ReadOnlyArray<ExportSpecifier>;
|
||||
specifiers: ReadonlyArray<ExportSpecifier>;
|
||||
}
|
||||
export interface ExportNamedDeclarationWithDeclaration extends ExportNamedDeclarationBase {
|
||||
type: "ExportNamedDeclaration";
|
||||
@@ -1301,7 +1301,7 @@ export interface KeyofTypeAnnotation extends BaseNode {
|
||||
}
|
||||
export interface TupleTypeAnnotation extends BaseNode {
|
||||
type: "TupleTypeAnnotation";
|
||||
types: $ReadOnlyArray<TypeAnnotationType>;
|
||||
types: ReadonlyArray<TypeAnnotationType>;
|
||||
inexact: boolean;
|
||||
}
|
||||
export interface TupleTypeSpreadElement extends BaseNode {
|
||||
@@ -1340,11 +1340,11 @@ export interface InterfaceTypeAnnotation extends BaseInterfaceNode {
|
||||
|
||||
export interface UnionTypeAnnotation extends BaseNode {
|
||||
type: "UnionTypeAnnotation";
|
||||
types: $ReadOnlyArray<TypeAnnotationType>;
|
||||
types: ReadonlyArray<TypeAnnotationType>;
|
||||
}
|
||||
export interface IntersectionTypeAnnotation extends BaseNode {
|
||||
type: "IntersectionTypeAnnotation";
|
||||
types: $ReadOnlyArray<TypeAnnotationType>;
|
||||
types: ReadonlyArray<TypeAnnotationType>;
|
||||
}
|
||||
|
||||
export interface ConditionalTypeAnnotation extends BaseNode {
|
||||
@@ -1391,7 +1391,7 @@ export interface TypePredicate extends BaseNode {
|
||||
|
||||
export interface FunctionTypeAnnotation extends BaseNode {
|
||||
type: "FunctionTypeAnnotation";
|
||||
params: $ReadOnlyArray<FunctionTypeParam>;
|
||||
params: ReadonlyArray<FunctionTypeParam>;
|
||||
returnType: TypeAnnotationType;
|
||||
rest: null | FunctionTypeParam;
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
@@ -1407,7 +1407,7 @@ export interface FunctionTypeParam extends BaseNode {
|
||||
}
|
||||
export interface HookTypeAnnotation extends BaseNode {
|
||||
type: "HookTypeAnnotation";
|
||||
params: $ReadOnlyArray<FunctionTypeParam>;
|
||||
params: ReadonlyArray<FunctionTypeParam>;
|
||||
returnType: TypeAnnotationType;
|
||||
rest: null | FunctionTypeParam;
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
@@ -1415,7 +1415,7 @@ export interface HookTypeAnnotation extends BaseNode {
|
||||
|
||||
export interface ComponentTypeAnnotation extends BaseNode {
|
||||
type: "ComponentTypeAnnotation";
|
||||
params: $ReadOnlyArray<ComponentTypeParameter>;
|
||||
params: ReadonlyArray<ComponentTypeParameter>;
|
||||
rest: null | ComponentTypeParameter;
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
rendersType: null | RendersType;
|
||||
@@ -1439,12 +1439,12 @@ export interface ObjectTypeAnnotation extends BaseNode {
|
||||
type: "ObjectTypeAnnotation";
|
||||
inexact: boolean;
|
||||
exact: boolean;
|
||||
properties: $ReadOnlyArray<
|
||||
properties: ReadonlyArray<
|
||||
ObjectTypeProperty | ObjectTypeSpreadProperty | ObjectTypeMappedTypeProperty
|
||||
>;
|
||||
indexers: $ReadOnlyArray<ObjectTypeIndexer>;
|
||||
callProperties: $ReadOnlyArray<ObjectTypeCallProperty>;
|
||||
internalSlots: $ReadOnlyArray<ObjectTypeInternalSlot>;
|
||||
indexers: ReadonlyArray<ObjectTypeIndexer>;
|
||||
callProperties: ReadonlyArray<ObjectTypeCallProperty>;
|
||||
internalSlots: ReadonlyArray<ObjectTypeInternalSlot>;
|
||||
}
|
||||
interface ObjectTypePropertyBase extends BaseNode {
|
||||
type: "ObjectTypeProperty";
|
||||
@@ -1558,7 +1558,7 @@ export interface AsConstExpression extends BaseNode {
|
||||
|
||||
interface BaseInterfaceNode extends BaseNode {
|
||||
body: ObjectTypeAnnotation;
|
||||
extends: $ReadOnlyArray<InterfaceExtends>;
|
||||
extends: ReadonlyArray<InterfaceExtends>;
|
||||
}
|
||||
interface BaseInterfaceDeclaration extends BaseInterfaceNode {
|
||||
id: Identifier;
|
||||
@@ -1594,7 +1594,7 @@ export interface Decorator extends BaseNode {
|
||||
|
||||
export interface TypeParameterDeclaration extends BaseNode {
|
||||
type: "TypeParameterDeclaration";
|
||||
params: $ReadOnlyArray<TypeParameter>;
|
||||
params: ReadonlyArray<TypeParameter>;
|
||||
}
|
||||
export interface TypeParameter extends BaseNode {
|
||||
type: "TypeParameter";
|
||||
@@ -1608,7 +1608,7 @@ export interface TypeParameter extends BaseNode {
|
||||
}
|
||||
export interface TypeParameterInstantiation extends BaseNode {
|
||||
type: "TypeParameterInstantiation";
|
||||
params: $ReadOnlyArray<TypeAnnotationType>;
|
||||
params: ReadonlyArray<TypeAnnotationType>;
|
||||
|
||||
parent: GenericTypeAnnotation | CallExpression | NewExpression;
|
||||
}
|
||||
@@ -1634,7 +1634,7 @@ interface BaseInferrableEnumBody extends BaseEnumBody {
|
||||
export interface EnumNumberBody extends BaseInferrableEnumBody {
|
||||
type: "EnumNumberBody";
|
||||
// enum number members cannot be defaulted
|
||||
members: $ReadOnlyArray<EnumNumberMember>;
|
||||
members: ReadonlyArray<EnumNumberMember>;
|
||||
explicitType: boolean;
|
||||
|
||||
parent: EnumDeclaration;
|
||||
@@ -1651,7 +1651,7 @@ export interface EnumNumberMember extends BaseNode {
|
||||
export interface EnumBigIntBody extends BaseInferrableEnumBody {
|
||||
type: "EnumBigIntBody";
|
||||
// enum bigint members cannot be defaulted
|
||||
members: $ReadOnlyArray<EnumBigIntMember>;
|
||||
members: ReadonlyArray<EnumBigIntMember>;
|
||||
explicitType: boolean;
|
||||
|
||||
parent: EnumDeclaration;
|
||||
@@ -1667,7 +1667,7 @@ export interface EnumBigIntMember extends BaseNode {
|
||||
|
||||
export interface EnumStringBody extends BaseInferrableEnumBody {
|
||||
type: "EnumStringBody";
|
||||
members: $ReadOnlyArray<EnumStringMember | EnumDefaultedMember>;
|
||||
members: ReadonlyArray<EnumStringMember | EnumDefaultedMember>;
|
||||
|
||||
parent: EnumDeclaration;
|
||||
}
|
||||
@@ -1683,7 +1683,7 @@ export interface EnumStringMember extends BaseNode {
|
||||
export interface EnumBooleanBody extends BaseInferrableEnumBody {
|
||||
type: "EnumBooleanBody";
|
||||
// enum boolean members cannot be defaulted
|
||||
members: $ReadOnlyArray<EnumBooleanMember>;
|
||||
members: ReadonlyArray<EnumBooleanMember>;
|
||||
|
||||
parent: EnumDeclaration;
|
||||
}
|
||||
@@ -1699,7 +1699,7 @@ export interface EnumBooleanMember extends BaseNode {
|
||||
export interface EnumSymbolBody extends BaseEnumBody {
|
||||
type: "EnumSymbolBody";
|
||||
// enum symbol members can only be defaulted
|
||||
members: $ReadOnlyArray<EnumDefaultedMember>;
|
||||
members: ReadonlyArray<EnumDefaultedMember>;
|
||||
|
||||
parent: EnumDeclaration;
|
||||
}
|
||||
@@ -1735,10 +1735,10 @@ export interface DeclareClass extends BaseNode {
|
||||
type: "DeclareClass";
|
||||
id: Identifier;
|
||||
typeParameters: null | TypeParameterDeclaration;
|
||||
extends: $ReadOnlyArray<InterfaceExtends>;
|
||||
implements: $ReadOnlyArray<ClassImplements>;
|
||||
extends: ReadonlyArray<InterfaceExtends>;
|
||||
implements: ReadonlyArray<ClassImplements>;
|
||||
body: ObjectTypeAnnotation;
|
||||
mixins: $ReadOnlyArray<InterfaceExtends>;
|
||||
mixins: ReadonlyArray<InterfaceExtends>;
|
||||
}
|
||||
|
||||
export interface DeclareComponent extends BaseNode {
|
||||
@@ -1815,7 +1815,7 @@ export interface DeclareExportAllDeclaration extends BaseNode {
|
||||
|
||||
interface DeclareExportDeclarationBase extends BaseNode {
|
||||
type: "DeclareExportDeclaration";
|
||||
specifiers: $ReadOnlyArray<ExportSpecifier>;
|
||||
specifiers: ReadonlyArray<ExportSpecifier>;
|
||||
source: StringLiteral | null;
|
||||
default: boolean;
|
||||
}
|
||||
@@ -1855,7 +1855,7 @@ export interface DeclareExportDeclarationNamedWithSpecifiers extends DeclareExpo
|
||||
declaration: null;
|
||||
default: false;
|
||||
source: StringLiteral;
|
||||
specifiers: $ReadOnlyArray<ExportSpecifier>;
|
||||
specifiers: ReadonlyArray<ExportSpecifier>;
|
||||
}
|
||||
export type DeclareExportDeclaration =
|
||||
| DeclareExportDefaultDeclaration
|
||||
@@ -1930,7 +1930,7 @@ export interface JSXElement extends BaseNode {
|
||||
type: "JSXElement";
|
||||
openingElement: JSXOpeningElement;
|
||||
closingElement: JSXClosingElement | null;
|
||||
children: $ReadOnlyArray<JSXChild>;
|
||||
children: ReadonlyArray<JSXChild>;
|
||||
}
|
||||
|
||||
export interface JSXEmptyExpression extends BaseNode {
|
||||
@@ -1946,7 +1946,7 @@ export interface JSXFragment extends BaseNode {
|
||||
type: "JSXFragment";
|
||||
openingFragment: JSXOpeningFragment;
|
||||
closingFragment: JSXClosingFragment;
|
||||
children: $ReadOnlyArray<JSXChild>;
|
||||
children: ReadonlyArray<JSXChild>;
|
||||
}
|
||||
|
||||
export interface JSXIdentifier extends BaseNode {
|
||||
@@ -1970,7 +1970,7 @@ export interface JSXOpeningElement extends BaseNode {
|
||||
type: "JSXOpeningElement";
|
||||
selfClosing: boolean;
|
||||
name: JSXTagNameExpression;
|
||||
attributes: $ReadOnlyArray<JSXAttribute | JSXSpreadAttribute>;
|
||||
attributes: ReadonlyArray<JSXAttribute | JSXSpreadAttribute>;
|
||||
typeArguments?: TypeParameterInstantiation | null;
|
||||
|
||||
parent: JSXElement;
|
||||
@@ -2007,7 +2007,7 @@ export interface JSXSpreadChild extends BaseNode {
|
||||
export interface MatchExpression extends BaseNode {
|
||||
type: "MatchExpression";
|
||||
argument: Expression;
|
||||
cases: $ReadOnlyArray<MatchExpressionCase>;
|
||||
cases: ReadonlyArray<MatchExpressionCase>;
|
||||
}
|
||||
export interface MatchExpressionCase extends BaseNode {
|
||||
type: "MatchExpressionCase";
|
||||
@@ -2019,7 +2019,7 @@ export interface MatchExpressionCase extends BaseNode {
|
||||
export interface MatchStatement extends BaseNode {
|
||||
type: "MatchStatement";
|
||||
argument: Expression;
|
||||
cases: $ReadOnlyArray<MatchStatementCase>;
|
||||
cases: ReadonlyArray<MatchStatementCase>;
|
||||
}
|
||||
export interface MatchStatementCase extends BaseNode {
|
||||
type: "MatchStatementCase";
|
||||
@@ -2046,7 +2046,7 @@ export type MatchPattern =
|
||||
|
||||
export interface MatchOrPattern extends BaseNode {
|
||||
type: "MatchOrPattern";
|
||||
patterns: $ReadOnlyArray<MatchPattern>;
|
||||
patterns: ReadonlyArray<MatchPattern>;
|
||||
}
|
||||
export interface MatchAsPattern extends BaseNode {
|
||||
type: "MatchAsPattern";
|
||||
@@ -2081,7 +2081,7 @@ export interface MatchBindingPattern extends BaseNode {
|
||||
}
|
||||
export interface MatchObjectPattern extends BaseNode {
|
||||
type: "MatchObjectPattern";
|
||||
properties: $ReadOnlyArray<MatchObjectPatternProperty>;
|
||||
properties: ReadonlyArray<MatchObjectPatternProperty>;
|
||||
rest: MatchRestPattern | null;
|
||||
}
|
||||
export interface MatchObjectPatternProperty extends BaseNode {
|
||||
@@ -2092,7 +2092,7 @@ export interface MatchObjectPatternProperty extends BaseNode {
|
||||
}
|
||||
export interface MatchArrayPattern extends BaseNode {
|
||||
type: "MatchArrayPattern";
|
||||
elements: $ReadOnlyArray<MatchPattern>;
|
||||
elements: ReadonlyArray<MatchPattern>;
|
||||
rest: MatchRestPattern | null;
|
||||
}
|
||||
export interface MatchRestPattern extends BaseNode {
|
||||
|
||||
@@ -135,6 +135,10 @@ function isBooleanLiteral(node) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@param {Node} node
|
||||
@returns {node is NodeMap["UnaryExpression"]}
|
||||
*/
|
||||
function isSignedNumericLiteral(node) {
|
||||
return (
|
||||
node.type === "UnaryExpression" &&
|
||||
@@ -623,8 +627,13 @@ function isSimpleCallArgument(node, depth = 2) {
|
||||
|
||||
if (isObjectExpression(node)) {
|
||||
return node.properties.every(
|
||||
(p) =>
|
||||
!p.computed && (p.shorthand || (p.value && isChildSimple(p.value))),
|
||||
(property) =>
|
||||
// @ts-expect-error -- FIXME
|
||||
!property.computed &&
|
||||
// @ts-expect-error -- FIXME
|
||||
(property.shorthand ||
|
||||
// @ts-expect-error -- FIXME
|
||||
(property.value && isChildSimple(property.value))),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user