| | |
| | | |
| | | var _is = require("../validators/is"); |
| | | |
| | | const defineType = (0, _utils.defineAliasedType)("TypeScript"); |
| | | const bool = (0, _utils.assertValueType)("boolean"); |
| | | const tSFunctionTypeAnnotationCommon = { |
| | | returnType: { |
| | |
| | | optional: true |
| | | } |
| | | }; |
| | | (0, _utils.default)("TSParameterProperty", { |
| | | defineType("TSParameterProperty", { |
| | | aliases: ["LVal"], |
| | | visitor: ["parameter"], |
| | | fields: { |
| | |
| | | } |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSDeclareFunction", { |
| | | defineType("TSDeclareFunction", { |
| | | aliases: ["Statement", "Declaration"], |
| | | visitor: ["id", "typeParameters", "params", "returnType"], |
| | | fields: Object.assign({}, _core.functionDeclarationCommon, tSFunctionTypeAnnotationCommon) |
| | | }); |
| | | (0, _utils.default)("TSDeclareMethod", { |
| | | defineType("TSDeclareMethod", { |
| | | visitor: ["decorators", "key", "typeParameters", "params", "returnType"], |
| | | fields: Object.assign({}, _core.classMethodOrDeclareMethodCommon, tSFunctionTypeAnnotationCommon) |
| | | }); |
| | | (0, _utils.default)("TSQualifiedName", { |
| | | defineType("TSQualifiedName", { |
| | | aliases: ["TSEntityName"], |
| | | visitor: ["left", "right"], |
| | | fields: { |
| | |
| | | }); |
| | | const signatureDeclarationCommon = { |
| | | typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), |
| | | parameters: (0, _utils.validateArrayOfType)(["Identifier", "RestElement"]), |
| | | typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation") |
| | | ["parameters"]: (0, _utils.validateArrayOfType)(["Identifier", "RestElement"]), |
| | | ["typeAnnotation"]: (0, _utils.validateOptionalType)("TSTypeAnnotation") |
| | | }; |
| | | const callConstructSignatureDeclaration = { |
| | | aliases: ["TSTypeElement"], |
| | | visitor: ["typeParameters", "parameters", "typeAnnotation"], |
| | | fields: signatureDeclarationCommon |
| | | }; |
| | | (0, _utils.default)("TSCallSignatureDeclaration", callConstructSignatureDeclaration); |
| | | (0, _utils.default)("TSConstructSignatureDeclaration", callConstructSignatureDeclaration); |
| | | defineType("TSCallSignatureDeclaration", callConstructSignatureDeclaration); |
| | | defineType("TSConstructSignatureDeclaration", callConstructSignatureDeclaration); |
| | | const namedTypeElementCommon = { |
| | | key: (0, _utils.validateType)("Expression"), |
| | | computed: (0, _utils.validate)(bool), |
| | | optional: (0, _utils.validateOptional)(bool) |
| | | }; |
| | | (0, _utils.default)("TSPropertySignature", { |
| | | defineType("TSPropertySignature", { |
| | | aliases: ["TSTypeElement"], |
| | | visitor: ["key", "typeAnnotation", "initializer"], |
| | | fields: Object.assign({}, namedTypeElementCommon, { |
| | |
| | | } |
| | | }) |
| | | }); |
| | | (0, _utils.default)("TSMethodSignature", { |
| | | defineType("TSMethodSignature", { |
| | | aliases: ["TSTypeElement"], |
| | | visitor: ["key", "typeParameters", "parameters", "typeAnnotation"], |
| | | fields: Object.assign({}, signatureDeclarationCommon, namedTypeElementCommon, { |
| | |
| | | } |
| | | }) |
| | | }); |
| | | (0, _utils.default)("TSIndexSignature", { |
| | | defineType("TSIndexSignature", { |
| | | aliases: ["TSTypeElement"], |
| | | visitor: ["parameters", "typeAnnotation"], |
| | | fields: { |
| | |
| | | const tsKeywordTypes = ["TSAnyKeyword", "TSBooleanKeyword", "TSBigIntKeyword", "TSIntrinsicKeyword", "TSNeverKeyword", "TSNullKeyword", "TSNumberKeyword", "TSObjectKeyword", "TSStringKeyword", "TSSymbolKeyword", "TSUndefinedKeyword", "TSUnknownKeyword", "TSVoidKeyword"]; |
| | | |
| | | for (const type of tsKeywordTypes) { |
| | | (0, _utils.default)(type, { |
| | | defineType(type, { |
| | | aliases: ["TSType", "TSBaseType"], |
| | | visitor: [], |
| | | fields: {} |
| | | }); |
| | | } |
| | | |
| | | (0, _utils.default)("TSThisType", { |
| | | defineType("TSThisType", { |
| | | aliases: ["TSType", "TSBaseType"], |
| | | visitor: [], |
| | | fields: {} |
| | |
| | | aliases: ["TSType"], |
| | | visitor: ["typeParameters", "parameters", "typeAnnotation"] |
| | | }; |
| | | (0, _utils.default)("TSFunctionType", Object.assign({}, fnOrCtrBase, { |
| | | defineType("TSFunctionType", Object.assign({}, fnOrCtrBase, { |
| | | fields: signatureDeclarationCommon |
| | | })); |
| | | (0, _utils.default)("TSConstructorType", Object.assign({}, fnOrCtrBase, { |
| | | defineType("TSConstructorType", Object.assign({}, fnOrCtrBase, { |
| | | fields: Object.assign({}, signatureDeclarationCommon, { |
| | | abstract: (0, _utils.validateOptional)(bool) |
| | | }) |
| | | })); |
| | | (0, _utils.default)("TSTypeReference", { |
| | | defineType("TSTypeReference", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeName", "typeParameters"], |
| | | fields: { |
| | |
| | | typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypePredicate", { |
| | | defineType("TSTypePredicate", { |
| | | aliases: ["TSType"], |
| | | visitor: ["parameterName", "typeAnnotation"], |
| | | builder: ["parameterName", "typeAnnotation", "asserts"], |
| | |
| | | asserts: (0, _utils.validateOptional)(bool) |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeQuery", { |
| | | defineType("TSTypeQuery", { |
| | | aliases: ["TSType"], |
| | | visitor: ["exprName"], |
| | | fields: { |
| | | exprName: (0, _utils.validateType)(["TSEntityName", "TSImportType"]) |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeLiteral", { |
| | | defineType("TSTypeLiteral", { |
| | | aliases: ["TSType"], |
| | | visitor: ["members"], |
| | | fields: { |
| | | members: (0, _utils.validateArrayOfType)("TSTypeElement") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSArrayType", { |
| | | defineType("TSArrayType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["elementType"], |
| | | fields: { |
| | | elementType: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTupleType", { |
| | | defineType("TSTupleType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["elementTypes"], |
| | | fields: { |
| | | elementTypes: (0, _utils.validateArrayOfType)(["TSType", "TSNamedTupleMember"]) |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSOptionalType", { |
| | | defineType("TSOptionalType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeAnnotation"], |
| | | fields: { |
| | | typeAnnotation: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSRestType", { |
| | | defineType("TSRestType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeAnnotation"], |
| | | fields: { |
| | | typeAnnotation: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSNamedTupleMember", { |
| | | defineType("TSNamedTupleMember", { |
| | | visitor: ["label", "elementType"], |
| | | builder: ["label", "elementType", "optional"], |
| | | fields: { |
| | |
| | | types: (0, _utils.validateArrayOfType)("TSType") |
| | | } |
| | | }; |
| | | (0, _utils.default)("TSUnionType", unionOrIntersection); |
| | | (0, _utils.default)("TSIntersectionType", unionOrIntersection); |
| | | (0, _utils.default)("TSConditionalType", { |
| | | defineType("TSUnionType", unionOrIntersection); |
| | | defineType("TSIntersectionType", unionOrIntersection); |
| | | defineType("TSConditionalType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["checkType", "extendsType", "trueType", "falseType"], |
| | | fields: { |
| | |
| | | falseType: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSInferType", { |
| | | defineType("TSInferType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeParameter"], |
| | | fields: { |
| | | typeParameter: (0, _utils.validateType)("TSTypeParameter") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSParenthesizedType", { |
| | | defineType("TSParenthesizedType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeAnnotation"], |
| | | fields: { |
| | | typeAnnotation: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeOperator", { |
| | | defineType("TSTypeOperator", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeAnnotation"], |
| | | fields: { |
| | |
| | | typeAnnotation: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSIndexedAccessType", { |
| | | defineType("TSIndexedAccessType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["objectType", "indexType"], |
| | | fields: { |
| | |
| | | indexType: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSMappedType", { |
| | | defineType("TSMappedType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["typeParameter", "typeAnnotation", "nameType"], |
| | | fields: { |
| | |
| | | nameType: (0, _utils.validateOptionalType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSLiteralType", { |
| | | defineType("TSLiteralType", { |
| | | aliases: ["TSType", "TSBaseType"], |
| | | visitor: ["literal"], |
| | | fields: { |
| | |
| | | } |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSExpressionWithTypeArguments", { |
| | | defineType("TSExpressionWithTypeArguments", { |
| | | aliases: ["TSType"], |
| | | visitor: ["expression", "typeParameters"], |
| | | fields: { |
| | |
| | | typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSInterfaceDeclaration", { |
| | | defineType("TSInterfaceDeclaration", { |
| | | aliases: ["Statement", "Declaration"], |
| | | visitor: ["id", "typeParameters", "extends", "body"], |
| | | fields: { |
| | |
| | | body: (0, _utils.validateType)("TSInterfaceBody") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSInterfaceBody", { |
| | | defineType("TSInterfaceBody", { |
| | | visitor: ["body"], |
| | | fields: { |
| | | body: (0, _utils.validateArrayOfType)("TSTypeElement") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeAliasDeclaration", { |
| | | defineType("TSTypeAliasDeclaration", { |
| | | aliases: ["Statement", "Declaration"], |
| | | visitor: ["id", "typeParameters", "typeAnnotation"], |
| | | fields: { |
| | |
| | | typeAnnotation: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSAsExpression", { |
| | | aliases: ["Expression"], |
| | | defineType("TSAsExpression", { |
| | | aliases: ["Expression", "LVal", "PatternLike"], |
| | | visitor: ["expression", "typeAnnotation"], |
| | | fields: { |
| | | expression: (0, _utils.validateType)("Expression"), |
| | | typeAnnotation: (0, _utils.validateType)("TSType") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeAssertion", { |
| | | aliases: ["Expression"], |
| | | defineType("TSTypeAssertion", { |
| | | aliases: ["Expression", "LVal", "PatternLike"], |
| | | visitor: ["typeAnnotation", "expression"], |
| | | fields: { |
| | | typeAnnotation: (0, _utils.validateType)("TSType"), |
| | | expression: (0, _utils.validateType)("Expression") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSEnumDeclaration", { |
| | | defineType("TSEnumDeclaration", { |
| | | aliases: ["Statement", "Declaration"], |
| | | visitor: ["id", "members"], |
| | | fields: { |
| | |
| | | initializer: (0, _utils.validateOptionalType)("Expression") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSEnumMember", { |
| | | defineType("TSEnumMember", { |
| | | visitor: ["id", "initializer"], |
| | | fields: { |
| | | id: (0, _utils.validateType)(["Identifier", "StringLiteral"]), |
| | | initializer: (0, _utils.validateOptionalType)("Expression") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSModuleDeclaration", { |
| | | defineType("TSModuleDeclaration", { |
| | | aliases: ["Statement", "Declaration"], |
| | | visitor: ["id", "body"], |
| | | fields: { |
| | |
| | | body: (0, _utils.validateType)(["TSModuleBlock", "TSModuleDeclaration"]) |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSModuleBlock", { |
| | | defineType("TSModuleBlock", { |
| | | aliases: ["Scopable", "Block", "BlockParent"], |
| | | visitor: ["body"], |
| | | fields: { |
| | | body: (0, _utils.validateArrayOfType)("Statement") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSImportType", { |
| | | defineType("TSImportType", { |
| | | aliases: ["TSType"], |
| | | visitor: ["argument", "qualifier", "typeParameters"], |
| | | fields: { |
| | |
| | | typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSImportEqualsDeclaration", { |
| | | defineType("TSImportEqualsDeclaration", { |
| | | aliases: ["Statement"], |
| | | visitor: ["id", "moduleReference"], |
| | | fields: { |
| | |
| | | } |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSExternalModuleReference", { |
| | | defineType("TSExternalModuleReference", { |
| | | visitor: ["expression"], |
| | | fields: { |
| | | expression: (0, _utils.validateType)("StringLiteral") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSNonNullExpression", { |
| | | aliases: ["Expression"], |
| | | defineType("TSNonNullExpression", { |
| | | aliases: ["Expression", "LVal", "PatternLike"], |
| | | visitor: ["expression"], |
| | | fields: { |
| | | expression: (0, _utils.validateType)("Expression") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSExportAssignment", { |
| | | defineType("TSExportAssignment", { |
| | | aliases: ["Statement"], |
| | | visitor: ["expression"], |
| | | fields: { |
| | | expression: (0, _utils.validateType)("Expression") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSNamespaceExportDeclaration", { |
| | | defineType("TSNamespaceExportDeclaration", { |
| | | aliases: ["Statement"], |
| | | visitor: ["id"], |
| | | fields: { |
| | | id: (0, _utils.validateType)("Identifier") |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeAnnotation", { |
| | | defineType("TSTypeAnnotation", { |
| | | visitor: ["typeAnnotation"], |
| | | fields: { |
| | | typeAnnotation: { |
| | |
| | | } |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeParameterInstantiation", { |
| | | defineType("TSTypeParameterInstantiation", { |
| | | visitor: ["params"], |
| | | fields: { |
| | | params: { |
| | |
| | | } |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeParameterDeclaration", { |
| | | defineType("TSTypeParameterDeclaration", { |
| | | visitor: ["params"], |
| | | fields: { |
| | | params: { |
| | |
| | | } |
| | | } |
| | | }); |
| | | (0, _utils.default)("TSTypeParameter", { |
| | | defineType("TSTypeParameter", { |
| | | builder: ["constraint", "default", "name"], |
| | | visitor: ["constraint", "default"], |
| | | fields: { |