fix typescript for babel-types (#10098)
* fix typescript for babel-types * fix missing typescript/flow types for babel-types * Add cloneNode to flow.js * Add cloneNode to typescript.js
This commit is contained in:
parent
c0e3fa0081
commit
a08e856804
@ -99,6 +99,14 @@ for (const type in t.NODE_FIELDS) {
|
|||||||
", "
|
", "
|
||||||
)}): ${NODE_PREFIX}${type};`
|
)}): ${NODE_PREFIX}${type};`
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
const functionName = toFunctionName(type);
|
||||||
|
lines.push(
|
||||||
|
`declare function _${functionName}(${args.join(
|
||||||
|
", "
|
||||||
|
)}): ${NODE_PREFIX}${type};`,
|
||||||
|
`declare export { _${functionName} as ${functionName} }`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +124,7 @@ lines.push(
|
|||||||
`declare function validate(n: BabelNode, key: string, value: mixed): void;`,
|
`declare function validate(n: BabelNode, key: string, value: mixed): void;`,
|
||||||
`declare function clone<T>(n: T): T;`,
|
`declare function clone<T>(n: T): T;`,
|
||||||
`declare function cloneDeep<T>(n: T): T;`,
|
`declare function cloneDeep<T>(n: T): T;`,
|
||||||
|
`declare function cloneNode<T>(n: T, deep?: boolean): T;`,
|
||||||
`declare function removeProperties<T>(n: T, opts: ?{}): void;`,
|
`declare function removeProperties<T>(n: T, opts: ?{}): void;`,
|
||||||
`declare function removePropertiesDeep<T>(n: T, opts: ?{}): T;`,
|
`declare function removePropertiesDeep<T>(n: T, opts: ?{}): T;`,
|
||||||
`declare type TraversalAncestors = Array<{
|
`declare type TraversalAncestors = Array<{
|
||||||
@ -129,7 +138,23 @@ lines.push(
|
|||||||
exit?: TraversalHandler<T>,
|
exit?: TraversalHandler<T>,
|
||||||
};`.replace(/(^|\n) {2}/g, "$1"),
|
};`.replace(/(^|\n) {2}/g, "$1"),
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
`declare function traverse<T>(n: BabelNode, TraversalHandler<T> | TraversalHandlers<T>, state?: T): void;`
|
`declare function traverse<T>(n: BabelNode, TraversalHandler<T> | TraversalHandlers<T>, state?: T): void;`,
|
||||||
|
`declare function is(type: string, n: BabelNode, opts: Object): boolean;`,
|
||||||
|
`declare function isBinding(node: BabelNode, parent: BabelNode, grandparent?: BabelNode): boolean`,
|
||||||
|
`declare function isBlockScoped(node: BabelNode): boolean`,
|
||||||
|
`declare function isImmutable(node: BabelNode): boolean`,
|
||||||
|
`declare function isLet(node: BabelNode): boolean`,
|
||||||
|
`declare function isNode(node: ?Object): boolean`,
|
||||||
|
`declare function isNodesEquivalent(a: any, b: any): boolean`,
|
||||||
|
`declare function isPlaceholderType(placeholderType: ?string, targetType: string): boolean`,
|
||||||
|
`declare function isReferenced(node: BabelNode, parent: BabelNode, grandparent?: BabelNode): boolean`,
|
||||||
|
`declare function isScope(node: BabelNode, parent: BabelNode): boolean`,
|
||||||
|
`declare function isSpecifierDefault(specifier: BabelNodeModuleSpecifier): boolean`,
|
||||||
|
`declare function isType(nodetype: ?string, targetType: string): boolean`,
|
||||||
|
`declare function isValidES3Identifier(name: string): boolean`,
|
||||||
|
`declare function isValidES3Identifier(name: string): boolean`,
|
||||||
|
`declare function isValidIdentifier(name: string): boolean`,
|
||||||
|
`declare function isVar(node: BabelNode): boolean`
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const type in t.FLIPPED_ALIAS_KEYS) {
|
for (const type in t.FLIPPED_ALIAS_KEYS) {
|
||||||
|
|||||||
@ -100,6 +100,12 @@ for (const type in t.NODE_FIELDS) {
|
|||||||
lines.push(
|
lines.push(
|
||||||
`export function ${toFunctionName(type)}(${args.join(", ")}): ${type};`
|
`export function ${toFunctionName(type)}(${args.join(", ")}): ${type};`
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
const functionName = toFunctionName(type);
|
||||||
|
lines.push(
|
||||||
|
`declare function _${functionName}(${args.join(", ")}): ${type};`,
|
||||||
|
`export { _${functionName} as ${functionName}}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +127,7 @@ lines.push(
|
|||||||
`export function validate(n: Node, key: string, value: any): void;`,
|
`export function validate(n: Node, key: string, value: any): void;`,
|
||||||
`export function clone<T extends Node>(n: T): T;`,
|
`export function clone<T extends Node>(n: T): T;`,
|
||||||
`export function cloneDeep<T extends Node>(n: T): T;`,
|
`export function cloneDeep<T extends Node>(n: T): T;`,
|
||||||
|
`export function cloneNode<T extends Node>(n: T, deep?: boolean): T;`,
|
||||||
`export function removeProperties(
|
`export function removeProperties(
|
||||||
n: Node,
|
n: Node,
|
||||||
opts?: { preserveComments: boolean } | null
|
opts?: { preserveComments: boolean } | null
|
||||||
@ -140,7 +147,23 @@ lines.push(
|
|||||||
exit?: TraversalHandler<T>,
|
exit?: TraversalHandler<T>,
|
||||||
};`.replace(/(^|\n) {2}/g, "$1"),
|
};`.replace(/(^|\n) {2}/g, "$1"),
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
`export function traverse<T>(n: Node, h: TraversalHandler<T> | TraversalHandlers<T>, state?: T): void;`
|
`export function traverse<T>(n: Node, h: TraversalHandler<T> | TraversalHandlers<T>, state?: T): void;`,
|
||||||
|
`export function is(type: string, n: Node, opts: object): boolean;`,
|
||||||
|
`export function isBinding(node: Node, parent: Node, grandparent?: Node): boolean`,
|
||||||
|
`export function isBlockScoped(node: Node): boolean`,
|
||||||
|
`export function isImmutable(node: Node): boolean`,
|
||||||
|
`export function isLet(node: Node): boolean`,
|
||||||
|
`export function isNode(node: ?object): boolean`,
|
||||||
|
`export function isNodesEquivalent(a: any, b: any): boolean`,
|
||||||
|
`export function isPlaceholderType(placeholderType: ?string, targetType: string): boolean`,
|
||||||
|
`export function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean`,
|
||||||
|
`export function isScope(node: Node, parent: Node): boolean`,
|
||||||
|
`export function isSpecifierDefault(specifier: ModuleSpecifier): boolean`,
|
||||||
|
`export function isType(nodetype: ?string, targetType: string): boolean`,
|
||||||
|
`export function isValidES3Identifier(name: string): boolean`,
|
||||||
|
`export function isValidES3Identifier(name: string): boolean`,
|
||||||
|
`export function isValidIdentifier(name: string): boolean`,
|
||||||
|
`export function isVar(node: Node): boolean`
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const type in t.DEPRECATED_KEYS) {
|
for (const type in t.DEPRECATED_KEYS) {
|
||||||
|
|||||||
@ -153,8 +153,8 @@ defineType("OptionalCallExpression", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
defineType("ClassPrivateProperty", {
|
defineType("ClassPrivateProperty", {
|
||||||
visitor: ["key", "value"],
|
visitor: ["key", "value", "decorators"],
|
||||||
builder: ["key", "value"],
|
builder: ["key", "value", "decorators"],
|
||||||
aliases: ["Property", "Private"],
|
aliases: ["Property", "Private"],
|
||||||
fields: {
|
fields: {
|
||||||
key: {
|
key: {
|
||||||
@ -164,6 +164,13 @@ defineType("ClassPrivateProperty", {
|
|||||||
validate: assertNodeType("Expression"),
|
validate: assertNodeType("Expression"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
decorators: {
|
||||||
|
validate: chain(
|
||||||
|
assertValueType("array"),
|
||||||
|
assertEach(assertNodeType("Decorator")),
|
||||||
|
),
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user