From 510799938e538505ef2e8ab6da9ba5791775201f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 14 Nov 2021 19:13:46 -0500 Subject: [PATCH] feat: wrap more JS doc nodes --- deno/ts_morph.d.ts | 142 +++++++ deno/ts_morph.js | 363 +++++++++++------- packages/ts-morph/lib/ts-morph.d.ts | 142 +++++++ packages/ts-morph/readme.md | 2 +- .../generation/outputWrappedNodesInfo.ts | 34 ++ .../ts-morph/src/compiler/ast/common/Node.ts | 89 +++++ .../src/compiler/ast/doc/JSDocAllType.ts | 8 + .../compiler/ast/doc/JSDocNameReference.ts | 12 + .../src/compiler/ast/doc/JSDocNamepathType.ts | 12 + .../compiler/ast/doc/JSDocNonNullableType.ts | 12 + .../src/compiler/ast/doc/JSDocNullableType.ts | 12 + .../src/compiler/ast/doc/JSDocOptionalType.ts | 12 + .../src/compiler/ast/doc/JSDocTypeLiteral.ts | 17 + .../src/compiler/ast/doc/JSDocUnknownType.ts | 8 + .../src/compiler/ast/doc/JSDocVariadicType.ts | 12 + .../ts-morph/src/compiler/ast/doc/index.ts | 9 + .../src/compiler/ast/kindToNodeMappings.ts | 9 + .../src/factories/StructurePrinterFactory.ts | 2 +- .../src/factories/kindToWrapperMappings.ts | 9 + packages/ts-morph/wrapped-nodes.md | 81 ++-- 20 files changed, 806 insertions(+), 181 deletions(-) create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocAllType.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocNameReference.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocNamepathType.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocNonNullableType.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocNullableType.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocOptionalType.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocTypeLiteral.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocUnknownType.ts create mode 100644 packages/ts-morph/src/compiler/ast/doc/JSDocVariadicType.ts diff --git a/deno/ts_morph.d.ts b/deno/ts_morph.d.ts index fb5c28fcd..c6d2c186b 100644 --- a/deno/ts_morph.d.ts +++ b/deno/ts_morph.d.ts @@ -4111,6 +4111,36 @@ export declare class Node { * @param node - Node to check. */ static isJSDocableNode(node: T | undefined): node is JSDocableNode & JSDocableNodeExtensionType & T; + /** + * Gets if the node is a JSDocAllType. + * @param node - Node to check. + */ + static isJSDocAllType(node: Node | undefined): node is JSDocAllType; + /** + * Gets if the node is a JSDocNamepathType. + * @param node - Node to check. + */ + static isJSDocNamepathType(node: Node | undefined): node is JSDocNamepathType; + /** + * Gets if the node is a JSDocNameReference. + * @param node - Node to check. + */ + static isJSDocNameReference(node: Node | undefined): node is JSDocNameReference; + /** + * Gets if the node is a JSDocNonNullableType. + * @param node - Node to check. + */ + static isJSDocNonNullableType(node: Node | undefined): node is JSDocNonNullableType; + /** + * Gets if the node is a JSDocNullableType. + * @param node - Node to check. + */ + static isJSDocNullableType(node: Node | undefined): node is JSDocNullableType; + /** + * Gets if the node is a JSDocOptionalType. + * @param node - Node to check. + */ + static isJSDocOptionalType(node: Node | undefined): node is JSDocOptionalType; /** * Gets if the node is a JSDocPropertyLikeTag. * @param node - Node to check. @@ -4131,6 +4161,11 @@ export declare class Node { * @param node - Node to check. */ static isJSDocTypeExpressionableTag(node: T | undefined): node is JSDocTypeExpressionableTag & JSDocTypeExpressionableTagExtensionType & T; + /** + * Gets if the node is a JSDocTypeLiteral. + * @param node - Node to check. + */ + static isJSDocTypeLiteral(node: Node | undefined): node is JSDocTypeLiteral; /** * Gets if the node is a JSDocTypeParameteredTag. * @param node - Node to check. @@ -4141,6 +4176,16 @@ export declare class Node { * @param node - Node to check. */ static isJSDocUnknownTag(node: Node | undefined): node is JSDocUnknownTag; + /** + * Gets if the node is a JSDocUnknownType. + * @param node - Node to check. + */ + static isJSDocUnknownType(node: Node | undefined): node is JSDocUnknownType; + /** + * Gets if the node is a JSDocVariadicType. + * @param node - Node to check. + */ + static isJSDocVariadicType(node: Node | undefined): node is JSDocVariadicType; /** * Gets if the node is a JsxAttributedNode. * @param node - Node to check. @@ -4719,6 +4764,14 @@ export declare class JSDoc extends JSDocBase { getParentOrThrow(): NonNullable>; } +/** JS doc all type. */ +export declare class JSDocAllType extends JSDocType { + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + /** JS doc augments tag node. */ export declare class JSDocAugmentsTag extends JSDocTag { /** @inheritdoc **/ @@ -4817,6 +4870,56 @@ export declare class JSDocMemberName extends Node { getParentOrThrow(): NonNullable>; } +/** JS doc namepath type. */ +export declare class JSDocNamepathType extends JSDocType { + /** Gets the type node of the JS doc namepath node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc name reference. */ +export declare class JSDocNameReference extends Node { + /** Gets the name of the JS doc name reference. */ + getName(): Identifier | QualifiedName | JSDocMemberName; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc non-nullable type. */ +export declare class JSDocNonNullableType extends JSDocType { + /** Gets the type node of the JS doc non-nullable type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc nullable type. */ +export declare class JSDocNullableType extends JSDocType { + /** Gets the type node of the JS doc nullable type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc optional type. */ +export declare class JSDocOptionalType extends JSDocType { + /** Gets the type node of the JS doc optional type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + /** JS doc override tag node. */ export declare class JSDocOverrideTag extends JSDocTag { /** @inheritdoc **/ @@ -5005,6 +5108,18 @@ export declare class JSDocTypeExpression extends TypeNode>; } +/** JS doc type literal. */ +export declare class JSDocTypeLiteral extends JSDocType { + /** Gets if it's an array type. */ + isArrayType(): boolean; + /** Gets the JS doc property tags if they exist. */ + getPropertyTags(): JSDocTag[] | undefined; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + /** JS doc type tag node. */ export declare class JSDocTypeTag extends JSDocTag { /** Gets the type expression node of the JS doc property type tag. */ @@ -5023,6 +5138,24 @@ export declare class JSDocUnknownTag extends JSDocTag { getParentOrThrow(): NonNullable>; } +/** JS doc unknown type. */ +export declare class JSDocUnknownType extends JSDocType { + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc variadic type. */ +export declare class JSDocVariadicType extends JSDocType { + /** Gets the type node of the JS doc variadic type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + export declare class CommentEnumMember extends Node { /** Removes this enum member comment. */ remove(): void; @@ -6432,6 +6565,7 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.InferType]: InferTypeNode; [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration; [SyntaxKind.IntersectionType]: IntersectionTypeNode; + [SyntaxKind.JSDocAllType]: JSDocAllType; [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag; [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag; [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag; @@ -6444,6 +6578,11 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.JSDocLinkCode]: JSDocLinkCode; [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain; [SyntaxKind.JSDocMemberName]: JSDocMemberName; + [SyntaxKind.JSDocNamepathType]: JSDocNamepathType; + [SyntaxKind.JSDocNameReference]: JSDocNameReference; + [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType; + [SyntaxKind.JSDocNullableType]: JSDocNullableType; + [SyntaxKind.JSDocOptionalType]: JSDocOptionalType; [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag; [SyntaxKind.JSDocParameterTag]: JSDocParameterTag; [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag; @@ -6459,8 +6598,11 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.JSDocText]: JSDocText; [SyntaxKind.JSDocThisTag]: JSDocThisTag; [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression; + [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral; [SyntaxKind.JSDocTypeTag]: JSDocTypeTag; [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag; + [SyntaxKind.JSDocUnknownType]: JSDocUnknownType; + [SyntaxKind.JSDocVariadicType]: JSDocVariadicType; [SyntaxKind.JsxAttribute]: JsxAttribute; [SyntaxKind.JsxClosingElement]: JsxClosingElement; [SyntaxKind.JsxClosingFragment]: JsxClosingFragment; diff --git a/deno/ts_morph.js b/deno/ts_morph.js index 59f579bcf..54e7fe478 100644 --- a/deno/ts_morph.js +++ b/deno/ts_morph.js @@ -4481,6 +4481,24 @@ class Node { return false; } } + static isJSDocAllType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocAllType; + } + static isJSDocNamepathType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocNamepathType; + } + static isJSDocNameReference(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocNameReference; + } + static isJSDocNonNullableType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocNonNullableType; + } + static isJSDocNullableType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocNullableType; + } + static isJSDocOptionalType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocOptionalType; + } static isJSDocPropertyLikeTag(node) { switch (node === null || node === void 0 ? void 0 : node.getKind()) { case SyntaxKind.JSDocParameterTag: @@ -4520,8 +4538,16 @@ class Node { } static isJSDocType(node) { switch (node === null || node === void 0 ? void 0 : node.getKind()) { + case SyntaxKind.JSDocAllType: case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocNamepathType: + case SyntaxKind.JSDocNonNullableType: + case SyntaxKind.JSDocNullableType: + case SyntaxKind.JSDocOptionalType: case SyntaxKind.JSDocSignature: + case SyntaxKind.JSDocTypeLiteral: + case SyntaxKind.JSDocUnknownType: + case SyntaxKind.JSDocVariadicType: return true; default: return false; @@ -4537,12 +4563,21 @@ class Node { return false; } } + static isJSDocTypeLiteral(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocTypeLiteral; + } static isJSDocTypeParameteredTag(node) { return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocTemplateTag; } static isJSDocUnknownTag(node) { return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocTag; } + static isJSDocUnknownType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocUnknownType; + } + static isJSDocVariadicType(node) { + return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDocVariadicType; + } static isJsxAttributedNode(node) { switch (node === null || node === void 0 ? void 0 : node.getKind()) { case SyntaxKind.JsxOpeningElement: @@ -5192,9 +5227,17 @@ class Node { case SyntaxKind.IndexedAccessType: case SyntaxKind.InferType: case SyntaxKind.IntersectionType: + case SyntaxKind.JSDocAllType: case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocNamepathType: + case SyntaxKind.JSDocNonNullableType: + case SyntaxKind.JSDocNullableType: + case SyntaxKind.JSDocOptionalType: case SyntaxKind.JSDocSignature: case SyntaxKind.JSDocTypeExpression: + case SyntaxKind.JSDocTypeLiteral: + case SyntaxKind.JSDocUnknownType: + case SyntaxKind.JSDocVariadicType: case SyntaxKind.LiteralType: case SyntaxKind.MappedType: case SyntaxKind.NamedTupleMember: @@ -14829,135 +14872,6 @@ class JSDoc extends JSDocBase { } } -const JSDocTagBase = Node; -class JSDocTag extends JSDocTagBase { - getTagName() { - return this.getTagNameNode().getText(); - } - getTagNameNode() { - return this._getNodeFromCompilerNode(this.compilerNode.tagName); - } - setTagName(tagName) { - return this.set({ tagName }); - } - getComment() { - if (this.compilerNode.comment == null) - return undefined; - else if (typeof this.compilerNode.comment === "string") - return this.compilerNode.comment; - else - return this.compilerNode.comment.map(n => this._getNodeFromCompilerNodeIfExists(n)); - } - getCommentText() { - if (typeof this.compilerNode.comment === "string") - return this.compilerNode.comment; - else - return ts.getTextOfJSDocComment(this.compilerNode.comment); - } - remove() { - const jsDocBodyStart = this.getParentOrThrow().getStart() + 3; - const nextJsDocTag = getNextJsDocTag(this); - const isLastJsDoc = nextJsDocTag == null; - const removalStart = getRemovalStart.call(this); - removeChildren({ - children: [this], - customRemovalPos: removalStart, - customRemovalEnd: getNextTagStartOrDocEnd(this, nextJsDocTag), - replaceTrivia: getReplaceTrivia.call(this), - }); - function getRemovalStart() { - return Math.max(jsDocBodyStart, getPreviousNonWhiteSpacePos(this, this.getStart())); - } - function getReplaceTrivia() { - if (removalStart === jsDocBodyStart && isLastJsDoc) - return ""; - const newLineKind = this._context.manipulationSettings.getNewLineKindAsString(); - const indentationText = this.getParentOrThrow().getIndentationText(); - return `${newLineKind}${indentationText} ` + (isLastJsDoc ? "" : "* "); - } - } - set(structure) { - callBaseSet(JSDocTagBase.prototype, this, structure); - if (structure.text != null || structure.tagName != null) { - return this.replaceWithText(writer => { - var _a; - this._context.structurePrinterFactory.forJSDocTag({ printStarsOnNewLine: true }).printText(writer, { - tagName: (_a = structure.tagName) !== null && _a !== void 0 ? _a : this.getTagName(), - text: structure.text != null ? structure.text : getText(this), - }); - }); - } - return this; - } - replaceWithText(textOrWriterFunction) { - const newText = getTextFromStringOrWriter(this._getWriterWithQueuedIndentation(), textOrWriterFunction); - const parent = this.getParentOrThrow(); - const childIndex = this.getChildIndex(); - const start = this.getStart(); - insertIntoParentTextRange({ - parent, - insertPos: start, - newText, - replacing: { - textLength: getTagEnd(this) - start, - }, - }); - return parent.getChildren()[childIndex]; - } - getStructure() { - const text = getText(this); - return callBaseGetStructure(JSDocTagBase.prototype, this, { - kind: StructureKind.JSDocTag, - tagName: this.getTagName(), - text: text.length === 0 ? undefined : text, - }); - } -} -function getText(jsDocTag) { - const text = jsDocTag.getSourceFile().getFullText(); - const nameEnd = jsDocTag.getTagNameNode().getEnd(); - const tagEnd = getTagEnd(jsDocTag); - const startPos = Math.min(text.charCodeAt(nameEnd) === CharCodes.SPACE ? nameEnd + 1 : nameEnd, tagEnd); - return getTextWithoutStars(text.substring(startPos, tagEnd)); -} -function getTagEnd(jsDocTag) { - return getPreviousNonWhiteSpacePos(jsDocTag, getNextTagStartOrDocEnd(jsDocTag)); -} -function getNextTagStartOrDocEnd(jsDocTag, nextJsDocTag) { - nextJsDocTag = nextJsDocTag !== null && nextJsDocTag !== void 0 ? nextJsDocTag : getNextJsDocTag(jsDocTag); - return nextJsDocTag != null - ? nextJsDocTag.getStart() - : jsDocTag.getParentOrThrow().getEnd() - 2; -} -function getNextJsDocTag(jsDocTag) { - const parent = jsDocTag.getParentIfKindOrThrow(SyntaxKind.JSDocComment); - const tags = parent.getTags(); - const thisIndex = tags.indexOf(jsDocTag); - return tags[thisIndex + 1]; -} -function getPreviousNonWhiteSpacePos(jsDocTag, pos) { - const sourceFileText = jsDocTag.getSourceFile().getFullText(); - return getPreviousMatchingPos(sourceFileText, pos, charCode => charCode !== CharCodes.ASTERISK && !StringUtils.isWhitespaceCharCode(charCode)); -} - -class JSDocAugmentsTag extends JSDocTag { -} - -class JSDocAuthorTag extends JSDocTag { -} - -class JSDocCallbackTag extends JSDocTag { -} - -class JSDocClassTag extends JSDocTag { -} - -class JSDocDeprecatedTag extends JSDocTag { -} - -class JSDocEnumTag extends JSDocTag { -} - class TypeNode extends Node { } @@ -15314,6 +15228,138 @@ class UnionTypeNode extends TypeNode { class JSDocType extends TypeNode { } +class JSDocAllType extends JSDocType { +} + +const JSDocTagBase = Node; +class JSDocTag extends JSDocTagBase { + getTagName() { + return this.getTagNameNode().getText(); + } + getTagNameNode() { + return this._getNodeFromCompilerNode(this.compilerNode.tagName); + } + setTagName(tagName) { + return this.set({ tagName }); + } + getComment() { + if (this.compilerNode.comment == null) + return undefined; + else if (typeof this.compilerNode.comment === "string") + return this.compilerNode.comment; + else + return this.compilerNode.comment.map(n => this._getNodeFromCompilerNodeIfExists(n)); + } + getCommentText() { + if (typeof this.compilerNode.comment === "string") + return this.compilerNode.comment; + else + return ts.getTextOfJSDocComment(this.compilerNode.comment); + } + remove() { + const jsDocBodyStart = this.getParentOrThrow().getStart() + 3; + const nextJsDocTag = getNextJsDocTag(this); + const isLastJsDoc = nextJsDocTag == null; + const removalStart = getRemovalStart.call(this); + removeChildren({ + children: [this], + customRemovalPos: removalStart, + customRemovalEnd: getNextTagStartOrDocEnd(this, nextJsDocTag), + replaceTrivia: getReplaceTrivia.call(this), + }); + function getRemovalStart() { + return Math.max(jsDocBodyStart, getPreviousNonWhiteSpacePos(this, this.getStart())); + } + function getReplaceTrivia() { + if (removalStart === jsDocBodyStart && isLastJsDoc) + return ""; + const newLineKind = this._context.manipulationSettings.getNewLineKindAsString(); + const indentationText = this.getParentOrThrow().getIndentationText(); + return `${newLineKind}${indentationText} ` + (isLastJsDoc ? "" : "* "); + } + } + set(structure) { + callBaseSet(JSDocTagBase.prototype, this, structure); + if (structure.text != null || structure.tagName != null) { + return this.replaceWithText(writer => { + var _a; + this._context.structurePrinterFactory.forJSDocTag({ printStarsOnNewLine: true }).printText(writer, { + tagName: (_a = structure.tagName) !== null && _a !== void 0 ? _a : this.getTagName(), + text: structure.text != null ? structure.text : getText(this), + }); + }); + } + return this; + } + replaceWithText(textOrWriterFunction) { + const newText = getTextFromStringOrWriter(this._getWriterWithQueuedIndentation(), textOrWriterFunction); + const parent = this.getParentOrThrow(); + const childIndex = this.getChildIndex(); + const start = this.getStart(); + insertIntoParentTextRange({ + parent, + insertPos: start, + newText, + replacing: { + textLength: getTagEnd(this) - start, + }, + }); + return parent.getChildren()[childIndex]; + } + getStructure() { + const text = getText(this); + return callBaseGetStructure(JSDocTagBase.prototype, this, { + kind: StructureKind.JSDocTag, + tagName: this.getTagName(), + text: text.length === 0 ? undefined : text, + }); + } +} +function getText(jsDocTag) { + const text = jsDocTag.getSourceFile().getFullText(); + const nameEnd = jsDocTag.getTagNameNode().getEnd(); + const tagEnd = getTagEnd(jsDocTag); + const startPos = Math.min(text.charCodeAt(nameEnd) === CharCodes.SPACE ? nameEnd + 1 : nameEnd, tagEnd); + return getTextWithoutStars(text.substring(startPos, tagEnd)); +} +function getTagEnd(jsDocTag) { + return getPreviousNonWhiteSpacePos(jsDocTag, getNextTagStartOrDocEnd(jsDocTag)); +} +function getNextTagStartOrDocEnd(jsDocTag, nextJsDocTag) { + nextJsDocTag = nextJsDocTag !== null && nextJsDocTag !== void 0 ? nextJsDocTag : getNextJsDocTag(jsDocTag); + return nextJsDocTag != null + ? nextJsDocTag.getStart() + : jsDocTag.getParentOrThrow().getEnd() - 2; +} +function getNextJsDocTag(jsDocTag) { + const parent = jsDocTag.getParentIfKindOrThrow(SyntaxKind.JSDocComment); + const tags = parent.getTags(); + const thisIndex = tags.indexOf(jsDocTag); + return tags[thisIndex + 1]; +} +function getPreviousNonWhiteSpacePos(jsDocTag, pos) { + const sourceFileText = jsDocTag.getSourceFile().getFullText(); + return getPreviousMatchingPos(sourceFileText, pos, charCode => charCode !== CharCodes.ASTERISK && !StringUtils.isWhitespaceCharCode(charCode)); +} + +class JSDocAugmentsTag extends JSDocTag { +} + +class JSDocAuthorTag extends JSDocTag { +} + +class JSDocCallbackTag extends JSDocTag { +} + +class JSDocClassTag extends JSDocTag { +} + +class JSDocDeprecatedTag extends JSDocTag { +} + +class JSDocEnumTag extends JSDocTag { +} + const JSDocFunctionTypeBase = SignaturedDeclaration(JSDocType); class JSDocFunctionType extends JSDocFunctionTypeBase { } @@ -15333,6 +15379,36 @@ class JSDocLinkPlain extends Node { class JSDocMemberName extends Node { } +class JSDocNamepathType extends JSDocType { + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} + +class JSDocNameReference extends Node { + getName() { + return this._getNodeFromCompilerNode(this.compilerNode.name); + } +} + +class JSDocNonNullableType extends JSDocType { + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} + +class JSDocNullableType extends JSDocType { + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} + +class JSDocOptionalType extends JSDocType { + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} + class JSDocOverrideTag extends JSDocTag { } @@ -15412,6 +15488,15 @@ class JSDocTypeExpression extends TypeNode { } } +class JSDocTypeLiteral extends JSDocType { + isArrayType() { + return this.compilerNode.isArrayType; + } + getPropertyTags() { + return this.compilerNode.jsDocPropertyTags ? this.compilerNode.jsDocPropertyTags.map(t => this._getNodeFromCompilerNode(t)) : undefined; + } +} + class JSDocTypeTag extends JSDocTag { getTypeExpression() { const node = this.compilerNode.typeExpression; @@ -15424,6 +15509,15 @@ class JSDocTypeTag extends JSDocTag { class JSDocUnknownTag extends JSDocTag { } +class JSDocUnknownType extends JSDocType { +} + +class JSDocVariadicType extends JSDocType { + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} + class CommentEnumMember extends Node { remove() { removeChildrenWithFormatting({ @@ -18560,6 +18654,7 @@ const kindToWrapperMappings = { [SyntaxKind.InferType]: InferTypeNode, [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration, [SyntaxKind.IntersectionType]: IntersectionTypeNode, + [SyntaxKind.JSDocAllType]: JSDocAllType, [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag, [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag, [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag, @@ -18572,6 +18667,11 @@ const kindToWrapperMappings = { [SyntaxKind.JSDocLinkCode]: JSDocLinkCode, [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain, [SyntaxKind.JSDocMemberName]: JSDocMemberName, + [SyntaxKind.JSDocNamepathType]: JSDocNamepathType, + [SyntaxKind.JSDocNameReference]: JSDocNameReference, + [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType, + [SyntaxKind.JSDocNullableType]: JSDocNullableType, + [SyntaxKind.JSDocOptionalType]: JSDocOptionalType, [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag, [SyntaxKind.JSDocParameterTag]: JSDocParameterTag, [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag, @@ -18587,8 +18687,11 @@ const kindToWrapperMappings = { [SyntaxKind.JSDocText]: JSDocText, [SyntaxKind.JSDocThisTag]: JSDocThisTag, [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression, + [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral, [SyntaxKind.JSDocTypeTag]: JSDocTypeTag, [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag, + [SyntaxKind.JSDocUnknownType]: JSDocUnknownType, + [SyntaxKind.JSDocVariadicType]: JSDocVariadicType, [SyntaxKind.JsxAttribute]: JsxAttribute, [SyntaxKind.JsxClosingElement]: JsxClosingElement, [SyntaxKind.JsxClosingFragment]: JsxClosingFragment, @@ -20014,4 +20117,4 @@ function writeValue(writer, value) { const { InvalidOperationError, FileNotFoundError, ArgumentError, ArgumentNullOrWhitespaceError, ArgumentOutOfRangeError, ArgumentTypeError, BaseError, DirectoryNotFoundError, NotImplementedError, NotSupportedError, PathNotFoundError, } = errors; -export { AbstractableNode, AmbientableNode, ArgumentError, ArgumentNullOrWhitespaceError, ArgumentOutOfRangeError, ArgumentTypeError, ArgumentedNode, ArrayBindingPattern, ArrayDestructuringAssignment, ArrayDestructuringAssignmentBase, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, ArrowFunctionBase, AsExpression, AsExpressionBase, AssignmentExpression, AssignmentExpressionBase, AsyncableNode, AwaitExpression, AwaitExpressionBase, AwaitableNode, BaseError, BaseExpressionedNode, BigIntLiteral, BigIntLiteralBase, BinaryExpression, BinaryExpressionBase, BindingElement, BindingElementBase, BindingNamedNode, Block, BlockBase, BodiedNode, BodyableNode, BreakStatement, CallExpression, CallExpressionBase, CallSignatureDeclaration, CallSignatureDeclarationBase, CaseBlock, CaseBlockBase, CaseClause, CaseClauseBase, CatchClause, CatchClauseBase, ChildOrderableNode, ClassDeclaration, ClassDeclarationBase, ClassElement, ClassExpression, ClassExpressionBase, ClassLikeDeclarationBase, ClassLikeDeclarationBaseSpecific, ClassStaticBlockDeclaration, ClassStaticBlockDeclarationBase, CodeAction, CodeFixAction, CombinedCodeActions, CommaListExpression, CommaListExpressionBase, CommentClassElement, CommentEnumMember, CommentNodeKind, CommentObjectLiteralElement, CommentRange, CommentStatement, CommentTypeElement, CommonIdentifierBase, CompilerCommentClassElement, CompilerCommentEnumMember, CompilerCommentNode, CompilerCommentObjectLiteralElement, CompilerCommentStatement, CompilerCommentTypeElement, ComputedPropertyName, ComputedPropertyNameBase, ConditionalExpression, ConditionalExpressionBase, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructSignatureDeclarationBase, ConstructorDeclaration, ConstructorDeclarationBase, ConstructorDeclarationOverloadBase, ConstructorTypeNode, ConstructorTypeNodeBase, ContinueStatement, DebuggerStatement, DebuggerStatementBase, DecoratableNode, Decorator, DecoratorBase, DefaultClause, DefaultClauseBase, DefinitionInfo, DeleteExpression, DeleteExpressionBase, Diagnostic, DiagnosticMessageChain, DiagnosticWithLocation, Directory, DirectoryEmitResult, DirectoryNotFoundError, DoStatement, DoStatementBase, DocumentSpan, DotDotDotTokenableNode, ElementAccessExpression, ElementAccessExpressionBase, EmitOutput, EmitResult, EmptyStatement, EmptyStatementBase, EnumDeclaration, EnumDeclarationBase, EnumMember, EnumMemberBase, ExclamationTokenableNode, ExportAssignment, ExportAssignmentBase, ExportDeclaration, ExportDeclarationBase, ExportGetableNode, ExportSpecifier, ExportSpecifierBase, ExportableNode, Expression, ExpressionStatement, ExpressionStatementBase, ExpressionWithTypeArguments, ExpressionWithTypeArgumentsBase, ExpressionableNode, ExpressionedNode, ExtendsClauseableNode, ExternalModuleReference, ExternalModuleReferenceBase, FalseLiteral, FalseLiteralBase, FileNotFoundError, FileReference, FileSystemRefreshResult, FileTextChanges, ForInStatement, ForInStatementBase, ForOfStatement, ForOfStatementBase, ForStatement, ForStatementBase, FunctionDeclaration, FunctionDeclarationBase, FunctionDeclarationOverloadBase, FunctionExpression, FunctionExpressionBase, FunctionLikeDeclaration, FunctionOrConstructorTypeNodeBase, FunctionOrConstructorTypeNodeBaseBase, FunctionTypeNode, FunctionTypeNodeBase, GeneratorableNode, GetAccessorDeclaration, GetAccessorDeclarationBase, HeritageClause, HeritageClauseableNode, Identifier, IdentifierBase, IfStatement, IfStatementBase, ImplementationLocation, ImplementsClauseableNode, ImportClause, ImportClauseBase, ImportDeclaration, ImportDeclarationBase, ImportEqualsDeclaration, ImportEqualsDeclarationBase, ImportExpression, ImportExpressionBase, ImportExpressionedNode, ImportSpecifier, ImportSpecifierBase, ImportTypeNode, ImportTypeNodeBase, IndentationText, IndexSignatureDeclaration, IndexSignatureDeclarationBase, IndexedAccessTypeNode, InferTypeNode, InitializerExpressionGetableNode, InitializerExpressionableNode, InterfaceDeclaration, InterfaceDeclarationBase, IntersectionTypeNode, InvalidOperationError, IterationStatement, JSDoc, JSDocAugmentsTag, JSDocAuthorTag, JSDocBase, JSDocCallbackTag, JSDocClassTag, JSDocDeprecatedTag, JSDocEnumTag, JSDocFunctionType, JSDocFunctionTypeBase, JSDocImplementsTag, JSDocLink, JSDocLinkCode, JSDocLinkPlain, JSDocMemberName, JSDocOverrideTag, JSDocParameterTag, JSDocParameterTagBase, JSDocPrivateTag, JSDocPropertyLikeTag, JSDocPropertyTag, JSDocPropertyTagBase, JSDocProtectedTag, JSDocPublicTag, JSDocReadonlyTag, JSDocReturnTag, JSDocReturnTagBase, JSDocSeeTag, JSDocSeeTagBase, JSDocSignature, JSDocTag, JSDocTagBase, JSDocTagInfo, JSDocTemplateTag, JSDocTemplateTagBase, JSDocText, JSDocThisTag, JSDocThisTagBase, JSDocType, JSDocTypeExpression, JSDocTypeExpressionableTag, JSDocTypeParameteredTag, JSDocTypeTag, JSDocTypedefTag, JSDocUnknownTag, JSDocableNode, JsxAttribute, JsxAttributeBase, JsxAttributedNode, JsxClosingElement, JsxClosingElementBase, JsxClosingFragment, JsxElement, JsxElementBase, JsxExpression, JsxExpressionBase, JsxFragment, JsxOpeningElement, JsxOpeningElementBase, JsxOpeningFragment, JsxSelfClosingElement, JsxSelfClosingElementBase, JsxSpreadAttribute, JsxSpreadAttributeBase, JsxTagNamedNode, JsxText, JsxTextBase, LabeledStatement, LabeledStatementBase, LanguageService, LeftHandSideExpression, LeftHandSideExpressionedNode, LiteralExpression, LiteralExpressionBase, LiteralLikeNode, LiteralTypeNode, ManipulationError, ManipulationSettingsContainer, MappedTypeNode, MemberExpression, MemoryEmitResult, MetaProperty, MetaPropertyBase, MethodDeclaration, MethodDeclarationBase, MethodDeclarationOverloadBase, MethodSignature, MethodSignatureBase, ModifierableNode, ModuleBlock, ModuleBlockBase, ModuleChildableNode, ModuleDeclaration, ModuleDeclarationBase, ModuleDeclarationKind, ModuleNamedNode, ModuledNode, NameableNode, NamedExports, NamedExportsBase, NamedImports, NamedImportsBase, NamedNode, NamedNodeBase, NamedTupleMember, NamedTupleMemberBase, NamespaceExport, NamespaceExportBase, NamespaceImport, NamespaceImportBase, NewExpression, NewExpressionBase, NoSubstitutionTemplateLiteral, NoSubstitutionTemplateLiteralBase, Node, NonNullExpression, NonNullExpressionBase, NotEmittedStatement, NotEmittedStatementBase, NotImplementedError, NotSupportedError, NullLiteral, NullLiteralBase, NumericLiteral, NumericLiteralBase, ObjectBindingPattern, ObjectDestructuringAssignment, ObjectDestructuringAssignmentBase, ObjectLiteralElement, ObjectLiteralExpression, ObjectLiteralExpressionBase, OmittedExpression, OmittedExpressionBase, OutputFile, OverloadableNode, OverrideableNode, ParameterDeclaration, ParameterDeclarationBase, ParameteredNode, ParenthesizedExpression, ParenthesizedExpressionBase, ParenthesizedTypeNode, PartiallyEmittedExpression, PartiallyEmittedExpressionBase, PathNotFoundError, PostfixUnaryExpression, PostfixUnaryExpressionBase, PrefixUnaryExpression, PrefixUnaryExpressionBase, PrimaryExpression, PrivateIdentifier, PrivateIdentifierBase, Program, Project, PropertyAccessExpression, PropertyAccessExpressionBase, PropertyAssignment, PropertyAssignmentBase, PropertyDeclaration, PropertyDeclarationBase, PropertyNamedNode, PropertySignature, PropertySignatureBase, QualifiedName, QuestionDotTokenableNode, QuestionTokenableNode, QuoteKind, ReadonlyableNode, RefactorEditInfo, ReferenceEntry, ReferenceFindableNode, ReferencedSymbol, ReferencedSymbolDefinitionInfo, RegularExpressionLiteral, RegularExpressionLiteralBase, RenameLocation, RenameableNode, ReturnStatement, ReturnStatementBase, ReturnTypedNode, Scope, ScopeableNode, ScopedNode, SetAccessorDeclaration, SetAccessorDeclarationBase, ShorthandPropertyAssignment, ShorthandPropertyAssignmentBase, Signature, SignaturedDeclaration, SourceFile, SourceFileBase, SpreadAssignment, SpreadAssignmentBase, SpreadElement, SpreadElementBase, Statement, StatementBase, StatementedNode, StaticableNode, StringLiteral, StringLiteralBase, Structure, StructureKind, SuperElementAccessExpression, SuperElementAccessExpressionBase, SuperExpression, SuperExpressionBase, SuperExpressionedNode, SuperPropertyAccessExpression, SuperPropertyAccessExpressionBase, SwitchStatement, SwitchStatementBase, Symbol, SymbolDisplayPart, SyntaxList, TaggedTemplateExpression, TemplateExpression, TemplateExpressionBase, TemplateHead, TemplateHeadBase, TemplateLiteralTypeNode, TemplateMiddle, TemplateMiddleBase, TemplateSpan, TemplateSpanBase, TemplateTail, TemplateTailBase, TextChange, TextInsertableNode, TextRange, TextSpan, ThisExpression, ThisExpressionBase, ThisTypeNode, ThrowStatement, ThrowStatementBase, TrueLiteral, TrueLiteralBase, TryStatement, TryStatementBase, TupleTypeNode, Type, TypeAliasDeclaration, TypeAliasDeclarationBase, TypeArgumentedNode, TypeAssertion, TypeAssertionBase, TypeChecker, TypeElement, TypeElementMemberedNode, TypeLiteralNode, TypeLiteralNodeBase, TypeNode, TypeOfExpression, TypeOfExpressionBase, TypeOperatorTypeNode, TypeParameter, TypeParameterDeclaration, TypeParameterDeclarationBase, TypeParameteredNode, TypePredicateNode, TypeQueryNode, TypeReferenceNode, TypedNode, UnaryExpression, UnaryExpressionedNode, UnionTypeNode, UnwrappableNode, UpdateExpression, VariableDeclaration, VariableDeclarationBase, VariableDeclarationKind, VariableDeclarationList, VariableDeclarationListBase, VariableStatement, VariableStatementBase, VoidExpression, VoidExpressionBase, WhileStatement, WhileStatementBase, WithStatement, WithStatementBase, Writers, YieldExpression, YieldExpressionBase, createWrappedNode, forEachStructureChild, getCompilerOptionsFromTsConfig, getScopeForNode, insertOverloads, printNode, setScopeForNode }; +export { AbstractableNode, AmbientableNode, ArgumentError, ArgumentNullOrWhitespaceError, ArgumentOutOfRangeError, ArgumentTypeError, ArgumentedNode, ArrayBindingPattern, ArrayDestructuringAssignment, ArrayDestructuringAssignmentBase, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, ArrowFunctionBase, AsExpression, AsExpressionBase, AssignmentExpression, AssignmentExpressionBase, AsyncableNode, AwaitExpression, AwaitExpressionBase, AwaitableNode, BaseError, BaseExpressionedNode, BigIntLiteral, BigIntLiteralBase, BinaryExpression, BinaryExpressionBase, BindingElement, BindingElementBase, BindingNamedNode, Block, BlockBase, BodiedNode, BodyableNode, BreakStatement, CallExpression, CallExpressionBase, CallSignatureDeclaration, CallSignatureDeclarationBase, CaseBlock, CaseBlockBase, CaseClause, CaseClauseBase, CatchClause, CatchClauseBase, ChildOrderableNode, ClassDeclaration, ClassDeclarationBase, ClassElement, ClassExpression, ClassExpressionBase, ClassLikeDeclarationBase, ClassLikeDeclarationBaseSpecific, ClassStaticBlockDeclaration, ClassStaticBlockDeclarationBase, CodeAction, CodeFixAction, CombinedCodeActions, CommaListExpression, CommaListExpressionBase, CommentClassElement, CommentEnumMember, CommentNodeKind, CommentObjectLiteralElement, CommentRange, CommentStatement, CommentTypeElement, CommonIdentifierBase, CompilerCommentClassElement, CompilerCommentEnumMember, CompilerCommentNode, CompilerCommentObjectLiteralElement, CompilerCommentStatement, CompilerCommentTypeElement, ComputedPropertyName, ComputedPropertyNameBase, ConditionalExpression, ConditionalExpressionBase, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructSignatureDeclarationBase, ConstructorDeclaration, ConstructorDeclarationBase, ConstructorDeclarationOverloadBase, ConstructorTypeNode, ConstructorTypeNodeBase, ContinueStatement, DebuggerStatement, DebuggerStatementBase, DecoratableNode, Decorator, DecoratorBase, DefaultClause, DefaultClauseBase, DefinitionInfo, DeleteExpression, DeleteExpressionBase, Diagnostic, DiagnosticMessageChain, DiagnosticWithLocation, Directory, DirectoryEmitResult, DirectoryNotFoundError, DoStatement, DoStatementBase, DocumentSpan, DotDotDotTokenableNode, ElementAccessExpression, ElementAccessExpressionBase, EmitOutput, EmitResult, EmptyStatement, EmptyStatementBase, EnumDeclaration, EnumDeclarationBase, EnumMember, EnumMemberBase, ExclamationTokenableNode, ExportAssignment, ExportAssignmentBase, ExportDeclaration, ExportDeclarationBase, ExportGetableNode, ExportSpecifier, ExportSpecifierBase, ExportableNode, Expression, ExpressionStatement, ExpressionStatementBase, ExpressionWithTypeArguments, ExpressionWithTypeArgumentsBase, ExpressionableNode, ExpressionedNode, ExtendsClauseableNode, ExternalModuleReference, ExternalModuleReferenceBase, FalseLiteral, FalseLiteralBase, FileNotFoundError, FileReference, FileSystemRefreshResult, FileTextChanges, ForInStatement, ForInStatementBase, ForOfStatement, ForOfStatementBase, ForStatement, ForStatementBase, FunctionDeclaration, FunctionDeclarationBase, FunctionDeclarationOverloadBase, FunctionExpression, FunctionExpressionBase, FunctionLikeDeclaration, FunctionOrConstructorTypeNodeBase, FunctionOrConstructorTypeNodeBaseBase, FunctionTypeNode, FunctionTypeNodeBase, GeneratorableNode, GetAccessorDeclaration, GetAccessorDeclarationBase, HeritageClause, HeritageClauseableNode, Identifier, IdentifierBase, IfStatement, IfStatementBase, ImplementationLocation, ImplementsClauseableNode, ImportClause, ImportClauseBase, ImportDeclaration, ImportDeclarationBase, ImportEqualsDeclaration, ImportEqualsDeclarationBase, ImportExpression, ImportExpressionBase, ImportExpressionedNode, ImportSpecifier, ImportSpecifierBase, ImportTypeNode, ImportTypeNodeBase, IndentationText, IndexSignatureDeclaration, IndexSignatureDeclarationBase, IndexedAccessTypeNode, InferTypeNode, InitializerExpressionGetableNode, InitializerExpressionableNode, InterfaceDeclaration, InterfaceDeclarationBase, IntersectionTypeNode, InvalidOperationError, IterationStatement, JSDoc, JSDocAllType, JSDocAugmentsTag, JSDocAuthorTag, JSDocBase, JSDocCallbackTag, JSDocClassTag, JSDocDeprecatedTag, JSDocEnumTag, JSDocFunctionType, JSDocFunctionTypeBase, JSDocImplementsTag, JSDocLink, JSDocLinkCode, JSDocLinkPlain, JSDocMemberName, JSDocNameReference, JSDocNamepathType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocOverrideTag, JSDocParameterTag, JSDocParameterTagBase, JSDocPrivateTag, JSDocPropertyLikeTag, JSDocPropertyTag, JSDocPropertyTagBase, JSDocProtectedTag, JSDocPublicTag, JSDocReadonlyTag, JSDocReturnTag, JSDocReturnTagBase, JSDocSeeTag, JSDocSeeTagBase, JSDocSignature, JSDocTag, JSDocTagBase, JSDocTagInfo, JSDocTemplateTag, JSDocTemplateTagBase, JSDocText, JSDocThisTag, JSDocThisTagBase, JSDocType, JSDocTypeExpression, JSDocTypeExpressionableTag, JSDocTypeLiteral, JSDocTypeParameteredTag, JSDocTypeTag, JSDocTypedefTag, JSDocUnknownTag, JSDocUnknownType, JSDocVariadicType, JSDocableNode, JsxAttribute, JsxAttributeBase, JsxAttributedNode, JsxClosingElement, JsxClosingElementBase, JsxClosingFragment, JsxElement, JsxElementBase, JsxExpression, JsxExpressionBase, JsxFragment, JsxOpeningElement, JsxOpeningElementBase, JsxOpeningFragment, JsxSelfClosingElement, JsxSelfClosingElementBase, JsxSpreadAttribute, JsxSpreadAttributeBase, JsxTagNamedNode, JsxText, JsxTextBase, LabeledStatement, LabeledStatementBase, LanguageService, LeftHandSideExpression, LeftHandSideExpressionedNode, LiteralExpression, LiteralExpressionBase, LiteralLikeNode, LiteralTypeNode, ManipulationError, ManipulationSettingsContainer, MappedTypeNode, MemberExpression, MemoryEmitResult, MetaProperty, MetaPropertyBase, MethodDeclaration, MethodDeclarationBase, MethodDeclarationOverloadBase, MethodSignature, MethodSignatureBase, ModifierableNode, ModuleBlock, ModuleBlockBase, ModuleChildableNode, ModuleDeclaration, ModuleDeclarationBase, ModuleDeclarationKind, ModuleNamedNode, ModuledNode, NameableNode, NamedExports, NamedExportsBase, NamedImports, NamedImportsBase, NamedNode, NamedNodeBase, NamedTupleMember, NamedTupleMemberBase, NamespaceExport, NamespaceExportBase, NamespaceImport, NamespaceImportBase, NewExpression, NewExpressionBase, NoSubstitutionTemplateLiteral, NoSubstitutionTemplateLiteralBase, Node, NonNullExpression, NonNullExpressionBase, NotEmittedStatement, NotEmittedStatementBase, NotImplementedError, NotSupportedError, NullLiteral, NullLiteralBase, NumericLiteral, NumericLiteralBase, ObjectBindingPattern, ObjectDestructuringAssignment, ObjectDestructuringAssignmentBase, ObjectLiteralElement, ObjectLiteralExpression, ObjectLiteralExpressionBase, OmittedExpression, OmittedExpressionBase, OutputFile, OverloadableNode, OverrideableNode, ParameterDeclaration, ParameterDeclarationBase, ParameteredNode, ParenthesizedExpression, ParenthesizedExpressionBase, ParenthesizedTypeNode, PartiallyEmittedExpression, PartiallyEmittedExpressionBase, PathNotFoundError, PostfixUnaryExpression, PostfixUnaryExpressionBase, PrefixUnaryExpression, PrefixUnaryExpressionBase, PrimaryExpression, PrivateIdentifier, PrivateIdentifierBase, Program, Project, PropertyAccessExpression, PropertyAccessExpressionBase, PropertyAssignment, PropertyAssignmentBase, PropertyDeclaration, PropertyDeclarationBase, PropertyNamedNode, PropertySignature, PropertySignatureBase, QualifiedName, QuestionDotTokenableNode, QuestionTokenableNode, QuoteKind, ReadonlyableNode, RefactorEditInfo, ReferenceEntry, ReferenceFindableNode, ReferencedSymbol, ReferencedSymbolDefinitionInfo, RegularExpressionLiteral, RegularExpressionLiteralBase, RenameLocation, RenameableNode, ReturnStatement, ReturnStatementBase, ReturnTypedNode, Scope, ScopeableNode, ScopedNode, SetAccessorDeclaration, SetAccessorDeclarationBase, ShorthandPropertyAssignment, ShorthandPropertyAssignmentBase, Signature, SignaturedDeclaration, SourceFile, SourceFileBase, SpreadAssignment, SpreadAssignmentBase, SpreadElement, SpreadElementBase, Statement, StatementBase, StatementedNode, StaticableNode, StringLiteral, StringLiteralBase, Structure, StructureKind, SuperElementAccessExpression, SuperElementAccessExpressionBase, SuperExpression, SuperExpressionBase, SuperExpressionedNode, SuperPropertyAccessExpression, SuperPropertyAccessExpressionBase, SwitchStatement, SwitchStatementBase, Symbol, SymbolDisplayPart, SyntaxList, TaggedTemplateExpression, TemplateExpression, TemplateExpressionBase, TemplateHead, TemplateHeadBase, TemplateLiteralTypeNode, TemplateMiddle, TemplateMiddleBase, TemplateSpan, TemplateSpanBase, TemplateTail, TemplateTailBase, TextChange, TextInsertableNode, TextRange, TextSpan, ThisExpression, ThisExpressionBase, ThisTypeNode, ThrowStatement, ThrowStatementBase, TrueLiteral, TrueLiteralBase, TryStatement, TryStatementBase, TupleTypeNode, Type, TypeAliasDeclaration, TypeAliasDeclarationBase, TypeArgumentedNode, TypeAssertion, TypeAssertionBase, TypeChecker, TypeElement, TypeElementMemberedNode, TypeLiteralNode, TypeLiteralNodeBase, TypeNode, TypeOfExpression, TypeOfExpressionBase, TypeOperatorTypeNode, TypeParameter, TypeParameterDeclaration, TypeParameterDeclarationBase, TypeParameteredNode, TypePredicateNode, TypeQueryNode, TypeReferenceNode, TypedNode, UnaryExpression, UnaryExpressionedNode, UnionTypeNode, UnwrappableNode, UpdateExpression, VariableDeclaration, VariableDeclarationBase, VariableDeclarationKind, VariableDeclarationList, VariableDeclarationListBase, VariableStatement, VariableStatementBase, VoidExpression, VoidExpressionBase, WhileStatement, WhileStatementBase, WithStatement, WithStatementBase, Writers, YieldExpression, YieldExpressionBase, createWrappedNode, forEachStructureChild, getCompilerOptionsFromTsConfig, getScopeForNode, insertOverloads, printNode, setScopeForNode }; diff --git a/packages/ts-morph/lib/ts-morph.d.ts b/packages/ts-morph/lib/ts-morph.d.ts index d0618f400..0736c6499 100644 --- a/packages/ts-morph/lib/ts-morph.d.ts +++ b/packages/ts-morph/lib/ts-morph.d.ts @@ -4111,6 +4111,36 @@ export declare class Node { * @param node - Node to check. */ static isJSDocableNode(node: T | undefined): node is JSDocableNode & JSDocableNodeExtensionType & T; + /** + * Gets if the node is a JSDocAllType. + * @param node - Node to check. + */ + static isJSDocAllType(node: Node | undefined): node is JSDocAllType; + /** + * Gets if the node is a JSDocNamepathType. + * @param node - Node to check. + */ + static isJSDocNamepathType(node: Node | undefined): node is JSDocNamepathType; + /** + * Gets if the node is a JSDocNameReference. + * @param node - Node to check. + */ + static isJSDocNameReference(node: Node | undefined): node is JSDocNameReference; + /** + * Gets if the node is a JSDocNonNullableType. + * @param node - Node to check. + */ + static isJSDocNonNullableType(node: Node | undefined): node is JSDocNonNullableType; + /** + * Gets if the node is a JSDocNullableType. + * @param node - Node to check. + */ + static isJSDocNullableType(node: Node | undefined): node is JSDocNullableType; + /** + * Gets if the node is a JSDocOptionalType. + * @param node - Node to check. + */ + static isJSDocOptionalType(node: Node | undefined): node is JSDocOptionalType; /** * Gets if the node is a JSDocPropertyLikeTag. * @param node - Node to check. @@ -4131,6 +4161,11 @@ export declare class Node { * @param node - Node to check. */ static isJSDocTypeExpressionableTag(node: T | undefined): node is JSDocTypeExpressionableTag & JSDocTypeExpressionableTagExtensionType & T; + /** + * Gets if the node is a JSDocTypeLiteral. + * @param node - Node to check. + */ + static isJSDocTypeLiteral(node: Node | undefined): node is JSDocTypeLiteral; /** * Gets if the node is a JSDocTypeParameteredTag. * @param node - Node to check. @@ -4141,6 +4176,16 @@ export declare class Node { * @param node - Node to check. */ static isJSDocUnknownTag(node: Node | undefined): node is JSDocUnknownTag; + /** + * Gets if the node is a JSDocUnknownType. + * @param node - Node to check. + */ + static isJSDocUnknownType(node: Node | undefined): node is JSDocUnknownType; + /** + * Gets if the node is a JSDocVariadicType. + * @param node - Node to check. + */ + static isJSDocVariadicType(node: Node | undefined): node is JSDocVariadicType; /** * Gets if the node is a JsxAttributedNode. * @param node - Node to check. @@ -4719,6 +4764,14 @@ export declare class JSDoc extends JSDocBase { getParentOrThrow(): NonNullable>; } +/** JS doc all type. */ +export declare class JSDocAllType extends JSDocType { + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + /** JS doc augments tag node. */ export declare class JSDocAugmentsTag extends JSDocTag { /** @inheritdoc **/ @@ -4817,6 +4870,56 @@ export declare class JSDocMemberName extends Node { getParentOrThrow(): NonNullable>; } +/** JS doc namepath type. */ +export declare class JSDocNamepathType extends JSDocType { + /** Gets the type node of the JS doc namepath node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc name reference. */ +export declare class JSDocNameReference extends Node { + /** Gets the name of the JS doc name reference. */ + getName(): Identifier | QualifiedName | JSDocMemberName; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc non-nullable type. */ +export declare class JSDocNonNullableType extends JSDocType { + /** Gets the type node of the JS doc non-nullable type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc nullable type. */ +export declare class JSDocNullableType extends JSDocType { + /** Gets the type node of the JS doc nullable type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc optional type. */ +export declare class JSDocOptionalType extends JSDocType { + /** Gets the type node of the JS doc optional type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + /** JS doc override tag node. */ export declare class JSDocOverrideTag extends JSDocTag { /** @inheritdoc **/ @@ -5005,6 +5108,18 @@ export declare class JSDocTypeExpression extends TypeNode>; } +/** JS doc type literal. */ +export declare class JSDocTypeLiteral extends JSDocType { + /** Gets if it's an array type. */ + isArrayType(): boolean; + /** Gets the JS doc property tags if they exist. */ + getPropertyTags(): JSDocTag[] | undefined; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + /** JS doc type tag node. */ export declare class JSDocTypeTag extends JSDocTag { /** Gets the type expression node of the JS doc property type tag. */ @@ -5023,6 +5138,24 @@ export declare class JSDocUnknownTag extends JSDocTag { getParentOrThrow(): NonNullable>; } +/** JS doc unknown type. */ +export declare class JSDocUnknownType extends JSDocType { + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + +/** JS doc variadic type. */ +export declare class JSDocVariadicType extends JSDocType { + /** Gets the type node of the JS doc variadic type node. */ + getTypeNode(): TypeNode; + /** @inheritdoc **/ + getParent(): NodeParentType; + /** @inheritdoc **/ + getParentOrThrow(): NonNullable>; +} + export declare class CommentEnumMember extends Node { /** Removes this enum member comment. */ remove(): void; @@ -6432,6 +6565,7 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.InferType]: InferTypeNode; [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration; [SyntaxKind.IntersectionType]: IntersectionTypeNode; + [SyntaxKind.JSDocAllType]: JSDocAllType; [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag; [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag; [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag; @@ -6444,6 +6578,11 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.JSDocLinkCode]: JSDocLinkCode; [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain; [SyntaxKind.JSDocMemberName]: JSDocMemberName; + [SyntaxKind.JSDocNamepathType]: JSDocNamepathType; + [SyntaxKind.JSDocNameReference]: JSDocNameReference; + [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType; + [SyntaxKind.JSDocNullableType]: JSDocNullableType; + [SyntaxKind.JSDocOptionalType]: JSDocOptionalType; [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag; [SyntaxKind.JSDocParameterTag]: JSDocParameterTag; [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag; @@ -6459,8 +6598,11 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.JSDocText]: JSDocText; [SyntaxKind.JSDocThisTag]: JSDocThisTag; [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression; + [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral; [SyntaxKind.JSDocTypeTag]: JSDocTypeTag; [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag; + [SyntaxKind.JSDocUnknownType]: JSDocUnknownType; + [SyntaxKind.JSDocVariadicType]: JSDocVariadicType; [SyntaxKind.JsxAttribute]: JsxAttribute; [SyntaxKind.JsxClosingElement]: JsxClosingElement; [SyntaxKind.JsxClosingFragment]: JsxClosingFragment; diff --git a/packages/ts-morph/readme.md b/packages/ts-morph/readme.md index bd827c390..fbf3cd339 100644 --- a/packages/ts-morph/readme.md +++ b/packages/ts-morph/readme.md @@ -18,7 +18,7 @@ Formerly `ts-simple-ast`. 1. Wraps the compiler API objects to provide helper methods for getting information and programmatically changing files. 2. Allows falling back to the compiler API objects if necessary (ex. `classDeclaration.compilerNode` or `typeChecker.compilerObject`). 3. All changes are kept in memory (including file and directory moves) until specifying to save to the underlying file system. -4. Changes are made to the text and wrapped nodes can be held onto between manipulations. +4. Changes are made to the text and wrapped nodes can be held on to between manipulations. ## Getting Started diff --git a/packages/ts-morph/scripts/generation/outputWrappedNodesInfo.ts b/packages/ts-morph/scripts/generation/outputWrappedNodesInfo.ts index 60ee9fc3d..e905ebfeb 100644 --- a/packages/ts-morph/scripts/generation/outputWrappedNodesInfo.ts +++ b/packages/ts-morph/scripts/generation/outputWrappedNodesInfo.ts @@ -78,6 +78,40 @@ function isIgnoredNode(node: TsNode) { switch (node.getName()) { // this would be implemented via a mixin case "Declaration": + // No node kind and implemented by CallExpression + case "ImportCall": + case "SuperCall": + case "CallChain": + // No node kind and implemented by PropertyAccessExpression + case "PropertyAccessChain": + // No node kind and implemented by ElementAccessExpression + case "ElementAccessChain": + // No node kind and implemented by NonNullExpression + case "NonNullChain": + // Not bothering since this is multiple files + case "Bundle": + case "InputFiles": + // Don't really do anything with Json + case "JsonSourceFile": + case "JsonMinusNumericLiteral": + case "JsonObjectExpressionStatement": + case "TsConfigSourceFile": + // Not bothering with unparsed + case "UnparsedPrepend": + case "UnparsedPrologue": + case "UnparsedSection": + case "UnparsedSource": + case "UnparsedSyntheticReference": + case "UnparsedTextLike": + // Seems implemented as ModuleDeclaration (but not really... perhaps this one could be wrapped somehow in the future) + case "JSDocNamespaceDeclaration": + // Handled in implementations + case "ClassLikeDeclarationBase": + case "DeclarationStatement": + case "FunctionOrConstructorTypeNodeBase": + case "NodeWithTypeArguments": + case "PropertyLikeDeclaration": + case "JSDocPropertyLikeTag": return true; default: return false; diff --git a/packages/ts-morph/src/compiler/ast/common/Node.ts b/packages/ts-morph/src/compiler/ast/common/Node.ts index eb6453cce..d3d92698e 100644 --- a/packages/ts-morph/src/compiler/ast/common/Node.ts +++ b/packages/ts-morph/src/compiler/ast/common/Node.ts @@ -2987,6 +2987,14 @@ export class Node { } } + /** + * Gets if the node is a JSDocAllType. + * @param node - Node to check. + */ + static isJSDocAllType(node: compiler.Node | undefined): node is compiler.JSDocAllType { + return node?.getKind() === SyntaxKind.JSDocAllType; + } + /** Gets if the node is a JSDocAugmentsTag. */ static readonly isJSDocAugmentsTag: (node: compiler.Node | undefined) => node is compiler.JSDocAugmentsTag = Node.is(SyntaxKind.JSDocAugmentsTag); /** Gets if the node is a JSDocAuthorTag. */ @@ -3011,6 +3019,47 @@ export class Node { static readonly isJSDocLinkPlain: (node: compiler.Node | undefined) => node is compiler.JSDocLinkPlain = Node.is(SyntaxKind.JSDocLinkPlain); /** Gets if the node is a JSDocMemberName. */ static readonly isJSDocMemberName: (node: compiler.Node | undefined) => node is compiler.JSDocMemberName = Node.is(SyntaxKind.JSDocMemberName); + + /** + * Gets if the node is a JSDocNamepathType. + * @param node - Node to check. + */ + static isJSDocNamepathType(node: compiler.Node | undefined): node is compiler.JSDocNamepathType { + return node?.getKind() === SyntaxKind.JSDocNamepathType; + } + + /** + * Gets if the node is a JSDocNameReference. + * @param node - Node to check. + */ + static isJSDocNameReference(node: compiler.Node | undefined): node is compiler.JSDocNameReference { + return node?.getKind() === SyntaxKind.JSDocNameReference; + } + + /** + * Gets if the node is a JSDocNonNullableType. + * @param node - Node to check. + */ + static isJSDocNonNullableType(node: compiler.Node | undefined): node is compiler.JSDocNonNullableType { + return node?.getKind() === SyntaxKind.JSDocNonNullableType; + } + + /** + * Gets if the node is a JSDocNullableType. + * @param node - Node to check. + */ + static isJSDocNullableType(node: compiler.Node | undefined): node is compiler.JSDocNullableType { + return node?.getKind() === SyntaxKind.JSDocNullableType; + } + + /** + * Gets if the node is a JSDocOptionalType. + * @param node - Node to check. + */ + static isJSDocOptionalType(node: compiler.Node | undefined): node is compiler.JSDocOptionalType { + return node?.getKind() === SyntaxKind.JSDocOptionalType; + } + /** Gets if the node is a JSDocOverrideTag. */ static readonly isJSDocOverrideTag: (node: compiler.Node | undefined) => node is compiler.JSDocOverrideTag = Node.is(SyntaxKind.JSDocOverrideTag); /** Gets if the node is a JSDocParameterTag. */ @@ -3093,8 +3142,16 @@ export class Node { */ static isJSDocType(node: compiler.Node | undefined): node is compiler.JSDocType { switch (node?.getKind()) { + case SyntaxKind.JSDocAllType: case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocNamepathType: + case SyntaxKind.JSDocNonNullableType: + case SyntaxKind.JSDocNullableType: + case SyntaxKind.JSDocOptionalType: case SyntaxKind.JSDocSignature: + case SyntaxKind.JSDocTypeLiteral: + case SyntaxKind.JSDocUnknownType: + case SyntaxKind.JSDocVariadicType: return true; default: return false; @@ -3121,6 +3178,14 @@ export class Node { } } + /** + * Gets if the node is a JSDocTypeLiteral. + * @param node - Node to check. + */ + static isJSDocTypeLiteral(node: compiler.Node | undefined): node is compiler.JSDocTypeLiteral { + return node?.getKind() === SyntaxKind.JSDocTypeLiteral; + } + /** * Gets if the node is a JSDocTypeParameteredTag. * @param node - Node to check. @@ -3140,6 +3205,22 @@ export class Node { return node?.getKind() === SyntaxKind.JSDocTag; } + /** + * Gets if the node is a JSDocUnknownType. + * @param node - Node to check. + */ + static isJSDocUnknownType(node: compiler.Node | undefined): node is compiler.JSDocUnknownType { + return node?.getKind() === SyntaxKind.JSDocUnknownType; + } + + /** + * Gets if the node is a JSDocVariadicType. + * @param node - Node to check. + */ + static isJSDocVariadicType(node: compiler.Node | undefined): node is compiler.JSDocVariadicType { + return node?.getKind() === SyntaxKind.JSDocVariadicType; + } + /** Gets if the node is a JsxAttribute. */ static readonly isJsxAttribute: (node: compiler.Node | undefined) => node is compiler.JsxAttribute = Node.is(SyntaxKind.JsxAttribute); @@ -4190,9 +4271,17 @@ export class Node { case SyntaxKind.IndexedAccessType: case SyntaxKind.InferType: case SyntaxKind.IntersectionType: + case SyntaxKind.JSDocAllType: case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocNamepathType: + case SyntaxKind.JSDocNonNullableType: + case SyntaxKind.JSDocNullableType: + case SyntaxKind.JSDocOptionalType: case SyntaxKind.JSDocSignature: case SyntaxKind.JSDocTypeExpression: + case SyntaxKind.JSDocTypeLiteral: + case SyntaxKind.JSDocUnknownType: + case SyntaxKind.JSDocVariadicType: case SyntaxKind.LiteralType: case SyntaxKind.MappedType: case SyntaxKind.NamedTupleMember: diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocAllType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocAllType.ts new file mode 100644 index 000000000..ca95d08ad --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocAllType.ts @@ -0,0 +1,8 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc all type. + */ +export class JSDocAllType extends JSDocType { +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocNameReference.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocNameReference.ts new file mode 100644 index 000000000..95bd7a1c8 --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocNameReference.ts @@ -0,0 +1,12 @@ +import { ts } from "@ts-morph/common"; +import { Node } from "../common"; + +/** + * JS doc name reference. + */ +export class JSDocNameReference extends Node { + /** Gets the name of the JS doc name reference. */ + getName() { + return this._getNodeFromCompilerNode(this.compilerNode.name); + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocNamepathType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocNamepathType.ts new file mode 100644 index 000000000..a838ac660 --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocNamepathType.ts @@ -0,0 +1,12 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc namepath type. + */ +export class JSDocNamepathType extends JSDocType { + /** Gets the type node of the JS doc namepath node. */ + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocNonNullableType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocNonNullableType.ts new file mode 100644 index 000000000..a46d5ace2 --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocNonNullableType.ts @@ -0,0 +1,12 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc non-nullable type. + */ +export class JSDocNonNullableType extends JSDocType { + /** Gets the type node of the JS doc non-nullable type node. */ + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocNullableType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocNullableType.ts new file mode 100644 index 000000000..d0bfa4f19 --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocNullableType.ts @@ -0,0 +1,12 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc nullable type. + */ +export class JSDocNullableType extends JSDocType { + /** Gets the type node of the JS doc nullable type node. */ + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocOptionalType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocOptionalType.ts new file mode 100644 index 000000000..ed20e5093 --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocOptionalType.ts @@ -0,0 +1,12 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc optional type. + */ +export class JSDocOptionalType extends JSDocType { + /** Gets the type node of the JS doc optional type node. */ + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocTypeLiteral.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocTypeLiteral.ts new file mode 100644 index 000000000..67f5f6388 --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocTypeLiteral.ts @@ -0,0 +1,17 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc type literal. + */ +export class JSDocTypeLiteral extends JSDocType { + /** Gets if it's an array type. */ + isArrayType() { + return this.compilerNode.isArrayType; + } + + /** Gets the JS doc property tags if they exist. */ + getPropertyTags() { + return this.compilerNode.jsDocPropertyTags ? this.compilerNode.jsDocPropertyTags.map(t => this._getNodeFromCompilerNode(t)) : undefined; + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocUnknownType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocUnknownType.ts new file mode 100644 index 000000000..eaa0bb07e --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocUnknownType.ts @@ -0,0 +1,8 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc unknown type. + */ +export class JSDocUnknownType extends JSDocType { +} diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocVariadicType.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocVariadicType.ts new file mode 100644 index 000000000..938f3803a --- /dev/null +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocVariadicType.ts @@ -0,0 +1,12 @@ +import { ts } from "@ts-morph/common"; +import { JSDocType } from "./JSDocType"; + +/** + * JS doc variadic type. + */ +export class JSDocVariadicType extends JSDocType { + /** Gets the type node of the JS doc variadic type node. */ + getTypeNode() { + return this._getNodeFromCompilerNode(this.compilerNode.type); + } +} diff --git a/packages/ts-morph/src/compiler/ast/doc/index.ts b/packages/ts-morph/src/compiler/ast/doc/index.ts index 9a11ca5f6..969518e27 100644 --- a/packages/ts-morph/src/compiler/ast/doc/index.ts +++ b/packages/ts-morph/src/compiler/ast/doc/index.ts @@ -1,5 +1,6 @@ export * from "./base"; export * from "./JSDoc"; +export * from "./JSDocAllType"; export * from "./JSDocAugmentsTag"; export * from "./JSDocAuthorTag"; export * from "./JSDocCallbackTag"; @@ -12,6 +13,11 @@ export * from "./JSDocLink"; export * from "./JSDocLinkCode"; export * from "./JSDocLinkPlain"; export * from "./JSDocMemberName"; +export * from "./JSDocNamepathType"; +export * from "./JSDocNameReference"; +export * from "./JSDocNonNullableType"; +export * from "./JSDocNullableType"; +export * from "./JSDocOptionalType"; export * from "./JSDocOverrideTag"; export * from "./JSDocParameterTag"; export * from "./JSDocPrivateTag"; @@ -30,5 +36,8 @@ export * from "./JSDocThisTag"; export * from "./JSDocType"; export * from "./JSDocTypedefTag"; export * from "./JSDocTypeExpression"; +export * from "./JSDocTypeLiteral"; export * from "./JSDocTypeTag"; export * from "./JSDocUnknownTag"; +export * from "./JSDocUnknownType"; +export * from "./JSDocVariadicType"; diff --git a/packages/ts-morph/src/compiler/ast/kindToNodeMappings.ts b/packages/ts-morph/src/compiler/ast/kindToNodeMappings.ts index b527fb157..ce8a1a614 100644 --- a/packages/ts-morph/src/compiler/ast/kindToNodeMappings.ts +++ b/packages/ts-morph/src/compiler/ast/kindToNodeMappings.ts @@ -68,6 +68,7 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.InferType]: compiler.InferTypeNode; [SyntaxKind.InterfaceDeclaration]: compiler.InterfaceDeclaration; [SyntaxKind.IntersectionType]: compiler.IntersectionTypeNode; + [SyntaxKind.JSDocAllType]: compiler.JSDocAllType; [SyntaxKind.JSDocAugmentsTag]: compiler.JSDocAugmentsTag; [SyntaxKind.JSDocAuthorTag]: compiler.JSDocAuthorTag; [SyntaxKind.JSDocCallbackTag]: compiler.JSDocCallbackTag; @@ -80,6 +81,11 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.JSDocLinkCode]: compiler.JSDocLinkCode; [SyntaxKind.JSDocLinkPlain]: compiler.JSDocLinkPlain; [SyntaxKind.JSDocMemberName]: compiler.JSDocMemberName; + [SyntaxKind.JSDocNamepathType]: compiler.JSDocNamepathType; + [SyntaxKind.JSDocNameReference]: compiler.JSDocNameReference; + [SyntaxKind.JSDocNonNullableType]: compiler.JSDocNonNullableType; + [SyntaxKind.JSDocNullableType]: compiler.JSDocNullableType; + [SyntaxKind.JSDocOptionalType]: compiler.JSDocOptionalType; [SyntaxKind.JSDocOverrideTag]: compiler.JSDocOverrideTag; [SyntaxKind.JSDocParameterTag]: compiler.JSDocParameterTag; [SyntaxKind.JSDocPrivateTag]: compiler.JSDocPrivateTag; @@ -95,8 +101,11 @@ export interface ImplementedKindToNodeMappings { [SyntaxKind.JSDocText]: compiler.JSDocText; [SyntaxKind.JSDocThisTag]: compiler.JSDocThisTag; [SyntaxKind.JSDocTypeExpression]: compiler.JSDocTypeExpression; + [SyntaxKind.JSDocTypeLiteral]: compiler.JSDocTypeLiteral; [SyntaxKind.JSDocTypeTag]: compiler.JSDocTypeTag; [SyntaxKind.JSDocTypedefTag]: compiler.JSDocTypedefTag; + [SyntaxKind.JSDocUnknownType]: compiler.JSDocUnknownType; + [SyntaxKind.JSDocVariadicType]: compiler.JSDocVariadicType; [SyntaxKind.JsxAttribute]: compiler.JsxAttribute; [SyntaxKind.JsxClosingElement]: compiler.JsxClosingElement; [SyntaxKind.JsxClosingFragment]: compiler.JsxClosingFragment; diff --git a/packages/ts-morph/src/factories/StructurePrinterFactory.ts b/packages/ts-morph/src/factories/StructurePrinterFactory.ts index 6880c586c..c54d3dc1a 100644 --- a/packages/ts-morph/src/factories/StructurePrinterFactory.ts +++ b/packages/ts-morph/src/factories/StructurePrinterFactory.ts @@ -1,7 +1,7 @@ // DO NOT EDIT - Automatically maintained by createStructurePrinterFactory.ts import { Memoize } from "@ts-morph/common"; -import { SupportedFormatCodeSettings } from "../options"; import * as structurePrinters from "../structurePrinters"; +import { SupportedFormatCodeSettings } from "../options"; /** Cached lazy factory for StructurePrinters. */ export class StructurePrinterFactory { diff --git a/packages/ts-morph/src/factories/kindToWrapperMappings.ts b/packages/ts-morph/src/factories/kindToWrapperMappings.ts index 2b8d498c2..face979fa 100644 --- a/packages/ts-morph/src/factories/kindToWrapperMappings.ts +++ b/packages/ts-morph/src/factories/kindToWrapperMappings.ts @@ -69,6 +69,7 @@ export const kindToWrapperMappings: { [key: number]: unknown } = { [SyntaxKind.InferType]: compiler.InferTypeNode, [SyntaxKind.InterfaceDeclaration]: compiler.InterfaceDeclaration, [SyntaxKind.IntersectionType]: compiler.IntersectionTypeNode, + [SyntaxKind.JSDocAllType]: compiler.JSDocAllType, [SyntaxKind.JSDocAugmentsTag]: compiler.JSDocAugmentsTag, [SyntaxKind.JSDocAuthorTag]: compiler.JSDocAuthorTag, [SyntaxKind.JSDocCallbackTag]: compiler.JSDocCallbackTag, @@ -81,6 +82,11 @@ export const kindToWrapperMappings: { [key: number]: unknown } = { [SyntaxKind.JSDocLinkCode]: compiler.JSDocLinkCode, [SyntaxKind.JSDocLinkPlain]: compiler.JSDocLinkPlain, [SyntaxKind.JSDocMemberName]: compiler.JSDocMemberName, + [SyntaxKind.JSDocNamepathType]: compiler.JSDocNamepathType, + [SyntaxKind.JSDocNameReference]: compiler.JSDocNameReference, + [SyntaxKind.JSDocNonNullableType]: compiler.JSDocNonNullableType, + [SyntaxKind.JSDocNullableType]: compiler.JSDocNullableType, + [SyntaxKind.JSDocOptionalType]: compiler.JSDocOptionalType, [SyntaxKind.JSDocOverrideTag]: compiler.JSDocOverrideTag, [SyntaxKind.JSDocParameterTag]: compiler.JSDocParameterTag, [SyntaxKind.JSDocPrivateTag]: compiler.JSDocPrivateTag, @@ -96,8 +102,11 @@ export const kindToWrapperMappings: { [key: number]: unknown } = { [SyntaxKind.JSDocText]: compiler.JSDocText, [SyntaxKind.JSDocThisTag]: compiler.JSDocThisTag, [SyntaxKind.JSDocTypeExpression]: compiler.JSDocTypeExpression, + [SyntaxKind.JSDocTypeLiteral]: compiler.JSDocTypeLiteral, [SyntaxKind.JSDocTypeTag]: compiler.JSDocTypeTag, [SyntaxKind.JSDocTypedefTag]: compiler.JSDocTypedefTag, + [SyntaxKind.JSDocUnknownType]: compiler.JSDocUnknownType, + [SyntaxKind.JSDocVariadicType]: compiler.JSDocVariadicType, [SyntaxKind.JsxAttribute]: compiler.JsxAttribute, [SyntaxKind.JsxClosingElement]: compiler.JsxClosingElement, [SyntaxKind.JsxClosingFragment]: compiler.JsxClosingFragment, diff --git a/packages/ts-morph/wrapped-nodes.md b/packages/ts-morph/wrapped-nodes.md index ad0103cd7..a21eb8952 100644 --- a/packages/ts-morph/wrapped-nodes.md +++ b/packages/ts-morph/wrapped-nodes.md @@ -6,7 +6,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method ## Exist -**Total:** 205 +**Total:** 214 * [ArrayBindingPattern](src/compiler/ast/binding/ArrayBindingPattern.ts) * :heavy_check_mark: elements @@ -78,10 +78,10 @@ The disadvantage to a node not being wrapped is that it won't have helper method * :heavy_check_mark: extendsType * :heavy_check_mark: trueType * :heavy_check_mark: falseType -* [ConstructSignatureDeclaration](src/compiler/ast/interface/ConstructSignatureDeclaration.ts) * [ConstructorDeclaration](src/compiler/ast/class/ConstructorDeclaration.ts) * :heavy_check_mark: body * [ConstructorTypeNode](src/compiler/ast/type/ConstructorTypeNode.ts) +* [ConstructSignatureDeclaration](src/compiler/ast/interface/ConstructSignatureDeclaration.ts) * [ContinueStatement](src/compiler/ast/statement/ContinueStatement.ts) * :heavy_check_mark: label * [DebuggerStatement](src/compiler/ast/statement/DebuggerStatement.ts) @@ -147,12 +147,12 @@ The disadvantage to a node not being wrapped is that it won't have helper method * [HeritageClause](src/compiler/ast/general/HeritageClause.ts) * :heavy_check_mark: token * :heavy_check_mark: types -* [Identifier](src/compiler/ast/name/Identifier.ts) - * :heavy_check_mark: text * [Identifier](src/compiler/ast/name/Identifier.ts) * :x: escapedText * :x: originalKeywordKind * :x: isInJSDocNamespace +* [Identifier](src/compiler/ast/name/Identifier.ts) + * :heavy_check_mark: text * [IfStatement](src/compiler/ast/statement/IfStatement.ts) * :heavy_check_mark: expression * :heavy_check_mark: thenStatement @@ -176,11 +176,11 @@ The disadvantage to a node not being wrapped is that it won't have helper method * :x: isTypeOf * :heavy_check_mark: argument * :heavy_check_mark: qualifier -* [IndexSignatureDeclaration](src/compiler/ast/interface/IndexSignatureDeclaration.ts) - * :heavy_check_mark: type * [IndexedAccessTypeNode](src/compiler/ast/type/IndexedAccessTypeNode.ts) * :heavy_check_mark: objectType * :heavy_check_mark: indexType +* [IndexSignatureDeclaration](src/compiler/ast/interface/IndexSignatureDeclaration.ts) + * :heavy_check_mark: type * [InferTypeNode](src/compiler/ast/type/InferTypeNode.ts) * :heavy_check_mark: typeParameter * [InterfaceDeclaration](src/compiler/ast/interface/InterfaceDeclaration.ts) @@ -195,6 +195,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method * [JSDoc](src/compiler/ast/doc/JSDoc.ts) * :heavy_check_mark: tags * :heavy_check_mark: comment +* [JSDocAllType](src/compiler/ast/doc/JSDocAllType.ts) * [JSDocAugmentsTag](src/compiler/ast/doc/JSDocAugmentsTag.ts) * :x: class * [JSDocAuthorTag](src/compiler/ast/doc/JSDocAuthorTag.ts) @@ -221,6 +222,16 @@ The disadvantage to a node not being wrapped is that it won't have helper method * [JSDocMemberName](src/compiler/ast/doc/JSDocMemberName.ts) * :x: left * :x: right +* [JSDocNamepathType](src/compiler/ast/doc/JSDocNamepathType.ts) + * :heavy_check_mark: type +* [JSDocNameReference](src/compiler/ast/doc/JSDocNameReference.ts) + * :heavy_check_mark: name +* [JSDocNonNullableType](src/compiler/ast/doc/JSDocNonNullableType.ts) + * :heavy_check_mark: type +* [JSDocNullableType](src/compiler/ast/doc/JSDocNullableType.ts) + * :heavy_check_mark: type +* [JSDocOptionalType](src/compiler/ast/doc/JSDocOptionalType.ts) + * :heavy_check_mark: type * [JSDocOverrideTag](src/compiler/ast/doc/JSDocOverrideTag.ts) * [JSDocParameterTag](src/compiler/ast/doc/JSDocParameterTag.ts) * [JSDocPrivateTag](src/compiler/ast/doc/JSDocPrivateTag.ts) @@ -247,15 +258,21 @@ The disadvantage to a node not being wrapped is that it won't have helper method * [JSDocThisTag](src/compiler/ast/doc/JSDocThisTag.ts) * :heavy_check_mark: typeExpression * [JSDocType](src/compiler/ast/doc/JSDocType.ts) -* [JSDocTypeExpression](src/compiler/ast/doc/JSDocTypeExpression.ts) - * :heavy_check_mark: type -* [JSDocTypeTag](src/compiler/ast/doc/JSDocTypeTag.ts) - * :heavy_check_mark: typeExpression * [JSDocTypedefTag](src/compiler/ast/doc/JSDocTypedefTag.ts) * :x: fullName * :heavy_check_mark: name * :x: typeExpression +* [JSDocTypeExpression](src/compiler/ast/doc/JSDocTypeExpression.ts) + * :heavy_check_mark: type +* [JSDocTypeLiteral](src/compiler/ast/doc/JSDocTypeLiteral.ts) + * :heavy_check_mark: jsDocPropertyTags + * :heavy_check_mark: isArrayType +* [JSDocTypeTag](src/compiler/ast/doc/JSDocTypeTag.ts) + * :heavy_check_mark: typeExpression * [JSDocUnknownTag](src/compiler/ast/doc/JSDocUnknownTag.ts) +* [JSDocUnknownType](src/compiler/ast/doc/JSDocUnknownType.ts) +* [JSDocVariadicType](src/compiler/ast/doc/JSDocVariadicType.ts) + * :heavy_check_mark: type * [JsxAttribute](src/compiler/ast/jsx/JsxAttribute.ts) * :heavy_check_mark: name * :heavy_check_mark: initializer @@ -331,9 +348,9 @@ The disadvantage to a node not being wrapped is that it won't have helper method * :heavy_check_mark: expression * :heavy_check_mark: typeArguments * :heavy_check_mark: arguments -* [NoSubstitutionTemplateLiteral](src/compiler/ast/literal/template/NoSubstitutionTemplateLiteral.ts) * [NonNullExpression](src/compiler/ast/expression/NonNullExpression.ts) * :heavy_check_mark: expression +* [NoSubstitutionTemplateLiteral](src/compiler/ast/literal/template/NoSubstitutionTemplateLiteral.ts) * [NotEmittedStatement](src/compiler/ast/statement/NotEmittedStatement.ts) * [NullLiteral](src/compiler/ast/literal/NullLiteral.ts) * [NumericLiteral](src/compiler/ast/literal/NumericLiteral.ts) @@ -364,10 +381,10 @@ The disadvantage to a node not being wrapped is that it won't have helper method * :heavy_check_mark: operator * :heavy_check_mark: operand * [PrimaryExpression](src/compiler/ast/expression/PrimaryExpression.ts) -* [PrivateIdentifier](src/compiler/ast/name/PrivateIdentifier.ts) - * :heavy_check_mark: text * [PrivateIdentifier](src/compiler/ast/name/PrivateIdentifier.ts) * :x: escapedText +* [PrivateIdentifier](src/compiler/ast/name/PrivateIdentifier.ts) + * :heavy_check_mark: text * [PropertyAccessExpression](src/compiler/ast/expression/PropertyAccessExpression.ts) * :heavy_check_mark: expression * :heavy_check_mark: questionDotToken @@ -404,7 +421,6 @@ The disadvantage to a node not being wrapped is that it won't have helper method * :heavy_check_mark: equalsToken * :heavy_check_mark: objectAssignmentInitializer * SignatureDeclarationBase - Implemented via mixin. -* [SourceFile](src/compiler/ast/module/SourceFile.ts) * [SourceFile](src/compiler/ast/module/SourceFile.ts) * :heavy_check_mark: statements * :x: endOfFileToken @@ -419,6 +435,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method * :heavy_check_mark: isDeclarationFile * :x: hasNoDefaultLib * :heavy_check_mark: languageVersion +* [SourceFile](src/compiler/ast/module/SourceFile.ts) * [SpreadAssignment](src/compiler/ast/expression/object/SpreadAssignment.ts) * :heavy_check_mark: expression * [SpreadElement](src/compiler/ast/expression/SpreadElement.ts) @@ -516,30 +533,8 @@ The disadvantage to a node not being wrapped is that it won't have helper method ## Not Exist -**Total:** 55 +**Total:** 21 -* Bundle -* CallChain -* ClassLikeDeclarationBase -* DeclarationStatement -* ElementAccessChain -* FunctionOrConstructorTypeNodeBase -* ImportCall -* InputFiles -* JSDocAllType -* JSDocNameReference -* JSDocNamepathType -* JSDocNamespaceDeclaration -* JSDocNonNullableType -* JSDocNullableType -* JSDocOptionalType -* JSDocPropertyLikeTag -* JSDocTypeLiteral -* JSDocUnknownType -* JSDocVariadicType -* JsonMinusNumericLiteral -* JsonObjectExpressionStatement -* JsonSourceFile * JsxAttributes * JsxTagNamePropertyAccess * KeywordToken @@ -549,27 +544,15 @@ The disadvantage to a node not being wrapped is that it won't have helper method * ModifierToken * NamespaceDeclaration * NamespaceExportDeclaration -* NodeWithTypeArguments -* NonNullChain * ObjectLiteralExpressionBase * OptionalTypeNode -* PropertyAccessChain * PropertyAccessEntityNameExpression -* PropertyLikeDeclaration * PunctuationToken * RestTypeNode * SemicolonClassElement -* SuperCall * SyntheticExpression * TemplateLiteralLikeNode * TemplateLiteralTypeSpan * Token * TransientIdentifier -* TsConfigSourceFile * TypeOperatorNode -* UnparsedPrepend -* UnparsedPrologue -* UnparsedSection -* UnparsedSource -* UnparsedSyntheticReference -* UnparsedTextLike