123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.TSTypeAnnotation = TSTypeAnnotation;
- exports.TSTypeParameterDeclaration = exports.TSTypeParameterInstantiation = TSTypeParameterInstantiation;
- exports.TSTypeParameter = TSTypeParameter;
- exports.TSParameterProperty = TSParameterProperty;
- exports.TSDeclareFunction = TSDeclareFunction;
- exports.TSDeclareMethod = TSDeclareMethod;
- exports.TSQualifiedName = TSQualifiedName;
- exports.TSCallSignatureDeclaration = TSCallSignatureDeclaration;
- exports.TSConstructSignatureDeclaration = TSConstructSignatureDeclaration;
- exports.TSPropertySignature = TSPropertySignature;
- exports.tsPrintPropertyOrMethodName = tsPrintPropertyOrMethodName;
- exports.TSMethodSignature = TSMethodSignature;
- exports.TSIndexSignature = TSIndexSignature;
- exports.TSAnyKeyword = TSAnyKeyword;
- exports.TSBigIntKeyword = TSBigIntKeyword;
- exports.TSUnknownKeyword = TSUnknownKeyword;
- exports.TSNumberKeyword = TSNumberKeyword;
- exports.TSObjectKeyword = TSObjectKeyword;
- exports.TSBooleanKeyword = TSBooleanKeyword;
- exports.TSStringKeyword = TSStringKeyword;
- exports.TSSymbolKeyword = TSSymbolKeyword;
- exports.TSVoidKeyword = TSVoidKeyword;
- exports.TSUndefinedKeyword = TSUndefinedKeyword;
- exports.TSNullKeyword = TSNullKeyword;
- exports.TSNeverKeyword = TSNeverKeyword;
- exports.TSIntrinsicKeyword = TSIntrinsicKeyword;
- exports.TSThisType = TSThisType;
- exports.TSFunctionType = TSFunctionType;
- exports.TSConstructorType = TSConstructorType;
- exports.tsPrintFunctionOrConstructorType = tsPrintFunctionOrConstructorType;
- exports.TSTypeReference = TSTypeReference;
- exports.TSTypePredicate = TSTypePredicate;
- exports.TSTypeQuery = TSTypeQuery;
- exports.TSTypeLiteral = TSTypeLiteral;
- exports.tsPrintTypeLiteralOrInterfaceBody = tsPrintTypeLiteralOrInterfaceBody;
- exports.tsPrintBraced = tsPrintBraced;
- exports.TSArrayType = TSArrayType;
- exports.TSTupleType = TSTupleType;
- exports.TSOptionalType = TSOptionalType;
- exports.TSRestType = TSRestType;
- exports.TSNamedTupleMember = TSNamedTupleMember;
- exports.TSUnionType = TSUnionType;
- exports.TSIntersectionType = TSIntersectionType;
- exports.tsPrintUnionOrIntersectionType = tsPrintUnionOrIntersectionType;
- exports.TSConditionalType = TSConditionalType;
- exports.TSInferType = TSInferType;
- exports.TSParenthesizedType = TSParenthesizedType;
- exports.TSTypeOperator = TSTypeOperator;
- exports.TSIndexedAccessType = TSIndexedAccessType;
- exports.TSMappedType = TSMappedType;
- exports.TSLiteralType = TSLiteralType;
- exports.TSExpressionWithTypeArguments = TSExpressionWithTypeArguments;
- exports.TSInterfaceDeclaration = TSInterfaceDeclaration;
- exports.TSInterfaceBody = TSInterfaceBody;
- exports.TSTypeAliasDeclaration = TSTypeAliasDeclaration;
- exports.TSAsExpression = TSAsExpression;
- exports.TSTypeAssertion = TSTypeAssertion;
- exports.TSEnumDeclaration = TSEnumDeclaration;
- exports.TSEnumMember = TSEnumMember;
- exports.TSModuleDeclaration = TSModuleDeclaration;
- exports.TSModuleBlock = TSModuleBlock;
- exports.TSImportType = TSImportType;
- exports.TSImportEqualsDeclaration = TSImportEqualsDeclaration;
- exports.TSExternalModuleReference = TSExternalModuleReference;
- exports.TSNonNullExpression = TSNonNullExpression;
- exports.TSExportAssignment = TSExportAssignment;
- exports.TSNamespaceExportDeclaration = TSNamespaceExportDeclaration;
- exports.tsPrintSignatureDeclarationBase = tsPrintSignatureDeclarationBase;
- exports.tsPrintClassMemberModifiers = tsPrintClassMemberModifiers;
-
- var t = require("@babel/types");
-
- function TSTypeAnnotation(node) {
- this.token(":");
- this.space();
- if (node.optional) this.token("?");
- this.print(node.typeAnnotation, node);
- }
-
- function TSTypeParameterInstantiation(node) {
- this.token("<");
- this.printList(node.params, node, {});
- this.token(">");
- }
-
- function TSTypeParameter(node) {
- this.word(node.name);
-
- if (node.constraint) {
- this.space();
- this.word("extends");
- this.space();
- this.print(node.constraint, node);
- }
-
- if (node.default) {
- this.space();
- this.token("=");
- this.space();
- this.print(node.default, node);
- }
- }
-
- function TSParameterProperty(node) {
- if (node.accessibility) {
- this.word(node.accessibility);
- this.space();
- }
-
- if (node.readonly) {
- this.word("readonly");
- this.space();
- }
-
- this._param(node.parameter);
- }
-
- function TSDeclareFunction(node) {
- if (node.declare) {
- this.word("declare");
- this.space();
- }
-
- this._functionHead(node);
-
- this.token(";");
- }
-
- function TSDeclareMethod(node) {
- this._classMethodHead(node);
-
- this.token(";");
- }
-
- function TSQualifiedName(node) {
- this.print(node.left, node);
- this.token(".");
- this.print(node.right, node);
- }
-
- function TSCallSignatureDeclaration(node) {
- this.tsPrintSignatureDeclarationBase(node);
- this.token(";");
- }
-
- function TSConstructSignatureDeclaration(node) {
- this.word("new");
- this.space();
- this.tsPrintSignatureDeclarationBase(node);
- this.token(";");
- }
-
- function TSPropertySignature(node) {
- const {
- readonly,
- initializer
- } = node;
-
- if (readonly) {
- this.word("readonly");
- this.space();
- }
-
- this.tsPrintPropertyOrMethodName(node);
- this.print(node.typeAnnotation, node);
-
- if (initializer) {
- this.space();
- this.token("=");
- this.space();
- this.print(initializer, node);
- }
-
- this.token(";");
- }
-
- function tsPrintPropertyOrMethodName(node) {
- if (node.computed) {
- this.token("[");
- }
-
- this.print(node.key, node);
-
- if (node.computed) {
- this.token("]");
- }
-
- if (node.optional) {
- this.token("?");
- }
- }
-
- function TSMethodSignature(node) {
- const {
- kind
- } = node;
-
- if (kind === "set" || kind === "get") {
- this.word(kind);
- this.space();
- }
-
- this.tsPrintPropertyOrMethodName(node);
- this.tsPrintSignatureDeclarationBase(node);
- this.token(";");
- }
-
- function TSIndexSignature(node) {
- const {
- readonly,
- static: isStatic
- } = node;
-
- if (isStatic) {
- this.word("static");
- this.space();
- }
-
- if (readonly) {
- this.word("readonly");
- this.space();
- }
-
- this.token("[");
-
- this._parameters(node.parameters, node);
-
- this.token("]");
- this.print(node.typeAnnotation, node);
- this.token(";");
- }
-
- function TSAnyKeyword() {
- this.word("any");
- }
-
- function TSBigIntKeyword() {
- this.word("bigint");
- }
-
- function TSUnknownKeyword() {
- this.word("unknown");
- }
-
- function TSNumberKeyword() {
- this.word("number");
- }
-
- function TSObjectKeyword() {
- this.word("object");
- }
-
- function TSBooleanKeyword() {
- this.word("boolean");
- }
-
- function TSStringKeyword() {
- this.word("string");
- }
-
- function TSSymbolKeyword() {
- this.word("symbol");
- }
-
- function TSVoidKeyword() {
- this.word("void");
- }
-
- function TSUndefinedKeyword() {
- this.word("undefined");
- }
-
- function TSNullKeyword() {
- this.word("null");
- }
-
- function TSNeverKeyword() {
- this.word("never");
- }
-
- function TSIntrinsicKeyword() {
- this.word("intrinsic");
- }
-
- function TSThisType() {
- this.word("this");
- }
-
- function TSFunctionType(node) {
- this.tsPrintFunctionOrConstructorType(node);
- }
-
- function TSConstructorType(node) {
- if (node.abstract) {
- this.word("abstract");
- this.space();
- }
-
- this.word("new");
- this.space();
- this.tsPrintFunctionOrConstructorType(node);
- }
-
- function tsPrintFunctionOrConstructorType(node) {
- const {
- typeParameters,
- parameters
- } = node;
- this.print(typeParameters, node);
- this.token("(");
-
- this._parameters(parameters, node);
-
- this.token(")");
- this.space();
- this.token("=>");
- this.space();
- this.print(node.typeAnnotation.typeAnnotation, node);
- }
-
- function TSTypeReference(node) {
- this.print(node.typeName, node);
- this.print(node.typeParameters, node);
- }
-
- function TSTypePredicate(node) {
- if (node.asserts) {
- this.word("asserts");
- this.space();
- }
-
- this.print(node.parameterName);
-
- if (node.typeAnnotation) {
- this.space();
- this.word("is");
- this.space();
- this.print(node.typeAnnotation.typeAnnotation);
- }
- }
-
- function TSTypeQuery(node) {
- this.word("typeof");
- this.space();
- this.print(node.exprName);
- }
-
- function TSTypeLiteral(node) {
- this.tsPrintTypeLiteralOrInterfaceBody(node.members, node);
- }
-
- function tsPrintTypeLiteralOrInterfaceBody(members, node) {
- this.tsPrintBraced(members, node);
- }
-
- function tsPrintBraced(members, node) {
- this.token("{");
-
- if (members.length) {
- this.indent();
- this.newline();
-
- for (const member of members) {
- this.print(member, node);
- this.newline();
- }
-
- this.dedent();
- this.rightBrace();
- } else {
- this.token("}");
- }
- }
-
- function TSArrayType(node) {
- this.print(node.elementType, node);
- this.token("[]");
- }
-
- function TSTupleType(node) {
- this.token("[");
- this.printList(node.elementTypes, node);
- this.token("]");
- }
-
- function TSOptionalType(node) {
- this.print(node.typeAnnotation, node);
- this.token("?");
- }
-
- function TSRestType(node) {
- this.token("...");
- this.print(node.typeAnnotation, node);
- }
-
- function TSNamedTupleMember(node) {
- this.print(node.label, node);
- if (node.optional) this.token("?");
- this.token(":");
- this.space();
- this.print(node.elementType, node);
- }
-
- function TSUnionType(node) {
- this.tsPrintUnionOrIntersectionType(node, "|");
- }
-
- function TSIntersectionType(node) {
- this.tsPrintUnionOrIntersectionType(node, "&");
- }
-
- function tsPrintUnionOrIntersectionType(node, sep) {
- this.printJoin(node.types, node, {
- separator() {
- this.space();
- this.token(sep);
- this.space();
- }
-
- });
- }
-
- function TSConditionalType(node) {
- this.print(node.checkType);
- this.space();
- this.word("extends");
- this.space();
- this.print(node.extendsType);
- this.space();
- this.token("?");
- this.space();
- this.print(node.trueType);
- this.space();
- this.token(":");
- this.space();
- this.print(node.falseType);
- }
-
- function TSInferType(node) {
- this.token("infer");
- this.space();
- this.print(node.typeParameter);
- }
-
- function TSParenthesizedType(node) {
- this.token("(");
- this.print(node.typeAnnotation, node);
- this.token(")");
- }
-
- function TSTypeOperator(node) {
- this.word(node.operator);
- this.space();
- this.print(node.typeAnnotation, node);
- }
-
- function TSIndexedAccessType(node) {
- this.print(node.objectType, node);
- this.token("[");
- this.print(node.indexType, node);
- this.token("]");
- }
-
- function TSMappedType(node) {
- const {
- nameType,
- optional,
- readonly,
- typeParameter
- } = node;
- this.token("{");
- this.space();
-
- if (readonly) {
- tokenIfPlusMinus(this, readonly);
- this.word("readonly");
- this.space();
- }
-
- this.token("[");
- this.word(typeParameter.name);
- this.space();
- this.word("in");
- this.space();
- this.print(typeParameter.constraint, typeParameter);
-
- if (nameType) {
- this.space();
- this.word("as");
- this.space();
- this.print(nameType, node);
- }
-
- this.token("]");
-
- if (optional) {
- tokenIfPlusMinus(this, optional);
- this.token("?");
- }
-
- this.token(":");
- this.space();
- this.print(node.typeAnnotation, node);
- this.space();
- this.token("}");
- }
-
- function tokenIfPlusMinus(self, tok) {
- if (tok !== true) {
- self.token(tok);
- }
- }
-
- function TSLiteralType(node) {
- this.print(node.literal, node);
- }
-
- function TSExpressionWithTypeArguments(node) {
- this.print(node.expression, node);
- this.print(node.typeParameters, node);
- }
-
- function TSInterfaceDeclaration(node) {
- const {
- declare,
- id,
- typeParameters,
- extends: extendz,
- body
- } = node;
-
- if (declare) {
- this.word("declare");
- this.space();
- }
-
- this.word("interface");
- this.space();
- this.print(id, node);
- this.print(typeParameters, node);
-
- if (extendz != null && extendz.length) {
- this.space();
- this.word("extends");
- this.space();
- this.printList(extendz, node);
- }
-
- this.space();
- this.print(body, node);
- }
-
- function TSInterfaceBody(node) {
- this.tsPrintTypeLiteralOrInterfaceBody(node.body, node);
- }
-
- function TSTypeAliasDeclaration(node) {
- const {
- declare,
- id,
- typeParameters,
- typeAnnotation
- } = node;
-
- if (declare) {
- this.word("declare");
- this.space();
- }
-
- this.word("type");
- this.space();
- this.print(id, node);
- this.print(typeParameters, node);
- this.space();
- this.token("=");
- this.space();
- this.print(typeAnnotation, node);
- this.token(";");
- }
-
- function TSAsExpression(node) {
- const {
- expression,
- typeAnnotation
- } = node;
- this.print(expression, node);
- this.space();
- this.word("as");
- this.space();
- this.print(typeAnnotation, node);
- }
-
- function TSTypeAssertion(node) {
- const {
- typeAnnotation,
- expression
- } = node;
- this.token("<");
- this.print(typeAnnotation, node);
- this.token(">");
- this.space();
- this.print(expression, node);
- }
-
- function TSEnumDeclaration(node) {
- const {
- declare,
- const: isConst,
- id,
- members
- } = node;
-
- if (declare) {
- this.word("declare");
- this.space();
- }
-
- if (isConst) {
- this.word("const");
- this.space();
- }
-
- this.word("enum");
- this.space();
- this.print(id, node);
- this.space();
- this.tsPrintBraced(members, node);
- }
-
- function TSEnumMember(node) {
- const {
- id,
- initializer
- } = node;
- this.print(id, node);
-
- if (initializer) {
- this.space();
- this.token("=");
- this.space();
- this.print(initializer, node);
- }
-
- this.token(",");
- }
-
- function TSModuleDeclaration(node) {
- const {
- declare,
- id
- } = node;
-
- if (declare) {
- this.word("declare");
- this.space();
- }
-
- if (!node.global) {
- this.word(id.type === "Identifier" ? "namespace" : "module");
- this.space();
- }
-
- this.print(id, node);
-
- if (!node.body) {
- this.token(";");
- return;
- }
-
- let body = node.body;
-
- while (body.type === "TSModuleDeclaration") {
- this.token(".");
- this.print(body.id, body);
- body = body.body;
- }
-
- this.space();
- this.print(body, node);
- }
-
- function TSModuleBlock(node) {
- this.tsPrintBraced(node.body, node);
- }
-
- function TSImportType(node) {
- const {
- argument,
- qualifier,
- typeParameters
- } = node;
- this.word("import");
- this.token("(");
- this.print(argument, node);
- this.token(")");
-
- if (qualifier) {
- this.token(".");
- this.print(qualifier, node);
- }
-
- if (typeParameters) {
- this.print(typeParameters, node);
- }
- }
-
- function TSImportEqualsDeclaration(node) {
- const {
- isExport,
- id,
- moduleReference
- } = node;
-
- if (isExport) {
- this.word("export");
- this.space();
- }
-
- this.word("import");
- this.space();
- this.print(id, node);
- this.space();
- this.token("=");
- this.space();
- this.print(moduleReference, node);
- this.token(";");
- }
-
- function TSExternalModuleReference(node) {
- this.token("require(");
- this.print(node.expression, node);
- this.token(")");
- }
-
- function TSNonNullExpression(node) {
- this.print(node.expression, node);
- this.token("!");
- }
-
- function TSExportAssignment(node) {
- this.word("export");
- this.space();
- this.token("=");
- this.space();
- this.print(node.expression, node);
- this.token(";");
- }
-
- function TSNamespaceExportDeclaration(node) {
- this.word("export");
- this.space();
- this.word("as");
- this.space();
- this.word("namespace");
- this.space();
- this.print(node.id, node);
- }
-
- function tsPrintSignatureDeclarationBase(node) {
- const {
- typeParameters,
- parameters
- } = node;
- this.print(typeParameters, node);
- this.token("(");
-
- this._parameters(parameters, node);
-
- this.token(")");
- this.print(node.typeAnnotation, node);
- }
-
- function tsPrintClassMemberModifiers(node, isField) {
- if (isField && node.declare) {
- this.word("declare");
- this.space();
- }
-
- if (node.accessibility) {
- this.word(node.accessibility);
- this.space();
- }
-
- if (node.static) {
- this.word("static");
- this.space();
- }
-
- if (node.override) {
- this.word("override");
- this.space();
- }
-
- if (node.abstract) {
- this.word("abstract");
- this.space();
- }
-
- if (isField && node.readonly) {
- this.word("readonly");
- this.space();
- }
- }
|