123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.TSAnyKeyword = TSAnyKeyword;
- exports.TSArrayType = TSArrayType;
- exports.TSSatisfiesExpression = exports.TSAsExpression = TSTypeExpression;
- exports.TSBigIntKeyword = TSBigIntKeyword;
- exports.TSBooleanKeyword = TSBooleanKeyword;
- exports.TSCallSignatureDeclaration = TSCallSignatureDeclaration;
- exports.TSInterfaceHeritage = exports.TSClassImplements = TSClassImplements;
- exports.TSConditionalType = TSConditionalType;
- exports.TSConstructSignatureDeclaration = TSConstructSignatureDeclaration;
- exports.TSConstructorType = TSConstructorType;
- exports.TSDeclareFunction = TSDeclareFunction;
- exports.TSDeclareMethod = TSDeclareMethod;
- exports.TSEnumBody = TSEnumBody;
- exports.TSEnumDeclaration = TSEnumDeclaration;
- exports.TSEnumMember = TSEnumMember;
- exports.TSExportAssignment = TSExportAssignment;
- exports.TSExternalModuleReference = TSExternalModuleReference;
- exports.TSFunctionType = TSFunctionType;
- exports.TSImportEqualsDeclaration = TSImportEqualsDeclaration;
- exports.TSImportType = TSImportType;
- exports.TSIndexSignature = TSIndexSignature;
- exports.TSIndexedAccessType = TSIndexedAccessType;
- exports.TSInferType = TSInferType;
- exports.TSInstantiationExpression = TSInstantiationExpression;
- exports.TSInterfaceBody = TSInterfaceBody;
- exports.TSInterfaceDeclaration = TSInterfaceDeclaration;
- exports.TSIntersectionType = TSIntersectionType;
- exports.TSIntrinsicKeyword = TSIntrinsicKeyword;
- exports.TSLiteralType = TSLiteralType;
- exports.TSMappedType = TSMappedType;
- exports.TSMethodSignature = TSMethodSignature;
- exports.TSModuleBlock = TSModuleBlock;
- exports.TSModuleDeclaration = TSModuleDeclaration;
- exports.TSNamedTupleMember = TSNamedTupleMember;
- exports.TSNamespaceExportDeclaration = TSNamespaceExportDeclaration;
- exports.TSNeverKeyword = TSNeverKeyword;
- exports.TSNonNullExpression = TSNonNullExpression;
- exports.TSNullKeyword = TSNullKeyword;
- exports.TSNumberKeyword = TSNumberKeyword;
- exports.TSObjectKeyword = TSObjectKeyword;
- exports.TSOptionalType = TSOptionalType;
- exports.TSParameterProperty = TSParameterProperty;
- exports.TSParenthesizedType = TSParenthesizedType;
- exports.TSPropertySignature = TSPropertySignature;
- exports.TSQualifiedName = TSQualifiedName;
- exports.TSRestType = TSRestType;
- exports.TSStringKeyword = TSStringKeyword;
- exports.TSSymbolKeyword = TSSymbolKeyword;
- exports.TSTemplateLiteralType = TSTemplateLiteralType;
- exports.TSThisType = TSThisType;
- exports.TSTupleType = TSTupleType;
- exports.TSTypeAliasDeclaration = TSTypeAliasDeclaration;
- exports.TSTypeAnnotation = TSTypeAnnotation;
- exports.TSTypeAssertion = TSTypeAssertion;
- exports.TSTypeLiteral = TSTypeLiteral;
- exports.TSTypeOperator = TSTypeOperator;
- exports.TSTypeParameter = TSTypeParameter;
- exports.TSTypeParameterDeclaration = exports.TSTypeParameterInstantiation = TSTypeParameterInstantiation;
- exports.TSTypePredicate = TSTypePredicate;
- exports.TSTypeQuery = TSTypeQuery;
- exports.TSTypeReference = TSTypeReference;
- exports.TSUndefinedKeyword = TSUndefinedKeyword;
- exports.TSUnionType = TSUnionType;
- exports.TSUnknownKeyword = TSUnknownKeyword;
- exports.TSVoidKeyword = TSVoidKeyword;
- exports.tsPrintClassMemberModifiers = tsPrintClassMemberModifiers;
- exports.tsPrintFunctionOrConstructorType = tsPrintFunctionOrConstructorType;
- exports.tsPrintPropertyOrMethodName = tsPrintPropertyOrMethodName;
- exports.tsPrintSignatureDeclarationBase = tsPrintSignatureDeclarationBase;
- function TSTypeAnnotation(node, parent) {
- this.token((parent.type === "TSFunctionType" || parent.type === "TSConstructorType") && parent.typeAnnotation === node ? "=>" : ":");
- this.space();
- if (node.optional) this.tokenChar(63);
- this.print(node.typeAnnotation);
- }
- function TSTypeParameterInstantiation(node, parent) {
- this.tokenChar(60);
- let printTrailingSeparator = parent.type === "ArrowFunctionExpression" && node.params.length === 1;
- if (this.tokenMap && node.start != null && node.end != null) {
- printTrailingSeparator && (printTrailingSeparator = !!this.tokenMap.find(node, t => this.tokenMap.matchesOriginal(t, ",")));
- printTrailingSeparator || (printTrailingSeparator = this.shouldPrintTrailingComma(">"));
- }
- this.printList(node.params, printTrailingSeparator);
- this.tokenChar(62);
- }
- function TSTypeParameter(node) {
- if (node.const) {
- this.word("const");
- this.space();
- }
- if (node.in) {
- this.word("in");
- this.space();
- }
- if (node.out) {
- this.word("out");
- this.space();
- }
- this.word(node.name);
- if (node.constraint) {
- this.space();
- this.word("extends");
- this.space();
- this.print(node.constraint);
- }
- if (node.default) {
- this.space();
- this.tokenChar(61);
- this.space();
- this.print(node.default);
- }
- }
- 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, parent) {
- if (node.declare) {
- this.word("declare");
- this.space();
- }
- this._functionHead(node, parent);
- this.semicolon();
- }
- function TSDeclareMethod(node) {
- this._classMethodHead(node);
- this.semicolon();
- }
- function TSQualifiedName(node) {
- this.print(node.left);
- this.tokenChar(46);
- this.print(node.right);
- }
- function TSCallSignatureDeclaration(node) {
- this.tsPrintSignatureDeclarationBase(node);
- maybePrintTrailingCommaOrSemicolon(this, node);
- }
- function maybePrintTrailingCommaOrSemicolon(printer, node) {
- if (!printer.tokenMap || !node.start || !node.end) {
- printer.semicolon();
- return;
- }
- if (printer.tokenMap.endMatches(node, ",")) {
- printer.token(",");
- } else if (printer.tokenMap.endMatches(node, ";")) {
- printer.semicolon();
- }
- }
- function TSConstructSignatureDeclaration(node) {
- this.word("new");
- this.space();
- this.tsPrintSignatureDeclarationBase(node);
- maybePrintTrailingCommaOrSemicolon(this, node);
- }
- function TSPropertySignature(node) {
- const {
- readonly
- } = node;
- if (readonly) {
- this.word("readonly");
- this.space();
- }
- this.tsPrintPropertyOrMethodName(node);
- this.print(node.typeAnnotation);
- maybePrintTrailingCommaOrSemicolon(this, node);
- }
- function tsPrintPropertyOrMethodName(node) {
- if (node.computed) {
- this.tokenChar(91);
- }
- this.print(node.key);
- if (node.computed) {
- this.tokenChar(93);
- }
- if (node.optional) {
- this.tokenChar(63);
- }
- }
- function TSMethodSignature(node) {
- const {
- kind
- } = node;
- if (kind === "set" || kind === "get") {
- this.word(kind);
- this.space();
- }
- this.tsPrintPropertyOrMethodName(node);
- this.tsPrintSignatureDeclarationBase(node);
- maybePrintTrailingCommaOrSemicolon(this, node);
- }
- function TSIndexSignature(node) {
- const {
- readonly,
- static: isStatic
- } = node;
- if (isStatic) {
- this.word("static");
- this.space();
- }
- if (readonly) {
- this.word("readonly");
- this.space();
- }
- this.tokenChar(91);
- this._parameters(node.parameters, "]");
- this.print(node.typeAnnotation);
- maybePrintTrailingCommaOrSemicolon(this, node);
- }
- 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
- } = node;
- const parameters = node.parameters;
- this.print(typeParameters);
- this.tokenChar(40);
- this._parameters(parameters, ")");
- this.space();
- const returnType = node.typeAnnotation;
- this.print(returnType);
- }
- function TSTypeReference(node) {
- const typeArguments = node.typeParameters;
- this.print(node.typeName, !!typeArguments);
- this.print(typeArguments);
- }
- 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);
- const typeArguments = node.typeParameters;
- if (typeArguments) {
- this.print(typeArguments);
- }
- }
- function TSTypeLiteral(node) {
- printBraced(this, node, () => this.printJoin(node.members, true, true));
- }
- function TSArrayType(node) {
- this.print(node.elementType, true);
- this.tokenChar(91);
- this.tokenChar(93);
- }
- function TSTupleType(node) {
- this.tokenChar(91);
- this.printList(node.elementTypes, this.shouldPrintTrailingComma("]"));
- this.tokenChar(93);
- }
- function TSOptionalType(node) {
- this.print(node.typeAnnotation);
- this.tokenChar(63);
- }
- function TSRestType(node) {
- this.token("...");
- this.print(node.typeAnnotation);
- }
- function TSNamedTupleMember(node) {
- this.print(node.label);
- if (node.optional) this.tokenChar(63);
- this.tokenChar(58);
- this.space();
- this.print(node.elementType);
- }
- function TSUnionType(node) {
- tsPrintUnionOrIntersectionType(this, node, "|");
- }
- function TSIntersectionType(node) {
- tsPrintUnionOrIntersectionType(this, node, "&");
- }
- function tsPrintUnionOrIntersectionType(printer, node, sep) {
- var _printer$tokenMap;
- let hasLeadingToken = 0;
- if ((_printer$tokenMap = printer.tokenMap) != null && _printer$tokenMap.startMatches(node, sep)) {
- hasLeadingToken = 1;
- printer.token(sep);
- }
- printer.printJoin(node.types, undefined, undefined, function (i) {
- this.space();
- this.token(sep, null, i + hasLeadingToken);
- this.space();
- });
- }
- function TSConditionalType(node) {
- this.print(node.checkType);
- this.space();
- this.word("extends");
- this.space();
- this.print(node.extendsType);
- this.space();
- this.tokenChar(63);
- this.space();
- this.print(node.trueType);
- this.space();
- this.tokenChar(58);
- this.space();
- this.print(node.falseType);
- }
- function TSInferType(node) {
- this.word("infer");
- this.print(node.typeParameter);
- }
- function TSParenthesizedType(node) {
- this.tokenChar(40);
- this.print(node.typeAnnotation);
- this.tokenChar(41);
- }
- function TSTypeOperator(node) {
- this.word(node.operator);
- this.space();
- this.print(node.typeAnnotation);
- }
- function TSIndexedAccessType(node) {
- this.print(node.objectType, true);
- this.tokenChar(91);
- this.print(node.indexType);
- this.tokenChar(93);
- }
- function TSMappedType(node) {
- const {
- nameType,
- optional,
- readonly,
- typeAnnotation
- } = node;
- this.tokenChar(123);
- const exit = this.enterDelimited();
- this.space();
- if (readonly) {
- tokenIfPlusMinus(this, readonly);
- this.word("readonly");
- this.space();
- }
- this.tokenChar(91);
- {
- this.word(node.typeParameter.name);
- }
- this.space();
- this.word("in");
- this.space();
- {
- this.print(node.typeParameter.constraint);
- }
- if (nameType) {
- this.space();
- this.word("as");
- this.space();
- this.print(nameType);
- }
- this.tokenChar(93);
- if (optional) {
- tokenIfPlusMinus(this, optional);
- this.tokenChar(63);
- }
- if (typeAnnotation) {
- this.tokenChar(58);
- this.space();
- this.print(typeAnnotation);
- }
- this.space();
- exit();
- this.tokenChar(125);
- }
- function tokenIfPlusMinus(self, tok) {
- if (tok !== true) {
- self.token(tok);
- }
- }
- function TSTemplateLiteralType(node) {
- this._printTemplate(node, node.types);
- }
- function TSLiteralType(node) {
- this.print(node.literal);
- }
- function TSClassImplements(node) {
- this.print(node.expression);
- this.print(node.typeArguments);
- }
- 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);
- this.print(typeParameters);
- if (extendz != null && extendz.length) {
- this.space();
- this.word("extends");
- this.space();
- this.printList(extendz);
- }
- this.space();
- this.print(body);
- }
- function TSInterfaceBody(node) {
- printBraced(this, node, () => this.printJoin(node.body, true, true));
- }
- function TSTypeAliasDeclaration(node) {
- const {
- declare,
- id,
- typeParameters,
- typeAnnotation
- } = node;
- if (declare) {
- this.word("declare");
- this.space();
- }
- this.word("type");
- this.space();
- this.print(id);
- this.print(typeParameters);
- this.space();
- this.tokenChar(61);
- this.space();
- this.print(typeAnnotation);
- this.semicolon();
- }
- function TSTypeExpression(node) {
- const {
- type,
- expression,
- typeAnnotation
- } = node;
- this.print(expression, true);
- this.space();
- this.word(type === "TSAsExpression" ? "as" : "satisfies");
- this.space();
- this.print(typeAnnotation);
- }
- function TSTypeAssertion(node) {
- const {
- typeAnnotation,
- expression
- } = node;
- this.tokenChar(60);
- this.print(typeAnnotation);
- this.tokenChar(62);
- this.space();
- this.print(expression);
- }
- function TSInstantiationExpression(node) {
- this.print(node.expression);
- {
- this.print(node.typeParameters);
- }
- }
- function TSEnumDeclaration(node) {
- const {
- declare,
- const: isConst,
- id
- } = node;
- if (declare) {
- this.word("declare");
- this.space();
- }
- if (isConst) {
- this.word("const");
- this.space();
- }
- this.word("enum");
- this.space();
- this.print(id);
- this.space();
- {
- TSEnumBody.call(this, node);
- }
- }
- function TSEnumBody(node) {
- printBraced(this, node, () => {
- var _this$shouldPrintTrai;
- return this.printList(node.members, (_this$shouldPrintTrai = this.shouldPrintTrailingComma("}")) != null ? _this$shouldPrintTrai : true, true, true);
- });
- }
- function TSEnumMember(node) {
- const {
- id,
- initializer
- } = node;
- this.print(id);
- if (initializer) {
- this.space();
- this.tokenChar(61);
- this.space();
- this.print(initializer);
- }
- }
- function TSModuleDeclaration(node) {
- const {
- declare,
- id,
- kind
- } = node;
- if (declare) {
- this.word("declare");
- this.space();
- }
- {
- if (!node.global) {
- this.word(kind != null ? kind : id.type === "Identifier" ? "namespace" : "module");
- this.space();
- }
- this.print(id);
- if (!node.body) {
- this.semicolon();
- return;
- }
- let body = node.body;
- while (body.type === "TSModuleDeclaration") {
- this.tokenChar(46);
- this.print(body.id);
- body = body.body;
- }
- this.space();
- this.print(body);
- }
- }
- function TSModuleBlock(node) {
- printBraced(this, node, () => this.printSequence(node.body, true));
- }
- function TSImportType(node) {
- const {
- argument,
- qualifier,
- options
- } = node;
- this.word("import");
- this.tokenChar(40);
- this.print(argument);
- if (options) {
- this.tokenChar(44);
- this.print(options);
- }
- this.tokenChar(41);
- if (qualifier) {
- this.tokenChar(46);
- this.print(qualifier);
- }
- const typeArguments = node.typeParameters;
- if (typeArguments) {
- this.print(typeArguments);
- }
- }
- function TSImportEqualsDeclaration(node) {
- const {
- id,
- moduleReference
- } = node;
- if (node.isExport) {
- this.word("export");
- this.space();
- }
- this.word("import");
- this.space();
- this.print(id);
- this.space();
- this.tokenChar(61);
- this.space();
- this.print(moduleReference);
- this.semicolon();
- }
- function TSExternalModuleReference(node) {
- this.token("require(");
- this.print(node.expression);
- this.tokenChar(41);
- }
- function TSNonNullExpression(node) {
- this.print(node.expression);
- this.tokenChar(33);
- }
- function TSExportAssignment(node) {
- this.word("export");
- this.space();
- this.tokenChar(61);
- this.space();
- this.print(node.expression);
- this.semicolon();
- }
- function TSNamespaceExportDeclaration(node) {
- this.word("export");
- this.space();
- this.word("as");
- this.space();
- this.word("namespace");
- this.space();
- this.print(node.id);
- this.semicolon();
- }
- function tsPrintSignatureDeclarationBase(node) {
- const {
- typeParameters
- } = node;
- const parameters = node.parameters;
- this.print(typeParameters);
- this.tokenChar(40);
- this._parameters(parameters, ")");
- const returnType = node.typeAnnotation;
- this.print(returnType);
- }
- function tsPrintClassMemberModifiers(node) {
- const isPrivateField = node.type === "ClassPrivateProperty";
- const isPublicField = node.type === "ClassAccessorProperty" || node.type === "ClassProperty";
- printModifiersList(this, node, [isPublicField && node.declare && "declare", !isPrivateField && node.accessibility]);
- if (node.static) {
- this.word("static");
- this.space();
- }
- printModifiersList(this, node, [!isPrivateField && node.abstract && "abstract", !isPrivateField && node.override && "override", (isPublicField || isPrivateField) && node.readonly && "readonly"]);
- }
- function printBraced(printer, node, cb) {
- printer.token("{");
- const exit = printer.enterDelimited();
- cb();
- exit();
- printer.rightBrace(node);
- }
- function printModifiersList(printer, node, modifiers) {
- var _printer$tokenMap2;
- const modifiersSet = new Set();
- for (const modifier of modifiers) {
- if (modifier) modifiersSet.add(modifier);
- }
- (_printer$tokenMap2 = printer.tokenMap) == null || _printer$tokenMap2.find(node, tok => {
- if (modifiersSet.has(tok.value)) {
- printer.token(tok.value);
- printer.space();
- modifiersSet.delete(tok.value);
- return modifiersSet.size === 0;
- }
- });
- for (const modifier of modifiersSet) {
- printer.word(modifier);
- printer.space();
- }
- }
- //# sourceMappingURL=typescript.js.map
|