From 4b39d4b272e93057cb3e1585c0ef9eb1cff9304c Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 14 Jun 2019 22:42:18 +0800 Subject: [PATCH] fix missing typescript/flow types for babel-types --- .../babel-types/scripts/generators/flow.js | 26 ++++++++++++++++++- .../scripts/generators/typescript.js | 23 +++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/packages/babel-types/scripts/generators/flow.js b/packages/babel-types/scripts/generators/flow.js index daab2411d742..5c7f1a11a607 100644 --- a/packages/babel-types/scripts/generators/flow.js +++ b/packages/babel-types/scripts/generators/flow.js @@ -99,6 +99,14 @@ for (const type in t.NODE_FIELDS) { ", " )}): ${NODE_PREFIX}${type};` ); + } else { + const functionName = toFunctionName(type); + lines.push( + `declare function _${functionName}(${args.join( + ", " + )}): ${NODE_PREFIX}${type};`, + `declare export { _${functionName} as ${functionName} }` + ); } } @@ -131,7 +139,23 @@ lines.push( exit?: TraversalHandler, };`.replace(/(^|\n) {2}/g, "$1"), // eslint-disable-next-line - `declare function traverse(n: BabelNode, TraversalHandler | TraversalHandlers, state?: T): void;` + `declare function traverse(n: BabelNode, TraversalHandler | TraversalHandlers, 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) { diff --git a/packages/babel-types/scripts/generators/typescript.js b/packages/babel-types/scripts/generators/typescript.js index f3aef23e59d5..7252461df305 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript.js @@ -101,9 +101,10 @@ for (const type in t.NODE_FIELDS) { `export function ${toFunctionName(type)}(${args.join(", ")}): ${type};` ); } else { + const functionName = toFunctionName(type); lines.push( - `declare function _${toFunctionName(type)}(${args.join(", ")}): ${type};`, - `export { _${toFunctionName(type)} as ${toFunctionName(type)}}` + `declare function _${functionName}(${args.join(", ")}): ${type};`, + `export { _${functionName} as ${functionName}}` ); } } @@ -147,7 +148,23 @@ lines.push( exit?: TraversalHandler, };`.replace(/(^|\n) {2}/g, "$1"), // eslint-disable-next-line - `export function traverse(n: Node, h: TraversalHandler | TraversalHandlers, state?: T): void;` + `export function traverse(n: Node, h: TraversalHandler | TraversalHandlers, 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) {