From 32dfc31b1f22629161d5599cb865a5cb031a4e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 8 Jul 2022 10:16:12 -0400 Subject: [PATCH] typings: intersect input node types for is* functions --- .../src/decorators.ts | 18 +- .../src/misc.ts | 2 +- .../src/index.ts | 2 +- .../babel-helper-replace-supers/src/index.ts | 22 +- .../babel-helper-wrap-function/src/index.ts | 30 +- .../src/util.ts | 12 +- .../src/index.ts | 5 +- .../src/transformer-2021-12.ts | 4 +- .../src/index.ts | 11 +- .../src/enum.ts | 5 +- .../scripts/generators/validators.js | 6 +- .../src/path/generated/validators.ts | 1692 ++++++++++++----- packages/babel-traverse/src/path/index.ts | 2 +- .../babel-traverse/src/path/introspection.ts | 13 +- 14 files changed, 1322 insertions(+), 502 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index a3d721a5412d..d2acfde94c61 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -94,13 +94,17 @@ function extractElementDescriptor( const { node, scope } = path as NodePath; - new ReplaceSupers({ - methodPath: path, - objectRef: classRef, - superRef, - file, - refToPreserve: classRef, - }).replace(); + if (!path.isTSDeclareMethod()) { + new ReplaceSupers({ + methodPath: path as NodePath< + Exclude + >, + objectRef: classRef, + superRef, + file, + refToPreserve: classRef, + }).replace(); + } const properties: t.ObjectExpression["properties"] = [ prop("kind", t.stringLiteral(t.isClassMethod(node) ? node.kind : "field")), diff --git a/packages/babel-helper-create-class-features-plugin/src/misc.ts b/packages/babel-helper-create-class-features-plugin/src/misc.ts index 3908941dc0d6..9352f69dad1b 100644 --- a/packages/babel-helper-create-class-features-plugin/src/misc.ts +++ b/packages/babel-helper-create-class-features-plugin/src/misc.ts @@ -122,7 +122,7 @@ export function extractComputedKeys( }; for (const computedPath of computedPaths) { const computedKey = computedPath.get("key"); - if (computedKey.isIdentifier() && computedKey.isReferencedIdentifier()) { + if (computedKey.isReferencedIdentifier()) { handleClassTDZ(computedKey, state); } else { computedKey.traverse(classFieldDefinitionEvaluationTDZVisitor, state); diff --git a/packages/babel-helper-remap-async-to-generator/src/index.ts b/packages/babel-helper-remap-async-to-generator/src/index.ts index 876372f6110c..e0a114362b3d 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.ts +++ b/packages/babel-helper-remap-async-to-generator/src/index.ts @@ -36,7 +36,7 @@ const awaitVisitor = traverse.visitors.merge<{ wrapAwait: t.Expression }>([ ]); export default function ( - path: NodePath, + path: NodePath, helpers: { wrapAsync: t.Expression; wrapAwait?: t.Expression; diff --git a/packages/babel-helper-replace-supers/src/index.ts b/packages/babel-helper-replace-supers/src/index.ts index b59c35850339..3e60b1b30cec 100644 --- a/packages/babel-helper-replace-supers/src/index.ts +++ b/packages/babel-helper-replace-supers/src/index.ts @@ -1,4 +1,4 @@ -import type { HubInterface, NodePath, Scope } from "@babel/traverse"; +import type { NodePath, Scope } from "@babel/traverse"; import traverse from "@babel/traverse"; import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions"; import type { HandlerState } from "@babel/helper-member-expression-to-functions"; @@ -317,9 +317,16 @@ const looseHandlers = { }; type ReplaceSupersOptionsBase = { - methodPath: NodePath; + methodPath: NodePath< + | t.ClassMethod + | t.ClassProperty + | t.ObjectMethod + | t.ClassPrivateMethod + | t.ClassPrivateProperty + | t.StaticBlock + >; constantSuper?: boolean; - file: any; + file: File; // objectRef might have been shadowed in child scopes, // in that case, we need to rename related variables. refToPreserve?: t.Identifier; @@ -336,7 +343,7 @@ type ReplaceSupersOptions = ReplaceSupersOptionsBase & ); interface ReplaceState { - file: unknown; + file: File; scope: Scope; isDerivedConstructor: boolean; isStatic: boolean; @@ -353,7 +360,10 @@ export default class ReplaceSupers { this.isDerivedConstructor = path.isClassMethod({ kind: "constructor" }) && !!opts.superRef; this.isStatic = - path.isObjectMethod() || path.node.static || path.isStaticBlock?.(); + path.isObjectMethod() || + // @ts-expect-error static is not in ClassPrivateMethod + path.node.static || + path.isStaticBlock?.(); this.isPrivateMethod = path.isPrivate() && path.isMethod(); this.file = opts.file; @@ -364,7 +374,7 @@ export default class ReplaceSupers { this.opts = opts; } - declare file: HubInterface; + declare file: File; declare isDerivedConstructor: boolean; declare constantSuper: boolean; declare isPrivateMethod: boolean; diff --git a/packages/babel-helper-wrap-function/src/index.ts b/packages/babel-helper-wrap-function/src/index.ts index b02014eea6bb..eb2f906d98e7 100644 --- a/packages/babel-helper-wrap-function/src/index.ts +++ b/packages/babel-helper-wrap-function/src/index.ts @@ -40,7 +40,7 @@ const buildDeclarationWrapper = template.statements(` function classOrObjectMethod( path: NodePath, - callId: any, + callId: t.Expression, ) { const node = path.node; const body = node.body; @@ -67,13 +67,17 @@ function classOrObjectMethod( } function plainFunction( - path: NodePath, - callId: any, + path: NodePath>, + callId: t.Expression, noNewArrows: boolean, ignoreFunctionLength: boolean, ) { + if (path.isArrowFunctionExpression()) { + path.arrowFunctionToExpression({ noNewArrows }); + } const node = path.node; const isDeclaration = path.isFunctionDeclaration(); + // @ts-expect-error node is FunctionDeclaration|FunctionExpression const functionId = node.id; const wrapper = isDeclaration ? buildDeclarationWrapper @@ -81,17 +85,16 @@ function plainFunction( ? buildNamedExpressionWrapper : buildAnonymousExpressionWrapper; - if (path.isArrowFunctionExpression()) { - path.arrowFunctionToExpression({ noNewArrows }); - } - + // @ts-expect-error node is FunctionDeclaration|FunctionExpression node.id = null; if (isDeclaration) { node.type = "FunctionExpression"; } - const built = callExpression(callId, [node]); + const built = callExpression(callId, [ + node as Exclude, + ]); const params: t.Identifier[] = []; for (const param of node.params) { @@ -138,8 +141,8 @@ function plainFunction( } export default function wrapFunction( - path: NodePath, - callId: any, + path: NodePath, + callId: t.Expression, // TODO(Babel 8): Consider defaulting to false for spec compliancy noNewArrows: boolean = true, ignoreFunctionLength: boolean = false, @@ -147,6 +150,11 @@ export default function wrapFunction( if (path.isMethod()) { classOrObjectMethod(path, callId); } else { - plainFunction(path, callId, noNewArrows, ignoreFunctionLength); + plainFunction( + path as NodePath>, + callId, + noNewArrows, + ignoreFunctionLength, + ); } } diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/util.ts b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/util.ts index 0c3f0863185c..afbc7cbdf3be 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/util.ts +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/util.ts @@ -24,17 +24,15 @@ export function shouldTransform( ): boolean { let optionalPath: NodePath = path; const chains = []; - while ( - optionalPath.isOptionalMemberExpression() || - optionalPath.isOptionalCallExpression() - ) { - const { node } = optionalPath; - chains.push(node); - + for (;;) { if (optionalPath.isOptionalMemberExpression()) { optionalPath = skipTransparentExprWrappers(optionalPath.get("object")); + chains.push(optionalPath.node); } else if (optionalPath.isOptionalCallExpression()) { optionalPath = skipTransparentExprWrappers(optionalPath.get("callee")); + chains.push(optionalPath.node); + } else { + break; } } for (let i = 0; i < chains.length; i++) { diff --git a/packages/babel-plugin-proposal-class-static-block/src/index.ts b/packages/babel-plugin-proposal-class-static-block/src/index.ts index 120fa50e7e1a..ed596bd04468 100644 --- a/packages/babel-plugin-proposal-class-static-block/src/index.ts +++ b/packages/babel-plugin-proposal-class-static-block/src/index.ts @@ -49,10 +49,7 @@ export default declare(({ types: t, template, assertVersion }) => { const body = classBody.get("body"); for (const path of body) { if (path.isPrivate()) { - privateNames.add( - // @ts-expect-error TS can't infer that NodePath & NodePath equals to NodePath - path.get("key.id").node.name, - ); + privateNames.add(path.get("key.id").node.name); } } for (const path of body) { diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts index 10af52865a2f..53011ef94fda 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-2021-12.ts @@ -685,10 +685,10 @@ function transformClass( const replaceSupers = new ReplaceSupers({ constantSuper, - methodPath: element, + methodPath: element as NodePath, objectRef: classLocal, superRef: path.node.superClass, - file: state, + file: state.file, refToPreserve: classLocal, }); diff --git a/packages/babel-plugin-proposal-object-rest-spread/src/index.ts b/packages/babel-plugin-proposal-object-rest-spread/src/index.ts index 76205389cb49..876f93a9a6d2 100644 --- a/packages/babel-plugin-proposal-object-rest-spread/src/index.ts +++ b/packages/babel-plugin-proposal-object-rest-spread/src/index.ts @@ -243,7 +243,9 @@ export default declare((api, opts: Options) => { function replaceRestElement( parentPath: NodePath, - paramPath: Param | NodePath, + paramPath: NodePath< + t.Function["params"][number] | t.AssignmentPattern["left"] + >, container?: t.VariableDeclaration[], ): void { if (paramPath.isAssignmentPattern()) { @@ -255,12 +257,7 @@ export default declare((api, opts: Options) => { const elements = paramPath.get("elements"); for (let i = 0; i < elements.length; i++) { - replaceRestElement( - parentPath, - // @ts-expect-error Fixme: handle TSAsExpression - elements[i], - container, - ); + replaceRestElement(parentPath, elements[i], container); } } diff --git a/packages/babel-plugin-transform-typescript/src/enum.ts b/packages/babel-plugin-transform-typescript/src/enum.ts index b39559d54a0b..9a3234286f69 100644 --- a/packages/babel-plugin-transform-typescript/src/enum.ts +++ b/packages/babel-plugin-transform-typescript/src/enum.ts @@ -156,10 +156,7 @@ export function translateEnumValues( } else { const initializerPath = memberPath.get("initializer"); - if ( - initializerPath.isIdentifier() && - initializerPath.isReferencedIdentifier() - ) { + if (initializerPath.isReferencedIdentifier()) { ReferencedIdentifier(initializerPath, { t, seen, diff --git a/packages/babel-traverse/scripts/generators/validators.js b/packages/babel-traverse/scripts/generators/validators.js index 3a2dbe29dae0..1dca02cd48f8 100644 --- a/packages/babel-traverse/scripts/generators/validators.js +++ b/packages/babel-traverse/scripts/generators/validators.js @@ -14,7 +14,7 @@ export interface NodePathValidators { `; for (const type of [...t.TYPES].sort()) { - output += `is${type}(opts?: object): this is NodePath;`; + output += `is${type}(this: NodePath, opts?: object): this is NodePath;`; } for (const type of Object.keys(virtualTypes)) { @@ -24,9 +24,9 @@ export interface NodePathValidators { const { types } = virtualTypes[type]; if (type[0] === "_") continue; if (t.NODE_FIELDS[type] || t.FLIPPED_ALIAS_KEYS[type]) { - output += `is${type}(opts?: object): this is NodePath;`; + output += `is${type}(this: NodePath, opts?: object): this is NodePath;`; } else if (types /* in VirtualTypeAliases */) { - output += `is${type}(opts?: object): this is NodePath;`; + output += `is${type}(this: NodePath, opts?: object): this is NodePath;`; } else if (type === "Pure") { output += `isPure(constantsOnly?: boolean): boolean;`; } else { diff --git a/packages/babel-traverse/src/path/generated/validators.ts b/packages/babel-traverse/src/path/generated/validators.ts index bd1c9a31b351..7271088faca8 100644 --- a/packages/babel-traverse/src/path/generated/validators.ts +++ b/packages/babel-traverse/src/path/generated/validators.ts @@ -7,459 +7,1265 @@ import NodePath from "../index"; import type { VirtualTypeAliases } from "./virtual-types"; export interface NodePathValidators { - isAccessor(opts?: object): this is NodePath; - isAnyTypeAnnotation(opts?: object): this is NodePath; - isArgumentPlaceholder(opts?: object): this is NodePath; - isArrayExpression(opts?: object): this is NodePath; - isArrayPattern(opts?: object): this is NodePath; - isArrayTypeAnnotation(opts?: object): this is NodePath; - isArrowFunctionExpression( - opts?: object, - ): this is NodePath; - isAssignmentExpression( - opts?: object, - ): this is NodePath; - isAssignmentPattern(opts?: object): this is NodePath; - isAwaitExpression(opts?: object): this is NodePath; - isBigIntLiteral(opts?: object): this is NodePath; - isBinary(opts?: object): this is NodePath; - isBinaryExpression(opts?: object): this is NodePath; - isBindExpression(opts?: object): this is NodePath; - isBlock(opts?: object): this is NodePath; - isBlockParent(opts?: object): this is NodePath; - isBlockStatement(opts?: object): this is NodePath; - isBooleanLiteral(opts?: object): this is NodePath; - isBooleanLiteralTypeAnnotation( - opts?: object, - ): this is NodePath; - isBooleanTypeAnnotation( - opts?: object, - ): this is NodePath; - isBreakStatement(opts?: object): this is NodePath; - isCallExpression(opts?: object): this is NodePath; - isCatchClause(opts?: object): this is NodePath; - isClass(opts?: object): this is NodePath; - isClassAccessorProperty( - opts?: object, - ): this is NodePath; - isClassBody(opts?: object): this is NodePath; - isClassDeclaration(opts?: object): this is NodePath; - isClassExpression(opts?: object): this is NodePath; - isClassImplements(opts?: object): this is NodePath; - isClassMethod(opts?: object): this is NodePath; - isClassPrivateMethod(opts?: object): this is NodePath; - isClassPrivateProperty( - opts?: object, - ): this is NodePath; - isClassProperty(opts?: object): this is NodePath; - isCompletionStatement(opts?: object): this is NodePath; - isConditional(opts?: object): this is NodePath; - isConditionalExpression( - opts?: object, - ): this is NodePath; - isContinueStatement(opts?: object): this is NodePath; - isDebuggerStatement(opts?: object): this is NodePath; - isDecimalLiteral(opts?: object): this is NodePath; - isDeclaration(opts?: object): this is NodePath; - isDeclareClass(opts?: object): this is NodePath; - isDeclareExportAllDeclaration( - opts?: object, - ): this is NodePath; - isDeclareExportDeclaration( - opts?: object, - ): this is NodePath; - isDeclareFunction(opts?: object): this is NodePath; - isDeclareInterface(opts?: object): this is NodePath; - isDeclareModule(opts?: object): this is NodePath; - isDeclareModuleExports( - opts?: object, - ): this is NodePath; - isDeclareOpaqueType(opts?: object): this is NodePath; - isDeclareTypeAlias(opts?: object): this is NodePath; - isDeclareVariable(opts?: object): this is NodePath; - isDeclaredPredicate(opts?: object): this is NodePath; - isDecorator(opts?: object): this is NodePath; - isDirective(opts?: object): this is NodePath; - isDirectiveLiteral(opts?: object): this is NodePath; - isDoExpression(opts?: object): this is NodePath; - isDoWhileStatement(opts?: object): this is NodePath; - isEmptyStatement(opts?: object): this is NodePath; - isEmptyTypeAnnotation(opts?: object): this is NodePath; - isEnumBody(opts?: object): this is NodePath; - isEnumBooleanBody(opts?: object): this is NodePath; - isEnumBooleanMember(opts?: object): this is NodePath; - isEnumDeclaration(opts?: object): this is NodePath; - isEnumDefaultedMember(opts?: object): this is NodePath; - isEnumMember(opts?: object): this is NodePath; - isEnumNumberBody(opts?: object): this is NodePath; - isEnumNumberMember(opts?: object): this is NodePath; - isEnumStringBody(opts?: object): this is NodePath; - isEnumStringMember(opts?: object): this is NodePath; - isEnumSymbolBody(opts?: object): this is NodePath; - isExistsTypeAnnotation( - opts?: object, - ): this is NodePath; - isExportAllDeclaration( - opts?: object, - ): this is NodePath; - isExportDeclaration(opts?: object): this is NodePath; - isExportDefaultDeclaration( - opts?: object, - ): this is NodePath; - isExportDefaultSpecifier( - opts?: object, - ): this is NodePath; - isExportNamedDeclaration( - opts?: object, - ): this is NodePath; - isExportNamespaceSpecifier( - opts?: object, - ): this is NodePath; - isExportSpecifier(opts?: object): this is NodePath; - isExpression(opts?: object): this is NodePath; - isExpressionStatement(opts?: object): this is NodePath; - isExpressionWrapper(opts?: object): this is NodePath; - isFile(opts?: object): this is NodePath; - isFlow(opts?: object): this is NodePath; - isFlowBaseAnnotation(opts?: object): this is NodePath; - isFlowDeclaration(opts?: object): this is NodePath; - isFlowPredicate(opts?: object): this is NodePath; - isFlowType(opts?: object): this is NodePath; - isFor(opts?: object): this is NodePath; - isForInStatement(opts?: object): this is NodePath; - isForOfStatement(opts?: object): this is NodePath; - isForStatement(opts?: object): this is NodePath; - isForXStatement(opts?: object): this is NodePath; - isFunction(opts?: object): this is NodePath; - isFunctionDeclaration(opts?: object): this is NodePath; - isFunctionExpression(opts?: object): this is NodePath; - isFunctionParent(opts?: object): this is NodePath; - isFunctionTypeAnnotation( - opts?: object, - ): this is NodePath; - isFunctionTypeParam(opts?: object): this is NodePath; - isGenericTypeAnnotation( - opts?: object, - ): this is NodePath; - isIdentifier(opts?: object): this is NodePath; - isIfStatement(opts?: object): this is NodePath; - isImmutable(opts?: object): this is NodePath; - isImport(opts?: object): this is NodePath; - isImportAttribute(opts?: object): this is NodePath; - isImportDeclaration(opts?: object): this is NodePath; - isImportDefaultSpecifier( - opts?: object, - ): this is NodePath; - isImportNamespaceSpecifier( - opts?: object, - ): this is NodePath; - isImportSpecifier(opts?: object): this is NodePath; - isIndexedAccessType(opts?: object): this is NodePath; - isInferredPredicate(opts?: object): this is NodePath; - isInterfaceDeclaration( - opts?: object, - ): this is NodePath; - isInterfaceExtends(opts?: object): this is NodePath; - isInterfaceTypeAnnotation( - opts?: object, - ): this is NodePath; - isInterpreterDirective( - opts?: object, - ): this is NodePath; - isIntersectionTypeAnnotation( - opts?: object, - ): this is NodePath; - isJSX(opts?: object): this is NodePath; - isJSXAttribute(opts?: object): this is NodePath; - isJSXClosingElement(opts?: object): this is NodePath; - isJSXClosingFragment(opts?: object): this is NodePath; - isJSXElement(opts?: object): this is NodePath; - isJSXEmptyExpression(opts?: object): this is NodePath; - isJSXExpressionContainer( - opts?: object, - ): this is NodePath; - isJSXFragment(opts?: object): this is NodePath; - isJSXIdentifier(opts?: object): this is NodePath; - isJSXMemberExpression(opts?: object): this is NodePath; - isJSXNamespacedName(opts?: object): this is NodePath; - isJSXOpeningElement(opts?: object): this is NodePath; - isJSXOpeningFragment(opts?: object): this is NodePath; - isJSXSpreadAttribute(opts?: object): this is NodePath; - isJSXSpreadChild(opts?: object): this is NodePath; - isJSXText(opts?: object): this is NodePath; - isLVal(opts?: object): this is NodePath; - isLabeledStatement(opts?: object): this is NodePath; - isLiteral(opts?: object): this is NodePath; - isLogicalExpression(opts?: object): this is NodePath; - isLoop(opts?: object): this is NodePath; - isMemberExpression(opts?: object): this is NodePath; - isMetaProperty(opts?: object): this is NodePath; - isMethod(opts?: object): this is NodePath; - isMiscellaneous(opts?: object): this is NodePath; - isMixedTypeAnnotation(opts?: object): this is NodePath; - isModuleDeclaration(opts?: object): this is NodePath; - isModuleExpression(opts?: object): this is NodePath; - isModuleSpecifier(opts?: object): this is NodePath; - isNewExpression(opts?: object): this is NodePath; - isNoop(opts?: object): this is NodePath; - isNullLiteral(opts?: object): this is NodePath; - isNullLiteralTypeAnnotation( - opts?: object, - ): this is NodePath; - isNullableTypeAnnotation( - opts?: object, - ): this is NodePath; - isNumberLiteral(opts?: object): this is NodePath; - isNumberLiteralTypeAnnotation( - opts?: object, - ): this is NodePath; - isNumberTypeAnnotation( - opts?: object, - ): this is NodePath; - isNumericLiteral(opts?: object): this is NodePath; - isObjectExpression(opts?: object): this is NodePath; - isObjectMember(opts?: object): this is NodePath; - isObjectMethod(opts?: object): this is NodePath; - isObjectPattern(opts?: object): this is NodePath; - isObjectProperty(opts?: object): this is NodePath; - isObjectTypeAnnotation( - opts?: object, - ): this is NodePath; - isObjectTypeCallProperty( - opts?: object, - ): this is NodePath; - isObjectTypeIndexer(opts?: object): this is NodePath; - isObjectTypeInternalSlot( - opts?: object, - ): this is NodePath; - isObjectTypeProperty(opts?: object): this is NodePath; - isObjectTypeSpreadProperty( - opts?: object, - ): this is NodePath; - isOpaqueType(opts?: object): this is NodePath; - isOptionalCallExpression( - opts?: object, - ): this is NodePath; - isOptionalIndexedAccessType( - opts?: object, - ): this is NodePath; - isOptionalMemberExpression( - opts?: object, - ): this is NodePath; - isParenthesizedExpression( - opts?: object, - ): this is NodePath; - isPattern(opts?: object): this is NodePath; - isPatternLike(opts?: object): this is NodePath; - isPipelineBareFunction( - opts?: object, - ): this is NodePath; - isPipelinePrimaryTopicReference( - opts?: object, - ): this is NodePath; - isPipelineTopicExpression( - opts?: object, - ): this is NodePath; - isPlaceholder(opts?: object): this is NodePath; - isPrivate(opts?: object): this is NodePath; - isPrivateName(opts?: object): this is NodePath; - isProgram(opts?: object): this is NodePath; - isProperty(opts?: object): this is NodePath; - isPureish(opts?: object): this is NodePath; - isQualifiedTypeIdentifier( - opts?: object, - ): this is NodePath; - isRecordExpression(opts?: object): this is NodePath; - isRegExpLiteral(opts?: object): this is NodePath; - isRegexLiteral(opts?: object): this is NodePath; - isRestElement(opts?: object): this is NodePath; - isRestProperty(opts?: object): this is NodePath; - isReturnStatement(opts?: object): this is NodePath; - isScopable(opts?: object): this is NodePath; - isSequenceExpression(opts?: object): this is NodePath; - isSpreadElement(opts?: object): this is NodePath; - isSpreadProperty(opts?: object): this is NodePath; - isStandardized(opts?: object): this is NodePath; - isStatement(opts?: object): this is NodePath; - isStaticBlock(opts?: object): this is NodePath; - isStringLiteral(opts?: object): this is NodePath; - isStringLiteralTypeAnnotation( - opts?: object, - ): this is NodePath; - isStringTypeAnnotation( - opts?: object, - ): this is NodePath; - isSuper(opts?: object): this is NodePath; - isSwitchCase(opts?: object): this is NodePath; - isSwitchStatement(opts?: object): this is NodePath; - isSymbolTypeAnnotation( - opts?: object, - ): this is NodePath; - isTSAnyKeyword(opts?: object): this is NodePath; - isTSArrayType(opts?: object): this is NodePath; - isTSAsExpression(opts?: object): this is NodePath; - isTSBaseType(opts?: object): this is NodePath; - isTSBigIntKeyword(opts?: object): this is NodePath; - isTSBooleanKeyword(opts?: object): this is NodePath; - isTSCallSignatureDeclaration( - opts?: object, - ): this is NodePath; - isTSConditionalType(opts?: object): this is NodePath; - isTSConstructSignatureDeclaration( - opts?: object, - ): this is NodePath; - isTSConstructorType(opts?: object): this is NodePath; - isTSDeclareFunction(opts?: object): this is NodePath; - isTSDeclareMethod(opts?: object): this is NodePath; - isTSEntityName(opts?: object): this is NodePath; - isTSEnumDeclaration(opts?: object): this is NodePath; - isTSEnumMember(opts?: object): this is NodePath; - isTSExportAssignment(opts?: object): this is NodePath; - isTSExpressionWithTypeArguments( - opts?: object, - ): this is NodePath; - isTSExternalModuleReference( - opts?: object, - ): this is NodePath; - isTSFunctionType(opts?: object): this is NodePath; - isTSImportEqualsDeclaration( - opts?: object, - ): this is NodePath; - isTSImportType(opts?: object): this is NodePath; - isTSIndexSignature(opts?: object): this is NodePath; - isTSIndexedAccessType(opts?: object): this is NodePath; - isTSInferType(opts?: object): this is NodePath; - isTSInstantiationExpression( - opts?: object, - ): this is NodePath; - isTSInterfaceBody(opts?: object): this is NodePath; - isTSInterfaceDeclaration( - opts?: object, - ): this is NodePath; - isTSIntersectionType(opts?: object): this is NodePath; - isTSIntrinsicKeyword(opts?: object): this is NodePath; - isTSLiteralType(opts?: object): this is NodePath; - isTSMappedType(opts?: object): this is NodePath; - isTSMethodSignature(opts?: object): this is NodePath; - isTSModuleBlock(opts?: object): this is NodePath; - isTSModuleDeclaration(opts?: object): this is NodePath; - isTSNamedTupleMember(opts?: object): this is NodePath; - isTSNamespaceExportDeclaration( - opts?: object, - ): this is NodePath; - isTSNeverKeyword(opts?: object): this is NodePath; - isTSNonNullExpression(opts?: object): this is NodePath; - isTSNullKeyword(opts?: object): this is NodePath; - isTSNumberKeyword(opts?: object): this is NodePath; - isTSObjectKeyword(opts?: object): this is NodePath; - isTSOptionalType(opts?: object): this is NodePath; - isTSParameterProperty(opts?: object): this is NodePath; - isTSParenthesizedType(opts?: object): this is NodePath; - isTSPropertySignature(opts?: object): this is NodePath; - isTSQualifiedName(opts?: object): this is NodePath; - isTSRestType(opts?: object): this is NodePath; - isTSStringKeyword(opts?: object): this is NodePath; - isTSSymbolKeyword(opts?: object): this is NodePath; - isTSThisType(opts?: object): this is NodePath; - isTSTupleType(opts?: object): this is NodePath; - isTSType(opts?: object): this is NodePath; - isTSTypeAliasDeclaration( - opts?: object, - ): this is NodePath; - isTSTypeAnnotation(opts?: object): this is NodePath; - isTSTypeAssertion(opts?: object): this is NodePath; - isTSTypeElement(opts?: object): this is NodePath; - isTSTypeLiteral(opts?: object): this is NodePath; - isTSTypeOperator(opts?: object): this is NodePath; - isTSTypeParameter(opts?: object): this is NodePath; - isTSTypeParameterDeclaration( - opts?: object, - ): this is NodePath; - isTSTypeParameterInstantiation( - opts?: object, - ): this is NodePath; - isTSTypePredicate(opts?: object): this is NodePath; - isTSTypeQuery(opts?: object): this is NodePath; - isTSTypeReference(opts?: object): this is NodePath; - isTSUndefinedKeyword(opts?: object): this is NodePath; - isTSUnionType(opts?: object): this is NodePath; - isTSUnknownKeyword(opts?: object): this is NodePath; - isTSVoidKeyword(opts?: object): this is NodePath; - isTaggedTemplateExpression( - opts?: object, - ): this is NodePath; - isTemplateElement(opts?: object): this is NodePath; - isTemplateLiteral(opts?: object): this is NodePath; - isTerminatorless(opts?: object): this is NodePath; - isThisExpression(opts?: object): this is NodePath; - isThisTypeAnnotation(opts?: object): this is NodePath; - isThrowStatement(opts?: object): this is NodePath; - isTopicReference(opts?: object): this is NodePath; - isTryStatement(opts?: object): this is NodePath; - isTupleExpression(opts?: object): this is NodePath; - isTupleTypeAnnotation(opts?: object): this is NodePath; - isTypeAlias(opts?: object): this is NodePath; - isTypeAnnotation(opts?: object): this is NodePath; - isTypeCastExpression(opts?: object): this is NodePath; - isTypeParameter(opts?: object): this is NodePath; - isTypeParameterDeclaration( - opts?: object, - ): this is NodePath; - isTypeParameterInstantiation( - opts?: object, - ): this is NodePath; - isTypeScript(opts?: object): this is NodePath; - isTypeofTypeAnnotation( - opts?: object, - ): this is NodePath; - isUnaryExpression(opts?: object): this is NodePath; - isUnaryLike(opts?: object): this is NodePath; - isUnionTypeAnnotation(opts?: object): this is NodePath; - isUpdateExpression(opts?: object): this is NodePath; - isUserWhitespacable(opts?: object): this is NodePath; - isV8IntrinsicIdentifier( - opts?: object, - ): this is NodePath; - isVariableDeclaration(opts?: object): this is NodePath; - isVariableDeclarator(opts?: object): this is NodePath; - isVariance(opts?: object): this is NodePath; - isVoidTypeAnnotation(opts?: object): this is NodePath; - isWhile(opts?: object): this is NodePath; - isWhileStatement(opts?: object): this is NodePath; - isWithStatement(opts?: object): this is NodePath; - isYieldExpression(opts?: object): this is NodePath; - isBindingIdentifier( - opts?: object, - ): this is NodePath; + isAccessor( + this: NodePath, + opts?: object, + ): this is NodePath; + isAnyTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isArgumentPlaceholder( + this: NodePath, + opts?: object, + ): this is NodePath; + isArrayExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isArrayPattern( + this: NodePath, + opts?: object, + ): this is NodePath; + isArrayTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isArrowFunctionExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isAssignmentExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isAssignmentPattern( + this: NodePath, + opts?: object, + ): this is NodePath; + isAwaitExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isBigIntLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isBinary( + this: NodePath, + opts?: object, + ): this is NodePath; + isBinaryExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isBindExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isBlock( + this: NodePath, + opts?: object, + ): this is NodePath; + isBlockParent( + this: NodePath, + opts?: object, + ): this is NodePath; + isBlockStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isBooleanLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isBooleanLiteralTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isBooleanTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isBreakStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isCallExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isCatchClause( + this: NodePath, + opts?: object, + ): this is NodePath; + isClass( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassAccessorProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassImplements( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassMethod( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassPrivateMethod( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassPrivateProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isClassProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isCompletionStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isConditional( + this: NodePath, + opts?: object, + ): this is NodePath; + isConditionalExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isContinueStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isDebuggerStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isDecimalLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareClass( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareExportAllDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareExportDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareFunction( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareInterface( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareModule( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareModuleExports( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareOpaqueType( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareTypeAlias( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclareVariable( + this: NodePath, + opts?: object, + ): this is NodePath; + isDeclaredPredicate( + this: NodePath, + opts?: object, + ): this is NodePath; + isDecorator( + this: NodePath, + opts?: object, + ): this is NodePath; + isDirective( + this: NodePath, + opts?: object, + ): this is NodePath; + isDirectiveLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isDoExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isDoWhileStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isEmptyStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isEmptyTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumBooleanBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumBooleanMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumDefaultedMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumNumberBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumNumberMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumStringBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumStringMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isEnumSymbolBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isExistsTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportAllDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportDefaultDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportDefaultSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportNamedDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportNamespaceSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isExportSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isExpressionStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isExpressionWrapper( + this: NodePath, + opts?: object, + ): this is NodePath; + isFile( + this: NodePath, + opts?: object, + ): this is NodePath; + isFlow( + this: NodePath, + opts?: object, + ): this is NodePath; + isFlowBaseAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isFlowDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isFlowPredicate( + this: NodePath, + opts?: object, + ): this is NodePath; + isFlowType( + this: NodePath, + opts?: object, + ): this is NodePath; + isFor( + this: NodePath, + opts?: object, + ): this is NodePath; + isForInStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isForOfStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isForStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isForXStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isFunction( + this: NodePath, + opts?: object, + ): this is NodePath; + isFunctionDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isFunctionExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isFunctionParent( + this: NodePath, + opts?: object, + ): this is NodePath; + isFunctionTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isFunctionTypeParam( + this: NodePath, + opts?: object, + ): this is NodePath; + isGenericTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isIdentifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isIfStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isImmutable( + this: NodePath, + opts?: object, + ): this is NodePath; + isImport( + this: NodePath, + opts?: object, + ): this is NodePath; + isImportAttribute( + this: NodePath, + opts?: object, + ): this is NodePath; + isImportDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isImportDefaultSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isImportNamespaceSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isImportSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isIndexedAccessType( + this: NodePath, + opts?: object, + ): this is NodePath; + isInferredPredicate( + this: NodePath, + opts?: object, + ): this is NodePath; + isInterfaceDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isInterfaceExtends( + this: NodePath, + opts?: object, + ): this is NodePath; + isInterfaceTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isInterpreterDirective( + this: NodePath, + opts?: object, + ): this is NodePath; + isIntersectionTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSX( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXAttribute( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXClosingElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXClosingFragment( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXEmptyExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXExpressionContainer( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXFragment( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXIdentifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXMemberExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXNamespacedName( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXOpeningElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXOpeningFragment( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXSpreadAttribute( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXSpreadChild( + this: NodePath, + opts?: object, + ): this is NodePath; + isJSXText( + this: NodePath, + opts?: object, + ): this is NodePath; + isLVal( + this: NodePath, + opts?: object, + ): this is NodePath; + isLabeledStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isLogicalExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isLoop( + this: NodePath, + opts?: object, + ): this is NodePath; + isMemberExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isMetaProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isMethod( + this: NodePath, + opts?: object, + ): this is NodePath; + isMiscellaneous( + this: NodePath, + opts?: object, + ): this is NodePath; + isMixedTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isModuleDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isModuleExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isModuleSpecifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isNewExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isNoop( + this: NodePath, + opts?: object, + ): this is NodePath; + isNullLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isNullLiteralTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isNullableTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isNumberLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isNumberLiteralTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isNumberTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isNumericLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectMethod( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectPattern( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectTypeCallProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectTypeIndexer( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectTypeInternalSlot( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectTypeProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isObjectTypeSpreadProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isOpaqueType( + this: NodePath, + opts?: object, + ): this is NodePath; + isOptionalCallExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isOptionalIndexedAccessType( + this: NodePath, + opts?: object, + ): this is NodePath; + isOptionalMemberExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isParenthesizedExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isPattern( + this: NodePath, + opts?: object, + ): this is NodePath; + isPatternLike( + this: NodePath, + opts?: object, + ): this is NodePath; + isPipelineBareFunction( + this: NodePath, + opts?: object, + ): this is NodePath; + isPipelinePrimaryTopicReference( + this: NodePath, + opts?: object, + ): this is NodePath; + isPipelineTopicExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isPlaceholder( + this: NodePath, + opts?: object, + ): this is NodePath; + isPrivate( + this: NodePath, + opts?: object, + ): this is NodePath; + isPrivateName( + this: NodePath, + opts?: object, + ): this is NodePath; + isProgram( + this: NodePath, + opts?: object, + ): this is NodePath; + isProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isPureish( + this: NodePath, + opts?: object, + ): this is NodePath; + isQualifiedTypeIdentifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isRecordExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isRegExpLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isRegexLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isRestElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isRestProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isReturnStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isScopable( + this: NodePath, + opts?: object, + ): this is NodePath; + isSequenceExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isSpreadElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isSpreadProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isStandardized( + this: NodePath, + opts?: object, + ): this is NodePath; + isStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isStaticBlock( + this: NodePath, + opts?: object, + ): this is NodePath; + isStringLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isStringLiteralTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isStringTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isSuper( + this: NodePath, + opts?: object, + ): this is NodePath; + isSwitchCase( + this: NodePath, + opts?: object, + ): this is NodePath; + isSwitchStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isSymbolTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSAnyKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSArrayType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSAsExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSBaseType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSBigIntKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSBooleanKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSCallSignatureDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSConditionalType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSConstructSignatureDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSConstructorType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSDeclareFunction( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSDeclareMethod( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSEntityName( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSEnumDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSEnumMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSExportAssignment( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSExpressionWithTypeArguments( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSExternalModuleReference( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSFunctionType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSImportEqualsDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSImportType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSIndexSignature( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSIndexedAccessType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSInferType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSInstantiationExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSInterfaceBody( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSInterfaceDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSIntersectionType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSIntrinsicKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSLiteralType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSMappedType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSMethodSignature( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSModuleBlock( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSModuleDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSNamedTupleMember( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSNamespaceExportDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSNeverKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSNonNullExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSNullKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSNumberKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSObjectKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSOptionalType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSParameterProperty( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSParenthesizedType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSPropertySignature( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSQualifiedName( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSRestType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSStringKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSSymbolKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSThisType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTupleType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeAliasDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeAssertion( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeOperator( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeParameter( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeParameterDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeParameterInstantiation( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypePredicate( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeQuery( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSTypeReference( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSUndefinedKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSUnionType( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSUnknownKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTSVoidKeyword( + this: NodePath, + opts?: object, + ): this is NodePath; + isTaggedTemplateExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isTemplateElement( + this: NodePath, + opts?: object, + ): this is NodePath; + isTemplateLiteral( + this: NodePath, + opts?: object, + ): this is NodePath; + isTerminatorless( + this: NodePath, + opts?: object, + ): this is NodePath; + isThisExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isThisTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isThrowStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isTopicReference( + this: NodePath, + opts?: object, + ): this is NodePath; + isTryStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isTupleExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isTupleTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeAlias( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeCastExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeParameter( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeParameterDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeParameterInstantiation( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeScript( + this: NodePath, + opts?: object, + ): this is NodePath; + isTypeofTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isUnaryExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isUnaryLike( + this: NodePath, + opts?: object, + ): this is NodePath; + isUnionTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isUpdateExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isUserWhitespacable( + this: NodePath, + opts?: object, + ): this is NodePath; + isV8IntrinsicIdentifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isVariableDeclaration( + this: NodePath, + opts?: object, + ): this is NodePath; + isVariableDeclarator( + this: NodePath, + opts?: object, + ): this is NodePath; + isVariance( + this: NodePath, + opts?: object, + ): this is NodePath; + isVoidTypeAnnotation( + this: NodePath, + opts?: object, + ): this is NodePath; + isWhile( + this: NodePath, + opts?: object, + ): this is NodePath; + isWhileStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isWithStatement( + this: NodePath, + opts?: object, + ): this is NodePath; + isYieldExpression( + this: NodePath, + opts?: object, + ): this is NodePath; + isBindingIdentifier( + this: NodePath, + opts?: object, + ): this is NodePath; isBlockScoped(opts?: object): boolean; - isExistentialTypeParam( + isExistentialTypeParam( + this: NodePath, + opts?: object, + ): this is NodePath; + isExpression( + this: NodePath, opts?: object, - ): this is NodePath; - isExpression(opts?: object): this is NodePath; - isFlow(opts?: object): this is NodePath; - isForAwaitStatement( + ): this is NodePath; + isFlow( + this: NodePath, opts?: object, - ): this is NodePath; + ): this is NodePath; + isForAwaitStatement( + this: NodePath, + opts?: object, + ): this is NodePath; isGenerated(opts?: object): boolean; - isNumericLiteralTypeAnnotation( + isNumericLiteralTypeAnnotation( + this: NodePath, opts?: object, - ): this is NodePath; + ): this is NodePath; isPure(constantsOnly?: boolean): boolean; isReferenced(opts?: object): boolean; - isReferencedIdentifier( + isReferencedIdentifier( + this: NodePath, + opts?: object, + ): this is NodePath; + isReferencedMemberExpression( + this: NodePath, opts?: object, - ): this is NodePath; - isReferencedMemberExpression( + ): this is NodePath; + isRestProperty( + this: NodePath, opts?: object, - ): this is NodePath; - isRestProperty( + ): this is NodePath; + isScope( + this: NodePath, opts?: object, - ): this is NodePath; - isScope(opts?: object): this is NodePath; - isSpreadProperty( + ): this is NodePath; + isSpreadProperty( + this: NodePath, opts?: object, - ): this is NodePath; - isStatement(opts?: object): this is NodePath; + ): this is NodePath; + isStatement( + this: NodePath, + opts?: object, + ): this is NodePath; isUser(opts?: object): boolean; - isVar(opts?: object): this is NodePath; + isVar( + this: NodePath, + opts?: object, + ): this is NodePath; } diff --git a/packages/babel-traverse/src/path/index.ts b/packages/babel-traverse/src/path/index.ts index 7a537612bbfa..faa5af2c55bc 100644 --- a/packages/babel-traverse/src/path/index.ts +++ b/packages/babel-traverse/src/path/index.ts @@ -272,7 +272,7 @@ for (const type of Object.keys(virtualTypes) as (keyof typeof virtualTypes)[]) { const virtualType = virtualTypes[type]; - NodePath.prototype[`is${type}`] = function (opts) { + NodePath.prototype[`is${type}`] = function (opts?: any) { // @ts-expect-error checkPath will throw when type is ExistentialTypeParam/NumericLiteralTypeAnnotation return virtualType.checkPath(this, opts); }; diff --git a/packages/babel-traverse/src/path/introspection.ts b/packages/babel-traverse/src/path/introspection.ts index cfe31bc76a9a..9a44718c387e 100644 --- a/packages/babel-traverse/src/path/introspection.ts +++ b/packages/babel-traverse/src/path/introspection.ts @@ -645,8 +645,6 @@ export function isInStrictMode(this: NodePath) { if (path.isClass()) return true; - if (!path.isProgram() && !path.isFunction()) return false; - if ( path.isArrowFunctionExpression() && !path.get("body").isBlockStatement() @@ -654,9 +652,14 @@ export function isInStrictMode(this: NodePath) { return false; } - const body: t.BlockStatement | t.Program = path.isFunction() - ? (path.node.body as t.BlockStatement) - : (path.node as t.Program); + let body: t.BlockStatement | t.Program; + if (path.isFunction()) { + body = path.node.body as t.BlockStatement; + } else if (path.isProgram()) { + body = path.node; + } else { + return false; + } for (const directive of body.directives) { if (directive.value.value === "use strict") {