diff --git a/packages/babel-types/scripts/generators/flow.js b/packages/babel-types/scripts/generators/flow.js index daab2411d742..ab4aff9efb53 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} }` + ); } } @@ -118,6 +126,7 @@ lines.push( `declare function validate(n: BabelNode, key: string, value: mixed): void;`, `declare function clone(n: T): T;`, `declare function cloneDeep(n: T): T;`, + `declare function cloneNode(n: T, deep?: boolean): T;`, `declare function removeProperties(n: T, opts: ?{}): void;`, `declare function removePropertiesDeep(n: T, opts: ?{}): T;`, `declare type TraversalAncestors = Array<{ @@ -131,7 +140,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 b6019ec37324..da09a8aaff63 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript.js @@ -100,6 +100,12 @@ for (const type in t.NODE_FIELDS) { lines.push( `export function ${toFunctionName(type)}(${args.join(", ")}): ${type};` ); + } else { + const functionName = toFunctionName(type); + lines.push( + `declare function _${functionName}(${args.join(", ")}): ${type};`, + `export { _${functionName} as ${functionName}}` + ); } } @@ -123,6 +129,7 @@ lines.push( `export function validate(n: Node, key: string, value: any): void;`, `export function clone(n: T): T;`, `export function cloneDeep(n: T): T;`, + `export function cloneNode(n: T, deep?: boolean): T;`, `export function removeProperties( n: Node, opts?: { preserveComments: boolean } | null @@ -142,7 +149,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) { diff --git a/packages/babel-types/src/definitions/experimental.js b/packages/babel-types/src/definitions/experimental.js index ed088af74bd6..a9983c87de6b 100644 --- a/packages/babel-types/src/definitions/experimental.js +++ b/packages/babel-types/src/definitions/experimental.js @@ -146,8 +146,8 @@ defineType("OptionalCallExpression", { }); defineType("ClassPrivateProperty", { - visitor: ["key", "value"], - builder: ["key", "value"], + visitor: ["key", "value", "decorators"], + builder: ["key", "value", "decorators"], aliases: ["Property", "Private"], fields: { key: { @@ -157,6 +157,13 @@ defineType("ClassPrivateProperty", { validate: assertNodeType("Expression"), optional: true, }, + decorators: { + validate: chain( + assertValueType("array"), + assertEach(assertNodeType("Decorator")), + ), + optional: true, + }, }, });