import type * as swc from '@swc/types' import type { Node, Callback, RecursiveVisitors } from './types' const ignore = (_n: Node, _st: S, _cb: Callback) => {} export class BaseVisitor implements Required> { ArrayExpression(n: swc.ArrayExpression, st: S, cb: Callback) { for (const el of n.elements) { if (el) { cb(el.expression, st) } } } ArrayPattern(n: swc.ArrayPattern, st: S, cb: Callback) { for (const el of n.elements) { if (el) { cb(el, st) } } } ArrowFunctionExpression(n: swc.ArrowFunctionExpression, st: S, cb: Callback) { cb(n.body, st) if (n.typeParameters) { cb(n.typeParameters, st) } } AssignmentExpression(n: swc.AssignmentExpression, st: S, cb: Callback) { cb(n.left, st) cb(n.right, st) } AssignmentPattern(n: swc.AssignmentPattern, st: S, cb: Callback) { cb(n.left, st) cb(n.right, st) // could be wrongly inherited from swc.PatternBase (could not find a way to trigger this) // if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } AssignmentPatternProperty(n: swc.AssignmentPatternProperty, st: S, cb: Callback) { cb(n.key, st) if (n.value) { cb(n.value, st) } } AssignmentProperty(n: swc.AssignmentProperty, st: S, cb: Callback) { cb(n.value, st) } AwaitExpression(n: swc.AwaitExpression, st: S, cb: Callback) { cb(n.argument, st) } BigIntLiteral = ignore BinaryExpression(n: swc.BinaryExpression, st: S, cb: Callback) { cb(n.left, st) cb(n.right, st) } BlockStatement(n: swc.BlockStatement, st: S, cb: Callback) { for (const stmt of n.stmts) { cb(stmt, st) } } BooleanLiteral = ignore BreakStatement(n: swc.BreakStatement, st: S, cb: Callback) { if (n.label) { cb(n.label, st) } } CallExpression(n: swc.CallExpression, st: S, cb: Callback) { cb(n.callee, st) for (const arg of n.arguments) { cb(arg.expression, st) } if (n.typeArguments) { cb(n.typeArguments, st) } } CatchClause(n: swc.CatchClause, st: S, cb: Callback) { if (n.param) { cb(n.param, st) } cb(n.body, st) } ClassDeclaration(n: swc.ClassDeclaration, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.identifier, st) for (const implement of n.implements) { cb(implement, st) } if (n.superClass) { cb(n.superClass, st) } if (n.superTypeParams) { cb(n.superTypeParams, st) } if (n.typeParams) { cb(n.typeParams, st) } for (const member of n.body) { cb(member, st) } } ClassExpression(n: swc.ClassExpression, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } if (n.identifier) { cb(n.identifier, st) } for (const implement of n.implements) { cb(implement, st) } if (n.superClass) { cb(n.superClass, st) } if (n.superTypeParams) { cb(n.superTypeParams, st) } if (n.typeParams) { cb(n.typeParams, st) } for (const member of n.body) { cb(member, st) } } ClassMethod(n: swc.ClassMethod, st: S, cb: Callback) { cb(n.key, st) for (const decorator of n.function.decorators ?? []) { cb(decorator, st) } for (const param of n.function.params) { cb(param, st) } if (n.function.returnType) { cb(n.function.returnType, st) } if (n.function.typeParameters) { cb(n.function.typeParameters, st) } if (n.function.body) { cb(n.function.body, st) } } ClassProperty(n: swc.ClassProperty, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.key, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } if (n.value) { cb(n.value, st) } } Computed(n: swc.ComputedPropName, st: S, cb: Callback) { cb(n.expression, st) } ConditionalExpression(n: swc.ConditionalExpression, st: S, cb: Callback) { cb(n.test, st) cb(n.consequent, st) cb(n.alternate, st) } Constructor(n: swc.Constructor, st: S, cb: Callback) { cb(n.key, st) for (const param of n.params) { cb(param, st) } if (n.body) { cb(n.body, st) } } ContinueStatement(n: swc.ContinueStatement, st: S, cb: Callback) { if (n.label) { cb(n.label, st) } } DebuggerStatement = ignore Decorator(n: swc.Decorator, st: S, cb: Callback) { cb(n.expression, st) } DoWhileStatement(n: swc.DoWhileStatement, st: S, cb: Callback) { cb(n.body, st) cb(n.test, st) } EmptyStatement = ignore ExportAllDeclaration(n: swc.ExportAllDeclaration, st: S, cb: Callback) { cb(n.source, st) // @ts-expect-error -- asserts is not typed in ExportAllDeclaration // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment n.asserts = n.asserts ?? n.with if (n.asserts) { cb(n.asserts, st) } } ExportDeclaration(n: swc.ExportDeclaration, st: S, cb: Callback) { cb(n.declaration, st) } ExportDefaultDeclaration(n: swc.ExportDefaultDeclaration, st: S, cb: Callback) { cb(n.decl, st) } ExportDefaultExpression(n: swc.ExportDefaultExpression, st: S, cb: Callback) { cb(n.expression, st) } ExportDefaultSpecifier(n: swc.ExportDefaultSpecifier, st: S, cb: Callback) { cb(n.exported, st) } ExportNamedDeclaration(n: swc.ExportNamedDeclaration, st: S, cb: Callback) { for (const specifier of n.specifiers) { cb(specifier, st) } if (n.source) { cb(n.source, st) } // @ts-expect-error -- asserts is not typed in ExportAllDeclaration // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment n.asserts = n.asserts ?? n.with if (n.asserts) { cb(n.asserts, st) } } ExportNamespaceSpecifier(n: swc.ExportNamespaceSpecifier, st: S, cb: Callback) { cb(n.name, st) } ExportSpecifier(n: swc.NamedExportSpecifier, st: S, cb: Callback) { if (n.exported) { cb(n.exported, st) } cb(n.orig, st) } ExpressionStatement(n: swc.ExpressionStatement, st: S, cb: Callback) { cb(n.expression, st) } ForInStatement(n: swc.ForInStatement, st: S, cb: Callback) { cb(n.left, st) cb(n.right, st) cb(n.body, st) } ForOfStatement(n: swc.ForOfStatement, st: S, cb: Callback) { cb(n.left, st) cb(n.right, st) cb(n.body, st) } ForStatement(n: swc.ForStatement, st: S, cb: Callback) { if (n.init) { cb(n.init, st) } if (n.test) { cb(n.test, st) } if (n.update) { cb(n.update, st) } cb(n.body, st) } FunctionDeclaration(n: swc.FunctionDeclaration, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.identifier, st) for (const param of n.params) { cb(param, st) } if (n.returnType) { cb(n.returnType, st) } if (n.typeParameters) { cb(n.typeParameters, st) } if (n.body) { cb(n.body, st) } } FunctionExpression(n: swc.FunctionExpression, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } if (n.identifier) { cb(n.identifier, st) } for (const param of n.params) { cb(param, st) } if (n.returnType) { cb(n.returnType, st) } if (n.typeParameters) { cb(n.typeParameters, st) } if (n.body) { cb(n.body, st) } } GetterProperty(n: swc.GetterProperty, st: S, cb: Callback) { cb(n.key, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } if (n.body) { cb(n.body, st) } } Identifier(n: swc.Identifier | swc.BindingIdentifier, st: S, cb: Callback) { if ('typeAnnotation' in n && n.typeAnnotation) { cb(n.typeAnnotation, st) } } IfStatement(n: swc.IfStatement, st: S, cb: Callback) { cb(n.test, st) cb(n.consequent, st) if (n.alternate) { cb(n.alternate, st) } } Import = ignore ImportDeclaration(n: swc.ImportDeclaration, st: S, cb: Callback) { for (const specifier of n.specifiers) { cb(specifier, st) } cb(n.source, st) // @ts-expect-error -- asserts is not typed in ExportAllDeclaration // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment n.asserts = n.asserts ?? n.with if (n.asserts) { cb(n.asserts, st) } } ImportDefaultSpecifier(n: swc.ImportDefaultSpecifier, st: S, cb: Callback) { cb(n.local, st) } ImportNamespaceSpecifier(n: swc.ImportNamespaceSpecifier, st: S, cb: Callback) { cb(n.local, st) } ImportSpecifier(n: swc.NamedImportSpecifier, st: S, cb: Callback) { if (n.imported) { cb(n.imported, st) } cb(n.local, st) } Invalid = ignore JSXAttribute(n: swc.JSXAttribute, st: S, cb: Callback) { cb(n.name, st) if (n.value) { cb(n.value, st) } } JSXClosingElement(n: swc.JSXClosingElement, st: S, cb: Callback) { cb(n.name, st) } JSXClosingFragment = ignore JSXElement(n: swc.JSXElement, st: S, cb: Callback) { cb(n.opening, st) for (const child of n.children) { cb(child, st) } if (n.closing) { cb(n.closing, st) } } JSXEmptyExpression = ignore JSXExpressionContainer(n: swc.JSXExpressionContainer, st: S, cb: Callback) { cb(n.expression, st) } JSXFragment(n: swc.JSXFragment, st: S, cb: Callback) { cb(n.opening, st) for (const child of n.children) { cb(child, st) } cb(n.closing, st) } JSXMemberExpression(n: swc.JSXMemberExpression, st: S, cb: Callback) { cb(n.property, st) cb(n.object, st) } JSXNamespacedName(n: swc.JSXNamespacedName, st: S, cb: Callback) { cb(n.namespace, st) cb(n.name, st) } JSXOpeningElement(n: swc.JSXOpeningElement, st: S, cb: Callback) { cb(n.name, st) for (const attr of n.attributes) { cb(attr, st) } if (n.typeArguments) { cb(n.typeArguments, st) } } JSXOpeningFragment = ignore JSXSpreadChild(n: swc.JSXSpreadChild, st: S, cb: Callback) { cb(n.expression, st) } JSXText = ignore KeyValuePatternProperty(n: swc.KeyValuePatternProperty, st: S, cb: Callback) { cb(n.key, st) cb(n.value, st) } KeyValueProperty(n: swc.KeyValueProperty, st: S, cb: Callback) { cb(n.key, st) cb(n.value, st) } LabeledStatement(n: swc.LabeledStatement, st: S, cb: Callback) { cb(n.label, st) cb(n.body, st) } MemberExpression(n: swc.MemberExpression, st: S, cb: Callback) { cb(n.object, st) cb(n.property, st) } MetaProperty = ignore MethodProperty(n: swc.MethodProperty, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.key, st) for (const param of n.params) { cb(param, st) } if (n.returnType) { cb(n.returnType, st) } if (n.typeParameters) { cb(n.typeParameters, st) } if (n.body) { cb(n.body, st) } } Module(n: swc.Module, st: S, cb: Callback) { for (const stmt of n.body) { cb(stmt, st) } } NewExpression(n: swc.NewExpression, st: S, cb: Callback) { cb(n.callee, st) if (n.arguments) { for (const arg of n.arguments) { cb(arg.expression, st) } } if (n.typeArguments) { cb(n.typeArguments, st) } } NullLiteral = ignore NumericLiteral = ignore ObjectExpression(n: swc.ObjectExpression, st: S, cb: Callback) { for (const property of n.properties) { cb(property, st) } } ObjectPattern(n: swc.ObjectPattern, st: S, cb: Callback) { for (const property of n.properties) { cb(property, st) } if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } OptionalChainingExpression(n: swc.OptionalChainingExpression, st: S, cb: Callback) { cb(n.base, st) } Parameter(n: swc.Param, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.pat, st) } ParenthesisExpression(n: swc.ParenthesisExpression, st: S, cb: Callback) { cb(n.expression, st) } PrivateMethod(n: swc.PrivateMethod, st: S, cb: Callback) { cb(n.key, st) for (const decorator of n.function.decorators ?? []) { cb(decorator, st) } for (const param of n.function.params) { cb(param, st) } if (n.function.returnType) { cb(n.function.returnType, st) } if (n.function.typeParameters) { cb(n.function.typeParameters, st) } if (n.function.body) { cb(n.function.body, st) } } PrivateName(n: swc.PrivateName, st: S, cb: Callback) { cb(n.id, st) } PrivateProperty(n: swc.PrivateProperty, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.key, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } if (n.value) { cb(n.value, st) } } RegExpLiteral = ignore RestElement(n: swc.RestElement, st: S, cb: Callback) { cb(n.argument, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } ReturnStatement(n: swc.ReturnStatement, st: S, cb: Callback) { if (n.argument) { cb(n.argument, st) } } Script(n: swc.Script, st: S, cb: Callback) { for (const stmt of n.body) { cb(stmt, st) } } SequenceExpression(n: swc.SequenceExpression, st: S, cb: Callback) { for (const expression of n.expressions) { cb(expression, st) } } SetterProperty(n: swc.SetterProperty, st: S, cb: Callback) { cb(n.key, st) cb(n.param, st) if (n.body) { cb(n.body, st) } } SpreadElement(n: swc.SpreadElement, st: S, cb: Callback) { cb(n.arguments, st) } StaticBlock(n: swc.StaticBlock, st: S, cb: Callback) { cb(n.body, st) } StringLiteral = ignore Super = ignore SuperPropExpression(n: swc.SuperPropExpression, st: S, cb: Callback) { cb(n.obj, st) cb(n.property, st) } SwitchCase(n: swc.SwitchCase, st: S, cb: Callback) { if (n.test) { cb(n.test, st) } for (const consequent of n.consequent) { cb(consequent, st) } } SwitchStatement(n: swc.SwitchStatement, st: S, cb: Callback) { cb(n.discriminant, st) for (const cases of n.cases) { cb(cases, st) } } TaggedTemplateExpression(n: swc.TaggedTemplateExpression, st: S, cb: Callback) { cb(n.tag, st) cb(n.template, st) if (n.typeParameters) { cb(n.typeParameters, st) } } TemplateElement = ignore TemplateLiteral(n: swc.TemplateLiteral | swc.TsTemplateLiteralType, st: S, cb: Callback) { for (const quasis of n.quasis) { cb(quasis, st) } if ('expressions' in n) { for (const expressions of n.expressions) { cb(expressions, st) } } if ('types' in n) { for (const types of n.types) { cb(types, st) } } } ThisExpression = ignore ThrowStatement(n: swc.ThrowStatement, st: S, cb: Callback) { cb(n.argument, st) } TryStatement(n: swc.TryStatement, st: S, cb: Callback) { cb(n.block, st) if (n.handler) { cb(n.handler, st) } if (n.finalizer) { cb(n.finalizer, st) } } TsArrayType(n: swc.TsArrayType, st: S, cb: Callback) { cb(n.elemType, st) } TsExpressionWithTypeArguments(n: swc.TsExpressionWithTypeArguments, st: S, cb: Callback) { cb(n.expression, st) if (n.typeArguments) { cb(n.typeArguments, st) } } TsInterfaceDeclaration(n: swc.TsInterfaceDeclaration, st: S, cb: Callback) { cb(n.id, st) cb(n.body, st) for (const ext of n.extends) { cb(ext, st) } if (n.typeParams) { cb(n.typeParams, st) } } TsInterfaceBody(n: swc.TsInterfaceBody, st: S, cb: Callback) { for (const ele of n.body) { cb(ele, st) } } TsKeywordType = ignore TsPropertySignature(n: swc.TsPropertySignature, st: S, cb: Callback) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- params can be undefined for (const param of n.params ?? []) { cb(param, st) } cb(n.key, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } if (n.typeParams) { cb(n.typeParams, st) } } TsAsExpression(n: swc.TsAsExpression, st: S, cb: Callback) { cb(n.expression, st) cb(n.typeAnnotation, st) } TsCallSignatureDeclaration(n: swc.TsCallSignatureDeclaration, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } if (n.typeParams) { cb(n.typeParams, st) } if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } TsConditionalType(n: swc.TsConditionalType, st: S, cb: Callback) { cb(n.checkType, st) cb(n.extendsType, st) cb(n.trueType, st) cb(n.falseType, st) } TsConstAssertion(n: swc.TsConstAssertion, st: S, cb: Callback) { cb(n.expression, st) } TsConstructorType(n: swc.TsConstructorType, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } cb(n.typeAnnotation, st) if (n.typeParams) { cb(n.typeParams, st) } } TsConstructSignatureDeclaration(n: swc.TsConstructSignatureDeclaration, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } if (n.typeParams) { cb(n.typeParams, st) } if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } TsEnumDeclaration(n: swc.TsEnumDeclaration, st: S, cb: Callback) { cb(n.id, st) for (const member of n.members) { cb(member, st) } } TsEnumMember(n: swc.TsEnumMember, st: S, cb: Callback) { cb(n.id, st) if (n.init) { cb(n.init, st) } } TsExportAssignment(n: swc.TsExportAssignment, st: S, cb: Callback) { cb(n.expression, st) } TsExternalModuleReference(n: swc.TsExternalModuleReference, st: S, cb: Callback) { cb(n.expression, st) } TsFunctionType(n: swc.TsFunctionType, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } cb(n.typeAnnotation, st) if (n.typeParams) { cb(n.typeParams, st) } } TsGetterSignature(n: swc.TsGetterSignature, st: S, cb: Callback) { cb(n.key, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } TsImportEqualsDeclaration(n: swc.TsImportEqualsDeclaration, st: S, cb: Callback) { cb(n.id, st) cb(n.moduleRef, st) } TsImportType(n: swc.TsImportType, st: S, cb: Callback) { cb(n.argument, st) if (n.qualifier) { cb(n.qualifier, st) } if (n.typeArguments) { cb(n.typeArguments, st) } } TsIndexedAccessType(n: swc.TsIndexedAccessType, st: S, cb: Callback) { cb(n.indexType, st) cb(n.objectType, st) } TsIndexSignature(n: swc.TsIndexSignature, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } TsInferType(n: swc.TsInferType, st: S, cb: Callback) { cb(n.typeParam, st) } TsInstantiation(n: swc.TsInstantiation, st: S, cb: Callback) { cb(n.expression, st) cb(n.typeArguments, st) } TsIntersectionType(n: swc.TsIntersectionType, st: S, cb: Callback) { for (const type of n.types) { cb(type, st) } } TsLiteralType(n: swc.TsLiteralType, st: S, cb: Callback) { cb(n.literal, st) } TsMappedType(n: swc.TsMappedType, st: S, cb: Callback) { if (n.nameType) { cb(n.nameType, st) } if (n.typeAnnotation) { cb(n.typeAnnotation, st) } cb(n.typeParam, st) } TsMethodSignature(n: swc.TsMethodSignature, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } cb(n.key, st) if (n.typeAnn) { cb(n.typeAnn, st) } if (n.typeParams) { cb(n.typeParams, st) } } TsModuleBlock(n: swc.TsModuleBlock, st: S, cb: Callback) { for (const stmt of n.body) { cb(stmt, st) } } TsModuleDeclaration(n: swc.TsModuleDeclaration, st: S, cb: Callback) { cb(n.id, st) if (n.body) { cb(n.body, st) } } TsNamespaceDeclaration(n: swc.TsNamespaceDeclaration, st: S, cb: Callback) { cb(n.id, st) cb(n.body, st) } TsNamespaceExportDeclaration(n: swc.TsNamespaceExportDeclaration, st: S, cb: Callback) { cb(n.id, st) } TsNonNullExpression(n: swc.TsNonNullExpression, st: S, cb: Callback) { cb(n.expression, st) } TsOptionalType(n: swc.TsOptionalType, st: S, cb: Callback) { cb(n.typeAnnotation, st) } TsParameterProperty(n: swc.TsParameterProperty, st: S, cb: Callback) { for (const decorator of n.decorators ?? []) { cb(decorator, st) } cb(n.param, st) } TsParenthesizedType(n: swc.TsParenthesizedType, st: S, cb: Callback) { cb(n.typeAnnotation, st) } TsQualifiedName(n: swc.TsQualifiedName, st: S, cb: Callback) { cb(n.left, st) cb(n.right, st) } TsRestType(n: swc.TsRestType, st: S, cb: Callback) { cb(n.typeAnnotation, st) } TsSatisfiesExpression(n: swc.TsSatisfiesExpression, st: S, cb: Callback) { cb(n.expression, st) cb(n.typeAnnotation, st) } TsSetterSignature(n: swc.TsSetterSignature, st: S, cb: Callback) { cb(n.key, st) cb(n.param, st) } TsThisType = ignore TsTupleElement(n: swc.TsTupleElement, st: S, cb: Callback) { if (n.label) { cb(n.label, st) } cb(n.ty, st) } TsTupleType(n: swc.TsTupleType, st: S, cb: Callback) { for (const el of n.elemTypes) { cb(el, st) } } TsTypeAliasDeclaration(n: swc.TsTypeAliasDeclaration, st: S, cb: Callback) { cb(n.id, st) cb(n.typeAnnotation, st) if (n.typeParams) { cb(n.typeParams, st) } } TsType = ignore TsTypeAnnotation(n: swc.TsTypeAnnotation, st: S, cb: Callback) { cb(n.typeAnnotation, st) } TsTypeParameter(n: swc.TsTypeParameter, st: S, cb: Callback) { cb(n.name, st) if (n.constraint) { cb(n.constraint, st) } if (n.default) { cb(n.default, st) } } TsTypeParameterDeclaration(n: swc.TsTypeParameterDeclaration, st: S, cb: Callback) { for (const param of n.parameters) { cb(param, st) } } TsTypeAssertion(n: swc.TsTypeAssertion, st: S, cb: Callback) { cb(n.expression, st) cb(n.typeAnnotation, st) } TsTypeElement = ignore TsTypeLiteral(n: swc.TsTypeLiteral, st: S, cb: Callback) { for (const member of n.members) { cb(member, st) } } TsTypeOperator(n: swc.TsTypeOperator, st: S, cb: Callback) { cb(n.typeAnnotation, st) } TsTypeParameterInstantiation(n: swc.TsTypeParameterInstantiation, st: S, cb: Callback) { for (const param of n.params) { cb(param, st) } } TsTypeReference(n: swc.TsTypeReference, st: S, cb: Callback) { cb(n.typeName, st) if (n.typeParams) { cb(n.typeParams, st) } } TsTypePredicate(n: swc.TsTypePredicate, st: S, cb: Callback) { cb(n.paramName, st) if (n.typeAnnotation) { cb(n.typeAnnotation, st) } } TsTypeQuery(n: swc.TsTypeQuery, st: S, cb: Callback) { cb(n.exprName, st) if (n.typeArguments) { cb(n.typeArguments, st) } } TsUnionType(n: swc.TsUnionType, st: S, cb: Callback) { for (const type of n.types) { cb(type, st) } } UnaryExpression(n: swc.UnaryExpression, st: S, cb: Callback) { cb(n.argument, st) } UpdateExpression(n: swc.UpdateExpression, st: S, cb: Callback) { cb(n.argument, st) } VariableDeclaration(n: swc.VariableDeclaration, st: S, cb: Callback) { for (const decl of n.declarations) { cb(decl, st) } } VariableDeclarator(n: swc.VariableDeclarator, st: S, cb: Callback) { cb(n.id, st) if (n.init) { cb(n.init, st) } } WhileStatement(n: swc.WhileStatement, st: S, cb: Callback) { cb(n.test, st) cb(n.body, st) } WithStatement(n: swc.WithStatement, st: S, cb: Callback) { cb(n.object, st) cb(n.body, st) } YieldExpression(n: swc.YieldExpression, st: S, cb: Callback) { if (n.argument) { cb(n.argument, st) } } } export default BaseVisitor