UNPKG

@babel/types

Version:

Babel Types is a Lodash-esque utility library for AST nodes

1,586 lines (1,584 loc) 85.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anyTypeAnnotation = anyTypeAnnotation; exports.argumentPlaceholder = argumentPlaceholder; exports.arrayExpression = arrayExpression; exports.arrayPattern = arrayPattern; exports.arrayTypeAnnotation = arrayTypeAnnotation; exports.arrowFunctionExpression = arrowFunctionExpression; exports.assignmentExpression = assignmentExpression; exports.assignmentPattern = assignmentPattern; exports.awaitExpression = awaitExpression; exports.bigIntLiteral = bigIntLiteral; exports.binaryExpression = binaryExpression; exports.bindExpression = bindExpression; exports.blockStatement = blockStatement; exports.booleanLiteral = booleanLiteral; exports.booleanLiteralTypeAnnotation = booleanLiteralTypeAnnotation; exports.booleanTypeAnnotation = booleanTypeAnnotation; exports.breakStatement = breakStatement; exports.callExpression = callExpression; exports.catchClause = catchClause; exports.classAccessorProperty = classAccessorProperty; exports.classBody = classBody; exports.classDeclaration = classDeclaration; exports.classExpression = classExpression; exports.classImplements = classImplements; exports.classMethod = classMethod; exports.classPrivateMethod = classPrivateMethod; exports.classPrivateProperty = classPrivateProperty; exports.classProperty = classProperty; exports.conditionalExpression = conditionalExpression; exports.continueStatement = continueStatement; exports.debuggerStatement = debuggerStatement; exports.decimalLiteral = decimalLiteral; exports.declareClass = declareClass; exports.declareExportAllDeclaration = declareExportAllDeclaration; exports.declareExportDeclaration = declareExportDeclaration; exports.declareFunction = declareFunction; exports.declareInterface = declareInterface; exports.declareModule = declareModule; exports.declareModuleExports = declareModuleExports; exports.declareOpaqueType = declareOpaqueType; exports.declareTypeAlias = declareTypeAlias; exports.declareVariable = declareVariable; exports.declaredPredicate = declaredPredicate; exports.decorator = decorator; exports.directive = directive; exports.directiveLiteral = directiveLiteral; exports.doExpression = doExpression; exports.doWhileStatement = doWhileStatement; exports.emptyStatement = emptyStatement; exports.emptyTypeAnnotation = emptyTypeAnnotation; exports.enumBooleanBody = enumBooleanBody; exports.enumBooleanMember = enumBooleanMember; exports.enumDeclaration = enumDeclaration; exports.enumDefaultedMember = enumDefaultedMember; exports.enumNumberBody = enumNumberBody; exports.enumNumberMember = enumNumberMember; exports.enumStringBody = enumStringBody; exports.enumStringMember = enumStringMember; exports.enumSymbolBody = enumSymbolBody; exports.existsTypeAnnotation = existsTypeAnnotation; exports.exportAllDeclaration = exportAllDeclaration; exports.exportDefaultDeclaration = exportDefaultDeclaration; exports.exportDefaultSpecifier = exportDefaultSpecifier; exports.exportNamedDeclaration = exportNamedDeclaration; exports.exportNamespaceSpecifier = exportNamespaceSpecifier; exports.exportSpecifier = exportSpecifier; exports.expressionStatement = expressionStatement; exports.file = file; exports.forInStatement = forInStatement; exports.forOfStatement = forOfStatement; exports.forStatement = forStatement; exports.functionDeclaration = functionDeclaration; exports.functionExpression = functionExpression; exports.functionTypeAnnotation = functionTypeAnnotation; exports.functionTypeParam = functionTypeParam; exports.genericTypeAnnotation = genericTypeAnnotation; exports.identifier = identifier; exports.ifStatement = ifStatement; exports.import = _import; exports.importAttribute = importAttribute; exports.importDeclaration = importDeclaration; exports.importDefaultSpecifier = importDefaultSpecifier; exports.importExpression = importExpression; exports.importNamespaceSpecifier = importNamespaceSpecifier; exports.importSpecifier = importSpecifier; exports.indexedAccessType = indexedAccessType; exports.inferredPredicate = inferredPredicate; exports.interfaceDeclaration = interfaceDeclaration; exports.interfaceExtends = interfaceExtends; exports.interfaceTypeAnnotation = interfaceTypeAnnotation; exports.interpreterDirective = interpreterDirective; exports.intersectionTypeAnnotation = intersectionTypeAnnotation; exports.jSXAttribute = exports.jsxAttribute = jsxAttribute; exports.jSXClosingElement = exports.jsxClosingElement = jsxClosingElement; exports.jSXClosingFragment = exports.jsxClosingFragment = jsxClosingFragment; exports.jSXElement = exports.jsxElement = jsxElement; exports.jSXEmptyExpression = exports.jsxEmptyExpression = jsxEmptyExpression; exports.jSXExpressionContainer = exports.jsxExpressionContainer = jsxExpressionContainer; exports.jSXFragment = exports.jsxFragment = jsxFragment; exports.jSXIdentifier = exports.jsxIdentifier = jsxIdentifier; exports.jSXMemberExpression = exports.jsxMemberExpression = jsxMemberExpression; exports.jSXNamespacedName = exports.jsxNamespacedName = jsxNamespacedName; exports.jSXOpeningElement = exports.jsxOpeningElement = jsxOpeningElement; exports.jSXOpeningFragment = exports.jsxOpeningFragment = jsxOpeningFragment; exports.jSXSpreadAttribute = exports.jsxSpreadAttribute = jsxSpreadAttribute; exports.jSXSpreadChild = exports.jsxSpreadChild = jsxSpreadChild; exports.jSXText = exports.jsxText = jsxText; exports.labeledStatement = labeledStatement; exports.logicalExpression = logicalExpression; exports.memberExpression = memberExpression; exports.metaProperty = metaProperty; exports.mixedTypeAnnotation = mixedTypeAnnotation; exports.moduleExpression = moduleExpression; exports.newExpression = newExpression; exports.noop = noop; exports.nullLiteral = nullLiteral; exports.nullLiteralTypeAnnotation = nullLiteralTypeAnnotation; exports.nullableTypeAnnotation = nullableTypeAnnotation; exports.numberLiteral = NumberLiteral; exports.numberLiteralTypeAnnotation = numberLiteralTypeAnnotation; exports.numberTypeAnnotation = numberTypeAnnotation; exports.numericLiteral = numericLiteral; exports.objectExpression = objectExpression; exports.objectMethod = objectMethod; exports.objectPattern = objectPattern; exports.objectProperty = objectProperty; exports.objectTypeAnnotation = objectTypeAnnotation; exports.objectTypeCallProperty = objectTypeCallProperty; exports.objectTypeIndexer = objectTypeIndexer; exports.objectTypeInternalSlot = objectTypeInternalSlot; exports.objectTypeProperty = objectTypeProperty; exports.objectTypeSpreadProperty = objectTypeSpreadProperty; exports.opaqueType = opaqueType; exports.optionalCallExpression = optionalCallExpression; exports.optionalIndexedAccessType = optionalIndexedAccessType; exports.optionalMemberExpression = optionalMemberExpression; exports.parenthesizedExpression = parenthesizedExpression; exports.pipelineBareFunction = pipelineBareFunction; exports.pipelinePrimaryTopicReference = pipelinePrimaryTopicReference; exports.pipelineTopicExpression = pipelineTopicExpression; exports.placeholder = placeholder; exports.privateName = privateName; exports.program = program; exports.qualifiedTypeIdentifier = qualifiedTypeIdentifier; exports.recordExpression = recordExpression; exports.regExpLiteral = regExpLiteral; exports.regexLiteral = RegexLiteral; exports.restElement = restElement; exports.restProperty = RestProperty; exports.returnStatement = returnStatement; exports.sequenceExpression = sequenceExpression; exports.spreadElement = spreadElement; exports.spreadProperty = SpreadProperty; exports.staticBlock = staticBlock; exports.stringLiteral = stringLiteral; exports.stringLiteralTypeAnnotation = stringLiteralTypeAnnotation; exports.stringTypeAnnotation = stringTypeAnnotation; exports.super = _super; exports.switchCase = switchCase; exports.switchStatement = switchStatement; exports.symbolTypeAnnotation = symbolTypeAnnotation; exports.taggedTemplateExpression = taggedTemplateExpression; exports.templateElement = templateElement; exports.templateLiteral = templateLiteral; exports.thisExpression = thisExpression; exports.thisTypeAnnotation = thisTypeAnnotation; exports.throwStatement = throwStatement; exports.topicReference = topicReference; exports.tryStatement = tryStatement; exports.tSAnyKeyword = exports.tsAnyKeyword = tsAnyKeyword; exports.tSArrayType = exports.tsArrayType = tsArrayType; exports.tSAsExpression = exports.tsAsExpression = tsAsExpression; exports.tSBigIntKeyword = exports.tsBigIntKeyword = tsBigIntKeyword; exports.tSBooleanKeyword = exports.tsBooleanKeyword = tsBooleanKeyword; exports.tSCallSignatureDeclaration = exports.tsCallSignatureDeclaration = tsCallSignatureDeclaration; exports.tSConditionalType = exports.tsConditionalType = tsConditionalType; exports.tSConstructSignatureDeclaration = exports.tsConstructSignatureDeclaration = tsConstructSignatureDeclaration; exports.tSConstructorType = exports.tsConstructorType = tsConstructorType; exports.tSDeclareFunction = exports.tsDeclareFunction = tsDeclareFunction; exports.tSDeclareMethod = exports.tsDeclareMethod = tsDeclareMethod; exports.tSEnumBody = exports.tsEnumBody = tsEnumBody; exports.tSEnumDeclaration = exports.tsEnumDeclaration = tsEnumDeclaration; exports.tSEnumMember = exports.tsEnumMember = tsEnumMember; exports.tSExportAssignment = exports.tsExportAssignment = tsExportAssignment; exports.tSExpressionWithTypeArguments = exports.tsExpressionWithTypeArguments = tsExpressionWithTypeArguments; exports.tSExternalModuleReference = exports.tsExternalModuleReference = tsExternalModuleReference; exports.tSFunctionType = exports.tsFunctionType = tsFunctionType; exports.tSImportEqualsDeclaration = exports.tsImportEqualsDeclaration = tsImportEqualsDeclaration; exports.tSImportType = exports.tsImportType = tsImportType; exports.tSIndexSignature = exports.tsIndexSignature = tsIndexSignature; exports.tSIndexedAccessType = exports.tsIndexedAccessType = tsIndexedAccessType; exports.tSInferType = exports.tsInferType = tsInferType; exports.tSInstantiationExpression = exports.tsInstantiationExpression = tsInstantiationExpression; exports.tSInterfaceBody = exports.tsInterfaceBody = tsInterfaceBody; exports.tSInterfaceDeclaration = exports.tsInterfaceDeclaration = tsInterfaceDeclaration; exports.tSIntersectionType = exports.tsIntersectionType = tsIntersectionType; exports.tSIntrinsicKeyword = exports.tsIntrinsicKeyword = tsIntrinsicKeyword; exports.tSLiteralType = exports.tsLiteralType = tsLiteralType; exports.tSMappedType = exports.tsMappedType = tsMappedType; exports.tSMethodSignature = exports.tsMethodSignature = tsMethodSignature; exports.tSModuleBlock = exports.tsModuleBlock = tsModuleBlock; exports.tSModuleDeclaration = exports.tsModuleDeclaration = tsModuleDeclaration; exports.tSNamedTupleMember = exports.tsNamedTupleMember = tsNamedTupleMember; exports.tSNamespaceExportDeclaration = exports.tsNamespaceExportDeclaration = tsNamespaceExportDeclaration; exports.tSNeverKeyword = exports.tsNeverKeyword = tsNeverKeyword; exports.tSNonNullExpression = exports.tsNonNullExpression = tsNonNullExpression; exports.tSNullKeyword = exports.tsNullKeyword = tsNullKeyword; exports.tSNumberKeyword = exports.tsNumberKeyword = tsNumberKeyword; exports.tSObjectKeyword = exports.tsObjectKeyword = tsObjectKeyword; exports.tSOptionalType = exports.tsOptionalType = tsOptionalType; exports.tSParameterProperty = exports.tsParameterProperty = tsParameterProperty; exports.tSParenthesizedType = exports.tsParenthesizedType = tsParenthesizedType; exports.tSPropertySignature = exports.tsPropertySignature = tsPropertySignature; exports.tSQualifiedName = exports.tsQualifiedName = tsQualifiedName; exports.tSRestType = exports.tsRestType = tsRestType; exports.tSSatisfiesExpression = exports.tsSatisfiesExpression = tsSatisfiesExpression; exports.tSStringKeyword = exports.tsStringKeyword = tsStringKeyword; exports.tSSymbolKeyword = exports.tsSymbolKeyword = tsSymbolKeyword; exports.tSTemplateLiteralType = exports.tsTemplateLiteralType = tsTemplateLiteralType; exports.tSThisType = exports.tsThisType = tsThisType; exports.tSTupleType = exports.tsTupleType = tsTupleType; exports.tSTypeAliasDeclaration = exports.tsTypeAliasDeclaration = tsTypeAliasDeclaration; exports.tSTypeAnnotation = exports.tsTypeAnnotation = tsTypeAnnotation; exports.tSTypeAssertion = exports.tsTypeAssertion = tsTypeAssertion; exports.tSTypeLiteral = exports.tsTypeLiteral = tsTypeLiteral; exports.tSTypeOperator = exports.tsTypeOperator = tsTypeOperator; exports.tSTypeParameter = exports.tsTypeParameter = tsTypeParameter; exports.tSTypeParameterDeclaration = exports.tsTypeParameterDeclaration = tsTypeParameterDeclaration; exports.tSTypeParameterInstantiation = exports.tsTypeParameterInstantiation = tsTypeParameterInstantiation; exports.tSTypePredicate = exports.tsTypePredicate = tsTypePredicate; exports.tSTypeQuery = exports.tsTypeQuery = tsTypeQuery; exports.tSTypeReference = exports.tsTypeReference = tsTypeReference; exports.tSUndefinedKeyword = exports.tsUndefinedKeyword = tsUndefinedKeyword; exports.tSUnionType = exports.tsUnionType = tsUnionType; exports.tSUnknownKeyword = exports.tsUnknownKeyword = tsUnknownKeyword; exports.tSVoidKeyword = exports.tsVoidKeyword = tsVoidKeyword; exports.tupleExpression = tupleExpression; exports.tupleTypeAnnotation = tupleTypeAnnotation; exports.typeAlias = typeAlias; exports.typeAnnotation = typeAnnotation; exports.typeCastExpression = typeCastExpression; exports.typeParameter = typeParameter; exports.typeParameterDeclaration = typeParameterDeclaration; exports.typeParameterInstantiation = typeParameterInstantiation; exports.typeofTypeAnnotation = typeofTypeAnnotation; exports.unaryExpression = unaryExpression; exports.unionTypeAnnotation = unionTypeAnnotation; exports.updateExpression = updateExpression; exports.v8IntrinsicIdentifier = v8IntrinsicIdentifier; exports.variableDeclaration = variableDeclaration; exports.variableDeclarator = variableDeclarator; exports.variance = variance; exports.voidPattern = voidPattern; exports.voidTypeAnnotation = voidTypeAnnotation; exports.whileStatement = whileStatement; exports.withStatement = withStatement; exports.yieldExpression = yieldExpression; var _validate = require("../../validators/validate.js"); var _deprecationWarning = require("../../utils/deprecationWarning.js"); var utils = require("../../definitions/utils.js"); const { validateInternal: validate } = _validate; const { NODE_FIELDS } = utils; function bigIntLiteral(value) { if (typeof value === "bigint") { value = value.toString(); } const node = { type: "BigIntLiteral", value }; const defs = NODE_FIELDS.BigIntLiteral; validate(defs.value, node, "value", value); return node; } function arrayExpression(elements = []) { const node = { type: "ArrayExpression", elements }; const defs = NODE_FIELDS.ArrayExpression; validate(defs.elements, node, "elements", elements, 1); return node; } function assignmentExpression(operator, left, right) { const node = { type: "AssignmentExpression", operator, left, right }; const defs = NODE_FIELDS.AssignmentExpression; validate(defs.operator, node, "operator", operator); validate(defs.left, node, "left", left, 1); validate(defs.right, node, "right", right, 1); return node; } function binaryExpression(operator, left, right) { const node = { type: "BinaryExpression", operator, left, right }; const defs = NODE_FIELDS.BinaryExpression; validate(defs.operator, node, "operator", operator); validate(defs.left, node, "left", left, 1); validate(defs.right, node, "right", right, 1); return node; } function interpreterDirective(value) { const node = { type: "InterpreterDirective", value }; const defs = NODE_FIELDS.InterpreterDirective; validate(defs.value, node, "value", value); return node; } function directive(value) { const node = { type: "Directive", value }; const defs = NODE_FIELDS.Directive; validate(defs.value, node, "value", value, 1); return node; } function directiveLiteral(value) { const node = { type: "DirectiveLiteral", value }; const defs = NODE_FIELDS.DirectiveLiteral; validate(defs.value, node, "value", value); return node; } function blockStatement(body, directives = []) { const node = { type: "BlockStatement", body, directives }; const defs = NODE_FIELDS.BlockStatement; validate(defs.body, node, "body", body, 1); validate(defs.directives, node, "directives", directives, 1); return node; } function breakStatement(label = null) { const node = { type: "BreakStatement", label }; const defs = NODE_FIELDS.BreakStatement; validate(defs.label, node, "label", label, 1); return node; } function callExpression(callee, _arguments) { const node = { type: "CallExpression", callee, arguments: _arguments }; const defs = NODE_FIELDS.CallExpression; validate(defs.callee, node, "callee", callee, 1); validate(defs.arguments, node, "arguments", _arguments, 1); return node; } function catchClause(param = null, body) { const node = { type: "CatchClause", param, body }; const defs = NODE_FIELDS.CatchClause; validate(defs.param, node, "param", param, 1); validate(defs.body, node, "body", body, 1); return node; } function conditionalExpression(test, consequent, alternate) { const node = { type: "ConditionalExpression", test, consequent, alternate }; const defs = NODE_FIELDS.ConditionalExpression; validate(defs.test, node, "test", test, 1); validate(defs.consequent, node, "consequent", consequent, 1); validate(defs.alternate, node, "alternate", alternate, 1); return node; } function continueStatement(label = null) { const node = { type: "ContinueStatement", label }; const defs = NODE_FIELDS.ContinueStatement; validate(defs.label, node, "label", label, 1); return node; } function debuggerStatement() { return { type: "DebuggerStatement" }; } function doWhileStatement(test, body) { const node = { type: "DoWhileStatement", test, body }; const defs = NODE_FIELDS.DoWhileStatement; validate(defs.test, node, "test", test, 1); validate(defs.body, node, "body", body, 1); return node; } function emptyStatement() { return { type: "EmptyStatement" }; } function expressionStatement(expression) { const node = { type: "ExpressionStatement", expression }; const defs = NODE_FIELDS.ExpressionStatement; validate(defs.expression, node, "expression", expression, 1); return node; } function file(program, comments = null, tokens = null) { const node = { type: "File", program, comments, tokens }; const defs = NODE_FIELDS.File; validate(defs.program, node, "program", program, 1); validate(defs.comments, node, "comments", comments, 1); validate(defs.tokens, node, "tokens", tokens); return node; } function forInStatement(left, right, body) { const node = { type: "ForInStatement", left, right, body }; const defs = NODE_FIELDS.ForInStatement; validate(defs.left, node, "left", left, 1); validate(defs.right, node, "right", right, 1); validate(defs.body, node, "body", body, 1); return node; } function forStatement(init = null, test = null, update = null, body) { const node = { type: "ForStatement", init, test, update, body }; const defs = NODE_FIELDS.ForStatement; validate(defs.init, node, "init", init, 1); validate(defs.test, node, "test", test, 1); validate(defs.update, node, "update", update, 1); validate(defs.body, node, "body", body, 1); return node; } function functionDeclaration(id = null, params, body, generator = false, async = false) { const node = { type: "FunctionDeclaration", id, params, body, generator, async }; const defs = NODE_FIELDS.FunctionDeclaration; validate(defs.id, node, "id", id, 1); validate(defs.params, node, "params", params, 1); validate(defs.body, node, "body", body, 1); validate(defs.generator, node, "generator", generator); validate(defs.async, node, "async", async); return node; } function functionExpression(id = null, params, body, generator = false, async = false) { const node = { type: "FunctionExpression", id, params, body, generator, async }; const defs = NODE_FIELDS.FunctionExpression; validate(defs.id, node, "id", id, 1); validate(defs.params, node, "params", params, 1); validate(defs.body, node, "body", body, 1); validate(defs.generator, node, "generator", generator); validate(defs.async, node, "async", async); return node; } function identifier(name) { const node = { type: "Identifier", name }; const defs = NODE_FIELDS.Identifier; validate(defs.name, node, "name", name); return node; } function ifStatement(test, consequent, alternate = null) { const node = { type: "IfStatement", test, consequent, alternate }; const defs = NODE_FIELDS.IfStatement; validate(defs.test, node, "test", test, 1); validate(defs.consequent, node, "consequent", consequent, 1); validate(defs.alternate, node, "alternate", alternate, 1); return node; } function labeledStatement(label, body) { const node = { type: "LabeledStatement", label, body }; const defs = NODE_FIELDS.LabeledStatement; validate(defs.label, node, "label", label, 1); validate(defs.body, node, "body", body, 1); return node; } function stringLiteral(value) { const node = { type: "StringLiteral", value }; const defs = NODE_FIELDS.StringLiteral; validate(defs.value, node, "value", value); return node; } function numericLiteral(value) { const node = { type: "NumericLiteral", value }; const defs = NODE_FIELDS.NumericLiteral; validate(defs.value, node, "value", value); return node; } function nullLiteral() { return { type: "NullLiteral" }; } function booleanLiteral(value) { const node = { type: "BooleanLiteral", value }; const defs = NODE_FIELDS.BooleanLiteral; validate(defs.value, node, "value", value); return node; } function regExpLiteral(pattern, flags = "") { const node = { type: "RegExpLiteral", pattern, flags }; const defs = NODE_FIELDS.RegExpLiteral; validate(defs.pattern, node, "pattern", pattern); validate(defs.flags, node, "flags", flags); return node; } function logicalExpression(operator, left, right) { const node = { type: "LogicalExpression", operator, left, right }; const defs = NODE_FIELDS.LogicalExpression; validate(defs.operator, node, "operator", operator); validate(defs.left, node, "left", left, 1); validate(defs.right, node, "right", right, 1); return node; } function memberExpression(object, property, computed = false, optional = null) { const node = { type: "MemberExpression", object, property, computed, optional }; const defs = NODE_FIELDS.MemberExpression; validate(defs.object, node, "object", object, 1); validate(defs.property, node, "property", property, 1); validate(defs.computed, node, "computed", computed); validate(defs.optional, node, "optional", optional); return node; } function newExpression(callee, _arguments) { const node = { type: "NewExpression", callee, arguments: _arguments }; const defs = NODE_FIELDS.NewExpression; validate(defs.callee, node, "callee", callee, 1); validate(defs.arguments, node, "arguments", _arguments, 1); return node; } function program(body, directives = [], sourceType = "script", interpreter = null) { const node = { type: "Program", body, directives, sourceType, interpreter }; const defs = NODE_FIELDS.Program; validate(defs.body, node, "body", body, 1); validate(defs.directives, node, "directives", directives, 1); validate(defs.sourceType, node, "sourceType", sourceType); validate(defs.interpreter, node, "interpreter", interpreter, 1); return node; } function objectExpression(properties) { const node = { type: "ObjectExpression", properties }; const defs = NODE_FIELDS.ObjectExpression; validate(defs.properties, node, "properties", properties, 1); return node; } function objectMethod(kind = "method", key, params, body, computed = false, generator = false, async = false) { const node = { type: "ObjectMethod", kind, key, params, body, computed, generator, async }; const defs = NODE_FIELDS.ObjectMethod; validate(defs.kind, node, "kind", kind); validate(defs.key, node, "key", key, 1); validate(defs.params, node, "params", params, 1); validate(defs.body, node, "body", body, 1); validate(defs.computed, node, "computed", computed); validate(defs.generator, node, "generator", generator); validate(defs.async, node, "async", async); return node; } function objectProperty(key, value, computed = false, shorthand = false, decorators = null) { const node = { type: "ObjectProperty", key, value, computed, shorthand, decorators }; const defs = NODE_FIELDS.ObjectProperty; validate(defs.key, node, "key", key, 1); validate(defs.value, node, "value", value, 1); validate(defs.computed, node, "computed", computed); validate(defs.shorthand, node, "shorthand", shorthand); validate(defs.decorators, node, "decorators", decorators, 1); return node; } function restElement(argument) { const node = { type: "RestElement", argument }; const defs = NODE_FIELDS.RestElement; validate(defs.argument, node, "argument", argument, 1); return node; } function returnStatement(argument = null) { const node = { type: "ReturnStatement", argument }; const defs = NODE_FIELDS.ReturnStatement; validate(defs.argument, node, "argument", argument, 1); return node; } function sequenceExpression(expressions) { const node = { type: "SequenceExpression", expressions }; const defs = NODE_FIELDS.SequenceExpression; validate(defs.expressions, node, "expressions", expressions, 1); return node; } function parenthesizedExpression(expression) { const node = { type: "ParenthesizedExpression", expression }; const defs = NODE_FIELDS.ParenthesizedExpression; validate(defs.expression, node, "expression", expression, 1); return node; } function switchCase(test = null, consequent) { const node = { type: "SwitchCase", test, consequent }; const defs = NODE_FIELDS.SwitchCase; validate(defs.test, node, "test", test, 1); validate(defs.consequent, node, "consequent", consequent, 1); return node; } function switchStatement(discriminant, cases) { const node = { type: "SwitchStatement", discriminant, cases }; const defs = NODE_FIELDS.SwitchStatement; validate(defs.discriminant, node, "discriminant", discriminant, 1); validate(defs.cases, node, "cases", cases, 1); return node; } function thisExpression() { return { type: "ThisExpression" }; } function throwStatement(argument) { const node = { type: "ThrowStatement", argument }; const defs = NODE_FIELDS.ThrowStatement; validate(defs.argument, node, "argument", argument, 1); return node; } function tryStatement(block, handler = null, finalizer = null) { const node = { type: "TryStatement", block, handler, finalizer }; const defs = NODE_FIELDS.TryStatement; validate(defs.block, node, "block", block, 1); validate(defs.handler, node, "handler", handler, 1); validate(defs.finalizer, node, "finalizer", finalizer, 1); return node; } function unaryExpression(operator, argument, prefix = true) { const node = { type: "UnaryExpression", operator, argument, prefix }; const defs = NODE_FIELDS.UnaryExpression; validate(defs.operator, node, "operator", operator); validate(defs.argument, node, "argument", argument, 1); validate(defs.prefix, node, "prefix", prefix); return node; } function updateExpression(operator, argument, prefix = false) { const node = { type: "UpdateExpression", operator, argument, prefix }; const defs = NODE_FIELDS.UpdateExpression; validate(defs.operator, node, "operator", operator); validate(defs.argument, node, "argument", argument, 1); validate(defs.prefix, node, "prefix", prefix); return node; } function variableDeclaration(kind, declarations) { const node = { type: "VariableDeclaration", kind, declarations }; const defs = NODE_FIELDS.VariableDeclaration; validate(defs.kind, node, "kind", kind); validate(defs.declarations, node, "declarations", declarations, 1); return node; } function variableDeclarator(id, init = null) { const node = { type: "VariableDeclarator", id, init }; const defs = NODE_FIELDS.VariableDeclarator; validate(defs.id, node, "id", id, 1); validate(defs.init, node, "init", init, 1); return node; } function whileStatement(test, body) { const node = { type: "WhileStatement", test, body }; const defs = NODE_FIELDS.WhileStatement; validate(defs.test, node, "test", test, 1); validate(defs.body, node, "body", body, 1); return node; } function withStatement(object, body) { const node = { type: "WithStatement", object, body }; const defs = NODE_FIELDS.WithStatement; validate(defs.object, node, "object", object, 1); validate(defs.body, node, "body", body, 1); return node; } function assignmentPattern(left, right) { const node = { type: "AssignmentPattern", left, right }; const defs = NODE_FIELDS.AssignmentPattern; validate(defs.left, node, "left", left, 1); validate(defs.right, node, "right", right, 1); return node; } function arrayPattern(elements) { const node = { type: "ArrayPattern", elements }; const defs = NODE_FIELDS.ArrayPattern; validate(defs.elements, node, "elements", elements, 1); return node; } function arrowFunctionExpression(params, body, async = false) { const node = { type: "ArrowFunctionExpression", params, body, async, expression: null }; const defs = NODE_FIELDS.ArrowFunctionExpression; validate(defs.params, node, "params", params, 1); validate(defs.body, node, "body", body, 1); validate(defs.async, node, "async", async); return node; } function classBody(body) { const node = { type: "ClassBody", body }; const defs = NODE_FIELDS.ClassBody; validate(defs.body, node, "body", body, 1); return node; } function classExpression(id = null, superClass = null, body, decorators = null) { const node = { type: "ClassExpression", id, superClass, body, decorators }; const defs = NODE_FIELDS.ClassExpression; validate(defs.id, node, "id", id, 1); validate(defs.superClass, node, "superClass", superClass, 1); validate(defs.body, node, "body", body, 1); validate(defs.decorators, node, "decorators", decorators, 1); return node; } function classDeclaration(id = null, superClass = null, body, decorators = null) { const node = { type: "ClassDeclaration", id, superClass, body, decorators }; const defs = NODE_FIELDS.ClassDeclaration; validate(defs.id, node, "id", id, 1); validate(defs.superClass, node, "superClass", superClass, 1); validate(defs.body, node, "body", body, 1); validate(defs.decorators, node, "decorators", decorators, 1); return node; } function exportAllDeclaration(source) { const node = { type: "ExportAllDeclaration", source }; const defs = NODE_FIELDS.ExportAllDeclaration; validate(defs.source, node, "source", source, 1); return node; } function exportDefaultDeclaration(declaration) { const node = { type: "ExportDefaultDeclaration", declaration }; const defs = NODE_FIELDS.ExportDefaultDeclaration; validate(defs.declaration, node, "declaration", declaration, 1); return node; } function exportNamedDeclaration(declaration = null, specifiers = [], source = null) { const node = { type: "ExportNamedDeclaration", declaration, specifiers, source }; const defs = NODE_FIELDS.ExportNamedDeclaration; validate(defs.declaration, node, "declaration", declaration, 1); validate(defs.specifiers, node, "specifiers", specifiers, 1); validate(defs.source, node, "source", source, 1); return node; } function exportSpecifier(local, exported) { const node = { type: "ExportSpecifier", local, exported }; const defs = NODE_FIELDS.ExportSpecifier; validate(defs.local, node, "local", local, 1); validate(defs.exported, node, "exported", exported, 1); return node; } function forOfStatement(left, right, body, _await = false) { const node = { type: "ForOfStatement", left, right, body, await: _await }; const defs = NODE_FIELDS.ForOfStatement; validate(defs.left, node, "left", left, 1); validate(defs.right, node, "right", right, 1); validate(defs.body, node, "body", body, 1); validate(defs.await, node, "await", _await); return node; } function importDeclaration(specifiers, source) { const node = { type: "ImportDeclaration", specifiers, source }; const defs = NODE_FIELDS.ImportDeclaration; validate(defs.specifiers, node, "specifiers", specifiers, 1); validate(defs.source, node, "source", source, 1); return node; } function importDefaultSpecifier(local) { const node = { type: "ImportDefaultSpecifier", local }; const defs = NODE_FIELDS.ImportDefaultSpecifier; validate(defs.local, node, "local", local, 1); return node; } function importNamespaceSpecifier(local) { const node = { type: "ImportNamespaceSpecifier", local }; const defs = NODE_FIELDS.ImportNamespaceSpecifier; validate(defs.local, node, "local", local, 1); return node; } function importSpecifier(local, imported) { const node = { type: "ImportSpecifier", local, imported }; const defs = NODE_FIELDS.ImportSpecifier; validate(defs.local, node, "local", local, 1); validate(defs.imported, node, "imported", imported, 1); return node; } function importExpression(source, options = null) { const node = { type: "ImportExpression", source, options }; const defs = NODE_FIELDS.ImportExpression; validate(defs.source, node, "source", source, 1); validate(defs.options, node, "options", options, 1); return node; } function metaProperty(meta, property) { const node = { type: "MetaProperty", meta, property }; const defs = NODE_FIELDS.MetaProperty; validate(defs.meta, node, "meta", meta, 1); validate(defs.property, node, "property", property, 1); return node; } function classMethod(kind = "method", key, params, body, computed = false, _static = false, generator = false, async = false) { const node = { type: "ClassMethod", kind, key, params, body, computed, static: _static, generator, async }; const defs = NODE_FIELDS.ClassMethod; validate(defs.kind, node, "kind", kind); validate(defs.key, node, "key", key, 1); validate(defs.params, node, "params", params, 1); validate(defs.body, node, "body", body, 1); validate(defs.computed, node, "computed", computed); validate(defs.static, node, "static", _static); validate(defs.generator, node, "generator", generator); validate(defs.async, node, "async", async); return node; } function objectPattern(properties) { const node = { type: "ObjectPattern", properties }; const defs = NODE_FIELDS.ObjectPattern; validate(defs.properties, node, "properties", properties, 1); return node; } function spreadElement(argument) { const node = { type: "SpreadElement", argument }; const defs = NODE_FIELDS.SpreadElement; validate(defs.argument, node, "argument", argument, 1); return node; } function _super() { return { type: "Super" }; } function taggedTemplateExpression(tag, quasi) { const node = { type: "TaggedTemplateExpression", tag, quasi }; const defs = NODE_FIELDS.TaggedTemplateExpression; validate(defs.tag, node, "tag", tag, 1); validate(defs.quasi, node, "quasi", quasi, 1); return node; } function templateElement(value, tail = false) { const node = { type: "TemplateElement", value, tail }; const defs = NODE_FIELDS.TemplateElement; validate(defs.value, node, "value", value); validate(defs.tail, node, "tail", tail); return node; } function templateLiteral(quasis, expressions) { const node = { type: "TemplateLiteral", quasis, expressions }; const defs = NODE_FIELDS.TemplateLiteral; validate(defs.quasis, node, "quasis", quasis, 1); validate(defs.expressions, node, "expressions", expressions, 1); return node; } function yieldExpression(argument = null, delegate = false) { const node = { type: "YieldExpression", argument, delegate }; const defs = NODE_FIELDS.YieldExpression; validate(defs.argument, node, "argument", argument, 1); validate(defs.delegate, node, "delegate", delegate); return node; } function awaitExpression(argument) { const node = { type: "AwaitExpression", argument }; const defs = NODE_FIELDS.AwaitExpression; validate(defs.argument, node, "argument", argument, 1); return node; } function _import() { return { type: "Import" }; } function exportNamespaceSpecifier(exported) { const node = { type: "ExportNamespaceSpecifier", exported }; const defs = NODE_FIELDS.ExportNamespaceSpecifier; validate(defs.exported, node, "exported", exported, 1); return node; } function optionalMemberExpression(object, property, computed = false, optional) { const node = { type: "OptionalMemberExpression", object, property, computed, optional }; const defs = NODE_FIELDS.OptionalMemberExpression; validate(defs.object, node, "object", object, 1); validate(defs.property, node, "property", property, 1); validate(defs.computed, node, "computed", computed); validate(defs.optional, node, "optional", optional); return node; } function optionalCallExpression(callee, _arguments, optional) { const node = { type: "OptionalCallExpression", callee, arguments: _arguments, optional }; const defs = NODE_FIELDS.OptionalCallExpression; validate(defs.callee, node, "callee", callee, 1); validate(defs.arguments, node, "arguments", _arguments, 1); validate(defs.optional, node, "optional", optional); return node; } function classProperty(key, value = null, typeAnnotation = null, decorators = null, computed = false, _static = false) { const node = { type: "ClassProperty", key, value, typeAnnotation, decorators, computed, static: _static }; const defs = NODE_FIELDS.ClassProperty; validate(defs.key, node, "key", key, 1); validate(defs.value, node, "value", value, 1); validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); validate(defs.decorators, node, "decorators", decorators, 1); validate(defs.computed, node, "computed", computed); validate(defs.static, node, "static", _static); return node; } function classAccessorProperty(key, value = null, typeAnnotation = null, decorators = null, computed = false, _static = false) { const node = { type: "ClassAccessorProperty", key, value, typeAnnotation, decorators, computed, static: _static }; const defs = NODE_FIELDS.ClassAccessorProperty; validate(defs.key, node, "key", key, 1); validate(defs.value, node, "value", value, 1); validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); validate(defs.decorators, node, "decorators", decorators, 1); validate(defs.computed, node, "computed", computed); validate(defs.static, node, "static", _static); return node; } function classPrivateProperty(key, value = null, decorators = null, _static = false) { const node = { type: "ClassPrivateProperty", key, value, decorators, static: _static }; const defs = NODE_FIELDS.ClassPrivateProperty; validate(defs.key, node, "key", key, 1); validate(defs.value, node, "value", value, 1); validate(defs.decorators, node, "decorators", decorators, 1); validate(defs.static, node, "static", _static); return node; } function classPrivateMethod(kind = "method", key, params, body, _static = false) { const node = { type: "ClassPrivateMethod", kind, key, params, body, static: _static }; const defs = NODE_FIELDS.ClassPrivateMethod; validate(defs.kind, node, "kind", kind); validate(defs.key, node, "key", key, 1); validate(defs.params, node, "params", params, 1); validate(defs.body, node, "body", body, 1); validate(defs.static, node, "static", _static); return node; } function privateName(id) { const node = { type: "PrivateName", id }; const defs = NODE_FIELDS.PrivateName; validate(defs.id, node, "id", id, 1); return node; } function staticBlock(body) { const node = { type: "StaticBlock", body }; const defs = NODE_FIELDS.StaticBlock; validate(defs.body, node, "body", body, 1); return node; } function importAttribute(key, value) { const node = { type: "ImportAttribute", key, value }; const defs = NODE_FIELDS.ImportAttribute; validate(defs.key, node, "key", key, 1); validate(defs.value, node, "value", value, 1); return node; } function anyTypeAnnotation() { return { type: "AnyTypeAnnotation" }; } function arrayTypeAnnotation(elementType) { const node = { type: "ArrayTypeAnnotation", elementType }; const defs = NODE_FIELDS.ArrayTypeAnnotation; validate(defs.elementType, node, "elementType", elementType, 1); return node; } function booleanTypeAnnotation() { return { type: "BooleanTypeAnnotation" }; } function booleanLiteralTypeAnnotation(value) { const node = { type: "BooleanLiteralTypeAnnotation", value }; const defs = NODE_FIELDS.BooleanLiteralTypeAnnotation; validate(defs.value, node, "value", value); return node; } function nullLiteralTypeAnnotation() { return { type: "NullLiteralTypeAnnotation" }; } function classImplements(id, typeParameters = null) { const node = { type: "ClassImplements", id, typeParameters }; const defs = NODE_FIELDS.ClassImplements; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); return node; } function declareClass(id, typeParameters = null, _extends = null, body) { const node = { type: "DeclareClass", id, typeParameters, extends: _extends, body }; const defs = NODE_FIELDS.DeclareClass; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); validate(defs.extends, node, "extends", _extends, 1); validate(defs.body, node, "body", body, 1); return node; } function declareFunction(id) { const node = { type: "DeclareFunction", id }; const defs = NODE_FIELDS.DeclareFunction; validate(defs.id, node, "id", id, 1); return node; } function declareInterface(id, typeParameters = null, _extends = null, body) { const node = { type: "DeclareInterface", id, typeParameters, extends: _extends, body }; const defs = NODE_FIELDS.DeclareInterface; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); validate(defs.extends, node, "extends", _extends, 1); validate(defs.body, node, "body", body, 1); return node; } function declareModule(id, body, kind = null) { const node = { type: "DeclareModule", id, body, kind }; const defs = NODE_FIELDS.DeclareModule; validate(defs.id, node, "id", id, 1); validate(defs.body, node, "body", body, 1); validate(defs.kind, node, "kind", kind); return node; } function declareModuleExports(typeAnnotation) { const node = { type: "DeclareModuleExports", typeAnnotation }; const defs = NODE_FIELDS.DeclareModuleExports; validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); return node; } function declareTypeAlias(id, typeParameters = null, right) { const node = { type: "DeclareTypeAlias", id, typeParameters, right }; const defs = NODE_FIELDS.DeclareTypeAlias; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); validate(defs.right, node, "right", right, 1); return node; } function declareOpaqueType(id, typeParameters = null, supertype = null) { const node = { type: "DeclareOpaqueType", id, typeParameters, supertype }; const defs = NODE_FIELDS.DeclareOpaqueType; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); validate(defs.supertype, node, "supertype", supertype, 1); return node; } function declareVariable(id) { const node = { type: "DeclareVariable", id }; const defs = NODE_FIELDS.DeclareVariable; validate(defs.id, node, "id", id, 1); return node; } function declareExportDeclaration(declaration = null, specifiers = null, source = null, attributes = null) { const node = { type: "DeclareExportDeclaration", declaration, specifiers, source, attributes }; const defs = NODE_FIELDS.DeclareExportDeclaration; validate(defs.declaration, node, "declaration", declaration, 1); validate(defs.specifiers, node, "specifiers", specifiers, 1); validate(defs.source, node, "source", source, 1); validate(defs.attributes, node, "attributes", attributes, 1); return node; } function declareExportAllDeclaration(source, attributes = null) { const node = { type: "DeclareExportAllDeclaration", source, attributes }; const defs = NODE_FIELDS.DeclareExportAllDeclaration; validate(defs.source, node, "source", source, 1); validate(defs.attributes, node, "attributes", attributes, 1); return node; } function declaredPredicate(value) { const node = { type: "DeclaredPredicate", value }; const defs = NODE_FIELDS.DeclaredPredicate; validate(defs.value, node, "value", value, 1); return node; } function existsTypeAnnotation() { return { type: "ExistsTypeAnnotation" }; } function functionTypeAnnotation(typeParameters = null, params, rest = null, returnType) { const node = { type: "FunctionTypeAnnotation", typeParameters, params, rest, returnType }; const defs = NODE_FIELDS.FunctionTypeAnnotation; validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); validate(defs.params, node, "params", params, 1); validate(defs.rest, node, "rest", rest, 1); validate(defs.returnType, node, "returnType", returnType, 1); return node; } function functionTypeParam(name = null, typeAnnotation) { const node = { type: "FunctionTypeParam", name, typeAnnotation }; const defs = NODE_FIELDS.FunctionTypeParam; validate(defs.name, node, "name", name, 1); validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); return node; } function genericTypeAnnotation(id, typeParameters = null) { const node = { type: "GenericTypeAnnotation", id, typeParameters }; const defs = NODE_FIELDS.GenericTypeAnnotation; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); return node; } function inferredPredicate() { return { type: "InferredPredicate" }; } function interfaceExtends(id, typeParameters = null) { const node = { type: "InterfaceExtends", id, typeParameters }; const defs = NODE_FIELDS.InterfaceExtends; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); return node; } function interfaceDeclaration(id, typeParameters = null, _extends = null, body) { const node = { type: "InterfaceDeclaration", id, typeParameters, extends: _extends, body }; const defs = NODE_FIELDS.InterfaceDeclaration; validate(defs.id, node, "id", id, 1); validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); validate(defs.extends, node, "extends", _extends, 1); validate(defs.body, node, "body", body, 1); return node; } function interfaceTypeAnnotation(_extends = null, body) { const node = { type: "InterfaceTypeAnnotation", extends: _extends, body }; const defs = NODE_FIELDS.InterfaceTypeAnnotation; validate(defs.extends, node, "extends", _extends, 1); validate(defs.body, node, "body", body, 1); return node; } function intersectionTypeAnnotation(types) { const node = { type: "IntersectionTypeAnnotation", types }; const defs = NODE_FIELDS.IntersectionTypeAnnotation; validate(defs.types, node, "types", types, 1); return node; } function mixedTypeAnnotation() { return { type: "MixedTypeAnnotation" }; } function emptyTypeAnnotation() { return { type: "EmptyTypeAnnotation" }; } function nullableTypeAnnotation(typeAnnotation) { const node = { type: "NullableTypeAnnotation", typeAnnotation }; const defs = NODE_FIELDS.NullableTypeAnnotation; validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); return node; } function numberLiteralTypeAnnotation(value) { const node = { type: "NumberLiteralTypeAnnotation", value }; const defs = NODE_FIELDS.NumberLiteralTypeAnnotation; validate(defs.value, node, "value", value); return node; } function numberTypeAnnotation() { return { type: "NumberTypeAnnotation" }; } function objectTypeAnnotation(properties, indexers = [], callProperties = [], internalSlots = [], exact = false) { const node = { type: "ObjectTypeAnnotation", properties, indexers, callProperties,