diff --git a/Gulpfile.js b/Gulpfile.js index c0f764e607..258dff03de 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -20,10 +20,15 @@ const rollupNodePolyfills = require("rollup-plugin-node-polyfills"); const rollupNodeResolve = require("@rollup/plugin-node-resolve").default; const rollupReplace = require("@rollup/plugin-replace"); const { terser: rollupTerser } = require("rollup-plugin-terser"); +const { default: rollupDts } = require("rollup-plugin-dts"); + +const defaultPackagesGlob = "./@(codemods|packages|eslint)/*"; +const defaultSourcesGlob = `${defaultPackagesGlob}/src/**/{*.js,!(*.d).ts}`; +const defaultDtsGlob = `${defaultPackagesGlob}/lib/**/*.d.ts{,.map}`; -const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.{js,ts}"; const babelStandalonePluginConfigGlob = "./packages/babel-standalone/scripts/pluginConfig.json"; + const buildTypingsWatchGlob = [ "./packages/babel-types/lib/definitions/**/*.js", "./packages/babel-types/scripts/generators/*.js", @@ -37,11 +42,14 @@ const buildTypingsWatchGlob = [ * @example * mapSrcToLib("packages/babel-template/src/index.ts") * // returns "packages/babel-template/lib/index.js" + * @example + * mapSrcToLib("packages/babel-template/src/index.d.ts") + * // returns "packages/babel-template/lib/index.d.ts" * @param {string} srcPath * @returns {string} */ function mapSrcToLib(srcPath) { - const parts = srcPath.replace(/\.ts$/, ".js").split(path.sep); + const parts = srcPath.replace(/(? callback()); + }); +} - let stream = gulp.src(sourcesGlob, { base: __dirname }); +function finish(stream) { + return new Promise((resolve, reject) => { + stream.on("end", resolve); + stream.on("finish", resolve); + stream.on("error", reject); + }); +} + +function getFiles(glob, { include, exclude }) { + let stream = gulp.src(glob, { base: __dirname }); if (exclude) { - const filters = exclude.map(p => `!**/${p.src}/**`); + const filters = exclude.map(p => `!**/${p}/**`); filters.unshift("**"); stream = stream.pipe(filter(filters)); } + if (include) { + const filters = include.map(p => `**/${p}/**`); + stream = stream.pipe(filter(filters)); + } - return stream + return stream; +} + +function buildBabel(exclude) { + const base = __dirname; + + return getFiles(defaultSourcesGlob, { + exclude: exclude && exclude.map(p => p.src), + }) .pipe(errorsLogger()) .pipe(newer({ dest: base, map: mapSrcToLib })) .pipe(compilationLogger()) @@ -283,6 +320,41 @@ function buildRollup(packages, targetBrowsers) { ); } +function buildRollupDts(packages) { + const sourcemap = process.env.NODE_ENV === "production"; + return Promise.all( + packages.map(async packageName => { + const input = `${packageName}/lib/index.d.ts`; + fancyLog(`Bundling '${chalk.cyan(input)}' with rollup ...`); + const bundle = await rollup.rollup({ + input, + plugins: [rollupDts()], + }); + + await finish( + gulp.src(`${packageName}/lib/**/*.d.ts{,.map}`).pipe(unlink()) + ); + + await bundle.write({ + file: `${packageName}/lib/index.d.ts`, + format: "es", + sourcemap: sourcemap, + exports: "named", + }); + }) + ); +} + +function removeDts(exclude) { + return getFiles(defaultDtsGlob, { exclude }).pipe(unlink()); +} + +function copyDts(packages) { + return getFiles(`${defaultPackagesGlob}/src/**/*.d.ts`, { include: packages }) + .pipe(rename(file => path.resolve(file.base, mapSrcToLib(file.relative)))) + .pipe(gulp.dest(__dirname)); +} + const libBundles = [ "packages/babel-parser", "packages/babel-plugin-proposal-optional-chaining", @@ -293,6 +365,8 @@ const libBundles = [ dest: "lib", })); +const dtsBundles = ["packages/babel-types"]; + const standaloneBundle = [ { src: "packages/babel-standalone", @@ -306,11 +380,15 @@ const standaloneBundle = [ gulp.task("generate-type-helpers", () => { fancyLog("Generating @babel/types dynamic functions"); - return Promise.all( - ["asserts", "builders", "constants", "validators"].map(helperKind => - generateTypeHelpers(helperKind) - ) - ); + + return Promise.all([ + generateTypeHelpers("asserts"), + generateTypeHelpers("builders"), + generateTypeHelpers("builders", "uppercase.js"), + generateTypeHelpers("constants"), + generateTypeHelpers("validators"), + generateTypeHelpers("ast-types"), + ]); }); gulp.task("generate-standalone", () => generateStandalone()); @@ -322,6 +400,13 @@ gulp.task( gulp.series("generate-standalone", "rollup-babel-standalone") ); +gulp.task("copy-dts", () => copyDts(dtsBundles)); +gulp.task( + "bundle-dts", + gulp.series("copy-dts", () => buildRollupDts(dtsBundles)) +); +gulp.task("clean-dts", () => removeDts(/* exclude */ dtsBundles)); + gulp.task("build-babel", () => buildBabel(/* exclude */ libBundles)); gulp.task( diff --git a/Makefile b/Makefile index 18f8d450a4..b798591f75 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ endif build-bundle: clean clean-lib $(YARN) gulp build - $(MAKE) build-typings + $(MAKE) build-flow-typings $(MAKE) build-dist build-bundle-ci: bootstrap-only @@ -39,14 +39,11 @@ generate-tsconfig: generate-type-helpers: $(YARN) gulp generate-type-helpers -build-typings: build-flow-typings build-typescript-typings - build-flow-typings: $(NODE) packages/babel-types/scripts/generators/flow.js > packages/babel-types/lib/index.js.flow -build-typescript-typings: - $(NODE) packages/babel-types/scripts/generators/typescript.js > packages/babel-types/lib/index.d.ts - $(NODE) packages/babel-types/scripts/generators/typescript.js --ts3.7 > packages/babel-types/lib/index-ts3.7.d.ts +build-typescript-3.7-typings: + $(NODE) packages/babel-types/scripts/generators/typescript-3.7.js > packages/babel-types/lib/index-ts3.7.d.ts build-standalone: build-babel-standalone @@ -74,7 +71,7 @@ build-no-bundle: clean clean-lib # Ensure that build artifacts for types are created during local # development too. # Babel-transform-fixture-test-runner requires minified polyfill for performance - $(MAKE) build-typings build-polyfill-dist + $(MAKE) build-flow-typings build-polyfill-dist watch: build-no-bundle BABEL_ENV=development $(YARN) gulp watch @@ -85,31 +82,19 @@ flowcheck-ci: code-quality: tscheck flow lint tscheck: generate-tsconfig - make build-typescript-typings $(YARN) tsc -b . -flow: +flow: build-flow-typings $(YARN) flow check --strip-root -lint-ci: lint-js-ci lint-ts-ci check-compat-data-ci - -lint-js-ci: - $(MAKE) lint-js - -lint-ts-ci: - $(MAKE) lint-ts +lint-ci: lint check-compat-data-ci check-compat-data-ci: $(MAKE) check-compat-data -lint: lint-js lint-ts - -lint-js: +lint: BABEL_ENV=test $(YARN) eslint scripts $(SOURCES) '*.{js,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts -lint-ts: - scripts/lint-ts-typings.sh - fix: fix-json fix-js fix-js: @@ -202,19 +187,21 @@ clone-license: prepublish-build: clean-lib clean-runtime-helpers NODE_ENV=production BABEL_ENV=production STRIP_BABEL_8_FLAG=true $(MAKE) build-bundle - $(MAKE) prepublish-build-standalone clone-license + $(MAKE) prepublish-build-standalone clone-license prepublish-prepare-dts + +prepublish-prepare-dts: + $(MAKE) clean-tsconfig + $(MAKE) tscheck + $(YARN) gulp bundle-dts + $(YARN) gulp clean-dts + $(MAKE) build-typescript-3.7-typings + $(MAKE) clean-tsconfig prepublish: $(MAKE) check-yarn-bug-1882 $(MAKE) bootstrap-only $(MAKE) prepublish-build IS_PUBLISH=true $(MAKE) test - # We don't want to publish TS-related files yet, except for @babel/types - rm -f packages/*/lib/**/*.d.ts{,.map} - rm -f codemods/*/lib/**/*.d.ts{,.map} - rm -f eslint/*/lib/**/*.d.ts{,.map} - $(MAKE) clean-tsconfig - $(MAKE) build-typescript-typings new-version: git pull --rebase diff --git a/codecov.yml b/codecov.yml index 17d3dfb026..9d32d68419 100644 --- a/codecov.yml +++ b/codecov.yml @@ -9,4 +9,4 @@ coverage: patch: enabled: false ignore: - - packages/babel-types/src/*/generated/index.js + - packages/babel-types/src/*/generated/* diff --git a/package.json b/package.json index 15d0d0391f..64e56c3c1b 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "mergeiterator": "^1.2.5", "prettier": "^2.0.5", "rollup": "^2.26.5", + "rollup-plugin-dts": "^2.0.0", "rollup-plugin-node-polyfills": "^0.2.1", "rollup-plugin-terser": "^7.0.0", "test262-stream": "^1.3.0", diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index 240e5b5504..969fd2b59b 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -46,7 +46,7 @@ export function skipAllButComputedKey(path: NodePath) { // Avoid using `path.scope` here export const environmentVisitor = { // todo (Babel 8): remove StaticBlock brand checks - [`${t.StaticBlock ? "StaticBlock|" : ""}ClassPrivateProperty|TypeAnnotation`]( + [`${t.staticBlock ? "StaticBlock|" : ""}ClassPrivateProperty|TypeAnnotation`]( path: NodePath, ) { path.skip(); diff --git a/packages/babel-standalone/src/generated/plugins.js b/packages/babel-standalone/src/generated/plugins.js index 1876de4a84..889f6a494e 100644 --- a/packages/babel-standalone/src/generated/plugins.js +++ b/packages/babel-standalone/src/generated/plugins.js @@ -95,7 +95,6 @@ import transformTypeofSymbol from "@babel/plugin-transform-typeof-symbol"; import transformTypescript from "@babel/plugin-transform-typescript"; import transformUnicodeEscapes from "@babel/plugin-transform-unicode-escapes"; import transformUnicodeRegex from "@babel/plugin-transform-unicode-regex"; - export { externalHelpers, syntaxAsyncGenerators, @@ -191,7 +190,6 @@ export { transformUnicodeEscapes, transformUnicodeRegex, }; - export const all = { "external-helpers": externalHelpers, "syntax-async-generators": syntaxAsyncGenerators, diff --git a/packages/babel-types/package.json b/packages/babel-types/package.json index 0401aaa95e..f9e6d1967d 100644 --- a/packages/babel-types/package.json +++ b/packages/babel-types/package.json @@ -14,9 +14,8 @@ "directory": "packages/babel-types" }, "main": "lib/index.js", - "types": "lib/index.d.ts", "typesVersions": { - ">=3.7": { + "<3.7": { "lib/index.d.ts": [ "lib/index-ts3.7.d.ts" ] @@ -29,6 +28,8 @@ }, "devDependencies": { "@babel/generator": "workspace:*", - "@babel/parser": "workspace:*" + "@babel/parser": "workspace:*", + "@types/lodash": "^4.14.162", + "chalk": "^4.1.0" } } diff --git a/packages/babel-types/scripts/generators/asserts.js b/packages/babel-types/scripts/generators/asserts.js index 26bdb8dccb..a517efb31a 100644 --- a/packages/babel-types/scripts/generators/asserts.js +++ b/packages/babel-types/scripts/generators/asserts.js @@ -2,23 +2,30 @@ const definitions = require("../../lib/definitions"); function addAssertHelper(type) { - return `export function assert${type}(node: Object, opts?: Object = {}): void { + const result = + definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type] + ? `node is t.${type}` + : "boolean"; + + return `export function assert${type}(node: object | null | undefined, opts?: object | null): asserts ${ + result === "boolean" ? "node" : result + } { assert("${type}", node, opts) } `; } module.exports = function generateAsserts() { - let output = `// @flow -/* + let output = `/* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ import is from "../../validators/is"; +import type * as t from "../.."; -function assert(type: string, node: Object, opts?: Object): void { +function assert(type: string, node: any, opts?: any): void { if (!is(type, node, opts)) { throw new Error( - \`Expected type "\${type}" with option \${JSON.stringify((opts: any))}, \` + + \`Expected type "\${type}" with option \${JSON.stringify(opts)}, \` + \`but instead got "\${node.type}".\`, ); } @@ -34,7 +41,7 @@ function assert(type: string, node: Object, opts?: Object): void { Object.keys(definitions.DEPRECATED_KEYS).forEach(type => { const newType = definitions.DEPRECATED_KEYS[type]; - output += `export function assert${type}(node: Object, opts: Object): void { + output += `export function assert${type}(node: any, opts: any): void { console.trace("The node type ${type} has been renamed to ${newType}"); assert("${type}", node, opts); }\n`; diff --git a/packages/babel-types/scripts/generators/ast-types.js b/packages/babel-types/scripts/generators/ast-types.js new file mode 100644 index 0000000000..a3c880592a --- /dev/null +++ b/packages/babel-types/scripts/generators/ast-types.js @@ -0,0 +1,139 @@ +"use strict"; + +const t = require("../../"); +const stringifyValidator = require("../utils/stringifyValidator"); + +module.exports = function generateAstTypes() { + let code = `// NOTE: This file is autogenerated. Do not modify. +// See packages/babel-types/scripts/generators/ast-types.js for script used. + +interface BaseComment { + value: string; + start: number; + end: number; + loc: SourceLocation; + type: "CommentBlock" | "CommentLine"; +} + +export interface CommentBlock extends BaseComment { + type: "CommentBlock"; +} + +export interface CommentLine extends BaseComment { + type: "CommentLine"; +} + +export type Comment = CommentBlock | CommentLine; + +export interface SourceLocation { + start: { + line: number; + column: number; + }; + + end: { + line: number; + column: number; + }; +} + +interface BaseNode { + leadingComments: ReadonlyArray | null; + innerComments: ReadonlyArray | null; + trailingComments: ReadonlyArray | null; + start: number | null; + end: number | null; + loc: SourceLocation | null; + type: Node["type"]; + extra?: Record; +} + +export type CommentTypeShorthand = "leading" | "inner" | "trailing"; + +export type Node = ${t.TYPES.sort().join(" | ")};\n\n`; + + const deprecatedAlias = {}; + for (const type in t.DEPRECATED_KEYS) { + deprecatedAlias[t.DEPRECATED_KEYS[type]] = type; + } + for (const type in t.NODE_FIELDS) { + const fields = t.NODE_FIELDS[type]; + const fieldNames = sortFieldNames(Object.keys(t.NODE_FIELDS[type]), type); + const struct = []; + + fieldNames.forEach(fieldName => { + const field = fields[fieldName]; + // Future / annoying TODO: + // MemberExpression.property, ObjectProperty.key and ObjectMethod.key need special cases; either: + // - convert the declaration to chain() like ClassProperty.key and ClassMethod.key, + // - declare an alias type for valid keys, detect the case and reuse it here, + // - declare a disjoint union with, for example, ObjectPropertyBase, + // ObjectPropertyLiteralKey and ObjectPropertyComputedKey, and declare ObjectProperty + // as "ObjectPropertyBase & (ObjectPropertyLiteralKey | ObjectPropertyComputedKey)" + let typeAnnotation = stringifyValidator(field.validate, ""); + + if (isNullable(field) && !hasDefault(field)) { + typeAnnotation += " | null"; + } + + const alphaNumeric = /^\w+$/; + + if (t.isValidIdentifier(fieldName) || alphaNumeric.test(fieldName)) { + struct.push(`${fieldName}: ${typeAnnotation};`); + } else { + struct.push(`"${fieldName}": ${typeAnnotation};`); + } + }); + + code += `export interface ${type} extends BaseNode { + type: "${type}"; + ${struct.join("\n ").trim()} +}\n\n`; + + if (deprecatedAlias[type]) { + code += `/** + * @deprecated Use \`${type}\` + */ +export interface ${deprecatedAlias[type]} extends BaseNode { + type: "${deprecatedAlias[type]}"; + ${struct.join("\n ").trim()} +}\n\n +`; + } + } + + for (const type in t.FLIPPED_ALIAS_KEYS) { + const types = t.FLIPPED_ALIAS_KEYS[type]; + code += `export type ${type} = ${types + .map(type => `${type}`) + .join(" | ")};\n`; + } + code += "\n"; + + code += "export interface Aliases {\n"; + for (const type in t.FLIPPED_ALIAS_KEYS) { + code += ` ${type}: ${type};\n`; + } + code += "}\n\n"; + + return code; +}; + +function hasDefault(field) { + return field.default != null; +} + +function isNullable(field) { + return field.optional || hasDefault(field); +} + +function sortFieldNames(fields, type) { + return fields.sort((fieldA, fieldB) => { + const indexA = t.BUILDER_KEYS[type].indexOf(fieldA); + const indexB = t.BUILDER_KEYS[type].indexOf(fieldB); + if (indexA === indexB) return fieldA < fieldB ? -1 : 1; + if (indexA === -1) return 1; + if (indexB === -1) return -1; + return indexA - indexB; + }); +} diff --git a/packages/babel-types/scripts/generators/builders.js b/packages/babel-types/scripts/generators/builders.js index 5ca9f74643..6a528fe0c3 100644 --- a/packages/babel-types/scripts/generators/builders.js +++ b/packages/babel-types/scripts/generators/builders.js @@ -3,26 +3,106 @@ const definitions = require("../../lib/definitions"); const formatBuilderName = require("../utils/formatBuilderName"); const lowerFirst = require("../utils/lowerFirst"); -module.exports = function generateBuilders() { - let output = `// @flow -/* +const t = require("../../"); +const stringifyValidator = require("../utils/stringifyValidator"); + +function areAllRemainingFieldsNullable(fieldName, fieldNames, fields) { + const index = fieldNames.indexOf(fieldName); + return fieldNames.slice(index).every(_ => isNullable(fields[_])); +} + +function hasDefault(field) { + return field.default != null; +} + +function isNullable(field) { + return field.optional || hasDefault(field); +} + +function sortFieldNames(fields, type) { + return fields.sort((fieldA, fieldB) => { + const indexA = t.BUILDER_KEYS[type].indexOf(fieldA); + const indexB = t.BUILDER_KEYS[type].indexOf(fieldB); + if (indexA === indexB) return fieldA < fieldB ? -1 : 1; + if (indexA === -1) return 1; + if (indexB === -1) return -1; + return indexA - indexB; + }); +} + +function generateBuilderArgs(type) { + const fields = t.NODE_FIELDS[type]; + const fieldNames = sortFieldNames(Object.keys(t.NODE_FIELDS[type]), type); + const builderNames = t.BUILDER_KEYS[type]; + + const args = []; + + fieldNames.forEach(fieldName => { + const field = fields[fieldName]; + // Future / annoying TODO: + // MemberExpression.property, ObjectProperty.key and ObjectMethod.key need special cases; either: + // - convert the declaration to chain() like ClassProperty.key and ClassMethod.key, + // - declare an alias type for valid keys, detect the case and reuse it here, + // - declare a disjoint union with, for example, ObjectPropertyBase, + // ObjectPropertyLiteralKey and ObjectPropertyComputedKey, and declare ObjectProperty + // as "ObjectPropertyBase & (ObjectPropertyLiteralKey | ObjectPropertyComputedKey)" + let typeAnnotation = stringifyValidator(field.validate, "t."); + + if (isNullable(field) && !hasDefault(field)) { + typeAnnotation += " | null"; + } + + if (builderNames.includes(fieldName)) { + const bindingIdentifierName = t.toBindingIdentifierName(fieldName); + if (areAllRemainingFieldsNullable(fieldName, builderNames, fields)) { + args.push( + `${bindingIdentifierName}${ + isNullable(field) ? "?:" : ":" + } ${typeAnnotation}` + ); + } else { + args.push( + `${bindingIdentifierName}: ${typeAnnotation}${ + isNullable(field) ? " | undefined" : "" + }` + ); + } + } + }); + + return args; +} + +module.exports = function generateBuilders(kind) { + return kind === "uppercase.js" + ? generateUppercaseBuilders() + : generateLowercaseBuilders(); +}; + +function generateLowercaseBuilders() { + let output = `/* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ -import builder from "../builder";\n\n`; +import builder from "../builder"; +import type * as t from "../.."; + +/* eslint-disable @typescript-eslint/no-unused-vars */ + +`; const reservedNames = new Set(["super", "import"]); Object.keys(definitions.BUILDER_KEYS).forEach(type => { + const defArgs = generateBuilderArgs(type); const formatedBuilderName = formatBuilderName(type); const formatedBuilderNameLocal = reservedNames.has(formatedBuilderName) ? `_${formatedBuilderName}` : formatedBuilderName; output += `${ formatedBuilderNameLocal === formatedBuilderName ? "export " : "" - }function ${formatedBuilderNameLocal}(...args: Array): Object { return builder("${type}", ...args); }\n`; - // This is needed for backwards compatibility. - // arrayExpression -> ArrayExpression - output += `export { ${formatedBuilderNameLocal} as ${type} };\n`; + }function ${formatedBuilderNameLocal}(${defArgs.join( + ", " + )}): t.${type} { return builder("${type}", ...arguments); }\n`; if (formatedBuilderNameLocal !== formatedBuilderName) { output += `export { ${formatedBuilderNameLocal} as ${formatedBuilderName} };\n`; } @@ -39,12 +119,13 @@ import builder from "../builder";\n\n`; Object.keys(definitions.DEPRECATED_KEYS).forEach(type => { const newType = definitions.DEPRECATED_KEYS[type]; - output += `export function ${type}(...args: Array): Object { + const formatedBuilderName = formatBuilderName(type); + output += `/** @deprecated */ +function ${type}(...args: Array): any { console.trace("The node type ${type} has been renamed to ${newType}"); return builder("${type}", ...args); } -export { ${type} as ${formatBuilderName(type)} };\n`; - +export { ${type} as ${formatedBuilderName} };\n`; // This is needed for backwards compatibility. // It should be removed in the next major version. // JSXIdentifier -> jSXIdentifier @@ -54,4 +135,31 @@ export { ${type} as ${formatBuilderName(type)} };\n`; }); return output; -}; +} + +function generateUppercaseBuilders() { + let output = `/* + * This file is auto-generated! Do not modify it directly. + * To re-generate run 'make build' + */ + +/** + * This file is written in JavaScript and not TypeScript because uppercase builders + * conflict with AST types. TypeScript reads the uppercase.d.ts file instead. + */ + + export {\n`; + + Object.keys(definitions.BUILDER_KEYS).forEach(type => { + const formatedBuilderName = formatBuilderName(type); + output += ` ${formatedBuilderName} as ${type},\n`; + }); + + Object.keys(definitions.DEPRECATED_KEYS).forEach(type => { + const formatedBuilderName = formatBuilderName(type); + output += ` ${formatedBuilderName} as ${type},\n`; + }); + + output += ` } from './index';\n`; + return output; +} diff --git a/packages/babel-types/scripts/generators/constants.js b/packages/babel-types/scripts/generators/constants.js index 1e4d2cabae..8e8b61c50b 100644 --- a/packages/babel-types/scripts/generators/constants.js +++ b/packages/babel-types/scripts/generators/constants.js @@ -2,8 +2,7 @@ const definitions = require("../../lib/definitions"); module.exports = function generateConstants() { - let output = `// @flow -/* + let output = `/* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ diff --git a/packages/babel-types/scripts/generators/flow.js b/packages/babel-types/scripts/generators/flow.js index 2a91703353..8a0a7b2635 100644 --- a/packages/babel-types/scripts/generators/flow.js +++ b/packages/babel-types/scripts/generators/flow.js @@ -98,7 +98,7 @@ for (const type in t.NODE_FIELDS) { // Flow chokes on super() and import() :/ if (type !== "Super" && type !== "Import") { lines.push( - `declare function ${toFunctionName(type)}(${args.join( + `declare export function ${toFunctionName(type)}(${args.join( ", " )}): ${NODE_PREFIX}${type};` ); @@ -117,85 +117,90 @@ for (const typeName of t.TYPES) { const isDeprecated = !!t.DEPRECATED_KEYS[typeName]; const realName = isDeprecated ? t.DEPRECATED_KEYS[typeName] : typeName; - let decl = `declare function is${typeName}(node: ?Object, opts?: ?Object): boolean`; + let decl = `declare export function is${typeName}(node: ?Object, opts?: ?Object): boolean`; if (t.NODE_FIELDS[realName]) { decl += ` %checks (node instanceof ${NODE_PREFIX}${realName})`; } lines.push(decl); lines.push( - `declare function assert${typeName}(node: ?Object, opts?: ?Object): void` + `declare export function assert${typeName}(node: ?Object, opts?: ?Object): void` ); } lines.push( + `declare export var VISITOR_KEYS: { [type: string]: string[] }`, + // assert/ - `declare function assertNode(obj: any): void`, + `declare export function assertNode(obj: any): void`, // builders/ // eslint-disable-next-line max-len - `declare function createTypeAnnotationBasedOnTypeof(type: 'string' | 'number' | 'undefined' | 'boolean' | 'function' | 'object' | 'symbol'): ${NODE_PREFIX}TypeAnnotation`, + `declare export function createTypeAnnotationBasedOnTypeof(type: 'string' | 'number' | 'undefined' | 'boolean' | 'function' | 'object' | 'symbol'): ${NODE_PREFIX}TypeAnnotation`, // eslint-disable-next-line max-len - `declare function createUnionTypeAnnotation(types: Array<${NODE_PREFIX}FlowType>): ${NODE_PREFIX}UnionTypeAnnotation`, + `declare export function createUnionTypeAnnotation(types: Array<${NODE_PREFIX}FlowType>): ${NODE_PREFIX}UnionTypeAnnotation`, // eslint-disable-next-line max-len - `declare function createFlowUnionType(types: Array<${NODE_PREFIX}FlowType>): ${NODE_PREFIX}UnionTypeAnnotation`, + `declare export function createFlowUnionType(types: Array<${NODE_PREFIX}FlowType>): ${NODE_PREFIX}UnionTypeAnnotation`, // this smells like "internal API" // eslint-disable-next-line max-len - `declare function buildChildren(node: { children: Array<${NODE_PREFIX}JSXText | ${NODE_PREFIX}JSXExpressionContainer | ${NODE_PREFIX}JSXSpreadChild | ${NODE_PREFIX}JSXElement | ${NODE_PREFIX}JSXFragment | ${NODE_PREFIX}JSXEmptyExpression> }): Array<${NODE_PREFIX}JSXText | ${NODE_PREFIX}JSXExpressionContainer | ${NODE_PREFIX}JSXSpreadChild | ${NODE_PREFIX}JSXElement | ${NODE_PREFIX}JSXFragment>`, + `declare export function buildChildren(node: { children: Array<${NODE_PREFIX}JSXText | ${NODE_PREFIX}JSXExpressionContainer | ${NODE_PREFIX}JSXSpreadChild | ${NODE_PREFIX}JSXElement | ${NODE_PREFIX}JSXFragment | ${NODE_PREFIX}JSXEmptyExpression> }): Array<${NODE_PREFIX}JSXText | ${NODE_PREFIX}JSXExpressionContainer | ${NODE_PREFIX}JSXSpreadChild | ${NODE_PREFIX}JSXElement | ${NODE_PREFIX}JSXFragment>`, // clone/ - `declare function clone(n: T): T;`, - `declare function cloneDeep(n: T): T;`, - `declare function cloneDeepWithoutLoc(n: T): T;`, - `declare function cloneNode(n: T, deep?: boolean, withoutLoc?: boolean): T;`, - `declare function cloneWithoutLoc(n: T): T;`, + `declare export function clone(n: T): T;`, + `declare export function cloneDeep(n: T): T;`, + `declare export function cloneDeepWithoutLoc(n: T): T;`, + `declare export function cloneNode(n: T, deep?: boolean, withoutLoc?: boolean): T;`, + `declare export function cloneWithoutLoc(n: T): T;`, // comments/ `declare type CommentTypeShorthand = 'leading' | 'inner' | 'trailing'`, // eslint-disable-next-line max-len - `declare function addComment(node: T, type: CommentTypeShorthand, content: string, line?: boolean): T`, + `declare export function addComment(node: T, type: CommentTypeShorthand, content: string, line?: boolean): T`, // eslint-disable-next-line max-len - `declare function addComments(node: T, type: CommentTypeShorthand, comments: Array): T`, - `declare function inheritInnerComments(node: Node, parent: Node): void`, - `declare function inheritLeadingComments(node: Node, parent: Node): void`, - `declare function inheritsComments(node: T, parent: Node): void`, - `declare function inheritTrailingComments(node: Node, parent: Node): void`, - `declare function removeComments(node: T): T`, + `declare export function addComments(node: T, type: CommentTypeShorthand, comments: Array): T`, + `declare export function inheritInnerComments(node: BabelNode, parent: BabelNode): void`, + `declare export function inheritLeadingComments(node: BabelNode, parent: BabelNode): void`, + `declare export function inheritsComments(node: T, parent: BabelNode): void`, + `declare export function inheritTrailingComments(node: BabelNode, parent: BabelNode): void`, + `declare export function removeComments(node: T): T`, // converters/ - `declare function ensureBlock(node: ${NODE_PREFIX}, key: string): ${NODE_PREFIX}BlockStatement`, - `declare function toBindingIdentifierName(name?: ?string): string`, + `declare export function ensureBlock(node: ${NODE_PREFIX}, key: string): ${NODE_PREFIX}BlockStatement`, + `declare export function toBindingIdentifierName(name?: ?string): string`, // eslint-disable-next-line max-len - `declare function toBlock(node: ${NODE_PREFIX}Statement | ${NODE_PREFIX}Expression, parent?: ${NODE_PREFIX}Function | null): ${NODE_PREFIX}BlockStatement`, + `declare export function toBlock(node: ${NODE_PREFIX}Statement | ${NODE_PREFIX}Expression, parent?: ${NODE_PREFIX}Function | null): ${NODE_PREFIX}BlockStatement`, // eslint-disable-next-line max-len - `declare function toComputedKey(node: ${NODE_PREFIX}Method | ${NODE_PREFIX}Property, key?: ${NODE_PREFIX}Expression | ${NODE_PREFIX}Identifier): ${NODE_PREFIX}Expression`, + `declare export function toComputedKey(node: ${NODE_PREFIX}Method | ${NODE_PREFIX}Property, key?: ${NODE_PREFIX}Expression | ${NODE_PREFIX}Identifier): ${NODE_PREFIX}Expression`, // eslint-disable-next-line max-len - `declare function toExpression(node: ${NODE_PREFIX}ExpressionStatement | ${NODE_PREFIX}Expression | ${NODE_PREFIX}Class | ${NODE_PREFIX}Function): ${NODE_PREFIX}Expression`, - `declare function toIdentifier(name?: ?string): string`, + `declare export function toExpression(node: ${NODE_PREFIX}ExpressionStatement | ${NODE_PREFIX}Expression | ${NODE_PREFIX}Class | ${NODE_PREFIX}Function): ${NODE_PREFIX}Expression`, + `declare export function toIdentifier(name?: ?string): string`, // eslint-disable-next-line max-len - `declare function toKeyAlias(node: ${NODE_PREFIX}Method | ${NODE_PREFIX}Property, key?: ${NODE_PREFIX}): string`, + `declare export function toKeyAlias(node: ${NODE_PREFIX}Method | ${NODE_PREFIX}Property, key?: ${NODE_PREFIX}): string`, // toSequenceExpression relies on types that aren't declared in flow // eslint-disable-next-line max-len - `declare function toStatement(node: ${NODE_PREFIX}Statement | ${NODE_PREFIX}Class | ${NODE_PREFIX}Function | ${NODE_PREFIX}AssignmentExpression, ignore?: boolean): ${NODE_PREFIX}Statement | void`, - `declare function valueToNode(value: any): ${NODE_PREFIX}Expression`, + `declare export function toStatement(node: ${NODE_PREFIX}Statement | ${NODE_PREFIX}Class | ${NODE_PREFIX}Function | ${NODE_PREFIX}AssignmentExpression, ignore?: boolean): ${NODE_PREFIX}Statement | void`, + `declare export function valueToNode(value: any): ${NODE_PREFIX}Expression`, // modifications/ // eslint-disable-next-line max-len - `declare function removeTypeDuplicates(types: Array<${NODE_PREFIX}FlowType>): Array<${NODE_PREFIX}FlowType>`, + `declare export function removeTypeDuplicates(types: Array<${NODE_PREFIX}FlowType>): Array<${NODE_PREFIX}FlowType>`, // eslint-disable-next-line max-len - `declare function appendToMemberExpression(member: ${NODE_PREFIX}MemberExpression, append: ${NODE_PREFIX}, computed?: boolean): ${NODE_PREFIX}MemberExpression`, + `declare export function appendToMemberExpression(member: ${NODE_PREFIX}MemberExpression, append: ${NODE_PREFIX}, computed?: boolean): ${NODE_PREFIX}MemberExpression`, // eslint-disable-next-line max-len - `declare function inherits(child: T, parent: ${NODE_PREFIX} | null | void): T`, + `declare export function inherits(child: T, parent: ${NODE_PREFIX} | null | void): T`, // eslint-disable-next-line max-len - `declare function prependToMemberExpression(member: ${NODE_PREFIX}MemberExpression, prepend: ${NODE_PREFIX}Expression): ${NODE_PREFIX}MemberExpression`, - `declare function removeProperties(n: T, opts: ?{}): void;`, - `declare function removePropertiesDeep(n: T, opts: ?{}): T;`, + `declare export function prependToMemberExpression(member: ${NODE_PREFIX}MemberExpression, prepend: ${NODE_PREFIX}Expression): ${NODE_PREFIX}MemberExpression`, + `declare export function removeProperties(n: T, opts: ?{}): void;`, + `declare export function removePropertiesDeep(n: T, opts: ?{}): T;`, // retrievers/ // eslint-disable-next-line max-len - `declare function getBindingIdentifiers(node: ${NODE_PREFIX}, duplicates: boolean, outerOnly?: boolean): { [key: string]: ${NODE_PREFIX}Identifier | Array<${NODE_PREFIX}Identifier> }`, + `declare export var getBindingIdentifiers: { + (node: ${NODE_PREFIX}, duplicates?: boolean, outerOnly?: boolean): { [key: string]: ${NODE_PREFIX}Identifier | Array<${NODE_PREFIX}Identifier> }, + keys: { [type: string]: string[] } + }`, // eslint-disable-next-line max-len - `declare function getOuterBindingIdentifiers(node: Node, duplicates: boolean): { [key: string]: ${NODE_PREFIX}Identifier | Array<${NODE_PREFIX}Identifier> }`, + `declare export function getOuterBindingIdentifiers(node: BabelNode, duplicates?: boolean): { [key: string]: ${NODE_PREFIX}Identifier | Array<${NODE_PREFIX}Identifier> }`, // traverse/ `declare type TraversalAncestors = Array<{ @@ -209,36 +214,36 @@ 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 traverseFast(n: Node, h: TraversalHandler, state?: T): void;`, + `declare export function traverse(n: BabelNode, TraversalHandler | TraversalHandlers, state?: T): void;`, + `declare export function traverseFast(n: BabelNode, h: TraversalHandler, state?: T): void;`, // utils/ // cleanJSXElementLiteralChild is not exported // inherit is not exported - `declare function shallowEqual(actual: Object, expected: Object): boolean`, + `declare export function shallowEqual(actual: Object, expected: Object): boolean`, // validators/ // eslint-disable-next-line max-len - `declare function buildMatchMemberExpression(match: string, allowPartial?: boolean): (?BabelNode) => boolean`, - `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`, + `declare export function buildMatchMemberExpression(match: string, allowPartial?: boolean): (?BabelNode) => boolean`, + `declare export function is(type: string, n: BabelNode, opts: Object): boolean;`, + `declare export function isBinding(node: BabelNode, parent: BabelNode, grandparent?: BabelNode): boolean`, + `declare export function isBlockScoped(node: BabelNode): boolean`, + `declare export function isImmutable(node: BabelNode): boolean`, + `declare export function isLet(node: BabelNode): boolean`, + `declare export function isNode(node: ?Object): boolean`, + `declare export function isNodesEquivalent(a: any, b: any): boolean`, + `declare export function isPlaceholderType(placeholderType: string, targetType: string): boolean`, + `declare export function isReferenced(node: BabelNode, parent: BabelNode, grandparent?: BabelNode): boolean`, + `declare export function isScope(node: BabelNode, parent: BabelNode): boolean`, + `declare export function isSpecifierDefault(specifier: BabelNodeModuleSpecifier): boolean`, + `declare export function isType(nodetype: ?string, targetType: string): boolean`, + `declare export function isValidES3Identifier(name: string): boolean`, + `declare export function isValidES3Identifier(name: string): boolean`, + `declare export function isValidIdentifier(name: string): boolean`, + `declare export function isVar(node: BabelNode): boolean`, // eslint-disable-next-line max-len - `declare function matchesPattern(node: ?BabelNode, match: string | Array, allowPartial?: boolean): boolean`, - `declare function validate(n: BabelNode, key: string, value: mixed): void;` + `declare export function matchesPattern(node: ?BabelNode, match: string | Array, allowPartial?: boolean): boolean`, + `declare export function validate(n: BabelNode, key: string, value: mixed): void;` ); 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-3.7.js similarity index 96% rename from packages/babel-types/scripts/generators/typescript.js rename to packages/babel-types/scripts/generators/typescript-3.7.js index 210124d829..98a4dbfe75 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript-3.7.js @@ -1,17 +1,11 @@ "use strict"; -const t = require("../../"); +const t = require("../../lib"); const stringifyValidator = require("../utils/stringifyValidator"); const toFunctionName = require("../utils/toFunctionName"); -// For backward compat, we cannot use TS 3.7 syntax in published packages -const ts3_7 = process.argv.includes("--ts3.7"); - -// TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations -const asserts = ts3_7 ? assertion => `asserts ${assertion}` : () => `void`; - let code = `// NOTE: This file is autogenerated. Do not modify. -// See packages/babel-types/scripts/generators/typescript.js for script used. +// See packages/babel-types/scripts/generators/typescript-3.7.js for script used. interface BaseComment { value: string; @@ -146,15 +140,13 @@ for (const typeName of t.TYPES) { lines.push(`/** @deprecated Use \`assert${realName}\` */`); } lines.push( - `export function assert${typeName}(node: object | null | undefined, opts?: object | null): ${asserts( - result === "boolean" ? "node" : result - )};` + `export function assert${typeName}(node: object | null | undefined, opts?: object | null): void;` ); } lines.push( // assert/ - `export function assertNode(obj: any): ${asserts("obj is Node")}`, + `export function assertNode(obj: any): void`, // builders/ // eslint-disable-next-line max-len @@ -320,9 +312,7 @@ lines.push( // eslint-disable-next-line max-len `export function matchesPattern(node: Node | null | undefined, match: string | ReadonlyArray, allowPartial?: boolean): node is MemberExpression`, // eslint-disable-next-line max-len - `export function validate(n: Node | null | undefined, key: K, value: T[K]): ${asserts( - "n is T" - )}`, + `export function validate(n: Node | null | undefined, key: K, value: T[K]): void;`, `export function validate(n: Node, key: string, value: any): void;` ); diff --git a/packages/babel-types/scripts/generators/validators.js b/packages/babel-types/scripts/generators/validators.js index 1455f99e5b..c63d447bcd 100644 --- a/packages/babel-types/scripts/generators/validators.js +++ b/packages/babel-types/scripts/generators/validators.js @@ -13,7 +13,7 @@ function addIsHelper(type, aliasKeys, deprecated) { const targetType = JSON.stringify(type); let aliasSource = ""; if (aliasKeys) { - aliasSource = " || " + joinComparisons(aliasKeys, "nodeType"); + aliasSource = joinComparisons(aliasKeys, "nodeType"); } let placeholderSource = ""; @@ -30,16 +30,26 @@ function addIsHelper(type, aliasKeys, deprecated) { if (placeholderTypes.length > 0) { placeholderSource = ' || nodeType === "Placeholder" && (' + - joinComparisons(placeholderTypes, "node.expectedNode") + + joinComparisons( + placeholderTypes, + "(node as t.Placeholder).expectedNode" + ) + ")"; } - return `export function is${type}(node: ?Object, opts?: Object): boolean { + const result = + definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type] + ? `node is t.${type}` + : "boolean"; + + return `export function is${type}(node: object | null | undefined, opts?: object | null): ${result} { ${deprecated || ""} if (!node) return false; - const nodeType = node.type; - if (nodeType === ${targetType}${aliasSource}${placeholderSource}) { + const nodeType = (node as t.Node).type; + if (${ + aliasSource ? aliasSource : `nodeType === ${targetType}` + }${placeholderSource}) { if (typeof opts === "undefined") { return true; } else { @@ -53,12 +63,12 @@ function addIsHelper(type, aliasKeys, deprecated) { } module.exports = function generateValidators() { - let output = `// @flow -/* + let output = `/* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ -import shallowEqual from "../../utils/shallowEqual";\n\n`; +import shallowEqual from "../../utils/shallowEqual"; +import type * as t from "../..";\n\n`; Object.keys(definitions.VISITOR_KEYS).forEach(type => { output += addIsHelper(type); diff --git a/packages/babel-types/src/asserts/assertNode.ts b/packages/babel-types/src/asserts/assertNode.ts index 9f4f327ef9..85c2d998c4 100644 --- a/packages/babel-types/src/asserts/assertNode.ts +++ b/packages/babel-types/src/asserts/assertNode.ts @@ -1,9 +1,9 @@ -// @flow import isNode from "../validators/isNode"; +import type * as t from ".."; -export default function assertNode(node?: Object): void { +export default function assertNode(node?: any): asserts node is t.Node { if (!isNode(node)) { const type = node?.type ?? JSON.stringify(node); - throw new TypeError(`Not a valid node of type "${(type: any)}"`); + throw new TypeError(`Not a valid node of type "${type as any}"`); } } diff --git a/packages/babel-types/src/asserts/generated/index.ts b/packages/babel-types/src/asserts/generated/index.ts index f8cc466531..2744f4c6bf 100755 --- a/packages/babel-types/src/asserts/generated/index.ts +++ b/packages/babel-types/src/asserts/generated/index.ts @@ -1,1246 +1,1756 @@ -// @flow /* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ import is from "../../validators/is"; +import type * as t from "../.."; -function assert(type: string, node: Object, opts?: Object): void { +function assert(type: string, node: any, opts?: any): void { if (!is(type, node, opts)) { throw new Error( - `Expected type "${type}" with option ${JSON.stringify((opts: any))}, ` + + `Expected type "${type}" with option ${JSON.stringify(opts)}, ` + `but instead got "${node.type}".`, ); } } -export function assertArrayExpression(node: Object, opts?: Object = {}): void { +export function assertArrayExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ArrayExpression { assert("ArrayExpression", node, opts); } export function assertAssignmentExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.AssignmentExpression { assert("AssignmentExpression", node, opts); } -export function assertBinaryExpression(node: Object, opts?: Object = {}): void { +export function assertBinaryExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BinaryExpression { assert("BinaryExpression", node, opts); } export function assertInterpreterDirective( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.InterpreterDirective { assert("InterpreterDirective", node, opts); } -export function assertDirective(node: Object, opts?: Object = {}): void { +export function assertDirective( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Directive { assert("Directive", node, opts); } -export function assertDirectiveLiteral(node: Object, opts?: Object = {}): void { +export function assertDirectiveLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DirectiveLiteral { assert("DirectiveLiteral", node, opts); } -export function assertBlockStatement(node: Object, opts?: Object = {}): void { +export function assertBlockStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BlockStatement { assert("BlockStatement", node, opts); } -export function assertBreakStatement(node: Object, opts?: Object = {}): void { +export function assertBreakStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BreakStatement { assert("BreakStatement", node, opts); } -export function assertCallExpression(node: Object, opts?: Object = {}): void { +export function assertCallExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.CallExpression { assert("CallExpression", node, opts); } -export function assertCatchClause(node: Object, opts?: Object = {}): void { +export function assertCatchClause( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.CatchClause { assert("CatchClause", node, opts); } export function assertConditionalExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ConditionalExpression { assert("ConditionalExpression", node, opts); } export function assertContinueStatement( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ContinueStatement { assert("ContinueStatement", node, opts); } export function assertDebuggerStatement( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DebuggerStatement { assert("DebuggerStatement", node, opts); } -export function assertDoWhileStatement(node: Object, opts?: Object = {}): void { +export function assertDoWhileStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DoWhileStatement { assert("DoWhileStatement", node, opts); } -export function assertEmptyStatement(node: Object, opts?: Object = {}): void { +export function assertEmptyStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EmptyStatement { assert("EmptyStatement", node, opts); } export function assertExpressionStatement( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExpressionStatement { assert("ExpressionStatement", node, opts); } -export function assertFile(node: Object, opts?: Object = {}): void { +export function assertFile( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.File { assert("File", node, opts); } -export function assertForInStatement(node: Object, opts?: Object = {}): void { +export function assertForInStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ForInStatement { assert("ForInStatement", node, opts); } -export function assertForStatement(node: Object, opts?: Object = {}): void { +export function assertForStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ForStatement { assert("ForStatement", node, opts); } export function assertFunctionDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FunctionDeclaration { assert("FunctionDeclaration", node, opts); } export function assertFunctionExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FunctionExpression { assert("FunctionExpression", node, opts); } -export function assertIdentifier(node: Object, opts?: Object = {}): void { +export function assertIdentifier( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Identifier { assert("Identifier", node, opts); } -export function assertIfStatement(node: Object, opts?: Object = {}): void { +export function assertIfStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.IfStatement { assert("IfStatement", node, opts); } -export function assertLabeledStatement(node: Object, opts?: Object = {}): void { +export function assertLabeledStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.LabeledStatement { assert("LabeledStatement", node, opts); } -export function assertStringLiteral(node: Object, opts?: Object = {}): void { +export function assertStringLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.StringLiteral { assert("StringLiteral", node, opts); } -export function assertNumericLiteral(node: Object, opts?: Object = {}): void { +export function assertNumericLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NumericLiteral { assert("NumericLiteral", node, opts); } -export function assertNullLiteral(node: Object, opts?: Object = {}): void { +export function assertNullLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NullLiteral { assert("NullLiteral", node, opts); } -export function assertBooleanLiteral(node: Object, opts?: Object = {}): void { +export function assertBooleanLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BooleanLiteral { assert("BooleanLiteral", node, opts); } -export function assertRegExpLiteral(node: Object, opts?: Object = {}): void { +export function assertRegExpLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.RegExpLiteral { assert("RegExpLiteral", node, opts); } export function assertLogicalExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.LogicalExpression { assert("LogicalExpression", node, opts); } -export function assertMemberExpression(node: Object, opts?: Object = {}): void { +export function assertMemberExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.MemberExpression { assert("MemberExpression", node, opts); } -export function assertNewExpression(node: Object, opts?: Object = {}): void { +export function assertNewExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NewExpression { assert("NewExpression", node, opts); } -export function assertProgram(node: Object, opts?: Object = {}): void { +export function assertProgram( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Program { assert("Program", node, opts); } -export function assertObjectExpression(node: Object, opts?: Object = {}): void { +export function assertObjectExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectExpression { assert("ObjectExpression", node, opts); } -export function assertObjectMethod(node: Object, opts?: Object = {}): void { +export function assertObjectMethod( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectMethod { assert("ObjectMethod", node, opts); } -export function assertObjectProperty(node: Object, opts?: Object = {}): void { +export function assertObjectProperty( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectProperty { assert("ObjectProperty", node, opts); } -export function assertRestElement(node: Object, opts?: Object = {}): void { +export function assertRestElement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.RestElement { assert("RestElement", node, opts); } -export function assertReturnStatement(node: Object, opts?: Object = {}): void { +export function assertReturnStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ReturnStatement { assert("ReturnStatement", node, opts); } export function assertSequenceExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.SequenceExpression { assert("SequenceExpression", node, opts); } export function assertParenthesizedExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ParenthesizedExpression { assert("ParenthesizedExpression", node, opts); } -export function assertSwitchCase(node: Object, opts?: Object = {}): void { +export function assertSwitchCase( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.SwitchCase { assert("SwitchCase", node, opts); } -export function assertSwitchStatement(node: Object, opts?: Object = {}): void { +export function assertSwitchStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.SwitchStatement { assert("SwitchStatement", node, opts); } -export function assertThisExpression(node: Object, opts?: Object = {}): void { +export function assertThisExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ThisExpression { assert("ThisExpression", node, opts); } -export function assertThrowStatement(node: Object, opts?: Object = {}): void { +export function assertThrowStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ThrowStatement { assert("ThrowStatement", node, opts); } -export function assertTryStatement(node: Object, opts?: Object = {}): void { +export function assertTryStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TryStatement { assert("TryStatement", node, opts); } -export function assertUnaryExpression(node: Object, opts?: Object = {}): void { +export function assertUnaryExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.UnaryExpression { assert("UnaryExpression", node, opts); } -export function assertUpdateExpression(node: Object, opts?: Object = {}): void { +export function assertUpdateExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.UpdateExpression { assert("UpdateExpression", node, opts); } export function assertVariableDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.VariableDeclaration { assert("VariableDeclaration", node, opts); } export function assertVariableDeclarator( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.VariableDeclarator { assert("VariableDeclarator", node, opts); } -export function assertWhileStatement(node: Object, opts?: Object = {}): void { +export function assertWhileStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.WhileStatement { assert("WhileStatement", node, opts); } -export function assertWithStatement(node: Object, opts?: Object = {}): void { +export function assertWithStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.WithStatement { assert("WithStatement", node, opts); } export function assertAssignmentPattern( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.AssignmentPattern { assert("AssignmentPattern", node, opts); } -export function assertArrayPattern(node: Object, opts?: Object = {}): void { +export function assertArrayPattern( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ArrayPattern { assert("ArrayPattern", node, opts); } export function assertArrowFunctionExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ArrowFunctionExpression { assert("ArrowFunctionExpression", node, opts); } -export function assertClassBody(node: Object, opts?: Object = {}): void { +export function assertClassBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassBody { assert("ClassBody", node, opts); } -export function assertClassExpression(node: Object, opts?: Object = {}): void { +export function assertClassExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassExpression { assert("ClassExpression", node, opts); } -export function assertClassDeclaration(node: Object, opts?: Object = {}): void { +export function assertClassDeclaration( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassDeclaration { assert("ClassDeclaration", node, opts); } export function assertExportAllDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportAllDeclaration { assert("ExportAllDeclaration", node, opts); } export function assertExportDefaultDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportDefaultDeclaration { assert("ExportDefaultDeclaration", node, opts); } export function assertExportNamedDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportNamedDeclaration { assert("ExportNamedDeclaration", node, opts); } -export function assertExportSpecifier(node: Object, opts?: Object = {}): void { +export function assertExportSpecifier( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportSpecifier { assert("ExportSpecifier", node, opts); } -export function assertForOfStatement(node: Object, opts?: Object = {}): void { +export function assertForOfStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ForOfStatement { assert("ForOfStatement", node, opts); } export function assertImportDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ImportDeclaration { assert("ImportDeclaration", node, opts); } export function assertImportDefaultSpecifier( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ImportDefaultSpecifier { assert("ImportDefaultSpecifier", node, opts); } export function assertImportNamespaceSpecifier( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ImportNamespaceSpecifier { assert("ImportNamespaceSpecifier", node, opts); } -export function assertImportSpecifier(node: Object, opts?: Object = {}): void { +export function assertImportSpecifier( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ImportSpecifier { assert("ImportSpecifier", node, opts); } -export function assertMetaProperty(node: Object, opts?: Object = {}): void { +export function assertMetaProperty( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.MetaProperty { assert("MetaProperty", node, opts); } -export function assertClassMethod(node: Object, opts?: Object = {}): void { +export function assertClassMethod( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassMethod { assert("ClassMethod", node, opts); } -export function assertObjectPattern(node: Object, opts?: Object = {}): void { +export function assertObjectPattern( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectPattern { assert("ObjectPattern", node, opts); } -export function assertSpreadElement(node: Object, opts?: Object = {}): void { +export function assertSpreadElement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.SpreadElement { assert("SpreadElement", node, opts); } -export function assertSuper(node: Object, opts?: Object = {}): void { +export function assertSuper( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Super { assert("Super", node, opts); } export function assertTaggedTemplateExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TaggedTemplateExpression { assert("TaggedTemplateExpression", node, opts); } -export function assertTemplateElement(node: Object, opts?: Object = {}): void { +export function assertTemplateElement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TemplateElement { assert("TemplateElement", node, opts); } -export function assertTemplateLiteral(node: Object, opts?: Object = {}): void { +export function assertTemplateLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TemplateLiteral { assert("TemplateLiteral", node, opts); } -export function assertYieldExpression(node: Object, opts?: Object = {}): void { +export function assertYieldExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.YieldExpression { assert("YieldExpression", node, opts); } -export function assertAwaitExpression(node: Object, opts?: Object = {}): void { +export function assertAwaitExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.AwaitExpression { assert("AwaitExpression", node, opts); } -export function assertImport(node: Object, opts?: Object = {}): void { +export function assertImport( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Import { assert("Import", node, opts); } -export function assertBigIntLiteral(node: Object, opts?: Object = {}): void { +export function assertBigIntLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BigIntLiteral { assert("BigIntLiteral", node, opts); } export function assertExportNamespaceSpecifier( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportNamespaceSpecifier { assert("ExportNamespaceSpecifier", node, opts); } export function assertOptionalMemberExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.OptionalMemberExpression { assert("OptionalMemberExpression", node, opts); } export function assertOptionalCallExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.OptionalCallExpression { assert("OptionalCallExpression", node, opts); } export function assertAnyTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.AnyTypeAnnotation { assert("AnyTypeAnnotation", node, opts); } export function assertArrayTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ArrayTypeAnnotation { assert("ArrayTypeAnnotation", node, opts); } export function assertBooleanTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BooleanTypeAnnotation { assert("BooleanTypeAnnotation", node, opts); } export function assertBooleanLiteralTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BooleanLiteralTypeAnnotation { assert("BooleanLiteralTypeAnnotation", node, opts); } export function assertNullLiteralTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NullLiteralTypeAnnotation { assert("NullLiteralTypeAnnotation", node, opts); } -export function assertClassImplements(node: Object, opts?: Object = {}): void { +export function assertClassImplements( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassImplements { assert("ClassImplements", node, opts); } -export function assertDeclareClass(node: Object, opts?: Object = {}): void { +export function assertDeclareClass( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareClass { assert("DeclareClass", node, opts); } -export function assertDeclareFunction(node: Object, opts?: Object = {}): void { +export function assertDeclareFunction( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareFunction { assert("DeclareFunction", node, opts); } -export function assertDeclareInterface(node: Object, opts?: Object = {}): void { +export function assertDeclareInterface( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareInterface { assert("DeclareInterface", node, opts); } -export function assertDeclareModule(node: Object, opts?: Object = {}): void { +export function assertDeclareModule( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareModule { assert("DeclareModule", node, opts); } export function assertDeclareModuleExports( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareModuleExports { assert("DeclareModuleExports", node, opts); } -export function assertDeclareTypeAlias(node: Object, opts?: Object = {}): void { +export function assertDeclareTypeAlias( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareTypeAlias { assert("DeclareTypeAlias", node, opts); } export function assertDeclareOpaqueType( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareOpaqueType { assert("DeclareOpaqueType", node, opts); } -export function assertDeclareVariable(node: Object, opts?: Object = {}): void { +export function assertDeclareVariable( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareVariable { assert("DeclareVariable", node, opts); } export function assertDeclareExportDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareExportDeclaration { assert("DeclareExportDeclaration", node, opts); } export function assertDeclareExportAllDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclareExportAllDeclaration { assert("DeclareExportAllDeclaration", node, opts); } export function assertDeclaredPredicate( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DeclaredPredicate { assert("DeclaredPredicate", node, opts); } export function assertExistsTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExistsTypeAnnotation { assert("ExistsTypeAnnotation", node, opts); } export function assertFunctionTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FunctionTypeAnnotation { assert("FunctionTypeAnnotation", node, opts); } export function assertFunctionTypeParam( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FunctionTypeParam { assert("FunctionTypeParam", node, opts); } export function assertGenericTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.GenericTypeAnnotation { assert("GenericTypeAnnotation", node, opts); } export function assertInferredPredicate( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.InferredPredicate { assert("InferredPredicate", node, opts); } -export function assertInterfaceExtends(node: Object, opts?: Object = {}): void { +export function assertInterfaceExtends( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.InterfaceExtends { assert("InterfaceExtends", node, opts); } export function assertInterfaceDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.InterfaceDeclaration { assert("InterfaceDeclaration", node, opts); } export function assertInterfaceTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.InterfaceTypeAnnotation { assert("InterfaceTypeAnnotation", node, opts); } export function assertIntersectionTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.IntersectionTypeAnnotation { assert("IntersectionTypeAnnotation", node, opts); } export function assertMixedTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.MixedTypeAnnotation { assert("MixedTypeAnnotation", node, opts); } export function assertEmptyTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EmptyTypeAnnotation { assert("EmptyTypeAnnotation", node, opts); } export function assertNullableTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NullableTypeAnnotation { assert("NullableTypeAnnotation", node, opts); } export function assertNumberLiteralTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NumberLiteralTypeAnnotation { assert("NumberLiteralTypeAnnotation", node, opts); } export function assertNumberTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.NumberTypeAnnotation { assert("NumberTypeAnnotation", node, opts); } export function assertObjectTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectTypeAnnotation { assert("ObjectTypeAnnotation", node, opts); } export function assertObjectTypeInternalSlot( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectTypeInternalSlot { assert("ObjectTypeInternalSlot", node, opts); } export function assertObjectTypeCallProperty( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectTypeCallProperty { assert("ObjectTypeCallProperty", node, opts); } export function assertObjectTypeIndexer( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectTypeIndexer { assert("ObjectTypeIndexer", node, opts); } export function assertObjectTypeProperty( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectTypeProperty { assert("ObjectTypeProperty", node, opts); } export function assertObjectTypeSpreadProperty( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectTypeSpreadProperty { assert("ObjectTypeSpreadProperty", node, opts); } -export function assertOpaqueType(node: Object, opts?: Object = {}): void { +export function assertOpaqueType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.OpaqueType { assert("OpaqueType", node, opts); } export function assertQualifiedTypeIdentifier( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.QualifiedTypeIdentifier { assert("QualifiedTypeIdentifier", node, opts); } export function assertStringLiteralTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.StringLiteralTypeAnnotation { assert("StringLiteralTypeAnnotation", node, opts); } export function assertStringTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.StringTypeAnnotation { assert("StringTypeAnnotation", node, opts); } export function assertSymbolTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.SymbolTypeAnnotation { assert("SymbolTypeAnnotation", node, opts); } export function assertThisTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ThisTypeAnnotation { assert("ThisTypeAnnotation", node, opts); } export function assertTupleTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TupleTypeAnnotation { assert("TupleTypeAnnotation", node, opts); } export function assertTypeofTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeofTypeAnnotation { assert("TypeofTypeAnnotation", node, opts); } -export function assertTypeAlias(node: Object, opts?: Object = {}): void { +export function assertTypeAlias( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeAlias { assert("TypeAlias", node, opts); } -export function assertTypeAnnotation(node: Object, opts?: Object = {}): void { +export function assertTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeAnnotation { assert("TypeAnnotation", node, opts); } export function assertTypeCastExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeCastExpression { assert("TypeCastExpression", node, opts); } -export function assertTypeParameter(node: Object, opts?: Object = {}): void { +export function assertTypeParameter( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeParameter { assert("TypeParameter", node, opts); } export function assertTypeParameterDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeParameterDeclaration { assert("TypeParameterDeclaration", node, opts); } export function assertTypeParameterInstantiation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeParameterInstantiation { assert("TypeParameterInstantiation", node, opts); } export function assertUnionTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.UnionTypeAnnotation { assert("UnionTypeAnnotation", node, opts); } -export function assertVariance(node: Object, opts?: Object = {}): void { +export function assertVariance( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Variance { assert("Variance", node, opts); } export function assertVoidTypeAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.VoidTypeAnnotation { assert("VoidTypeAnnotation", node, opts); } -export function assertEnumDeclaration(node: Object, opts?: Object = {}): void { +export function assertEnumDeclaration( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumDeclaration { assert("EnumDeclaration", node, opts); } -export function assertEnumBooleanBody(node: Object, opts?: Object = {}): void { +export function assertEnumBooleanBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumBooleanBody { assert("EnumBooleanBody", node, opts); } -export function assertEnumNumberBody(node: Object, opts?: Object = {}): void { +export function assertEnumNumberBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumNumberBody { assert("EnumNumberBody", node, opts); } -export function assertEnumStringBody(node: Object, opts?: Object = {}): void { +export function assertEnumStringBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumStringBody { assert("EnumStringBody", node, opts); } -export function assertEnumSymbolBody(node: Object, opts?: Object = {}): void { +export function assertEnumSymbolBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumSymbolBody { assert("EnumSymbolBody", node, opts); } export function assertEnumBooleanMember( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumBooleanMember { assert("EnumBooleanMember", node, opts); } -export function assertEnumNumberMember(node: Object, opts?: Object = {}): void { +export function assertEnumNumberMember( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumNumberMember { assert("EnumNumberMember", node, opts); } -export function assertEnumStringMember(node: Object, opts?: Object = {}): void { +export function assertEnumStringMember( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumStringMember { assert("EnumStringMember", node, opts); } export function assertEnumDefaultedMember( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumDefaultedMember { assert("EnumDefaultedMember", node, opts); } -export function assertJSXAttribute(node: Object, opts?: Object = {}): void { +export function assertJSXAttribute( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXAttribute { assert("JSXAttribute", node, opts); } export function assertJSXClosingElement( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXClosingElement { assert("JSXClosingElement", node, opts); } -export function assertJSXElement(node: Object, opts?: Object = {}): void { +export function assertJSXElement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXElement { assert("JSXElement", node, opts); } export function assertJSXEmptyExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXEmptyExpression { assert("JSXEmptyExpression", node, opts); } export function assertJSXExpressionContainer( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXExpressionContainer { assert("JSXExpressionContainer", node, opts); } -export function assertJSXSpreadChild(node: Object, opts?: Object = {}): void { +export function assertJSXSpreadChild( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXSpreadChild { assert("JSXSpreadChild", node, opts); } -export function assertJSXIdentifier(node: Object, opts?: Object = {}): void { +export function assertJSXIdentifier( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXIdentifier { assert("JSXIdentifier", node, opts); } export function assertJSXMemberExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXMemberExpression { assert("JSXMemberExpression", node, opts); } export function assertJSXNamespacedName( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXNamespacedName { assert("JSXNamespacedName", node, opts); } export function assertJSXOpeningElement( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXOpeningElement { assert("JSXOpeningElement", node, opts); } export function assertJSXSpreadAttribute( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXSpreadAttribute { assert("JSXSpreadAttribute", node, opts); } -export function assertJSXText(node: Object, opts?: Object = {}): void { +export function assertJSXText( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXText { assert("JSXText", node, opts); } -export function assertJSXFragment(node: Object, opts?: Object = {}): void { +export function assertJSXFragment( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXFragment { assert("JSXFragment", node, opts); } export function assertJSXOpeningFragment( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXOpeningFragment { assert("JSXOpeningFragment", node, opts); } export function assertJSXClosingFragment( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSXClosingFragment { assert("JSXClosingFragment", node, opts); } -export function assertNoop(node: Object, opts?: Object = {}): void { +export function assertNoop( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Noop { assert("Noop", node, opts); } -export function assertPlaceholder(node: Object, opts?: Object = {}): void { +export function assertPlaceholder( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Placeholder { assert("Placeholder", node, opts); } export function assertV8IntrinsicIdentifier( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.V8IntrinsicIdentifier { assert("V8IntrinsicIdentifier", node, opts); } export function assertArgumentPlaceholder( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ArgumentPlaceholder { assert("ArgumentPlaceholder", node, opts); } -export function assertBindExpression(node: Object, opts?: Object = {}): void { +export function assertBindExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BindExpression { assert("BindExpression", node, opts); } -export function assertClassProperty(node: Object, opts?: Object = {}): void { +export function assertClassProperty( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassProperty { assert("ClassProperty", node, opts); } export function assertPipelineTopicExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PipelineTopicExpression { assert("PipelineTopicExpression", node, opts); } export function assertPipelineBareFunction( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PipelineBareFunction { assert("PipelineBareFunction", node, opts); } export function assertPipelinePrimaryTopicReference( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PipelinePrimaryTopicReference { assert("PipelinePrimaryTopicReference", node, opts); } export function assertClassPrivateProperty( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassPrivateProperty { assert("ClassPrivateProperty", node, opts); } export function assertClassPrivateMethod( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ClassPrivateMethod { assert("ClassPrivateMethod", node, opts); } -export function assertImportAttribute(node: Object, opts?: Object = {}): void { +export function assertImportAttribute( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ImportAttribute { assert("ImportAttribute", node, opts); } -export function assertDecorator(node: Object, opts?: Object = {}): void { +export function assertDecorator( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Decorator { assert("Decorator", node, opts); } -export function assertDoExpression(node: Object, opts?: Object = {}): void { +export function assertDoExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DoExpression { assert("DoExpression", node, opts); } export function assertExportDefaultSpecifier( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportDefaultSpecifier { assert("ExportDefaultSpecifier", node, opts); } -export function assertPrivateName(node: Object, opts?: Object = {}): void { +export function assertPrivateName( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PrivateName { assert("PrivateName", node, opts); } -export function assertRecordExpression(node: Object, opts?: Object = {}): void { +export function assertRecordExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.RecordExpression { assert("RecordExpression", node, opts); } -export function assertTupleExpression(node: Object, opts?: Object = {}): void { +export function assertTupleExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TupleExpression { assert("TupleExpression", node, opts); } -export function assertDecimalLiteral(node: Object, opts?: Object = {}): void { +export function assertDecimalLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.DecimalLiteral { assert("DecimalLiteral", node, opts); } -export function assertStaticBlock(node: Object, opts?: Object = {}): void { +export function assertStaticBlock( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.StaticBlock { assert("StaticBlock", node, opts); } export function assertTSParameterProperty( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSParameterProperty { assert("TSParameterProperty", node, opts); } export function assertTSDeclareFunction( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSDeclareFunction { assert("TSDeclareFunction", node, opts); } -export function assertTSDeclareMethod(node: Object, opts?: Object = {}): void { +export function assertTSDeclareMethod( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSDeclareMethod { assert("TSDeclareMethod", node, opts); } -export function assertTSQualifiedName(node: Object, opts?: Object = {}): void { +export function assertTSQualifiedName( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSQualifiedName { assert("TSQualifiedName", node, opts); } export function assertTSCallSignatureDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSCallSignatureDeclaration { assert("TSCallSignatureDeclaration", node, opts); } export function assertTSConstructSignatureDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSConstructSignatureDeclaration { assert("TSConstructSignatureDeclaration", node, opts); } export function assertTSPropertySignature( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSPropertySignature { assert("TSPropertySignature", node, opts); } export function assertTSMethodSignature( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSMethodSignature { assert("TSMethodSignature", node, opts); } -export function assertTSIndexSignature(node: Object, opts?: Object = {}): void { +export function assertTSIndexSignature( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSIndexSignature { assert("TSIndexSignature", node, opts); } -export function assertTSAnyKeyword(node: Object, opts?: Object = {}): void { +export function assertTSAnyKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSAnyKeyword { assert("TSAnyKeyword", node, opts); } -export function assertTSBooleanKeyword(node: Object, opts?: Object = {}): void { +export function assertTSBooleanKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSBooleanKeyword { assert("TSBooleanKeyword", node, opts); } -export function assertTSBigIntKeyword(node: Object, opts?: Object = {}): void { +export function assertTSBigIntKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSBigIntKeyword { assert("TSBigIntKeyword", node, opts); } export function assertTSIntrinsicKeyword( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSIntrinsicKeyword { assert("TSIntrinsicKeyword", node, opts); } -export function assertTSNeverKeyword(node: Object, opts?: Object = {}): void { +export function assertTSNeverKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSNeverKeyword { assert("TSNeverKeyword", node, opts); } -export function assertTSNullKeyword(node: Object, opts?: Object = {}): void { +export function assertTSNullKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSNullKeyword { assert("TSNullKeyword", node, opts); } -export function assertTSNumberKeyword(node: Object, opts?: Object = {}): void { +export function assertTSNumberKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSNumberKeyword { assert("TSNumberKeyword", node, opts); } -export function assertTSObjectKeyword(node: Object, opts?: Object = {}): void { +export function assertTSObjectKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSObjectKeyword { assert("TSObjectKeyword", node, opts); } -export function assertTSStringKeyword(node: Object, opts?: Object = {}): void { +export function assertTSStringKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSStringKeyword { assert("TSStringKeyword", node, opts); } -export function assertTSSymbolKeyword(node: Object, opts?: Object = {}): void { +export function assertTSSymbolKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSSymbolKeyword { assert("TSSymbolKeyword", node, opts); } export function assertTSUndefinedKeyword( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSUndefinedKeyword { assert("TSUndefinedKeyword", node, opts); } -export function assertTSUnknownKeyword(node: Object, opts?: Object = {}): void { +export function assertTSUnknownKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSUnknownKeyword { assert("TSUnknownKeyword", node, opts); } -export function assertTSVoidKeyword(node: Object, opts?: Object = {}): void { +export function assertTSVoidKeyword( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSVoidKeyword { assert("TSVoidKeyword", node, opts); } -export function assertTSThisType(node: Object, opts?: Object = {}): void { +export function assertTSThisType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSThisType { assert("TSThisType", node, opts); } -export function assertTSFunctionType(node: Object, opts?: Object = {}): void { +export function assertTSFunctionType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSFunctionType { assert("TSFunctionType", node, opts); } export function assertTSConstructorType( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSConstructorType { assert("TSConstructorType", node, opts); } -export function assertTSTypeReference(node: Object, opts?: Object = {}): void { +export function assertTSTypeReference( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeReference { assert("TSTypeReference", node, opts); } -export function assertTSTypePredicate(node: Object, opts?: Object = {}): void { +export function assertTSTypePredicate( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypePredicate { assert("TSTypePredicate", node, opts); } -export function assertTSTypeQuery(node: Object, opts?: Object = {}): void { +export function assertTSTypeQuery( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeQuery { assert("TSTypeQuery", node, opts); } -export function assertTSTypeLiteral(node: Object, opts?: Object = {}): void { +export function assertTSTypeLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeLiteral { assert("TSTypeLiteral", node, opts); } -export function assertTSArrayType(node: Object, opts?: Object = {}): void { +export function assertTSArrayType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSArrayType { assert("TSArrayType", node, opts); } -export function assertTSTupleType(node: Object, opts?: Object = {}): void { +export function assertTSTupleType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTupleType { assert("TSTupleType", node, opts); } -export function assertTSOptionalType(node: Object, opts?: Object = {}): void { +export function assertTSOptionalType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSOptionalType { assert("TSOptionalType", node, opts); } -export function assertTSRestType(node: Object, opts?: Object = {}): void { +export function assertTSRestType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSRestType { assert("TSRestType", node, opts); } export function assertTSNamedTupleMember( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSNamedTupleMember { assert("TSNamedTupleMember", node, opts); } -export function assertTSUnionType(node: Object, opts?: Object = {}): void { +export function assertTSUnionType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSUnionType { assert("TSUnionType", node, opts); } export function assertTSIntersectionType( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSIntersectionType { assert("TSIntersectionType", node, opts); } export function assertTSConditionalType( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSConditionalType { assert("TSConditionalType", node, opts); } -export function assertTSInferType(node: Object, opts?: Object = {}): void { +export function assertTSInferType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSInferType { assert("TSInferType", node, opts); } export function assertTSParenthesizedType( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSParenthesizedType { assert("TSParenthesizedType", node, opts); } -export function assertTSTypeOperator(node: Object, opts?: Object = {}): void { +export function assertTSTypeOperator( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeOperator { assert("TSTypeOperator", node, opts); } export function assertTSIndexedAccessType( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSIndexedAccessType { assert("TSIndexedAccessType", node, opts); } -export function assertTSMappedType(node: Object, opts?: Object = {}): void { +export function assertTSMappedType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSMappedType { assert("TSMappedType", node, opts); } -export function assertTSLiteralType(node: Object, opts?: Object = {}): void { +export function assertTSLiteralType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSLiteralType { assert("TSLiteralType", node, opts); } export function assertTSExpressionWithTypeArguments( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSExpressionWithTypeArguments { assert("TSExpressionWithTypeArguments", node, opts); } export function assertTSInterfaceDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSInterfaceDeclaration { assert("TSInterfaceDeclaration", node, opts); } -export function assertTSInterfaceBody(node: Object, opts?: Object = {}): void { +export function assertTSInterfaceBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSInterfaceBody { assert("TSInterfaceBody", node, opts); } export function assertTSTypeAliasDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeAliasDeclaration { assert("TSTypeAliasDeclaration", node, opts); } -export function assertTSAsExpression(node: Object, opts?: Object = {}): void { +export function assertTSAsExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSAsExpression { assert("TSAsExpression", node, opts); } -export function assertTSTypeAssertion(node: Object, opts?: Object = {}): void { +export function assertTSTypeAssertion( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeAssertion { assert("TSTypeAssertion", node, opts); } export function assertTSEnumDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSEnumDeclaration { assert("TSEnumDeclaration", node, opts); } -export function assertTSEnumMember(node: Object, opts?: Object = {}): void { +export function assertTSEnumMember( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSEnumMember { assert("TSEnumMember", node, opts); } export function assertTSModuleDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSModuleDeclaration { assert("TSModuleDeclaration", node, opts); } -export function assertTSModuleBlock(node: Object, opts?: Object = {}): void { +export function assertTSModuleBlock( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSModuleBlock { assert("TSModuleBlock", node, opts); } -export function assertTSImportType(node: Object, opts?: Object = {}): void { +export function assertTSImportType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSImportType { assert("TSImportType", node, opts); } export function assertTSImportEqualsDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSImportEqualsDeclaration { assert("TSImportEqualsDeclaration", node, opts); } export function assertTSExternalModuleReference( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSExternalModuleReference { assert("TSExternalModuleReference", node, opts); } export function assertTSNonNullExpression( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSNonNullExpression { assert("TSNonNullExpression", node, opts); } export function assertTSExportAssignment( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSExportAssignment { assert("TSExportAssignment", node, opts); } export function assertTSNamespaceExportDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSNamespaceExportDeclaration { assert("TSNamespaceExportDeclaration", node, opts); } -export function assertTSTypeAnnotation(node: Object, opts?: Object = {}): void { +export function assertTSTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeAnnotation { assert("TSTypeAnnotation", node, opts); } export function assertTSTypeParameterInstantiation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeParameterInstantiation { assert("TSTypeParameterInstantiation", node, opts); } export function assertTSTypeParameterDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeParameterDeclaration { assert("TSTypeParameterDeclaration", node, opts); } -export function assertTSTypeParameter(node: Object, opts?: Object = {}): void { +export function assertTSTypeParameter( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeParameter { assert("TSTypeParameter", node, opts); } -export function assertExpression(node: Object, opts?: Object = {}): void { +export function assertExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Expression { assert("Expression", node, opts); } -export function assertBinary(node: Object, opts?: Object = {}): void { +export function assertBinary( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Binary { assert("Binary", node, opts); } -export function assertScopable(node: Object, opts?: Object = {}): void { +export function assertScopable( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Scopable { assert("Scopable", node, opts); } -export function assertBlockParent(node: Object, opts?: Object = {}): void { +export function assertBlockParent( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.BlockParent { assert("BlockParent", node, opts); } -export function assertBlock(node: Object, opts?: Object = {}): void { +export function assertBlock( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Block { assert("Block", node, opts); } -export function assertStatement(node: Object, opts?: Object = {}): void { +export function assertStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Statement { assert("Statement", node, opts); } -export function assertTerminatorless(node: Object, opts?: Object = {}): void { +export function assertTerminatorless( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Terminatorless { assert("Terminatorless", node, opts); } export function assertCompletionStatement( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.CompletionStatement { assert("CompletionStatement", node, opts); } -export function assertConditional(node: Object, opts?: Object = {}): void { +export function assertConditional( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Conditional { assert("Conditional", node, opts); } -export function assertLoop(node: Object, opts?: Object = {}): void { +export function assertLoop( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Loop { assert("Loop", node, opts); } -export function assertWhile(node: Object, opts?: Object = {}): void { +export function assertWhile( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.While { assert("While", node, opts); } export function assertExpressionWrapper( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExpressionWrapper { assert("ExpressionWrapper", node, opts); } -export function assertFor(node: Object, opts?: Object = {}): void { +export function assertFor( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.For { assert("For", node, opts); } -export function assertForXStatement(node: Object, opts?: Object = {}): void { +export function assertForXStatement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ForXStatement { assert("ForXStatement", node, opts); } -export function assertFunction(node: Object, opts?: Object = {}): void { +export function assertFunction( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Function { assert("Function", node, opts); } -export function assertFunctionParent(node: Object, opts?: Object = {}): void { +export function assertFunctionParent( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FunctionParent { assert("FunctionParent", node, opts); } -export function assertPureish(node: Object, opts?: Object = {}): void { +export function assertPureish( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Pureish { assert("Pureish", node, opts); } -export function assertDeclaration(node: Object, opts?: Object = {}): void { +export function assertDeclaration( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Declaration { assert("Declaration", node, opts); } -export function assertPatternLike(node: Object, opts?: Object = {}): void { +export function assertPatternLike( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PatternLike { assert("PatternLike", node, opts); } -export function assertLVal(node: Object, opts?: Object = {}): void { +export function assertLVal( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.LVal { assert("LVal", node, opts); } -export function assertTSEntityName(node: Object, opts?: Object = {}): void { +export function assertTSEntityName( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSEntityName { assert("TSEntityName", node, opts); } -export function assertLiteral(node: Object, opts?: Object = {}): void { +export function assertLiteral( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Literal { assert("Literal", node, opts); } -export function assertImmutable(node: Object, opts?: Object = {}): void { +export function assertImmutable( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Immutable { assert("Immutable", node, opts); } export function assertUserWhitespacable( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.UserWhitespacable { assert("UserWhitespacable", node, opts); } -export function assertMethod(node: Object, opts?: Object = {}): void { +export function assertMethod( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Method { assert("Method", node, opts); } -export function assertObjectMember(node: Object, opts?: Object = {}): void { +export function assertObjectMember( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ObjectMember { assert("ObjectMember", node, opts); } -export function assertProperty(node: Object, opts?: Object = {}): void { +export function assertProperty( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Property { assert("Property", node, opts); } -export function assertUnaryLike(node: Object, opts?: Object = {}): void { +export function assertUnaryLike( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.UnaryLike { assert("UnaryLike", node, opts); } -export function assertPattern(node: Object, opts?: Object = {}): void { +export function assertPattern( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Pattern { assert("Pattern", node, opts); } -export function assertClass(node: Object, opts?: Object = {}): void { +export function assertClass( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Class { assert("Class", node, opts); } export function assertModuleDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ModuleDeclaration { assert("ModuleDeclaration", node, opts); } export function assertExportDeclaration( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ExportDeclaration { assert("ExportDeclaration", node, opts); } -export function assertModuleSpecifier(node: Object, opts?: Object = {}): void { +export function assertModuleSpecifier( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.ModuleSpecifier { assert("ModuleSpecifier", node, opts); } -export function assertFlow(node: Object, opts?: Object = {}): void { +export function assertFlow( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Flow { assert("Flow", node, opts); } -export function assertFlowType(node: Object, opts?: Object = {}): void { +export function assertFlowType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FlowType { assert("FlowType", node, opts); } export function assertFlowBaseAnnotation( - node: Object, - opts?: Object = {}, -): void { + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FlowBaseAnnotation { assert("FlowBaseAnnotation", node, opts); } -export function assertFlowDeclaration(node: Object, opts?: Object = {}): void { +export function assertFlowDeclaration( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FlowDeclaration { assert("FlowDeclaration", node, opts); } -export function assertFlowPredicate(node: Object, opts?: Object = {}): void { +export function assertFlowPredicate( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.FlowPredicate { assert("FlowPredicate", node, opts); } -export function assertEnumBody(node: Object, opts?: Object = {}): void { +export function assertEnumBody( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumBody { assert("EnumBody", node, opts); } -export function assertEnumMember(node: Object, opts?: Object = {}): void { +export function assertEnumMember( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.EnumMember { assert("EnumMember", node, opts); } -export function assertJSX(node: Object, opts?: Object = {}): void { +export function assertJSX( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.JSX { assert("JSX", node, opts); } -export function assertPrivate(node: Object, opts?: Object = {}): void { +export function assertPrivate( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Private { assert("Private", node, opts); } -export function assertTSTypeElement(node: Object, opts?: Object = {}): void { +export function assertTSTypeElement( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSTypeElement { assert("TSTypeElement", node, opts); } -export function assertTSType(node: Object, opts?: Object = {}): void { +export function assertTSType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSType { assert("TSType", node, opts); } -export function assertTSBaseType(node: Object, opts?: Object = {}): void { +export function assertTSBaseType( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TSBaseType { assert("TSBaseType", node, opts); } -export function assertNumberLiteral(node: Object, opts: Object): void { +export function assertNumberLiteral(node: any, opts: any): void { console.trace( "The node type NumberLiteral has been renamed to NumericLiteral", ); assert("NumberLiteral", node, opts); } -export function assertRegexLiteral(node: Object, opts: Object): void { +export function assertRegexLiteral(node: any, opts: any): void { console.trace("The node type RegexLiteral has been renamed to RegExpLiteral"); assert("RegexLiteral", node, opts); } -export function assertRestProperty(node: Object, opts: Object): void { +export function assertRestProperty(node: any, opts: any): void { console.trace("The node type RestProperty has been renamed to RestElement"); assert("RestProperty", node, opts); } -export function assertSpreadProperty(node: Object, opts: Object): void { +export function assertSpreadProperty(node: any, opts: any): void { console.trace( "The node type SpreadProperty has been renamed to SpreadElement", ); diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts new file mode 100755 index 0000000000..529efecdec --- /dev/null +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -0,0 +1,2518 @@ +// NOTE: This file is autogenerated. Do not modify. +// See packages/babel-types/scripts/generators/ast-types.js for script used. + +interface BaseComment { + value: string; + start: number; + end: number; + loc: SourceLocation; + type: "CommentBlock" | "CommentLine"; +} + +export interface CommentBlock extends BaseComment { + type: "CommentBlock"; +} + +export interface CommentLine extends BaseComment { + type: "CommentLine"; +} + +export type Comment = CommentBlock | CommentLine; + +export interface SourceLocation { + start: { + line: number; + column: number; + }; + + end: { + line: number; + column: number; + }; +} + +interface BaseNode { + leadingComments: ReadonlyArray | null; + innerComments: ReadonlyArray | null; + trailingComments: ReadonlyArray | null; + start: number | null; + end: number | null; + loc: SourceLocation | null; + type: Node["type"]; + extra?: Record; +} + +export type CommentTypeShorthand = "leading" | "inner" | "trailing"; + +export type Node = + | AnyTypeAnnotation + | ArgumentPlaceholder + | ArrayExpression + | ArrayPattern + | ArrayTypeAnnotation + | ArrowFunctionExpression + | AssignmentExpression + | AssignmentPattern + | AwaitExpression + | BigIntLiteral + | Binary + | BinaryExpression + | BindExpression + | Block + | BlockParent + | BlockStatement + | BooleanLiteral + | BooleanLiteralTypeAnnotation + | BooleanTypeAnnotation + | BreakStatement + | CallExpression + | CatchClause + | Class + | ClassBody + | ClassDeclaration + | ClassExpression + | ClassImplements + | ClassMethod + | ClassPrivateMethod + | ClassPrivateProperty + | ClassProperty + | CompletionStatement + | Conditional + | ConditionalExpression + | ContinueStatement + | DebuggerStatement + | DecimalLiteral + | Declaration + | DeclareClass + | DeclareExportAllDeclaration + | DeclareExportDeclaration + | DeclareFunction + | DeclareInterface + | DeclareModule + | DeclareModuleExports + | DeclareOpaqueType + | DeclareTypeAlias + | DeclareVariable + | DeclaredPredicate + | Decorator + | Directive + | DirectiveLiteral + | DoExpression + | DoWhileStatement + | EmptyStatement + | EmptyTypeAnnotation + | EnumBody + | EnumBooleanBody + | EnumBooleanMember + | EnumDeclaration + | EnumDefaultedMember + | EnumMember + | EnumNumberBody + | EnumNumberMember + | EnumStringBody + | EnumStringMember + | EnumSymbolBody + | ExistsTypeAnnotation + | ExportAllDeclaration + | ExportDeclaration + | ExportDefaultDeclaration + | ExportDefaultSpecifier + | ExportNamedDeclaration + | ExportNamespaceSpecifier + | ExportSpecifier + | Expression + | ExpressionStatement + | ExpressionWrapper + | File + | Flow + | FlowBaseAnnotation + | FlowDeclaration + | FlowPredicate + | FlowType + | For + | ForInStatement + | ForOfStatement + | ForStatement + | ForXStatement + | Function + | FunctionDeclaration + | FunctionExpression + | FunctionParent + | FunctionTypeAnnotation + | FunctionTypeParam + | GenericTypeAnnotation + | Identifier + | IfStatement + | Immutable + | Import + | ImportAttribute + | ImportDeclaration + | ImportDefaultSpecifier + | ImportNamespaceSpecifier + | ImportSpecifier + | InferredPredicate + | InterfaceDeclaration + | InterfaceExtends + | InterfaceTypeAnnotation + | InterpreterDirective + | IntersectionTypeAnnotation + | JSX + | JSXAttribute + | JSXClosingElement + | JSXClosingFragment + | JSXElement + | JSXEmptyExpression + | JSXExpressionContainer + | JSXFragment + | JSXIdentifier + | JSXMemberExpression + | JSXNamespacedName + | JSXOpeningElement + | JSXOpeningFragment + | JSXSpreadAttribute + | JSXSpreadChild + | JSXText + | LVal + | LabeledStatement + | Literal + | LogicalExpression + | Loop + | MemberExpression + | MetaProperty + | Method + | MixedTypeAnnotation + | ModuleDeclaration + | ModuleSpecifier + | NewExpression + | Noop + | NullLiteral + | NullLiteralTypeAnnotation + | NullableTypeAnnotation + | NumberLiteral + | NumberLiteralTypeAnnotation + | NumberTypeAnnotation + | NumericLiteral + | ObjectExpression + | ObjectMember + | ObjectMethod + | ObjectPattern + | ObjectProperty + | ObjectTypeAnnotation + | ObjectTypeCallProperty + | ObjectTypeIndexer + | ObjectTypeInternalSlot + | ObjectTypeProperty + | ObjectTypeSpreadProperty + | OpaqueType + | OptionalCallExpression + | OptionalMemberExpression + | ParenthesizedExpression + | Pattern + | PatternLike + | PipelineBareFunction + | PipelinePrimaryTopicReference + | PipelineTopicExpression + | Placeholder + | Private + | PrivateName + | Program + | Property + | Pureish + | QualifiedTypeIdentifier + | RecordExpression + | RegExpLiteral + | RegexLiteral + | RestElement + | RestProperty + | ReturnStatement + | Scopable + | SequenceExpression + | SpreadElement + | SpreadProperty + | Statement + | StaticBlock + | StringLiteral + | StringLiteralTypeAnnotation + | StringTypeAnnotation + | Super + | SwitchCase + | SwitchStatement + | SymbolTypeAnnotation + | TSAnyKeyword + | TSArrayType + | TSAsExpression + | TSBaseType + | TSBigIntKeyword + | TSBooleanKeyword + | TSCallSignatureDeclaration + | TSConditionalType + | TSConstructSignatureDeclaration + | TSConstructorType + | TSDeclareFunction + | TSDeclareMethod + | TSEntityName + | TSEnumDeclaration + | TSEnumMember + | TSExportAssignment + | TSExpressionWithTypeArguments + | TSExternalModuleReference + | TSFunctionType + | TSImportEqualsDeclaration + | TSImportType + | TSIndexSignature + | TSIndexedAccessType + | TSInferType + | TSInterfaceBody + | TSInterfaceDeclaration + | TSIntersectionType + | TSIntrinsicKeyword + | TSLiteralType + | TSMappedType + | TSMethodSignature + | TSModuleBlock + | TSModuleDeclaration + | TSNamedTupleMember + | TSNamespaceExportDeclaration + | TSNeverKeyword + | TSNonNullExpression + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSOptionalType + | TSParameterProperty + | TSParenthesizedType + | TSPropertySignature + | TSQualifiedName + | TSRestType + | TSStringKeyword + | TSSymbolKeyword + | TSThisType + | TSTupleType + | TSType + | TSTypeAliasDeclaration + | TSTypeAnnotation + | TSTypeAssertion + | TSTypeElement + | TSTypeLiteral + | TSTypeOperator + | TSTypeParameter + | TSTypeParameterDeclaration + | TSTypeParameterInstantiation + | TSTypePredicate + | TSTypeQuery + | TSTypeReference + | TSUndefinedKeyword + | TSUnionType + | TSUnknownKeyword + | TSVoidKeyword + | TaggedTemplateExpression + | TemplateElement + | TemplateLiteral + | Terminatorless + | ThisExpression + | ThisTypeAnnotation + | ThrowStatement + | TryStatement + | TupleExpression + | TupleTypeAnnotation + | TypeAlias + | TypeAnnotation + | TypeCastExpression + | TypeParameter + | TypeParameterDeclaration + | TypeParameterInstantiation + | TypeofTypeAnnotation + | UnaryExpression + | UnaryLike + | UnionTypeAnnotation + | UpdateExpression + | UserWhitespacable + | V8IntrinsicIdentifier + | VariableDeclaration + | VariableDeclarator + | Variance + | VoidTypeAnnotation + | While + | WhileStatement + | WithStatement + | YieldExpression; + +export interface ArrayExpression extends BaseNode { + type: "ArrayExpression"; + elements: Array; +} + +export interface AssignmentExpression extends BaseNode { + type: "AssignmentExpression"; + operator: string; + left: LVal; + right: Expression; +} + +export interface BinaryExpression extends BaseNode { + type: "BinaryExpression"; + operator: + | "+" + | "-" + | "/" + | "%" + | "*" + | "**" + | "&" + | "|" + | ">>" + | ">>>" + | "<<" + | "^" + | "==" + | "===" + | "!=" + | "!==" + | "in" + | "instanceof" + | ">" + | "<" + | ">=" + | "<="; + left: Expression | PrivateName; + right: Expression; +} + +export interface InterpreterDirective extends BaseNode { + type: "InterpreterDirective"; + value: string; +} + +export interface Directive extends BaseNode { + type: "Directive"; + value: DirectiveLiteral; +} + +export interface DirectiveLiteral extends BaseNode { + type: "DirectiveLiteral"; + value: string; +} + +export interface BlockStatement extends BaseNode { + type: "BlockStatement"; + body: Array; + directives: Array; +} + +export interface BreakStatement extends BaseNode { + type: "BreakStatement"; + label: Identifier | null; +} + +export interface CallExpression extends BaseNode { + type: "CallExpression"; + callee: Expression | V8IntrinsicIdentifier; + arguments: Array< + Expression | SpreadElement | JSXNamespacedName | ArgumentPlaceholder + >; + optional: true | false | null; + typeArguments: TypeParameterInstantiation | null; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface CatchClause extends BaseNode { + type: "CatchClause"; + param: Identifier | ArrayPattern | ObjectPattern | null; + body: BlockStatement; +} + +export interface ConditionalExpression extends BaseNode { + type: "ConditionalExpression"; + test: Expression; + consequent: Expression; + alternate: Expression; +} + +export interface ContinueStatement extends BaseNode { + type: "ContinueStatement"; + label: Identifier | null; +} + +export interface DebuggerStatement extends BaseNode { + type: "DebuggerStatement"; +} + +export interface DoWhileStatement extends BaseNode { + type: "DoWhileStatement"; + test: Expression; + body: Statement; +} + +export interface EmptyStatement extends BaseNode { + type: "EmptyStatement"; +} + +export interface ExpressionStatement extends BaseNode { + type: "ExpressionStatement"; + expression: Expression; +} + +export interface File extends BaseNode { + type: "File"; + program: Program; + comments: Array | null; + tokens: Array | null; +} + +export interface ForInStatement extends BaseNode { + type: "ForInStatement"; + left: VariableDeclaration | LVal; + right: Expression; + body: Statement; +} + +export interface ForStatement extends BaseNode { + type: "ForStatement"; + init: VariableDeclaration | Expression | null; + test: Expression | null; + update: Expression | null; + body: Statement; +} + +export interface FunctionDeclaration extends BaseNode { + type: "FunctionDeclaration"; + id: Identifier | null; + params: Array; + body: BlockStatement; + generator: boolean; + async: boolean; + declare: boolean | null; + returnType: TypeAnnotation | TSTypeAnnotation | Noop | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface FunctionExpression extends BaseNode { + type: "FunctionExpression"; + id: Identifier | null; + params: Array; + body: BlockStatement; + generator: boolean; + async: boolean; + returnType: TypeAnnotation | TSTypeAnnotation | Noop | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface Identifier extends BaseNode { + type: "Identifier"; + name: string; + decorators: Array | null; + optional: boolean | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; +} + +export interface IfStatement extends BaseNode { + type: "IfStatement"; + test: Expression; + consequent: Statement; + alternate: Statement | null; +} + +export interface LabeledStatement extends BaseNode { + type: "LabeledStatement"; + label: Identifier; + body: Statement; +} + +export interface StringLiteral extends BaseNode { + type: "StringLiteral"; + value: string; +} + +export interface NumericLiteral extends BaseNode { + type: "NumericLiteral"; + value: number; +} + +/** + * @deprecated Use `NumericLiteral` + */ +export interface NumberLiteral extends BaseNode { + type: "NumberLiteral"; + value: number; +} + +export interface NullLiteral extends BaseNode { + type: "NullLiteral"; +} + +export interface BooleanLiteral extends BaseNode { + type: "BooleanLiteral"; + value: boolean; +} + +export interface RegExpLiteral extends BaseNode { + type: "RegExpLiteral"; + pattern: string; + flags: string; +} + +/** + * @deprecated Use `RegExpLiteral` + */ +export interface RegexLiteral extends BaseNode { + type: "RegexLiteral"; + pattern: string; + flags: string; +} + +export interface LogicalExpression extends BaseNode { + type: "LogicalExpression"; + operator: "||" | "&&" | "??"; + left: Expression; + right: Expression; +} + +export interface MemberExpression extends BaseNode { + type: "MemberExpression"; + object: Expression; + property: Expression | Identifier | PrivateName; + computed: boolean; + optional: true | false | null; +} + +export interface NewExpression extends BaseNode { + type: "NewExpression"; + callee: Expression | V8IntrinsicIdentifier; + arguments: Array< + Expression | SpreadElement | JSXNamespacedName | ArgumentPlaceholder + >; + optional: true | false | null; + typeArguments: TypeParameterInstantiation | null; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface Program extends BaseNode { + type: "Program"; + body: Array; + directives: Array; + sourceType: "script" | "module"; + interpreter: InterpreterDirective | null; + sourceFile: string; +} + +export interface ObjectExpression extends BaseNode { + type: "ObjectExpression"; + properties: Array; +} + +export interface ObjectMethod extends BaseNode { + type: "ObjectMethod"; + kind: "method" | "get" | "set"; + key: Expression | Identifier | StringLiteral | NumericLiteral; + params: Array; + body: BlockStatement; + computed: boolean; + generator: boolean; + async: boolean; + decorators: Array | null; + returnType: TypeAnnotation | TSTypeAnnotation | Noop | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface ObjectProperty extends BaseNode { + type: "ObjectProperty"; + key: Expression | Identifier | StringLiteral | NumericLiteral; + value: Expression | PatternLike; + computed: boolean; + shorthand: boolean; + decorators: Array | null; +} + +export interface RestElement extends BaseNode { + type: "RestElement"; + argument: LVal; + decorators: Array | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; +} + +/** + * @deprecated Use `RestElement` + */ +export interface RestProperty extends BaseNode { + type: "RestProperty"; + argument: LVal; + decorators: Array | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; +} + +export interface ReturnStatement extends BaseNode { + type: "ReturnStatement"; + argument: Expression | null; +} + +export interface SequenceExpression extends BaseNode { + type: "SequenceExpression"; + expressions: Array; +} + +export interface ParenthesizedExpression extends BaseNode { + type: "ParenthesizedExpression"; + expression: Expression; +} + +export interface SwitchCase extends BaseNode { + type: "SwitchCase"; + test: Expression | null; + consequent: Array; +} + +export interface SwitchStatement extends BaseNode { + type: "SwitchStatement"; + discriminant: Expression; + cases: Array; +} + +export interface ThisExpression extends BaseNode { + type: "ThisExpression"; +} + +export interface ThrowStatement extends BaseNode { + type: "ThrowStatement"; + argument: Expression; +} + +export interface TryStatement extends BaseNode { + type: "TryStatement"; + block: BlockStatement; + handler: CatchClause | null; + finalizer: BlockStatement | null; +} + +export interface UnaryExpression extends BaseNode { + type: "UnaryExpression"; + operator: "void" | "throw" | "delete" | "!" | "+" | "-" | "~" | "typeof"; + argument: Expression; + prefix: boolean; +} + +export interface UpdateExpression extends BaseNode { + type: "UpdateExpression"; + operator: "++" | "--"; + argument: Expression; + prefix: boolean; +} + +export interface VariableDeclaration extends BaseNode { + type: "VariableDeclaration"; + kind: "var" | "let" | "const"; + declarations: Array; + declare: boolean | null; +} + +export interface VariableDeclarator extends BaseNode { + type: "VariableDeclarator"; + id: LVal; + init: Expression | null; + definite: boolean | null; +} + +export interface WhileStatement extends BaseNode { + type: "WhileStatement"; + test: Expression; + body: Statement; +} + +export interface WithStatement extends BaseNode { + type: "WithStatement"; + object: Expression; + body: Statement; +} + +export interface AssignmentPattern extends BaseNode { + type: "AssignmentPattern"; + left: Identifier | ObjectPattern | ArrayPattern | MemberExpression; + right: Expression; + decorators: Array | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; +} + +export interface ArrayPattern extends BaseNode { + type: "ArrayPattern"; + elements: Array; + decorators: Array | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; +} + +export interface ArrowFunctionExpression extends BaseNode { + type: "ArrowFunctionExpression"; + params: Array; + body: BlockStatement | Expression; + async: boolean; + expression: boolean; + generator: boolean; + returnType: TypeAnnotation | TSTypeAnnotation | Noop | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface ClassBody extends BaseNode { + type: "ClassBody"; + body: Array< + | ClassMethod + | ClassPrivateMethod + | ClassProperty + | ClassPrivateProperty + | TSDeclareMethod + | TSIndexSignature + >; +} + +export interface ClassExpression extends BaseNode { + type: "ClassExpression"; + id: Identifier | null; + superClass: Expression | null; + body: ClassBody; + decorators: Array | null; + implements: Array | null; + mixins: InterfaceExtends | null; + superTypeParameters: + | TypeParameterInstantiation + | TSTypeParameterInstantiation + | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface ClassDeclaration extends BaseNode { + type: "ClassDeclaration"; + id: Identifier; + superClass: Expression | null; + body: ClassBody; + decorators: Array | null; + abstract: boolean | null; + declare: boolean | null; + implements: Array | null; + mixins: InterfaceExtends | null; + superTypeParameters: + | TypeParameterInstantiation + | TSTypeParameterInstantiation + | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface ExportAllDeclaration extends BaseNode { + type: "ExportAllDeclaration"; + source: StringLiteral; + assertions: ImportAttribute | null; +} + +export interface ExportDefaultDeclaration extends BaseNode { + type: "ExportDefaultDeclaration"; + declaration: + | FunctionDeclaration + | TSDeclareFunction + | ClassDeclaration + | Expression; +} + +export interface ExportNamedDeclaration extends BaseNode { + type: "ExportNamedDeclaration"; + declaration: Declaration | null; + specifiers: Array< + ExportSpecifier | ExportDefaultSpecifier | ExportNamespaceSpecifier + >; + source: StringLiteral | null; + assertions: ImportAttribute | null; + exportKind: "type" | "value" | null; +} + +export interface ExportSpecifier extends BaseNode { + type: "ExportSpecifier"; + local: Identifier; + exported: Identifier | StringLiteral; +} + +export interface ForOfStatement extends BaseNode { + type: "ForOfStatement"; + left: VariableDeclaration | LVal; + right: Expression; + body: Statement; + await: boolean; +} + +export interface ImportDeclaration extends BaseNode { + type: "ImportDeclaration"; + specifiers: Array< + ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier + >; + source: StringLiteral; + assertions: ImportAttribute | null; + importKind: "type" | "typeof" | "value" | null; +} + +export interface ImportDefaultSpecifier extends BaseNode { + type: "ImportDefaultSpecifier"; + local: Identifier; +} + +export interface ImportNamespaceSpecifier extends BaseNode { + type: "ImportNamespaceSpecifier"; + local: Identifier; +} + +export interface ImportSpecifier extends BaseNode { + type: "ImportSpecifier"; + local: Identifier; + imported: Identifier | StringLiteral; + importKind: "type" | "typeof" | null; +} + +export interface MetaProperty extends BaseNode { + type: "MetaProperty"; + meta: Identifier; + property: Identifier; +} + +export interface ClassMethod extends BaseNode { + type: "ClassMethod"; + kind: "get" | "set" | "method" | "constructor"; + key: Identifier | StringLiteral | NumericLiteral | Expression; + params: Array; + body: BlockStatement; + computed: boolean; + static: boolean; + generator: boolean; + async: boolean; + abstract: boolean | null; + access: "public" | "private" | "protected" | null; + accessibility: "public" | "private" | "protected" | null; + decorators: Array | null; + optional: boolean | null; + returnType: TypeAnnotation | TSTypeAnnotation | Noop | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface ObjectPattern extends BaseNode { + type: "ObjectPattern"; + properties: Array; + decorators: Array | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; +} + +export interface SpreadElement extends BaseNode { + type: "SpreadElement"; + argument: Expression; +} + +/** + * @deprecated Use `SpreadElement` + */ +export interface SpreadProperty extends BaseNode { + type: "SpreadProperty"; + argument: Expression; +} + +export interface Super extends BaseNode { + type: "Super"; +} + +export interface TaggedTemplateExpression extends BaseNode { + type: "TaggedTemplateExpression"; + tag: Expression; + quasi: TemplateLiteral; + typeParameters: + | TypeParameterInstantiation + | TSTypeParameterInstantiation + | null; +} + +export interface TemplateElement extends BaseNode { + type: "TemplateElement"; + value: { raw: string; cooked?: string }; + tail: boolean; +} + +export interface TemplateLiteral extends BaseNode { + type: "TemplateLiteral"; + quasis: Array; + expressions: Array; +} + +export interface YieldExpression extends BaseNode { + type: "YieldExpression"; + argument: Expression | null; + delegate: boolean; +} + +export interface AwaitExpression extends BaseNode { + type: "AwaitExpression"; + argument: Expression; +} + +export interface Import extends BaseNode { + type: "Import"; +} + +export interface BigIntLiteral extends BaseNode { + type: "BigIntLiteral"; + value: string; +} + +export interface ExportNamespaceSpecifier extends BaseNode { + type: "ExportNamespaceSpecifier"; + exported: Identifier; +} + +export interface OptionalMemberExpression extends BaseNode { + type: "OptionalMemberExpression"; + object: Expression; + property: Expression | Identifier; + computed: boolean; + optional: boolean; +} + +export interface OptionalCallExpression extends BaseNode { + type: "OptionalCallExpression"; + callee: Expression; + arguments: Array< + Expression | SpreadElement | JSXNamespacedName | ArgumentPlaceholder + >; + optional: boolean; + typeArguments: TypeParameterInstantiation | null; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface AnyTypeAnnotation extends BaseNode { + type: "AnyTypeAnnotation"; +} + +export interface ArrayTypeAnnotation extends BaseNode { + type: "ArrayTypeAnnotation"; + elementType: FlowType; +} + +export interface BooleanTypeAnnotation extends BaseNode { + type: "BooleanTypeAnnotation"; +} + +export interface BooleanLiteralTypeAnnotation extends BaseNode { + type: "BooleanLiteralTypeAnnotation"; + value: boolean; +} + +export interface NullLiteralTypeAnnotation extends BaseNode { + type: "NullLiteralTypeAnnotation"; +} + +export interface ClassImplements extends BaseNode { + type: "ClassImplements"; + id: Identifier; + typeParameters: TypeParameterInstantiation | null; +} + +export interface DeclareClass extends BaseNode { + type: "DeclareClass"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + extends: Array | null; + body: ObjectTypeAnnotation; + implements: Array | null; + mixins: Array | null; +} + +export interface DeclareFunction extends BaseNode { + type: "DeclareFunction"; + id: Identifier; + predicate: DeclaredPredicate | null; +} + +export interface DeclareInterface extends BaseNode { + type: "DeclareInterface"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + extends: Array | null; + body: ObjectTypeAnnotation; + implements: Array | null; + mixins: Array | null; +} + +export interface DeclareModule extends BaseNode { + type: "DeclareModule"; + id: Identifier | StringLiteral; + body: BlockStatement; + kind: "CommonJS" | "ES" | null; +} + +export interface DeclareModuleExports extends BaseNode { + type: "DeclareModuleExports"; + typeAnnotation: TypeAnnotation; +} + +export interface DeclareTypeAlias extends BaseNode { + type: "DeclareTypeAlias"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + right: FlowType; +} + +export interface DeclareOpaqueType extends BaseNode { + type: "DeclareOpaqueType"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + supertype: FlowType | null; +} + +export interface DeclareVariable extends BaseNode { + type: "DeclareVariable"; + id: Identifier; +} + +export interface DeclareExportDeclaration extends BaseNode { + type: "DeclareExportDeclaration"; + declaration: Flow | null; + specifiers: Array | null; + source: StringLiteral | null; + default: boolean | null; +} + +export interface DeclareExportAllDeclaration extends BaseNode { + type: "DeclareExportAllDeclaration"; + source: StringLiteral; + exportKind: "type" | "value" | null; +} + +export interface DeclaredPredicate extends BaseNode { + type: "DeclaredPredicate"; + value: Flow; +} + +export interface ExistsTypeAnnotation extends BaseNode { + type: "ExistsTypeAnnotation"; +} + +export interface FunctionTypeAnnotation extends BaseNode { + type: "FunctionTypeAnnotation"; + typeParameters: TypeParameterDeclaration | null; + params: Array; + rest: FunctionTypeParam | null; + returnType: FlowType; +} + +export interface FunctionTypeParam extends BaseNode { + type: "FunctionTypeParam"; + name: Identifier | null; + typeAnnotation: FlowType; + optional: boolean | null; +} + +export interface GenericTypeAnnotation extends BaseNode { + type: "GenericTypeAnnotation"; + id: Identifier | QualifiedTypeIdentifier; + typeParameters: TypeParameterInstantiation | null; +} + +export interface InferredPredicate extends BaseNode { + type: "InferredPredicate"; +} + +export interface InterfaceExtends extends BaseNode { + type: "InterfaceExtends"; + id: Identifier | QualifiedTypeIdentifier; + typeParameters: TypeParameterInstantiation | null; +} + +export interface InterfaceDeclaration extends BaseNode { + type: "InterfaceDeclaration"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + extends: Array | null; + body: ObjectTypeAnnotation; + implements: Array | null; + mixins: Array | null; +} + +export interface InterfaceTypeAnnotation extends BaseNode { + type: "InterfaceTypeAnnotation"; + extends: Array | null; + body: ObjectTypeAnnotation; +} + +export interface IntersectionTypeAnnotation extends BaseNode { + type: "IntersectionTypeAnnotation"; + types: Array; +} + +export interface MixedTypeAnnotation extends BaseNode { + type: "MixedTypeAnnotation"; +} + +export interface EmptyTypeAnnotation extends BaseNode { + type: "EmptyTypeAnnotation"; +} + +export interface NullableTypeAnnotation extends BaseNode { + type: "NullableTypeAnnotation"; + typeAnnotation: FlowType; +} + +export interface NumberLiteralTypeAnnotation extends BaseNode { + type: "NumberLiteralTypeAnnotation"; + value: number; +} + +export interface NumberTypeAnnotation extends BaseNode { + type: "NumberTypeAnnotation"; +} + +export interface ObjectTypeAnnotation extends BaseNode { + type: "ObjectTypeAnnotation"; + properties: Array; + indexers: Array | null; + callProperties: Array | null; + internalSlots: Array | null; + exact: boolean; + inexact: boolean | null; +} + +export interface ObjectTypeInternalSlot extends BaseNode { + type: "ObjectTypeInternalSlot"; + id: Identifier; + value: FlowType; + optional: boolean; + static: boolean; + method: boolean; +} + +export interface ObjectTypeCallProperty extends BaseNode { + type: "ObjectTypeCallProperty"; + value: FlowType; + static: boolean; +} + +export interface ObjectTypeIndexer extends BaseNode { + type: "ObjectTypeIndexer"; + id: Identifier | null; + key: FlowType; + value: FlowType; + variance: Variance | null; + static: boolean; +} + +export interface ObjectTypeProperty extends BaseNode { + type: "ObjectTypeProperty"; + key: Identifier | StringLiteral; + value: FlowType; + variance: Variance | null; + kind: "init" | "get" | "set"; + optional: boolean; + proto: boolean; + static: boolean; +} + +export interface ObjectTypeSpreadProperty extends BaseNode { + type: "ObjectTypeSpreadProperty"; + argument: FlowType; +} + +export interface OpaqueType extends BaseNode { + type: "OpaqueType"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + supertype: FlowType | null; + impltype: FlowType; +} + +export interface QualifiedTypeIdentifier extends BaseNode { + type: "QualifiedTypeIdentifier"; + id: Identifier; + qualification: Identifier | QualifiedTypeIdentifier; +} + +export interface StringLiteralTypeAnnotation extends BaseNode { + type: "StringLiteralTypeAnnotation"; + value: string; +} + +export interface StringTypeAnnotation extends BaseNode { + type: "StringTypeAnnotation"; +} + +export interface SymbolTypeAnnotation extends BaseNode { + type: "SymbolTypeAnnotation"; +} + +export interface ThisTypeAnnotation extends BaseNode { + type: "ThisTypeAnnotation"; +} + +export interface TupleTypeAnnotation extends BaseNode { + type: "TupleTypeAnnotation"; + types: Array; +} + +export interface TypeofTypeAnnotation extends BaseNode { + type: "TypeofTypeAnnotation"; + argument: FlowType; +} + +export interface TypeAlias extends BaseNode { + type: "TypeAlias"; + id: Identifier; + typeParameters: TypeParameterDeclaration | null; + right: FlowType; +} + +export interface TypeAnnotation extends BaseNode { + type: "TypeAnnotation"; + typeAnnotation: FlowType; +} + +export interface TypeCastExpression extends BaseNode { + type: "TypeCastExpression"; + expression: Expression; + typeAnnotation: TypeAnnotation; +} + +export interface TypeParameter extends BaseNode { + type: "TypeParameter"; + bound: TypeAnnotation | null; + default: FlowType | null; + variance: Variance | null; + name: string; +} + +export interface TypeParameterDeclaration extends BaseNode { + type: "TypeParameterDeclaration"; + params: Array; +} + +export interface TypeParameterInstantiation extends BaseNode { + type: "TypeParameterInstantiation"; + params: Array; +} + +export interface UnionTypeAnnotation extends BaseNode { + type: "UnionTypeAnnotation"; + types: Array; +} + +export interface Variance extends BaseNode { + type: "Variance"; + kind: "minus" | "plus"; +} + +export interface VoidTypeAnnotation extends BaseNode { + type: "VoidTypeAnnotation"; +} + +export interface EnumDeclaration extends BaseNode { + type: "EnumDeclaration"; + id: Identifier; + body: EnumBooleanBody | EnumNumberBody | EnumStringBody | EnumSymbolBody; +} + +export interface EnumBooleanBody extends BaseNode { + type: "EnumBooleanBody"; + members: Array; + explicit: boolean; +} + +export interface EnumNumberBody extends BaseNode { + type: "EnumNumberBody"; + members: Array; + explicit: boolean; +} + +export interface EnumStringBody extends BaseNode { + type: "EnumStringBody"; + members: Array; + explicit: boolean; +} + +export interface EnumSymbolBody extends BaseNode { + type: "EnumSymbolBody"; + members: Array; +} + +export interface EnumBooleanMember extends BaseNode { + type: "EnumBooleanMember"; + id: Identifier; + init: BooleanLiteral; +} + +export interface EnumNumberMember extends BaseNode { + type: "EnumNumberMember"; + id: Identifier; + init: NumericLiteral; +} + +export interface EnumStringMember extends BaseNode { + type: "EnumStringMember"; + id: Identifier; + init: StringLiteral; +} + +export interface EnumDefaultedMember extends BaseNode { + type: "EnumDefaultedMember"; + id: Identifier; +} + +export interface JSXAttribute extends BaseNode { + type: "JSXAttribute"; + name: JSXIdentifier | JSXNamespacedName; + value: + | JSXElement + | JSXFragment + | StringLiteral + | JSXExpressionContainer + | null; +} + +export interface JSXClosingElement extends BaseNode { + type: "JSXClosingElement"; + name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName; +} + +export interface JSXElement extends BaseNode { + type: "JSXElement"; + openingElement: JSXOpeningElement; + closingElement: JSXClosingElement | null; + children: Array< + JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment + >; + selfClosing: boolean | null; +} + +export interface JSXEmptyExpression extends BaseNode { + type: "JSXEmptyExpression"; +} + +export interface JSXExpressionContainer extends BaseNode { + type: "JSXExpressionContainer"; + expression: Expression | JSXEmptyExpression; +} + +export interface JSXSpreadChild extends BaseNode { + type: "JSXSpreadChild"; + expression: Expression; +} + +export interface JSXIdentifier extends BaseNode { + type: "JSXIdentifier"; + name: string; +} + +export interface JSXMemberExpression extends BaseNode { + type: "JSXMemberExpression"; + object: JSXMemberExpression | JSXIdentifier; + property: JSXIdentifier; +} + +export interface JSXNamespacedName extends BaseNode { + type: "JSXNamespacedName"; + namespace: JSXIdentifier; + name: JSXIdentifier; +} + +export interface JSXOpeningElement extends BaseNode { + type: "JSXOpeningElement"; + name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName; + attributes: Array; + selfClosing: boolean; + typeParameters: + | TypeParameterInstantiation + | TSTypeParameterInstantiation + | null; +} + +export interface JSXSpreadAttribute extends BaseNode { + type: "JSXSpreadAttribute"; + argument: Expression; +} + +export interface JSXText extends BaseNode { + type: "JSXText"; + value: string; +} + +export interface JSXFragment extends BaseNode { + type: "JSXFragment"; + openingFragment: JSXOpeningFragment; + closingFragment: JSXClosingFragment; + children: Array< + JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment + >; +} + +export interface JSXOpeningFragment extends BaseNode { + type: "JSXOpeningFragment"; +} + +export interface JSXClosingFragment extends BaseNode { + type: "JSXClosingFragment"; +} + +export interface Noop extends BaseNode { + type: "Noop"; +} + +export interface Placeholder extends BaseNode { + type: "Placeholder"; + expectedNode: + | "Identifier" + | "StringLiteral" + | "Expression" + | "Statement" + | "Declaration" + | "BlockStatement" + | "ClassBody" + | "Pattern"; + name: Identifier; +} + +export interface V8IntrinsicIdentifier extends BaseNode { + type: "V8IntrinsicIdentifier"; + name: string; +} + +export interface ArgumentPlaceholder extends BaseNode { + type: "ArgumentPlaceholder"; +} + +export interface BindExpression extends BaseNode { + type: "BindExpression"; + object: Expression; + callee: Expression; +} + +export interface ClassProperty extends BaseNode { + type: "ClassProperty"; + key: Identifier | StringLiteral | NumericLiteral | Expression; + value: Expression | null; + typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop | null; + decorators: Array | null; + computed: boolean; + static: boolean; + abstract: boolean | null; + accessibility: "public" | "private" | "protected" | null; + declare: boolean | null; + definite: boolean | null; + optional: boolean | null; + readonly: boolean | null; +} + +export interface PipelineTopicExpression extends BaseNode { + type: "PipelineTopicExpression"; + expression: Expression; +} + +export interface PipelineBareFunction extends BaseNode { + type: "PipelineBareFunction"; + callee: Expression; +} + +export interface PipelinePrimaryTopicReference extends BaseNode { + type: "PipelinePrimaryTopicReference"; +} + +export interface ClassPrivateProperty extends BaseNode { + type: "ClassPrivateProperty"; + key: PrivateName; + value: Expression | null; + decorators: Array | null; + static: any; +} + +export interface ClassPrivateMethod extends BaseNode { + type: "ClassPrivateMethod"; + kind: "get" | "set" | "method" | "constructor"; + key: PrivateName; + params: Array; + body: BlockStatement; + static: boolean; + abstract: boolean | null; + access: "public" | "private" | "protected" | null; + accessibility: "public" | "private" | "protected" | null; + async: boolean; + computed: boolean; + decorators: Array | null; + generator: boolean; + optional: boolean | null; + returnType: TypeAnnotation | TSTypeAnnotation | Noop | null; + typeParameters: + | TypeParameterDeclaration + | TSTypeParameterDeclaration + | Noop + | null; +} + +export interface ImportAttribute extends BaseNode { + type: "ImportAttribute"; + key: Identifier | StringLiteral; + value: StringLiteral; +} + +export interface Decorator extends BaseNode { + type: "Decorator"; + expression: Expression; +} + +export interface DoExpression extends BaseNode { + type: "DoExpression"; + body: BlockStatement; +} + +export interface ExportDefaultSpecifier extends BaseNode { + type: "ExportDefaultSpecifier"; + exported: Identifier; +} + +export interface PrivateName extends BaseNode { + type: "PrivateName"; + id: Identifier; +} + +export interface RecordExpression extends BaseNode { + type: "RecordExpression"; + properties: Array; +} + +export interface TupleExpression extends BaseNode { + type: "TupleExpression"; + elements: Array; +} + +export interface DecimalLiteral extends BaseNode { + type: "DecimalLiteral"; + value: string; +} + +export interface StaticBlock extends BaseNode { + type: "StaticBlock"; + body: Array; +} + +export interface TSParameterProperty extends BaseNode { + type: "TSParameterProperty"; + parameter: Identifier | AssignmentPattern; + accessibility: "public" | "private" | "protected" | null; + readonly: boolean | null; +} + +export interface TSDeclareFunction extends BaseNode { + type: "TSDeclareFunction"; + id: Identifier | null; + typeParameters: TSTypeParameterDeclaration | Noop | null; + params: Array; + returnType: TSTypeAnnotation | Noop | null; + async: boolean; + declare: boolean | null; + generator: boolean; +} + +export interface TSDeclareMethod extends BaseNode { + type: "TSDeclareMethod"; + decorators: Array | null; + key: Identifier | StringLiteral | NumericLiteral | Expression; + typeParameters: TSTypeParameterDeclaration | Noop | null; + params: Array; + returnType: TSTypeAnnotation | Noop | null; + abstract: boolean | null; + access: "public" | "private" | "protected" | null; + accessibility: "public" | "private" | "protected" | null; + async: boolean; + computed: boolean; + generator: boolean; + kind: "get" | "set" | "method" | "constructor"; + optional: boolean | null; + static: boolean; +} + +export interface TSQualifiedName extends BaseNode { + type: "TSQualifiedName"; + left: TSEntityName; + right: Identifier; +} + +export interface TSCallSignatureDeclaration extends BaseNode { + type: "TSCallSignatureDeclaration"; + typeParameters: TSTypeParameterDeclaration | null; + parameters: Array; + typeAnnotation: TSTypeAnnotation | null; +} + +export interface TSConstructSignatureDeclaration extends BaseNode { + type: "TSConstructSignatureDeclaration"; + typeParameters: TSTypeParameterDeclaration | null; + parameters: Array; + typeAnnotation: TSTypeAnnotation | null; +} + +export interface TSPropertySignature extends BaseNode { + type: "TSPropertySignature"; + key: Expression; + typeAnnotation: TSTypeAnnotation | null; + initializer: Expression | null; + computed: boolean | null; + optional: boolean | null; + readonly: boolean | null; +} + +export interface TSMethodSignature extends BaseNode { + type: "TSMethodSignature"; + key: Expression; + typeParameters: TSTypeParameterDeclaration | null; + parameters: Array; + typeAnnotation: TSTypeAnnotation | null; + computed: boolean | null; + optional: boolean | null; +} + +export interface TSIndexSignature extends BaseNode { + type: "TSIndexSignature"; + parameters: Array; + typeAnnotation: TSTypeAnnotation | null; + readonly: boolean | null; +} + +export interface TSAnyKeyword extends BaseNode { + type: "TSAnyKeyword"; +} + +export interface TSBooleanKeyword extends BaseNode { + type: "TSBooleanKeyword"; +} + +export interface TSBigIntKeyword extends BaseNode { + type: "TSBigIntKeyword"; +} + +export interface TSIntrinsicKeyword extends BaseNode { + type: "TSIntrinsicKeyword"; +} + +export interface TSNeverKeyword extends BaseNode { + type: "TSNeverKeyword"; +} + +export interface TSNullKeyword extends BaseNode { + type: "TSNullKeyword"; +} + +export interface TSNumberKeyword extends BaseNode { + type: "TSNumberKeyword"; +} + +export interface TSObjectKeyword extends BaseNode { + type: "TSObjectKeyword"; +} + +export interface TSStringKeyword extends BaseNode { + type: "TSStringKeyword"; +} + +export interface TSSymbolKeyword extends BaseNode { + type: "TSSymbolKeyword"; +} + +export interface TSUndefinedKeyword extends BaseNode { + type: "TSUndefinedKeyword"; +} + +export interface TSUnknownKeyword extends BaseNode { + type: "TSUnknownKeyword"; +} + +export interface TSVoidKeyword extends BaseNode { + type: "TSVoidKeyword"; +} + +export interface TSThisType extends BaseNode { + type: "TSThisType"; +} + +export interface TSFunctionType extends BaseNode { + type: "TSFunctionType"; + typeParameters: TSTypeParameterDeclaration | null; + parameters: Array; + typeAnnotation: TSTypeAnnotation | null; +} + +export interface TSConstructorType extends BaseNode { + type: "TSConstructorType"; + typeParameters: TSTypeParameterDeclaration | null; + parameters: Array; + typeAnnotation: TSTypeAnnotation | null; +} + +export interface TSTypeReference extends BaseNode { + type: "TSTypeReference"; + typeName: TSEntityName; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface TSTypePredicate extends BaseNode { + type: "TSTypePredicate"; + parameterName: Identifier | TSThisType; + typeAnnotation: TSTypeAnnotation | null; + asserts: boolean | null; +} + +export interface TSTypeQuery extends BaseNode { + type: "TSTypeQuery"; + exprName: TSEntityName | TSImportType; +} + +export interface TSTypeLiteral extends BaseNode { + type: "TSTypeLiteral"; + members: Array; +} + +export interface TSArrayType extends BaseNode { + type: "TSArrayType"; + elementType: TSType; +} + +export interface TSTupleType extends BaseNode { + type: "TSTupleType"; + elementTypes: Array; +} + +export interface TSOptionalType extends BaseNode { + type: "TSOptionalType"; + typeAnnotation: TSType; +} + +export interface TSRestType extends BaseNode { + type: "TSRestType"; + typeAnnotation: TSType; +} + +export interface TSNamedTupleMember extends BaseNode { + type: "TSNamedTupleMember"; + label: Identifier; + elementType: TSType; + optional: boolean; +} + +export interface TSUnionType extends BaseNode { + type: "TSUnionType"; + types: Array; +} + +export interface TSIntersectionType extends BaseNode { + type: "TSIntersectionType"; + types: Array; +} + +export interface TSConditionalType extends BaseNode { + type: "TSConditionalType"; + checkType: TSType; + extendsType: TSType; + trueType: TSType; + falseType: TSType; +} + +export interface TSInferType extends BaseNode { + type: "TSInferType"; + typeParameter: TSTypeParameter; +} + +export interface TSParenthesizedType extends BaseNode { + type: "TSParenthesizedType"; + typeAnnotation: TSType; +} + +export interface TSTypeOperator extends BaseNode { + type: "TSTypeOperator"; + typeAnnotation: TSType; + operator: string; +} + +export interface TSIndexedAccessType extends BaseNode { + type: "TSIndexedAccessType"; + objectType: TSType; + indexType: TSType; +} + +export interface TSMappedType extends BaseNode { + type: "TSMappedType"; + typeParameter: TSTypeParameter; + typeAnnotation: TSType | null; + nameType: TSType | null; + optional: boolean | null; + readonly: boolean | null; +} + +export interface TSLiteralType extends BaseNode { + type: "TSLiteralType"; + literal: NumericLiteral | StringLiteral | BooleanLiteral | BigIntLiteral; +} + +export interface TSExpressionWithTypeArguments extends BaseNode { + type: "TSExpressionWithTypeArguments"; + expression: TSEntityName; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface TSInterfaceDeclaration extends BaseNode { + type: "TSInterfaceDeclaration"; + id: Identifier; + typeParameters: TSTypeParameterDeclaration | null; + extends: Array | null; + body: TSInterfaceBody; + declare: boolean | null; +} + +export interface TSInterfaceBody extends BaseNode { + type: "TSInterfaceBody"; + body: Array; +} + +export interface TSTypeAliasDeclaration extends BaseNode { + type: "TSTypeAliasDeclaration"; + id: Identifier; + typeParameters: TSTypeParameterDeclaration | null; + typeAnnotation: TSType; + declare: boolean | null; +} + +export interface TSAsExpression extends BaseNode { + type: "TSAsExpression"; + expression: Expression; + typeAnnotation: TSType; +} + +export interface TSTypeAssertion extends BaseNode { + type: "TSTypeAssertion"; + typeAnnotation: TSType; + expression: Expression; +} + +export interface TSEnumDeclaration extends BaseNode { + type: "TSEnumDeclaration"; + id: Identifier; + members: Array; + const: boolean | null; + declare: boolean | null; + initializer: Expression | null; +} + +export interface TSEnumMember extends BaseNode { + type: "TSEnumMember"; + id: Identifier | StringLiteral; + initializer: Expression | null; +} + +export interface TSModuleDeclaration extends BaseNode { + type: "TSModuleDeclaration"; + id: Identifier | StringLiteral; + body: TSModuleBlock | TSModuleDeclaration; + declare: boolean | null; + global: boolean | null; +} + +export interface TSModuleBlock extends BaseNode { + type: "TSModuleBlock"; + body: Array; +} + +export interface TSImportType extends BaseNode { + type: "TSImportType"; + argument: StringLiteral; + qualifier: TSEntityName | null; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface TSImportEqualsDeclaration extends BaseNode { + type: "TSImportEqualsDeclaration"; + id: Identifier; + moduleReference: TSEntityName | TSExternalModuleReference; + isExport: boolean; +} + +export interface TSExternalModuleReference extends BaseNode { + type: "TSExternalModuleReference"; + expression: StringLiteral; +} + +export interface TSNonNullExpression extends BaseNode { + type: "TSNonNullExpression"; + expression: Expression; +} + +export interface TSExportAssignment extends BaseNode { + type: "TSExportAssignment"; + expression: Expression; +} + +export interface TSNamespaceExportDeclaration extends BaseNode { + type: "TSNamespaceExportDeclaration"; + id: Identifier; +} + +export interface TSTypeAnnotation extends BaseNode { + type: "TSTypeAnnotation"; + typeAnnotation: TSType; +} + +export interface TSTypeParameterInstantiation extends BaseNode { + type: "TSTypeParameterInstantiation"; + params: Array; +} + +export interface TSTypeParameterDeclaration extends BaseNode { + type: "TSTypeParameterDeclaration"; + params: Array; +} + +export interface TSTypeParameter extends BaseNode { + type: "TSTypeParameter"; + constraint: TSType | null; + default: TSType | null; + name: string; +} + +export type Expression = + | ArrayExpression + | AssignmentExpression + | BinaryExpression + | CallExpression + | ConditionalExpression + | FunctionExpression + | Identifier + | StringLiteral + | NumericLiteral + | NullLiteral + | BooleanLiteral + | RegExpLiteral + | LogicalExpression + | MemberExpression + | NewExpression + | ObjectExpression + | SequenceExpression + | ParenthesizedExpression + | ThisExpression + | UnaryExpression + | UpdateExpression + | ArrowFunctionExpression + | ClassExpression + | MetaProperty + | Super + | TaggedTemplateExpression + | TemplateLiteral + | YieldExpression + | AwaitExpression + | Import + | BigIntLiteral + | OptionalMemberExpression + | OptionalCallExpression + | TypeCastExpression + | JSXElement + | JSXFragment + | BindExpression + | PipelinePrimaryTopicReference + | DoExpression + | RecordExpression + | TupleExpression + | DecimalLiteral + | TSAsExpression + | TSTypeAssertion + | TSNonNullExpression; +export type Binary = BinaryExpression | LogicalExpression; +export type Scopable = + | BlockStatement + | CatchClause + | DoWhileStatement + | ForInStatement + | ForStatement + | FunctionDeclaration + | FunctionExpression + | Program + | ObjectMethod + | SwitchStatement + | WhileStatement + | ArrowFunctionExpression + | ClassExpression + | ClassDeclaration + | ForOfStatement + | ClassMethod + | ClassPrivateMethod + | StaticBlock + | TSModuleBlock; +export type BlockParent = + | BlockStatement + | CatchClause + | DoWhileStatement + | ForInStatement + | ForStatement + | FunctionDeclaration + | FunctionExpression + | Program + | ObjectMethod + | SwitchStatement + | WhileStatement + | ArrowFunctionExpression + | ForOfStatement + | ClassMethod + | ClassPrivateMethod + | StaticBlock + | TSModuleBlock; +export type Block = BlockStatement | Program | TSModuleBlock; +export type Statement = + | BlockStatement + | BreakStatement + | ContinueStatement + | DebuggerStatement + | DoWhileStatement + | EmptyStatement + | ExpressionStatement + | ForInStatement + | ForStatement + | FunctionDeclaration + | IfStatement + | LabeledStatement + | ReturnStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | VariableDeclaration + | WhileStatement + | WithStatement + | ClassDeclaration + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ForOfStatement + | ImportDeclaration + | DeclareClass + | DeclareFunction + | DeclareInterface + | DeclareModule + | DeclareModuleExports + | DeclareTypeAlias + | DeclareOpaqueType + | DeclareVariable + | DeclareExportDeclaration + | DeclareExportAllDeclaration + | InterfaceDeclaration + | OpaqueType + | TypeAlias + | EnumDeclaration + | TSDeclareFunction + | TSInterfaceDeclaration + | TSTypeAliasDeclaration + | TSEnumDeclaration + | TSModuleDeclaration + | TSImportEqualsDeclaration + | TSExportAssignment + | TSNamespaceExportDeclaration; +export type Terminatorless = + | BreakStatement + | ContinueStatement + | ReturnStatement + | ThrowStatement + | YieldExpression + | AwaitExpression; +export type CompletionStatement = + | BreakStatement + | ContinueStatement + | ReturnStatement + | ThrowStatement; +export type Conditional = ConditionalExpression | IfStatement; +export type Loop = + | DoWhileStatement + | ForInStatement + | ForStatement + | WhileStatement + | ForOfStatement; +export type While = DoWhileStatement | WhileStatement; +export type ExpressionWrapper = + | ExpressionStatement + | ParenthesizedExpression + | TypeCastExpression; +export type For = ForInStatement | ForStatement | ForOfStatement; +export type ForXStatement = ForInStatement | ForOfStatement; +export type Function = + | FunctionDeclaration + | FunctionExpression + | ObjectMethod + | ArrowFunctionExpression + | ClassMethod + | ClassPrivateMethod; +export type FunctionParent = + | FunctionDeclaration + | FunctionExpression + | ObjectMethod + | ArrowFunctionExpression + | ClassMethod + | ClassPrivateMethod; +export type Pureish = + | FunctionDeclaration + | FunctionExpression + | StringLiteral + | NumericLiteral + | NullLiteral + | BooleanLiteral + | RegExpLiteral + | ArrowFunctionExpression + | BigIntLiteral + | DecimalLiteral; +export type Declaration = + | FunctionDeclaration + | VariableDeclaration + | ClassDeclaration + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ImportDeclaration + | DeclareClass + | DeclareFunction + | DeclareInterface + | DeclareModule + | DeclareModuleExports + | DeclareTypeAlias + | DeclareOpaqueType + | DeclareVariable + | DeclareExportDeclaration + | DeclareExportAllDeclaration + | InterfaceDeclaration + | OpaqueType + | TypeAlias + | EnumDeclaration + | TSDeclareFunction + | TSInterfaceDeclaration + | TSTypeAliasDeclaration + | TSEnumDeclaration + | TSModuleDeclaration; +export type PatternLike = + | Identifier + | RestElement + | AssignmentPattern + | ArrayPattern + | ObjectPattern; +export type LVal = + | Identifier + | MemberExpression + | RestElement + | AssignmentPattern + | ArrayPattern + | ObjectPattern + | TSParameterProperty; +export type TSEntityName = Identifier | TSQualifiedName; +export type Literal = + | StringLiteral + | NumericLiteral + | NullLiteral + | BooleanLiteral + | RegExpLiteral + | TemplateLiteral + | BigIntLiteral + | DecimalLiteral; +export type Immutable = + | StringLiteral + | NumericLiteral + | NullLiteral + | BooleanLiteral + | BigIntLiteral + | JSXAttribute + | JSXClosingElement + | JSXElement + | JSXExpressionContainer + | JSXSpreadChild + | JSXOpeningElement + | JSXText + | JSXFragment + | JSXOpeningFragment + | JSXClosingFragment + | DecimalLiteral; +export type UserWhitespacable = + | ObjectMethod + | ObjectProperty + | ObjectTypeInternalSlot + | ObjectTypeCallProperty + | ObjectTypeIndexer + | ObjectTypeProperty + | ObjectTypeSpreadProperty; +export type Method = ObjectMethod | ClassMethod | ClassPrivateMethod; +export type ObjectMember = ObjectMethod | ObjectProperty; +export type Property = ObjectProperty | ClassProperty | ClassPrivateProperty; +export type UnaryLike = UnaryExpression | SpreadElement; +export type Pattern = AssignmentPattern | ArrayPattern | ObjectPattern; +export type Class = ClassExpression | ClassDeclaration; +export type ModuleDeclaration = + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ImportDeclaration; +export type ExportDeclaration = + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration; +export type ModuleSpecifier = + | ExportSpecifier + | ImportDefaultSpecifier + | ImportNamespaceSpecifier + | ImportSpecifier + | ExportNamespaceSpecifier + | ExportDefaultSpecifier; +export type Flow = + | AnyTypeAnnotation + | ArrayTypeAnnotation + | BooleanTypeAnnotation + | BooleanLiteralTypeAnnotation + | NullLiteralTypeAnnotation + | ClassImplements + | DeclareClass + | DeclareFunction + | DeclareInterface + | DeclareModule + | DeclareModuleExports + | DeclareTypeAlias + | DeclareOpaqueType + | DeclareVariable + | DeclareExportDeclaration + | DeclareExportAllDeclaration + | DeclaredPredicate + | ExistsTypeAnnotation + | FunctionTypeAnnotation + | FunctionTypeParam + | GenericTypeAnnotation + | InferredPredicate + | InterfaceExtends + | InterfaceDeclaration + | InterfaceTypeAnnotation + | IntersectionTypeAnnotation + | MixedTypeAnnotation + | EmptyTypeAnnotation + | NullableTypeAnnotation + | NumberLiteralTypeAnnotation + | NumberTypeAnnotation + | ObjectTypeAnnotation + | ObjectTypeInternalSlot + | ObjectTypeCallProperty + | ObjectTypeIndexer + | ObjectTypeProperty + | ObjectTypeSpreadProperty + | OpaqueType + | QualifiedTypeIdentifier + | StringLiteralTypeAnnotation + | StringTypeAnnotation + | SymbolTypeAnnotation + | ThisTypeAnnotation + | TupleTypeAnnotation + | TypeofTypeAnnotation + | TypeAlias + | TypeAnnotation + | TypeCastExpression + | TypeParameter + | TypeParameterDeclaration + | TypeParameterInstantiation + | UnionTypeAnnotation + | Variance + | VoidTypeAnnotation; +export type FlowType = + | AnyTypeAnnotation + | ArrayTypeAnnotation + | BooleanTypeAnnotation + | BooleanLiteralTypeAnnotation + | NullLiteralTypeAnnotation + | ExistsTypeAnnotation + | FunctionTypeAnnotation + | GenericTypeAnnotation + | InterfaceTypeAnnotation + | IntersectionTypeAnnotation + | MixedTypeAnnotation + | EmptyTypeAnnotation + | NullableTypeAnnotation + | NumberLiteralTypeAnnotation + | NumberTypeAnnotation + | ObjectTypeAnnotation + | StringLiteralTypeAnnotation + | StringTypeAnnotation + | SymbolTypeAnnotation + | ThisTypeAnnotation + | TupleTypeAnnotation + | TypeofTypeAnnotation + | UnionTypeAnnotation + | VoidTypeAnnotation; +export type FlowBaseAnnotation = + | AnyTypeAnnotation + | BooleanTypeAnnotation + | NullLiteralTypeAnnotation + | MixedTypeAnnotation + | EmptyTypeAnnotation + | NumberTypeAnnotation + | StringTypeAnnotation + | SymbolTypeAnnotation + | ThisTypeAnnotation + | VoidTypeAnnotation; +export type FlowDeclaration = + | DeclareClass + | DeclareFunction + | DeclareInterface + | DeclareModule + | DeclareModuleExports + | DeclareTypeAlias + | DeclareOpaqueType + | DeclareVariable + | DeclareExportDeclaration + | DeclareExportAllDeclaration + | InterfaceDeclaration + | OpaqueType + | TypeAlias; +export type FlowPredicate = DeclaredPredicate | InferredPredicate; +export type EnumBody = + | EnumBooleanBody + | EnumNumberBody + | EnumStringBody + | EnumSymbolBody; +export type EnumMember = + | EnumBooleanMember + | EnumNumberMember + | EnumStringMember + | EnumDefaultedMember; +export type JSX = + | JSXAttribute + | JSXClosingElement + | JSXElement + | JSXEmptyExpression + | JSXExpressionContainer + | JSXSpreadChild + | JSXIdentifier + | JSXMemberExpression + | JSXNamespacedName + | JSXOpeningElement + | JSXSpreadAttribute + | JSXText + | JSXFragment + | JSXOpeningFragment + | JSXClosingFragment; +export type Private = ClassPrivateProperty | ClassPrivateMethod | PrivateName; +export type TSTypeElement = + | TSCallSignatureDeclaration + | TSConstructSignatureDeclaration + | TSPropertySignature + | TSMethodSignature + | TSIndexSignature; +export type TSType = + | TSAnyKeyword + | TSBooleanKeyword + | TSBigIntKeyword + | TSIntrinsicKeyword + | TSNeverKeyword + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSStringKeyword + | TSSymbolKeyword + | TSUndefinedKeyword + | TSUnknownKeyword + | TSVoidKeyword + | TSThisType + | TSFunctionType + | TSConstructorType + | TSTypeReference + | TSTypePredicate + | TSTypeQuery + | TSTypeLiteral + | TSArrayType + | TSTupleType + | TSOptionalType + | TSRestType + | TSUnionType + | TSIntersectionType + | TSConditionalType + | TSInferType + | TSParenthesizedType + | TSTypeOperator + | TSIndexedAccessType + | TSMappedType + | TSLiteralType + | TSExpressionWithTypeArguments + | TSImportType; +export type TSBaseType = + | TSAnyKeyword + | TSBooleanKeyword + | TSBigIntKeyword + | TSIntrinsicKeyword + | TSNeverKeyword + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSStringKeyword + | TSSymbolKeyword + | TSUndefinedKeyword + | TSUnknownKeyword + | TSVoidKeyword + | TSThisType + | TSLiteralType; + +export interface Aliases { + Expression: Expression; + Binary: Binary; + Scopable: Scopable; + BlockParent: BlockParent; + Block: Block; + Statement: Statement; + Terminatorless: Terminatorless; + CompletionStatement: CompletionStatement; + Conditional: Conditional; + Loop: Loop; + While: While; + ExpressionWrapper: ExpressionWrapper; + For: For; + ForXStatement: ForXStatement; + Function: Function; + FunctionParent: FunctionParent; + Pureish: Pureish; + Declaration: Declaration; + PatternLike: PatternLike; + LVal: LVal; + TSEntityName: TSEntityName; + Literal: Literal; + Immutable: Immutable; + UserWhitespacable: UserWhitespacable; + Method: Method; + ObjectMember: ObjectMember; + Property: Property; + UnaryLike: UnaryLike; + Pattern: Pattern; + Class: Class; + ModuleDeclaration: ModuleDeclaration; + ExportDeclaration: ExportDeclaration; + ModuleSpecifier: ModuleSpecifier; + Flow: Flow; + FlowType: FlowType; + FlowBaseAnnotation: FlowBaseAnnotation; + FlowDeclaration: FlowDeclaration; + FlowPredicate: FlowPredicate; + EnumBody: EnumBody; + EnumMember: EnumMember; + JSX: JSX; + Private: Private; + TSTypeElement: TSTypeElement; + TSType: TSType; + TSBaseType: TSBaseType; +} diff --git a/packages/babel-types/src/builders/builder.ts b/packages/babel-types/src/builders/builder.ts index 04b5df08b8..899d2d45e5 100644 --- a/packages/babel-types/src/builders/builder.ts +++ b/packages/babel-types/src/builders/builder.ts @@ -1,9 +1,12 @@ -// @flow import loClone from "lodash/clone"; import { NODE_FIELDS, BUILDER_KEYS } from "../definitions"; import validate from "../validators/validate"; +import type * as t from ".."; -export default function builder(type: string, ...args: Array): Object { +export default function builder( + type: T["type"], + ...args: Array +): T { const keys = BUILDER_KEYS[type]; const countArgs = args.length; if (countArgs > keys.length) { @@ -27,8 +30,8 @@ export default function builder(type: string, ...args: Array): Object { }); for (const key of Object.keys(node)) { - validate(node, key, node[key]); + validate(node as t.Node, key, node[key]); } - return node; + return node as T; } diff --git a/packages/babel-types/src/builders/flow/createFlowUnionType.ts b/packages/babel-types/src/builders/flow/createFlowUnionType.ts index 2f2dd03ffb..91314ff89d 100644 --- a/packages/babel-types/src/builders/flow/createFlowUnionType.ts +++ b/packages/babel-types/src/builders/flow/createFlowUnionType.ts @@ -1,16 +1,18 @@ -// @flow import { unionTypeAnnotation } from "../generated"; import removeTypeDuplicates from "../../modifications/flow/removeTypeDuplicates"; +import type * as t from "../.."; /** * Takes an array of `types` and flattens them, removing duplicates and * returns a `UnionTypeAnnotation` node containing them. */ -export default function createFlowUnionType(types: Array): Object { +export default function createFlowUnionType( + types: [T] | Array, +): T | t.UnionTypeAnnotation { const flattened = removeTypeDuplicates(types); if (flattened.length === 1) { - return flattened[0]; + return flattened[0] as T; } else { return unionTypeAnnotation(flattened); } diff --git a/packages/babel-types/src/builders/flow/createTypeAnnotationBasedOnTypeof.ts b/packages/babel-types/src/builders/flow/createTypeAnnotationBasedOnTypeof.ts index 57f930abcb..8107e5508b 100644 --- a/packages/babel-types/src/builders/flow/createTypeAnnotationBasedOnTypeof.ts +++ b/packages/babel-types/src/builders/flow/createTypeAnnotationBasedOnTypeof.ts @@ -1,4 +1,3 @@ -// @flow import { stringTypeAnnotation, numberTypeAnnotation, @@ -7,13 +6,26 @@ import { genericTypeAnnotation, identifier, } from "../generated"; +import type * as t from "../.."; /** * Create a type annotation based on typeof expression. */ export default function createTypeAnnotationBasedOnTypeof( - type: string, -): Object { + type: + | "string" + | "number" + | "undefined" + | "boolean" + | "function" + | "object" + | "symbol", +): + | t.StringTypeAnnotation + | t.VoidTypeAnnotation + | t.NumberTypeAnnotation + | t.BooleanTypeAnnotation + | t.GenericTypeAnnotation { if (type === "string") { return stringTypeAnnotation(); } else if (type === "number") { diff --git a/packages/babel-types/src/builders/generated/index.ts b/packages/babel-types/src/builders/generated/index.ts index 02e19ab4a4..3328c722a3 100755 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -1,1076 +1,1484 @@ -// @flow /* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ import builder from "../builder"; +import type * as t from "../.."; -export function arrayExpression(...args: Array): Object { - return builder("ArrayExpression", ...args); +/* eslint-disable @typescript-eslint/no-unused-vars */ + +export function arrayExpression( + elements?: Array, +): t.ArrayExpression { + return builder("ArrayExpression", ...arguments); +} +export function assignmentExpression( + operator: string, + left: t.LVal, + right: t.Expression, +): t.AssignmentExpression { + return builder("AssignmentExpression", ...arguments); +} +export function binaryExpression( + operator: + | "+" + | "-" + | "/" + | "%" + | "*" + | "**" + | "&" + | "|" + | ">>" + | ">>>" + | "<<" + | "^" + | "==" + | "===" + | "!=" + | "!==" + | "in" + | "instanceof" + | ">" + | "<" + | ">=" + | "<=", + left: t.Expression | t.PrivateName, + right: t.Expression, +): t.BinaryExpression { + return builder("BinaryExpression", ...arguments); +} +export function interpreterDirective(value: string): t.InterpreterDirective { + return builder("InterpreterDirective", ...arguments); +} +export function directive(value: t.DirectiveLiteral): t.Directive { + return builder("Directive", ...arguments); +} +export function directiveLiteral(value: string): t.DirectiveLiteral { + return builder("DirectiveLiteral", ...arguments); +} +export function blockStatement( + body: Array, + directives?: Array, +): t.BlockStatement { + return builder("BlockStatement", ...arguments); +} +export function breakStatement(label?: t.Identifier | null): t.BreakStatement { + return builder("BreakStatement", ...arguments); +} +export function callExpression( + callee: t.Expression | t.V8IntrinsicIdentifier, + _arguments: Array< + t.Expression | t.SpreadElement | t.JSXNamespacedName | t.ArgumentPlaceholder + >, +): t.CallExpression { + return builder("CallExpression", ...arguments); +} +export function catchClause( + param: t.Identifier | t.ArrayPattern | t.ObjectPattern | null | undefined, + body: t.BlockStatement, +): t.CatchClause { + return builder("CatchClause", ...arguments); +} +export function conditionalExpression( + test: t.Expression, + consequent: t.Expression, + alternate: t.Expression, +): t.ConditionalExpression { + return builder("ConditionalExpression", ...arguments); +} +export function continueStatement( + label?: t.Identifier | null, +): t.ContinueStatement { + return builder("ContinueStatement", ...arguments); +} +export function debuggerStatement(): t.DebuggerStatement { + return builder("DebuggerStatement", ...arguments); +} +export function doWhileStatement( + test: t.Expression, + body: t.Statement, +): t.DoWhileStatement { + return builder("DoWhileStatement", ...arguments); +} +export function emptyStatement(): t.EmptyStatement { + return builder("EmptyStatement", ...arguments); +} +export function expressionStatement( + expression: t.Expression, +): t.ExpressionStatement { + return builder("ExpressionStatement", ...arguments); +} +export function file( + program: t.Program, + comments?: Array | null, + tokens?: Array | null, +): t.File { + return builder("File", ...arguments); +} +export function forInStatement( + left: t.VariableDeclaration | t.LVal, + right: t.Expression, + body: t.Statement, +): t.ForInStatement { + return builder("ForInStatement", ...arguments); +} +export function forStatement( + init: t.VariableDeclaration | t.Expression | null | undefined, + test: t.Expression | null | undefined, + update: t.Expression | null | undefined, + body: t.Statement, +): t.ForStatement { + return builder("ForStatement", ...arguments); +} +export function functionDeclaration( + id: t.Identifier | null | undefined, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + body: t.BlockStatement, + generator?: boolean, + async?: boolean, +): t.FunctionDeclaration { + return builder("FunctionDeclaration", ...arguments); +} +export function functionExpression( + id: t.Identifier | null | undefined, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + body: t.BlockStatement, + generator?: boolean, + async?: boolean, +): t.FunctionExpression { + return builder("FunctionExpression", ...arguments); +} +export function identifier(name: string): t.Identifier { + return builder("Identifier", ...arguments); +} +export function ifStatement( + test: t.Expression, + consequent: t.Statement, + alternate?: t.Statement | null, +): t.IfStatement { + return builder("IfStatement", ...arguments); +} +export function labeledStatement( + label: t.Identifier, + body: t.Statement, +): t.LabeledStatement { + return builder("LabeledStatement", ...arguments); +} +export function stringLiteral(value: string): t.StringLiteral { + return builder("StringLiteral", ...arguments); +} +export function numericLiteral(value: number): t.NumericLiteral { + return builder("NumericLiteral", ...arguments); +} +export function nullLiteral(): t.NullLiteral { + return builder("NullLiteral", ...arguments); +} +export function booleanLiteral(value: boolean): t.BooleanLiteral { + return builder("BooleanLiteral", ...arguments); +} +export function regExpLiteral( + pattern: string, + flags?: string, +): t.RegExpLiteral { + return builder("RegExpLiteral", ...arguments); +} +export function logicalExpression( + operator: "||" | "&&" | "??", + left: t.Expression, + right: t.Expression, +): t.LogicalExpression { + return builder("LogicalExpression", ...arguments); +} +export function memberExpression( + object: t.Expression, + property: t.Expression | t.Identifier | t.PrivateName, + computed?: boolean, + optional?: true | false | null, +): t.MemberExpression { + return builder("MemberExpression", ...arguments); +} +export function newExpression( + callee: t.Expression | t.V8IntrinsicIdentifier, + _arguments: Array< + t.Expression | t.SpreadElement | t.JSXNamespacedName | t.ArgumentPlaceholder + >, +): t.NewExpression { + return builder("NewExpression", ...arguments); +} +export function program( + body: Array, + directives?: Array, + sourceType?: "script" | "module", + interpreter?: t.InterpreterDirective | null, +): t.Program { + return builder("Program", ...arguments); +} +export function objectExpression( + properties: Array, +): t.ObjectExpression { + return builder("ObjectExpression", ...arguments); +} +export function objectMethod( + kind: "method" | "get" | "set" | undefined, + key: t.Expression | t.Identifier | t.StringLiteral | t.NumericLiteral, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + body: t.BlockStatement, + computed?: boolean, + generator?: boolean, + async?: boolean, +): t.ObjectMethod { + return builder("ObjectMethod", ...arguments); +} +export function objectProperty( + key: t.Expression | t.Identifier | t.StringLiteral | t.NumericLiteral, + value: t.Expression | t.PatternLike, + computed?: boolean, + shorthand?: boolean, + decorators?: Array | null, +): t.ObjectProperty { + return builder("ObjectProperty", ...arguments); +} +export function restElement(argument: t.LVal): t.RestElement { + return builder("RestElement", ...arguments); +} +export function returnStatement( + argument?: t.Expression | null, +): t.ReturnStatement { + return builder("ReturnStatement", ...arguments); +} +export function sequenceExpression( + expressions: Array, +): t.SequenceExpression { + return builder("SequenceExpression", ...arguments); +} +export function parenthesizedExpression( + expression: t.Expression, +): t.ParenthesizedExpression { + return builder("ParenthesizedExpression", ...arguments); +} +export function switchCase( + test: t.Expression | null | undefined, + consequent: Array, +): t.SwitchCase { + return builder("SwitchCase", ...arguments); +} +export function switchStatement( + discriminant: t.Expression, + cases: Array, +): t.SwitchStatement { + return builder("SwitchStatement", ...arguments); +} +export function thisExpression(): t.ThisExpression { + return builder("ThisExpression", ...arguments); +} +export function throwStatement(argument: t.Expression): t.ThrowStatement { + return builder("ThrowStatement", ...arguments); +} +export function tryStatement( + block: t.BlockStatement, + handler?: t.CatchClause | null, + finalizer?: t.BlockStatement | null, +): t.TryStatement { + return builder("TryStatement", ...arguments); +} +export function unaryExpression( + operator: "void" | "throw" | "delete" | "!" | "+" | "-" | "~" | "typeof", + argument: t.Expression, + prefix?: boolean, +): t.UnaryExpression { + return builder("UnaryExpression", ...arguments); +} +export function updateExpression( + operator: "++" | "--", + argument: t.Expression, + prefix?: boolean, +): t.UpdateExpression { + return builder("UpdateExpression", ...arguments); +} +export function variableDeclaration( + kind: "var" | "let" | "const", + declarations: Array, +): t.VariableDeclaration { + return builder("VariableDeclaration", ...arguments); +} +export function variableDeclarator( + id: t.LVal, + init?: t.Expression | null, +): t.VariableDeclarator { + return builder("VariableDeclarator", ...arguments); +} +export function whileStatement( + test: t.Expression, + body: t.Statement, +): t.WhileStatement { + return builder("WhileStatement", ...arguments); +} +export function withStatement( + object: t.Expression, + body: t.Statement, +): t.WithStatement { + return builder("WithStatement", ...arguments); +} +export function assignmentPattern( + left: t.Identifier | t.ObjectPattern | t.ArrayPattern | t.MemberExpression, + right: t.Expression, +): t.AssignmentPattern { + return builder("AssignmentPattern", ...arguments); +} +export function arrayPattern( + elements: Array, +): t.ArrayPattern { + return builder("ArrayPattern", ...arguments); +} +export function arrowFunctionExpression( + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + body: t.BlockStatement | t.Expression, + async?: boolean, +): t.ArrowFunctionExpression { + return builder("ArrowFunctionExpression", ...arguments); +} +export function classBody( + body: Array< + | t.ClassMethod + | t.ClassPrivateMethod + | t.ClassProperty + | t.ClassPrivateProperty + | t.TSDeclareMethod + | t.TSIndexSignature + >, +): t.ClassBody { + return builder("ClassBody", ...arguments); +} +export function classExpression( + id: t.Identifier | null | undefined, + superClass: t.Expression | null | undefined, + body: t.ClassBody, + decorators?: Array | null, +): t.ClassExpression { + return builder("ClassExpression", ...arguments); +} +export function classDeclaration( + id: t.Identifier, + superClass: t.Expression | null | undefined, + body: t.ClassBody, + decorators?: Array | null, +): t.ClassDeclaration { + return builder("ClassDeclaration", ...arguments); +} +export function exportAllDeclaration( + source: t.StringLiteral, +): t.ExportAllDeclaration { + return builder("ExportAllDeclaration", ...arguments); +} +export function exportDefaultDeclaration( + declaration: + | t.FunctionDeclaration + | t.TSDeclareFunction + | t.ClassDeclaration + | t.Expression, +): t.ExportDefaultDeclaration { + return builder("ExportDefaultDeclaration", ...arguments); +} +export function exportNamedDeclaration( + declaration?: t.Declaration | null, + specifiers?: Array< + t.ExportSpecifier | t.ExportDefaultSpecifier | t.ExportNamespaceSpecifier + >, + source?: t.StringLiteral | null, +): t.ExportNamedDeclaration { + return builder("ExportNamedDeclaration", ...arguments); +} +export function exportSpecifier( + local: t.Identifier, + exported: t.Identifier | t.StringLiteral, +): t.ExportSpecifier { + return builder("ExportSpecifier", ...arguments); +} +export function forOfStatement( + left: t.VariableDeclaration | t.LVal, + right: t.Expression, + body: t.Statement, + _await?: boolean, +): t.ForOfStatement { + return builder("ForOfStatement", ...arguments); +} +export function importDeclaration( + specifiers: Array< + t.ImportSpecifier | t.ImportDefaultSpecifier | t.ImportNamespaceSpecifier + >, + source: t.StringLiteral, +): t.ImportDeclaration { + return builder("ImportDeclaration", ...arguments); +} +export function importDefaultSpecifier( + local: t.Identifier, +): t.ImportDefaultSpecifier { + return builder("ImportDefaultSpecifier", ...arguments); +} +export function importNamespaceSpecifier( + local: t.Identifier, +): t.ImportNamespaceSpecifier { + return builder("ImportNamespaceSpecifier", ...arguments); +} +export function importSpecifier( + local: t.Identifier, + imported: t.Identifier | t.StringLiteral, +): t.ImportSpecifier { + return builder("ImportSpecifier", ...arguments); +} +export function metaProperty( + meta: t.Identifier, + property: t.Identifier, +): t.MetaProperty { + return builder("MetaProperty", ...arguments); +} +export function classMethod( + kind: "get" | "set" | "method" | "constructor" | undefined, + key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.Expression, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + body: t.BlockStatement, + computed?: boolean, + _static?: boolean, + generator?: boolean, + async?: boolean, +): t.ClassMethod { + return builder("ClassMethod", ...arguments); +} +export function objectPattern( + properties: Array, +): t.ObjectPattern { + return builder("ObjectPattern", ...arguments); +} +export function spreadElement(argument: t.Expression): t.SpreadElement { + return builder("SpreadElement", ...arguments); +} +function _super(): t.Super { + return builder("Super", ...arguments); } -export { arrayExpression as ArrayExpression }; -export function assignmentExpression(...args: Array): Object { - return builder("AssignmentExpression", ...args); -} -export { assignmentExpression as AssignmentExpression }; -export function binaryExpression(...args: Array): Object { - return builder("BinaryExpression", ...args); -} -export { binaryExpression as BinaryExpression }; -export function interpreterDirective(...args: Array): Object { - return builder("InterpreterDirective", ...args); -} -export { interpreterDirective as InterpreterDirective }; -export function directive(...args: Array): Object { - return builder("Directive", ...args); -} -export { directive as Directive }; -export function directiveLiteral(...args: Array): Object { - return builder("DirectiveLiteral", ...args); -} -export { directiveLiteral as DirectiveLiteral }; -export function blockStatement(...args: Array): Object { - return builder("BlockStatement", ...args); -} -export { blockStatement as BlockStatement }; -export function breakStatement(...args: Array): Object { - return builder("BreakStatement", ...args); -} -export { breakStatement as BreakStatement }; -export function callExpression(...args: Array): Object { - return builder("CallExpression", ...args); -} -export { callExpression as CallExpression }; -export function catchClause(...args: Array): Object { - return builder("CatchClause", ...args); -} -export { catchClause as CatchClause }; -export function conditionalExpression(...args: Array): Object { - return builder("ConditionalExpression", ...args); -} -export { conditionalExpression as ConditionalExpression }; -export function continueStatement(...args: Array): Object { - return builder("ContinueStatement", ...args); -} -export { continueStatement as ContinueStatement }; -export function debuggerStatement(...args: Array): Object { - return builder("DebuggerStatement", ...args); -} -export { debuggerStatement as DebuggerStatement }; -export function doWhileStatement(...args: Array): Object { - return builder("DoWhileStatement", ...args); -} -export { doWhileStatement as DoWhileStatement }; -export function emptyStatement(...args: Array): Object { - return builder("EmptyStatement", ...args); -} -export { emptyStatement as EmptyStatement }; -export function expressionStatement(...args: Array): Object { - return builder("ExpressionStatement", ...args); -} -export { expressionStatement as ExpressionStatement }; -export function file(...args: Array): Object { - return builder("File", ...args); -} -export { file as File }; -export function forInStatement(...args: Array): Object { - return builder("ForInStatement", ...args); -} -export { forInStatement as ForInStatement }; -export function forStatement(...args: Array): Object { - return builder("ForStatement", ...args); -} -export { forStatement as ForStatement }; -export function functionDeclaration(...args: Array): Object { - return builder("FunctionDeclaration", ...args); -} -export { functionDeclaration as FunctionDeclaration }; -export function functionExpression(...args: Array): Object { - return builder("FunctionExpression", ...args); -} -export { functionExpression as FunctionExpression }; -export function identifier(...args: Array): Object { - return builder("Identifier", ...args); -} -export { identifier as Identifier }; -export function ifStatement(...args: Array): Object { - return builder("IfStatement", ...args); -} -export { ifStatement as IfStatement }; -export function labeledStatement(...args: Array): Object { - return builder("LabeledStatement", ...args); -} -export { labeledStatement as LabeledStatement }; -export function stringLiteral(...args: Array): Object { - return builder("StringLiteral", ...args); -} -export { stringLiteral as StringLiteral }; -export function numericLiteral(...args: Array): Object { - return builder("NumericLiteral", ...args); -} -export { numericLiteral as NumericLiteral }; -export function nullLiteral(...args: Array): Object { - return builder("NullLiteral", ...args); -} -export { nullLiteral as NullLiteral }; -export function booleanLiteral(...args: Array): Object { - return builder("BooleanLiteral", ...args); -} -export { booleanLiteral as BooleanLiteral }; -export function regExpLiteral(...args: Array): Object { - return builder("RegExpLiteral", ...args); -} -export { regExpLiteral as RegExpLiteral }; -export function logicalExpression(...args: Array): Object { - return builder("LogicalExpression", ...args); -} -export { logicalExpression as LogicalExpression }; -export function memberExpression(...args: Array): Object { - return builder("MemberExpression", ...args); -} -export { memberExpression as MemberExpression }; -export function newExpression(...args: Array): Object { - return builder("NewExpression", ...args); -} -export { newExpression as NewExpression }; -export function program(...args: Array): Object { - return builder("Program", ...args); -} -export { program as Program }; -export function objectExpression(...args: Array): Object { - return builder("ObjectExpression", ...args); -} -export { objectExpression as ObjectExpression }; -export function objectMethod(...args: Array): Object { - return builder("ObjectMethod", ...args); -} -export { objectMethod as ObjectMethod }; -export function objectProperty(...args: Array): Object { - return builder("ObjectProperty", ...args); -} -export { objectProperty as ObjectProperty }; -export function restElement(...args: Array): Object { - return builder("RestElement", ...args); -} -export { restElement as RestElement }; -export function returnStatement(...args: Array): Object { - return builder("ReturnStatement", ...args); -} -export { returnStatement as ReturnStatement }; -export function sequenceExpression(...args: Array): Object { - return builder("SequenceExpression", ...args); -} -export { sequenceExpression as SequenceExpression }; -export function parenthesizedExpression(...args: Array): Object { - return builder("ParenthesizedExpression", ...args); -} -export { parenthesizedExpression as ParenthesizedExpression }; -export function switchCase(...args: Array): Object { - return builder("SwitchCase", ...args); -} -export { switchCase as SwitchCase }; -export function switchStatement(...args: Array): Object { - return builder("SwitchStatement", ...args); -} -export { switchStatement as SwitchStatement }; -export function thisExpression(...args: Array): Object { - return builder("ThisExpression", ...args); -} -export { thisExpression as ThisExpression }; -export function throwStatement(...args: Array): Object { - return builder("ThrowStatement", ...args); -} -export { throwStatement as ThrowStatement }; -export function tryStatement(...args: Array): Object { - return builder("TryStatement", ...args); -} -export { tryStatement as TryStatement }; -export function unaryExpression(...args: Array): Object { - return builder("UnaryExpression", ...args); -} -export { unaryExpression as UnaryExpression }; -export function updateExpression(...args: Array): Object { - return builder("UpdateExpression", ...args); -} -export { updateExpression as UpdateExpression }; -export function variableDeclaration(...args: Array): Object { - return builder("VariableDeclaration", ...args); -} -export { variableDeclaration as VariableDeclaration }; -export function variableDeclarator(...args: Array): Object { - return builder("VariableDeclarator", ...args); -} -export { variableDeclarator as VariableDeclarator }; -export function whileStatement(...args: Array): Object { - return builder("WhileStatement", ...args); -} -export { whileStatement as WhileStatement }; -export function withStatement(...args: Array): Object { - return builder("WithStatement", ...args); -} -export { withStatement as WithStatement }; -export function assignmentPattern(...args: Array): Object { - return builder("AssignmentPattern", ...args); -} -export { assignmentPattern as AssignmentPattern }; -export function arrayPattern(...args: Array): Object { - return builder("ArrayPattern", ...args); -} -export { arrayPattern as ArrayPattern }; -export function arrowFunctionExpression(...args: Array): Object { - return builder("ArrowFunctionExpression", ...args); -} -export { arrowFunctionExpression as ArrowFunctionExpression }; -export function classBody(...args: Array): Object { - return builder("ClassBody", ...args); -} -export { classBody as ClassBody }; -export function classExpression(...args: Array): Object { - return builder("ClassExpression", ...args); -} -export { classExpression as ClassExpression }; -export function classDeclaration(...args: Array): Object { - return builder("ClassDeclaration", ...args); -} -export { classDeclaration as ClassDeclaration }; -export function exportAllDeclaration(...args: Array): Object { - return builder("ExportAllDeclaration", ...args); -} -export { exportAllDeclaration as ExportAllDeclaration }; -export function exportDefaultDeclaration(...args: Array): Object { - return builder("ExportDefaultDeclaration", ...args); -} -export { exportDefaultDeclaration as ExportDefaultDeclaration }; -export function exportNamedDeclaration(...args: Array): Object { - return builder("ExportNamedDeclaration", ...args); -} -export { exportNamedDeclaration as ExportNamedDeclaration }; -export function exportSpecifier(...args: Array): Object { - return builder("ExportSpecifier", ...args); -} -export { exportSpecifier as ExportSpecifier }; -export function forOfStatement(...args: Array): Object { - return builder("ForOfStatement", ...args); -} -export { forOfStatement as ForOfStatement }; -export function importDeclaration(...args: Array): Object { - return builder("ImportDeclaration", ...args); -} -export { importDeclaration as ImportDeclaration }; -export function importDefaultSpecifier(...args: Array): Object { - return builder("ImportDefaultSpecifier", ...args); -} -export { importDefaultSpecifier as ImportDefaultSpecifier }; -export function importNamespaceSpecifier(...args: Array): Object { - return builder("ImportNamespaceSpecifier", ...args); -} -export { importNamespaceSpecifier as ImportNamespaceSpecifier }; -export function importSpecifier(...args: Array): Object { - return builder("ImportSpecifier", ...args); -} -export { importSpecifier as ImportSpecifier }; -export function metaProperty(...args: Array): Object { - return builder("MetaProperty", ...args); -} -export { metaProperty as MetaProperty }; -export function classMethod(...args: Array): Object { - return builder("ClassMethod", ...args); -} -export { classMethod as ClassMethod }; -export function objectPattern(...args: Array): Object { - return builder("ObjectPattern", ...args); -} -export { objectPattern as ObjectPattern }; -export function spreadElement(...args: Array): Object { - return builder("SpreadElement", ...args); -} -export { spreadElement as SpreadElement }; -function _super(...args: Array): Object { - return builder("Super", ...args); -} -export { _super as Super }; export { _super as super }; -export function taggedTemplateExpression(...args: Array): Object { - return builder("TaggedTemplateExpression", ...args); +export function taggedTemplateExpression( + tag: t.Expression, + quasi: t.TemplateLiteral, +): t.TaggedTemplateExpression { + return builder("TaggedTemplateExpression", ...arguments); } -export { taggedTemplateExpression as TaggedTemplateExpression }; -export function templateElement(...args: Array): Object { - return builder("TemplateElement", ...args); +export function templateElement( + value: { raw: string; cooked?: string }, + tail?: boolean, +): t.TemplateElement { + return builder("TemplateElement", ...arguments); } -export { templateElement as TemplateElement }; -export function templateLiteral(...args: Array): Object { - return builder("TemplateLiteral", ...args); +export function templateLiteral( + quasis: Array, + expressions: Array, +): t.TemplateLiteral { + return builder("TemplateLiteral", ...arguments); } -export { templateLiteral as TemplateLiteral }; -export function yieldExpression(...args: Array): Object { - return builder("YieldExpression", ...args); +export function yieldExpression( + argument?: t.Expression | null, + delegate?: boolean, +): t.YieldExpression { + return builder("YieldExpression", ...arguments); } -export { yieldExpression as YieldExpression }; -export function awaitExpression(...args: Array): Object { - return builder("AwaitExpression", ...args); +export function awaitExpression(argument: t.Expression): t.AwaitExpression { + return builder("AwaitExpression", ...arguments); } -export { awaitExpression as AwaitExpression }; -function _import(...args: Array): Object { - return builder("Import", ...args); +function _import(): t.Import { + return builder("Import", ...arguments); } -export { _import as Import }; export { _import as import }; -export function bigIntLiteral(...args: Array): Object { - return builder("BigIntLiteral", ...args); +export function bigIntLiteral(value: string): t.BigIntLiteral { + return builder("BigIntLiteral", ...arguments); +} +export function exportNamespaceSpecifier( + exported: t.Identifier, +): t.ExportNamespaceSpecifier { + return builder("ExportNamespaceSpecifier", ...arguments); +} +export function optionalMemberExpression( + object: t.Expression, + property: t.Expression | t.Identifier, + computed: boolean | undefined, + optional: boolean, +): t.OptionalMemberExpression { + return builder("OptionalMemberExpression", ...arguments); +} +export function optionalCallExpression( + callee: t.Expression, + _arguments: Array< + t.Expression | t.SpreadElement | t.JSXNamespacedName | t.ArgumentPlaceholder + >, + optional: boolean, +): t.OptionalCallExpression { + return builder("OptionalCallExpression", ...arguments); +} +export function anyTypeAnnotation(): t.AnyTypeAnnotation { + return builder("AnyTypeAnnotation", ...arguments); +} +export function arrayTypeAnnotation( + elementType: t.FlowType, +): t.ArrayTypeAnnotation { + return builder("ArrayTypeAnnotation", ...arguments); +} +export function booleanTypeAnnotation(): t.BooleanTypeAnnotation { + return builder("BooleanTypeAnnotation", ...arguments); +} +export function booleanLiteralTypeAnnotation( + value: boolean, +): t.BooleanLiteralTypeAnnotation { + return builder("BooleanLiteralTypeAnnotation", ...arguments); +} +export function nullLiteralTypeAnnotation(): t.NullLiteralTypeAnnotation { + return builder("NullLiteralTypeAnnotation", ...arguments); +} +export function classImplements( + id: t.Identifier, + typeParameters?: t.TypeParameterInstantiation | null, +): t.ClassImplements { + return builder("ClassImplements", ...arguments); +} +export function declareClass( + id: t.Identifier, + typeParameters: t.TypeParameterDeclaration | null | undefined, + _extends: Array | null | undefined, + body: t.ObjectTypeAnnotation, +): t.DeclareClass { + return builder("DeclareClass", ...arguments); +} +export function declareFunction(id: t.Identifier): t.DeclareFunction { + return builder("DeclareFunction", ...arguments); +} +export function declareInterface( + id: t.Identifier, + typeParameters: t.TypeParameterDeclaration | null | undefined, + _extends: Array | null | undefined, + body: t.ObjectTypeAnnotation, +): t.DeclareInterface { + return builder("DeclareInterface", ...arguments); +} +export function declareModule( + id: t.Identifier | t.StringLiteral, + body: t.BlockStatement, + kind?: "CommonJS" | "ES" | null, +): t.DeclareModule { + return builder("DeclareModule", ...arguments); +} +export function declareModuleExports( + typeAnnotation: t.TypeAnnotation, +): t.DeclareModuleExports { + return builder("DeclareModuleExports", ...arguments); +} +export function declareTypeAlias( + id: t.Identifier, + typeParameters: t.TypeParameterDeclaration | null | undefined, + right: t.FlowType, +): t.DeclareTypeAlias { + return builder("DeclareTypeAlias", ...arguments); +} +export function declareOpaqueType( + id: t.Identifier, + typeParameters?: t.TypeParameterDeclaration | null, + supertype?: t.FlowType | null, +): t.DeclareOpaqueType { + return builder("DeclareOpaqueType", ...arguments); +} +export function declareVariable(id: t.Identifier): t.DeclareVariable { + return builder("DeclareVariable", ...arguments); +} +export function declareExportDeclaration( + declaration?: t.Flow | null, + specifiers?: Array | null, + source?: t.StringLiteral | null, +): t.DeclareExportDeclaration { + return builder("DeclareExportDeclaration", ...arguments); +} +export function declareExportAllDeclaration( + source: t.StringLiteral, +): t.DeclareExportAllDeclaration { + return builder("DeclareExportAllDeclaration", ...arguments); +} +export function declaredPredicate(value: t.Flow): t.DeclaredPredicate { + return builder("DeclaredPredicate", ...arguments); +} +export function existsTypeAnnotation(): t.ExistsTypeAnnotation { + return builder("ExistsTypeAnnotation", ...arguments); +} +export function functionTypeAnnotation( + typeParameters: t.TypeParameterDeclaration | null | undefined, + params: Array, + rest: t.FunctionTypeParam | null | undefined, + returnType: t.FlowType, +): t.FunctionTypeAnnotation { + return builder("FunctionTypeAnnotation", ...arguments); +} +export function functionTypeParam( + name: t.Identifier | null | undefined, + typeAnnotation: t.FlowType, +): t.FunctionTypeParam { + return builder("FunctionTypeParam", ...arguments); +} +export function genericTypeAnnotation( + id: t.Identifier | t.QualifiedTypeIdentifier, + typeParameters?: t.TypeParameterInstantiation | null, +): t.GenericTypeAnnotation { + return builder("GenericTypeAnnotation", ...arguments); +} +export function inferredPredicate(): t.InferredPredicate { + return builder("InferredPredicate", ...arguments); +} +export function interfaceExtends( + id: t.Identifier | t.QualifiedTypeIdentifier, + typeParameters?: t.TypeParameterInstantiation | null, +): t.InterfaceExtends { + return builder("InterfaceExtends", ...arguments); +} +export function interfaceDeclaration( + id: t.Identifier, + typeParameters: t.TypeParameterDeclaration | null | undefined, + _extends: Array | null | undefined, + body: t.ObjectTypeAnnotation, +): t.InterfaceDeclaration { + return builder("InterfaceDeclaration", ...arguments); +} +export function interfaceTypeAnnotation( + _extends: Array | null | undefined, + body: t.ObjectTypeAnnotation, +): t.InterfaceTypeAnnotation { + return builder("InterfaceTypeAnnotation", ...arguments); +} +export function intersectionTypeAnnotation( + types: Array, +): t.IntersectionTypeAnnotation { + return builder("IntersectionTypeAnnotation", ...arguments); +} +export function mixedTypeAnnotation(): t.MixedTypeAnnotation { + return builder("MixedTypeAnnotation", ...arguments); +} +export function emptyTypeAnnotation(): t.EmptyTypeAnnotation { + return builder("EmptyTypeAnnotation", ...arguments); +} +export function nullableTypeAnnotation( + typeAnnotation: t.FlowType, +): t.NullableTypeAnnotation { + return builder("NullableTypeAnnotation", ...arguments); +} +export function numberLiteralTypeAnnotation( + value: number, +): t.NumberLiteralTypeAnnotation { + return builder("NumberLiteralTypeAnnotation", ...arguments); +} +export function numberTypeAnnotation(): t.NumberTypeAnnotation { + return builder("NumberTypeAnnotation", ...arguments); +} +export function objectTypeAnnotation( + properties: Array, + indexers?: Array | null, + callProperties?: Array | null, + internalSlots?: Array | null, + exact?: boolean, +): t.ObjectTypeAnnotation { + return builder("ObjectTypeAnnotation", ...arguments); +} +export function objectTypeInternalSlot( + id: t.Identifier, + value: t.FlowType, + optional: boolean, + _static: boolean, + method: boolean, +): t.ObjectTypeInternalSlot { + return builder("ObjectTypeInternalSlot", ...arguments); +} +export function objectTypeCallProperty( + value: t.FlowType, +): t.ObjectTypeCallProperty { + return builder("ObjectTypeCallProperty", ...arguments); +} +export function objectTypeIndexer( + id: t.Identifier | null | undefined, + key: t.FlowType, + value: t.FlowType, + variance?: t.Variance | null, +): t.ObjectTypeIndexer { + return builder("ObjectTypeIndexer", ...arguments); +} +export function objectTypeProperty( + key: t.Identifier | t.StringLiteral, + value: t.FlowType, + variance?: t.Variance | null, +): t.ObjectTypeProperty { + return builder("ObjectTypeProperty", ...arguments); +} +export function objectTypeSpreadProperty( + argument: t.FlowType, +): t.ObjectTypeSpreadProperty { + return builder("ObjectTypeSpreadProperty", ...arguments); +} +export function opaqueType( + id: t.Identifier, + typeParameters: t.TypeParameterDeclaration | null | undefined, + supertype: t.FlowType | null | undefined, + impltype: t.FlowType, +): t.OpaqueType { + return builder("OpaqueType", ...arguments); +} +export function qualifiedTypeIdentifier( + id: t.Identifier, + qualification: t.Identifier | t.QualifiedTypeIdentifier, +): t.QualifiedTypeIdentifier { + return builder("QualifiedTypeIdentifier", ...arguments); +} +export function stringLiteralTypeAnnotation( + value: string, +): t.StringLiteralTypeAnnotation { + return builder("StringLiteralTypeAnnotation", ...arguments); +} +export function stringTypeAnnotation(): t.StringTypeAnnotation { + return builder("StringTypeAnnotation", ...arguments); +} +export function symbolTypeAnnotation(): t.SymbolTypeAnnotation { + return builder("SymbolTypeAnnotation", ...arguments); +} +export function thisTypeAnnotation(): t.ThisTypeAnnotation { + return builder("ThisTypeAnnotation", ...arguments); +} +export function tupleTypeAnnotation( + types: Array, +): t.TupleTypeAnnotation { + return builder("TupleTypeAnnotation", ...arguments); +} +export function typeofTypeAnnotation( + argument: t.FlowType, +): t.TypeofTypeAnnotation { + return builder("TypeofTypeAnnotation", ...arguments); +} +export function typeAlias( + id: t.Identifier, + typeParameters: t.TypeParameterDeclaration | null | undefined, + right: t.FlowType, +): t.TypeAlias { + return builder("TypeAlias", ...arguments); +} +export function typeAnnotation(typeAnnotation: t.FlowType): t.TypeAnnotation { + return builder("TypeAnnotation", ...arguments); +} +export function typeCastExpression( + expression: t.Expression, + typeAnnotation: t.TypeAnnotation, +): t.TypeCastExpression { + return builder("TypeCastExpression", ...arguments); +} +export function typeParameter( + bound?: t.TypeAnnotation | null, + _default?: t.FlowType | null, + variance?: t.Variance | null, +): t.TypeParameter { + return builder("TypeParameter", ...arguments); +} +export function typeParameterDeclaration( + params: Array, +): t.TypeParameterDeclaration { + return builder("TypeParameterDeclaration", ...arguments); +} +export function typeParameterInstantiation( + params: Array, +): t.TypeParameterInstantiation { + return builder("TypeParameterInstantiation", ...arguments); +} +export function unionTypeAnnotation( + types: Array, +): t.UnionTypeAnnotation { + return builder("UnionTypeAnnotation", ...arguments); +} +export function variance(kind: "minus" | "plus"): t.Variance { + return builder("Variance", ...arguments); +} +export function voidTypeAnnotation(): t.VoidTypeAnnotation { + return builder("VoidTypeAnnotation", ...arguments); +} +export function enumDeclaration( + id: t.Identifier, + body: + | t.EnumBooleanBody + | t.EnumNumberBody + | t.EnumStringBody + | t.EnumSymbolBody, +): t.EnumDeclaration { + return builder("EnumDeclaration", ...arguments); +} +export function enumBooleanBody( + members: Array, +): t.EnumBooleanBody { + return builder("EnumBooleanBody", ...arguments); +} +export function enumNumberBody( + members: Array, +): t.EnumNumberBody { + return builder("EnumNumberBody", ...arguments); +} +export function enumStringBody( + members: Array, +): t.EnumStringBody { + return builder("EnumStringBody", ...arguments); +} +export function enumSymbolBody( + members: Array, +): t.EnumSymbolBody { + return builder("EnumSymbolBody", ...arguments); +} +export function enumBooleanMember(id: t.Identifier): t.EnumBooleanMember { + return builder("EnumBooleanMember", ...arguments); +} +export function enumNumberMember( + id: t.Identifier, + init: t.NumericLiteral, +): t.EnumNumberMember { + return builder("EnumNumberMember", ...arguments); +} +export function enumStringMember( + id: t.Identifier, + init: t.StringLiteral, +): t.EnumStringMember { + return builder("EnumStringMember", ...arguments); +} +export function enumDefaultedMember(id: t.Identifier): t.EnumDefaultedMember { + return builder("EnumDefaultedMember", ...arguments); +} +export function jsxAttribute( + name: t.JSXIdentifier | t.JSXNamespacedName, + value?: + | t.JSXElement + | t.JSXFragment + | t.StringLiteral + | t.JSXExpressionContainer + | null, +): t.JSXAttribute { + return builder("JSXAttribute", ...arguments); } -export { bigIntLiteral as BigIntLiteral }; -export function exportNamespaceSpecifier(...args: Array): Object { - return builder("ExportNamespaceSpecifier", ...args); -} -export { exportNamespaceSpecifier as ExportNamespaceSpecifier }; -export function optionalMemberExpression(...args: Array): Object { - return builder("OptionalMemberExpression", ...args); -} -export { optionalMemberExpression as OptionalMemberExpression }; -export function optionalCallExpression(...args: Array): Object { - return builder("OptionalCallExpression", ...args); -} -export { optionalCallExpression as OptionalCallExpression }; -export function anyTypeAnnotation(...args: Array): Object { - return builder("AnyTypeAnnotation", ...args); -} -export { anyTypeAnnotation as AnyTypeAnnotation }; -export function arrayTypeAnnotation(...args: Array): Object { - return builder("ArrayTypeAnnotation", ...args); -} -export { arrayTypeAnnotation as ArrayTypeAnnotation }; -export function booleanTypeAnnotation(...args: Array): Object { - return builder("BooleanTypeAnnotation", ...args); -} -export { booleanTypeAnnotation as BooleanTypeAnnotation }; -export function booleanLiteralTypeAnnotation(...args: Array): Object { - return builder("BooleanLiteralTypeAnnotation", ...args); -} -export { booleanLiteralTypeAnnotation as BooleanLiteralTypeAnnotation }; -export function nullLiteralTypeAnnotation(...args: Array): Object { - return builder("NullLiteralTypeAnnotation", ...args); -} -export { nullLiteralTypeAnnotation as NullLiteralTypeAnnotation }; -export function classImplements(...args: Array): Object { - return builder("ClassImplements", ...args); -} -export { classImplements as ClassImplements }; -export function declareClass(...args: Array): Object { - return builder("DeclareClass", ...args); -} -export { declareClass as DeclareClass }; -export function declareFunction(...args: Array): Object { - return builder("DeclareFunction", ...args); -} -export { declareFunction as DeclareFunction }; -export function declareInterface(...args: Array): Object { - return builder("DeclareInterface", ...args); -} -export { declareInterface as DeclareInterface }; -export function declareModule(...args: Array): Object { - return builder("DeclareModule", ...args); -} -export { declareModule as DeclareModule }; -export function declareModuleExports(...args: Array): Object { - return builder("DeclareModuleExports", ...args); -} -export { declareModuleExports as DeclareModuleExports }; -export function declareTypeAlias(...args: Array): Object { - return builder("DeclareTypeAlias", ...args); -} -export { declareTypeAlias as DeclareTypeAlias }; -export function declareOpaqueType(...args: Array): Object { - return builder("DeclareOpaqueType", ...args); -} -export { declareOpaqueType as DeclareOpaqueType }; -export function declareVariable(...args: Array): Object { - return builder("DeclareVariable", ...args); -} -export { declareVariable as DeclareVariable }; -export function declareExportDeclaration(...args: Array): Object { - return builder("DeclareExportDeclaration", ...args); -} -export { declareExportDeclaration as DeclareExportDeclaration }; -export function declareExportAllDeclaration(...args: Array): Object { - return builder("DeclareExportAllDeclaration", ...args); -} -export { declareExportAllDeclaration as DeclareExportAllDeclaration }; -export function declaredPredicate(...args: Array): Object { - return builder("DeclaredPredicate", ...args); -} -export { declaredPredicate as DeclaredPredicate }; -export function existsTypeAnnotation(...args: Array): Object { - return builder("ExistsTypeAnnotation", ...args); -} -export { existsTypeAnnotation as ExistsTypeAnnotation }; -export function functionTypeAnnotation(...args: Array): Object { - return builder("FunctionTypeAnnotation", ...args); -} -export { functionTypeAnnotation as FunctionTypeAnnotation }; -export function functionTypeParam(...args: Array): Object { - return builder("FunctionTypeParam", ...args); -} -export { functionTypeParam as FunctionTypeParam }; -export function genericTypeAnnotation(...args: Array): Object { - return builder("GenericTypeAnnotation", ...args); -} -export { genericTypeAnnotation as GenericTypeAnnotation }; -export function inferredPredicate(...args: Array): Object { - return builder("InferredPredicate", ...args); -} -export { inferredPredicate as InferredPredicate }; -export function interfaceExtends(...args: Array): Object { - return builder("InterfaceExtends", ...args); -} -export { interfaceExtends as InterfaceExtends }; -export function interfaceDeclaration(...args: Array): Object { - return builder("InterfaceDeclaration", ...args); -} -export { interfaceDeclaration as InterfaceDeclaration }; -export function interfaceTypeAnnotation(...args: Array): Object { - return builder("InterfaceTypeAnnotation", ...args); -} -export { interfaceTypeAnnotation as InterfaceTypeAnnotation }; -export function intersectionTypeAnnotation(...args: Array): Object { - return builder("IntersectionTypeAnnotation", ...args); -} -export { intersectionTypeAnnotation as IntersectionTypeAnnotation }; -export function mixedTypeAnnotation(...args: Array): Object { - return builder("MixedTypeAnnotation", ...args); -} -export { mixedTypeAnnotation as MixedTypeAnnotation }; -export function emptyTypeAnnotation(...args: Array): Object { - return builder("EmptyTypeAnnotation", ...args); -} -export { emptyTypeAnnotation as EmptyTypeAnnotation }; -export function nullableTypeAnnotation(...args: Array): Object { - return builder("NullableTypeAnnotation", ...args); -} -export { nullableTypeAnnotation as NullableTypeAnnotation }; -export function numberLiteralTypeAnnotation(...args: Array): Object { - return builder("NumberLiteralTypeAnnotation", ...args); -} -export { numberLiteralTypeAnnotation as NumberLiteralTypeAnnotation }; -export function numberTypeAnnotation(...args: Array): Object { - return builder("NumberTypeAnnotation", ...args); -} -export { numberTypeAnnotation as NumberTypeAnnotation }; -export function objectTypeAnnotation(...args: Array): Object { - return builder("ObjectTypeAnnotation", ...args); -} -export { objectTypeAnnotation as ObjectTypeAnnotation }; -export function objectTypeInternalSlot(...args: Array): Object { - return builder("ObjectTypeInternalSlot", ...args); -} -export { objectTypeInternalSlot as ObjectTypeInternalSlot }; -export function objectTypeCallProperty(...args: Array): Object { - return builder("ObjectTypeCallProperty", ...args); -} -export { objectTypeCallProperty as ObjectTypeCallProperty }; -export function objectTypeIndexer(...args: Array): Object { - return builder("ObjectTypeIndexer", ...args); -} -export { objectTypeIndexer as ObjectTypeIndexer }; -export function objectTypeProperty(...args: Array): Object { - return builder("ObjectTypeProperty", ...args); -} -export { objectTypeProperty as ObjectTypeProperty }; -export function objectTypeSpreadProperty(...args: Array): Object { - return builder("ObjectTypeSpreadProperty", ...args); -} -export { objectTypeSpreadProperty as ObjectTypeSpreadProperty }; -export function opaqueType(...args: Array): Object { - return builder("OpaqueType", ...args); -} -export { opaqueType as OpaqueType }; -export function qualifiedTypeIdentifier(...args: Array): Object { - return builder("QualifiedTypeIdentifier", ...args); -} -export { qualifiedTypeIdentifier as QualifiedTypeIdentifier }; -export function stringLiteralTypeAnnotation(...args: Array): Object { - return builder("StringLiteralTypeAnnotation", ...args); -} -export { stringLiteralTypeAnnotation as StringLiteralTypeAnnotation }; -export function stringTypeAnnotation(...args: Array): Object { - return builder("StringTypeAnnotation", ...args); -} -export { stringTypeAnnotation as StringTypeAnnotation }; -export function symbolTypeAnnotation(...args: Array): Object { - return builder("SymbolTypeAnnotation", ...args); -} -export { symbolTypeAnnotation as SymbolTypeAnnotation }; -export function thisTypeAnnotation(...args: Array): Object { - return builder("ThisTypeAnnotation", ...args); -} -export { thisTypeAnnotation as ThisTypeAnnotation }; -export function tupleTypeAnnotation(...args: Array): Object { - return builder("TupleTypeAnnotation", ...args); -} -export { tupleTypeAnnotation as TupleTypeAnnotation }; -export function typeofTypeAnnotation(...args: Array): Object { - return builder("TypeofTypeAnnotation", ...args); -} -export { typeofTypeAnnotation as TypeofTypeAnnotation }; -export function typeAlias(...args: Array): Object { - return builder("TypeAlias", ...args); -} -export { typeAlias as TypeAlias }; -export function typeAnnotation(...args: Array): Object { - return builder("TypeAnnotation", ...args); -} -export { typeAnnotation as TypeAnnotation }; -export function typeCastExpression(...args: Array): Object { - return builder("TypeCastExpression", ...args); -} -export { typeCastExpression as TypeCastExpression }; -export function typeParameter(...args: Array): Object { - return builder("TypeParameter", ...args); -} -export { typeParameter as TypeParameter }; -export function typeParameterDeclaration(...args: Array): Object { - return builder("TypeParameterDeclaration", ...args); -} -export { typeParameterDeclaration as TypeParameterDeclaration }; -export function typeParameterInstantiation(...args: Array): Object { - return builder("TypeParameterInstantiation", ...args); -} -export { typeParameterInstantiation as TypeParameterInstantiation }; -export function unionTypeAnnotation(...args: Array): Object { - return builder("UnionTypeAnnotation", ...args); -} -export { unionTypeAnnotation as UnionTypeAnnotation }; -export function variance(...args: Array): Object { - return builder("Variance", ...args); -} -export { variance as Variance }; -export function voidTypeAnnotation(...args: Array): Object { - return builder("VoidTypeAnnotation", ...args); -} -export { voidTypeAnnotation as VoidTypeAnnotation }; -export function enumDeclaration(...args: Array): Object { - return builder("EnumDeclaration", ...args); -} -export { enumDeclaration as EnumDeclaration }; -export function enumBooleanBody(...args: Array): Object { - return builder("EnumBooleanBody", ...args); -} -export { enumBooleanBody as EnumBooleanBody }; -export function enumNumberBody(...args: Array): Object { - return builder("EnumNumberBody", ...args); -} -export { enumNumberBody as EnumNumberBody }; -export function enumStringBody(...args: Array): Object { - return builder("EnumStringBody", ...args); -} -export { enumStringBody as EnumStringBody }; -export function enumSymbolBody(...args: Array): Object { - return builder("EnumSymbolBody", ...args); -} -export { enumSymbolBody as EnumSymbolBody }; -export function enumBooleanMember(...args: Array): Object { - return builder("EnumBooleanMember", ...args); -} -export { enumBooleanMember as EnumBooleanMember }; -export function enumNumberMember(...args: Array): Object { - return builder("EnumNumberMember", ...args); -} -export { enumNumberMember as EnumNumberMember }; -export function enumStringMember(...args: Array): Object { - return builder("EnumStringMember", ...args); -} -export { enumStringMember as EnumStringMember }; -export function enumDefaultedMember(...args: Array): Object { - return builder("EnumDefaultedMember", ...args); -} -export { enumDefaultedMember as EnumDefaultedMember }; -export function jsxAttribute(...args: Array): Object { - return builder("JSXAttribute", ...args); -} -export { jsxAttribute as JSXAttribute }; export { jsxAttribute as jSXAttribute }; -export function jsxClosingElement(...args: Array): Object { - return builder("JSXClosingElement", ...args); +export function jsxClosingElement( + name: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName, +): t.JSXClosingElement { + return builder("JSXClosingElement", ...arguments); } -export { jsxClosingElement as JSXClosingElement }; export { jsxClosingElement as jSXClosingElement }; -export function jsxElement(...args: Array): Object { - return builder("JSXElement", ...args); +export function jsxElement( + openingElement: t.JSXOpeningElement, + closingElement: t.JSXClosingElement | null | undefined, + children: Array< + | t.JSXText + | t.JSXExpressionContainer + | t.JSXSpreadChild + | t.JSXElement + | t.JSXFragment + >, + selfClosing?: boolean | null, +): t.JSXElement { + return builder("JSXElement", ...arguments); } -export { jsxElement as JSXElement }; export { jsxElement as jSXElement }; -export function jsxEmptyExpression(...args: Array): Object { - return builder("JSXEmptyExpression", ...args); +export function jsxEmptyExpression(): t.JSXEmptyExpression { + return builder("JSXEmptyExpression", ...arguments); } -export { jsxEmptyExpression as JSXEmptyExpression }; export { jsxEmptyExpression as jSXEmptyExpression }; -export function jsxExpressionContainer(...args: Array): Object { - return builder("JSXExpressionContainer", ...args); +export function jsxExpressionContainer( + expression: t.Expression | t.JSXEmptyExpression, +): t.JSXExpressionContainer { + return builder("JSXExpressionContainer", ...arguments); } -export { jsxExpressionContainer as JSXExpressionContainer }; export { jsxExpressionContainer as jSXExpressionContainer }; -export function jsxSpreadChild(...args: Array): Object { - return builder("JSXSpreadChild", ...args); +export function jsxSpreadChild(expression: t.Expression): t.JSXSpreadChild { + return builder("JSXSpreadChild", ...arguments); } -export { jsxSpreadChild as JSXSpreadChild }; export { jsxSpreadChild as jSXSpreadChild }; -export function jsxIdentifier(...args: Array): Object { - return builder("JSXIdentifier", ...args); +export function jsxIdentifier(name: string): t.JSXIdentifier { + return builder("JSXIdentifier", ...arguments); } -export { jsxIdentifier as JSXIdentifier }; export { jsxIdentifier as jSXIdentifier }; -export function jsxMemberExpression(...args: Array): Object { - return builder("JSXMemberExpression", ...args); +export function jsxMemberExpression( + object: t.JSXMemberExpression | t.JSXIdentifier, + property: t.JSXIdentifier, +): t.JSXMemberExpression { + return builder("JSXMemberExpression", ...arguments); } -export { jsxMemberExpression as JSXMemberExpression }; export { jsxMemberExpression as jSXMemberExpression }; -export function jsxNamespacedName(...args: Array): Object { - return builder("JSXNamespacedName", ...args); +export function jsxNamespacedName( + namespace: t.JSXIdentifier, + name: t.JSXIdentifier, +): t.JSXNamespacedName { + return builder("JSXNamespacedName", ...arguments); } -export { jsxNamespacedName as JSXNamespacedName }; export { jsxNamespacedName as jSXNamespacedName }; -export function jsxOpeningElement(...args: Array): Object { - return builder("JSXOpeningElement", ...args); +export function jsxOpeningElement( + name: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName, + attributes: Array, + selfClosing?: boolean, +): t.JSXOpeningElement { + return builder("JSXOpeningElement", ...arguments); } -export { jsxOpeningElement as JSXOpeningElement }; export { jsxOpeningElement as jSXOpeningElement }; -export function jsxSpreadAttribute(...args: Array): Object { - return builder("JSXSpreadAttribute", ...args); +export function jsxSpreadAttribute( + argument: t.Expression, +): t.JSXSpreadAttribute { + return builder("JSXSpreadAttribute", ...arguments); } -export { jsxSpreadAttribute as JSXSpreadAttribute }; export { jsxSpreadAttribute as jSXSpreadAttribute }; -export function jsxText(...args: Array): Object { - return builder("JSXText", ...args); +export function jsxText(value: string): t.JSXText { + return builder("JSXText", ...arguments); } -export { jsxText as JSXText }; export { jsxText as jSXText }; -export function jsxFragment(...args: Array): Object { - return builder("JSXFragment", ...args); +export function jsxFragment( + openingFragment: t.JSXOpeningFragment, + closingFragment: t.JSXClosingFragment, + children: Array< + | t.JSXText + | t.JSXExpressionContainer + | t.JSXSpreadChild + | t.JSXElement + | t.JSXFragment + >, +): t.JSXFragment { + return builder("JSXFragment", ...arguments); } -export { jsxFragment as JSXFragment }; export { jsxFragment as jSXFragment }; -export function jsxOpeningFragment(...args: Array): Object { - return builder("JSXOpeningFragment", ...args); +export function jsxOpeningFragment(): t.JSXOpeningFragment { + return builder("JSXOpeningFragment", ...arguments); } -export { jsxOpeningFragment as JSXOpeningFragment }; export { jsxOpeningFragment as jSXOpeningFragment }; -export function jsxClosingFragment(...args: Array): Object { - return builder("JSXClosingFragment", ...args); +export function jsxClosingFragment(): t.JSXClosingFragment { + return builder("JSXClosingFragment", ...arguments); } -export { jsxClosingFragment as JSXClosingFragment }; export { jsxClosingFragment as jSXClosingFragment }; -export function noop(...args: Array): Object { - return builder("Noop", ...args); +export function noop(): t.Noop { + return builder("Noop", ...arguments); } -export { noop as Noop }; -export function placeholder(...args: Array): Object { - return builder("Placeholder", ...args); +export function placeholder( + expectedNode: + | "Identifier" + | "StringLiteral" + | "Expression" + | "Statement" + | "Declaration" + | "BlockStatement" + | "ClassBody" + | "Pattern", + name: t.Identifier, +): t.Placeholder { + return builder("Placeholder", ...arguments); } -export { placeholder as Placeholder }; -export function v8IntrinsicIdentifier(...args: Array): Object { - return builder("V8IntrinsicIdentifier", ...args); +export function v8IntrinsicIdentifier(name: string): t.V8IntrinsicIdentifier { + return builder("V8IntrinsicIdentifier", ...arguments); } -export { v8IntrinsicIdentifier as V8IntrinsicIdentifier }; -export function argumentPlaceholder(...args: Array): Object { - return builder("ArgumentPlaceholder", ...args); +export function argumentPlaceholder(): t.ArgumentPlaceholder { + return builder("ArgumentPlaceholder", ...arguments); } -export { argumentPlaceholder as ArgumentPlaceholder }; -export function bindExpression(...args: Array): Object { - return builder("BindExpression", ...args); +export function bindExpression( + object: t.Expression, + callee: t.Expression, +): t.BindExpression { + return builder("BindExpression", ...arguments); } -export { bindExpression as BindExpression }; -export function classProperty(...args: Array): Object { - return builder("ClassProperty", ...args); +export function classProperty( + key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.Expression, + value?: t.Expression | null, + typeAnnotation?: t.TypeAnnotation | t.TSTypeAnnotation | t.Noop | null, + decorators?: Array | null, + computed?: boolean, + _static?: boolean, +): t.ClassProperty { + return builder("ClassProperty", ...arguments); } -export { classProperty as ClassProperty }; -export function pipelineTopicExpression(...args: Array): Object { - return builder("PipelineTopicExpression", ...args); +export function pipelineTopicExpression( + expression: t.Expression, +): t.PipelineTopicExpression { + return builder("PipelineTopicExpression", ...arguments); } -export { pipelineTopicExpression as PipelineTopicExpression }; -export function pipelineBareFunction(...args: Array): Object { - return builder("PipelineBareFunction", ...args); +export function pipelineBareFunction( + callee: t.Expression, +): t.PipelineBareFunction { + return builder("PipelineBareFunction", ...arguments); } -export { pipelineBareFunction as PipelineBareFunction }; -export function pipelinePrimaryTopicReference(...args: Array): Object { - return builder("PipelinePrimaryTopicReference", ...args); +export function pipelinePrimaryTopicReference(): t.PipelinePrimaryTopicReference { + return builder("PipelinePrimaryTopicReference", ...arguments); } -export { pipelinePrimaryTopicReference as PipelinePrimaryTopicReference }; -export function classPrivateProperty(...args: Array): Object { - return builder("ClassPrivateProperty", ...args); +export function classPrivateProperty( + key: t.PrivateName, + value: t.Expression | null | undefined, + decorators: Array | null | undefined, + _static: any, +): t.ClassPrivateProperty { + return builder("ClassPrivateProperty", ...arguments); } -export { classPrivateProperty as ClassPrivateProperty }; -export function classPrivateMethod(...args: Array): Object { - return builder("ClassPrivateMethod", ...args); +export function classPrivateMethod( + kind: "get" | "set" | "method" | "constructor" | undefined, + key: t.PrivateName, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + body: t.BlockStatement, + _static?: boolean, +): t.ClassPrivateMethod { + return builder("ClassPrivateMethod", ...arguments); } -export { classPrivateMethod as ClassPrivateMethod }; -export function importAttribute(...args: Array): Object { - return builder("ImportAttribute", ...args); +export function importAttribute( + key: t.Identifier | t.StringLiteral, + value: t.StringLiteral, +): t.ImportAttribute { + return builder("ImportAttribute", ...arguments); } -export { importAttribute as ImportAttribute }; -export function decorator(...args: Array): Object { - return builder("Decorator", ...args); +export function decorator(expression: t.Expression): t.Decorator { + return builder("Decorator", ...arguments); } -export { decorator as Decorator }; -export function doExpression(...args: Array): Object { - return builder("DoExpression", ...args); +export function doExpression(body: t.BlockStatement): t.DoExpression { + return builder("DoExpression", ...arguments); } -export { doExpression as DoExpression }; -export function exportDefaultSpecifier(...args: Array): Object { - return builder("ExportDefaultSpecifier", ...args); +export function exportDefaultSpecifier( + exported: t.Identifier, +): t.ExportDefaultSpecifier { + return builder("ExportDefaultSpecifier", ...arguments); } -export { exportDefaultSpecifier as ExportDefaultSpecifier }; -export function privateName(...args: Array): Object { - return builder("PrivateName", ...args); +export function privateName(id: t.Identifier): t.PrivateName { + return builder("PrivateName", ...arguments); } -export { privateName as PrivateName }; -export function recordExpression(...args: Array): Object { - return builder("RecordExpression", ...args); +export function recordExpression( + properties: Array, +): t.RecordExpression { + return builder("RecordExpression", ...arguments); } -export { recordExpression as RecordExpression }; -export function tupleExpression(...args: Array): Object { - return builder("TupleExpression", ...args); +export function tupleExpression( + elements?: Array, +): t.TupleExpression { + return builder("TupleExpression", ...arguments); } -export { tupleExpression as TupleExpression }; -export function decimalLiteral(...args: Array): Object { - return builder("DecimalLiteral", ...args); +export function decimalLiteral(value: string): t.DecimalLiteral { + return builder("DecimalLiteral", ...arguments); } -export { decimalLiteral as DecimalLiteral }; -export function staticBlock(...args: Array): Object { - return builder("StaticBlock", ...args); +export function staticBlock(body: Array): t.StaticBlock { + return builder("StaticBlock", ...arguments); } -export { staticBlock as StaticBlock }; -export function tsParameterProperty(...args: Array): Object { - return builder("TSParameterProperty", ...args); +export function tsParameterProperty( + parameter: t.Identifier | t.AssignmentPattern, +): t.TSParameterProperty { + return builder("TSParameterProperty", ...arguments); } -export { tsParameterProperty as TSParameterProperty }; export { tsParameterProperty as tSParameterProperty }; -export function tsDeclareFunction(...args: Array): Object { - return builder("TSDeclareFunction", ...args); +export function tsDeclareFunction( + id: t.Identifier | null | undefined, + typeParameters: t.TSTypeParameterDeclaration | t.Noop | null | undefined, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + returnType?: t.TSTypeAnnotation | t.Noop | null, +): t.TSDeclareFunction { + return builder("TSDeclareFunction", ...arguments); } -export { tsDeclareFunction as TSDeclareFunction }; export { tsDeclareFunction as tSDeclareFunction }; -export function tsDeclareMethod(...args: Array): Object { - return builder("TSDeclareMethod", ...args); +export function tsDeclareMethod( + decorators: Array | null | undefined, + key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.Expression, + typeParameters: t.TSTypeParameterDeclaration | t.Noop | null | undefined, + params: Array< + t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty + >, + returnType?: t.TSTypeAnnotation | t.Noop | null, +): t.TSDeclareMethod { + return builder("TSDeclareMethod", ...arguments); } -export { tsDeclareMethod as TSDeclareMethod }; export { tsDeclareMethod as tSDeclareMethod }; -export function tsQualifiedName(...args: Array): Object { - return builder("TSQualifiedName", ...args); +export function tsQualifiedName( + left: t.TSEntityName, + right: t.Identifier, +): t.TSQualifiedName { + return builder("TSQualifiedName", ...arguments); } -export { tsQualifiedName as TSQualifiedName }; export { tsQualifiedName as tSQualifiedName }; -export function tsCallSignatureDeclaration(...args: Array): Object { - return builder("TSCallSignatureDeclaration", ...args); +export function tsCallSignatureDeclaration( + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + parameters: Array, + typeAnnotation?: t.TSTypeAnnotation | null, +): t.TSCallSignatureDeclaration { + return builder("TSCallSignatureDeclaration", ...arguments); } -export { tsCallSignatureDeclaration as TSCallSignatureDeclaration }; export { tsCallSignatureDeclaration as tSCallSignatureDeclaration }; -export function tsConstructSignatureDeclaration(...args: Array): Object { - return builder("TSConstructSignatureDeclaration", ...args); +export function tsConstructSignatureDeclaration( + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + parameters: Array, + typeAnnotation?: t.TSTypeAnnotation | null, +): t.TSConstructSignatureDeclaration { + return builder("TSConstructSignatureDeclaration", ...arguments); } -export { tsConstructSignatureDeclaration as TSConstructSignatureDeclaration }; export { tsConstructSignatureDeclaration as tSConstructSignatureDeclaration }; -export function tsPropertySignature(...args: Array): Object { - return builder("TSPropertySignature", ...args); +export function tsPropertySignature( + key: t.Expression, + typeAnnotation?: t.TSTypeAnnotation | null, + initializer?: t.Expression | null, +): t.TSPropertySignature { + return builder("TSPropertySignature", ...arguments); } -export { tsPropertySignature as TSPropertySignature }; export { tsPropertySignature as tSPropertySignature }; -export function tsMethodSignature(...args: Array): Object { - return builder("TSMethodSignature", ...args); +export function tsMethodSignature( + key: t.Expression, + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + parameters: Array, + typeAnnotation?: t.TSTypeAnnotation | null, +): t.TSMethodSignature { + return builder("TSMethodSignature", ...arguments); } -export { tsMethodSignature as TSMethodSignature }; export { tsMethodSignature as tSMethodSignature }; -export function tsIndexSignature(...args: Array): Object { - return builder("TSIndexSignature", ...args); +export function tsIndexSignature( + parameters: Array, + typeAnnotation?: t.TSTypeAnnotation | null, +): t.TSIndexSignature { + return builder("TSIndexSignature", ...arguments); } -export { tsIndexSignature as TSIndexSignature }; export { tsIndexSignature as tSIndexSignature }; -export function tsAnyKeyword(...args: Array): Object { - return builder("TSAnyKeyword", ...args); +export function tsAnyKeyword(): t.TSAnyKeyword { + return builder("TSAnyKeyword", ...arguments); } -export { tsAnyKeyword as TSAnyKeyword }; export { tsAnyKeyword as tSAnyKeyword }; -export function tsBooleanKeyword(...args: Array): Object { - return builder("TSBooleanKeyword", ...args); +export function tsBooleanKeyword(): t.TSBooleanKeyword { + return builder("TSBooleanKeyword", ...arguments); } -export { tsBooleanKeyword as TSBooleanKeyword }; export { tsBooleanKeyword as tSBooleanKeyword }; -export function tsBigIntKeyword(...args: Array): Object { - return builder("TSBigIntKeyword", ...args); +export function tsBigIntKeyword(): t.TSBigIntKeyword { + return builder("TSBigIntKeyword", ...arguments); } -export { tsBigIntKeyword as TSBigIntKeyword }; export { tsBigIntKeyword as tSBigIntKeyword }; -export function tsIntrinsicKeyword(...args: Array): Object { - return builder("TSIntrinsicKeyword", ...args); +export function tsIntrinsicKeyword(): t.TSIntrinsicKeyword { + return builder("TSIntrinsicKeyword", ...arguments); } -export { tsIntrinsicKeyword as TSIntrinsicKeyword }; export { tsIntrinsicKeyword as tSIntrinsicKeyword }; -export function tsNeverKeyword(...args: Array): Object { - return builder("TSNeverKeyword", ...args); +export function tsNeverKeyword(): t.TSNeverKeyword { + return builder("TSNeverKeyword", ...arguments); } -export { tsNeverKeyword as TSNeverKeyword }; export { tsNeverKeyword as tSNeverKeyword }; -export function tsNullKeyword(...args: Array): Object { - return builder("TSNullKeyword", ...args); +export function tsNullKeyword(): t.TSNullKeyword { + return builder("TSNullKeyword", ...arguments); } -export { tsNullKeyword as TSNullKeyword }; export { tsNullKeyword as tSNullKeyword }; -export function tsNumberKeyword(...args: Array): Object { - return builder("TSNumberKeyword", ...args); +export function tsNumberKeyword(): t.TSNumberKeyword { + return builder("TSNumberKeyword", ...arguments); } -export { tsNumberKeyword as TSNumberKeyword }; export { tsNumberKeyword as tSNumberKeyword }; -export function tsObjectKeyword(...args: Array): Object { - return builder("TSObjectKeyword", ...args); +export function tsObjectKeyword(): t.TSObjectKeyword { + return builder("TSObjectKeyword", ...arguments); } -export { tsObjectKeyword as TSObjectKeyword }; export { tsObjectKeyword as tSObjectKeyword }; -export function tsStringKeyword(...args: Array): Object { - return builder("TSStringKeyword", ...args); +export function tsStringKeyword(): t.TSStringKeyword { + return builder("TSStringKeyword", ...arguments); } -export { tsStringKeyword as TSStringKeyword }; export { tsStringKeyword as tSStringKeyword }; -export function tsSymbolKeyword(...args: Array): Object { - return builder("TSSymbolKeyword", ...args); +export function tsSymbolKeyword(): t.TSSymbolKeyword { + return builder("TSSymbolKeyword", ...arguments); } -export { tsSymbolKeyword as TSSymbolKeyword }; export { tsSymbolKeyword as tSSymbolKeyword }; -export function tsUndefinedKeyword(...args: Array): Object { - return builder("TSUndefinedKeyword", ...args); +export function tsUndefinedKeyword(): t.TSUndefinedKeyword { + return builder("TSUndefinedKeyword", ...arguments); } -export { tsUndefinedKeyword as TSUndefinedKeyword }; export { tsUndefinedKeyword as tSUndefinedKeyword }; -export function tsUnknownKeyword(...args: Array): Object { - return builder("TSUnknownKeyword", ...args); +export function tsUnknownKeyword(): t.TSUnknownKeyword { + return builder("TSUnknownKeyword", ...arguments); } -export { tsUnknownKeyword as TSUnknownKeyword }; export { tsUnknownKeyword as tSUnknownKeyword }; -export function tsVoidKeyword(...args: Array): Object { - return builder("TSVoidKeyword", ...args); +export function tsVoidKeyword(): t.TSVoidKeyword { + return builder("TSVoidKeyword", ...arguments); } -export { tsVoidKeyword as TSVoidKeyword }; export { tsVoidKeyword as tSVoidKeyword }; -export function tsThisType(...args: Array): Object { - return builder("TSThisType", ...args); +export function tsThisType(): t.TSThisType { + return builder("TSThisType", ...arguments); } -export { tsThisType as TSThisType }; export { tsThisType as tSThisType }; -export function tsFunctionType(...args: Array): Object { - return builder("TSFunctionType", ...args); +export function tsFunctionType( + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + parameters: Array, + typeAnnotation?: t.TSTypeAnnotation | null, +): t.TSFunctionType { + return builder("TSFunctionType", ...arguments); } -export { tsFunctionType as TSFunctionType }; export { tsFunctionType as tSFunctionType }; -export function tsConstructorType(...args: Array): Object { - return builder("TSConstructorType", ...args); +export function tsConstructorType( + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + parameters: Array, + typeAnnotation?: t.TSTypeAnnotation | null, +): t.TSConstructorType { + return builder("TSConstructorType", ...arguments); } -export { tsConstructorType as TSConstructorType }; export { tsConstructorType as tSConstructorType }; -export function tsTypeReference(...args: Array): Object { - return builder("TSTypeReference", ...args); +export function tsTypeReference( + typeName: t.TSEntityName, + typeParameters?: t.TSTypeParameterInstantiation | null, +): t.TSTypeReference { + return builder("TSTypeReference", ...arguments); } -export { tsTypeReference as TSTypeReference }; export { tsTypeReference as tSTypeReference }; -export function tsTypePredicate(...args: Array): Object { - return builder("TSTypePredicate", ...args); +export function tsTypePredicate( + parameterName: t.Identifier | t.TSThisType, + typeAnnotation?: t.TSTypeAnnotation | null, + asserts?: boolean | null, +): t.TSTypePredicate { + return builder("TSTypePredicate", ...arguments); } -export { tsTypePredicate as TSTypePredicate }; export { tsTypePredicate as tSTypePredicate }; -export function tsTypeQuery(...args: Array): Object { - return builder("TSTypeQuery", ...args); +export function tsTypeQuery( + exprName: t.TSEntityName | t.TSImportType, +): t.TSTypeQuery { + return builder("TSTypeQuery", ...arguments); } -export { tsTypeQuery as TSTypeQuery }; export { tsTypeQuery as tSTypeQuery }; -export function tsTypeLiteral(...args: Array): Object { - return builder("TSTypeLiteral", ...args); +export function tsTypeLiteral( + members: Array, +): t.TSTypeLiteral { + return builder("TSTypeLiteral", ...arguments); } -export { tsTypeLiteral as TSTypeLiteral }; export { tsTypeLiteral as tSTypeLiteral }; -export function tsArrayType(...args: Array): Object { - return builder("TSArrayType", ...args); +export function tsArrayType(elementType: t.TSType): t.TSArrayType { + return builder("TSArrayType", ...arguments); } -export { tsArrayType as TSArrayType }; export { tsArrayType as tSArrayType }; -export function tsTupleType(...args: Array): Object { - return builder("TSTupleType", ...args); +export function tsTupleType( + elementTypes: Array, +): t.TSTupleType { + return builder("TSTupleType", ...arguments); } -export { tsTupleType as TSTupleType }; export { tsTupleType as tSTupleType }; -export function tsOptionalType(...args: Array): Object { - return builder("TSOptionalType", ...args); +export function tsOptionalType(typeAnnotation: t.TSType): t.TSOptionalType { + return builder("TSOptionalType", ...arguments); } -export { tsOptionalType as TSOptionalType }; export { tsOptionalType as tSOptionalType }; -export function tsRestType(...args: Array): Object { - return builder("TSRestType", ...args); +export function tsRestType(typeAnnotation: t.TSType): t.TSRestType { + return builder("TSRestType", ...arguments); } -export { tsRestType as TSRestType }; export { tsRestType as tSRestType }; -export function tsNamedTupleMember(...args: Array): Object { - return builder("TSNamedTupleMember", ...args); +export function tsNamedTupleMember( + label: t.Identifier, + elementType: t.TSType, + optional?: boolean, +): t.TSNamedTupleMember { + return builder("TSNamedTupleMember", ...arguments); } -export { tsNamedTupleMember as TSNamedTupleMember }; export { tsNamedTupleMember as tSNamedTupleMember }; -export function tsUnionType(...args: Array): Object { - return builder("TSUnionType", ...args); +export function tsUnionType(types: Array): t.TSUnionType { + return builder("TSUnionType", ...arguments); } -export { tsUnionType as TSUnionType }; export { tsUnionType as tSUnionType }; -export function tsIntersectionType(...args: Array): Object { - return builder("TSIntersectionType", ...args); +export function tsIntersectionType( + types: Array, +): t.TSIntersectionType { + return builder("TSIntersectionType", ...arguments); } -export { tsIntersectionType as TSIntersectionType }; export { tsIntersectionType as tSIntersectionType }; -export function tsConditionalType(...args: Array): Object { - return builder("TSConditionalType", ...args); +export function tsConditionalType( + checkType: t.TSType, + extendsType: t.TSType, + trueType: t.TSType, + falseType: t.TSType, +): t.TSConditionalType { + return builder("TSConditionalType", ...arguments); } -export { tsConditionalType as TSConditionalType }; export { tsConditionalType as tSConditionalType }; -export function tsInferType(...args: Array): Object { - return builder("TSInferType", ...args); +export function tsInferType(typeParameter: t.TSTypeParameter): t.TSInferType { + return builder("TSInferType", ...arguments); } -export { tsInferType as TSInferType }; export { tsInferType as tSInferType }; -export function tsParenthesizedType(...args: Array): Object { - return builder("TSParenthesizedType", ...args); +export function tsParenthesizedType( + typeAnnotation: t.TSType, +): t.TSParenthesizedType { + return builder("TSParenthesizedType", ...arguments); } -export { tsParenthesizedType as TSParenthesizedType }; export { tsParenthesizedType as tSParenthesizedType }; -export function tsTypeOperator(...args: Array): Object { - return builder("TSTypeOperator", ...args); +export function tsTypeOperator(typeAnnotation: t.TSType): t.TSTypeOperator { + return builder("TSTypeOperator", ...arguments); } -export { tsTypeOperator as TSTypeOperator }; export { tsTypeOperator as tSTypeOperator }; -export function tsIndexedAccessType(...args: Array): Object { - return builder("TSIndexedAccessType", ...args); +export function tsIndexedAccessType( + objectType: t.TSType, + indexType: t.TSType, +): t.TSIndexedAccessType { + return builder("TSIndexedAccessType", ...arguments); } -export { tsIndexedAccessType as TSIndexedAccessType }; export { tsIndexedAccessType as tSIndexedAccessType }; -export function tsMappedType(...args: Array): Object { - return builder("TSMappedType", ...args); +export function tsMappedType( + typeParameter: t.TSTypeParameter, + typeAnnotation?: t.TSType | null, + nameType?: t.TSType | null, +): t.TSMappedType { + return builder("TSMappedType", ...arguments); } -export { tsMappedType as TSMappedType }; export { tsMappedType as tSMappedType }; -export function tsLiteralType(...args: Array): Object { - return builder("TSLiteralType", ...args); +export function tsLiteralType( + literal: + | t.NumericLiteral + | t.StringLiteral + | t.BooleanLiteral + | t.BigIntLiteral, +): t.TSLiteralType { + return builder("TSLiteralType", ...arguments); } -export { tsLiteralType as TSLiteralType }; export { tsLiteralType as tSLiteralType }; -export function tsExpressionWithTypeArguments(...args: Array): Object { - return builder("TSExpressionWithTypeArguments", ...args); +export function tsExpressionWithTypeArguments( + expression: t.TSEntityName, + typeParameters?: t.TSTypeParameterInstantiation | null, +): t.TSExpressionWithTypeArguments { + return builder("TSExpressionWithTypeArguments", ...arguments); } -export { tsExpressionWithTypeArguments as TSExpressionWithTypeArguments }; export { tsExpressionWithTypeArguments as tSExpressionWithTypeArguments }; -export function tsInterfaceDeclaration(...args: Array): Object { - return builder("TSInterfaceDeclaration", ...args); +export function tsInterfaceDeclaration( + id: t.Identifier, + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + _extends: Array | null | undefined, + body: t.TSInterfaceBody, +): t.TSInterfaceDeclaration { + return builder("TSInterfaceDeclaration", ...arguments); } -export { tsInterfaceDeclaration as TSInterfaceDeclaration }; export { tsInterfaceDeclaration as tSInterfaceDeclaration }; -export function tsInterfaceBody(...args: Array): Object { - return builder("TSInterfaceBody", ...args); +export function tsInterfaceBody( + body: Array, +): t.TSInterfaceBody { + return builder("TSInterfaceBody", ...arguments); } -export { tsInterfaceBody as TSInterfaceBody }; export { tsInterfaceBody as tSInterfaceBody }; -export function tsTypeAliasDeclaration(...args: Array): Object { - return builder("TSTypeAliasDeclaration", ...args); +export function tsTypeAliasDeclaration( + id: t.Identifier, + typeParameters: t.TSTypeParameterDeclaration | null | undefined, + typeAnnotation: t.TSType, +): t.TSTypeAliasDeclaration { + return builder("TSTypeAliasDeclaration", ...arguments); } -export { tsTypeAliasDeclaration as TSTypeAliasDeclaration }; export { tsTypeAliasDeclaration as tSTypeAliasDeclaration }; -export function tsAsExpression(...args: Array): Object { - return builder("TSAsExpression", ...args); +export function tsAsExpression( + expression: t.Expression, + typeAnnotation: t.TSType, +): t.TSAsExpression { + return builder("TSAsExpression", ...arguments); } -export { tsAsExpression as TSAsExpression }; export { tsAsExpression as tSAsExpression }; -export function tsTypeAssertion(...args: Array): Object { - return builder("TSTypeAssertion", ...args); +export function tsTypeAssertion( + typeAnnotation: t.TSType, + expression: t.Expression, +): t.TSTypeAssertion { + return builder("TSTypeAssertion", ...arguments); } -export { tsTypeAssertion as TSTypeAssertion }; export { tsTypeAssertion as tSTypeAssertion }; -export function tsEnumDeclaration(...args: Array): Object { - return builder("TSEnumDeclaration", ...args); +export function tsEnumDeclaration( + id: t.Identifier, + members: Array, +): t.TSEnumDeclaration { + return builder("TSEnumDeclaration", ...arguments); } -export { tsEnumDeclaration as TSEnumDeclaration }; export { tsEnumDeclaration as tSEnumDeclaration }; -export function tsEnumMember(...args: Array): Object { - return builder("TSEnumMember", ...args); +export function tsEnumMember( + id: t.Identifier | t.StringLiteral, + initializer?: t.Expression | null, +): t.TSEnumMember { + return builder("TSEnumMember", ...arguments); } -export { tsEnumMember as TSEnumMember }; export { tsEnumMember as tSEnumMember }; -export function tsModuleDeclaration(...args: Array): Object { - return builder("TSModuleDeclaration", ...args); +export function tsModuleDeclaration( + id: t.Identifier | t.StringLiteral, + body: t.TSModuleBlock | t.TSModuleDeclaration, +): t.TSModuleDeclaration { + return builder("TSModuleDeclaration", ...arguments); } -export { tsModuleDeclaration as TSModuleDeclaration }; export { tsModuleDeclaration as tSModuleDeclaration }; -export function tsModuleBlock(...args: Array): Object { - return builder("TSModuleBlock", ...args); +export function tsModuleBlock(body: Array): t.TSModuleBlock { + return builder("TSModuleBlock", ...arguments); } -export { tsModuleBlock as TSModuleBlock }; export { tsModuleBlock as tSModuleBlock }; -export function tsImportType(...args: Array): Object { - return builder("TSImportType", ...args); +export function tsImportType( + argument: t.StringLiteral, + qualifier?: t.TSEntityName | null, + typeParameters?: t.TSTypeParameterInstantiation | null, +): t.TSImportType { + return builder("TSImportType", ...arguments); } -export { tsImportType as TSImportType }; export { tsImportType as tSImportType }; -export function tsImportEqualsDeclaration(...args: Array): Object { - return builder("TSImportEqualsDeclaration", ...args); +export function tsImportEqualsDeclaration( + id: t.Identifier, + moduleReference: t.TSEntityName | t.TSExternalModuleReference, +): t.TSImportEqualsDeclaration { + return builder("TSImportEqualsDeclaration", ...arguments); } -export { tsImportEqualsDeclaration as TSImportEqualsDeclaration }; export { tsImportEqualsDeclaration as tSImportEqualsDeclaration }; -export function tsExternalModuleReference(...args: Array): Object { - return builder("TSExternalModuleReference", ...args); +export function tsExternalModuleReference( + expression: t.StringLiteral, +): t.TSExternalModuleReference { + return builder("TSExternalModuleReference", ...arguments); } -export { tsExternalModuleReference as TSExternalModuleReference }; export { tsExternalModuleReference as tSExternalModuleReference }; -export function tsNonNullExpression(...args: Array): Object { - return builder("TSNonNullExpression", ...args); +export function tsNonNullExpression( + expression: t.Expression, +): t.TSNonNullExpression { + return builder("TSNonNullExpression", ...arguments); } -export { tsNonNullExpression as TSNonNullExpression }; export { tsNonNullExpression as tSNonNullExpression }; -export function tsExportAssignment(...args: Array): Object { - return builder("TSExportAssignment", ...args); +export function tsExportAssignment( + expression: t.Expression, +): t.TSExportAssignment { + return builder("TSExportAssignment", ...arguments); } -export { tsExportAssignment as TSExportAssignment }; export { tsExportAssignment as tSExportAssignment }; -export function tsNamespaceExportDeclaration(...args: Array): Object { - return builder("TSNamespaceExportDeclaration", ...args); +export function tsNamespaceExportDeclaration( + id: t.Identifier, +): t.TSNamespaceExportDeclaration { + return builder("TSNamespaceExportDeclaration", ...arguments); } -export { tsNamespaceExportDeclaration as TSNamespaceExportDeclaration }; export { tsNamespaceExportDeclaration as tSNamespaceExportDeclaration }; -export function tsTypeAnnotation(...args: Array): Object { - return builder("TSTypeAnnotation", ...args); +export function tsTypeAnnotation(typeAnnotation: t.TSType): t.TSTypeAnnotation { + return builder("TSTypeAnnotation", ...arguments); } -export { tsTypeAnnotation as TSTypeAnnotation }; export { tsTypeAnnotation as tSTypeAnnotation }; -export function tsTypeParameterInstantiation(...args: Array): Object { - return builder("TSTypeParameterInstantiation", ...args); +export function tsTypeParameterInstantiation( + params: Array, +): t.TSTypeParameterInstantiation { + return builder("TSTypeParameterInstantiation", ...arguments); } -export { tsTypeParameterInstantiation as TSTypeParameterInstantiation }; export { tsTypeParameterInstantiation as tSTypeParameterInstantiation }; -export function tsTypeParameterDeclaration(...args: Array): Object { - return builder("TSTypeParameterDeclaration", ...args); +export function tsTypeParameterDeclaration( + params: Array, +): t.TSTypeParameterDeclaration { + return builder("TSTypeParameterDeclaration", ...arguments); } -export { tsTypeParameterDeclaration as TSTypeParameterDeclaration }; export { tsTypeParameterDeclaration as tSTypeParameterDeclaration }; -export function tsTypeParameter(...args: Array): Object { - return builder("TSTypeParameter", ...args); +export function tsTypeParameter( + constraint: t.TSType | null | undefined, + _default: t.TSType | null | undefined, + name: string, +): t.TSTypeParameter { + return builder("TSTypeParameter", ...arguments); } -export { tsTypeParameter as TSTypeParameter }; export { tsTypeParameter as tSTypeParameter }; -export function NumberLiteral(...args: Array): Object { +/** @deprecated */ +function NumberLiteral(...args: Array): any { console.trace( "The node type NumberLiteral has been renamed to NumericLiteral", ); return builder("NumberLiteral", ...args); } export { NumberLiteral as numberLiteral }; -export function RegexLiteral(...args: Array): Object { +/** @deprecated */ +function RegexLiteral(...args: Array): any { console.trace("The node type RegexLiteral has been renamed to RegExpLiteral"); return builder("RegexLiteral", ...args); } export { RegexLiteral as regexLiteral }; -export function RestProperty(...args: Array): Object { +/** @deprecated */ +function RestProperty(...args: Array): any { console.trace("The node type RestProperty has been renamed to RestElement"); return builder("RestProperty", ...args); } export { RestProperty as restProperty }; -export function SpreadProperty(...args: Array): Object { +/** @deprecated */ +function SpreadProperty(...args: Array): any { console.trace( "The node type SpreadProperty has been renamed to SpreadElement", ); diff --git a/packages/babel-types/src/builders/generated/uppercase.d.ts b/packages/babel-types/src/builders/generated/uppercase.d.ts new file mode 100644 index 0000000000..6ea1755bda --- /dev/null +++ b/packages/babel-types/src/builders/generated/uppercase.d.ts @@ -0,0 +1,6 @@ +/** + * uppercase.js file is written in JavaScript and not TypeScript because uppercase + * builders conflict with AST types. TypeScript reads the this file instead. + */ + +export {}; diff --git a/packages/babel-types/src/builders/generated/uppercase.js b/packages/babel-types/src/builders/generated/uppercase.js new file mode 100755 index 0000000000..f217d2532a --- /dev/null +++ b/packages/babel-types/src/builders/generated/uppercase.js @@ -0,0 +1,258 @@ +/* + * This file is auto-generated! Do not modify it directly. + * To re-generate run 'make build' + */ + +/** + * This file is written in JavaScript and not TypeScript because uppercase builders + * conflict with AST types. TypeScript reads the uppercase.d.ts file instead. + */ + +export { + arrayExpression as ArrayExpression, + assignmentExpression as AssignmentExpression, + binaryExpression as BinaryExpression, + interpreterDirective as InterpreterDirective, + directive as Directive, + directiveLiteral as DirectiveLiteral, + blockStatement as BlockStatement, + breakStatement as BreakStatement, + callExpression as CallExpression, + catchClause as CatchClause, + conditionalExpression as ConditionalExpression, + continueStatement as ContinueStatement, + debuggerStatement as DebuggerStatement, + doWhileStatement as DoWhileStatement, + emptyStatement as EmptyStatement, + expressionStatement as ExpressionStatement, + file as File, + forInStatement as ForInStatement, + forStatement as ForStatement, + functionDeclaration as FunctionDeclaration, + functionExpression as FunctionExpression, + identifier as Identifier, + ifStatement as IfStatement, + labeledStatement as LabeledStatement, + stringLiteral as StringLiteral, + numericLiteral as NumericLiteral, + nullLiteral as NullLiteral, + booleanLiteral as BooleanLiteral, + regExpLiteral as RegExpLiteral, + logicalExpression as LogicalExpression, + memberExpression as MemberExpression, + newExpression as NewExpression, + program as Program, + objectExpression as ObjectExpression, + objectMethod as ObjectMethod, + objectProperty as ObjectProperty, + restElement as RestElement, + returnStatement as ReturnStatement, + sequenceExpression as SequenceExpression, + parenthesizedExpression as ParenthesizedExpression, + switchCase as SwitchCase, + switchStatement as SwitchStatement, + thisExpression as ThisExpression, + throwStatement as ThrowStatement, + tryStatement as TryStatement, + unaryExpression as UnaryExpression, + updateExpression as UpdateExpression, + variableDeclaration as VariableDeclaration, + variableDeclarator as VariableDeclarator, + whileStatement as WhileStatement, + withStatement as WithStatement, + assignmentPattern as AssignmentPattern, + arrayPattern as ArrayPattern, + arrowFunctionExpression as ArrowFunctionExpression, + classBody as ClassBody, + classExpression as ClassExpression, + classDeclaration as ClassDeclaration, + exportAllDeclaration as ExportAllDeclaration, + exportDefaultDeclaration as ExportDefaultDeclaration, + exportNamedDeclaration as ExportNamedDeclaration, + exportSpecifier as ExportSpecifier, + forOfStatement as ForOfStatement, + importDeclaration as ImportDeclaration, + importDefaultSpecifier as ImportDefaultSpecifier, + importNamespaceSpecifier as ImportNamespaceSpecifier, + importSpecifier as ImportSpecifier, + metaProperty as MetaProperty, + classMethod as ClassMethod, + objectPattern as ObjectPattern, + spreadElement as SpreadElement, + super as Super, + taggedTemplateExpression as TaggedTemplateExpression, + templateElement as TemplateElement, + templateLiteral as TemplateLiteral, + yieldExpression as YieldExpression, + awaitExpression as AwaitExpression, + import as Import, + bigIntLiteral as BigIntLiteral, + exportNamespaceSpecifier as ExportNamespaceSpecifier, + optionalMemberExpression as OptionalMemberExpression, + optionalCallExpression as OptionalCallExpression, + anyTypeAnnotation as AnyTypeAnnotation, + arrayTypeAnnotation as ArrayTypeAnnotation, + booleanTypeAnnotation as BooleanTypeAnnotation, + booleanLiteralTypeAnnotation as BooleanLiteralTypeAnnotation, + nullLiteralTypeAnnotation as NullLiteralTypeAnnotation, + classImplements as ClassImplements, + declareClass as DeclareClass, + declareFunction as DeclareFunction, + declareInterface as DeclareInterface, + declareModule as DeclareModule, + declareModuleExports as DeclareModuleExports, + declareTypeAlias as DeclareTypeAlias, + declareOpaqueType as DeclareOpaqueType, + declareVariable as DeclareVariable, + declareExportDeclaration as DeclareExportDeclaration, + declareExportAllDeclaration as DeclareExportAllDeclaration, + declaredPredicate as DeclaredPredicate, + existsTypeAnnotation as ExistsTypeAnnotation, + functionTypeAnnotation as FunctionTypeAnnotation, + functionTypeParam as FunctionTypeParam, + genericTypeAnnotation as GenericTypeAnnotation, + inferredPredicate as InferredPredicate, + interfaceExtends as InterfaceExtends, + interfaceDeclaration as InterfaceDeclaration, + interfaceTypeAnnotation as InterfaceTypeAnnotation, + intersectionTypeAnnotation as IntersectionTypeAnnotation, + mixedTypeAnnotation as MixedTypeAnnotation, + emptyTypeAnnotation as EmptyTypeAnnotation, + nullableTypeAnnotation as NullableTypeAnnotation, + numberLiteralTypeAnnotation as NumberLiteralTypeAnnotation, + numberTypeAnnotation as NumberTypeAnnotation, + objectTypeAnnotation as ObjectTypeAnnotation, + objectTypeInternalSlot as ObjectTypeInternalSlot, + objectTypeCallProperty as ObjectTypeCallProperty, + objectTypeIndexer as ObjectTypeIndexer, + objectTypeProperty as ObjectTypeProperty, + objectTypeSpreadProperty as ObjectTypeSpreadProperty, + opaqueType as OpaqueType, + qualifiedTypeIdentifier as QualifiedTypeIdentifier, + stringLiteralTypeAnnotation as StringLiteralTypeAnnotation, + stringTypeAnnotation as StringTypeAnnotation, + symbolTypeAnnotation as SymbolTypeAnnotation, + thisTypeAnnotation as ThisTypeAnnotation, + tupleTypeAnnotation as TupleTypeAnnotation, + typeofTypeAnnotation as TypeofTypeAnnotation, + typeAlias as TypeAlias, + typeAnnotation as TypeAnnotation, + typeCastExpression as TypeCastExpression, + typeParameter as TypeParameter, + typeParameterDeclaration as TypeParameterDeclaration, + typeParameterInstantiation as TypeParameterInstantiation, + unionTypeAnnotation as UnionTypeAnnotation, + variance as Variance, + voidTypeAnnotation as VoidTypeAnnotation, + enumDeclaration as EnumDeclaration, + enumBooleanBody as EnumBooleanBody, + enumNumberBody as EnumNumberBody, + enumStringBody as EnumStringBody, + enumSymbolBody as EnumSymbolBody, + enumBooleanMember as EnumBooleanMember, + enumNumberMember as EnumNumberMember, + enumStringMember as EnumStringMember, + enumDefaultedMember as EnumDefaultedMember, + jsxAttribute as JSXAttribute, + jsxClosingElement as JSXClosingElement, + jsxElement as JSXElement, + jsxEmptyExpression as JSXEmptyExpression, + jsxExpressionContainer as JSXExpressionContainer, + jsxSpreadChild as JSXSpreadChild, + jsxIdentifier as JSXIdentifier, + jsxMemberExpression as JSXMemberExpression, + jsxNamespacedName as JSXNamespacedName, + jsxOpeningElement as JSXOpeningElement, + jsxSpreadAttribute as JSXSpreadAttribute, + jsxText as JSXText, + jsxFragment as JSXFragment, + jsxOpeningFragment as JSXOpeningFragment, + jsxClosingFragment as JSXClosingFragment, + noop as Noop, + placeholder as Placeholder, + v8IntrinsicIdentifier as V8IntrinsicIdentifier, + argumentPlaceholder as ArgumentPlaceholder, + bindExpression as BindExpression, + classProperty as ClassProperty, + pipelineTopicExpression as PipelineTopicExpression, + pipelineBareFunction as PipelineBareFunction, + pipelinePrimaryTopicReference as PipelinePrimaryTopicReference, + classPrivateProperty as ClassPrivateProperty, + classPrivateMethod as ClassPrivateMethod, + importAttribute as ImportAttribute, + decorator as Decorator, + doExpression as DoExpression, + exportDefaultSpecifier as ExportDefaultSpecifier, + privateName as PrivateName, + recordExpression as RecordExpression, + tupleExpression as TupleExpression, + decimalLiteral as DecimalLiteral, + staticBlock as StaticBlock, + tsParameterProperty as TSParameterProperty, + tsDeclareFunction as TSDeclareFunction, + tsDeclareMethod as TSDeclareMethod, + tsQualifiedName as TSQualifiedName, + tsCallSignatureDeclaration as TSCallSignatureDeclaration, + tsConstructSignatureDeclaration as TSConstructSignatureDeclaration, + tsPropertySignature as TSPropertySignature, + tsMethodSignature as TSMethodSignature, + tsIndexSignature as TSIndexSignature, + tsAnyKeyword as TSAnyKeyword, + tsBooleanKeyword as TSBooleanKeyword, + tsBigIntKeyword as TSBigIntKeyword, + tsIntrinsicKeyword as TSIntrinsicKeyword, + tsNeverKeyword as TSNeverKeyword, + tsNullKeyword as TSNullKeyword, + tsNumberKeyword as TSNumberKeyword, + tsObjectKeyword as TSObjectKeyword, + tsStringKeyword as TSStringKeyword, + tsSymbolKeyword as TSSymbolKeyword, + tsUndefinedKeyword as TSUndefinedKeyword, + tsUnknownKeyword as TSUnknownKeyword, + tsVoidKeyword as TSVoidKeyword, + tsThisType as TSThisType, + tsFunctionType as TSFunctionType, + tsConstructorType as TSConstructorType, + tsTypeReference as TSTypeReference, + tsTypePredicate as TSTypePredicate, + tsTypeQuery as TSTypeQuery, + tsTypeLiteral as TSTypeLiteral, + tsArrayType as TSArrayType, + tsTupleType as TSTupleType, + tsOptionalType as TSOptionalType, + tsRestType as TSRestType, + tsNamedTupleMember as TSNamedTupleMember, + tsUnionType as TSUnionType, + tsIntersectionType as TSIntersectionType, + tsConditionalType as TSConditionalType, + tsInferType as TSInferType, + tsParenthesizedType as TSParenthesizedType, + tsTypeOperator as TSTypeOperator, + tsIndexedAccessType as TSIndexedAccessType, + tsMappedType as TSMappedType, + tsLiteralType as TSLiteralType, + tsExpressionWithTypeArguments as TSExpressionWithTypeArguments, + tsInterfaceDeclaration as TSInterfaceDeclaration, + tsInterfaceBody as TSInterfaceBody, + tsTypeAliasDeclaration as TSTypeAliasDeclaration, + tsAsExpression as TSAsExpression, + tsTypeAssertion as TSTypeAssertion, + tsEnumDeclaration as TSEnumDeclaration, + tsEnumMember as TSEnumMember, + tsModuleDeclaration as TSModuleDeclaration, + tsModuleBlock as TSModuleBlock, + tsImportType as TSImportType, + tsImportEqualsDeclaration as TSImportEqualsDeclaration, + tsExternalModuleReference as TSExternalModuleReference, + tsNonNullExpression as TSNonNullExpression, + tsExportAssignment as TSExportAssignment, + tsNamespaceExportDeclaration as TSNamespaceExportDeclaration, + tsTypeAnnotation as TSTypeAnnotation, + tsTypeParameterInstantiation as TSTypeParameterInstantiation, + tsTypeParameterDeclaration as TSTypeParameterDeclaration, + tsTypeParameter as TSTypeParameter, + numberLiteral as NumberLiteral, + regexLiteral as RegexLiteral, + restProperty as RestProperty, + spreadProperty as SpreadProperty, +} from "./index"; diff --git a/packages/babel-types/src/builders/react/buildChildren.ts b/packages/babel-types/src/builders/react/buildChildren.ts index dc2c470caa..0893a8bb30 100644 --- a/packages/babel-types/src/builders/react/buildChildren.ts +++ b/packages/babel-types/src/builders/react/buildChildren.ts @@ -1,16 +1,32 @@ -// @flow import { isJSXText, isJSXExpressionContainer, isJSXEmptyExpression, } from "../../validators/generated"; import cleanJSXElementLiteralChild from "../../utils/react/cleanJSXElementLiteralChild"; +import type * as t from "../.."; -export default function buildChildren(node: Object): Array { +type ReturnedChild = + | t.JSXExpressionContainer + | t.JSXSpreadChild + | t.JSXElement + | t.JSXFragment + | t.Expression; + +export default function buildChildren(node: { + children: ReadonlyArray< + | t.JSXText + | t.JSXExpressionContainer + | t.JSXSpreadChild + | t.JSXElement + | t.JSXFragment + | t.JSXEmptyExpression + >; +}): ReturnedChild[] { const elements = []; for (let i = 0; i < node.children.length; i++) { - let child = node.children[i]; + let child: any = node.children[i]; if (isJSXText(child)) { cleanJSXElementLiteralChild(child, elements); diff --git a/packages/babel-types/src/builders/typescript/createTSUnionType.ts b/packages/babel-types/src/builders/typescript/createTSUnionType.ts index ae4e5ded1c..a24b3b0b62 100644 --- a/packages/babel-types/src/builders/typescript/createTSUnionType.ts +++ b/packages/babel-types/src/builders/typescript/createTSUnionType.ts @@ -1,14 +1,15 @@ import { tsUnionType } from "../generated"; import removeTypeDuplicates from "../../modifications/typescript/removeTypeDuplicates"; +import type * as t from "../.."; /** * Takes an array of `types` and flattens them, removing duplicates and * returns a `UnionTypeAnnotation` node containing them. */ export default function createTSUnionType( - typeAnnotations: Array, -): Object { - const types = typeAnnotations.map(type => type.typeAnnotations); + typeAnnotations: Array, +): t.TSType { + const types = typeAnnotations.map(type => type.typeAnnotation); const flattened = removeTypeDuplicates(types); if (flattened.length === 1) { diff --git a/packages/babel-types/src/clone/clone.ts b/packages/babel-types/src/clone/clone.ts index 5a742a1785..2ce31a0ef3 100644 --- a/packages/babel-types/src/clone/clone.ts +++ b/packages/babel-types/src/clone/clone.ts @@ -1,12 +1,11 @@ -// @flow - import cloneNode from "./cloneNode"; +import type * as t from ".."; /** * Create a shallow clone of a `node`, including only * properties belonging to the node. * @deprecated Use t.cloneNode instead. */ -export default function clone(node: T): T { +export default function clone(node: T): T { return cloneNode(node, /* deep */ false); } diff --git a/packages/babel-types/src/clone/cloneDeep.ts b/packages/babel-types/src/clone/cloneDeep.ts index c0e31db8ce..072001490e 100644 --- a/packages/babel-types/src/clone/cloneDeep.ts +++ b/packages/babel-types/src/clone/cloneDeep.ts @@ -1,12 +1,11 @@ -// @flow - import cloneNode from "./cloneNode"; +import type * as t from ".."; /** * Create a deep clone of a `node` and all of it's child nodes * including only properties belonging to the node. * @deprecated Use t.cloneNode instead. */ -export default function cloneDeep(node: T): T { +export default function cloneDeep(node: T): T { return cloneNode(node); } diff --git a/packages/babel-types/src/clone/cloneDeepWithoutLoc.ts b/packages/babel-types/src/clone/cloneDeepWithoutLoc.ts index 80c1872308..2bab5d1f0f 100644 --- a/packages/babel-types/src/clone/cloneDeepWithoutLoc.ts +++ b/packages/babel-types/src/clone/cloneDeepWithoutLoc.ts @@ -1,10 +1,10 @@ -// @flow import cloneNode from "./cloneNode"; +import type * as t from ".."; /** * Create a deep clone of a `node` and all of it's child nodes * including only properties belonging to the node. * excluding `_private` and location properties. */ -export default function cloneDeepWithoutLoc(node: T): T { +export default function cloneDeepWithoutLoc(node: T): T { return cloneNode(node, /* deep */ true, /* withoutLoc */ true); } diff --git a/packages/babel-types/src/clone/cloneNode.ts b/packages/babel-types/src/clone/cloneNode.ts index 9f71429a2c..1ef270afe2 100644 --- a/packages/babel-types/src/clone/cloneNode.ts +++ b/packages/babel-types/src/clone/cloneNode.ts @@ -1,4 +1,6 @@ import { NODE_FIELDS } from "../definitions"; +import type * as t from ".."; +import { isFile, isIdentifier } from "../validators/generated"; const has = Function.call.bind(Object.prototype.hasOwnProperty); @@ -23,7 +25,7 @@ function cloneIfNodeOrArray(obj, deep, withoutLoc) { * If the second parameter is `false`, cloneNode performs a shallow clone. * If the third parameter is true, the cloned nodes exclude location properties. */ -export default function cloneNode( +export default function cloneNode( node: T, deep: boolean = true, withoutLoc: boolean = false, @@ -31,10 +33,10 @@ export default function cloneNode( if (!node) return node; const { type } = node; - const newNode = (({ type }: any): T); + const newNode: any = { type: node.type }; // Special-case identifiers since they are the most cloned nodes. - if (type === "Identifier") { + if (isIdentifier(node)) { newNode.name = node.name; if (has(node, "optional") && typeof node.optional === "boolean") { @@ -53,7 +55,7 @@ export default function cloneNode( if (has(node, field)) { if (deep) { newNode[field] = - type === "File" && field === "comments" + isFile(node) && field === "comments" ? maybeCloneComments(node.comments, deep, withoutLoc) : cloneIfNodeOrArray(node[field], true, withoutLoc); } else { @@ -100,8 +102,15 @@ export default function cloneNode( return newNode; } -function cloneCommentsWithoutLoc(comments: T[]): T { - return comments.map(({ type, value }) => ({ type, value, loc: null })); +function cloneCommentsWithoutLoc(comments: T[]): T[] { + return comments.map( + ({ type, value }) => + ({ + type, + value, + loc: null, + } as T), + ); } function maybeCloneComments(comments, deep, withoutLoc) { diff --git a/packages/babel-types/src/clone/cloneWithoutLoc.ts b/packages/babel-types/src/clone/cloneWithoutLoc.ts index b5cfe2fff0..21a09f5d68 100644 --- a/packages/babel-types/src/clone/cloneWithoutLoc.ts +++ b/packages/babel-types/src/clone/cloneWithoutLoc.ts @@ -1,8 +1,9 @@ -// @flow import cloneNode from "./cloneNode"; +import type * as t from ".."; + /** * Create a shallow clone of a `node` excluding `_private` and location properties. */ -export default function cloneWithoutLoc(node: T): T { +export default function cloneWithoutLoc(node: T): T { return cloneNode(node, /* deep */ false, /* withoutLoc */ true); } diff --git a/packages/babel-types/src/comments/addComment.ts b/packages/babel-types/src/comments/addComment.ts index 1a7482fb18..80c3e617ed 100644 --- a/packages/babel-types/src/comments/addComment.ts +++ b/packages/babel-types/src/comments/addComment.ts @@ -1,12 +1,12 @@ -// @flow import addComments from "./addComments"; +import type * as t from ".."; /** * Add comment of certain type to a node. */ -export default function addComment( +export default function addComment( node: T, - type: string, + type: t.CommentTypeShorthand, content: string, line?: boolean, ): T { @@ -14,6 +14,6 @@ export default function addComment( { type: line ? "CommentLine" : "CommentBlock", value: content, - }, + } as t.Comment, ]); } diff --git a/packages/babel-types/src/comments/addComments.ts b/packages/babel-types/src/comments/addComments.ts index 7652ae37f9..7aba077976 100644 --- a/packages/babel-types/src/comments/addComments.ts +++ b/packages/babel-types/src/comments/addComments.ts @@ -1,12 +1,12 @@ -// @flow +import type * as t from ".."; /** * Add comments of certain type to a node. */ -export default function addComments( +export default function addComments( node: T, - type: string, - comments: Array, + type: t.CommentTypeShorthand, + comments: ReadonlyArray, ): T { if (!comments || !node) return node; diff --git a/packages/babel-types/src/comments/inheritInnerComments.ts b/packages/babel-types/src/comments/inheritInnerComments.ts index 04153c0a25..1f1d314159 100644 --- a/packages/babel-types/src/comments/inheritInnerComments.ts +++ b/packages/babel-types/src/comments/inheritInnerComments.ts @@ -1,9 +1,9 @@ -// @flow import inherit from "../utils/inherit"; +import type * as t from ".."; export default function inheritInnerComments( - child: Object, - parent: Object, + child: t.Node, + parent: t.Node, ): void { inherit("innerComments", child, parent); } diff --git a/packages/babel-types/src/comments/inheritLeadingComments.ts b/packages/babel-types/src/comments/inheritLeadingComments.ts index fadcb9a0eb..83b418d7a3 100644 --- a/packages/babel-types/src/comments/inheritLeadingComments.ts +++ b/packages/babel-types/src/comments/inheritLeadingComments.ts @@ -1,9 +1,9 @@ -// @flow import inherit from "../utils/inherit"; +import type * as t from ".."; export default function inheritLeadingComments( - child: Object, - parent: Object, + child: t.Node, + parent: t.Node, ): void { inherit("leadingComments", child, parent); } diff --git a/packages/babel-types/src/comments/inheritTrailingComments.ts b/packages/babel-types/src/comments/inheritTrailingComments.ts index 502f71f5c3..bbcb323810 100644 --- a/packages/babel-types/src/comments/inheritTrailingComments.ts +++ b/packages/babel-types/src/comments/inheritTrailingComments.ts @@ -1,9 +1,9 @@ -// @flow import inherit from "../utils/inherit"; +import type * as t from ".."; export default function inheritTrailingComments( - child: Object, - parent: Object, + child: t.Node, + parent: t.Node, ): void { inherit("trailingComments", child, parent); } diff --git a/packages/babel-types/src/comments/inheritsComments.ts b/packages/babel-types/src/comments/inheritsComments.ts index 5135c963b2..a1a013e45e 100644 --- a/packages/babel-types/src/comments/inheritsComments.ts +++ b/packages/babel-types/src/comments/inheritsComments.ts @@ -1,14 +1,14 @@ -// @flow import inheritTrailingComments from "./inheritTrailingComments"; import inheritLeadingComments from "./inheritLeadingComments"; import inheritInnerComments from "./inheritInnerComments"; +import type * as t from ".."; /** * Inherit all unique comments from `parent` node to `child` node. */ -export default function inheritsComments( +export default function inheritsComments( child: T, - parent: Object, + parent: t.Node, ): T { inheritTrailingComments(child, parent); inheritLeadingComments(child, parent); diff --git a/packages/babel-types/src/comments/removeComments.ts b/packages/babel-types/src/comments/removeComments.ts index 317ab07094..a822f2109d 100644 --- a/packages/babel-types/src/comments/removeComments.ts +++ b/packages/babel-types/src/comments/removeComments.ts @@ -1,10 +1,10 @@ -// @flow import { COMMENT_KEYS } from "../constants"; +import type * as t from ".."; /** * Remove comment properties from a node. */ -export default function removeComments(node: T): T { +export default function removeComments(node: T): T { COMMENT_KEYS.forEach(key => { node[key] = null; }); diff --git a/packages/babel-types/src/constants/generated/index.ts b/packages/babel-types/src/constants/generated/index.ts index acdf21744a..d102bc9731 100755 --- a/packages/babel-types/src/constants/generated/index.ts +++ b/packages/babel-types/src/constants/generated/index.ts @@ -1,4 +1,3 @@ -// @flow /* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' diff --git a/packages/babel-types/src/constants/index.ts b/packages/babel-types/src/constants/index.ts index 4cac678b73..f1155ee7b3 100644 --- a/packages/babel-types/src/constants/index.ts +++ b/packages/babel-types/src/constants/index.ts @@ -1,4 +1,3 @@ -// @flow export const STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; export const FLATTENABLE_KEYS = ["body", "expressions"]; export const FOR_INIT_KEYS = ["left", "init"]; diff --git a/packages/babel-types/src/converters/Scope.ts b/packages/babel-types/src/converters/Scope.ts new file mode 100644 index 0000000000..3ea3ef8ae4 --- /dev/null +++ b/packages/babel-types/src/converters/Scope.ts @@ -0,0 +1,8 @@ +// NOTE: this actually uses Scope from @babel/traverse, but we can't add a dependency on its types, +// because this would be cyclic dependency. Declare the structural subset that is required. +import type * as t from ".."; + +export type Scope = { + push(value: { id: t.LVal; kind: "var"; init?: t.Expression }): void; + buildUndefinedNode(): t.Node; +}; diff --git a/packages/babel-types/src/converters/ensureBlock.ts b/packages/babel-types/src/converters/ensureBlock.ts index ee02d46eea..069e099df7 100644 --- a/packages/babel-types/src/converters/ensureBlock.ts +++ b/packages/babel-types/src/converters/ensureBlock.ts @@ -1,5 +1,5 @@ -// @flow import toBlock from "./toBlock"; +import type * as t from ".."; /** * Ensure the `key` (defaults to "body") of a `node` is a block. @@ -8,8 +8,8 @@ import toBlock from "./toBlock"; * Returns the BlockStatement */ export default function ensureBlock( - node: Object, + node: t.Node, key: string = "body", -): Object { +): t.BlockStatement { return (node[key] = toBlock(node[key], node)); } diff --git a/packages/babel-types/src/converters/gatherSequenceExpressions.ts b/packages/babel-types/src/converters/gatherSequenceExpressions.ts index ef0ccc0757..71ef31ec9d 100644 --- a/packages/babel-types/src/converters/gatherSequenceExpressions.ts +++ b/packages/babel-types/src/converters/gatherSequenceExpressions.ts @@ -1,5 +1,3 @@ -// @flow -import type { Scope } from "@babel/traverse"; import getBindingIdentifiers from "../retrievers/getBindingIdentifiers"; import { isExpression, @@ -15,12 +13,14 @@ import { conditionalExpression, } from "../builders/generated"; import cloneNode from "../clone/cloneNode"; +import type * as t from ".."; +import type { Scope } from "./Scope"; export default function gatherSequenceExpressions( - nodes: Array, + nodes: ReadonlyArray, scope: Scope, - declars: Array, -): ?Object { + declars: Array, +): t.SequenceExpression { const exprs = []; let ensureLastUndefined = true; @@ -38,7 +38,7 @@ export default function gatherSequenceExpressions( } else if (isVariableDeclaration(node)) { if (node.kind !== "var") return; // bailed - for (const declar of (node.declarations: Array)) { + for (const declar of node.declarations) { const bindings = getBindingIdentifiers(declar); for (const key of Object.keys(bindings)) { declars.push({ @@ -62,6 +62,7 @@ export default function gatherSequenceExpressions( : scope.buildUndefinedNode(); if (!consequent || !alternate) return; // bailed + // @ts-expect-error todo(flow->ts) consequent - Argument of type 'Node' is not assignable to parameter of type 'Expression' exprs.push(conditionalExpression(node.test, consequent, alternate)); } else if (isBlockStatement(node)) { const body = gatherSequenceExpressions(node.body, scope, declars); diff --git a/packages/babel-types/src/converters/toBindingIdentifierName.ts b/packages/babel-types/src/converters/toBindingIdentifierName.ts index a7cac3a8e9..1bda43565c 100644 --- a/packages/babel-types/src/converters/toBindingIdentifierName.ts +++ b/packages/babel-types/src/converters/toBindingIdentifierName.ts @@ -1,4 +1,3 @@ -// @flow import toIdentifier from "./toIdentifier"; export default function toBindingIdentifierName(name: string): string { diff --git a/packages/babel-types/src/converters/toBlock.ts b/packages/babel-types/src/converters/toBlock.ts index 1086b792e5..34f2a1a640 100644 --- a/packages/babel-types/src/converters/toBlock.ts +++ b/packages/babel-types/src/converters/toBlock.ts @@ -1,4 +1,3 @@ -// @flow import { isBlockStatement, isFunction, @@ -10,8 +9,12 @@ import { expressionStatement, blockStatement, } from "../builders/generated"; +import type * as t from ".."; -export default function toBlock(node: Object, parent: Object): Object { +export default function toBlock( + node: t.Statement | t.Expression, + parent?: t.Node, +): t.BlockStatement { if (isBlockStatement(node)) { return node; } diff --git a/packages/babel-types/src/converters/toComputedKey.ts b/packages/babel-types/src/converters/toComputedKey.ts index a09ced3a41..d82d266af1 100644 --- a/packages/babel-types/src/converters/toComputedKey.ts +++ b/packages/babel-types/src/converters/toComputedKey.ts @@ -1,11 +1,18 @@ -// @flow import { isIdentifier } from "../validators/generated"; import { stringLiteral } from "../builders/generated"; +import type * as t from ".."; export default function toComputedKey( - node: Object, - key: Object = node.key || node.property, -): Object { + node: + | t.ObjectMember + | t.ObjectProperty + | t.ClassMethod + | t.ClassProperty + | t.MemberExpression + | t.OptionalMemberExpression, + // @ts-expect-error todo(flow->ts): maybe check the type of node before accessing .key and .property + key: t.Expression = node.key || node.property, +) { if (!node.computed && isIdentifier(key)) key = stringLiteral(key.name); return key; diff --git a/packages/babel-types/src/converters/toExpression.ts b/packages/babel-types/src/converters/toExpression.ts index 15c98b7f7d..1878ef887c 100644 --- a/packages/babel-types/src/converters/toExpression.ts +++ b/packages/babel-types/src/converters/toExpression.ts @@ -1,12 +1,22 @@ -// @flow import { isExpression, isFunction, isClass, isExpressionStatement, } from "../validators/generated"; +import type * as t from ".."; -export default function toExpression(node: Object): Object { +export default toExpression as { + (node: t.Function): t.FunctionExpression; + (node: t.Class): t.ClassExpression; + ( + node: t.ExpressionStatement | t.Expression | t.Class | t.Function, + ): t.Expression; +}; + +function toExpression( + node: t.ExpressionStatement | t.Expression | t.Class | t.Function, +): t.Expression { if (isExpressionStatement(node)) { node = node.expression; } @@ -25,8 +35,10 @@ export default function toExpression(node: Object): Object { // ClassDeclaration -> ClassExpression // FunctionDeclaration, ObjectMethod, ClassMethod -> FunctionExpression if (isClass(node)) { + // @ts-expect-error todo(flow->ts): avoid type unsafe mutations node.type = "ClassExpression"; } else if (isFunction(node)) { + // @ts-expect-error todo(flow->ts): avoid type unsafe mutations node.type = "FunctionExpression"; } diff --git a/packages/babel-types/src/converters/toIdentifier.ts b/packages/babel-types/src/converters/toIdentifier.ts index 50337f70c0..70a42d97e9 100644 --- a/packages/babel-types/src/converters/toIdentifier.ts +++ b/packages/babel-types/src/converters/toIdentifier.ts @@ -1,4 +1,3 @@ -// @flow import isValidIdentifier from "../validators/isValidIdentifier"; export default function toIdentifier(name: string): string { diff --git a/packages/babel-types/src/converters/toKeyAlias.ts b/packages/babel-types/src/converters/toKeyAlias.ts index 6515a34d54..2e5f8aac4e 100644 --- a/packages/babel-types/src/converters/toKeyAlias.ts +++ b/packages/babel-types/src/converters/toKeyAlias.ts @@ -1,14 +1,15 @@ -// @flow import { isIdentifier, isStringLiteral } from "../validators/generated"; import cloneNode from "../clone/cloneNode"; import removePropertiesDeep from "../modifications/removePropertiesDeep"; +import type * as t from ".."; export default function toKeyAlias( - node: Object, - key: Object = node.key, + node: t.Method | t.Property, + key: t.Node = node.key, ): string { let alias; + // @ts-expect-error todo(flow->ts): maybe add node type check before checking `.kind` if (node.kind === "method") { return toKeyAlias.increment() + ""; } else if (isIdentifier(key)) { @@ -19,10 +20,12 @@ export default function toKeyAlias( alias = JSON.stringify(removePropertiesDeep(cloneNode(key))); } + // @ts-expect-error todo(flow->ts): maybe add node type check before checking `.computed` if (node.computed) { alias = `[${alias}]`; } + // @ts-expect-error todo(flow->ts): maybe add node type check before checking `.static` if (node.static) { alias = `static:${alias}`; } diff --git a/packages/babel-types/src/converters/toSequenceExpression.ts b/packages/babel-types/src/converters/toSequenceExpression.ts index d386b53017..5d99d4cf24 100644 --- a/packages/babel-types/src/converters/toSequenceExpression.ts +++ b/packages/babel-types/src/converters/toSequenceExpression.ts @@ -1,6 +1,6 @@ -// @flow -import type { Scope } from "@babel/traverse"; import gatherSequenceExpressions from "./gatherSequenceExpressions"; +import type * as t from ".."; +import type { Scope } from "./Scope"; /** * Turn an array of statement `nodes` into a `SequenceExpression`. @@ -11,9 +11,9 @@ import gatherSequenceExpressions from "./gatherSequenceExpressions"; * Expression statements are just resolved to their expression. */ export default function toSequenceExpression( - nodes: Array, + nodes: ReadonlyArray, scope: Scope, -): ?Object { +): t.SequenceExpression | undefined { if (!nodes?.length) return; const declars = []; diff --git a/packages/babel-types/src/converters/toStatement.ts b/packages/babel-types/src/converters/toStatement.ts index 8f9ce505a3..6537206014 100644 --- a/packages/babel-types/src/converters/toStatement.ts +++ b/packages/babel-types/src/converters/toStatement.ts @@ -1,4 +1,3 @@ -// @flow import { isStatement, isFunction, @@ -6,8 +5,25 @@ import { isAssignmentExpression, } from "../validators/generated"; import { expressionStatement } from "../builders/generated"; +import type * as t from ".."; -export default function toStatement(node: Object, ignore?: boolean) { +export default toStatement as { + (node: t.AssignmentExpression, ignore?: boolean): t.ExpressionStatement; + + (node: T, ignore: false): T; + (node: T, ignore?: boolean): T | false; + + (node: t.Class, ignore: false): t.ClassDeclaration; + (node: t.Class, ignore?: boolean): t.ClassDeclaration | false; + + (node: t.Function, ignore: false): t.FunctionDeclaration; + (node: t.Function, ignore?: boolean): t.FunctionDeclaration | false; + + (node: t.Node, ignore: false): t.Statement; + (node: t.Node, ignore?: boolean): t.Statement | false; +}; + +function toStatement(node: t.Node, ignore?: boolean): t.Statement | false { if (isStatement(node)) { return node; } @@ -25,6 +41,7 @@ export default function toStatement(node: Object, ignore?: boolean) { return expressionStatement(node); } + // @ts-expect-error todo(flow->ts): node.id might be missing if (mustHaveId && !node.id) { newType = false; } @@ -39,5 +56,6 @@ export default function toStatement(node: Object, ignore?: boolean) { node.type = newType; + // @ts-expect-error todo(flow->ts) refactor to avoid type unsafe mutations like reassigning node type above return node; } diff --git a/packages/babel-types/src/converters/valueToNode.ts b/packages/babel-types/src/converters/valueToNode.ts index 56bb7ff06b..ed58a475fb 100644 --- a/packages/babel-types/src/converters/valueToNode.ts +++ b/packages/babel-types/src/converters/valueToNode.ts @@ -1,4 +1,3 @@ -// @flow import isPlainObject from "lodash/isPlainObject"; import isRegExp from "lodash/isRegExp"; import isValidIdentifier from "../validators/isValidIdentifier"; @@ -15,8 +14,26 @@ import { unaryExpression, binaryExpression, } from "../builders/generated"; +import type * as t from ".."; -export default function valueToNode(value: any): Object { +export default valueToNode as { + (value: undefined): t.Identifier; // TODO: This should return "void 0" + (value: boolean): t.BooleanLiteral; + (value: null): t.NullLiteral; + (value: string): t.StringLiteral; + // Infinities and NaN need to use a BinaryExpression; negative values must be wrapped in UnaryExpression + (value: number): t.NumericLiteral | t.BinaryExpression | t.UnaryExpression; + (value: RegExp): t.RegExpLiteral; + (value: ReadonlyArray): t.ArrayExpression; + + // this throws with objects that are not PlainObject according to lodash, + // or if there are non-valueToNode-able values + (value: object): t.ObjectExpression; + + (value: unknown): t.Expression; +}; + +function valueToNode(value: unknown): t.Expression { // undefined if (value === undefined) { return identifier("undefined"); diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index fe5edc6b98..572fa6d711 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -1,5 +1,3 @@ -// @flow - import is from "../validators/is"; import isValidIdentifier from "../validators/isValidIdentifier"; import { isKeyword, isReservedWord } from "@babel/helper-validator-identifier"; @@ -1708,7 +1706,7 @@ export const classMethodOrPropertyCommon = { ); const computed = assertNodeType("Expression"); - return function (node: Object, key: string, val: any) { + return function (node: any, key: string, val: any) { const validator = node.computed ? computed : normal; validator(node, key, val); }; diff --git a/packages/babel-types/src/definitions/experimental.ts b/packages/babel-types/src/definitions/experimental.ts index b7f3360f98..29e7ecdbe7 100644 --- a/packages/babel-types/src/definitions/experimental.ts +++ b/packages/babel-types/src/definitions/experimental.ts @@ -1,4 +1,3 @@ -// @flow import defineType, { assertEach, assertNodeType, diff --git a/packages/babel-types/src/definitions/flow.ts b/packages/babel-types/src/definitions/flow.ts index 182b6fec6e..e475fff4d8 100644 --- a/packages/babel-types/src/definitions/flow.ts +++ b/packages/babel-types/src/definitions/flow.ts @@ -1,4 +1,3 @@ -// @flow import defineType, { arrayOfType, assertOneOf, diff --git a/packages/babel-types/src/definitions/index.ts b/packages/babel-types/src/definitions/index.ts index 4e41f0b77b..453d8c0025 100644 --- a/packages/babel-types/src/definitions/index.ts +++ b/packages/babel-types/src/definitions/index.ts @@ -1,4 +1,3 @@ -// @flow import toFastProperties from "to-fast-properties"; import "./core"; import "./flow"; diff --git a/packages/babel-types/src/definitions/jsx.ts b/packages/babel-types/src/definitions/jsx.ts index 837c4f25b2..566236031e 100644 --- a/packages/babel-types/src/definitions/jsx.ts +++ b/packages/babel-types/src/definitions/jsx.ts @@ -1,4 +1,3 @@ -// @flow import defineType, { assertNodeType, assertValueType, diff --git a/packages/babel-types/src/definitions/misc.ts b/packages/babel-types/src/definitions/misc.ts index da67c68706..c33f18c73e 100644 --- a/packages/babel-types/src/definitions/misc.ts +++ b/packages/babel-types/src/definitions/misc.ts @@ -1,4 +1,3 @@ -// @flow import defineType, { assertNodeType, assertOneOf, diff --git a/packages/babel-types/src/definitions/placeholders.ts b/packages/babel-types/src/definitions/placeholders.ts index 2eb8e9b634..e643eb0eed 100644 --- a/packages/babel-types/src/definitions/placeholders.ts +++ b/packages/babel-types/src/definitions/placeholders.ts @@ -11,7 +11,7 @@ export const PLACEHOLDERS = [ "Pattern", ]; -export const PLACEHOLDERS_ALIAS: { [string]: Array } = { +export const PLACEHOLDERS_ALIAS: Record = { Declaration: ["Statement"], Pattern: ["PatternLike", "LVal"], }; @@ -21,7 +21,7 @@ for (const type of PLACEHOLDERS) { if (alias?.length) PLACEHOLDERS_ALIAS[type] = alias; } -export const PLACEHOLDERS_FLIPPED_ALIAS: { [string]: Array } = {}; +export const PLACEHOLDERS_FLIPPED_ALIAS: Record = {}; Object.keys(PLACEHOLDERS_ALIAS).forEach(type => { PLACEHOLDERS_ALIAS[type].forEach(alias => { diff --git a/packages/babel-types/src/definitions/typescript.ts b/packages/babel-types/src/definitions/typescript.ts index 4c8446f4d0..23075cf40f 100644 --- a/packages/babel-types/src/definitions/typescript.ts +++ b/packages/babel-types/src/definitions/typescript.ts @@ -1,4 +1,3 @@ -// @flow import defineType, { arrayOfType, assertEach, diff --git a/packages/babel-types/src/definitions/utils.ts b/packages/babel-types/src/definitions/utils.ts index 9404fdbab6..be5390813a 100644 --- a/packages/babel-types/src/definitions/utils.ts +++ b/packages/babel-types/src/definitions/utils.ts @@ -1,13 +1,12 @@ -// @flow import is from "../validators/is"; import { validateField, validateChild } from "../validators/validate"; -export const VISITOR_KEYS: { [string]: Array } = {}; -export const ALIAS_KEYS: { [string]: Array } = {}; -export const FLIPPED_ALIAS_KEYS: { [string]: Array } = {}; -export const NODE_FIELDS: { [string]: {} } = {}; -export const BUILDER_KEYS: { [string]: Array } = {}; -export const DEPRECATED_KEYS: { [string]: string } = {}; +export const VISITOR_KEYS: Record = {}; +export const ALIAS_KEYS: Record = {}; +export const FLIPPED_ALIAS_KEYS: Record = {}; +export const NODE_FIELDS: Record = {}; +export const BUILDER_KEYS: Record = {}; +export const DEPRECATED_KEYS: Record = {}; export const NODE_PARENT_VALIDATIONS = {}; function getType(val) { @@ -21,12 +20,16 @@ function getType(val) { } // TODO: Import and use Node instead of any -type Validator = (any, string, any) => void; +type Validator = { chainOf?: Validator[] } & (( + parent: any, + key: string, + node: any, +) => void); type FieldOptions = { - default?: any, - optional?: boolean, - validate?: Validator, + default?: any; + optional?: boolean; + validate?: Validator; }; export function validate(validate: Validator): FieldOptions { @@ -81,7 +84,7 @@ export function assertEach(callback: Validator): Validator { } export function assertOneOf(...values: Array): Validator { - function validate(node: Object, key: string, val: any) { + function validate(node: any, key: string, val: any) { if (values.indexOf(val) < 0) { throw new TypeError( `Property ${key} expected value to be one of ${JSON.stringify( @@ -158,7 +161,7 @@ export function assertValueType(type: string): Validator { return validate; } -export function assertShape(shape: { [string]: FieldOptions }): Validator { +export function assertShape(shape: { [x: string]: FieldOptions }): Validator { function validate(node, key, val) { const errors = []; for (const property of Object.keys(shape)) { @@ -215,11 +218,11 @@ export function assertOptionalChainStart(): Validator { } export function chain(...fns: Array): Validator { - function validate(...args) { + const validate: Validator = function (...args) { for (const fn of fns) { fn(...args); } - } + }; validate.chainOf = fns; return validate; } @@ -239,14 +242,14 @@ export default function defineType( type: string, opts: { fields?: { - [string]: FieldOptions, - }, - visitor?: Array, - aliases?: Array, - builder?: Array, - inherits?: string, - deprecatedAlias?: string, - validate?: Validator, + [x: string]: FieldOptions; + }; + visitor?: Array; + aliases?: Array; + builder?: Array; + inherits?: string; + deprecatedAlias?: string; + validate?: Validator; } = {}, ) { const inherits = (opts.inherits && store[opts.inherits]) || {}; @@ -256,7 +259,7 @@ export default function defineType( fields = {}; if (inherits.fields) { const keys = Object.getOwnPropertyNames(inherits.fields); - for (const key of (keys: Array)) { + for (const key of keys) { const field = inherits.fields[key]; fields[key] = { default: field.default, @@ -272,7 +275,7 @@ export default function defineType( const builder: Array = opts.builder || inherits.builder || opts.visitor || []; - for (const k of (Object.keys(opts): Array)) { + for (const k of Object.keys(opts)) { if (validTypeOpts.indexOf(k) === -1) { throw new Error(`Unknown type option "${k}" on ${type}`); } @@ -283,7 +286,7 @@ export default function defineType( } // ensure all field keys are represented in `fields` - for (const key of (visitor.concat(builder): Array)) { + for (const key of visitor.concat(builder)) { fields[key] = fields[key] || {}; } @@ -299,7 +302,7 @@ export default function defineType( field.validate = assertValueType(getType(field.default)); } - for (const k of (Object.keys(field): Array)) { + for (const k of Object.keys(field)) { if (validFieldKeys.indexOf(k) === -1) { throw new Error(`Unknown field key "${k}" on ${type}.${key}`); } diff --git a/packages/babel-types/src/index.ts b/packages/babel-types/src/index.ts index 7239401fd6..d80b74ee70 100644 --- a/packages/babel-types/src/index.ts +++ b/packages/babel-types/src/index.ts @@ -1,4 +1,3 @@ -// @flow import isReactComponent from "./validators/react/isReactComponent"; import isCompatTag from "./validators/react/isCompatTag"; import buildChildren from "./builders/react/buildChildren"; @@ -9,10 +8,12 @@ export * from "./asserts/generated"; // builders export { default as createTypeAnnotationBasedOnTypeof } from "./builders/flow/createTypeAnnotationBasedOnTypeof"; +/** @deprecated use createFlowUnionType instead */ export { default as createUnionTypeAnnotation } from "./builders/flow/createFlowUnionType"; export { default as createFlowUnionType } from "./builders/flow/createFlowUnionType"; export { default as createTSUnionType } from "./builders/typescript/createTSUnionType"; export * from "./builders/generated"; +export * from "./builders/generated/uppercase"; // clone export { default as cloneNode } from "./clone/cloneNode"; @@ -63,7 +64,7 @@ export { default as getOuterBindingIdentifiers } from "./retrievers/getOuterBind // traverse export { default as traverse } from "./traverse/traverse"; -export type * from "./traverse/traverse"; +export * from "./traverse/traverse"; export { default as traverseFast } from "./traverse/traverseFast"; // utils @@ -96,3 +97,5 @@ export const react = { isCompatTag, buildChildren, }; + +export * from "./ast-types/generated"; diff --git a/packages/babel-types/src/modifications/appendToMemberExpression.ts b/packages/babel-types/src/modifications/appendToMemberExpression.ts index 1232ce6af3..ded0408bf0 100644 --- a/packages/babel-types/src/modifications/appendToMemberExpression.ts +++ b/packages/babel-types/src/modifications/appendToMemberExpression.ts @@ -1,14 +1,14 @@ -// @flow import { memberExpression } from "../builders/generated"; +import type * as t from ".."; /** * Append a node to a member expression. */ -export default function appendToMemberExpression( - member: T, - append: Object, - computed?: boolean = false, -): T { +export default function appendToMemberExpression( + member: t.MemberExpression, + append: t.MemberExpression["property"], + computed: boolean = false, +): t.MemberExpression { member.object = memberExpression( member.object, member.property, diff --git a/packages/babel-types/src/modifications/flow/removeTypeDuplicates.ts b/packages/babel-types/src/modifications/flow/removeTypeDuplicates.ts index 629c265ff5..dbe07300fa 100644 --- a/packages/babel-types/src/modifications/flow/removeTypeDuplicates.ts +++ b/packages/babel-types/src/modifications/flow/removeTypeDuplicates.ts @@ -1,17 +1,24 @@ -// @flow import { isAnyTypeAnnotation, isGenericTypeAnnotation, isUnionTypeAnnotation, isFlowBaseAnnotation, + isIdentifier, } from "../../validators/generated"; +import type * as t from "../.."; + +function getQualifiedName(node: t.GenericTypeAnnotation["id"]) { + return isIdentifier(node) + ? node.name + : `${node.id.name}.${getQualifiedName(node.qualification)}`; +} /** * Dedupe type annotations. */ export default function removeTypeDuplicates( - nodes: Array, -): Array { + nodes: ReadonlyArray, +): t.FlowType[] { const generics = {}; const bases = {}; @@ -49,7 +56,7 @@ export default function removeTypeDuplicates( // find a matching generic type and merge and deduplicate the type parameters if (isGenericTypeAnnotation(node)) { - const name = node.id.name; + const name = getQualifiedName(node.id); if (generics[name]) { let existing = generics[name]; diff --git a/packages/babel-types/src/modifications/inherits.ts b/packages/babel-types/src/modifications/inherits.ts index a802182859..d426ee44c5 100644 --- a/packages/babel-types/src/modifications/inherits.ts +++ b/packages/babel-types/src/modifications/inherits.ts @@ -1,15 +1,18 @@ -// @flow import { INHERIT_KEYS } from "../constants"; import inheritsComments from "../comments/inheritsComments"; +import type * as t from ".."; /** * Inherit all contextual properties from `parent` node to `child` node. */ -export default function inherits(child: T, parent: Object): T { +export default function inherits( + child: T, + parent: t.Node | null | undefined, +): T { if (!child || !parent) return child; // optionally inherit specific properties if not null - for (const key of (INHERIT_KEYS.optional: Array)) { + for (const key of INHERIT_KEYS.optional) { if (child[key] == null) { child[key] = parent[key]; } @@ -21,7 +24,7 @@ export default function inherits(child: T, parent: Object): T { } // force inherit select properties - for (const key of (INHERIT_KEYS.force: Array)) { + for (const key of INHERIT_KEYS.force) { child[key] = parent[key]; } diff --git a/packages/babel-types/src/modifications/prependToMemberExpression.ts b/packages/babel-types/src/modifications/prependToMemberExpression.ts index ce7f4a89f6..804e72d082 100644 --- a/packages/babel-types/src/modifications/prependToMemberExpression.ts +++ b/packages/babel-types/src/modifications/prependToMemberExpression.ts @@ -1,13 +1,12 @@ -// @flow import { memberExpression } from "../builders/generated"; +import type * as t from ".."; /** * Prepend a node to a member expression. */ -export default function prependToMemberExpression( - member: T, - prepend: Object, -): T { +export default function prependToMemberExpression< + T extends Pick +>(member: T, prepend: t.MemberExpression["object"]): T { member.object = memberExpression(prepend, member.object); return member; diff --git a/packages/babel-types/src/modifications/removeProperties.ts b/packages/babel-types/src/modifications/removeProperties.ts index eb27fd7cbb..38e4595ed9 100644 --- a/packages/babel-types/src/modifications/removeProperties.ts +++ b/packages/babel-types/src/modifications/removeProperties.ts @@ -1,5 +1,5 @@ -// @flow import { COMMENT_KEYS } from "../constants"; +import type * as t from ".."; const CLEAR_KEYS = ["tokens", "start", "end", "loc", "raw", "rawValue"]; @@ -12,8 +12,8 @@ const CLEAR_KEYS_PLUS_COMMENTS = COMMENT_KEYS.concat(["comments"]).concat( * properties like location data and raw token data. */ export default function removeProperties( - node: Object, - opts?: Object = {}, + node: t.Node, + opts: { preserveComments?: boolean } = {}, ): void { const map = opts.preserveComments ? CLEAR_KEYS : CLEAR_KEYS_PLUS_COMMENTS; for (const key of map) { diff --git a/packages/babel-types/src/modifications/removePropertiesDeep.ts b/packages/babel-types/src/modifications/removePropertiesDeep.ts index fdafc5ca6c..c22fa32a16 100644 --- a/packages/babel-types/src/modifications/removePropertiesDeep.ts +++ b/packages/babel-types/src/modifications/removePropertiesDeep.ts @@ -1,10 +1,10 @@ -// @flow import traverseFast from "../traverse/traverseFast"; import removeProperties from "./removeProperties"; +import type * as t from ".."; -export default function removePropertiesDeep( +export default function removePropertiesDeep( tree: T, - opts?: Object, + opts?: { preserveComments: boolean } | null, ): T { traverseFast(tree, removeProperties, opts); diff --git a/packages/babel-types/src/modifications/typescript/removeTypeDuplicates.ts b/packages/babel-types/src/modifications/typescript/removeTypeDuplicates.ts index 1ed0e34f3f..b418dafc4b 100644 --- a/packages/babel-types/src/modifications/typescript/removeTypeDuplicates.ts +++ b/packages/babel-types/src/modifications/typescript/removeTypeDuplicates.ts @@ -3,13 +3,14 @@ import { isTSUnionType, isTSBaseType, } from "../../validators/generated"; +import type * as t from "../.."; /** * Dedupe type annotations. */ export default function removeTypeDuplicates( - nodes: Array, -): Array { + nodes: Array, +): Array { const generics = {}; const bases = {}; @@ -28,7 +29,7 @@ export default function removeTypeDuplicates( } // this type matches anything - if (isTSAnyKeyword(node.type)) { + if (isTSAnyKeyword(node)) { return [node]; } diff --git a/packages/babel-types/src/retrievers/getBindingIdentifiers.ts b/packages/babel-types/src/retrievers/getBindingIdentifiers.ts index d437409f40..8fe3500dbc 100644 --- a/packages/babel-types/src/retrievers/getBindingIdentifiers.ts +++ b/packages/babel-types/src/retrievers/getBindingIdentifiers.ts @@ -1,20 +1,41 @@ -// @flow import { isExportDeclaration, isIdentifier, isDeclaration, isFunctionDeclaration, isFunctionExpression, + isExportAllDeclaration, } from "../validators/generated"; +import type * as t from ".."; + +export { getBindingIdentifiers as default }; + +function getBindingIdentifiers( + node: t.Node, + duplicates: true, + outerOnly?: boolean, +): Record>; + +function getBindingIdentifiers( + node: t.Node, + duplicates?: false, + outerOnly?: boolean, +): Record; + +function getBindingIdentifiers( + node: t.Node, + duplicates?: boolean, + outerOnly?: boolean, +): Record | Record>; /** * Return a list of binding identifiers associated with the input `node`. */ -export default function getBindingIdentifiers( - node: Object, +function getBindingIdentifiers( + node: t.Node, duplicates?: boolean, outerOnly?: boolean, -): { [string]: Object | Array } { +): Record | Record> { let search = [].concat(node); const ids = Object.create(null); @@ -34,7 +55,7 @@ export default function getBindingIdentifiers( continue; } - if (isExportDeclaration(id)) { + if (isExportDeclaration(id) && !isExportAllDeclaration(id)) { if (isDeclaration(id.declaration)) { search.push(id.declaration); } diff --git a/packages/babel-types/src/retrievers/getOuterBindingIdentifiers.ts b/packages/babel-types/src/retrievers/getOuterBindingIdentifiers.ts index caade4b19b..f47eee436d 100644 --- a/packages/babel-types/src/retrievers/getOuterBindingIdentifiers.ts +++ b/packages/babel-types/src/retrievers/getOuterBindingIdentifiers.ts @@ -1,9 +1,17 @@ -// @flow import getBindingIdentifiers from "./getBindingIdentifiers"; +import type * as t from ".."; -export default function getOuterBindingIdentifiers( - node: Object, - duplicates?: boolean, -): { [string]: Object | Array } { +export default getOuterBindingIdentifiers as { + (node: t.Node, duplicates: true): Record>; + (node: t.Node, duplicates?: false): Record; + (node: t.Node, duplicates?: boolean): + | Record + | Record>; +}; + +function getOuterBindingIdentifiers( + node: t.Node, + duplicates: boolean, +): Record | Record> { return getBindingIdentifiers(node, duplicates, true); } diff --git a/packages/babel-types/src/traverse/traverse.ts b/packages/babel-types/src/traverse/traverse.ts index 3a72d4daa3..43e0c47f6e 100644 --- a/packages/babel-types/src/traverse/traverse.ts +++ b/packages/babel-types/src/traverse/traverse.ts @@ -1,15 +1,22 @@ -// @flow import { VISITOR_KEYS } from "../definitions"; +import type * as t from ".."; export type TraversalAncestors = Array<{ - node: BabelNode, - key: string, - index?: number, + node: t.Node; + key: string; + index?: number; }>; -export type TraversalHandler = (BabelNode, TraversalAncestors, T) => void; + +export type TraversalHandler = ( + this: undefined, + node: t.Node, + parent: TraversalAncestors, + state: T, +) => void; + export type TraversalHandlers = { - enter?: TraversalHandler, - exit?: TraversalHandler, + enter?: TraversalHandler; + exit?: TraversalHandler; }; /** @@ -18,7 +25,7 @@ export type TraversalHandlers = { * AST data can be taken into account. */ export default function traverse( - node: BabelNode, + node: t.Node, handlers: TraversalHandler | TraversalHandlers, state?: T, ): void { @@ -26,16 +33,16 @@ export default function traverse( handlers = { enter: handlers }; } - const { enter, exit } = (handlers: TraversalHandlers); + const { enter, exit } = handlers as TraversalHandlers; traverseSimpleImpl(node, enter, exit, state, []); } function traverseSimpleImpl( - node: Object, - enter: ?Function, - exit: ?Function, - state: ?T, + node: any, + enter: Function | undefined | null, + exit: Function | undefined | null, + state: T | undefined | null, ancestors: TraversalAncestors, ) { const keys = VISITOR_KEYS[node.type]; diff --git a/packages/babel-types/src/traverse/traverseFast.ts b/packages/babel-types/src/traverse/traverseFast.ts index e262c10ad4..d0dc337695 100644 --- a/packages/babel-types/src/traverse/traverseFast.ts +++ b/packages/babel-types/src/traverse/traverseFast.ts @@ -1,14 +1,15 @@ -// @flow import { VISITOR_KEYS } from "../definitions"; +import type * as t from ".."; /** * A prefix AST traversal implementation meant for simple searching * and processing. */ export default function traverseFast( - node: Object, - enter: (node: BabelNode, opts?: Object) => void, - opts?: Object, + node: t.Node | null | undefined, + enter: (node: t.Node, opts?: any) => void, + // todo(flow->ts) We could parametrize opts to T rather than any, so that the type is "forwarded" to the callback. + opts?: any, ): void { if (!node) return; diff --git a/packages/babel-types/src/utils/inherit.ts b/packages/babel-types/src/utils/inherit.ts index be57867e8b..53e65be848 100644 --- a/packages/babel-types/src/utils/inherit.ts +++ b/packages/babel-types/src/utils/inherit.ts @@ -1,8 +1,9 @@ -// @flow +import type * as t from ".."; + export default function inherit( key: string, - child: Object, - parent: Object, + child: t.Node, + parent: t.Node, ): void { if (child && parent) { child[key] = Array.from( diff --git a/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts b/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts index 038782e734..a4039e65c7 100644 --- a/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts +++ b/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts @@ -1,9 +1,11 @@ -// @flow import { stringLiteral } from "../../builders/generated"; +import type * as t from "../.."; export default function cleanJSXElementLiteralChild( - child: { value: string }, - args: Array, + child: { + value: string; + }, + args: Array, ) { const lines = child.value.split(/\r\n|\n|\r/); diff --git a/packages/babel-types/src/utils/shallowEqual.ts b/packages/babel-types/src/utils/shallowEqual.ts index 0d4caa46ea..98ddebcd7d 100644 --- a/packages/babel-types/src/utils/shallowEqual.ts +++ b/packages/babel-types/src/utils/shallowEqual.ts @@ -1,11 +1,10 @@ -// @flow -export default function shallowEqual( - actual: Object, - expected: Object, -): boolean { +export default function shallowEqual( + actual: object, + expected: T, +): actual is T { const keys = Object.keys(expected); - for (const key of (keys: Array)) { + for (const key of keys) { if (actual[key] !== expected[key]) { return false; } diff --git a/packages/babel-types/src/validators/buildMatchMemberExpression.ts b/packages/babel-types/src/validators/buildMatchMemberExpression.ts index 18612de07e..a020dba06b 100644 --- a/packages/babel-types/src/validators/buildMatchMemberExpression.ts +++ b/packages/babel-types/src/validators/buildMatchMemberExpression.ts @@ -1,4 +1,5 @@ import matchesPattern from "./matchesPattern"; +import type * as t from ".."; /** * Build a function that when called will return whether or not the @@ -10,9 +11,8 @@ import matchesPattern from "./matchesPattern"; export default function buildMatchMemberExpression( match: string, allowPartial?: boolean, -): Object => boolean { +) { const parts = match.split("."); - return (member: Object): boolean => - matchesPattern(member, parts, allowPartial); + return (member: t.Node) => matchesPattern(member, parts, allowPartial); } diff --git a/packages/babel-types/src/validators/generated/index.ts b/packages/babel-types/src/validators/generated/index.ts index 2bf0ed62ea..d839e1f62b 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -1,14 +1,17 @@ -// @flow /* * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ import shallowEqual from "../../utils/shallowEqual"; +import type * as t from "../.."; -export function isArrayExpression(node: ?Object, opts?: Object): boolean { +export function isArrayExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.ArrayExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ArrayExpression") { if (typeof opts === "undefined") { return true; @@ -19,10 +22,13 @@ export function isArrayExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isAssignmentExpression(node: ?Object, opts?: Object): boolean { +export function isAssignmentExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.AssignmentExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "AssignmentExpression") { if (typeof opts === "undefined") { return true; @@ -33,10 +39,13 @@ export function isAssignmentExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isBinaryExpression(node: ?Object, opts?: Object): boolean { +export function isBinaryExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.BinaryExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BinaryExpression") { if (typeof opts === "undefined") { return true; @@ -47,10 +56,13 @@ export function isBinaryExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isInterpreterDirective(node: ?Object, opts?: Object): boolean { +export function isInterpreterDirective( + node: object | null | undefined, + opts?: object | null, +): node is t.InterpreterDirective { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "InterpreterDirective") { if (typeof opts === "undefined") { return true; @@ -61,10 +73,13 @@ export function isInterpreterDirective(node: ?Object, opts?: Object): boolean { return false; } -export function isDirective(node: ?Object, opts?: Object): boolean { +export function isDirective( + node: object | null | undefined, + opts?: object | null, +): node is t.Directive { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Directive") { if (typeof opts === "undefined") { return true; @@ -75,10 +90,13 @@ export function isDirective(node: ?Object, opts?: Object): boolean { return false; } -export function isDirectiveLiteral(node: ?Object, opts?: Object): boolean { +export function isDirectiveLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.DirectiveLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DirectiveLiteral") { if (typeof opts === "undefined") { return true; @@ -89,10 +107,13 @@ export function isDirectiveLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isBlockStatement(node: ?Object, opts?: Object): boolean { +export function isBlockStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.BlockStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BlockStatement") { if (typeof opts === "undefined") { return true; @@ -103,10 +124,13 @@ export function isBlockStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isBreakStatement(node: ?Object, opts?: Object): boolean { +export function isBreakStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.BreakStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BreakStatement") { if (typeof opts === "undefined") { return true; @@ -117,10 +141,13 @@ export function isBreakStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isCallExpression(node: ?Object, opts?: Object): boolean { +export function isCallExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.CallExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "CallExpression") { if (typeof opts === "undefined") { return true; @@ -131,10 +158,13 @@ export function isCallExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isCatchClause(node: ?Object, opts?: Object): boolean { +export function isCatchClause( + node: object | null | undefined, + opts?: object | null, +): node is t.CatchClause { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "CatchClause") { if (typeof opts === "undefined") { return true; @@ -145,10 +175,13 @@ export function isCatchClause(node: ?Object, opts?: Object): boolean { return false; } -export function isConditionalExpression(node: ?Object, opts?: Object): boolean { +export function isConditionalExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.ConditionalExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ConditionalExpression") { if (typeof opts === "undefined") { return true; @@ -159,10 +192,13 @@ export function isConditionalExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isContinueStatement(node: ?Object, opts?: Object): boolean { +export function isContinueStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ContinueStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ContinueStatement") { if (typeof opts === "undefined") { return true; @@ -173,10 +209,13 @@ export function isContinueStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isDebuggerStatement(node: ?Object, opts?: Object): boolean { +export function isDebuggerStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.DebuggerStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DebuggerStatement") { if (typeof opts === "undefined") { return true; @@ -187,10 +226,13 @@ export function isDebuggerStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isDoWhileStatement(node: ?Object, opts?: Object): boolean { +export function isDoWhileStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.DoWhileStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DoWhileStatement") { if (typeof opts === "undefined") { return true; @@ -201,10 +243,13 @@ export function isDoWhileStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isEmptyStatement(node: ?Object, opts?: Object): boolean { +export function isEmptyStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.EmptyStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EmptyStatement") { if (typeof opts === "undefined") { return true; @@ -215,10 +260,13 @@ export function isEmptyStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isExpressionStatement(node: ?Object, opts?: Object): boolean { +export function isExpressionStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ExpressionStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExpressionStatement") { if (typeof opts === "undefined") { return true; @@ -229,10 +277,13 @@ export function isExpressionStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isFile(node: ?Object, opts?: Object): boolean { +export function isFile( + node: object | null | undefined, + opts?: object | null, +): node is t.File { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "File") { if (typeof opts === "undefined") { return true; @@ -243,10 +294,13 @@ export function isFile(node: ?Object, opts?: Object): boolean { return false; } -export function isForInStatement(node: ?Object, opts?: Object): boolean { +export function isForInStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ForInStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ForInStatement") { if (typeof opts === "undefined") { return true; @@ -257,10 +311,13 @@ export function isForInStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isForStatement(node: ?Object, opts?: Object): boolean { +export function isForStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ForStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ForStatement") { if (typeof opts === "undefined") { return true; @@ -271,10 +328,13 @@ export function isForStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isFunctionDeclaration(node: ?Object, opts?: Object): boolean { +export function isFunctionDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.FunctionDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "FunctionDeclaration") { if (typeof opts === "undefined") { return true; @@ -285,10 +345,13 @@ export function isFunctionDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isFunctionExpression(node: ?Object, opts?: Object): boolean { +export function isFunctionExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.FunctionExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "FunctionExpression") { if (typeof opts === "undefined") { return true; @@ -299,10 +362,13 @@ export function isFunctionExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isIdentifier(node: ?Object, opts?: Object): boolean { +export function isIdentifier( + node: object | null | undefined, + opts?: object | null, +): node is t.Identifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Identifier") { if (typeof opts === "undefined") { return true; @@ -313,10 +379,13 @@ export function isIdentifier(node: ?Object, opts?: Object): boolean { return false; } -export function isIfStatement(node: ?Object, opts?: Object): boolean { +export function isIfStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.IfStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "IfStatement") { if (typeof opts === "undefined") { return true; @@ -327,10 +396,13 @@ export function isIfStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isLabeledStatement(node: ?Object, opts?: Object): boolean { +export function isLabeledStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.LabeledStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "LabeledStatement") { if (typeof opts === "undefined") { return true; @@ -341,10 +413,13 @@ export function isLabeledStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isStringLiteral(node: ?Object, opts?: Object): boolean { +export function isStringLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.StringLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "StringLiteral") { if (typeof opts === "undefined") { return true; @@ -355,10 +430,13 @@ export function isStringLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isNumericLiteral(node: ?Object, opts?: Object): boolean { +export function isNumericLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.NumericLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NumericLiteral") { if (typeof opts === "undefined") { return true; @@ -369,10 +447,13 @@ export function isNumericLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isNullLiteral(node: ?Object, opts?: Object): boolean { +export function isNullLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.NullLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NullLiteral") { if (typeof opts === "undefined") { return true; @@ -383,10 +464,13 @@ export function isNullLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isBooleanLiteral(node: ?Object, opts?: Object): boolean { +export function isBooleanLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.BooleanLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BooleanLiteral") { if (typeof opts === "undefined") { return true; @@ -397,10 +481,13 @@ export function isBooleanLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isRegExpLiteral(node: ?Object, opts?: Object): boolean { +export function isRegExpLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.RegExpLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "RegExpLiteral") { if (typeof opts === "undefined") { return true; @@ -411,10 +498,13 @@ export function isRegExpLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isLogicalExpression(node: ?Object, opts?: Object): boolean { +export function isLogicalExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.LogicalExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "LogicalExpression") { if (typeof opts === "undefined") { return true; @@ -425,10 +515,13 @@ export function isLogicalExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isMemberExpression(node: ?Object, opts?: Object): boolean { +export function isMemberExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.MemberExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "MemberExpression") { if (typeof opts === "undefined") { return true; @@ -439,10 +532,13 @@ export function isMemberExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isNewExpression(node: ?Object, opts?: Object): boolean { +export function isNewExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.NewExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NewExpression") { if (typeof opts === "undefined") { return true; @@ -453,10 +549,13 @@ export function isNewExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isProgram(node: ?Object, opts?: Object): boolean { +export function isProgram( + node: object | null | undefined, + opts?: object | null, +): node is t.Program { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Program") { if (typeof opts === "undefined") { return true; @@ -467,10 +566,13 @@ export function isProgram(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectExpression(node: ?Object, opts?: Object): boolean { +export function isObjectExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectExpression") { if (typeof opts === "undefined") { return true; @@ -481,10 +583,13 @@ export function isObjectExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectMethod(node: ?Object, opts?: Object): boolean { +export function isObjectMethod( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectMethod { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectMethod") { if (typeof opts === "undefined") { return true; @@ -495,10 +600,13 @@ export function isObjectMethod(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectProperty(node: ?Object, opts?: Object): boolean { +export function isObjectProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectProperty") { if (typeof opts === "undefined") { return true; @@ -509,10 +617,13 @@ export function isObjectProperty(node: ?Object, opts?: Object): boolean { return false; } -export function isRestElement(node: ?Object, opts?: Object): boolean { +export function isRestElement( + node: object | null | undefined, + opts?: object | null, +): node is t.RestElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "RestElement") { if (typeof opts === "undefined") { return true; @@ -523,10 +634,13 @@ export function isRestElement(node: ?Object, opts?: Object): boolean { return false; } -export function isReturnStatement(node: ?Object, opts?: Object): boolean { +export function isReturnStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ReturnStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ReturnStatement") { if (typeof opts === "undefined") { return true; @@ -537,10 +651,13 @@ export function isReturnStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isSequenceExpression(node: ?Object, opts?: Object): boolean { +export function isSequenceExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.SequenceExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "SequenceExpression") { if (typeof opts === "undefined") { return true; @@ -552,12 +669,12 @@ export function isSequenceExpression(node: ?Object, opts?: Object): boolean { return false; } export function isParenthesizedExpression( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ParenthesizedExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ParenthesizedExpression") { if (typeof opts === "undefined") { return true; @@ -568,10 +685,13 @@ export function isParenthesizedExpression( return false; } -export function isSwitchCase(node: ?Object, opts?: Object): boolean { +export function isSwitchCase( + node: object | null | undefined, + opts?: object | null, +): node is t.SwitchCase { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "SwitchCase") { if (typeof opts === "undefined") { return true; @@ -582,10 +702,13 @@ export function isSwitchCase(node: ?Object, opts?: Object): boolean { return false; } -export function isSwitchStatement(node: ?Object, opts?: Object): boolean { +export function isSwitchStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.SwitchStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "SwitchStatement") { if (typeof opts === "undefined") { return true; @@ -596,10 +719,13 @@ export function isSwitchStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isThisExpression(node: ?Object, opts?: Object): boolean { +export function isThisExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.ThisExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ThisExpression") { if (typeof opts === "undefined") { return true; @@ -610,10 +736,13 @@ export function isThisExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isThrowStatement(node: ?Object, opts?: Object): boolean { +export function isThrowStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ThrowStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ThrowStatement") { if (typeof opts === "undefined") { return true; @@ -624,10 +753,13 @@ export function isThrowStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isTryStatement(node: ?Object, opts?: Object): boolean { +export function isTryStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.TryStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TryStatement") { if (typeof opts === "undefined") { return true; @@ -638,10 +770,13 @@ export function isTryStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isUnaryExpression(node: ?Object, opts?: Object): boolean { +export function isUnaryExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.UnaryExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "UnaryExpression") { if (typeof opts === "undefined") { return true; @@ -652,10 +787,13 @@ export function isUnaryExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isUpdateExpression(node: ?Object, opts?: Object): boolean { +export function isUpdateExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.UpdateExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "UpdateExpression") { if (typeof opts === "undefined") { return true; @@ -666,10 +804,13 @@ export function isUpdateExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isVariableDeclaration(node: ?Object, opts?: Object): boolean { +export function isVariableDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.VariableDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "VariableDeclaration") { if (typeof opts === "undefined") { return true; @@ -680,10 +821,13 @@ export function isVariableDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isVariableDeclarator(node: ?Object, opts?: Object): boolean { +export function isVariableDeclarator( + node: object | null | undefined, + opts?: object | null, +): node is t.VariableDeclarator { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "VariableDeclarator") { if (typeof opts === "undefined") { return true; @@ -694,10 +838,13 @@ export function isVariableDeclarator(node: ?Object, opts?: Object): boolean { return false; } -export function isWhileStatement(node: ?Object, opts?: Object): boolean { +export function isWhileStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.WhileStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "WhileStatement") { if (typeof opts === "undefined") { return true; @@ -708,10 +855,13 @@ export function isWhileStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isWithStatement(node: ?Object, opts?: Object): boolean { +export function isWithStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.WithStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "WithStatement") { if (typeof opts === "undefined") { return true; @@ -722,10 +872,13 @@ export function isWithStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isAssignmentPattern(node: ?Object, opts?: Object): boolean { +export function isAssignmentPattern( + node: object | null | undefined, + opts?: object | null, +): node is t.AssignmentPattern { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "AssignmentPattern") { if (typeof opts === "undefined") { return true; @@ -736,10 +889,13 @@ export function isAssignmentPattern(node: ?Object, opts?: Object): boolean { return false; } -export function isArrayPattern(node: ?Object, opts?: Object): boolean { +export function isArrayPattern( + node: object | null | undefined, + opts?: object | null, +): node is t.ArrayPattern { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ArrayPattern") { if (typeof opts === "undefined") { return true; @@ -751,12 +907,12 @@ export function isArrayPattern(node: ?Object, opts?: Object): boolean { return false; } export function isArrowFunctionExpression( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ArrowFunctionExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ArrowFunctionExpression") { if (typeof opts === "undefined") { return true; @@ -767,10 +923,13 @@ export function isArrowFunctionExpression( return false; } -export function isClassBody(node: ?Object, opts?: Object): boolean { +export function isClassBody( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassBody") { if (typeof opts === "undefined") { return true; @@ -781,10 +940,13 @@ export function isClassBody(node: ?Object, opts?: Object): boolean { return false; } -export function isClassExpression(node: ?Object, opts?: Object): boolean { +export function isClassExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassExpression") { if (typeof opts === "undefined") { return true; @@ -795,10 +957,13 @@ export function isClassExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isClassDeclaration(node: ?Object, opts?: Object): boolean { +export function isClassDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassDeclaration") { if (typeof opts === "undefined") { return true; @@ -809,10 +974,13 @@ export function isClassDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isExportAllDeclaration(node: ?Object, opts?: Object): boolean { +export function isExportAllDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.ExportAllDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExportAllDeclaration") { if (typeof opts === "undefined") { return true; @@ -824,12 +992,12 @@ export function isExportAllDeclaration(node: ?Object, opts?: Object): boolean { return false; } export function isExportDefaultDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ExportDefaultDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExportDefaultDeclaration") { if (typeof opts === "undefined") { return true; @@ -841,12 +1009,12 @@ export function isExportDefaultDeclaration( return false; } export function isExportNamedDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ExportNamedDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExportNamedDeclaration") { if (typeof opts === "undefined") { return true; @@ -857,10 +1025,13 @@ export function isExportNamedDeclaration( return false; } -export function isExportSpecifier(node: ?Object, opts?: Object): boolean { +export function isExportSpecifier( + node: object | null | undefined, + opts?: object | null, +): node is t.ExportSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExportSpecifier") { if (typeof opts === "undefined") { return true; @@ -871,10 +1042,13 @@ export function isExportSpecifier(node: ?Object, opts?: Object): boolean { return false; } -export function isForOfStatement(node: ?Object, opts?: Object): boolean { +export function isForOfStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ForOfStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ForOfStatement") { if (typeof opts === "undefined") { return true; @@ -885,10 +1059,13 @@ export function isForOfStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isImportDeclaration(node: ?Object, opts?: Object): boolean { +export function isImportDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.ImportDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ImportDeclaration") { if (typeof opts === "undefined") { return true; @@ -900,12 +1077,12 @@ export function isImportDeclaration(node: ?Object, opts?: Object): boolean { return false; } export function isImportDefaultSpecifier( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ImportDefaultSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ImportDefaultSpecifier") { if (typeof opts === "undefined") { return true; @@ -917,12 +1094,12 @@ export function isImportDefaultSpecifier( return false; } export function isImportNamespaceSpecifier( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ImportNamespaceSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ImportNamespaceSpecifier") { if (typeof opts === "undefined") { return true; @@ -933,10 +1110,13 @@ export function isImportNamespaceSpecifier( return false; } -export function isImportSpecifier(node: ?Object, opts?: Object): boolean { +export function isImportSpecifier( + node: object | null | undefined, + opts?: object | null, +): node is t.ImportSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ImportSpecifier") { if (typeof opts === "undefined") { return true; @@ -947,10 +1127,13 @@ export function isImportSpecifier(node: ?Object, opts?: Object): boolean { return false; } -export function isMetaProperty(node: ?Object, opts?: Object): boolean { +export function isMetaProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.MetaProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "MetaProperty") { if (typeof opts === "undefined") { return true; @@ -961,10 +1144,13 @@ export function isMetaProperty(node: ?Object, opts?: Object): boolean { return false; } -export function isClassMethod(node: ?Object, opts?: Object): boolean { +export function isClassMethod( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassMethod { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassMethod") { if (typeof opts === "undefined") { return true; @@ -975,10 +1161,13 @@ export function isClassMethod(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectPattern(node: ?Object, opts?: Object): boolean { +export function isObjectPattern( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectPattern { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectPattern") { if (typeof opts === "undefined") { return true; @@ -989,10 +1178,13 @@ export function isObjectPattern(node: ?Object, opts?: Object): boolean { return false; } -export function isSpreadElement(node: ?Object, opts?: Object): boolean { +export function isSpreadElement( + node: object | null | undefined, + opts?: object | null, +): node is t.SpreadElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "SpreadElement") { if (typeof opts === "undefined") { return true; @@ -1003,10 +1195,13 @@ export function isSpreadElement(node: ?Object, opts?: Object): boolean { return false; } -export function isSuper(node: ?Object, opts?: Object): boolean { +export function isSuper( + node: object | null | undefined, + opts?: object | null, +): node is t.Super { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Super") { if (typeof opts === "undefined") { return true; @@ -1018,12 +1213,12 @@ export function isSuper(node: ?Object, opts?: Object): boolean { return false; } export function isTaggedTemplateExpression( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TaggedTemplateExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TaggedTemplateExpression") { if (typeof opts === "undefined") { return true; @@ -1034,10 +1229,13 @@ export function isTaggedTemplateExpression( return false; } -export function isTemplateElement(node: ?Object, opts?: Object): boolean { +export function isTemplateElement( + node: object | null | undefined, + opts?: object | null, +): node is t.TemplateElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TemplateElement") { if (typeof opts === "undefined") { return true; @@ -1048,10 +1246,13 @@ export function isTemplateElement(node: ?Object, opts?: Object): boolean { return false; } -export function isTemplateLiteral(node: ?Object, opts?: Object): boolean { +export function isTemplateLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.TemplateLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TemplateLiteral") { if (typeof opts === "undefined") { return true; @@ -1062,10 +1263,13 @@ export function isTemplateLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isYieldExpression(node: ?Object, opts?: Object): boolean { +export function isYieldExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.YieldExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "YieldExpression") { if (typeof opts === "undefined") { return true; @@ -1076,10 +1280,13 @@ export function isYieldExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isAwaitExpression(node: ?Object, opts?: Object): boolean { +export function isAwaitExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.AwaitExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "AwaitExpression") { if (typeof opts === "undefined") { return true; @@ -1090,10 +1297,13 @@ export function isAwaitExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isImport(node: ?Object, opts?: Object): boolean { +export function isImport( + node: object | null | undefined, + opts?: object | null, +): node is t.Import { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Import") { if (typeof opts === "undefined") { return true; @@ -1104,10 +1314,13 @@ export function isImport(node: ?Object, opts?: Object): boolean { return false; } -export function isBigIntLiteral(node: ?Object, opts?: Object): boolean { +export function isBigIntLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.BigIntLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BigIntLiteral") { if (typeof opts === "undefined") { return true; @@ -1119,12 +1332,12 @@ export function isBigIntLiteral(node: ?Object, opts?: Object): boolean { return false; } export function isExportNamespaceSpecifier( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ExportNamespaceSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExportNamespaceSpecifier") { if (typeof opts === "undefined") { return true; @@ -1136,12 +1349,12 @@ export function isExportNamespaceSpecifier( return false; } export function isOptionalMemberExpression( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.OptionalMemberExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "OptionalMemberExpression") { if (typeof opts === "undefined") { return true; @@ -1153,12 +1366,12 @@ export function isOptionalMemberExpression( return false; } export function isOptionalCallExpression( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.OptionalCallExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "OptionalCallExpression") { if (typeof opts === "undefined") { return true; @@ -1169,10 +1382,13 @@ export function isOptionalCallExpression( return false; } -export function isAnyTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isAnyTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.AnyTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "AnyTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1183,10 +1399,13 @@ export function isAnyTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isArrayTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isArrayTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.ArrayTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ArrayTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1197,10 +1416,13 @@ export function isArrayTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isBooleanTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isBooleanTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.BooleanTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BooleanTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1212,12 +1434,12 @@ export function isBooleanTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } export function isBooleanLiteralTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.BooleanLiteralTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BooleanLiteralTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1229,12 +1451,12 @@ export function isBooleanLiteralTypeAnnotation( return false; } export function isNullLiteralTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.NullLiteralTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NullLiteralTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1245,10 +1467,13 @@ export function isNullLiteralTypeAnnotation( return false; } -export function isClassImplements(node: ?Object, opts?: Object): boolean { +export function isClassImplements( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassImplements { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassImplements") { if (typeof opts === "undefined") { return true; @@ -1259,10 +1484,13 @@ export function isClassImplements(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareClass(node: ?Object, opts?: Object): boolean { +export function isDeclareClass( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareClass { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareClass") { if (typeof opts === "undefined") { return true; @@ -1273,10 +1501,13 @@ export function isDeclareClass(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareFunction(node: ?Object, opts?: Object): boolean { +export function isDeclareFunction( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareFunction { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareFunction") { if (typeof opts === "undefined") { return true; @@ -1287,10 +1518,13 @@ export function isDeclareFunction(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareInterface(node: ?Object, opts?: Object): boolean { +export function isDeclareInterface( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareInterface { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareInterface") { if (typeof opts === "undefined") { return true; @@ -1301,10 +1535,13 @@ export function isDeclareInterface(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareModule(node: ?Object, opts?: Object): boolean { +export function isDeclareModule( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareModule { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareModule") { if (typeof opts === "undefined") { return true; @@ -1315,10 +1552,13 @@ export function isDeclareModule(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareModuleExports(node: ?Object, opts?: Object): boolean { +export function isDeclareModuleExports( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareModuleExports { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareModuleExports") { if (typeof opts === "undefined") { return true; @@ -1329,10 +1569,13 @@ export function isDeclareModuleExports(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareTypeAlias(node: ?Object, opts?: Object): boolean { +export function isDeclareTypeAlias( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareTypeAlias { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareTypeAlias") { if (typeof opts === "undefined") { return true; @@ -1343,10 +1586,13 @@ export function isDeclareTypeAlias(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareOpaqueType(node: ?Object, opts?: Object): boolean { +export function isDeclareOpaqueType( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareOpaqueType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareOpaqueType") { if (typeof opts === "undefined") { return true; @@ -1357,10 +1603,13 @@ export function isDeclareOpaqueType(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclareVariable(node: ?Object, opts?: Object): boolean { +export function isDeclareVariable( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareVariable { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareVariable") { if (typeof opts === "undefined") { return true; @@ -1372,12 +1621,12 @@ export function isDeclareVariable(node: ?Object, opts?: Object): boolean { return false; } export function isDeclareExportDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareExportDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareExportDeclaration") { if (typeof opts === "undefined") { return true; @@ -1389,12 +1638,12 @@ export function isDeclareExportDeclaration( return false; } export function isDeclareExportAllDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.DeclareExportAllDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclareExportAllDeclaration") { if (typeof opts === "undefined") { return true; @@ -1405,10 +1654,13 @@ export function isDeclareExportAllDeclaration( return false; } -export function isDeclaredPredicate(node: ?Object, opts?: Object): boolean { +export function isDeclaredPredicate( + node: object | null | undefined, + opts?: object | null, +): node is t.DeclaredPredicate { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DeclaredPredicate") { if (typeof opts === "undefined") { return true; @@ -1419,10 +1671,13 @@ export function isDeclaredPredicate(node: ?Object, opts?: Object): boolean { return false; } -export function isExistsTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isExistsTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.ExistsTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExistsTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1434,12 +1689,12 @@ export function isExistsTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } export function isFunctionTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.FunctionTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "FunctionTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1450,10 +1705,13 @@ export function isFunctionTypeAnnotation( return false; } -export function isFunctionTypeParam(node: ?Object, opts?: Object): boolean { +export function isFunctionTypeParam( + node: object | null | undefined, + opts?: object | null, +): node is t.FunctionTypeParam { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "FunctionTypeParam") { if (typeof opts === "undefined") { return true; @@ -1464,10 +1722,13 @@ export function isFunctionTypeParam(node: ?Object, opts?: Object): boolean { return false; } -export function isGenericTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isGenericTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.GenericTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "GenericTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1478,10 +1739,13 @@ export function isGenericTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isInferredPredicate(node: ?Object, opts?: Object): boolean { +export function isInferredPredicate( + node: object | null | undefined, + opts?: object | null, +): node is t.InferredPredicate { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "InferredPredicate") { if (typeof opts === "undefined") { return true; @@ -1492,10 +1756,13 @@ export function isInferredPredicate(node: ?Object, opts?: Object): boolean { return false; } -export function isInterfaceExtends(node: ?Object, opts?: Object): boolean { +export function isInterfaceExtends( + node: object | null | undefined, + opts?: object | null, +): node is t.InterfaceExtends { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "InterfaceExtends") { if (typeof opts === "undefined") { return true; @@ -1506,10 +1773,13 @@ export function isInterfaceExtends(node: ?Object, opts?: Object): boolean { return false; } -export function isInterfaceDeclaration(node: ?Object, opts?: Object): boolean { +export function isInterfaceDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.InterfaceDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "InterfaceDeclaration") { if (typeof opts === "undefined") { return true; @@ -1521,12 +1791,12 @@ export function isInterfaceDeclaration(node: ?Object, opts?: Object): boolean { return false; } export function isInterfaceTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.InterfaceTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "InterfaceTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1538,12 +1808,12 @@ export function isInterfaceTypeAnnotation( return false; } export function isIntersectionTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.IntersectionTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "IntersectionTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1554,10 +1824,13 @@ export function isIntersectionTypeAnnotation( return false; } -export function isMixedTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isMixedTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.MixedTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "MixedTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1568,10 +1841,13 @@ export function isMixedTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isEmptyTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isEmptyTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.EmptyTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EmptyTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1583,12 +1859,12 @@ export function isEmptyTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } export function isNullableTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.NullableTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NullableTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1600,12 +1876,12 @@ export function isNullableTypeAnnotation( return false; } export function isNumberLiteralTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.NumberLiteralTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NumberLiteralTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1616,10 +1892,13 @@ export function isNumberLiteralTypeAnnotation( return false; } -export function isNumberTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isNumberTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.NumberTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NumberTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1630,10 +1909,13 @@ export function isNumberTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isObjectTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1645,12 +1927,12 @@ export function isObjectTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } export function isObjectTypeInternalSlot( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectTypeInternalSlot { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectTypeInternalSlot") { if (typeof opts === "undefined") { return true; @@ -1662,12 +1944,12 @@ export function isObjectTypeInternalSlot( return false; } export function isObjectTypeCallProperty( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectTypeCallProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectTypeCallProperty") { if (typeof opts === "undefined") { return true; @@ -1678,10 +1960,13 @@ export function isObjectTypeCallProperty( return false; } -export function isObjectTypeIndexer(node: ?Object, opts?: Object): boolean { +export function isObjectTypeIndexer( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectTypeIndexer { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectTypeIndexer") { if (typeof opts === "undefined") { return true; @@ -1692,10 +1977,13 @@ export function isObjectTypeIndexer(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectTypeProperty(node: ?Object, opts?: Object): boolean { +export function isObjectTypeProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectTypeProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectTypeProperty") { if (typeof opts === "undefined") { return true; @@ -1707,12 +1995,12 @@ export function isObjectTypeProperty(node: ?Object, opts?: Object): boolean { return false; } export function isObjectTypeSpreadProperty( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectTypeSpreadProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ObjectTypeSpreadProperty") { if (typeof opts === "undefined") { return true; @@ -1723,10 +2011,13 @@ export function isObjectTypeSpreadProperty( return false; } -export function isOpaqueType(node: ?Object, opts?: Object): boolean { +export function isOpaqueType( + node: object | null | undefined, + opts?: object | null, +): node is t.OpaqueType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "OpaqueType") { if (typeof opts === "undefined") { return true; @@ -1738,12 +2029,12 @@ export function isOpaqueType(node: ?Object, opts?: Object): boolean { return false; } export function isQualifiedTypeIdentifier( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.QualifiedTypeIdentifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "QualifiedTypeIdentifier") { if (typeof opts === "undefined") { return true; @@ -1755,12 +2046,12 @@ export function isQualifiedTypeIdentifier( return false; } export function isStringLiteralTypeAnnotation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.StringLiteralTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "StringLiteralTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1771,10 +2062,13 @@ export function isStringLiteralTypeAnnotation( return false; } -export function isStringTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isStringTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.StringTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "StringTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1785,10 +2079,13 @@ export function isStringTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isSymbolTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isSymbolTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.SymbolTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "SymbolTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1799,10 +2096,13 @@ export function isSymbolTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isThisTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isThisTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.ThisTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ThisTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1813,10 +2113,13 @@ export function isThisTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isTupleTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isTupleTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.TupleTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TupleTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1827,10 +2130,13 @@ export function isTupleTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isTypeofTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isTypeofTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.TypeofTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeofTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1841,10 +2147,13 @@ export function isTypeofTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isTypeAlias(node: ?Object, opts?: Object): boolean { +export function isTypeAlias( + node: object | null | undefined, + opts?: object | null, +): node is t.TypeAlias { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeAlias") { if (typeof opts === "undefined") { return true; @@ -1855,10 +2164,13 @@ export function isTypeAlias(node: ?Object, opts?: Object): boolean { return false; } -export function isTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.TypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1869,10 +2181,13 @@ export function isTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isTypeCastExpression(node: ?Object, opts?: Object): boolean { +export function isTypeCastExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.TypeCastExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeCastExpression") { if (typeof opts === "undefined") { return true; @@ -1883,10 +2198,13 @@ export function isTypeCastExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isTypeParameter(node: ?Object, opts?: Object): boolean { +export function isTypeParameter( + node: object | null | undefined, + opts?: object | null, +): node is t.TypeParameter { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeParameter") { if (typeof opts === "undefined") { return true; @@ -1898,12 +2216,12 @@ export function isTypeParameter(node: ?Object, opts?: Object): boolean { return false; } export function isTypeParameterDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TypeParameterDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeParameterDeclaration") { if (typeof opts === "undefined") { return true; @@ -1915,12 +2233,12 @@ export function isTypeParameterDeclaration( return false; } export function isTypeParameterInstantiation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TypeParameterInstantiation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TypeParameterInstantiation") { if (typeof opts === "undefined") { return true; @@ -1931,10 +2249,13 @@ export function isTypeParameterInstantiation( return false; } -export function isUnionTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isUnionTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.UnionTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "UnionTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1945,10 +2266,13 @@ export function isUnionTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isVariance(node: ?Object, opts?: Object): boolean { +export function isVariance( + node: object | null | undefined, + opts?: object | null, +): node is t.Variance { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Variance") { if (typeof opts === "undefined") { return true; @@ -1959,10 +2283,13 @@ export function isVariance(node: ?Object, opts?: Object): boolean { return false; } -export function isVoidTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isVoidTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.VoidTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "VoidTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -1973,10 +2300,13 @@ export function isVoidTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumDeclaration(node: ?Object, opts?: Object): boolean { +export function isEnumDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumDeclaration") { if (typeof opts === "undefined") { return true; @@ -1987,10 +2317,13 @@ export function isEnumDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumBooleanBody(node: ?Object, opts?: Object): boolean { +export function isEnumBooleanBody( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumBooleanBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumBooleanBody") { if (typeof opts === "undefined") { return true; @@ -2001,10 +2334,13 @@ export function isEnumBooleanBody(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumNumberBody(node: ?Object, opts?: Object): boolean { +export function isEnumNumberBody( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumNumberBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumNumberBody") { if (typeof opts === "undefined") { return true; @@ -2015,10 +2351,13 @@ export function isEnumNumberBody(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumStringBody(node: ?Object, opts?: Object): boolean { +export function isEnumStringBody( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumStringBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumStringBody") { if (typeof opts === "undefined") { return true; @@ -2029,10 +2368,13 @@ export function isEnumStringBody(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumSymbolBody(node: ?Object, opts?: Object): boolean { +export function isEnumSymbolBody( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumSymbolBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumSymbolBody") { if (typeof opts === "undefined") { return true; @@ -2043,10 +2385,13 @@ export function isEnumSymbolBody(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumBooleanMember(node: ?Object, opts?: Object): boolean { +export function isEnumBooleanMember( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumBooleanMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumBooleanMember") { if (typeof opts === "undefined") { return true; @@ -2057,10 +2402,13 @@ export function isEnumBooleanMember(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumNumberMember(node: ?Object, opts?: Object): boolean { +export function isEnumNumberMember( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumNumberMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumNumberMember") { if (typeof opts === "undefined") { return true; @@ -2071,10 +2419,13 @@ export function isEnumNumberMember(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumStringMember(node: ?Object, opts?: Object): boolean { +export function isEnumStringMember( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumStringMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumStringMember") { if (typeof opts === "undefined") { return true; @@ -2085,10 +2436,13 @@ export function isEnumStringMember(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumDefaultedMember(node: ?Object, opts?: Object): boolean { +export function isEnumDefaultedMember( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumDefaultedMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "EnumDefaultedMember") { if (typeof opts === "undefined") { return true; @@ -2099,10 +2453,13 @@ export function isEnumDefaultedMember(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXAttribute(node: ?Object, opts?: Object): boolean { +export function isJSXAttribute( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXAttribute { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXAttribute") { if (typeof opts === "undefined") { return true; @@ -2113,10 +2470,13 @@ export function isJSXAttribute(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXClosingElement(node: ?Object, opts?: Object): boolean { +export function isJSXClosingElement( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXClosingElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXClosingElement") { if (typeof opts === "undefined") { return true; @@ -2127,10 +2487,13 @@ export function isJSXClosingElement(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXElement(node: ?Object, opts?: Object): boolean { +export function isJSXElement( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXElement") { if (typeof opts === "undefined") { return true; @@ -2141,10 +2504,13 @@ export function isJSXElement(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXEmptyExpression(node: ?Object, opts?: Object): boolean { +export function isJSXEmptyExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXEmptyExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXEmptyExpression") { if (typeof opts === "undefined") { return true; @@ -2156,12 +2522,12 @@ export function isJSXEmptyExpression(node: ?Object, opts?: Object): boolean { return false; } export function isJSXExpressionContainer( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.JSXExpressionContainer { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXExpressionContainer") { if (typeof opts === "undefined") { return true; @@ -2172,10 +2538,13 @@ export function isJSXExpressionContainer( return false; } -export function isJSXSpreadChild(node: ?Object, opts?: Object): boolean { +export function isJSXSpreadChild( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXSpreadChild { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXSpreadChild") { if (typeof opts === "undefined") { return true; @@ -2186,10 +2555,13 @@ export function isJSXSpreadChild(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXIdentifier(node: ?Object, opts?: Object): boolean { +export function isJSXIdentifier( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXIdentifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXIdentifier") { if (typeof opts === "undefined") { return true; @@ -2200,10 +2572,13 @@ export function isJSXIdentifier(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXMemberExpression(node: ?Object, opts?: Object): boolean { +export function isJSXMemberExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXMemberExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXMemberExpression") { if (typeof opts === "undefined") { return true; @@ -2214,10 +2589,13 @@ export function isJSXMemberExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXNamespacedName(node: ?Object, opts?: Object): boolean { +export function isJSXNamespacedName( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXNamespacedName { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXNamespacedName") { if (typeof opts === "undefined") { return true; @@ -2228,10 +2606,13 @@ export function isJSXNamespacedName(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXOpeningElement(node: ?Object, opts?: Object): boolean { +export function isJSXOpeningElement( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXOpeningElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXOpeningElement") { if (typeof opts === "undefined") { return true; @@ -2242,10 +2623,13 @@ export function isJSXOpeningElement(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXSpreadAttribute(node: ?Object, opts?: Object): boolean { +export function isJSXSpreadAttribute( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXSpreadAttribute { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXSpreadAttribute") { if (typeof opts === "undefined") { return true; @@ -2256,10 +2640,13 @@ export function isJSXSpreadAttribute(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXText(node: ?Object, opts?: Object): boolean { +export function isJSXText( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXText { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXText") { if (typeof opts === "undefined") { return true; @@ -2270,10 +2657,13 @@ export function isJSXText(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXFragment(node: ?Object, opts?: Object): boolean { +export function isJSXFragment( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXFragment { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXFragment") { if (typeof opts === "undefined") { return true; @@ -2284,10 +2674,13 @@ export function isJSXFragment(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXOpeningFragment(node: ?Object, opts?: Object): boolean { +export function isJSXOpeningFragment( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXOpeningFragment { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXOpeningFragment") { if (typeof opts === "undefined") { return true; @@ -2298,10 +2691,13 @@ export function isJSXOpeningFragment(node: ?Object, opts?: Object): boolean { return false; } -export function isJSXClosingFragment(node: ?Object, opts?: Object): boolean { +export function isJSXClosingFragment( + node: object | null | undefined, + opts?: object | null, +): node is t.JSXClosingFragment { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "JSXClosingFragment") { if (typeof opts === "undefined") { return true; @@ -2312,10 +2708,13 @@ export function isJSXClosingFragment(node: ?Object, opts?: Object): boolean { return false; } -export function isNoop(node: ?Object, opts?: Object): boolean { +export function isNoop( + node: object | null | undefined, + opts?: object | null, +): node is t.Noop { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Noop") { if (typeof opts === "undefined") { return true; @@ -2326,10 +2725,13 @@ export function isNoop(node: ?Object, opts?: Object): boolean { return false; } -export function isPlaceholder(node: ?Object, opts?: Object): boolean { +export function isPlaceholder( + node: object | null | undefined, + opts?: object | null, +): node is t.Placeholder { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Placeholder") { if (typeof opts === "undefined") { return true; @@ -2340,10 +2742,13 @@ export function isPlaceholder(node: ?Object, opts?: Object): boolean { return false; } -export function isV8IntrinsicIdentifier(node: ?Object, opts?: Object): boolean { +export function isV8IntrinsicIdentifier( + node: object | null | undefined, + opts?: object | null, +): node is t.V8IntrinsicIdentifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "V8IntrinsicIdentifier") { if (typeof opts === "undefined") { return true; @@ -2354,10 +2759,13 @@ export function isV8IntrinsicIdentifier(node: ?Object, opts?: Object): boolean { return false; } -export function isArgumentPlaceholder(node: ?Object, opts?: Object): boolean { +export function isArgumentPlaceholder( + node: object | null | undefined, + opts?: object | null, +): node is t.ArgumentPlaceholder { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ArgumentPlaceholder") { if (typeof opts === "undefined") { return true; @@ -2368,10 +2776,13 @@ export function isArgumentPlaceholder(node: ?Object, opts?: Object): boolean { return false; } -export function isBindExpression(node: ?Object, opts?: Object): boolean { +export function isBindExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.BindExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "BindExpression") { if (typeof opts === "undefined") { return true; @@ -2382,10 +2793,13 @@ export function isBindExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isClassProperty(node: ?Object, opts?: Object): boolean { +export function isClassProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassProperty") { if (typeof opts === "undefined") { return true; @@ -2397,12 +2811,12 @@ export function isClassProperty(node: ?Object, opts?: Object): boolean { return false; } export function isPipelineTopicExpression( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.PipelineTopicExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "PipelineTopicExpression") { if (typeof opts === "undefined") { return true; @@ -2413,10 +2827,13 @@ export function isPipelineTopicExpression( return false; } -export function isPipelineBareFunction(node: ?Object, opts?: Object): boolean { +export function isPipelineBareFunction( + node: object | null | undefined, + opts?: object | null, +): node is t.PipelineBareFunction { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "PipelineBareFunction") { if (typeof opts === "undefined") { return true; @@ -2428,12 +2845,12 @@ export function isPipelineBareFunction(node: ?Object, opts?: Object): boolean { return false; } export function isPipelinePrimaryTopicReference( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.PipelinePrimaryTopicReference { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "PipelinePrimaryTopicReference") { if (typeof opts === "undefined") { return true; @@ -2444,10 +2861,13 @@ export function isPipelinePrimaryTopicReference( return false; } -export function isClassPrivateProperty(node: ?Object, opts?: Object): boolean { +export function isClassPrivateProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassPrivateProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassPrivateProperty") { if (typeof opts === "undefined") { return true; @@ -2458,10 +2878,13 @@ export function isClassPrivateProperty(node: ?Object, opts?: Object): boolean { return false; } -export function isClassPrivateMethod(node: ?Object, opts?: Object): boolean { +export function isClassPrivateMethod( + node: object | null | undefined, + opts?: object | null, +): node is t.ClassPrivateMethod { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ClassPrivateMethod") { if (typeof opts === "undefined") { return true; @@ -2472,10 +2895,13 @@ export function isClassPrivateMethod(node: ?Object, opts?: Object): boolean { return false; } -export function isImportAttribute(node: ?Object, opts?: Object): boolean { +export function isImportAttribute( + node: object | null | undefined, + opts?: object | null, +): node is t.ImportAttribute { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ImportAttribute") { if (typeof opts === "undefined") { return true; @@ -2486,10 +2912,13 @@ export function isImportAttribute(node: ?Object, opts?: Object): boolean { return false; } -export function isDecorator(node: ?Object, opts?: Object): boolean { +export function isDecorator( + node: object | null | undefined, + opts?: object | null, +): node is t.Decorator { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "Decorator") { if (typeof opts === "undefined") { return true; @@ -2500,10 +2929,13 @@ export function isDecorator(node: ?Object, opts?: Object): boolean { return false; } -export function isDoExpression(node: ?Object, opts?: Object): boolean { +export function isDoExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.DoExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DoExpression") { if (typeof opts === "undefined") { return true; @@ -2515,12 +2947,12 @@ export function isDoExpression(node: ?Object, opts?: Object): boolean { return false; } export function isExportDefaultSpecifier( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.ExportDefaultSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "ExportDefaultSpecifier") { if (typeof opts === "undefined") { return true; @@ -2531,10 +2963,13 @@ export function isExportDefaultSpecifier( return false; } -export function isPrivateName(node: ?Object, opts?: Object): boolean { +export function isPrivateName( + node: object | null | undefined, + opts?: object | null, +): node is t.PrivateName { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "PrivateName") { if (typeof opts === "undefined") { return true; @@ -2545,10 +2980,13 @@ export function isPrivateName(node: ?Object, opts?: Object): boolean { return false; } -export function isRecordExpression(node: ?Object, opts?: Object): boolean { +export function isRecordExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.RecordExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "RecordExpression") { if (typeof opts === "undefined") { return true; @@ -2559,10 +2997,13 @@ export function isRecordExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isTupleExpression(node: ?Object, opts?: Object): boolean { +export function isTupleExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.TupleExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TupleExpression") { if (typeof opts === "undefined") { return true; @@ -2573,10 +3014,13 @@ export function isTupleExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isDecimalLiteral(node: ?Object, opts?: Object): boolean { +export function isDecimalLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.DecimalLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "DecimalLiteral") { if (typeof opts === "undefined") { return true; @@ -2587,10 +3031,13 @@ export function isDecimalLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isStaticBlock(node: ?Object, opts?: Object): boolean { +export function isStaticBlock( + node: object | null | undefined, + opts?: object | null, +): node is t.StaticBlock { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "StaticBlock") { if (typeof opts === "undefined") { return true; @@ -2601,10 +3048,13 @@ export function isStaticBlock(node: ?Object, opts?: Object): boolean { return false; } -export function isTSParameterProperty(node: ?Object, opts?: Object): boolean { +export function isTSParameterProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.TSParameterProperty { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSParameterProperty") { if (typeof opts === "undefined") { return true; @@ -2615,10 +3065,13 @@ export function isTSParameterProperty(node: ?Object, opts?: Object): boolean { return false; } -export function isTSDeclareFunction(node: ?Object, opts?: Object): boolean { +export function isTSDeclareFunction( + node: object | null | undefined, + opts?: object | null, +): node is t.TSDeclareFunction { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSDeclareFunction") { if (typeof opts === "undefined") { return true; @@ -2629,10 +3082,13 @@ export function isTSDeclareFunction(node: ?Object, opts?: Object): boolean { return false; } -export function isTSDeclareMethod(node: ?Object, opts?: Object): boolean { +export function isTSDeclareMethod( + node: object | null | undefined, + opts?: object | null, +): node is t.TSDeclareMethod { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSDeclareMethod") { if (typeof opts === "undefined") { return true; @@ -2643,10 +3099,13 @@ export function isTSDeclareMethod(node: ?Object, opts?: Object): boolean { return false; } -export function isTSQualifiedName(node: ?Object, opts?: Object): boolean { +export function isTSQualifiedName( + node: object | null | undefined, + opts?: object | null, +): node is t.TSQualifiedName { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSQualifiedName") { if (typeof opts === "undefined") { return true; @@ -2658,12 +3117,12 @@ export function isTSQualifiedName(node: ?Object, opts?: Object): boolean { return false; } export function isTSCallSignatureDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSCallSignatureDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSCallSignatureDeclaration") { if (typeof opts === "undefined") { return true; @@ -2675,12 +3134,12 @@ export function isTSCallSignatureDeclaration( return false; } export function isTSConstructSignatureDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSConstructSignatureDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSConstructSignatureDeclaration") { if (typeof opts === "undefined") { return true; @@ -2691,10 +3150,13 @@ export function isTSConstructSignatureDeclaration( return false; } -export function isTSPropertySignature(node: ?Object, opts?: Object): boolean { +export function isTSPropertySignature( + node: object | null | undefined, + opts?: object | null, +): node is t.TSPropertySignature { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSPropertySignature") { if (typeof opts === "undefined") { return true; @@ -2705,10 +3167,13 @@ export function isTSPropertySignature(node: ?Object, opts?: Object): boolean { return false; } -export function isTSMethodSignature(node: ?Object, opts?: Object): boolean { +export function isTSMethodSignature( + node: object | null | undefined, + opts?: object | null, +): node is t.TSMethodSignature { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSMethodSignature") { if (typeof opts === "undefined") { return true; @@ -2719,10 +3184,13 @@ export function isTSMethodSignature(node: ?Object, opts?: Object): boolean { return false; } -export function isTSIndexSignature(node: ?Object, opts?: Object): boolean { +export function isTSIndexSignature( + node: object | null | undefined, + opts?: object | null, +): node is t.TSIndexSignature { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSIndexSignature") { if (typeof opts === "undefined") { return true; @@ -2733,10 +3201,13 @@ export function isTSIndexSignature(node: ?Object, opts?: Object): boolean { return false; } -export function isTSAnyKeyword(node: ?Object, opts?: Object): boolean { +export function isTSAnyKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSAnyKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSAnyKeyword") { if (typeof opts === "undefined") { return true; @@ -2747,10 +3218,13 @@ export function isTSAnyKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSBooleanKeyword(node: ?Object, opts?: Object): boolean { +export function isTSBooleanKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSBooleanKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSBooleanKeyword") { if (typeof opts === "undefined") { return true; @@ -2761,10 +3235,13 @@ export function isTSBooleanKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSBigIntKeyword(node: ?Object, opts?: Object): boolean { +export function isTSBigIntKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSBigIntKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSBigIntKeyword") { if (typeof opts === "undefined") { return true; @@ -2775,10 +3252,13 @@ export function isTSBigIntKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSIntrinsicKeyword(node: ?Object, opts?: Object): boolean { +export function isTSIntrinsicKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSIntrinsicKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSIntrinsicKeyword") { if (typeof opts === "undefined") { return true; @@ -2789,10 +3269,13 @@ export function isTSIntrinsicKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSNeverKeyword(node: ?Object, opts?: Object): boolean { +export function isTSNeverKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSNeverKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSNeverKeyword") { if (typeof opts === "undefined") { return true; @@ -2803,10 +3286,13 @@ export function isTSNeverKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSNullKeyword(node: ?Object, opts?: Object): boolean { +export function isTSNullKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSNullKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSNullKeyword") { if (typeof opts === "undefined") { return true; @@ -2817,10 +3303,13 @@ export function isTSNullKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSNumberKeyword(node: ?Object, opts?: Object): boolean { +export function isTSNumberKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSNumberKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSNumberKeyword") { if (typeof opts === "undefined") { return true; @@ -2831,10 +3320,13 @@ export function isTSNumberKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSObjectKeyword(node: ?Object, opts?: Object): boolean { +export function isTSObjectKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSObjectKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSObjectKeyword") { if (typeof opts === "undefined") { return true; @@ -2845,10 +3337,13 @@ export function isTSObjectKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSStringKeyword(node: ?Object, opts?: Object): boolean { +export function isTSStringKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSStringKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSStringKeyword") { if (typeof opts === "undefined") { return true; @@ -2859,10 +3354,13 @@ export function isTSStringKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSSymbolKeyword(node: ?Object, opts?: Object): boolean { +export function isTSSymbolKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSSymbolKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSSymbolKeyword") { if (typeof opts === "undefined") { return true; @@ -2873,10 +3371,13 @@ export function isTSSymbolKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSUndefinedKeyword(node: ?Object, opts?: Object): boolean { +export function isTSUndefinedKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSUndefinedKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSUndefinedKeyword") { if (typeof opts === "undefined") { return true; @@ -2887,10 +3388,13 @@ export function isTSUndefinedKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSUnknownKeyword(node: ?Object, opts?: Object): boolean { +export function isTSUnknownKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSUnknownKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSUnknownKeyword") { if (typeof opts === "undefined") { return true; @@ -2901,10 +3405,13 @@ export function isTSUnknownKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSVoidKeyword(node: ?Object, opts?: Object): boolean { +export function isTSVoidKeyword( + node: object | null | undefined, + opts?: object | null, +): node is t.TSVoidKeyword { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSVoidKeyword") { if (typeof opts === "undefined") { return true; @@ -2915,10 +3422,13 @@ export function isTSVoidKeyword(node: ?Object, opts?: Object): boolean { return false; } -export function isTSThisType(node: ?Object, opts?: Object): boolean { +export function isTSThisType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSThisType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSThisType") { if (typeof opts === "undefined") { return true; @@ -2929,10 +3439,13 @@ export function isTSThisType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSFunctionType(node: ?Object, opts?: Object): boolean { +export function isTSFunctionType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSFunctionType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSFunctionType") { if (typeof opts === "undefined") { return true; @@ -2943,10 +3456,13 @@ export function isTSFunctionType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSConstructorType(node: ?Object, opts?: Object): boolean { +export function isTSConstructorType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSConstructorType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSConstructorType") { if (typeof opts === "undefined") { return true; @@ -2957,10 +3473,13 @@ export function isTSConstructorType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypeReference(node: ?Object, opts?: Object): boolean { +export function isTSTypeReference( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeReference { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeReference") { if (typeof opts === "undefined") { return true; @@ -2971,10 +3490,13 @@ export function isTSTypeReference(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypePredicate(node: ?Object, opts?: Object): boolean { +export function isTSTypePredicate( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypePredicate { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypePredicate") { if (typeof opts === "undefined") { return true; @@ -2985,10 +3507,13 @@ export function isTSTypePredicate(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypeQuery(node: ?Object, opts?: Object): boolean { +export function isTSTypeQuery( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeQuery { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeQuery") { if (typeof opts === "undefined") { return true; @@ -2999,10 +3524,13 @@ export function isTSTypeQuery(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypeLiteral(node: ?Object, opts?: Object): boolean { +export function isTSTypeLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeLiteral { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeLiteral") { if (typeof opts === "undefined") { return true; @@ -3013,10 +3541,13 @@ export function isTSTypeLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isTSArrayType(node: ?Object, opts?: Object): boolean { +export function isTSArrayType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSArrayType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSArrayType") { if (typeof opts === "undefined") { return true; @@ -3027,10 +3558,13 @@ export function isTSArrayType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTupleType(node: ?Object, opts?: Object): boolean { +export function isTSTupleType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTupleType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTupleType") { if (typeof opts === "undefined") { return true; @@ -3041,10 +3575,13 @@ export function isTSTupleType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSOptionalType(node: ?Object, opts?: Object): boolean { +export function isTSOptionalType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSOptionalType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSOptionalType") { if (typeof opts === "undefined") { return true; @@ -3055,10 +3592,13 @@ export function isTSOptionalType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSRestType(node: ?Object, opts?: Object): boolean { +export function isTSRestType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSRestType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSRestType") { if (typeof opts === "undefined") { return true; @@ -3069,10 +3609,13 @@ export function isTSRestType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSNamedTupleMember(node: ?Object, opts?: Object): boolean { +export function isTSNamedTupleMember( + node: object | null | undefined, + opts?: object | null, +): node is t.TSNamedTupleMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSNamedTupleMember") { if (typeof opts === "undefined") { return true; @@ -3083,10 +3626,13 @@ export function isTSNamedTupleMember(node: ?Object, opts?: Object): boolean { return false; } -export function isTSUnionType(node: ?Object, opts?: Object): boolean { +export function isTSUnionType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSUnionType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSUnionType") { if (typeof opts === "undefined") { return true; @@ -3097,10 +3643,13 @@ export function isTSUnionType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSIntersectionType(node: ?Object, opts?: Object): boolean { +export function isTSIntersectionType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSIntersectionType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSIntersectionType") { if (typeof opts === "undefined") { return true; @@ -3111,10 +3660,13 @@ export function isTSIntersectionType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSConditionalType(node: ?Object, opts?: Object): boolean { +export function isTSConditionalType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSConditionalType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSConditionalType") { if (typeof opts === "undefined") { return true; @@ -3125,10 +3677,13 @@ export function isTSConditionalType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSInferType(node: ?Object, opts?: Object): boolean { +export function isTSInferType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSInferType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSInferType") { if (typeof opts === "undefined") { return true; @@ -3139,10 +3694,13 @@ export function isTSInferType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSParenthesizedType(node: ?Object, opts?: Object): boolean { +export function isTSParenthesizedType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSParenthesizedType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSParenthesizedType") { if (typeof opts === "undefined") { return true; @@ -3153,10 +3711,13 @@ export function isTSParenthesizedType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypeOperator(node: ?Object, opts?: Object): boolean { +export function isTSTypeOperator( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeOperator { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeOperator") { if (typeof opts === "undefined") { return true; @@ -3167,10 +3728,13 @@ export function isTSTypeOperator(node: ?Object, opts?: Object): boolean { return false; } -export function isTSIndexedAccessType(node: ?Object, opts?: Object): boolean { +export function isTSIndexedAccessType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSIndexedAccessType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSIndexedAccessType") { if (typeof opts === "undefined") { return true; @@ -3181,10 +3745,13 @@ export function isTSIndexedAccessType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSMappedType(node: ?Object, opts?: Object): boolean { +export function isTSMappedType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSMappedType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSMappedType") { if (typeof opts === "undefined") { return true; @@ -3195,10 +3762,13 @@ export function isTSMappedType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSLiteralType(node: ?Object, opts?: Object): boolean { +export function isTSLiteralType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSLiteralType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSLiteralType") { if (typeof opts === "undefined") { return true; @@ -3210,12 +3780,12 @@ export function isTSLiteralType(node: ?Object, opts?: Object): boolean { return false; } export function isTSExpressionWithTypeArguments( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSExpressionWithTypeArguments { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSExpressionWithTypeArguments") { if (typeof opts === "undefined") { return true; @@ -3227,12 +3797,12 @@ export function isTSExpressionWithTypeArguments( return false; } export function isTSInterfaceDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSInterfaceDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSInterfaceDeclaration") { if (typeof opts === "undefined") { return true; @@ -3243,10 +3813,13 @@ export function isTSInterfaceDeclaration( return false; } -export function isTSInterfaceBody(node: ?Object, opts?: Object): boolean { +export function isTSInterfaceBody( + node: object | null | undefined, + opts?: object | null, +): node is t.TSInterfaceBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSInterfaceBody") { if (typeof opts === "undefined") { return true; @@ -3258,12 +3831,12 @@ export function isTSInterfaceBody(node: ?Object, opts?: Object): boolean { return false; } export function isTSTypeAliasDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeAliasDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeAliasDeclaration") { if (typeof opts === "undefined") { return true; @@ -3274,10 +3847,13 @@ export function isTSTypeAliasDeclaration( return false; } -export function isTSAsExpression(node: ?Object, opts?: Object): boolean { +export function isTSAsExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.TSAsExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSAsExpression") { if (typeof opts === "undefined") { return true; @@ -3288,10 +3864,13 @@ export function isTSAsExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypeAssertion(node: ?Object, opts?: Object): boolean { +export function isTSTypeAssertion( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeAssertion { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeAssertion") { if (typeof opts === "undefined") { return true; @@ -3302,10 +3881,13 @@ export function isTSTypeAssertion(node: ?Object, opts?: Object): boolean { return false; } -export function isTSEnumDeclaration(node: ?Object, opts?: Object): boolean { +export function isTSEnumDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.TSEnumDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSEnumDeclaration") { if (typeof opts === "undefined") { return true; @@ -3316,10 +3898,13 @@ export function isTSEnumDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isTSEnumMember(node: ?Object, opts?: Object): boolean { +export function isTSEnumMember( + node: object | null | undefined, + opts?: object | null, +): node is t.TSEnumMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSEnumMember") { if (typeof opts === "undefined") { return true; @@ -3330,10 +3915,13 @@ export function isTSEnumMember(node: ?Object, opts?: Object): boolean { return false; } -export function isTSModuleDeclaration(node: ?Object, opts?: Object): boolean { +export function isTSModuleDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.TSModuleDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSModuleDeclaration") { if (typeof opts === "undefined") { return true; @@ -3344,10 +3932,13 @@ export function isTSModuleDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isTSModuleBlock(node: ?Object, opts?: Object): boolean { +export function isTSModuleBlock( + node: object | null | undefined, + opts?: object | null, +): node is t.TSModuleBlock { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSModuleBlock") { if (typeof opts === "undefined") { return true; @@ -3358,10 +3949,13 @@ export function isTSModuleBlock(node: ?Object, opts?: Object): boolean { return false; } -export function isTSImportType(node: ?Object, opts?: Object): boolean { +export function isTSImportType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSImportType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSImportType") { if (typeof opts === "undefined") { return true; @@ -3373,12 +3967,12 @@ export function isTSImportType(node: ?Object, opts?: Object): boolean { return false; } export function isTSImportEqualsDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSImportEqualsDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSImportEqualsDeclaration") { if (typeof opts === "undefined") { return true; @@ -3390,12 +3984,12 @@ export function isTSImportEqualsDeclaration( return false; } export function isTSExternalModuleReference( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSExternalModuleReference { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSExternalModuleReference") { if (typeof opts === "undefined") { return true; @@ -3406,10 +4000,13 @@ export function isTSExternalModuleReference( return false; } -export function isTSNonNullExpression(node: ?Object, opts?: Object): boolean { +export function isTSNonNullExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.TSNonNullExpression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSNonNullExpression") { if (typeof opts === "undefined") { return true; @@ -3420,10 +4017,13 @@ export function isTSNonNullExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isTSExportAssignment(node: ?Object, opts?: Object): boolean { +export function isTSExportAssignment( + node: object | null | undefined, + opts?: object | null, +): node is t.TSExportAssignment { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSExportAssignment") { if (typeof opts === "undefined") { return true; @@ -3435,12 +4035,12 @@ export function isTSExportAssignment(node: ?Object, opts?: Object): boolean { return false; } export function isTSNamespaceExportDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSNamespaceExportDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSNamespaceExportDeclaration") { if (typeof opts === "undefined") { return true; @@ -3451,10 +4051,13 @@ export function isTSNamespaceExportDeclaration( return false; } -export function isTSTypeAnnotation(node: ?Object, opts?: Object): boolean { +export function isTSTypeAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeAnnotation") { if (typeof opts === "undefined") { return true; @@ -3466,12 +4069,12 @@ export function isTSTypeAnnotation(node: ?Object, opts?: Object): boolean { return false; } export function isTSTypeParameterInstantiation( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeParameterInstantiation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeParameterInstantiation") { if (typeof opts === "undefined") { return true; @@ -3483,12 +4086,12 @@ export function isTSTypeParameterInstantiation( return false; } export function isTSTypeParameterDeclaration( - node: ?Object, - opts?: Object, -): boolean { + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeParameterDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeParameterDeclaration") { if (typeof opts === "undefined") { return true; @@ -3499,10 +4102,13 @@ export function isTSTypeParameterDeclaration( return false; } -export function isTSTypeParameter(node: ?Object, opts?: Object): boolean { +export function isTSTypeParameter( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeParameter { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "TSTypeParameter") { if (typeof opts === "undefined") { return true; @@ -3513,12 +4119,14 @@ export function isTSTypeParameter(node: ?Object, opts?: Object): boolean { return false; } -export function isExpression(node: ?Object, opts?: Object): boolean { +export function isExpression( + node: object | null | undefined, + opts?: object | null, +): node is t.Expression { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Expression" || "ArrayExpression" === nodeType || "AssignmentExpression" === nodeType || "BinaryExpression" === nodeType || @@ -3565,9 +4173,9 @@ export function isExpression(node: ?Object, opts?: Object): boolean { "TSTypeAssertion" === nodeType || "TSNonNullExpression" === nodeType || (nodeType === "Placeholder" && - ("Expression" === node.expectedNode || - "Identifier" === node.expectedNode || - "StringLiteral" === node.expectedNode)) + ("Expression" === (node as t.Placeholder).expectedNode || + "Identifier" === (node as t.Placeholder).expectedNode || + "StringLiteral" === (node as t.Placeholder).expectedNode)) ) { if (typeof opts === "undefined") { return true; @@ -3578,15 +4186,14 @@ export function isExpression(node: ?Object, opts?: Object): boolean { return false; } -export function isBinary(node: ?Object, opts?: Object): boolean { +export function isBinary( + node: object | null | undefined, + opts?: object | null, +): node is t.Binary { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "Binary" || - "BinaryExpression" === nodeType || - "LogicalExpression" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("BinaryExpression" === nodeType || "LogicalExpression" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -3596,12 +4203,14 @@ export function isBinary(node: ?Object, opts?: Object): boolean { return false; } -export function isScopable(node: ?Object, opts?: Object): boolean { +export function isScopable( + node: object | null | undefined, + opts?: object | null, +): node is t.Scopable { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Scopable" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || @@ -3621,7 +4230,8 @@ export function isScopable(node: ?Object, opts?: Object): boolean { "ClassPrivateMethod" === nodeType || "StaticBlock" === nodeType || "TSModuleBlock" === nodeType || - (nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) + (nodeType === "Placeholder" && + "BlockStatement" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -3632,12 +4242,14 @@ export function isScopable(node: ?Object, opts?: Object): boolean { return false; } -export function isBlockParent(node: ?Object, opts?: Object): boolean { +export function isBlockParent( + node: object | null | undefined, + opts?: object | null, +): node is t.BlockParent { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "BlockParent" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || @@ -3655,7 +4267,8 @@ export function isBlockParent(node: ?Object, opts?: Object): boolean { "ClassPrivateMethod" === nodeType || "StaticBlock" === nodeType || "TSModuleBlock" === nodeType || - (nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) + (nodeType === "Placeholder" && + "BlockStatement" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -3666,16 +4279,19 @@ export function isBlockParent(node: ?Object, opts?: Object): boolean { return false; } -export function isBlock(node: ?Object, opts?: Object): boolean { +export function isBlock( + node: object | null | undefined, + opts?: object | null, +): node is t.Block { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Block" || "BlockStatement" === nodeType || "Program" === nodeType || "TSModuleBlock" === nodeType || - (nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) + (nodeType === "Placeholder" && + "BlockStatement" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -3686,12 +4302,14 @@ export function isBlock(node: ?Object, opts?: Object): boolean { return false; } -export function isStatement(node: ?Object, opts?: Object): boolean { +export function isStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.Statement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Statement" || "BlockStatement" === nodeType || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || @@ -3740,9 +4358,9 @@ export function isStatement(node: ?Object, opts?: Object): boolean { "TSExportAssignment" === nodeType || "TSNamespaceExportDeclaration" === nodeType || (nodeType === "Placeholder" && - ("Statement" === node.expectedNode || - "Declaration" === node.expectedNode || - "BlockStatement" === node.expectedNode)) + ("Statement" === (node as t.Placeholder).expectedNode || + "Declaration" === (node as t.Placeholder).expectedNode || + "BlockStatement" === (node as t.Placeholder).expectedNode)) ) { if (typeof opts === "undefined") { return true; @@ -3753,12 +4371,14 @@ export function isStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isTerminatorless(node: ?Object, opts?: Object): boolean { +export function isTerminatorless( + node: object | null | undefined, + opts?: object | null, +): node is t.Terminatorless { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Terminatorless" || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || "ReturnStatement" === nodeType || @@ -3775,12 +4395,14 @@ export function isTerminatorless(node: ?Object, opts?: Object): boolean { return false; } -export function isCompletionStatement(node: ?Object, opts?: Object): boolean { +export function isCompletionStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.CompletionStatement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "CompletionStatement" || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || "ReturnStatement" === nodeType || @@ -3795,15 +4417,14 @@ export function isCompletionStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isConditional(node: ?Object, opts?: Object): boolean { +export function isConditional( + node: object | null | undefined, + opts?: object | null, +): node is t.Conditional { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "Conditional" || - "ConditionalExpression" === nodeType || - "IfStatement" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("ConditionalExpression" === nodeType || "IfStatement" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -3813,12 +4434,14 @@ export function isConditional(node: ?Object, opts?: Object): boolean { return false; } -export function isLoop(node: ?Object, opts?: Object): boolean { +export function isLoop( + node: object | null | undefined, + opts?: object | null, +): node is t.Loop { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Loop" || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || @@ -3834,15 +4457,14 @@ export function isLoop(node: ?Object, opts?: Object): boolean { return false; } -export function isWhile(node: ?Object, opts?: Object): boolean { +export function isWhile( + node: object | null | undefined, + opts?: object | null, +): node is t.While { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "While" || - "DoWhileStatement" === nodeType || - "WhileStatement" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("DoWhileStatement" === nodeType || "WhileStatement" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -3852,12 +4474,14 @@ export function isWhile(node: ?Object, opts?: Object): boolean { return false; } -export function isExpressionWrapper(node: ?Object, opts?: Object): boolean { +export function isExpressionWrapper( + node: object | null | undefined, + opts?: object | null, +): node is t.ExpressionWrapper { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "ExpressionWrapper" || "ExpressionStatement" === nodeType || "ParenthesizedExpression" === nodeType || "TypeCastExpression" === nodeType @@ -3871,12 +4495,14 @@ export function isExpressionWrapper(node: ?Object, opts?: Object): boolean { return false; } -export function isFor(node: ?Object, opts?: Object): boolean { +export function isFor( + node: object | null | undefined, + opts?: object | null, +): node is t.For { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "For" || "ForInStatement" === nodeType || "ForStatement" === nodeType || "ForOfStatement" === nodeType @@ -3890,15 +4516,14 @@ export function isFor(node: ?Object, opts?: Object): boolean { return false; } -export function isForXStatement(node: ?Object, opts?: Object): boolean { +export function isForXStatement( + node: object | null | undefined, + opts?: object | null, +): node is t.ForXStatement { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "ForXStatement" || - "ForInStatement" === nodeType || - "ForOfStatement" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("ForInStatement" === nodeType || "ForOfStatement" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -3908,12 +4533,14 @@ export function isForXStatement(node: ?Object, opts?: Object): boolean { return false; } -export function isFunction(node: ?Object, opts?: Object): boolean { +export function isFunction( + node: object | null | undefined, + opts?: object | null, +): node is t.Function { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Function" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "ObjectMethod" === nodeType || @@ -3930,12 +4557,14 @@ export function isFunction(node: ?Object, opts?: Object): boolean { return false; } -export function isFunctionParent(node: ?Object, opts?: Object): boolean { +export function isFunctionParent( + node: object | null | undefined, + opts?: object | null, +): node is t.FunctionParent { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "FunctionParent" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "ObjectMethod" === nodeType || @@ -3952,12 +4581,14 @@ export function isFunctionParent(node: ?Object, opts?: Object): boolean { return false; } -export function isPureish(node: ?Object, opts?: Object): boolean { +export function isPureish( + node: object | null | undefined, + opts?: object | null, +): node is t.Pureish { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Pureish" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "StringLiteral" === nodeType || @@ -3968,7 +4599,8 @@ export function isPureish(node: ?Object, opts?: Object): boolean { "ArrowFunctionExpression" === nodeType || "BigIntLiteral" === nodeType || "DecimalLiteral" === nodeType || - (nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) + (nodeType === "Placeholder" && + "StringLiteral" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -3979,12 +4611,14 @@ export function isPureish(node: ?Object, opts?: Object): boolean { return false; } -export function isDeclaration(node: ?Object, opts?: Object): boolean { +export function isDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.Declaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Declaration" || "FunctionDeclaration" === nodeType || "VariableDeclaration" === nodeType || "ClassDeclaration" === nodeType || @@ -4011,7 +4645,8 @@ export function isDeclaration(node: ?Object, opts?: Object): boolean { "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || - (nodeType === "Placeholder" && "Declaration" === node.expectedNode) + (nodeType === "Placeholder" && + "Declaration" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -4022,19 +4657,22 @@ export function isDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isPatternLike(node: ?Object, opts?: Object): boolean { +export function isPatternLike( + node: object | null | undefined, + opts?: object | null, +): node is t.PatternLike { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "PatternLike" || "Identifier" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || (nodeType === "Placeholder" && - ("Pattern" === node.expectedNode || "Identifier" === node.expectedNode)) + ("Pattern" === (node as t.Placeholder).expectedNode || + "Identifier" === (node as t.Placeholder).expectedNode)) ) { if (typeof opts === "undefined") { return true; @@ -4045,12 +4683,14 @@ export function isPatternLike(node: ?Object, opts?: Object): boolean { return false; } -export function isLVal(node: ?Object, opts?: Object): boolean { +export function isLVal( + node: object | null | undefined, + opts?: object | null, +): node is t.LVal { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "LVal" || "Identifier" === nodeType || "MemberExpression" === nodeType || "RestElement" === nodeType || @@ -4059,7 +4699,8 @@ export function isLVal(node: ?Object, opts?: Object): boolean { "ObjectPattern" === nodeType || "TSParameterProperty" === nodeType || (nodeType === "Placeholder" && - ("Pattern" === node.expectedNode || "Identifier" === node.expectedNode)) + ("Pattern" === (node as t.Placeholder).expectedNode || + "Identifier" === (node as t.Placeholder).expectedNode)) ) { if (typeof opts === "undefined") { return true; @@ -4070,15 +4711,18 @@ export function isLVal(node: ?Object, opts?: Object): boolean { return false; } -export function isTSEntityName(node: ?Object, opts?: Object): boolean { +export function isTSEntityName( + node: object | null | undefined, + opts?: object | null, +): node is t.TSEntityName { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "TSEntityName" || "Identifier" === nodeType || "TSQualifiedName" === nodeType || - (nodeType === "Placeholder" && "Identifier" === node.expectedNode) + (nodeType === "Placeholder" && + "Identifier" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -4089,12 +4733,14 @@ export function isTSEntityName(node: ?Object, opts?: Object): boolean { return false; } -export function isLiteral(node: ?Object, opts?: Object): boolean { +export function isLiteral( + node: object | null | undefined, + opts?: object | null, +): node is t.Literal { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Literal" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || @@ -4103,7 +4749,8 @@ export function isLiteral(node: ?Object, opts?: Object): boolean { "TemplateLiteral" === nodeType || "BigIntLiteral" === nodeType || "DecimalLiteral" === nodeType || - (nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) + (nodeType === "Placeholder" && + "StringLiteral" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -4114,12 +4761,14 @@ export function isLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isImmutable(node: ?Object, opts?: Object): boolean { +export function isImmutable( + node: object | null | undefined, + opts?: object | null, +): node is t.Immutable { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Immutable" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || @@ -4136,7 +4785,8 @@ export function isImmutable(node: ?Object, opts?: Object): boolean { "JSXOpeningFragment" === nodeType || "JSXClosingFragment" === nodeType || "DecimalLiteral" === nodeType || - (nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) + (nodeType === "Placeholder" && + "StringLiteral" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -4147,12 +4797,14 @@ export function isImmutable(node: ?Object, opts?: Object): boolean { return false; } -export function isUserWhitespacable(node: ?Object, opts?: Object): boolean { +export function isUserWhitespacable( + node: object | null | undefined, + opts?: object | null, +): node is t.UserWhitespacable { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "UserWhitespacable" || "ObjectMethod" === nodeType || "ObjectProperty" === nodeType || "ObjectTypeInternalSlot" === nodeType || @@ -4170,12 +4822,14 @@ export function isUserWhitespacable(node: ?Object, opts?: Object): boolean { return false; } -export function isMethod(node: ?Object, opts?: Object): boolean { +export function isMethod( + node: object | null | undefined, + opts?: object | null, +): node is t.Method { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Method" || "ObjectMethod" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType @@ -4189,15 +4843,14 @@ export function isMethod(node: ?Object, opts?: Object): boolean { return false; } -export function isObjectMember(node: ?Object, opts?: Object): boolean { +export function isObjectMember( + node: object | null | undefined, + opts?: object | null, +): node is t.ObjectMember { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "ObjectMember" || - "ObjectMethod" === nodeType || - "ObjectProperty" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("ObjectMethod" === nodeType || "ObjectProperty" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -4207,12 +4860,14 @@ export function isObjectMember(node: ?Object, opts?: Object): boolean { return false; } -export function isProperty(node: ?Object, opts?: Object): boolean { +export function isProperty( + node: object | null | undefined, + opts?: object | null, +): node is t.Property { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Property" || "ObjectProperty" === nodeType || "ClassProperty" === nodeType || "ClassPrivateProperty" === nodeType @@ -4226,15 +4881,14 @@ export function isProperty(node: ?Object, opts?: Object): boolean { return false; } -export function isUnaryLike(node: ?Object, opts?: Object): boolean { +export function isUnaryLike( + node: object | null | undefined, + opts?: object | null, +): node is t.UnaryLike { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "UnaryLike" || - "UnaryExpression" === nodeType || - "SpreadElement" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("UnaryExpression" === nodeType || "SpreadElement" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -4244,16 +4898,19 @@ export function isUnaryLike(node: ?Object, opts?: Object): boolean { return false; } -export function isPattern(node: ?Object, opts?: Object): boolean { +export function isPattern( + node: object | null | undefined, + opts?: object | null, +): node is t.Pattern { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Pattern" || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || - (nodeType === "Placeholder" && "Pattern" === node.expectedNode) + (nodeType === "Placeholder" && + "Pattern" === (node as t.Placeholder).expectedNode) ) { if (typeof opts === "undefined") { return true; @@ -4264,15 +4921,14 @@ export function isPattern(node: ?Object, opts?: Object): boolean { return false; } -export function isClass(node: ?Object, opts?: Object): boolean { +export function isClass( + node: object | null | undefined, + opts?: object | null, +): node is t.Class { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "Class" || - "ClassExpression" === nodeType || - "ClassDeclaration" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("ClassExpression" === nodeType || "ClassDeclaration" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -4282,12 +4938,14 @@ export function isClass(node: ?Object, opts?: Object): boolean { return false; } -export function isModuleDeclaration(node: ?Object, opts?: Object): boolean { +export function isModuleDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.ModuleDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "ModuleDeclaration" || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || @@ -4302,12 +4960,14 @@ export function isModuleDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isExportDeclaration(node: ?Object, opts?: Object): boolean { +export function isExportDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.ExportDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "ExportDeclaration" || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType @@ -4321,12 +4981,14 @@ export function isExportDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isModuleSpecifier(node: ?Object, opts?: Object): boolean { +export function isModuleSpecifier( + node: object | null | undefined, + opts?: object | null, +): node is t.ModuleSpecifier { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "ModuleSpecifier" || "ExportSpecifier" === nodeType || "ImportDefaultSpecifier" === nodeType || "ImportNamespaceSpecifier" === nodeType || @@ -4343,12 +5005,14 @@ export function isModuleSpecifier(node: ?Object, opts?: Object): boolean { return false; } -export function isFlow(node: ?Object, opts?: Object): boolean { +export function isFlow( + node: object | null | undefined, + opts?: object | null, +): node is t.Flow { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Flow" || "AnyTypeAnnotation" === nodeType || "ArrayTypeAnnotation" === nodeType || "BooleanTypeAnnotation" === nodeType || @@ -4413,12 +5077,14 @@ export function isFlow(node: ?Object, opts?: Object): boolean { return false; } -export function isFlowType(node: ?Object, opts?: Object): boolean { +export function isFlowType( + node: object | null | undefined, + opts?: object | null, +): node is t.FlowType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "FlowType" || "AnyTypeAnnotation" === nodeType || "ArrayTypeAnnotation" === nodeType || "BooleanTypeAnnotation" === nodeType || @@ -4453,12 +5119,14 @@ export function isFlowType(node: ?Object, opts?: Object): boolean { return false; } -export function isFlowBaseAnnotation(node: ?Object, opts?: Object): boolean { +export function isFlowBaseAnnotation( + node: object | null | undefined, + opts?: object | null, +): node is t.FlowBaseAnnotation { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "FlowBaseAnnotation" || "AnyTypeAnnotation" === nodeType || "BooleanTypeAnnotation" === nodeType || "NullLiteralTypeAnnotation" === nodeType || @@ -4479,12 +5147,14 @@ export function isFlowBaseAnnotation(node: ?Object, opts?: Object): boolean { return false; } -export function isFlowDeclaration(node: ?Object, opts?: Object): boolean { +export function isFlowDeclaration( + node: object | null | undefined, + opts?: object | null, +): node is t.FlowDeclaration { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "FlowDeclaration" || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || @@ -4508,15 +5178,14 @@ export function isFlowDeclaration(node: ?Object, opts?: Object): boolean { return false; } -export function isFlowPredicate(node: ?Object, opts?: Object): boolean { +export function isFlowPredicate( + node: object | null | undefined, + opts?: object | null, +): node is t.FlowPredicate { if (!node) return false; - const nodeType = node.type; - if ( - nodeType === "FlowPredicate" || - "DeclaredPredicate" === nodeType || - "InferredPredicate" === nodeType - ) { + const nodeType = (node as t.Node).type; + if ("DeclaredPredicate" === nodeType || "InferredPredicate" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -4526,12 +5195,14 @@ export function isFlowPredicate(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumBody(node: ?Object, opts?: Object): boolean { +export function isEnumBody( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumBody { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "EnumBody" || "EnumBooleanBody" === nodeType || "EnumNumberBody" === nodeType || "EnumStringBody" === nodeType || @@ -4546,12 +5217,14 @@ export function isEnumBody(node: ?Object, opts?: Object): boolean { return false; } -export function isEnumMember(node: ?Object, opts?: Object): boolean { +export function isEnumMember( + node: object | null | undefined, + opts?: object | null, +): node is t.EnumMember { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "EnumMember" || "EnumBooleanMember" === nodeType || "EnumNumberMember" === nodeType || "EnumStringMember" === nodeType || @@ -4566,12 +5239,14 @@ export function isEnumMember(node: ?Object, opts?: Object): boolean { return false; } -export function isJSX(node: ?Object, opts?: Object): boolean { +export function isJSX( + node: object | null | undefined, + opts?: object | null, +): node is t.JSX { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "JSX" || "JSXAttribute" === nodeType || "JSXClosingElement" === nodeType || "JSXElement" === nodeType || @@ -4597,12 +5272,14 @@ export function isJSX(node: ?Object, opts?: Object): boolean { return false; } -export function isPrivate(node: ?Object, opts?: Object): boolean { +export function isPrivate( + node: object | null | undefined, + opts?: object | null, +): node is t.Private { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "Private" || "ClassPrivateProperty" === nodeType || "ClassPrivateMethod" === nodeType || "PrivateName" === nodeType @@ -4616,12 +5293,14 @@ export function isPrivate(node: ?Object, opts?: Object): boolean { return false; } -export function isTSTypeElement(node: ?Object, opts?: Object): boolean { +export function isTSTypeElement( + node: object | null | undefined, + opts?: object | null, +): node is t.TSTypeElement { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "TSTypeElement" || "TSCallSignatureDeclaration" === nodeType || "TSConstructSignatureDeclaration" === nodeType || "TSPropertySignature" === nodeType || @@ -4637,12 +5316,14 @@ export function isTSTypeElement(node: ?Object, opts?: Object): boolean { return false; } -export function isTSType(node: ?Object, opts?: Object): boolean { +export function isTSType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "TSType" || "TSAnyKeyword" === nodeType || "TSBooleanKeyword" === nodeType || "TSBigIntKeyword" === nodeType || @@ -4688,12 +5369,14 @@ export function isTSType(node: ?Object, opts?: Object): boolean { return false; } -export function isTSBaseType(node: ?Object, opts?: Object): boolean { +export function isTSBaseType( + node: object | null | undefined, + opts?: object | null, +): node is t.TSBaseType { if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if ( - nodeType === "TSBaseType" || "TSAnyKeyword" === nodeType || "TSBooleanKeyword" === nodeType || "TSBigIntKeyword" === nodeType || @@ -4719,13 +5402,16 @@ export function isTSBaseType(node: ?Object, opts?: Object): boolean { return false; } -export function isNumberLiteral(node: ?Object, opts?: Object): boolean { +export function isNumberLiteral( + node: object | null | undefined, + opts?: object | null, +): boolean { console.trace( "The node type NumberLiteral has been renamed to NumericLiteral", ); if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "NumberLiteral") { if (typeof opts === "undefined") { return true; @@ -4736,11 +5422,14 @@ export function isNumberLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isRegexLiteral(node: ?Object, opts?: Object): boolean { +export function isRegexLiteral( + node: object | null | undefined, + opts?: object | null, +): boolean { console.trace("The node type RegexLiteral has been renamed to RegExpLiteral"); if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "RegexLiteral") { if (typeof opts === "undefined") { return true; @@ -4751,11 +5440,14 @@ export function isRegexLiteral(node: ?Object, opts?: Object): boolean { return false; } -export function isRestProperty(node: ?Object, opts?: Object): boolean { +export function isRestProperty( + node: object | null | undefined, + opts?: object | null, +): boolean { console.trace("The node type RestProperty has been renamed to RestElement"); if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "RestProperty") { if (typeof opts === "undefined") { return true; @@ -4766,13 +5458,16 @@ export function isRestProperty(node: ?Object, opts?: Object): boolean { return false; } -export function isSpreadProperty(node: ?Object, opts?: Object): boolean { +export function isSpreadProperty( + node: object | null | undefined, + opts?: object | null, +): boolean { console.trace( "The node type SpreadProperty has been renamed to SpreadElement", ); if (!node) return false; - const nodeType = node.type; + const nodeType = (node as t.Node).type; if (nodeType === "SpreadProperty") { if (typeof opts === "undefined") { return true; diff --git a/packages/babel-types/src/validators/is.ts b/packages/babel-types/src/validators/is.ts index 50cf945ff8..b6b2f3be7f 100644 --- a/packages/babel-types/src/validators/is.ts +++ b/packages/babel-types/src/validators/is.ts @@ -1,15 +1,41 @@ -// @flow import shallowEqual from "../utils/shallowEqual"; import isType from "./isType"; import isPlaceholderType from "./isPlaceholderType"; import { FLIPPED_ALIAS_KEYS } from "../definitions"; +import type * as t from ".."; +export default function is( + type: T, + node: t.Node | null | undefined, + opts?: undefined, +): node is Extract; + +export default function is< + T extends t.Node["type"], + P extends Extract +>(type: T, n: t.Node | null | undefined, required: Partial

): n is P; + +export default function is

( + type: string, + node: t.Node | null | undefined, + opts: Partial

, +): node is P; + +export default function is( + type: string, + node: t.Node | null | undefined, + opts?: Partial, +): node is t.Node; /** * Returns whether `node` is of given `type`. * * For better performance, use this instead of `is[Type]` when `type` is unknown. */ -export default function is(type: string, node: Object, opts?: Object): boolean { +export default function is( + type: string, + node: t.Node | null | undefined, + opts?: Partial, +): node is t.Node { if (!node) return false; const matches = isType(node.type, type); diff --git a/packages/babel-types/src/validators/isBinding.ts b/packages/babel-types/src/validators/isBinding.ts index 234da4f6ec..a91ad6306e 100644 --- a/packages/babel-types/src/validators/isBinding.ts +++ b/packages/babel-types/src/validators/isBinding.ts @@ -1,12 +1,12 @@ -// @flow import getBindingIdentifiers from "../retrievers/getBindingIdentifiers"; +import type * as t from ".."; /** * Check if the input `node` is a binding identifier. */ export default function isBinding( - node: Object, - parent: Object, - grandparent?: Object, + node: t.Node, + parent: t.Node, + grandparent?: t.Node, ): boolean { if ( grandparent && diff --git a/packages/babel-types/src/validators/isBlockScoped.ts b/packages/babel-types/src/validators/isBlockScoped.ts index 51ae6e0749..828963cf61 100644 --- a/packages/babel-types/src/validators/isBlockScoped.ts +++ b/packages/babel-types/src/validators/isBlockScoped.ts @@ -1,10 +1,10 @@ -// @flow import { isClassDeclaration, isFunctionDeclaration } from "./generated"; import isLet from "./isLet"; +import type * as t from ".."; /** * Check if the input `node` is block scoped. */ -export default function isBlockScoped(node: Object): boolean { +export default function isBlockScoped(node: t.Node): boolean { return isFunctionDeclaration(node) || isClassDeclaration(node) || isLet(node); } diff --git a/packages/babel-types/src/validators/isImmutable.ts b/packages/babel-types/src/validators/isImmutable.ts index d4d049c583..b305953b02 100644 --- a/packages/babel-types/src/validators/isImmutable.ts +++ b/packages/babel-types/src/validators/isImmutable.ts @@ -1,11 +1,11 @@ -// @flow import isType from "./isType"; import { isIdentifier } from "./generated"; +import type * as t from ".."; /** * Check if the input `node` is definitely immutable. */ -export default function isImmutable(node: Object): boolean { +export default function isImmutable(node: t.Node): boolean { if (isType(node.type, "Immutable")) return true; if (isIdentifier(node)) { diff --git a/packages/babel-types/src/validators/isLet.ts b/packages/babel-types/src/validators/isLet.ts index a8c48182f1..06450cb9b4 100644 --- a/packages/babel-types/src/validators/isLet.ts +++ b/packages/babel-types/src/validators/isLet.ts @@ -1,11 +1,11 @@ -// @flow import { isVariableDeclaration } from "./generated"; import { BLOCK_SCOPED_SYMBOL } from "../constants"; +import type * as t from ".."; /** * Check if the input `node` is a `let` variable declaration. */ -export default function isLet(node: Object): boolean { +export default function isLet(node: t.Node): boolean { return ( isVariableDeclaration(node) && (node.kind !== "var" || node[BLOCK_SCOPED_SYMBOL]) diff --git a/packages/babel-types/src/validators/isNode.ts b/packages/babel-types/src/validators/isNode.ts index afa11190fa..83d2f17f4c 100644 --- a/packages/babel-types/src/validators/isNode.ts +++ b/packages/babel-types/src/validators/isNode.ts @@ -1,6 +1,6 @@ -// @flow import { VISITOR_KEYS } from "../definitions"; +import type * as t from ".."; -export default function isNode(node?: Object): boolean { +export default function isNode(node: any): node is t.Node { return !!(node && VISITOR_KEYS[node.type]); } diff --git a/packages/babel-types/src/validators/isNodesEquivalent.ts b/packages/babel-types/src/validators/isNodesEquivalent.ts index 9127e68de2..93a74b6216 100644 --- a/packages/babel-types/src/validators/isNodesEquivalent.ts +++ b/packages/babel-types/src/validators/isNodesEquivalent.ts @@ -1,10 +1,13 @@ -// @flow import { NODE_FIELDS, VISITOR_KEYS } from "../definitions"; +import type * as t from ".."; /** * Check if two nodes are equivalent */ -export default function isNodesEquivalent(a: any, b: any): boolean { +export default function isNodesEquivalent>( + a: T, + b: any, +): b is T { if ( typeof a !== "object" || typeof b !== "object" || diff --git a/packages/babel-types/src/validators/isPlaceholderType.ts b/packages/babel-types/src/validators/isPlaceholderType.ts index fac93b2745..38af7ac065 100644 --- a/packages/babel-types/src/validators/isPlaceholderType.ts +++ b/packages/babel-types/src/validators/isPlaceholderType.ts @@ -1,4 +1,3 @@ -// @flow import { PLACEHOLDERS_ALIAS } from "../definitions"; /** @@ -10,7 +9,8 @@ export default function isPlaceholderType( ): boolean { if (placeholderType === targetType) return true; - const aliases: ?Array = PLACEHOLDERS_ALIAS[placeholderType]; + const aliases: Array | undefined = + PLACEHOLDERS_ALIAS[placeholderType]; if (aliases) { for (const alias of aliases) { if (targetType === alias) return true; diff --git a/packages/babel-types/src/validators/isReferenced.ts b/packages/babel-types/src/validators/isReferenced.ts index 8048419bed..519dd7c6d4 100644 --- a/packages/babel-types/src/validators/isReferenced.ts +++ b/packages/babel-types/src/validators/isReferenced.ts @@ -1,11 +1,12 @@ -// @flow +import type * as t from ".."; + /** * Check if the input `node` is a reference to a bound variable. */ export default function isReferenced( - node: Object, - parent: Object, - grandparent?: Object, + node: t.Node, + parent: t.Node, + grandparent?: t.Node, ): boolean { switch (parent.type) { // yes: PARENT[NODE] @@ -15,6 +16,7 @@ export default function isReferenced( case "JSXMemberExpression": case "OptionalMemberExpression": if (parent.property === node) { + // @ts-expect-error todo(flow->ts): computed is missing on JSXMemberExpression return !!parent.computed; } return parent.object === node; @@ -42,6 +44,7 @@ export default function isReferenced( case "ClassMethod": case "ClassPrivateMethod": case "ObjectMethod": + // @ts-expect-error todo(flow->ts) params have more specific type comparing to node if (parent.params.includes(node)) { return false; } @@ -60,8 +63,10 @@ export default function isReferenced( case "ClassProperty": case "ClassPrivateProperty": if (parent.key === node) { + // @ts-expect-error todo(flow->ts): computed might not exist return !!parent.computed; } + // @ts-expect-error todo(flow->ts): ObjectMethod does not have value property if (parent.value === node) { return !grandparent || grandparent.type !== "ObjectPattern"; } @@ -115,6 +120,7 @@ export default function isReferenced( // yes: export { NODE as foo }; // no: export { NODE as foo } from "foo"; case "ExportSpecifier": + // @ts-expect-error todo(flow->ts): Property 'source' does not exist on type 'AnyTypeAnnotation'. if (grandparent?.source) { return false; } diff --git a/packages/babel-types/src/validators/isScope.ts b/packages/babel-types/src/validators/isScope.ts index b1cc9b78f0..70a2a8b66f 100644 --- a/packages/babel-types/src/validators/isScope.ts +++ b/packages/babel-types/src/validators/isScope.ts @@ -1,4 +1,3 @@ -// @flow import { isFunction, isCatchClause, @@ -6,11 +5,12 @@ import { isScopable, isPattern, } from "./generated"; +import type * as t from ".."; /** * Check if the input `node` is a scope. */ -export default function isScope(node: Object, parent: Object): boolean { +export default function isScope(node: t.Node, parent: t.Node): boolean { // If a BlockStatement is an immediate descendent of a Function/CatchClause, it must be in the body. // Hence we skipped the parentKey === "params" check if (isBlockStatement(node) && (isFunction(parent) || isCatchClause(parent))) { diff --git a/packages/babel-types/src/validators/isSpecifierDefault.ts b/packages/babel-types/src/validators/isSpecifierDefault.ts index 13fbe0fcb3..33bec5f6c5 100644 --- a/packages/babel-types/src/validators/isSpecifierDefault.ts +++ b/packages/babel-types/src/validators/isSpecifierDefault.ts @@ -1,12 +1,15 @@ -// @flow import { isIdentifier, isImportDefaultSpecifier } from "./generated"; +import type * as t from ".."; /** * Check if the input `specifier` is a `default` import or export. */ -export default function isSpecifierDefault(specifier: Object): boolean { +export default function isSpecifierDefault( + specifier: t.ModuleSpecifier, +): boolean { return ( isImportDefaultSpecifier(specifier) || + // @ts-expect-error todo(flow->ts): stricter type for specifier isIdentifier(specifier.imported || specifier.exported, { name: "default", }) diff --git a/packages/babel-types/src/validators/isType.ts b/packages/babel-types/src/validators/isType.ts index cf9a681a0a..646675c943 100644 --- a/packages/babel-types/src/validators/isType.ts +++ b/packages/babel-types/src/validators/isType.ts @@ -1,17 +1,30 @@ -// @flow import { FLIPPED_ALIAS_KEYS, ALIAS_KEYS } from "../definitions"; +import type * as t from ".."; + +export default function isType( + nodeType: string, + targetType: T, +): nodeType is T; + +export default function isType( + nodeType: string | null | undefined, + targetType: string, +): boolean; /** * Test if a `nodeType` is a `targetType` or if `targetType` is an alias of `nodeType`. */ -export default function isType(nodeType: ?string, targetType: string): boolean { +export default function isType( + nodeType: string | undefined | null, + targetType: string, +): boolean { if (nodeType === targetType) return true; // This is a fast-path. If the test above failed, but an alias key is found, then the // targetType was a primary node type, so there's no need to check the aliases. if (ALIAS_KEYS[targetType]) return false; - const aliases: ?Array = FLIPPED_ALIAS_KEYS[targetType]; + const aliases: Array | undefined = FLIPPED_ALIAS_KEYS[targetType]; if (aliases) { if (aliases[0] === nodeType) return true; diff --git a/packages/babel-types/src/validators/isValidES3Identifier.ts b/packages/babel-types/src/validators/isValidES3Identifier.ts index 3d34a12fea..c19e3844e8 100644 --- a/packages/babel-types/src/validators/isValidES3Identifier.ts +++ b/packages/babel-types/src/validators/isValidES3Identifier.ts @@ -1,4 +1,3 @@ -// @flow import isValidIdentifier from "./isValidIdentifier"; const RESERVED_WORDS_ES3_ONLY: Set = new Set([ diff --git a/packages/babel-types/src/validators/isValidIdentifier.ts b/packages/babel-types/src/validators/isValidIdentifier.ts index 4862274ae1..1fd56898d5 100644 --- a/packages/babel-types/src/validators/isValidIdentifier.ts +++ b/packages/babel-types/src/validators/isValidIdentifier.ts @@ -1,4 +1,3 @@ -// @flow import { isIdentifierName, isStrictReservedWord, diff --git a/packages/babel-types/src/validators/isVar.ts b/packages/babel-types/src/validators/isVar.ts index 98eb627265..6eca80cd8d 100644 --- a/packages/babel-types/src/validators/isVar.ts +++ b/packages/babel-types/src/validators/isVar.ts @@ -1,11 +1,11 @@ -// @flow import { isVariableDeclaration } from "./generated"; import { BLOCK_SCOPED_SYMBOL } from "../constants"; +import type * as t from ".."; /** * Check if the input `node` is a variable declaration. */ -export default function isVar(node: Object): boolean { +export default function isVar(node: t.Node): boolean { return ( isVariableDeclaration(node, { kind: "var" }) && !node[BLOCK_SCOPED_SYMBOL] ); diff --git a/packages/babel-types/src/validators/matchesPattern.ts b/packages/babel-types/src/validators/matchesPattern.ts index 4c7ff9d781..6088f2e48c 100644 --- a/packages/babel-types/src/validators/matchesPattern.ts +++ b/packages/babel-types/src/validators/matchesPattern.ts @@ -1,4 +1,5 @@ import { isIdentifier, isMemberExpression, isStringLiteral } from "./generated"; +import type * as t from ".."; /** * Determines whether or not the input node `member` matches the @@ -8,8 +9,8 @@ import { isIdentifier, isMemberExpression, isStringLiteral } from "./generated"; * parsed nodes of `React.createClass` and `React["createClass"]`. */ export default function matchesPattern( - member: Object, - match: string | Array, + member: t.Node | null | undefined, + match: string | string[], allowPartial?: boolean, ): boolean { // not a member expression diff --git a/packages/babel-types/src/validators/react/isCompatTag.ts b/packages/babel-types/src/validators/react/isCompatTag.ts index 7f329bec71..048182d16f 100644 --- a/packages/babel-types/src/validators/react/isCompatTag.ts +++ b/packages/babel-types/src/validators/react/isCompatTag.ts @@ -1,4 +1,3 @@ -// @flow export default function isCompatTag(tagName?: string): boolean { // Must start with a lowercase ASCII letter return !!tagName && /^[a-z]/.test(tagName); diff --git a/packages/babel-types/src/validators/react/isReactComponent.ts b/packages/babel-types/src/validators/react/isReactComponent.ts index 6f91769843..70a7616dae 100644 --- a/packages/babel-types/src/validators/react/isReactComponent.ts +++ b/packages/babel-types/src/validators/react/isReactComponent.ts @@ -1,4 +1,3 @@ -// @flow import buildMatchMemberExpression from "../buildMatchMemberExpression"; const isReactComponent = buildMatchMemberExpression("React.Component"); diff --git a/packages/babel-types/src/validators/validate.ts b/packages/babel-types/src/validators/validate.ts index c8c9ab496c..28bd5397df 100644 --- a/packages/babel-types/src/validators/validate.ts +++ b/packages/babel-types/src/validators/validate.ts @@ -1,7 +1,11 @@ -// @flow import { NODE_FIELDS, NODE_PARENT_VALIDATIONS } from "../definitions"; +import type * as t from ".."; -export default function validate(node?: Object, key: string, val: any): void { +export default function validate( + node: t.Node | undefined | null, + key: string, + val: any, +): void { if (!node) return; const fields = NODE_FIELDS[node.type]; @@ -13,7 +17,7 @@ export default function validate(node?: Object, key: string, val: any): void { } export function validateField( - node?: Object, + node: t.Node | undefined | null, key: string, val: any, field: any, @@ -24,7 +28,11 @@ export function validateField( field.validate(node, key, val); } -export function validateChild(node?: Object, key: string, val?: Object) { +export function validateChild( + node: t.Node | undefined | null, + key: string, + val?: any, +) { if (val == null) return; const validate = NODE_PARENT_VALIDATIONS[val.type]; if (!validate) return; diff --git a/scripts/lint-ts-typings.sh b/scripts/lint-ts-typings.sh deleted file mode 100755 index 625ff7e375..0000000000 --- a/scripts/lint-ts-typings.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e - -tsFlags="--strict" - -yarn tsc $tsFlags ./packages/babel-types/lib/index.d.ts diff --git a/yarn.lock b/yarn.lock index 458b468d2c..6903cf4da5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3381,6 +3381,8 @@ __metadata: "@babel/generator": "workspace:*" "@babel/helper-validator-identifier": "workspace:^7.10.4" "@babel/parser": "workspace:*" + "@types/lodash": ^4.14.162 + chalk: ^4.1.0 lodash: ^4.17.19 to-fast-properties: ^2.0.0 languageName: unknown @@ -3899,6 +3901,13 @@ __metadata: languageName: node linkType: hard +"@types/lodash@npm:^4.14.162": + version: 4.14.165 + resolution: "@types/lodash@npm:4.14.165" + checksum: 525bfc34b0b591cc957125a961c70e63e5ad8b23cbd89b7594a5ea74823285b6d96993a7eec506e26b379ee52dc9dcd3a894ff210be4c97bccb536e62361dbc8 + languageName: node + linkType: hard + "@types/minimatch@npm:*": version: 3.0.3 resolution: "@types/minimatch@npm:3.0.3" @@ -4835,6 +4844,7 @@ __metadata: mergeiterator: ^1.2.5 prettier: ^2.0.5 rollup: ^2.26.5 + rollup-plugin-dts: ^2.0.0 rollup-plugin-node-polyfills: ^0.2.1 rollup-plugin-terser: ^7.0.0 test262-stream: ^1.3.0 @@ -9709,7 +9719,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"magic-string@npm:^0.25.2, magic-string@npm:^0.25.3, magic-string@npm:^0.25.5": +"magic-string@npm:^0.25.2, magic-string@npm:^0.25.3, magic-string@npm:^0.25.5, magic-string@npm:^0.25.7": version: 0.25.7 resolution: "magic-string@npm:0.25.7" dependencies: @@ -11705,6 +11715,22 @@ fsevents@^1.2.7: languageName: node linkType: hard +"rollup-plugin-dts@npm:^2.0.0": + version: 2.0.0 + resolution: "rollup-plugin-dts@npm:2.0.0" + dependencies: + "@babel/code-frame": ^7.10.4 + magic-string: ^0.25.7 + peerDependencies: + rollup: ^2.33.3 + typescript: ^4.1.2 + dependenciesMeta: + "@babel/code-frame": + optional: true + checksum: 858dea6359da9fd3926311f22591b51f4cd29669ab63a8556ff25eede91f2461107eec74b1d25447f9343243e21cc9091f924941baa4c9e1700ecbe4bdbe3d43 + languageName: node + linkType: hard + "rollup-plugin-inject@npm:^3.0.0": version: 3.0.2 resolution: "rollup-plugin-inject@npm:3.0.2"