├── .editorconfig ├── .gitattributes ├── .github ├── CODE_OF_CONDUCT.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md └── workflows │ ├── ci.yml │ └── publish.yml ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── DEVELOPMENT.md ├── LICENSE ├── deno.json ├── deno.lock ├── docs ├── CNAME ├── Gemfile ├── _config.yml ├── _layouts │ └── default.html ├── _script-templates │ └── main.ts ├── assets │ └── css │ │ └── style.scss ├── details │ ├── ambient.md │ ├── async.md │ ├── classes.md │ ├── comment-ranges.md │ ├── comments.md │ ├── decorators.md │ ├── documentation.md │ ├── enums.md │ ├── exports.md │ ├── expressions.md │ ├── functions.md │ ├── generators.md │ ├── identifiers.md │ ├── imports.md │ ├── index.md │ ├── initializers.md │ ├── interfaces.md │ ├── literals.md │ ├── modifiers.md │ ├── modules.md │ ├── namespaces.md │ ├── object-literal-expressions.md │ ├── parameters.md │ ├── signatures.md │ ├── source-files.md │ ├── type-aliases.md │ ├── type-parameters.md │ ├── types.md │ └── variables.md ├── emitting.md ├── index.md ├── manipulation │ ├── code-writer.md │ ├── formatting.md │ ├── index.md │ ├── order.md │ ├── performance.md │ ├── removing.md │ ├── renaming.md │ ├── settings.md │ ├── structures.md │ └── transforms.md ├── metrics │ └── performance.json ├── navigation │ ├── ambient-modules.md │ ├── compiler-nodes.md │ ├── directories.md │ ├── example.md │ ├── finding-references.md │ ├── getting-source-files.md │ ├── images │ │ └── getChildrenVsForEachChild.gif │ ├── index.md │ ├── language-service.md │ ├── program.md │ └── type-checker.md ├── setup │ ├── adding-source-files.md │ ├── ast-viewers.md │ ├── diagnostics.md │ ├── file-system.md │ ├── images │ │ ├── atom-ast.png │ │ ├── atom-ast_small.png │ │ ├── atom-command-palette.png │ │ ├── atom-file.png │ │ └── ts-ast-viewer.png │ └── index.md └── utilities.md ├── dprint.json ├── package.json ├── packages ├── bootstrap │ ├── .mocharc.yml │ ├── .npmignore │ ├── LICENSE │ ├── lib │ │ └── ts-morph-bootstrap.d.ts │ ├── package.json │ ├── readme.md │ ├── rollup.config.mjs │ ├── scripts │ │ ├── buildDeclarations.ts │ │ ├── buildDeno.ts │ │ ├── deps.ts │ │ └── test │ │ │ └── testTypeScriptVersions.ts │ ├── src │ │ ├── Project.ts │ │ ├── SourceFileCache.ts │ │ ├── index.ts │ │ └── tests │ │ │ └── projectTests.ts │ ├── tsconfig.json │ └── tsconfig.rollup.json ├── common │ ├── .mocharc.yml │ ├── .npmignore │ ├── LICENSE │ ├── lib │ │ ├── ts-morph-common.d.ts │ │ └── typescript.d.ts │ ├── package.json │ ├── readme.md │ ├── rollup.config.mjs │ ├── scripts │ │ ├── buildDeclarations.ts │ │ ├── buildDeno.ts │ │ ├── bundleLocalTs.ts │ │ ├── createLibFile.ts │ │ └── deps.ts │ ├── src │ │ ├── collections │ │ │ ├── KeyValueCache.ts │ │ │ ├── SortedKeyValueArray.ts │ │ │ ├── WeakCache.ts │ │ │ └── index.ts │ │ ├── comparers │ │ │ ├── Comparer.ts │ │ │ ├── ComparerToStoredComparer.ts │ │ │ ├── LocaleStringComparer.ts │ │ │ ├── PropertyComparer.ts │ │ │ ├── PropertyStoredComparer.ts │ │ │ ├── StoredComparer.ts │ │ │ └── index.ts │ │ ├── compiler │ │ │ ├── DocumentRegistry.ts │ │ │ ├── ResolutionHost.ts │ │ │ ├── TsSourceFileContainer.ts │ │ │ ├── createCompilerSourceFile.ts │ │ │ ├── createDocumentCache.ts │ │ │ ├── createHosts.ts │ │ │ ├── createModuleResolutionHost.ts │ │ │ └── index.ts │ │ ├── data │ │ │ └── libFiles.ts │ │ ├── decorators │ │ │ ├── Memoize.ts │ │ │ └── index.ts │ │ ├── errors.ts │ │ ├── fileSystem │ │ │ ├── FileSystemHost.ts │ │ │ ├── FileUtils.ts │ │ │ ├── InMemoryFileSystemHost.ts │ │ │ ├── RealFileSystemHost.ts │ │ │ ├── StandardizedFilePath.ts │ │ │ ├── TransactionalFileSystem.ts │ │ │ ├── index.ts │ │ │ └── matchGlobs.ts │ │ ├── getLibFiles.ts │ │ ├── helpers │ │ │ ├── getSyntaxKindName.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── options │ │ │ ├── CompilerOptionsContainer.ts │ │ │ ├── SettingsContainer.ts │ │ │ └── index.ts │ │ ├── runtimes │ │ │ ├── BrowserRuntime.ts │ │ │ ├── DenoRuntime.ts │ │ │ ├── NodeRuntime.ts │ │ │ ├── Runtime.ts │ │ │ ├── getRuntime.ts │ │ │ └── index.ts │ │ ├── tests │ │ │ ├── collections │ │ │ │ ├── keyValueCacheTests.ts │ │ │ │ └── sortedKeyValueArrayTests.ts │ │ │ ├── decorators │ │ │ │ └── memoizeTests.ts │ │ │ ├── errorsTests.ts │ │ │ ├── fileSystem │ │ │ │ ├── fileUtilsTests.ts │ │ │ │ ├── inMemoryFileSystemHostTests.ts │ │ │ │ ├── realFileSystemHostTests.ts │ │ │ │ └── transactionalFileSystemTests.ts │ │ │ ├── tsconfig │ │ │ │ ├── getCompilerOptionsFromTsConfigTests.ts │ │ │ │ └── tsConfigResolverTests.ts │ │ │ ├── typescript │ │ │ │ └── tsInternalTests.ts │ │ │ └── utils │ │ │ │ ├── arrayUtilsTests.ts │ │ │ │ ├── eventContainerTests.ts │ │ │ │ └── stringUtilsTests.ts │ │ ├── tsconfig │ │ │ ├── TsConfigResolver.ts │ │ │ ├── getCompilerOptionsFromTsConfig.ts │ │ │ ├── getTsParseConfigHost.ts │ │ │ ├── index.ts │ │ │ └── readDirectory.ts │ │ ├── types.d.ts │ │ ├── typescript │ │ │ ├── index.ts │ │ │ ├── public.ts │ │ │ └── tsInternal.ts │ │ └── utils │ │ │ ├── ArrayUtils.ts │ │ │ ├── CharCodes.ts │ │ │ ├── EventContainer.ts │ │ │ ├── IterableUtils.ts │ │ │ ├── ObjectUtils.ts │ │ │ ├── StringUtils.ts │ │ │ ├── deepClone.ts │ │ │ ├── index.ts │ │ │ └── nameof.ts │ ├── tsconfig.json │ └── tsconfig.rollup.json ├── scripts │ ├── changeTypeScriptVersion.ts │ ├── createDeclarationProject.ts │ ├── deps.ts │ ├── execScript.ts │ ├── folders.ts │ ├── getDevCompilerVersions.ts │ ├── mod.ts │ └── utils │ │ ├── Memoize.ts │ │ ├── forEachTypeText.ts │ │ ├── makeConstructorsPrivate.ts │ │ ├── mod.ts │ │ └── printDiagnostics.ts └── ts-morph │ ├── .mocharc.yml │ ├── .npmignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── breaking-changes.md │ ├── lib │ └── ts-morph.d.ts │ ├── package.json │ ├── readme.md │ ├── rollup.config.mjs │ ├── scripts │ ├── buildDeno.ts │ ├── common │ │ ├── cloning.ts │ │ ├── getDeclarationProject.ts │ │ ├── getProject.ts │ │ ├── hasInternalDocTag.ts │ │ ├── isNodeClass.ts │ │ ├── mod.ts │ │ └── typeHelpers.ts │ ├── config │ │ ├── isAllowedMixin.ts │ │ ├── isAllowedMixinForStructure.ts │ │ ├── isOverloadStructure.ts │ │ └── mod.ts │ ├── deps.ts │ ├── generation │ │ ├── createDeclarationFile.ts │ │ ├── createForEachStructureChild.ts │ │ ├── createGetStructureFunctions.ts │ │ ├── createKindToNodeMappings.ts │ │ ├── createNodeTypeGuards.ts │ │ ├── createStructurePrinterFactory.ts │ │ ├── createStructureTypeGuards.ts │ │ ├── declarationFile │ │ │ ├── getCodeBlockWriterStatements.ts │ │ │ ├── getDeclarationFileStatements.ts │ │ │ └── mod.ts │ │ ├── main.ts │ │ └── outputWrappedNodesInfo.ts │ ├── inspectors │ │ ├── InspectorFactory.ts │ │ ├── TsInspector.ts │ │ ├── TsMorphInspector.ts │ │ ├── WrapperFactory.ts │ │ ├── mod.ts │ │ ├── ts │ │ │ ├── TsNode.ts │ │ │ ├── TsNodeProperty.ts │ │ │ └── mod.ts │ │ └── tsMorph │ │ │ ├── KindToWrapperMapping.ts │ │ │ ├── Mixin.ts │ │ │ ├── Structure.ts │ │ │ ├── WrappedNode.ts │ │ │ └── mod.ts │ ├── markdown │ │ ├── CodeBlock.ts │ │ ├── MarkDownFile.ts │ │ ├── mod.ts │ │ └── parseMarkDown.ts │ ├── readme.md │ ├── test │ │ └── testTypeScriptVersions.ts │ ├── typeCheckDocumentation.ts │ ├── typeCheckLibrary.ts │ └── verification │ │ ├── Problem.ts │ │ ├── ensureArrayInputsReadonly.ts │ │ ├── ensureClassesImplementStructureMethods.ts │ │ ├── ensureMixinNotAppliedMultipleTimes.ts │ │ ├── ensureNoDeclarationFileErrors.ts │ │ ├── ensureNoProjectCompileErrors.ts │ │ ├── ensureOrThrowExists.ts │ │ ├── ensureOverloadStructuresMatch.ts │ │ ├── ensurePublicApiHasTests.ts │ │ ├── ensureStructuresMatchClasses.ts │ │ ├── main.ts │ │ ├── validateCodeFences.ts │ │ ├── validateCompilerNodeToWrappedType.ts │ │ └── validatePublicApiClassMemberNames.ts │ ├── src │ ├── Project.ts │ ├── ProjectContext.ts │ ├── codeBlockWriter │ │ ├── code-block-writer.ts │ │ └── index.ts │ ├── compiler │ │ ├── ast │ │ │ ├── CompilerNodeToWrappedType.ts │ │ │ ├── aliases.ts │ │ │ ├── base │ │ │ │ ├── AmbientableNode.ts │ │ │ │ ├── ArgumentedNode.ts │ │ │ │ ├── AsyncableNode.ts │ │ │ │ ├── AwaitableNode.ts │ │ │ │ ├── BodiedNode.ts │ │ │ │ ├── BodyableNode.ts │ │ │ │ ├── ChildOrderableNode.ts │ │ │ │ ├── DecoratableNode.ts │ │ │ │ ├── DotDotDotTokenableNode.ts │ │ │ │ ├── ExclamationTokenableNode.ts │ │ │ │ ├── ExtendsClauseableNode.ts │ │ │ │ ├── GeneratorableNode.ts │ │ │ │ ├── HeritageClauseableNode.ts │ │ │ │ ├── ImplementsClauseableNode.ts │ │ │ │ ├── JSDocableNode.ts │ │ │ │ ├── LiteralLikeNode.ts │ │ │ │ ├── ModifierableNode.ts │ │ │ │ ├── ModuledNode.ts │ │ │ │ ├── OverrideableNode.ts │ │ │ │ ├── ParameteredNode.ts │ │ │ │ ├── QuestionDotTokenableNode.ts │ │ │ │ ├── QuestionTokenableNode.ts │ │ │ │ ├── ReadonlyableNode.ts │ │ │ │ ├── ReturnTypedNode.ts │ │ │ │ ├── ScopeableNode.ts │ │ │ │ ├── ScopedNode.ts │ │ │ │ ├── SignaturedDeclaration.ts │ │ │ │ ├── StaticableNode.ts │ │ │ │ ├── TextInsertableNode.ts │ │ │ │ ├── TypeArgumentedNode.ts │ │ │ │ ├── TypeElementMemberedNode.ts │ │ │ │ ├── TypeParameteredNode.ts │ │ │ │ ├── TypedNode.ts │ │ │ │ ├── UnwrappableNode.ts │ │ │ │ ├── export │ │ │ │ │ ├── ExportGetableNode.ts │ │ │ │ │ ├── ExportableNode.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── helpers │ │ │ │ │ ├── getBodyText.ts │ │ │ │ │ ├── getBodyTextWithoutLeadingIndentation.ts │ │ │ │ │ ├── hasBlock.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── renameNode.ts │ │ │ │ │ └── setBodyTextForNode.ts │ │ │ │ ├── index.ts │ │ │ │ ├── initializer │ │ │ │ │ ├── InitializerExpressionGetableNode.ts │ │ │ │ │ ├── InitializerExpressionableNode.ts │ │ │ │ │ └── index.ts │ │ │ │ └── name │ │ │ │ │ ├── BindingNamedNode.ts │ │ │ │ │ ├── ImportAttributeNamedNode.ts │ │ │ │ │ ├── ModuleNamedNode.ts │ │ │ │ │ ├── NameableNode.ts │ │ │ │ │ ├── NamedNode.ts │ │ │ │ │ ├── NamedNodeBase.ts │ │ │ │ │ ├── PropertyNamedNode.ts │ │ │ │ │ ├── ReferenceFindableNode.ts │ │ │ │ │ ├── RenameableNode.ts │ │ │ │ │ └── index.ts │ │ │ ├── binding │ │ │ │ ├── ArrayBindingPattern.ts │ │ │ │ ├── BindingElement.ts │ │ │ │ ├── ObjectBindingPattern.ts │ │ │ │ └── index.ts │ │ │ ├── callBaseGetStructure.ts │ │ │ ├── callBaseSet.ts │ │ │ ├── class │ │ │ │ ├── ClassDeclaration.ts │ │ │ │ ├── ClassElement.ts │ │ │ │ ├── ClassExpression.ts │ │ │ │ ├── ClassStaticBlockDeclaration.ts │ │ │ │ ├── CommentClassElement.ts │ │ │ │ ├── ConstructorDeclaration.ts │ │ │ │ ├── GetAccessorDeclaration.ts │ │ │ │ ├── MethodDeclaration.ts │ │ │ │ ├── PropertyDeclaration.ts │ │ │ │ ├── SetAccessorDeclaration.ts │ │ │ │ ├── base │ │ │ │ │ ├── AbstractableNode.ts │ │ │ │ │ ├── ClassLikeDeclarationBase.ts │ │ │ │ │ └── index.ts │ │ │ │ └── index.ts │ │ │ ├── comment │ │ │ │ ├── CommentRange.ts │ │ │ │ ├── CompilerComments.ts │ │ │ │ └── index.ts │ │ │ ├── common │ │ │ │ ├── Node.ts │ │ │ │ ├── Scope.ts │ │ │ │ ├── SyntaxList.ts │ │ │ │ ├── TextRange.ts │ │ │ │ ├── TraversalControl.ts │ │ │ │ └── index.ts │ │ │ ├── decorator │ │ │ │ ├── Decorator.ts │ │ │ │ └── index.ts │ │ │ ├── doc │ │ │ │ ├── JSDoc.ts │ │ │ │ ├── JSDocAllType.ts │ │ │ │ ├── JSDocAugmentsTag.ts │ │ │ │ ├── JSDocAuthorTag.ts │ │ │ │ ├── JSDocCallbackTag.ts │ │ │ │ ├── JSDocClassTag.ts │ │ │ │ ├── JSDocDeprecatedTag.ts │ │ │ │ ├── JSDocEnumTag.ts │ │ │ │ ├── JSDocFunctionType.ts │ │ │ │ ├── JSDocImplementsTag.ts │ │ │ │ ├── JSDocLink.ts │ │ │ │ ├── JSDocLinkCode.ts │ │ │ │ ├── JSDocLinkPlain.ts │ │ │ │ ├── JSDocMemberName.ts │ │ │ │ ├── JSDocNameReference.ts │ │ │ │ ├── JSDocNamepathType.ts │ │ │ │ ├── JSDocNonNullableType.ts │ │ │ │ ├── JSDocNullableType.ts │ │ │ │ ├── JSDocOptionalType.ts │ │ │ │ ├── JSDocOverloadTag.ts │ │ │ │ ├── JSDocOverrideTag.ts │ │ │ │ ├── JSDocParameterTag.ts │ │ │ │ ├── JSDocPrivateTag.ts │ │ │ │ ├── JSDocPropertyTag.ts │ │ │ │ ├── JSDocProtectedTag.ts │ │ │ │ ├── JSDocPublicTag.ts │ │ │ │ ├── JSDocReadonlyTag.ts │ │ │ │ ├── JSDocReturnTag.ts │ │ │ │ ├── JSDocSatisfiesTag.ts │ │ │ │ ├── JSDocSeeTag.ts │ │ │ │ ├── JSDocSignature.ts │ │ │ │ ├── JSDocTag.ts │ │ │ │ ├── JSDocTagInfo.ts │ │ │ │ ├── JSDocTemplateTag.ts │ │ │ │ ├── JSDocText.ts │ │ │ │ ├── JSDocThisTag.ts │ │ │ │ ├── JSDocThrowsTag.ts │ │ │ │ ├── JSDocType.ts │ │ │ │ ├── JSDocTypeExpression.ts │ │ │ │ ├── JSDocTypeLiteral.ts │ │ │ │ ├── JSDocTypeTag.ts │ │ │ │ ├── JSDocTypedefTag.ts │ │ │ │ ├── JSDocUnknownTag.ts │ │ │ │ ├── JSDocUnknownType.ts │ │ │ │ ├── JSDocVariadicType.ts │ │ │ │ ├── base │ │ │ │ │ ├── JSDocPropertyLikeTag.ts │ │ │ │ │ ├── JSDocTypeExpressionableTag.ts │ │ │ │ │ ├── JSDocTypeParameteredTag.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ └── utils │ │ │ │ │ └── getTextWithoutStars.ts │ │ │ ├── enum │ │ │ │ ├── CommentEnumMember.ts │ │ │ │ ├── EnumDeclaration.ts │ │ │ │ ├── EnumMember.ts │ │ │ │ └── index.ts │ │ │ ├── expression │ │ │ │ ├── AsExpression.ts │ │ │ │ ├── AssignmentExpression.ts │ │ │ │ ├── AwaitExpression.ts │ │ │ │ ├── BinaryExpression.ts │ │ │ │ ├── CallExpression.ts │ │ │ │ ├── CommaListExpression.ts │ │ │ │ ├── ConditionalExpression.ts │ │ │ │ ├── DeleteExpression.ts │ │ │ │ ├── ElementAccessExpression.ts │ │ │ │ ├── Expression.ts │ │ │ │ ├── ImportExpression.ts │ │ │ │ ├── LeftHandSideExpression.ts │ │ │ │ ├── LiteralExpression.ts │ │ │ │ ├── MemberExpression.ts │ │ │ │ ├── MetaProperty.ts │ │ │ │ ├── NewExpression.ts │ │ │ │ ├── NonNullExpression.ts │ │ │ │ ├── OmittedExpression.ts │ │ │ │ ├── ParenthesizedExpression.ts │ │ │ │ ├── PartiallyEmittedExpression.ts │ │ │ │ ├── PostfixUnaryExpression.ts │ │ │ │ ├── PrefixUnaryExpression.ts │ │ │ │ ├── PrimaryExpression.ts │ │ │ │ ├── PropertyAccessExpression.ts │ │ │ │ ├── SatisfiesExpression.ts │ │ │ │ ├── SpreadElement.ts │ │ │ │ ├── SuperElementAccessExpression.ts │ │ │ │ ├── SuperExpression.ts │ │ │ │ ├── SuperPropertyAccessExpression.ts │ │ │ │ ├── ThisExpression.ts │ │ │ │ ├── TypeAssertion.ts │ │ │ │ ├── TypeOfExpression.ts │ │ │ │ ├── UnaryExpression.ts │ │ │ │ ├── UpdateExpression.ts │ │ │ │ ├── VoidExpression.ts │ │ │ │ ├── YieldExpression.ts │ │ │ │ ├── array │ │ │ │ │ ├── ArrayDestructuringAssignment.ts │ │ │ │ │ ├── ArrayLiteralExpression.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── expressioned │ │ │ │ │ ├── ExpressionableNode.ts │ │ │ │ │ ├── ExpressionedNode.ts │ │ │ │ │ ├── ImportExpressionedNode.ts │ │ │ │ │ ├── LeftHandSideExpressionedNode.ts │ │ │ │ │ ├── SuperExpressionedNode.ts │ │ │ │ │ ├── UnaryExpressionedNode.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── index.ts │ │ │ │ └── object │ │ │ │ │ ├── CommentObjectLiteralElement.ts │ │ │ │ │ ├── ObjectDestructuringAssignment.ts │ │ │ │ │ ├── ObjectLiteralElement.ts │ │ │ │ │ ├── ObjectLiteralExpression.ts │ │ │ │ │ ├── PropertyAssignment.ts │ │ │ │ │ ├── ShorthandPropertyAssignment.ts │ │ │ │ │ ├── SpreadAssignment.ts │ │ │ │ │ └── index.ts │ │ │ ├── function │ │ │ │ ├── ArrowFunction.ts │ │ │ │ ├── FunctionDeclaration.ts │ │ │ │ ├── FunctionExpression.ts │ │ │ │ ├── FunctionLikeDeclaration.ts │ │ │ │ ├── OverloadableNode.ts │ │ │ │ ├── ParameterDeclaration.ts │ │ │ │ └── index.ts │ │ │ ├── general │ │ │ │ ├── HeritageClause.ts │ │ │ │ └── index.ts │ │ │ ├── index.ts │ │ │ ├── interface │ │ │ │ ├── CallSignatureDeclaration.ts │ │ │ │ ├── CommentTypeElement.ts │ │ │ │ ├── ConstructSignatureDeclaration.ts │ │ │ │ ├── IndexSignatureDeclaration.ts │ │ │ │ ├── InterfaceDeclaration.ts │ │ │ │ ├── MethodSignature.ts │ │ │ │ ├── PropertySignature.ts │ │ │ │ ├── TypeElement.ts │ │ │ │ └── index.ts │ │ │ ├── jsx │ │ │ │ ├── JsxAttribute.ts │ │ │ │ ├── JsxClosingElement.ts │ │ │ │ ├── JsxClosingFragment.ts │ │ │ │ ├── JsxElement.ts │ │ │ │ ├── JsxExpression.ts │ │ │ │ ├── JsxFragment.ts │ │ │ │ ├── JsxNamespacedName.ts │ │ │ │ ├── JsxOpeningElement.ts │ │ │ │ ├── JsxOpeningFragment.ts │ │ │ │ ├── JsxSelfClosingElement.ts │ │ │ │ ├── JsxSpreadAttribute.ts │ │ │ │ ├── JsxText.ts │ │ │ │ ├── base │ │ │ │ │ ├── JsxAttributedNode.ts │ │ │ │ │ ├── JsxTagNamedNode.ts │ │ │ │ │ └── index.ts │ │ │ │ └── index.ts │ │ │ ├── kindToNodeMappings.generated.ts │ │ │ ├── literal │ │ │ │ ├── BigIntLiteral.ts │ │ │ │ ├── BooleanLiterals.ts │ │ │ │ ├── NullLiteral.ts │ │ │ │ ├── NumericLiteral.ts │ │ │ │ ├── QuoteKind.ts │ │ │ │ ├── RegularExpressionLiteral.ts │ │ │ │ ├── StringLiteral.ts │ │ │ │ ├── index.ts │ │ │ │ └── template │ │ │ │ │ ├── NoSubstitutionTemplateLiteral.ts │ │ │ │ │ ├── TaggedTemplateExpression.ts │ │ │ │ │ ├── TemplateExpression.ts │ │ │ │ │ ├── TemplateHead.ts │ │ │ │ │ ├── TemplateMiddle.ts │ │ │ │ │ ├── TemplateSpan.ts │ │ │ │ │ ├── TemplateTail.ts │ │ │ │ │ └── index.ts │ │ │ ├── module │ │ │ │ ├── ExportAssignment.ts │ │ │ │ ├── ExportDeclaration.ts │ │ │ │ ├── ExportSpecifier.ts │ │ │ │ ├── ExternalModuleReference.ts │ │ │ │ ├── ImportAttribute.ts │ │ │ │ ├── ImportAttributes.ts │ │ │ │ ├── ImportClause.ts │ │ │ │ ├── ImportDeclaration.ts │ │ │ │ ├── ImportEqualsDeclaration.ts │ │ │ │ ├── ImportSpecifier.ts │ │ │ │ ├── ModuleBlock.ts │ │ │ │ ├── ModuleChildableNode.ts │ │ │ │ ├── ModuleDeclaration.ts │ │ │ │ ├── ModuleDeclarationKind.ts │ │ │ │ ├── NamedExports.ts │ │ │ │ ├── NamedImports.ts │ │ │ │ ├── NamespaceExport.ts │ │ │ │ ├── NamespaceImport.ts │ │ │ │ ├── SourceFile.ts │ │ │ │ ├── index.ts │ │ │ │ └── results │ │ │ │ │ ├── FileReference.ts │ │ │ │ │ ├── FileSystemRefreshResult.ts │ │ │ │ │ └── index.ts │ │ │ ├── name │ │ │ │ ├── ComputedPropertyName.ts │ │ │ │ ├── Identifier.ts │ │ │ │ ├── PrivateIdentifier.ts │ │ │ │ ├── QualifiedName.ts │ │ │ │ ├── base │ │ │ │ │ ├── CommonIdentifierBase.ts │ │ │ │ │ └── index.ts │ │ │ │ └── index.ts │ │ │ ├── statement │ │ │ │ ├── Block.ts │ │ │ │ ├── BreakStatement.ts │ │ │ │ ├── CaseBlock.ts │ │ │ │ ├── CaseClause.ts │ │ │ │ ├── CatchClause.ts │ │ │ │ ├── CommentStatement.ts │ │ │ │ ├── ContinueStatement.ts │ │ │ │ ├── DebuggerStatement.ts │ │ │ │ ├── DefaultClause.ts │ │ │ │ ├── DoStatement.ts │ │ │ │ ├── EmptyStatement.ts │ │ │ │ ├── ExpressionStatement.ts │ │ │ │ ├── ForInStatement.ts │ │ │ │ ├── ForOfStatement.ts │ │ │ │ ├── ForStatement.ts │ │ │ │ ├── IfStatement.ts │ │ │ │ ├── IterationStatement.ts │ │ │ │ ├── LabeledStatement.ts │ │ │ │ ├── NotEmittedStatement.ts │ │ │ │ ├── ReturnStatement.ts │ │ │ │ ├── Statement.ts │ │ │ │ ├── StatementedNode.ts │ │ │ │ ├── SwitchStatement.ts │ │ │ │ ├── ThrowStatement.ts │ │ │ │ ├── TryStatement.ts │ │ │ │ ├── VariableStatement.ts │ │ │ │ ├── WhileStatement.ts │ │ │ │ ├── WithStatement.ts │ │ │ │ └── index.ts │ │ │ ├── type │ │ │ │ ├── ArrayTypeNode.ts │ │ │ │ ├── ConditionalTypeNode.ts │ │ │ │ ├── ConstructorTypeNode.ts │ │ │ │ ├── ExpressionWithTypeArguments.ts │ │ │ │ ├── FunctionOrConstructorTypeNodeBase.ts │ │ │ │ ├── FunctionTypeNode.ts │ │ │ │ ├── ImportTypeNode.ts │ │ │ │ ├── IndexedAccessTypeNode.ts │ │ │ │ ├── InferTypeNode.ts │ │ │ │ ├── IntersectionTypeNode.ts │ │ │ │ ├── LiteralTypeNode.ts │ │ │ │ ├── MappedTypeNode.ts │ │ │ │ ├── NamedTupleMember.ts │ │ │ │ ├── ParenthesizedTypeNode.ts │ │ │ │ ├── RestTypeNode.ts │ │ │ │ ├── TemplateLiteralTypeNode.ts │ │ │ │ ├── ThisTypeNode.ts │ │ │ │ ├── TupleTypeNode.ts │ │ │ │ ├── TypeAliasDeclaration.ts │ │ │ │ ├── TypeLiteralNode.ts │ │ │ │ ├── TypeNode.ts │ │ │ │ ├── TypeOperatorTypeNode.ts │ │ │ │ ├── TypeParameterDeclaration.ts │ │ │ │ ├── TypePredicateNode.ts │ │ │ │ ├── TypeQueryNode.ts │ │ │ │ ├── TypeReferenceNode.ts │ │ │ │ ├── UnionTypeNode.ts │ │ │ │ └── index.ts │ │ │ ├── utils │ │ │ │ ├── CommentNodeParser.ts │ │ │ │ ├── ExtendedParser.ts │ │ │ │ ├── index.ts │ │ │ │ └── isComment.ts │ │ │ └── variable │ │ │ │ ├── VariableDeclaration.ts │ │ │ │ ├── VariableDeclarationKind.ts │ │ │ │ ├── VariableDeclarationList.ts │ │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── symbols │ │ │ ├── Signature.ts │ │ │ ├── Symbol.ts │ │ │ └── index.ts │ │ ├── tools │ │ │ ├── LanguageService.ts │ │ │ ├── Program.ts │ │ │ ├── TypeChecker.ts │ │ │ ├── index.ts │ │ │ ├── inputs │ │ │ │ ├── FormatCodeSettings.ts │ │ │ │ ├── RenameOptions.ts │ │ │ │ ├── UserPreferences.ts │ │ │ │ └── index.ts │ │ │ └── results │ │ │ │ ├── CodeAction.ts │ │ │ │ ├── CodeFixAction.ts │ │ │ │ ├── CombinedCodeActions.ts │ │ │ │ ├── DefinitionInfo.ts │ │ │ │ ├── Diagnostic.ts │ │ │ │ ├── DiagnosticMessageChain.ts │ │ │ │ ├── DiagnosticWithLocation.ts │ │ │ │ ├── DocumentSpan.ts │ │ │ │ ├── EmitOutput.ts │ │ │ │ ├── EmitResult.ts │ │ │ │ ├── FileTextChanges.ts │ │ │ │ ├── ImplementationLocation.ts │ │ │ │ ├── MemoryEmitResult.ts │ │ │ │ ├── OutputFile.ts │ │ │ │ ├── RefactorEditInfo.ts │ │ │ │ ├── ReferenceEntry.ts │ │ │ │ ├── ReferencedSymbol.ts │ │ │ │ ├── ReferencedSymbolDefinitionInfo.ts │ │ │ │ ├── RenameLocation.ts │ │ │ │ ├── SymbolDisplayPart.ts │ │ │ │ ├── TextChange.ts │ │ │ │ ├── TextSpan.ts │ │ │ │ └── index.ts │ │ └── types │ │ │ ├── Type.ts │ │ │ ├── TypeParameter.ts │ │ │ └── index.ts │ ├── factories │ │ ├── CompilerFactory.ts │ │ ├── DirectoryCache.ts │ │ ├── ForgetfulNodeCache.ts │ │ ├── InProjectCoordinator.ts │ │ ├── StructurePrinterFactory.ts │ │ ├── index.ts │ │ └── kindToWrapperMappings.ts │ ├── fileSystem │ │ ├── Directory.ts │ │ ├── DirectoryCoordinator.ts │ │ ├── DirectoryEmitResult.ts │ │ └── index.ts │ ├── main.ts │ ├── manipulation │ │ ├── code │ │ │ ├── getNewInsertCode.ts │ │ │ └── index.ts │ │ ├── formatting │ │ │ ├── FormattingKind.ts │ │ │ ├── getClassMemberFormatting.ts │ │ │ ├── getFormattingKindText.ts │ │ │ ├── getGeneralFormatting.ts │ │ │ ├── getInterfaceMemberFormatting.ts │ │ │ ├── getStatementedNodeChildFormatting.ts │ │ │ ├── getTextFromFormattingEdits.ts │ │ │ ├── hasBody.ts │ │ │ └── index.ts │ │ ├── helpers │ │ │ ├── appendCommaToText.ts │ │ │ ├── getEndIndexFromArray.ts │ │ │ ├── getInsertPosFromIndex.ts │ │ │ ├── getMixinStructureFunctions.ts │ │ │ ├── getNodesToReturn.ts │ │ │ ├── getRangeWithoutCommentsFromArray.ts │ │ │ ├── getStructureFunctions.ts │ │ │ ├── index.ts │ │ │ └── verifyAndGetIndex.ts │ │ ├── index.ts │ │ ├── manipulations │ │ │ ├── ManipulationError.ts │ │ │ ├── doManipulation.ts │ │ │ ├── index.ts │ │ │ ├── insertion.ts │ │ │ ├── move.ts │ │ │ ├── removal.ts │ │ │ └── replaction.ts │ │ ├── nodeHandlers │ │ │ ├── ChangeChildOrderParentHandler.ts │ │ │ ├── DefaultParentHandler.ts │ │ │ ├── ForgetChangedNodeHandler.ts │ │ │ ├── NodeHandler.ts │ │ │ ├── NodeHandlerFactory.ts │ │ │ ├── NodeHandlerHelper.ts │ │ │ ├── ParentFinderReplacementNodeHandler.ts │ │ │ ├── RangeHandler.ts │ │ │ ├── RangeParentHandler.ts │ │ │ ├── RenameNodeHandler.ts │ │ │ ├── StraightReplacementNodeHandler.ts │ │ │ ├── TryOrForgetNodeHandler.ts │ │ │ ├── UnwrapParentHandler.ts │ │ │ └── index.ts │ │ ├── readme.md │ │ ├── textChecks.ts │ │ ├── textManipulators │ │ │ ├── ChangingChildOrderTextManipulator.ts │ │ │ ├── FullReplacementTextManipulator.ts │ │ │ ├── InsertionTextManipulator.ts │ │ │ ├── RemoveChildrenTextManipulator.ts │ │ │ ├── RemoveChildrenWithFormattingTextManipulator.ts │ │ │ ├── RenameLocationTextManipulator.ts │ │ │ ├── TextManipulator.ts │ │ │ ├── UnchangedTextManipulator.ts │ │ │ ├── UnwrapTextManipulator.ts │ │ │ ├── getSpacingBetweenNodes.ts │ │ │ ├── getTextForError.ts │ │ │ └── index.ts │ │ └── textSeek │ │ │ ├── getNextMatchingPos.ts │ │ │ ├── getNextNonWhitespacePos.ts │ │ │ ├── getPosAfterNewLine.ts │ │ │ ├── getPosAfterPreviousNonBlankLine.ts │ │ │ ├── getPosAtEndOfPreviousLine.ts │ │ │ ├── getPosAtEndOfPreviousLineOrNonWhitespace.ts │ │ │ ├── getPosAtNextNonBlankLine.ts │ │ │ ├── getPosAtStartOfLineOrNonWhitespace.ts │ │ │ ├── getPreviousMatchingPos.ts │ │ │ └── index.ts │ ├── next-major-deprecations.md │ ├── options │ │ ├── ManipulationSettingsContainer.ts │ │ └── index.ts │ ├── structurePrinters │ │ ├── NodePrinter.ts │ │ ├── Printer.ts │ │ ├── Writers.ts │ │ ├── base │ │ │ ├── InitializerExpressionableNodeStructurePrinter.ts │ │ │ ├── ModifierableNodeStructurePrinter.ts │ │ │ ├── ReturnTypedNodeStructurePrinter.ts │ │ │ ├── TypedNodeStructurePrinter.ts │ │ │ └── index.ts │ │ ├── class │ │ │ ├── ClassDeclarationStructurePrinter.ts │ │ │ ├── ClassMemberStructurePrinter.ts │ │ │ ├── ClassStaticBlockDeclarationStructurePrinter.ts │ │ │ ├── ConstructorDeclarationStructurePrinter.ts │ │ │ ├── GetAccessorDeclarationStructurePrinter.ts │ │ │ ├── GetAndSetAccessorStructurePrinter.ts │ │ │ ├── MethodDeclarationStructurePrinter.ts │ │ │ ├── PropertyDeclarationStructurePrinter.ts │ │ │ ├── SetAccessorDeclarationStructurePrinter.ts │ │ │ └── index.ts │ │ ├── common │ │ │ ├── StringStructurePrinter.ts │ │ │ └── index.ts │ │ ├── decorator │ │ │ ├── DecoratorStructurePrinter.ts │ │ │ └── index.ts │ │ ├── doc │ │ │ ├── JSDocStructurePrinter.ts │ │ │ ├── JSDocTagStructurePrinter.ts │ │ │ └── index.ts │ │ ├── enum │ │ │ ├── EnumDeclarationStructurePrinter.ts │ │ │ ├── EnumMemberStructurePrinter.ts │ │ │ └── index.ts │ │ ├── expression │ │ │ ├── index.ts │ │ │ └── object │ │ │ │ ├── ObjectLiteralExpressionPropertyStructurePrinter.ts │ │ │ │ ├── PropertyAssignmentStructurePrinter.ts │ │ │ │ ├── ShorthandPropertyAssignmentStructurePrinter.ts │ │ │ │ ├── SpreadAssignmentStructurePrinter.ts │ │ │ │ └── index.ts │ │ ├── formatting │ │ │ ├── BlankLineFormattingStructuresPrinter.ts │ │ │ ├── CommaNewLineSeparatedStructuresPrinter.ts │ │ │ ├── CommaSeparatedStructuresPrinter.ts │ │ │ ├── NewLineFormattingStructuresPrinter.ts │ │ │ ├── SpaceFormattingStructuresPrinter.ts │ │ │ └── index.ts │ │ ├── function │ │ │ ├── FunctionDeclarationStructurePrinter.ts │ │ │ ├── ParameterDeclarationStructurePrinter.ts │ │ │ └── index.ts │ │ ├── helpers │ │ │ ├── index.ts │ │ │ └── writerUtils.ts │ │ ├── index.ts │ │ ├── interface │ │ │ ├── CallSignatureDeclarationStructurePrinter.ts │ │ │ ├── ConstructSignatureDeclarationStructurePrinter.ts │ │ │ ├── IndexSignatureDeclarationStructurePrinter.ts │ │ │ ├── InterfaceDeclarationStructurePrinter.ts │ │ │ ├── MethodSignatureStructurePrinter.ts │ │ │ ├── PropertySignatureStructurePrinter.ts │ │ │ ├── TypeElementMemberStructurePrinter.ts │ │ │ ├── TypeElementMemberedNodeStructurePrinter.ts │ │ │ └── index.ts │ │ ├── jsx │ │ │ ├── JsxAttributeDeciderStructurePrinter.ts │ │ │ ├── JsxAttributeStructurePrinter.ts │ │ │ ├── JsxChildDeciderStructurePrinter.ts │ │ │ ├── JsxElementStructurePrinter.ts │ │ │ ├── JsxNamespacedNameStructurePrinter.ts │ │ │ ├── JsxSelfClosingElementStructurePrinter.ts │ │ │ ├── JsxSpreadAttributeStructurePrinter.ts │ │ │ └── index.ts │ │ ├── module │ │ │ ├── ExportAssignmentStructurePrinter.ts │ │ │ ├── ExportDeclarationStructurePrinter.ts │ │ │ ├── ImportAttributeStructurePrinter.ts │ │ │ ├── ImportDeclarationStructurePrinter.ts │ │ │ ├── ModuleDeclarationStructurePrinter.ts │ │ │ ├── NamedImportExportSpecifierStructurePrinter.ts │ │ │ ├── SourceFileStructurePrinter.ts │ │ │ └── index.ts │ │ ├── statement │ │ │ ├── StatementStructurePrinter.ts │ │ │ ├── StatementedNodeStructurePrinter.ts │ │ │ ├── VariableStatementStructurePrinter.ts │ │ │ └── index.ts │ │ ├── types │ │ │ ├── TypeAliasDeclarationStructurePrinter.ts │ │ │ ├── TypeParameterDeclarationStructurePrinter.ts │ │ │ └── index.ts │ │ └── variable │ │ │ ├── VariableDeclarationStructurePrinter.ts │ │ │ └── index.ts │ ├── structures │ │ ├── Structure.generated.ts │ │ ├── StructureKind.ts │ │ ├── aliases.ts │ │ ├── base │ │ │ ├── AbstractableNodeStructure.ts │ │ │ ├── AmbientableNodeStructure.ts │ │ │ ├── AsyncableNodeStructure.ts │ │ │ ├── AwaitableNodeStructure.ts │ │ │ ├── DecoratableNodeStructure.ts │ │ │ ├── ExclamationTokenableNodeStructure.ts │ │ │ ├── ExportableNodeStructure.ts │ │ │ ├── ExtendsClauseableNodeStructure.ts │ │ │ ├── GeneratorableNodeStructure.ts │ │ │ ├── ImplementsClauseableNodeStructure.ts │ │ │ ├── InitializerExpressionableNodeStructure.ts │ │ │ ├── JSDocableNodeStructure.ts │ │ │ ├── OverrideableNodeStructure.ts │ │ │ ├── ParameteredNodeStructure.ts │ │ │ ├── QuestionDotTokenableNodeStructure.ts │ │ │ ├── QuestionTokenableNodeStructure.ts │ │ │ ├── ReadonlyableNodeStructure.ts │ │ │ ├── ReturnTypedNodeStructure.ts │ │ │ ├── ScopeableNodeStructure.ts │ │ │ ├── ScopedNodeStructure.ts │ │ │ ├── SignaturedDeclarationStructure.ts │ │ │ ├── StaticableNodeStructure.ts │ │ │ ├── TypeElementMemberedNodeStructure.ts │ │ │ ├── TypeParameteredNodeStructure.ts │ │ │ ├── TypedNodeStructure.ts │ │ │ ├── index.ts │ │ │ └── name │ │ │ │ ├── BindingNamedNodeStructure.ts │ │ │ │ ├── ImportAttributeNamedNodeStructure.ts │ │ │ │ ├── ModuleNamedNodeStructure.ts │ │ │ │ ├── NameableNodeStructure.ts │ │ │ │ ├── NamedNodeStructure.ts │ │ │ │ ├── PropertyNameableNodeStructure.ts │ │ │ │ ├── PropertyNamedNodeStructure.ts │ │ │ │ └── index.ts │ │ ├── class │ │ │ ├── ClassDeclarationStructure.ts │ │ │ ├── ClassStaticBlockDeclarationStructure.ts │ │ │ ├── ConstructorDeclarationStructure.ts │ │ │ ├── GetAccessorDeclarationStructure.ts │ │ │ ├── MethodDeclarationStructure.ts │ │ │ ├── PropertyDeclarationStructure.ts │ │ │ ├── SetAccessorDeclarationStructure.ts │ │ │ ├── base │ │ │ │ ├── ClassLikeDeclarationBaseStructure.ts │ │ │ │ └── index.ts │ │ │ └── index.ts │ │ ├── decorator │ │ │ ├── DecoratorStructure.ts │ │ │ └── index.ts │ │ ├── doc │ │ │ ├── JSDocStructure.ts │ │ │ ├── JSDocTagStructure.ts │ │ │ └── index.ts │ │ ├── enum │ │ │ ├── EnumDeclarationStructure.ts │ │ │ ├── EnumMemberStructure.ts │ │ │ └── index.ts │ │ ├── expression │ │ │ ├── expressioned │ │ │ │ ├── ExpressionedNodeStructure.ts │ │ │ │ └── index.ts │ │ │ ├── index.ts │ │ │ └── object │ │ │ │ ├── PropertyAssignmentStructure.ts │ │ │ │ ├── ShorthandPropertyAssignmentStructure.ts │ │ │ │ ├── SpreadAssignmentStructure.ts │ │ │ │ └── index.ts │ │ ├── function │ │ │ ├── FunctionDeclarationStructure.ts │ │ │ ├── FunctionLikeDeclarationStructure.ts │ │ │ ├── ParameterDeclarationStructure.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── interface │ │ │ ├── CallSignatureDeclarationStructure.ts │ │ │ ├── ConstructSignatureDeclarationStructure.ts │ │ │ ├── IndexSignatureDeclarationStructure.ts │ │ │ ├── InterfaceDeclarationStructure.ts │ │ │ ├── MethodSignatureStructure.ts │ │ │ ├── PropertySignatureStructure.ts │ │ │ └── index.ts │ │ ├── jsx │ │ │ ├── JsxAttributeStructure.ts │ │ │ ├── JsxElementStructure.ts │ │ │ ├── JsxNamespacedNameStructure.ts │ │ │ ├── JsxSelfClosingElementStructure.ts │ │ │ ├── JsxSpreadAttributeStructure.ts │ │ │ ├── base │ │ │ │ ├── JsxAttributedNodeStructure.ts │ │ │ │ ├── JsxTagNamedNodeStructure.ts │ │ │ │ └── index.ts │ │ │ └── index.ts │ │ ├── module │ │ │ ├── ExportAssignmentStructure.ts │ │ │ ├── ExportDeclarationStructure.ts │ │ │ ├── ExportSpecifierStructure.ts │ │ │ ├── ImportAttributeStructure.ts │ │ │ ├── ImportDeclarationStructure.ts │ │ │ ├── ImportSpecifierStructure.ts │ │ │ ├── ModuleDeclarationStructure.ts │ │ │ ├── SourceFileStructure.ts │ │ │ └── index.ts │ │ ├── statement │ │ │ ├── StatementedNodeStructure.ts │ │ │ ├── VariableDeclarationStructure.ts │ │ │ ├── VariableStatementStructure.ts │ │ │ └── index.ts │ │ ├── type │ │ │ ├── TypeAliasDeclarationStructure.ts │ │ │ ├── TypeParameterDeclarationStructure.ts │ │ │ └── index.ts │ │ ├── types.ts │ │ └── utils │ │ │ ├── forEachStructureChild.ts │ │ │ └── index.ts │ ├── tests │ │ ├── compiler │ │ │ ├── ast │ │ │ │ ├── base │ │ │ │ │ ├── ambientableNodeTests.ts │ │ │ │ │ ├── argumentedNodeTests.ts │ │ │ │ │ ├── asyncableNodeTests.ts │ │ │ │ │ ├── awaitableNodeTests.ts │ │ │ │ │ ├── bodiedNodeTests.ts │ │ │ │ │ ├── bodyableNodeTests.ts │ │ │ │ │ ├── childOrderableNodeTests.ts │ │ │ │ │ ├── decoratableNodeTests.ts │ │ │ │ │ ├── exclamationTokenableNodeTests.ts │ │ │ │ │ ├── export │ │ │ │ │ │ ├── exportGetableNodeTests.ts │ │ │ │ │ │ └── exportableNodeTests.ts │ │ │ │ │ ├── extendsClauseableNodeTests.ts │ │ │ │ │ ├── generatorableNodeTests.ts │ │ │ │ │ ├── heritageClauseableNodeTests.ts │ │ │ │ │ ├── implementsClauseableNodeTests.ts │ │ │ │ │ ├── initializer │ │ │ │ │ │ ├── initializerExpressionGetableNodeTests.ts │ │ │ │ │ │ └── initializerExpressionableNodeTests.ts │ │ │ │ │ ├── jsDocableNodeTests.ts │ │ │ │ │ ├── literalLikeNodeTests.ts │ │ │ │ │ ├── modifierableNodeTests.ts │ │ │ │ │ ├── moduledNodeTests.ts │ │ │ │ │ ├── name │ │ │ │ │ │ ├── bindingNamedNodeTests.ts │ │ │ │ │ │ ├── nameableNodeTests.ts │ │ │ │ │ │ ├── namedNodeTests.ts │ │ │ │ │ │ └── propertyNamedNodeTests.ts │ │ │ │ │ ├── overrideableNodeTest.ts │ │ │ │ │ ├── parameteredNodeTests.ts │ │ │ │ │ ├── questionDotTokenableNodeTests.ts │ │ │ │ │ ├── questionTokenableNodeTests.ts │ │ │ │ │ ├── readonlyableNodeTests.ts │ │ │ │ │ ├── returnTypedNodeTests.ts │ │ │ │ │ ├── scopeableNodeTests.ts │ │ │ │ │ ├── scopedNodeTests.ts │ │ │ │ │ ├── staticableNodeTests.ts │ │ │ │ │ ├── textInsertableNodeTests.ts │ │ │ │ │ ├── typeArgumentedNodeTests.ts │ │ │ │ │ ├── typeElementMemberedNodeTests.ts │ │ │ │ │ ├── typeParameteredNodeTests.ts │ │ │ │ │ ├── typedNodeTests.ts │ │ │ │ │ └── unwrappableNodeTests.ts │ │ │ │ ├── bindings │ │ │ │ │ ├── arrayBindingPatternTests.ts │ │ │ │ │ ├── bindingElementTests.ts │ │ │ │ │ └── objectBindingPatternTests.ts │ │ │ │ ├── class │ │ │ │ │ ├── base │ │ │ │ │ │ ├── abstractableNodeTests.ts │ │ │ │ │ │ └── classLikeDeclarationBaseTests.ts │ │ │ │ │ ├── classDeclarationTests.ts │ │ │ │ │ ├── commentClassElementTests.ts │ │ │ │ │ ├── constructorDeclarationTests.ts │ │ │ │ │ ├── getAccessorDeclarationTests.ts │ │ │ │ │ ├── methodDeclarationTests.ts │ │ │ │ │ ├── propertyDeclarationTests.ts │ │ │ │ │ └── setAccessorDeclarationTests.ts │ │ │ │ ├── comment │ │ │ │ │ ├── commentNodeTests.ts │ │ │ │ │ └── compilerCommentsTests.ts │ │ │ │ ├── common │ │ │ │ │ ├── commentRangeTests.ts │ │ │ │ │ ├── nodeTests.ts │ │ │ │ │ ├── nodeTypeGuardsTests.ts │ │ │ │ │ └── syntaxListTests.ts │ │ │ │ ├── decorator │ │ │ │ │ └── decoratorTests.ts │ │ │ │ ├── doc │ │ │ │ │ ├── base │ │ │ │ │ │ └── jsDocPropertyLikeTagTests.ts │ │ │ │ │ ├── jsDocFunctionTypeTests.ts │ │ │ │ │ ├── jsDocReturnTagTests.ts │ │ │ │ │ ├── jsDocSignatureTests.ts │ │ │ │ │ ├── jsDocTagTests.ts │ │ │ │ │ ├── jsDocTemplateTagTests.ts │ │ │ │ │ ├── jsDocTests.ts │ │ │ │ │ ├── jsDocThisTagTests.ts │ │ │ │ │ ├── jsDocTypeExpressionTests.ts │ │ │ │ │ └── jsDocTypeTagTests.ts │ │ │ │ ├── enum │ │ │ │ │ ├── enumDeclarationTests.ts │ │ │ │ │ └── enumMemberTests.ts │ │ │ │ ├── expression │ │ │ │ │ ├── array │ │ │ │ │ │ ├── arrayDestructuringAssignmentTests.ts │ │ │ │ │ │ └── arrayLiteralExpressionTests.ts │ │ │ │ │ ├── assignmentExpressionTests.ts │ │ │ │ │ ├── binaryExpressionTests.ts │ │ │ │ │ ├── callExpressionTests.ts │ │ │ │ │ ├── conditionalExpressionTests.ts │ │ │ │ │ ├── elementAccessExpressionTests.ts │ │ │ │ │ ├── expressionTests.ts │ │ │ │ │ ├── expressioned │ │ │ │ │ │ ├── expressionedNodeTests.ts │ │ │ │ │ │ ├── importExpressionedNodeTests.ts │ │ │ │ │ │ ├── leftHandSideExpressionedNodeTests.ts │ │ │ │ │ │ ├── superExpressionedNodeTests.ts │ │ │ │ │ │ └── unaryExpressionedNodeTests.ts │ │ │ │ │ ├── metaPropertyTests.ts │ │ │ │ │ ├── object │ │ │ │ │ │ ├── commentObjectLiteralElementTests.ts │ │ │ │ │ │ ├── objectDestructuringAssignmentTests.ts │ │ │ │ │ │ ├── objectLiteralExpressionTests.ts │ │ │ │ │ │ ├── propertyAssignmentTests.ts │ │ │ │ │ │ ├── shorthandPropertyAssignmentTests.ts │ │ │ │ │ │ └── spreadAssignmentTests.ts │ │ │ │ │ ├── postfixUnaryExpression.ts │ │ │ │ │ ├── prefixUnaryExpressionTests.ts │ │ │ │ │ ├── propertyAccessExpressionTests.ts │ │ │ │ │ └── yieldExpressionTests.ts │ │ │ │ ├── function │ │ │ │ │ ├── arrowFunctionTests.ts │ │ │ │ │ ├── functionDeclarationTests.ts │ │ │ │ │ ├── overloadableNodeTests.ts │ │ │ │ │ └── parameterDeclarationTests.ts │ │ │ │ ├── general │ │ │ │ │ └── heritageClauseTests.ts │ │ │ │ ├── interface │ │ │ │ │ ├── callSignatureDeclarationTests.ts │ │ │ │ │ ├── commentTypeElementTests.ts │ │ │ │ │ ├── constructSignatureDeclarationTests.ts │ │ │ │ │ ├── indexSignatureDeclarationTests.ts │ │ │ │ │ ├── interfaceDeclarationTests.ts │ │ │ │ │ ├── methodSignatureTests.ts │ │ │ │ │ └── propertySignatureTests.ts │ │ │ │ ├── jsx │ │ │ │ │ ├── base │ │ │ │ │ │ └── jsxAttributedNodeTests.ts │ │ │ │ │ ├── jsxAttributeTests.ts │ │ │ │ │ ├── jsxClosingElementTests.ts │ │ │ │ │ ├── jsxElementTests.ts │ │ │ │ │ ├── jsxExpressionTests.ts │ │ │ │ │ ├── jsxFragmentTests.ts │ │ │ │ │ ├── jsxOpeningElementTests.ts │ │ │ │ │ ├── jsxSelfClosingElementTests.ts │ │ │ │ │ ├── jsxSpreadAttributeTests.ts │ │ │ │ │ └── jsxTextTests.ts │ │ │ │ ├── literal │ │ │ │ │ ├── bigIntLiteralTests.ts │ │ │ │ │ ├── booleanLiteralsTests.ts │ │ │ │ │ ├── numericLiteralTests.ts │ │ │ │ │ ├── regularExpressionLiteralTests.ts │ │ │ │ │ ├── stringLiteralTests.ts │ │ │ │ │ └── template │ │ │ │ │ │ ├── noSubstitutionTemplateLiteralTests.ts │ │ │ │ │ │ ├── taggedTemplateExpressionTests.ts │ │ │ │ │ │ ├── templateExpressionTests.ts │ │ │ │ │ │ └── templateSpanTests.ts │ │ │ │ ├── module │ │ │ │ │ ├── exportAssignmentTests.ts │ │ │ │ │ ├── exportDeclarationTests.ts │ │ │ │ │ ├── exportSpecifierTests.ts │ │ │ │ │ ├── externalModuleReferenceTests.ts │ │ │ │ │ ├── importAttributeTests.ts │ │ │ │ │ ├── importDeclarationTests.ts │ │ │ │ │ ├── importEqualsDeclarationTests.ts │ │ │ │ │ ├── importSpecifierTests.ts │ │ │ │ │ ├── moduleChildableNode.ts │ │ │ │ │ ├── moduleDeclarationTests.ts │ │ │ │ │ ├── namedExportsTests.ts │ │ │ │ │ ├── namedImportsTests.ts │ │ │ │ │ ├── namespaceExportTests.ts │ │ │ │ │ ├── namespaceImportTests.ts │ │ │ │ │ └── sourceFileTests.ts │ │ │ │ ├── name │ │ │ │ │ ├── computedPropertyNameTests.ts │ │ │ │ │ ├── identifierTests.ts │ │ │ │ │ ├── privateIdentifierTests.ts │ │ │ │ │ └── qualifiedNameTests.ts │ │ │ │ ├── statement │ │ │ │ │ ├── breakStatementTests.ts │ │ │ │ │ ├── caseBlockTests.ts │ │ │ │ │ ├── caseClauseTests.ts │ │ │ │ │ ├── catchClauseTests.ts │ │ │ │ │ ├── continueStatementTests.ts │ │ │ │ │ ├── defaultClauseTests.ts │ │ │ │ │ ├── doStatementTests.ts │ │ │ │ │ ├── expressionStatementTests.ts │ │ │ │ │ ├── forInStatementTests.ts │ │ │ │ │ ├── forOfStatementTests.ts │ │ │ │ │ ├── forStatementTests.ts │ │ │ │ │ ├── ifStatementTests.ts │ │ │ │ │ ├── iterationStatementTests.ts │ │ │ │ │ ├── labeledStatementTests.ts │ │ │ │ │ ├── returnStatementTests.ts │ │ │ │ │ ├── statementTests.ts │ │ │ │ │ ├── statementedNode │ │ │ │ │ │ ├── classTests.ts │ │ │ │ │ │ ├── enumTests.ts │ │ │ │ │ │ ├── functionTests.ts │ │ │ │ │ │ ├── generalTests.ts │ │ │ │ │ │ ├── interfaceTests.ts │ │ │ │ │ │ ├── moduleTests.ts │ │ │ │ │ │ ├── typeAliasTests.ts │ │ │ │ │ │ └── variableTests.ts │ │ │ │ │ ├── statementedNodeTests.ts │ │ │ │ │ ├── switchStatementTests.ts │ │ │ │ │ ├── throwStatementTests.ts │ │ │ │ │ ├── tryStatementTests.ts │ │ │ │ │ ├── variableDeclarationListTests.ts │ │ │ │ │ ├── variableDeclarationTests.ts │ │ │ │ │ ├── variableStatementTests.ts │ │ │ │ │ ├── whileStatementTests.ts │ │ │ │ │ └── withStatementTests.ts │ │ │ │ ├── type │ │ │ │ │ ├── arrayTypeNodeTests.ts │ │ │ │ │ ├── conditionalTypeNodeTests.ts │ │ │ │ │ ├── constructorTypeNodeTests.ts │ │ │ │ │ ├── expressionWithTypeArgumentsTests.ts │ │ │ │ │ ├── functionTypeNodeTests.ts │ │ │ │ │ ├── importTypeNodeTests.ts │ │ │ │ │ ├── indexedAccessTypeNodeTests.ts │ │ │ │ │ ├── inferTypeNodeTests.ts │ │ │ │ │ ├── intersectionTypeNodeTests.ts │ │ │ │ │ ├── literalTypeNodeTests.ts │ │ │ │ │ ├── mappedTypeNodeTests.ts │ │ │ │ │ ├── namedTupleMemberTests.ts │ │ │ │ │ ├── parenthesizedTypeNodeTests.ts │ │ │ │ │ ├── restTypeNodeTest.ts │ │ │ │ │ ├── templateLiteralTypeNodeTests.ts │ │ │ │ │ ├── thisTypeNodeTests.ts │ │ │ │ │ ├── tupleTypeNodeTests.ts │ │ │ │ │ ├── typeAliasDeclarationTests.ts │ │ │ │ │ ├── typeOperatorTypeNodeTests.ts │ │ │ │ │ ├── typeParameterDeclarationTests.ts │ │ │ │ │ ├── typePredicateNodeTests.ts │ │ │ │ │ ├── typeQueryNodeTests.ts │ │ │ │ │ ├── typeReferenceTests.ts │ │ │ │ │ └── unionTypeNodeTests.ts │ │ │ │ └── utils │ │ │ │ │ ├── commentNodeParserTests.ts │ │ │ │ │ └── extendedParserTests.ts │ │ │ ├── symbols │ │ │ │ ├── signatureTests.ts │ │ │ │ └── symbolTests.ts │ │ │ ├── testHelpers │ │ │ │ ├── fillStructureWithDefaults.ts │ │ │ │ ├── getInfoFromText.ts │ │ │ │ ├── index.ts │ │ │ │ └── types.ts │ │ │ ├── tools │ │ │ │ ├── diagnosticMessageChainTests.ts │ │ │ │ ├── diagnosticTests.ts │ │ │ │ ├── emitResultTests.ts │ │ │ │ ├── errors.ts │ │ │ │ ├── languageServiceTests.ts │ │ │ │ ├── programTests.ts │ │ │ │ ├── results │ │ │ │ │ ├── combinedCodeActionsTests.ts │ │ │ │ │ ├── fileTextChangesTests.ts │ │ │ │ │ ├── memoryEmitResultTests.ts │ │ │ │ │ └── refactorEditInfoTests.ts │ │ │ │ └── typeCheckerTests.ts │ │ │ └── type │ │ │ │ ├── typeParameterTests.ts │ │ │ │ └── typeTests.ts │ │ ├── factories │ │ │ └── forgetfulNodeCacheTests.ts │ │ ├── fileSystem │ │ │ └── directoryTests.ts │ │ ├── issues │ │ │ ├── 0038tests.ts │ │ │ ├── 0053tests.ts │ │ │ ├── 0057tests.ts │ │ │ ├── 0076tests.ts │ │ │ ├── 0089tests.ts │ │ │ ├── 0090tests.ts │ │ │ ├── 0189tests.ts │ │ │ ├── 0265tests.ts │ │ │ ├── 0312tests.ts │ │ │ ├── 0328tests.ts │ │ │ ├── 0335tests.ts │ │ │ ├── 0336tests.ts │ │ │ ├── 0344tests.ts │ │ │ ├── 0365tests.ts │ │ │ ├── 0394tests.ts │ │ │ ├── 0397tests.ts │ │ │ ├── 0405tests.ts │ │ │ ├── 0413tests.ts │ │ │ ├── 0414tests.ts │ │ │ ├── 0415tests.ts │ │ │ ├── 0421tests.ts │ │ │ ├── 0424tests.ts │ │ │ ├── 0437tests.ts │ │ │ ├── 0450tests.ts │ │ │ ├── 0460tests.ts │ │ │ ├── 0464tests.ts │ │ │ ├── 0474tests.ts │ │ │ ├── 0484tests.ts │ │ │ ├── 0494tests.ts │ │ │ ├── 0519tests.ts │ │ │ ├── 0534tests.ts │ │ │ ├── 0560tests.ts │ │ │ ├── 0654tests.ts │ │ │ ├── 0665tests.ts │ │ │ ├── 0708tests.ts │ │ │ ├── 0735tests.ts │ │ │ ├── 0745tests.ts │ │ │ ├── 0778tests.ts │ │ │ ├── 0817tests.ts │ │ │ ├── 0823tests.ts │ │ │ ├── 0836tests.ts │ │ │ ├── 0840tests.ts │ │ │ ├── 0844tests.ts │ │ │ ├── 0854tests.ts │ │ │ ├── 0867tests.ts │ │ │ ├── 1164tests.ts │ │ │ ├── 1171tests.ts │ │ │ ├── 1198tests.ts │ │ │ ├── 1227tests.ts │ │ │ ├── 1244tests.ts │ │ │ └── 1273tests.ts │ │ ├── manipulation │ │ │ ├── getEndIndexFromArray.ts │ │ │ ├── getMixinStructureFunctionsTests.ts │ │ │ ├── helpers │ │ │ │ └── appendCommaToTextTests.ts │ │ │ ├── manipulations │ │ │ │ ├── doManipulationTests.ts │ │ │ │ └── insertIntoCommaSeparatedNodesTests.ts │ │ │ ├── textChecks │ │ │ │ └── isBlankLineAtPosTests.ts │ │ │ ├── textSeek │ │ │ │ ├── getNextNonWhitespacePosTests.ts │ │ │ │ ├── getPosAfterPreviousNonBlankLineTests.ts │ │ │ │ └── getPosAtNextNonBlankLineTests.ts │ │ │ └── verifyAndGetIndexTests.ts │ │ ├── manipulationSettingsTests.ts │ │ ├── projectTests.ts │ │ ├── structurePrinters │ │ │ ├── base │ │ │ │ ├── initializerExpressionableNodeStructurePrinterTests.ts │ │ │ │ ├── returnTypedNodeStructurePrinterTests.ts │ │ │ │ └── typedNodeStructurePrinterTests.ts │ │ │ ├── class │ │ │ │ ├── classDeclarationStructurePrinterTests.ts │ │ │ │ ├── methodDeclarationStructurePrinterTests.ts │ │ │ │ └── propertyDeclarationStructurePrinterTests.ts │ │ │ ├── decorator │ │ │ │ └── decoratorStructurePrinterTests.ts │ │ │ ├── doc │ │ │ │ ├── jsDocStructurePrinterTests.ts │ │ │ │ └── jsDocTagStructurePrinterTests.ts │ │ │ ├── function │ │ │ │ └── parameterDeclarationStructurePrinterTests.ts │ │ │ ├── interface │ │ │ │ └── interfaceDeclarationStructurePrinterTests.ts │ │ │ ├── module │ │ │ │ ├── exportAssignmentStructurePrinterTests.ts │ │ │ │ ├── exportDeclarationStructurePrinterTests.ts │ │ │ │ ├── importDeclarationStructurePrinterTests.ts │ │ │ │ └── namedImportExportSpecifierStructurePrinterTests.ts │ │ │ ├── nodePrinterTests.ts │ │ │ ├── type │ │ │ │ └── typeParameterDeclarationStructurePrinterTests.ts │ │ │ └── writersTests.ts │ │ ├── structures │ │ │ └── utils │ │ │ │ ├── forEachStructureChildTests.ts │ │ │ │ └── structureTypeGuardTests.ts │ │ ├── testFiles │ │ │ ├── index.ts │ │ │ ├── testClasses.ts │ │ │ └── testInterfaces.ts │ │ ├── testHelpers │ │ │ ├── fileSystemHostHelpers.ts │ │ │ ├── getDefaultFormatCodeSettings.ts │ │ │ ├── index.ts │ │ │ └── testDirectoryTree.ts │ │ └── utils │ │ │ ├── advancedIteratorTests.ts │ │ │ ├── compiler │ │ │ ├── createWrappedNodeTests.ts │ │ │ └── printNodeTests.ts │ │ │ ├── newLineKindToStringTests.ts │ │ │ ├── tsconfig │ │ │ └── getCompilerOptionsFromTsConfigTests.ts │ │ │ └── writerUtilsTests.ts │ ├── types.ts │ ├── typings.ts │ └── utils │ │ ├── AdvancedIterator.ts │ │ ├── CharCodes.ts │ │ ├── TypeScriptVersionChecker.ts │ │ ├── WriterUtils.ts │ │ ├── compiler │ │ ├── ModuleUtils.ts │ │ ├── createWrappedNode.ts │ │ ├── getNodeByNameOrFindFunction.ts │ │ ├── getParentSyntaxList.ts │ │ ├── getSymbolByNameOrFindFunction.ts │ │ ├── index.ts │ │ ├── isNodeAmbientOrInAmbientContext.ts │ │ ├── isStringKind.ts │ │ └── printNode.ts │ │ ├── fillDefaultEditorSettings.ts │ │ ├── fillDefaultFormatCodeSettings.ts │ │ ├── getTextFromStringOrWriter.ts │ │ ├── index.ts │ │ ├── logging │ │ ├── ConsoleLogger.ts │ │ ├── EnableableLogger.ts │ │ ├── Logger.ts │ │ └── index.ts │ │ ├── namingValidator.ts │ │ ├── newLineKindToString.ts │ │ ├── references │ │ ├── LazyReferenceCoordinator.ts │ │ ├── SourceFileReferenceContainer.ts │ │ └── index.ts │ │ ├── setValueIfUndefined.ts │ │ └── tsconfig │ │ ├── getCompilerOptionsFromTsConfig.ts │ │ └── index.ts │ ├── tsconfig.declarations.json │ ├── tsconfig.json │ ├── tsconfig.rollup.json │ └── wrapped-nodes.md ├── readme.md ├── rfcs ├── README.md └── RFC-0001 - Inserting Into Statements Handling Comments.md └── tsconfig.common.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | 7 | [*.ts] 8 | indent_style = space 9 | indent_size = 2 10 | trim_trailing_whitespace = true 11 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # force lf newlines 2 | * text=auto eol=lf 3 | 4 | *.ts text eol=lf 5 | *.js text eol=lf 6 | *.json text eol=lf 7 | *.md text eol=lf 8 | *.sh text eol=lf 9 | 10 | *.jpg binary 11 | *.png binary 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Anything else... Please do not submit bugs using this... 4 | --- 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea 4 | --- 5 | 6 | 7 | 8 | **Is your feature request related to a problem? Please describe.** 9 | 10 | 11 | 12 | **Describe the solution you'd like** 13 | 14 | 15 | 16 | **Describe alternatives you've considered** 17 | 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /docs/Gemfile.lock 2 | /docs/_site 3 | /deno 4 | packages/*/node_modules 5 | packages/*/temp 6 | packages/*/dist-cg 7 | packages/*/dist 8 | packages/*/dist-deno 9 | packages/*/dist-scripts 10 | packages/*/dist-declarations 11 | node_modules 12 | *.js.map 13 | npm-debug.log 14 | 15 | #IDE 16 | .idea 17 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "prettier.enable": false, 3 | "deno.enablePaths": [ 4 | "deno", 5 | "packages/bootstrap/scripts/", 6 | "packages/common/scripts/", 7 | "packages/scripts/", 8 | "packages/ts-morph/scripts/" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "unstable": [ 3 | "sloppy-imports", 4 | "bare-node-builtins", 5 | "detect-cjs", 6 | "node-globals" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | ts-morph.com -------------------------------------------------------------------------------- /docs/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'github-pages', group: :jekyll_plugins -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | repository: dsherret/ts-morph 2 | port: 4001 3 | title: ts-morph 4 | description: TypeScript Compiler API wrapper for static analysis and programmatic code changes. 5 | markdown: GFM 6 | -------------------------------------------------------------------------------- /docs/details/async.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Async 3 | --- 4 | 5 | ## Async 6 | 7 | Certain nodes in TypeScript can have an `async` keyword modifier. 8 | 9 | ### Is async 10 | 11 | A node can be tested if it's async using the `isAsync()` method: 12 | 13 | ```ts 14 | functionDeclaration.isAsync(); // returns: boolean 15 | ``` 16 | 17 | ### `async` keyword 18 | 19 | Get the `async` keyword if it exists: 20 | 21 | ```ts 22 | functionDeclaration.getAsyncKeyword(); 23 | ``` 24 | 25 | ### Set async 26 | 27 | Set if the declaration is async using `setIsAsync`: 28 | 29 | ```ts 30 | functionDeclaration.setIsAsync(true); 31 | ``` 32 | -------------------------------------------------------------------------------- /docs/details/comment-ranges.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Comment Ranges 3 | --- 4 | 5 | ## Comment Ranges 6 | 7 | See [Comments](comments.md). 8 | -------------------------------------------------------------------------------- /docs/details/generators.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Generators 3 | --- 4 | 5 | ## Generators 6 | 7 | Nodes like `FunctionDeclaration` and `MethodDeclaration` can be generators. 8 | 9 | ### Tell if a generator 10 | 11 | ```ts 12 | functionDeclaration.isGenerator(); // returns: boolean 13 | ``` 14 | 15 | ### Set as a generator 16 | 17 | ```ts 18 | functionDeclaration.setIsGenerator(true); // or false to set as not one 19 | ``` 20 | 21 | ### Get asterisk token (`*`) 22 | 23 | Gets the asterisk token or undefined if not exists: 24 | 25 | ```ts 26 | functionDeclaration.getAsteriskToken(); 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/details/literals.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Literals 3 | --- 4 | 5 | ## Literals 6 | 7 | Literals: 8 | 9 | - `StringLiteral` (ex. `"some string"`) 10 | - `NumericLiteral` (ex. `5`, `10.53`) 11 | - `TrueLiteral` / `FalseLiteral` (ex. `true` / `false`) 12 | - `NoSubstitutionTemplateLiteral` (ex. `` `some string` ``) 13 | - `RegularExpressionLiteral` (ex. `/pattern/gi`) 14 | 15 | Methods: 16 | 17 | - `.getLiteralValue()` - Returns the string, number, boolean, or RegExp value. 18 | - `.setLiteralValue(...)` - Allows setting the literal value. 19 | - `isTerminated()` - If the literal is terminated. 20 | - `hasExtendedUnicodeEscape()` - If the literal has a unicode escape (ex. `\u{20bb7}`) 21 | -------------------------------------------------------------------------------- /docs/details/namespaces.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Namespaces 3 | --- 4 | 5 | ## Namespaces 6 | 7 | See [Modules](modules). 8 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Documentation 3 | --- 4 | 5 | ## Purpose 6 | 7 | Setup, navigation, and manipulation of the TypeScript AST can be a challenge. This library wraps the TypeScript compiler API so it's simple. 8 | 9 | ## Installing 10 | 11 | Install as usual via npm: 12 | 13 | ``` 14 | npm install --save-dev ts-morph 15 | ``` 16 | 17 | Or if you're using Deno and want to install via JSR: 18 | 19 | ``` 20 | deno add ts-morph@jsr:@ts-morph/ts-morph 21 | ``` 22 | 23 | ## Documentation Progress 24 | 25 | I've been still slowly updating the documentation. I'm keeping it up to date with any new features, but some existing features don't have documentation. 26 | -------------------------------------------------------------------------------- /docs/manipulation/code-writer.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Code Writer 3 | --- 4 | 5 | ## Code Writer 6 | 7 | With manipulation methods that accept a `string` for the new code, it's possible to write text using a provided [code-block-writer](https://github.com/dsherret/code-block-writer). 8 | 9 | Using the writer is very useful because it will write code out using the indentation and newline settings of the project. It's also easier to use. 10 | 11 | ### Example 12 | 13 | ```ts 14 | functionDeclaration.setBodyText(writer => 15 | writer.writeLine("let myNumber = 5;") 16 | .write("if (myNumber === 5)").block(() => { 17 | writer.writeLine("console.log('yes')"); 18 | }) 19 | ); 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/manipulation/order.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Order 3 | --- 4 | 5 | ## Order 6 | 7 | Change the order of certain nodes using the `.setOrder(newIndex: number)` method. 8 | 9 | ```ts 10 | const interfaceDeclaration = sourceFile.getInterfaceOrThrow("MyInterface"); 11 | interfaceDeclaration.setOrder(2); 12 | ``` 13 | 14 | Notice: Right now this is not supported on comma separated nodes. See [Issue #44](https://github.com/dsherret/ts-morph/issues/44) for more information. 15 | -------------------------------------------------------------------------------- /docs/metrics/performance.json: -------------------------------------------------------------------------------- 1 | { 2 | "1": { "name": "Renaming Performance Test", "runs": [{ "dateTime": 1555118846870, "duration": 10905, "version": "1.3.2" }] }, 3 | "2": { "name": "Removing Performance Test", "runs": [{ "dateTime": 1555118846870, "duration": 14834, "version": "1.3.2" }] } 4 | } 5 | -------------------------------------------------------------------------------- /docs/navigation/ambient-modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ambient Modules 3 | --- 4 | 5 | ## Ambient Modules 6 | 7 | The ambient module symbols can be retrieved by calling: 8 | 9 | ```ts 10 | const ambientModules = project.getAmbientModules(); 11 | ``` 12 | 13 | This will return the ambient modules resolved by the compiler (ex. ambient modules in `@types` or `node_modules`). 14 | 15 | ### Getting by name 16 | 17 | Get an ambient module symbol based on its name: 18 | 19 | ```ts 20 | const jQuerySymbol = project.getAmbientModule("jquery"); // returns: Symbol | undefined 21 | const momentSymbol = project.getAmbientModuleOrThrow("moment"); // returns: Symbol 22 | ``` 23 | -------------------------------------------------------------------------------- /docs/navigation/images/getChildrenVsForEachChild.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsherret/ts-morph/fa5d14dc8a12640c74ef45b42b84565742c47db5/docs/navigation/images/getChildrenVsForEachChild.gif -------------------------------------------------------------------------------- /docs/navigation/language-service.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Language Service 3 | --- 4 | 5 | ## Language Service 6 | 7 | Get the language service by calling: 8 | 9 | ```ts 10 | const languageService = project.getLanguageService(); 11 | ``` 12 | 13 | ### Underlying compiler object 14 | 15 | The underlying `ts.LanguageService` can be retrieved as follows: 16 | 17 | ```ts 18 | const tsLanguageService = languageService.compilerObject; 19 | ``` 20 | 21 | ### Use 22 | 23 | Generally you won't need to use the language service because most of the functionality is exposed as methods on other objects. 24 | -------------------------------------------------------------------------------- /docs/navigation/program.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Program 3 | --- 4 | 5 | ## Program 6 | 7 | Get the program by calling: 8 | 9 | ```ts 10 | const program = project.getProgram(); 11 | ``` 12 | 13 | ### Underlying compiler object 14 | 15 | The underlying `ts.Program` can be retrieved as follows: 16 | 17 | ```ts 18 | const tsProgram = program.compilerObject; 19 | ``` 20 | 21 | **Warning:** The underlying compiler object will be discared whenever manipulation occurs. For that reason, only hold onto the underlying compiler object between manipulations. 22 | 23 | ### Use 24 | 25 | Generally you won't need to use the program because most of the functionality is exposed as methods on other objects. 26 | -------------------------------------------------------------------------------- /docs/setup/images/atom-ast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsherret/ts-morph/fa5d14dc8a12640c74ef45b42b84565742c47db5/docs/setup/images/atom-ast.png -------------------------------------------------------------------------------- /docs/setup/images/atom-ast_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsherret/ts-morph/fa5d14dc8a12640c74ef45b42b84565742c47db5/docs/setup/images/atom-ast_small.png -------------------------------------------------------------------------------- /docs/setup/images/atom-command-palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsherret/ts-morph/fa5d14dc8a12640c74ef45b42b84565742c47db5/docs/setup/images/atom-command-palette.png -------------------------------------------------------------------------------- /docs/setup/images/atom-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsherret/ts-morph/fa5d14dc8a12640c74ef45b42b84565742c47db5/docs/setup/images/atom-file.png -------------------------------------------------------------------------------- /docs/setup/images/ts-ast-viewer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsherret/ts-morph/fa5d14dc8a12640c74ef45b42b84565742c47db5/docs/setup/images/ts-ast-viewer.png -------------------------------------------------------------------------------- /dprint.json: -------------------------------------------------------------------------------- 1 | { 2 | "indentWidth": 2, 3 | "lineWidth": 160, 4 | "typescript": { 5 | "useBraces": "preferNone" 6 | }, 7 | "excludes": [ 8 | "**/node_modules", 9 | "**/*-lock.json", 10 | "packages/*/dist/", 11 | "packages/*/lib/*.ts", 12 | "**/CHANGELOG.md", 13 | "packages/ts-morph/src/compiler/ast/common/Node.ts", 14 | "./deno", 15 | "dist-deno" 16 | ], 17 | "plugins": [ 18 | "https://plugins.dprint.dev/typescript-0.95.3.wasm", 19 | "https://plugins.dprint.dev/json-0.20.0.wasm", 20 | "https://plugins.dprint.dev/markdown-0.18.0.wasm" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/bootstrap/.mocharc.yml: -------------------------------------------------------------------------------- 1 | recursive: true 2 | reporter: progress 3 | timeout: 10000 4 | spec: src/tests/**/*.ts 5 | -------------------------------------------------------------------------------- /packages/bootstrap/.npmignore: -------------------------------------------------------------------------------- 1 | /scripts 2 | /src 3 | azure-pipelines.yml 4 | .mocharc.yml 5 | .npmignore 6 | CHANGELOG.md 7 | rollup.config.mjs 8 | tsconfig.json 9 | tsconfig.*.json 10 | yarn-error.log 11 | # do not include lock files to allow releasing only ts-morph/common 12 | yarn.lock 13 | package-lock.json 14 | dist-deno 15 | -------------------------------------------------------------------------------- /packages/bootstrap/rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import typescript from "@rollup/plugin-typescript"; 2 | const isDeno = process.env.BUILD === "deno"; 3 | const outputFolder = isDeno ? "./dist-deno" : "./dist"; 4 | const moduleKind = isDeno ? "es" : "cjs"; 5 | 6 | export default { 7 | input: "./src/index.ts", 8 | external: [], 9 | output: { 10 | file: outputFolder + "/ts-morph-bootstrap.js", 11 | format: moduleKind, 12 | interop: "compat", 13 | }, 14 | plugins: [ 15 | typescript({ 16 | tsconfig: "tsconfig.rollup.json", 17 | outDir: outputFolder, 18 | }), 19 | ], 20 | }; 21 | -------------------------------------------------------------------------------- /packages/bootstrap/scripts/deps.ts: -------------------------------------------------------------------------------- 1 | export * from "../../scripts/mod.ts"; 2 | -------------------------------------------------------------------------------- /packages/bootstrap/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | CompilerOptionsContainer, 3 | FileSystemHost, 4 | InMemoryFileSystemHost, 5 | ResolutionHost, 6 | ResolutionHostFactory, 7 | ResolutionHosts, 8 | SettingsContainer, 9 | ts, 10 | } from "@ts-morph/common"; 11 | export * from "./Project"; 12 | -------------------------------------------------------------------------------- /packages/bootstrap/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.common.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "rootDir": "./src", 6 | "outDir": "./dist" 7 | }, 8 | "include": [ 9 | "./src" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/bootstrap/tsconfig.rollup.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "es2015", 5 | "moduleResolution": "node", 6 | "removeComments": true 7 | }, 8 | "exclude": [ 9 | "lib", 10 | "scripts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/common/.mocharc.yml: -------------------------------------------------------------------------------- 1 | recursive: true 2 | reporter: progress 3 | timeout: 10000 4 | spec: src/tests/**/*.ts 5 | -------------------------------------------------------------------------------- /packages/common/.npmignore: -------------------------------------------------------------------------------- 1 | /.vscode 2 | /scripts 3 | /src 4 | /dist-deno 5 | .mocharc.yml 6 | .npmignore 7 | CHANGELOG.md 8 | rollup.config.mjs 9 | tsconfig.json 10 | tsconfig.*.json 11 | yarn-error.log 12 | -------------------------------------------------------------------------------- /packages/common/readme.md: -------------------------------------------------------------------------------- 1 | # @ts-morph/common 2 | 3 | Common functionality for [ts-morph](../ts-morph) and [@ts-morph/bootstrap](../bootstrap). 4 | 5 | Please do not depend on this library! 6 | -------------------------------------------------------------------------------- /packages/common/rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import typescript from "@rollup/plugin-typescript"; 2 | const isDeno = process.env.BUILD === "deno"; 3 | const outputFolder = isDeno ? "./dist-deno" : "./dist"; 4 | const moduleKind = isDeno ? "es" : "cjs"; 5 | 6 | export default [{ 7 | input: ["./src/index.ts"], 8 | external: [], 9 | output: { 10 | file: outputFolder + "/ts-morph-common.js", 11 | format: moduleKind, 12 | interop: "compat", 13 | }, 14 | plugins: [ 15 | typescript({ 16 | tsconfig: "tsconfig.rollup.json", 17 | outDir: outputFolder, 18 | }), 19 | ], 20 | }]; 21 | -------------------------------------------------------------------------------- /packages/common/scripts/deps.ts: -------------------------------------------------------------------------------- 1 | export { createMinifier as createDtsMinifier } from "https://deno.land/x/dts_minify@0.3.2/mod.ts"; 2 | export * from "../../scripts/mod.ts"; 3 | -------------------------------------------------------------------------------- /packages/common/src/collections/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./KeyValueCache"; 2 | export * from "./SortedKeyValueArray"; 3 | export * from "./WeakCache"; 4 | -------------------------------------------------------------------------------- /packages/common/src/comparers/Comparer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Compares two values specifying the sort order. 3 | */ 4 | export interface Comparer { 5 | /** 6 | * Checks the two items returning -1 if `a` preceeds, 0 if equal, and 1 if `a` follows. 7 | * @param a - Item to use. 8 | * @param b - Item to compare with. 9 | */ 10 | compareTo(a: T, b: T): number; 11 | } 12 | -------------------------------------------------------------------------------- /packages/common/src/comparers/LocaleStringComparer.ts: -------------------------------------------------------------------------------- 1 | import { Comparer } from "./Comparer"; 2 | 3 | /** 4 | * Compares two strings by en-us-u-kf-upper locale. 5 | */ 6 | export class LocaleStringComparer implements Comparer { 7 | /** Static instance for reuse. */ 8 | static readonly instance = new LocaleStringComparer(); 9 | 10 | /** @inheritdoc */ 11 | compareTo(a: string, b: string) { 12 | // always use en-us so everyone gets the same behaviour 13 | const comparisonResult = a.localeCompare(b, "en-us-u-kf-upper"); 14 | 15 | if (comparisonResult < 0) 16 | return -1; 17 | else if (comparisonResult === 0) 18 | return 0; 19 | return 1; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/common/src/comparers/StoredComparer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Compares a value against a stored value. 3 | */ 4 | export interface StoredComparer { 5 | /** 6 | * Checks the value against a stored value returning -1 if the stored value preceeds, 0 if the value is equal, and 1 if follows. 7 | * @param value - Value to compare. 8 | */ 9 | compareTo(value: T): number; 10 | } 11 | -------------------------------------------------------------------------------- /packages/common/src/comparers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Comparer"; 2 | export * from "./ComparerToStoredComparer"; 3 | export * from "./LocaleStringComparer"; 4 | export * from "./PropertyComparer"; 5 | export * from "./PropertyStoredComparer"; 6 | export * from "./StoredComparer"; 7 | -------------------------------------------------------------------------------- /packages/common/src/compiler/createCompilerSourceFile.ts: -------------------------------------------------------------------------------- 1 | import { StandardizedFilePath } from "../fileSystem"; 2 | import { ScriptKind, ts } from "../typescript"; 3 | 4 | export function createCompilerSourceFile( 5 | filePath: StandardizedFilePath, 6 | scriptSnapshot: ts.IScriptSnapshot, 7 | optionsOrScriptTarget: ts.ScriptTarget | ts.CreateSourceFileOptions | undefined, 8 | version: string, 9 | setParentNodes: boolean, 10 | scriptKind: ScriptKind | undefined, 11 | ) { 12 | return ts.createLanguageServiceSourceFile( 13 | filePath, 14 | scriptSnapshot, 15 | optionsOrScriptTarget ?? ts.ScriptTarget.Latest, 16 | version, 17 | setParentNodes, 18 | scriptKind, 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /packages/common/src/compiler/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./createDocumentCache"; 2 | export * from "./createHosts"; 3 | export * from "./createModuleResolutionHost"; 4 | export * from "./DocumentRegistry"; 5 | export * from "./ResolutionHost"; 6 | export * from "./TsSourceFileContainer"; 7 | -------------------------------------------------------------------------------- /packages/common/src/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Memoize"; 2 | -------------------------------------------------------------------------------- /packages/common/src/fileSystem/StandardizedFilePath.ts: -------------------------------------------------------------------------------- 1 | /** Nominal type to denote a file path that has been standardized. */ 2 | export type StandardizedFilePath = string & { _standardizedFilePathBrand: undefined }; 3 | -------------------------------------------------------------------------------- /packages/common/src/fileSystem/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./FileSystemHost"; 2 | export * from "./FileUtils"; 3 | export * from "./InMemoryFileSystemHost"; 4 | export * from "./matchGlobs"; 5 | export * from "./RealFileSystemHost"; 6 | export * from "./StandardizedFilePath"; 7 | export * from "./TransactionalFileSystem"; 8 | -------------------------------------------------------------------------------- /packages/common/src/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getSyntaxKindName"; 2 | -------------------------------------------------------------------------------- /packages/common/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./collections"; 2 | export * from "./comparers"; 3 | export * from "./compiler"; 4 | export * from "./decorators"; 5 | export * from "./errors"; 6 | export * from "./fileSystem"; 7 | export * from "./getLibFiles"; 8 | export * from "./helpers"; 9 | export * from "./options"; 10 | export * from "./runtimes"; 11 | export { CompilerOptionsFromTsConfigOptions, CompilerOptionsFromTsConfigResult, getCompilerOptionsFromTsConfig, TsConfigResolver } from "./tsconfig"; 12 | export * from "./typescript"; 13 | export * from "./utils"; 14 | -------------------------------------------------------------------------------- /packages/common/src/options/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CompilerOptionsContainer"; 2 | export * from "./SettingsContainer"; 3 | -------------------------------------------------------------------------------- /packages/common/src/runtimes/getRuntime.ts: -------------------------------------------------------------------------------- 1 | import { BrowserRuntime } from "./BrowserRuntime"; 2 | import { NodeRuntime } from "./NodeRuntime"; 3 | import { Runtime } from "./Runtime"; 4 | 5 | export const runtime = getRuntime(); 6 | 7 | function getRuntime(): Runtime { 8 | if (isNodeJs()) 9 | return new NodeRuntime(); 10 | else 11 | return new BrowserRuntime(); 12 | } 13 | 14 | function isNodeJs() { 15 | // https://stackoverflow.com/a/31456668/188246 16 | return typeof globalThis.process === "object" 17 | && typeof globalThis.process.versions === "object" 18 | && typeof globalThis.process.versions.node !== "undefined"; 19 | } 20 | -------------------------------------------------------------------------------- /packages/common/src/runtimes/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getRuntime"; 2 | export * from "./Runtime"; 3 | -------------------------------------------------------------------------------- /packages/common/src/tests/collections/keyValueCacheTests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { KeyValueCache } from "../../collections"; 3 | import { nameof } from "../../utils"; 4 | 5 | // todo: more tests 6 | 7 | describe("KeyValueCache", () => { 8 | describe(nameof>("replaceKey"), () => { 9 | it("should throw when replacing a key that doesn't exist", () => { 10 | const cache = new KeyValueCache<{}, {}>(); 11 | expect(() => cache.replaceKey({}, {})).to.throw(Error, "Key not found."); 12 | }); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/common/src/tsconfig/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getCompilerOptionsFromTsConfig"; 2 | export * from "./getTsParseConfigHost"; 3 | export * from "./TsConfigResolver"; 4 | -------------------------------------------------------------------------------- /packages/common/src/types.d.ts: -------------------------------------------------------------------------------- 1 | declare module "path-browserify" { 2 | import * as path from "path"; 3 | export = path; 4 | } 5 | -------------------------------------------------------------------------------- /packages/common/src/typescript/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./public"; 2 | export * from "./tsInternal"; 3 | -------------------------------------------------------------------------------- /packages/common/src/utils/CharCodes.ts: -------------------------------------------------------------------------------- 1 | export const CharCodes = { 2 | ASTERISK: "*".charCodeAt(0), 3 | NEWLINE: "\n".charCodeAt(0), 4 | CARRIAGE_RETURN: "\r".charCodeAt(0), 5 | SPACE: " ".charCodeAt(0), 6 | TAB: "\t".charCodeAt(0), 7 | CLOSE_BRACE: "}".charCodeAt(0), 8 | }; 9 | -------------------------------------------------------------------------------- /packages/common/src/utils/IterableUtils.ts: -------------------------------------------------------------------------------- 1 | export class IterableUtils { 2 | static find(items: IterableIterator, condition: (item: T) => boolean): T | undefined { 3 | for (const item of items) { 4 | if (condition(item)) 5 | return item; 6 | } 7 | return undefined; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/common/src/utils/ObjectUtils.ts: -------------------------------------------------------------------------------- 1 | export class ObjectUtils { 2 | private constructor() { 3 | } 4 | 5 | static clone(obj: T): T { 6 | // todo: make this an actual deep clone... good enough for now... 7 | if (obj == null) 8 | return undefined as any as T; 9 | if (obj instanceof Array) 10 | return cloneArray(obj) as any as T; 11 | return Object.assign({}, obj); 12 | 13 | function cloneArray(a: any[]) { 14 | return a.map(item => ObjectUtils.clone(item)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/common/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ArrayUtils"; 2 | export * from "./deepClone"; 3 | export * from "./EventContainer"; 4 | export * from "./IterableUtils"; 5 | export * from "./nameof"; 6 | export * from "./ObjectUtils"; 7 | export * from "./StringUtils"; 8 | -------------------------------------------------------------------------------- /packages/common/src/utils/nameof.ts: -------------------------------------------------------------------------------- 1 | export function nameof(obj: TObject, key: keyof TObject): string; 2 | export function nameof(key: keyof TObject): string; 3 | export function nameof(key1: any, key2?: any): any { 4 | return key2 ?? key1; 5 | } 6 | -------------------------------------------------------------------------------- /packages/common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.common.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "rootDir": "./src", 6 | "outDir": "./dist" 7 | }, 8 | "include": [ 9 | "./src" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/common/tsconfig.rollup.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "es2015", 5 | "moduleResolution": "node", 6 | "removeComments": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/scripts/deps.ts: -------------------------------------------------------------------------------- 1 | export * as path from "https://deno.land/std@0.208.0/path/mod.ts"; 2 | export * as tsMorph from "jsr:@ts-morph/ts-morph"; 3 | -------------------------------------------------------------------------------- /packages/scripts/folders.ts: -------------------------------------------------------------------------------- 1 | import { path } from "./deps.ts"; 2 | 3 | const dirname = path.dirname(path.fromFileUrl(import.meta.url)); 4 | const root = path.join(dirname, "../../"); 5 | export const folders = { 6 | scripts: path.join(root, "./packages/scripts"), 7 | common: path.join(root, "./packages/common"), 8 | bootstrap: path.join(root, "./packages/bootstrap"), 9 | tsMorph: path.join(root, "./packages/ts-morph"), 10 | root, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/scripts/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./changeTypeScriptVersion.ts"; 2 | export * from "./createDeclarationProject.ts"; 3 | export { path, tsMorph } from "./deps.ts"; 4 | export * from "./execScript.ts"; 5 | export * from "./folders.ts"; 6 | export * from "./getDevCompilerVersions.ts"; 7 | export * from "./utils/mod.ts"; 8 | -------------------------------------------------------------------------------- /packages/scripts/utils/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./forEachTypeText.ts"; 2 | export * from "./makeConstructorsPrivate.ts"; 3 | export * from "./Memoize.ts"; 4 | export * from "./printDiagnostics.ts"; 5 | -------------------------------------------------------------------------------- /packages/scripts/utils/printDiagnostics.ts: -------------------------------------------------------------------------------- 1 | import { tsMorph } from "../deps.ts"; 2 | 3 | /** Prints the provided diagnostics with colour and context. */ 4 | export function printDiagnostics(diagnostics: tsMorph.Diagnostic[]) { 5 | console.log(tsMorph.ts.formatDiagnosticsWithColorAndContext(diagnostics.map(d => d.compilerObject), { 6 | getCurrentDirectory: () => Deno.cwd(), 7 | getCanonicalFileName: fileName => fileName, 8 | getNewLine: () => "\n", 9 | })); 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/.mocharc.yml: -------------------------------------------------------------------------------- 1 | recursive: true 2 | reporter: progress 3 | timeout: 10000 4 | spec: src/tests/**/*.ts 5 | ignore: src/tests/performance/**/*.ts 6 | -------------------------------------------------------------------------------- /packages/ts-morph/.npmignore: -------------------------------------------------------------------------------- 1 | /.vs 2 | /.github 3 | /node_modules 4 | /.vscode 5 | /scripts 6 | /dist-deno 7 | /dist-scripts 8 | /dist/tests 9 | /src 10 | /docs 11 | *.js.map 12 | /obj 13 | /temp 14 | /bin 15 | .mocharc.yml 16 | *.suo 17 | *.csproj 18 | *.csproj.user 19 | *.sln 20 | .editorconfig 21 | .npmignore 22 | breaking-changes.md 23 | CHANGELOG.md 24 | CODE_OF_CONDUCT.md 25 | CONTRIBUTING.md 26 | dprint.config.js 27 | rollup.config.mjs 28 | gulpfile.js 29 | tsconfig.json 30 | tsconfig.*.json 31 | wrapped-nodes.md 32 | yarn-error.log 33 | # do not include lock files to allow releasing only ts-morph/common 34 | yarn.lock 35 | package-lock.json 36 | -------------------------------------------------------------------------------- /packages/ts-morph/rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import typescript from "@rollup/plugin-typescript"; 2 | const isDeno = process.env.BUILD === "deno"; 3 | const outputFolder = isDeno ? "./dist-deno" : "./dist"; 4 | const moduleKind = isDeno ? "es" : "cjs"; 5 | 6 | export default { 7 | input: "./src/main.ts", 8 | external: [ 9 | "code-block-writer", 10 | "@ts-morph/common", 11 | ], 12 | output: { 13 | file: outputFolder + "/ts-morph.js", 14 | format: moduleKind, 15 | interop: "compat", 16 | }, 17 | plugins: [ 18 | typescript({ 19 | tsconfig: "tsconfig.rollup.json", 20 | outDir: outputFolder, 21 | }), 22 | ], 23 | }; 24 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/common/getProject.ts: -------------------------------------------------------------------------------- 1 | import { folders, path, tsMorph } from "../deps.ts"; 2 | 3 | export function getProject() { 4 | return new tsMorph.Project({ 5 | tsConfigFilePath: path.join(folders.tsMorph, "tsconfig.json"), 6 | skipAddingFilesFromTsConfig: false, 7 | manipulationSettings: { 8 | indentationText: tsMorph.IndentationText.TwoSpaces, 9 | newLineKind: tsMorph.NewLineKind.LineFeed, 10 | insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true, 11 | }, 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/common/hasInternalDocTag.ts: -------------------------------------------------------------------------------- 1 | import { tsMorph } from "../deps.ts"; 2 | 3 | export function hasInternalDocTag(node: tsMorph.Node) { 4 | return tsMorph.Node.isJSDocable(node) 5 | && node.getJsDocs().some(d => d.getTags().some(t => t.getTagName() === "internal")); 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/common/isNodeClass.ts: -------------------------------------------------------------------------------- 1 | import { tsMorph } from "../deps.ts"; 2 | import { hasDescendantNodeType } from "./typeHelpers.ts"; 3 | 4 | export function isNodeClass(classDec: tsMorph.ClassDeclaration) { 5 | if (classDec.getName() === "Node") 6 | return true; 7 | return classDec.getBaseTypes().some(t => hasDescendantNodeType(t)); 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/common/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./cloning.ts"; 2 | export * from "./getDeclarationProject.ts"; 3 | export * from "./getProject.ts"; 4 | export * from "./hasInternalDocTag.ts"; 5 | export * from "./isNodeClass.ts"; 6 | export * from "./typeHelpers.ts"; 7 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/config/isOverloadStructure.ts: -------------------------------------------------------------------------------- 1 | export function isOverloadStructure(name: string) { 2 | switch (name) { 3 | case "FunctionDeclarationOverloadStructure": 4 | case "MethodDeclarationOverloadStructure": 5 | case "ConstructorDeclarationOverloadStructure": 6 | return true; 7 | default: 8 | return false; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/config/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./isAllowedMixin.ts"; 2 | export * from "./isAllowedMixinForStructure.ts"; 3 | export * from "./isOverloadStructure.ts"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/deps.ts: -------------------------------------------------------------------------------- 1 | export * from "../../scripts/mod.ts"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/generation/declarationFile/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./getCodeBlockWriterStatements.ts"; 2 | export * from "./getDeclarationFileStatements.ts"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/inspectors/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./InspectorFactory.ts"; 2 | export * from "./ts/mod.ts"; 3 | export * from "./TsInspector.ts"; 4 | export * from "./tsMorph/mod.ts"; 5 | export * from "./TsMorphInspector.ts"; 6 | export * from "./WrapperFactory.ts"; 7 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/inspectors/ts/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./TsNode.ts"; 2 | export * from "./TsNodeProperty.ts"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/inspectors/tsMorph/KindToWrapperMapping.ts: -------------------------------------------------------------------------------- 1 | import { WrappedNode } from "./WrappedNode.ts"; 2 | 3 | export interface KindToWrapperMapping { 4 | wrapperName: string; 5 | wrappedNode: WrappedNode; 6 | syntaxKindNames: string[]; 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/inspectors/tsMorph/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./KindToWrapperMapping.ts"; 2 | export * from "./Mixin.ts"; 3 | export * from "./Structure.ts"; 4 | export * from "./WrappedNode.ts"; 5 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/markdown/MarkDownFile.ts: -------------------------------------------------------------------------------- 1 | import { CodeBlock } from "./CodeBlock.ts"; 2 | import { parseMarkDown } from "./parseMarkDown.ts"; 3 | 4 | export class MarkDownFile { 5 | constructor(private readonly filePath: string, private readonly text: string) { 6 | } 7 | 8 | getFilePath() { 9 | return this.filePath; 10 | } 11 | 12 | getText() { 13 | return this.text; 14 | } 15 | 16 | getCodeBlocks(): CodeBlock[] { 17 | return parseMarkDown(this); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/markdown/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./CodeBlock.ts"; 2 | export * from "./MarkDownFile.ts"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/readme.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | This folder contains the code that verifies, manipulates, and generates code for ts-morph. 4 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/typeCheckLibrary.ts: -------------------------------------------------------------------------------- 1 | import { getProject } from "./common/mod.ts"; 2 | import { printDiagnostics } from "./deps.ts"; 3 | 4 | const project = getProject(); 5 | const diagnostics = project.getPreEmitDiagnostics(); 6 | 7 | printDiagnostics(diagnostics); 8 | 9 | console.log(`Found ${diagnostics.length} diagnostics.`); 10 | 11 | if (diagnostics.length > 0) 12 | Deno.exit(1); 13 | -------------------------------------------------------------------------------- /packages/ts-morph/scripts/verification/Problem.ts: -------------------------------------------------------------------------------- 1 | export interface Problem { 2 | filePath: string; 3 | lineNumber: number; 4 | message: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/codeBlockWriter/code-block-writer.ts: -------------------------------------------------------------------------------- 1 | import CodeBlockWriter from "code-block-writer"; 2 | 3 | export { CodeBlockWriter }; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/codeBlockWriter/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./code-block-writer"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/SignaturedDeclaration.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Constructor } from "../../../types"; 3 | import { Node } from "../common"; 4 | import { ParameteredNode } from "./ParameteredNode"; 5 | import { ReturnTypedNode } from "./ReturnTypedNode"; 6 | 7 | export type SignaturedDeclarationExtensionType = Node; 8 | 9 | export interface SignaturedDeclaration extends ParameteredNode, ReturnTypedNode { 10 | } 11 | 12 | export function SignaturedDeclaration>(Base: T): Constructor & T { 13 | return ReturnTypedNode(ParameteredNode(Base)); 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/UnwrappableNode.ts: -------------------------------------------------------------------------------- 1 | import { unwrapNode } from "../../../manipulation"; 2 | import { Constructor } from "../../../types"; 3 | import { Node } from "../common"; 4 | 5 | export type UnwrappableNodeExtensionType = Node; 6 | 7 | export interface UnwrappableNode { 8 | /** 9 | * Replaces the node's text with its body's statements. 10 | */ 11 | unwrap(): void; 12 | } 13 | 14 | export function UnwrappableNode>(Base: T): Constructor & T { 15 | return class extends Base implements UnwrappableNode { 16 | unwrap() { 17 | unwrapNode(this); 18 | } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/export/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ExportableNode"; 2 | export * from "./ExportGetableNode"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/helpers/hasBlock.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../../common"; 2 | 3 | export function hasBlock(node: Node) { 4 | return Node.isClassDeclaration(node) 5 | || Node.isModuleDeclaration(node) 6 | || Node.isInterfaceDeclaration(node) 7 | || Node.isEnumDeclaration(node) 8 | || Node.hasBody(node); 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getBodyText"; 2 | export * from "./getBodyTextWithoutLeadingIndentation"; 3 | export * from "./hasBlock"; 4 | export * from "./renameNode"; 5 | export * from "./setBodyTextForNode"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/initializer/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./InitializerExpressionableNode"; 2 | export * from "./InitializerExpressionGetableNode"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/base/name/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./BindingNamedNode"; 2 | export * from "./ImportAttributeNamedNode"; 3 | export * from "./ModuleNamedNode"; 4 | export * from "./NameableNode"; 5 | export * from "./NamedNode"; 6 | export * from "./NamedNodeBase"; 7 | export * from "./PropertyNamedNode"; 8 | export * from "./ReferenceFindableNode"; 9 | export * from "./RenameableNode"; 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/binding/ArrayBindingPattern.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | export class ArrayBindingPattern extends Node { 5 | /** 6 | * Gets the array binding pattern's elements. 7 | */ 8 | getElements() { 9 | return this.compilerNode.elements.map(e => this._getNodeFromCompilerNode(e)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/binding/ObjectBindingPattern.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | export class ObjectBindingPattern extends Node { 5 | /** 6 | * Gets the object binding pattern's elements. 7 | */ 8 | getElements() { 9 | return this.compilerNode.elements.map(e => this._getNodeFromCompilerNode(e)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/binding/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ArrayBindingPattern"; 2 | export * from "./BindingElement"; 3 | export * from "./ObjectBindingPattern"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/callBaseGetStructure.ts: -------------------------------------------------------------------------------- 1 | import { MakeRequired } from "../../typings"; 2 | import { Node } from "./common/Node"; 3 | 4 | /** @internal */ 5 | export function callBaseGetStructure>(basePrototype: any, node: Node, structure: MakeRequired | undefined): any { 6 | let newStructure: T; 7 | if (basePrototype.getStructure != null) 8 | newStructure = basePrototype.getStructure.call(node); 9 | else 10 | newStructure = {} as any; 11 | 12 | if (structure != null) 13 | Object.assign(newStructure as any, structure); 14 | 15 | return newStructure; 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/callBaseSet.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "./common"; 2 | 3 | /** @internal */ 4 | export function callBaseSet(basePrototype: any, node: Node, structure: any) { 5 | if (basePrototype.set != null) 6 | basePrototype.set.call(node, structure); 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/class/ClassExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { PrimaryExpression } from "../expression/PrimaryExpression"; 3 | import { ClassLikeDeclarationBase } from "./base"; 4 | 5 | export const ClassExpressionBase = ClassLikeDeclarationBase(PrimaryExpression); 6 | export class ClassExpression extends ClassExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/class/CommentClassElement.ts: -------------------------------------------------------------------------------- 1 | import { CompilerCommentClassElement } from "../comment"; 2 | import { ClassElement } from "./ClassElement"; 3 | 4 | export class CommentClassElement extends ClassElement { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/class/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./AbstractableNode"; 2 | export * from "./ClassLikeDeclarationBase"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/class/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./base"; 2 | export * from "./ClassDeclaration"; 3 | export * from "./ClassElement"; 4 | export * from "./ClassExpression"; 5 | export * from "./ClassStaticBlockDeclaration"; 6 | export * from "./CommentClassElement"; 7 | export * from "./ConstructorDeclaration"; 8 | export * from "./GetAccessorDeclaration"; 9 | export * from "./MethodDeclaration"; 10 | export * from "./PropertyDeclaration"; 11 | export * from "./SetAccessorDeclaration"; 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/comment/CommentRange.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TextRange } from "../common/TextRange"; 3 | import { SourceFile } from "../module"; 4 | 5 | export class CommentRange extends TextRange { 6 | /** 7 | * @private 8 | */ 9 | constructor(compilerObject: ts.CommentRange, sourceFile: SourceFile) { 10 | super(compilerObject, sourceFile); 11 | } 12 | 13 | /** 14 | * Gets the comment syntax kind. 15 | */ 16 | getKind(): ts.CommentKind { 17 | return this.compilerObject.kind; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/comment/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CommentRange"; 2 | export * from "./CompilerComments"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/common/Scope.ts: -------------------------------------------------------------------------------- 1 | export enum Scope { 2 | Public = "public", 3 | Protected = "protected", 4 | Private = "private", 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Node"; 2 | export * from "./Scope"; 3 | export * from "./SyntaxList"; 4 | export * from "./TextRange"; 5 | export * from "./TraversalControl"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/decorator/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Decorator"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocAllType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc all type. 6 | */ 7 | export class JSDocAllType extends JSDocType { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocAugmentsTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc augments tag node. 6 | */ 7 | export class JSDocAugmentsTag extends JSDocTag { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocAuthorTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc author tag node. 6 | */ 7 | export class JSDocAuthorTag extends JSDocTag {} 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocCallbackTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc callback tag node. 6 | */ 7 | export class JSDocCallbackTag extends JSDocTag {} 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocClassTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc class tag node. 6 | */ 7 | export class JSDocClassTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocDeprecatedTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc deprecated tag node. 6 | */ 7 | export class JSDocDeprecatedTag extends JSDocTag {} 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocEnumTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc enum tag node. 6 | */ 7 | export class JSDocEnumTag extends JSDocTag {} 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocFunctionType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { SignaturedDeclaration } from "../base"; 3 | import { JSDocType } from "./JSDocType"; 4 | 5 | export const JSDocFunctionTypeBase = SignaturedDeclaration(JSDocType); 6 | 7 | /** 8 | * JS doc function type. 9 | */ 10 | export class JSDocFunctionType extends JSDocFunctionTypeBase { 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocImplementsTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc implements tag node. 6 | */ 7 | export class JSDocImplementsTag extends JSDocTag {} 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocLink.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | /** 5 | * JS doc link node. 6 | */ 7 | export class JSDocLink extends Node { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocLinkCode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | /** 5 | * JS doc link code node. 6 | */ 7 | export class JSDocLinkCode extends Node { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocLinkPlain.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | /** 5 | * JS doc link plain node. 6 | */ 7 | export class JSDocLinkPlain extends Node { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocMemberName.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | /** 5 | * JS doc member name node. 6 | */ 7 | export class JSDocMemberName extends Node { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocNameReference.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | /** 5 | * JS doc name reference. 6 | */ 7 | export class JSDocNameReference extends Node { 8 | /** Gets the name of the JS doc name reference. */ 9 | getName() { 10 | return this._getNodeFromCompilerNode(this.compilerNode.name); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocNamepathType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc namepath type. 6 | */ 7 | export class JSDocNamepathType extends JSDocType { 8 | /** Gets the type node of the JS doc namepath node. */ 9 | getTypeNode() { 10 | return this._getNodeFromCompilerNode(this.compilerNode.type); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocNonNullableType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc non-nullable type. 6 | */ 7 | export class JSDocNonNullableType extends JSDocType { 8 | /** Gets the type node of the JS doc non-nullable type node. */ 9 | getTypeNode() { 10 | return this._getNodeFromCompilerNode(this.compilerNode.type); 11 | } 12 | 13 | isPostfix() { 14 | return this.compilerNode.postfix; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocNullableType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc nullable type. 6 | */ 7 | export class JSDocNullableType extends JSDocType { 8 | /** Gets the type node of the JS doc nullable type node. */ 9 | getTypeNode() { 10 | return this._getNodeFromCompilerNode(this.compilerNode.type); 11 | } 12 | 13 | isPostfix() { 14 | return this.compilerNode.postfix; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocOptionalType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc optional type. 6 | */ 7 | export class JSDocOptionalType extends JSDocType { 8 | /** Gets the type node of the JS doc optional type node. */ 9 | getTypeNode() { 10 | return this._getNodeFromCompilerNode(this.compilerNode.type); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocOverloadTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTypeExpressionableTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocOverloadTagBase = JSDocTypeExpressionableTag(JSDocTag); 6 | /** JS doc overload tag. */ 7 | export class JSDocOverloadTag extends JSDocOverloadTagBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocOverrideTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc override tag node. 6 | */ 7 | export class JSDocOverrideTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocParameterTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocPropertyLikeTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocParameterTagBase = JSDocPropertyLikeTag(JSDocTag); 6 | /** 7 | * JS doc parameter tag node. 8 | */ 9 | export class JSDocParameterTag extends JSDocParameterTagBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocPrivateTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc private tag node. 6 | */ 7 | export class JSDocPrivateTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocPropertyTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocPropertyLikeTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocPropertyTagBase = JSDocPropertyLikeTag(JSDocTag); 6 | /** 7 | * JS doc property tag node. 8 | */ 9 | export class JSDocPropertyTag extends JSDocPropertyTagBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocProtectedTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc protected tag node. 6 | */ 7 | export class JSDocProtectedTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocPublicTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc public tag node. 6 | */ 7 | export class JSDocPublicTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocReadonlyTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc readonly tag node. 6 | */ 7 | export class JSDocReadonlyTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocReturnTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTypeExpressionableTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocReturnTagBase = JSDocTypeExpressionableTag(JSDocTag); 6 | /** 7 | * JS doc return tag node. 8 | */ 9 | export class JSDocReturnTag extends JSDocReturnTagBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocSatisfiesTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTypeExpressionableTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocSatisfiesTagBase = JSDocTypeExpressionableTag(JSDocTag); 6 | /** 7 | * JS doc satifiest tag. 8 | */ 9 | export class JSDocSatisfiesTag extends JSDocSatisfiesTagBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocSeeTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTypeExpressionableTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocSeeTagBase = JSDocTypeExpressionableTag(JSDocTag); 6 | /** 7 | * JS doc "see" tag node. 8 | */ 9 | export class JSDocSeeTag extends JSDocSeeTagBase { 10 | // todo: helper methods 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocSignature.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc signature node. 6 | */ 7 | export class JSDocSignature extends JSDocType { 8 | /** 9 | * Gets the type node of the JS doc signature. 10 | */ 11 | getTypeNode() { 12 | return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); 13 | } 14 | 15 | // todo: more methods 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocText.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | 4 | /** 5 | * JS doc text node. 6 | */ 7 | export class JSDocText extends Node { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocThisTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTypeExpressionableTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocThisTagBase = JSDocTypeExpressionableTag(JSDocTag); 6 | /** 7 | * JS doc "this" tag node. 8 | */ 9 | export class JSDocThisTag extends JSDocThisTagBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocThrowsTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTypeExpressionableTag } from "./base"; 3 | import { JSDocTag } from "./JSDocTag"; 4 | 5 | export const JSDocThrowsTagBase = JSDocTypeExpressionableTag(JSDocTag); 6 | /** 7 | * JS doc return tag node. 8 | */ 9 | export class JSDocThrowsTag extends JSDocThrowsTagBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "../type"; 3 | 4 | /** 5 | * JS doc type node. 6 | */ 7 | export class JSDocType extends TypeNode { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocTypeExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "../type"; 3 | 4 | /** 5 | * JS doc type expression node. 6 | */ 7 | export class JSDocTypeExpression extends TypeNode { 8 | /** 9 | * Gets the type node of the JS doc type expression. 10 | */ 11 | getTypeNode() { 12 | return this._getNodeFromCompilerNode(this.compilerNode.type); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocTypeLiteral.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc type literal. 6 | */ 7 | export class JSDocTypeLiteral extends JSDocType { 8 | /** Gets if it's an array type. */ 9 | isArrayType() { 10 | return this.compilerNode.isArrayType; 11 | } 12 | 13 | /** Gets the JS doc property tags if they exist. */ 14 | getPropertyTags() { 15 | return this.compilerNode.jsDocPropertyTags ? this.compilerNode.jsDocPropertyTags.map(t => this._getNodeFromCompilerNode(t)) : undefined; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocTypeTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc type tag node. 6 | */ 7 | export class JSDocTypeTag extends JSDocTag { 8 | /** 9 | * Gets the type expression node of the JS doc property type tag. 10 | */ 11 | getTypeExpression() { 12 | // for some reason the compiler will still return a node when it doesn't exist 13 | const node = this.compilerNode.typeExpression; 14 | if (node != null && node.pos === node.end) 15 | return undefined; 16 | 17 | return this._getNodeFromCompilerNodeIfExists(this.compilerNode.typeExpression); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocTypedefTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc type def tag node. 6 | */ 7 | export class JSDocTypedefTag extends JSDocTag { 8 | // todo: helper methods 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocUnknownTag.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocTag } from "./JSDocTag"; 3 | 4 | /** 5 | * JS doc unknown tag node. 6 | */ 7 | export class JSDocUnknownTag extends JSDocTag { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocUnknownType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc unknown type. 6 | */ 7 | export class JSDocUnknownType extends JSDocType { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/JSDocVariadicType.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocType } from "./JSDocType"; 3 | 4 | /** 5 | * JS doc variadic type. 6 | */ 7 | export class JSDocVariadicType extends JSDocType { 8 | /** Gets the type node of the JS doc variadic type node. */ 9 | getTypeNode() { 10 | return this._getNodeFromCompilerNode(this.compilerNode.type); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/doc/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JSDocPropertyLikeTag"; 2 | export * from "./JSDocTypeExpressionableTag"; 3 | export * from "./JSDocTypeParameteredTag"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/enum/CommentEnumMember.ts: -------------------------------------------------------------------------------- 1 | import { FormattingKind, removeChildrenWithFormatting } from "../../../manipulation"; 2 | import { CompilerCommentEnumMember } from "../comment"; 3 | import { Node } from "../common"; 4 | 5 | export class CommentEnumMember extends Node { 6 | /** 7 | * Removes this enum member comment. 8 | */ 9 | remove() { 10 | removeChildrenWithFormatting({ 11 | children: [this], 12 | getSiblingFormatting: () => FormattingKind.Newline, 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/enum/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CommentEnumMember"; 2 | export * from "./EnumDeclaration"; 3 | export * from "./EnumMember"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/AsExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypedNode } from "../base"; 3 | import { Expression } from "./Expression"; 4 | import { ExpressionedNode } from "./expressioned"; 5 | 6 | const createBase = (ctor: T) => TypedNode(ExpressionedNode(ctor)); 7 | export const AsExpressionBase = createBase(Expression); 8 | export class AsExpression extends AsExpressionBase { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/AssignmentExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { BinaryExpression } from "./BinaryExpression"; 3 | 4 | export const AssignmentExpressionBase = BinaryExpression; 5 | export class AssignmentExpression< 6 | T extends ts.AssignmentExpression = ts.AssignmentExpression, 7 | > extends AssignmentExpressionBase { 8 | /** 9 | * Gets the operator token of the assignment expression. 10 | */ 11 | getOperatorToken() { 12 | return this._getNodeFromCompilerNode(this.compilerNode.operatorToken); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/AwaitExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UnaryExpressionedNode } from "./expressioned"; 3 | import { UnaryExpression } from "./UnaryExpression"; 4 | 5 | export const AwaitExpressionBase = UnaryExpressionedNode(UnaryExpression); 6 | export class AwaitExpression extends AwaitExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/CommaListExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "./Expression"; 3 | 4 | export const CommaListExpressionBase = Expression; 5 | export class CommaListExpression extends CommaListExpressionBase { 6 | /** 7 | * Gets the elements. 8 | */ 9 | getElements(): Expression[] { 10 | return this.compilerNode.elements.map(e => this._getNodeFromCompilerNode(e)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/DeleteExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UnaryExpressionedNode } from "./expressioned"; 3 | import { UnaryExpression } from "./UnaryExpression"; 4 | 5 | export const DeleteExpressionBase = UnaryExpressionedNode(UnaryExpression); 6 | export class DeleteExpression extends DeleteExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/Expression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Type } from "../../types"; 3 | import { Node } from "../common/Node"; 4 | 5 | export class Expression extends Node { 6 | /** 7 | * Gets the contextual type of the expression. 8 | */ 9 | getContextualType(): Type | undefined { 10 | return this._context.typeChecker.getContextualType(this); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/ImportExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { PrimaryExpression } from "./PrimaryExpression"; 3 | 4 | export const ImportExpressionBase = PrimaryExpression; 5 | export class ImportExpression extends ImportExpressionBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/LeftHandSideExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UpdateExpression } from "./UpdateExpression"; 3 | 4 | export class LeftHandSideExpression extends UpdateExpression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/LiteralExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { LiteralLikeNode } from "../base"; 3 | import { PrimaryExpression } from "./PrimaryExpression"; 4 | 5 | export const LiteralExpressionBase = LiteralLikeNode(PrimaryExpression); 6 | export class LiteralExpression extends LiteralExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/MemberExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { LeftHandSideExpression } from "./LeftHandSideExpression"; 3 | 4 | export class MemberExpression extends LeftHandSideExpression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/MetaProperty.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { NamedNode } from "../base"; 3 | import { PrimaryExpression } from "./PrimaryExpression"; 4 | 5 | export const MetaPropertyBase = NamedNode(PrimaryExpression); 6 | export class MetaProperty extends MetaPropertyBase { 7 | /** 8 | * Gets the keyword token. 9 | */ 10 | getKeywordToken() { 11 | return this.compilerNode.keywordToken; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/NewExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ArgumentedNode, TypeArgumentedNode } from "../base"; 3 | import { LeftHandSideExpressionedNode } from "./expressioned"; 4 | import { PrimaryExpression } from "./PrimaryExpression"; 5 | 6 | const createBase = (ctor: T) => 7 | TypeArgumentedNode(ArgumentedNode( 8 | LeftHandSideExpressionedNode(ctor), 9 | )); 10 | export const NewExpressionBase = createBase(PrimaryExpression); 11 | export class NewExpression extends NewExpressionBase { 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/NonNullExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ExpressionedNode } from "./expressioned"; 3 | import { LeftHandSideExpression } from "./LeftHandSideExpression"; 4 | 5 | export const NonNullExpressionBase = ExpressionedNode(LeftHandSideExpression); 6 | export class NonNullExpression extends NonNullExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/OmittedExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "./Expression"; 3 | 4 | export const OmittedExpressionBase = Expression; 5 | export class OmittedExpression extends OmittedExpressionBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/ParenthesizedExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "./Expression"; 3 | import { ExpressionedNode } from "./expressioned"; 4 | 5 | export const ParenthesizedExpressionBase = ExpressionedNode(Expression); 6 | export class ParenthesizedExpression extends ParenthesizedExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/PartiallyEmittedExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "./Expression"; 3 | import { ExpressionedNode } from "./expressioned"; 4 | 5 | export const PartiallyEmittedExpressionBase = ExpressionedNode(Expression); 6 | export class PartiallyEmittedExpression extends PartiallyEmittedExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/PrefixUnaryExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UnaryExpression } from "./UnaryExpression"; 3 | 4 | export const PrefixUnaryExpressionBase = UnaryExpression; 5 | export class PrefixUnaryExpression extends PrefixUnaryExpressionBase { 6 | /** 7 | * Gets the operator token of the prefix unary expression. 8 | */ 9 | getOperatorToken() { 10 | return this.compilerNode.operator; 11 | } 12 | 13 | /** 14 | * Gets the operand of the prefix unary expression. 15 | */ 16 | getOperand(): UnaryExpression { 17 | return this._getNodeFromCompilerNode(this.compilerNode.operand); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/PrimaryExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { MemberExpression } from "./MemberExpression"; 3 | 4 | export class PrimaryExpression extends MemberExpression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/PropertyAccessExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { NamedNode, QuestionDotTokenableNode } from "../base"; 3 | import { LeftHandSideExpressionedNode } from "./expressioned"; 4 | import { MemberExpression } from "./MemberExpression"; 5 | 6 | const createBase = (ctor: T) => NamedNode(QuestionDotTokenableNode(LeftHandSideExpressionedNode(ctor))); 7 | export const PropertyAccessExpressionBase = createBase(MemberExpression); 8 | export class PropertyAccessExpression extends PropertyAccessExpressionBase { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/SatisfiesExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypedNode } from "../base"; 3 | import { Expression } from "./Expression"; 4 | import { ExpressionedNode } from "./expressioned"; 5 | 6 | const createBase = (ctor: T) => TypedNode(ExpressionedNode(ctor)); 7 | export const SatisfiesExpressionBase = createBase(Expression); 8 | export class SatisfiesExpression extends SatisfiesExpressionBase { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/SpreadElement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "./Expression"; 3 | import { ExpressionedNode } from "./expressioned"; 4 | 5 | export const SpreadElementBase = ExpressionedNode(Expression); 6 | export class SpreadElement extends SpreadElementBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/SuperElementAccessExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ElementAccessExpression } from "./ElementAccessExpression"; 3 | import { SuperExpressionedNode } from "./expressioned"; 4 | 5 | export const SuperElementAccessExpressionBase = SuperExpressionedNode(ElementAccessExpression); 6 | export class SuperElementAccessExpression extends SuperElementAccessExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/SuperExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { PrimaryExpression } from "./PrimaryExpression"; 3 | 4 | export const SuperExpressionBase = PrimaryExpression; 5 | export class SuperExpression extends SuperExpressionBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/SuperPropertyAccessExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { SuperExpressionedNode } from "./expressioned"; 3 | import { PropertyAccessExpression } from "./PropertyAccessExpression"; 4 | 5 | export const SuperPropertyAccessExpressionBase = SuperExpressionedNode(PropertyAccessExpression); 6 | export class SuperPropertyAccessExpression extends SuperPropertyAccessExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/ThisExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { PrimaryExpression } from "./PrimaryExpression"; 3 | 4 | export const ThisExpressionBase = PrimaryExpression; 5 | export class ThisExpression extends ThisExpressionBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/TypeAssertion.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypedNode } from "../base"; 3 | import { UnaryExpressionedNode } from "./expressioned"; 4 | import { UnaryExpression } from "./UnaryExpression"; 5 | 6 | const createBase = (ctor: T) => TypedNode(UnaryExpressionedNode(ctor)); 7 | export const TypeAssertionBase = createBase(UnaryExpression); 8 | export class TypeAssertion extends TypeAssertionBase { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/TypeOfExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UnaryExpressionedNode } from "./expressioned"; 3 | import { UnaryExpression } from "./UnaryExpression"; 4 | 5 | export const TypeOfExpressionBase = UnaryExpressionedNode(UnaryExpression); 6 | export class TypeOfExpression extends TypeOfExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/UnaryExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "./Expression"; 3 | 4 | export class UnaryExpression extends Expression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/UpdateExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UnaryExpression } from "./UnaryExpression"; 3 | 4 | export class UpdateExpression extends UnaryExpression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/VoidExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { UnaryExpressionedNode } from "./expressioned"; 3 | import { UnaryExpression } from "./UnaryExpression"; 4 | 5 | export const VoidExpressionBase = UnaryExpressionedNode(UnaryExpression); 6 | export class VoidExpression extends VoidExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/YieldExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { GeneratorableNode } from "../base"; 3 | import { Expression } from "./Expression"; 4 | import { ExpressionableNode } from "./expressioned"; 5 | 6 | export const YieldExpressionBase = ExpressionableNode(GeneratorableNode(Expression)); 7 | export class YieldExpression extends YieldExpressionBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/array/ArrayDestructuringAssignment.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { AssignmentExpression } from "../AssignmentExpression"; 3 | import { ArrayLiteralExpression } from "./ArrayLiteralExpression"; 4 | 5 | export const ArrayDestructuringAssignmentBase = AssignmentExpression; 6 | export class ArrayDestructuringAssignment extends ArrayDestructuringAssignmentBase { 7 | /** 8 | * Gets the left array literal expression of the array destructuring assignment. 9 | */ 10 | getLeft(): ArrayLiteralExpression { 11 | return this._getNodeFromCompilerNode(this.compilerNode.left); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/array/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ArrayDestructuringAssignment"; 2 | export * from "./ArrayLiteralExpression"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/expressioned/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ExpressionableNode"; 2 | export * from "./ExpressionedNode"; 3 | export * from "./ImportExpressionedNode"; 4 | export * from "./LeftHandSideExpressionedNode"; 5 | export * from "./SuperExpressionedNode"; 6 | export * from "./UnaryExpressionedNode"; 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/object/CommentObjectLiteralElement.ts: -------------------------------------------------------------------------------- 1 | import { CompilerCommentObjectLiteralElement } from "../../comment"; 2 | import { ObjectLiteralElement } from "./ObjectLiteralElement"; 3 | 4 | export class CommentObjectLiteralElement extends ObjectLiteralElement { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/object/ObjectDestructuringAssignment.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { AssignmentExpression } from "../AssignmentExpression"; 3 | import { ObjectLiteralExpression } from "./ObjectLiteralExpression"; 4 | 5 | export const ObjectDestructuringAssignmentBase = AssignmentExpression; 6 | export class ObjectDestructuringAssignment extends ObjectDestructuringAssignmentBase { 7 | /** 8 | * Gets the left object literal expression of the object destructuring assignment. 9 | */ 10 | getLeft(): ObjectLiteralExpression { 11 | return this._getNodeFromCompilerNode(this.compilerNode.left); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/object/ObjectLiteralElement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { removeCommaSeparatedChild } from "../../../../manipulation"; 3 | import { Node } from "../../common"; 4 | 5 | // todo: There are ClassElement nodes like MethodDeclaration that should implement this as well so what's done here isn't really correct 6 | 7 | export class ObjectLiteralElement extends Node { 8 | /** 9 | * Removes the object literal element from the object literal expression. 10 | */ 11 | remove() { 12 | removeCommaSeparatedChild(this); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/expression/object/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CommentObjectLiteralElement"; 2 | export * from "./ObjectDestructuringAssignment"; 3 | export * from "./ObjectLiteralElement"; 4 | export * from "./ObjectLiteralExpression"; 5 | export * from "./PropertyAssignment"; 6 | export * from "./ShorthandPropertyAssignment"; 7 | export * from "./SpreadAssignment"; 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/function/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ArrowFunction"; 2 | export * from "./FunctionDeclaration"; 3 | export * from "./FunctionExpression"; 4 | export * from "./FunctionLikeDeclaration"; 5 | export * from "./OverloadableNode"; 6 | export * from "./ParameterDeclaration"; 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/general/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./HeritageClause"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/interface/CommentTypeElement.ts: -------------------------------------------------------------------------------- 1 | import { CompilerCommentTypeElement } from "../comment"; 2 | import { TypeElement } from "./TypeElement"; 3 | 4 | export class CommentTypeElement extends TypeElement { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/interface/TypeElement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { removeInterfaceMember } from "../../../manipulation"; 3 | import { Node } from "../common"; 4 | 5 | export class TypeElement extends Node { 6 | /** 7 | * Removes the member. 8 | */ 9 | remove() { 10 | removeInterfaceMember(this); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/interface/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CallSignatureDeclaration"; 2 | export * from "./CommentTypeElement"; 3 | export * from "./ConstructSignatureDeclaration"; 4 | export * from "./IndexSignatureDeclaration"; 5 | export * from "./InterfaceDeclaration"; 6 | export * from "./MethodSignature"; 7 | export * from "./PropertySignature"; 8 | export * from "./TypeElement"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/JsxClosingElement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | import { JsxTagNamedNode } from "./base"; 4 | 5 | const createBase = (ctor: T) => JsxTagNamedNode(ctor); 6 | export const JsxClosingElementBase = createBase(Node); 7 | export class JsxClosingElement extends JsxClosingElementBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/JsxClosingFragment.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "../expression"; 3 | 4 | export class JsxClosingFragment extends Expression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/JsxExpression.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { DotDotDotTokenableNode } from "../base"; 3 | import { Expression, ExpressionableNode } from "../expression"; 4 | 5 | export const JsxExpressionBase = ExpressionableNode(DotDotDotTokenableNode(Expression)); 6 | export class JsxExpression extends JsxExpressionBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/JsxOpeningElement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "../expression"; 3 | import { JsxAttributedNode, JsxTagNamedNode } from "./base"; 4 | 5 | const createBase = (ctor: T) => JsxAttributedNode(JsxTagNamedNode(ctor)); 6 | export const JsxOpeningElementBase = createBase(Expression); 7 | export class JsxOpeningElement extends JsxOpeningElementBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/JsxOpeningFragment.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression } from "../expression"; 3 | 4 | export class JsxOpeningFragment extends Expression { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JsxAttributedNode"; 2 | export * from "./JsxTagNamedNode"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/jsx/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./base"; 2 | export * from "./JsxAttribute"; 3 | export * from "./JsxClosingElement"; 4 | export * from "./JsxClosingFragment"; 5 | export * from "./JsxElement"; 6 | export * from "./JsxExpression"; 7 | export * from "./JsxFragment"; 8 | export * from "./JsxNamespacedName"; 9 | export * from "./JsxOpeningElement"; 10 | export * from "./JsxOpeningFragment"; 11 | export * from "./JsxSelfClosingElement"; 12 | export * from "./JsxSpreadAttribute"; 13 | export * from "./JsxText"; 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/NullLiteral.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { PrimaryExpression } from "../expression"; 3 | 4 | export const NullLiteralBase = PrimaryExpression; 5 | export class NullLiteral extends NullLiteralBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/QuoteKind.ts: -------------------------------------------------------------------------------- 1 | /** Quote type for a string literal. */ 2 | export enum QuoteKind { 3 | /** Single quote */ 4 | Single = "'", 5 | /** Double quote */ 6 | Double = "\"", 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./BigIntLiteral"; 2 | export * from "./BooleanLiterals"; 3 | export * from "./NullLiteral"; 4 | export * from "./NumericLiteral"; 5 | export * from "./QuoteKind"; 6 | export * from "./RegularExpressionLiteral"; 7 | export * from "./StringLiteral"; 8 | export * from "./template"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/template/TemplateHead.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { LiteralLikeNode } from "../../base"; 3 | import { Node } from "../../common"; 4 | 5 | export const TemplateHeadBase = LiteralLikeNode(Node); 6 | export class TemplateHead extends TemplateHeadBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/template/TemplateMiddle.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { LiteralLikeNode } from "../../base"; 3 | import { Node } from "../../common"; 4 | 5 | export const TemplateMiddleBase = LiteralLikeNode(Node); 6 | export class TemplateMiddle extends TemplateMiddleBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/template/TemplateSpan.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../../common"; 3 | import { ExpressionedNode } from "../../expression"; 4 | import { TemplateMiddle } from "./TemplateMiddle"; 5 | import { TemplateTail } from "./TemplateTail"; 6 | 7 | export const TemplateSpanBase = ExpressionedNode(Node); 8 | export class TemplateSpan extends TemplateSpanBase { 9 | /** 10 | * Gets the template literal. 11 | */ 12 | getLiteral(): TemplateMiddle | TemplateTail { 13 | return this._getNodeFromCompilerNode(this.compilerNode.literal); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/template/TemplateTail.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { LiteralLikeNode } from "../../base"; 3 | import { Node } from "../../common"; 4 | 5 | export const TemplateTailBase = LiteralLikeNode(Node); 6 | export class TemplateTail extends TemplateTailBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/literal/template/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./NoSubstitutionTemplateLiteral"; 2 | export * from "./TaggedTemplateExpression"; 3 | export * from "./TemplateExpression"; 4 | export * from "./TemplateHead"; 5 | export * from "./TemplateMiddle"; 6 | export * from "./TemplateSpan"; 7 | export * from "./TemplateTail"; 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/ModuleBlock.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Statement, StatementedNode } from "../statement"; 3 | export const ModuleBlockBase = StatementedNode(Statement); 4 | export class ModuleBlock extends ModuleBlockBase { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/ModuleDeclarationKind.ts: -------------------------------------------------------------------------------- 1 | export enum ModuleDeclarationKind { 2 | Namespace = "namespace", 3 | Module = "module", 4 | Global = "global", 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/NamedExports.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | import { ExportSpecifier } from "./ExportSpecifier"; 4 | 5 | export const NamedExportsBase = Node; 6 | export class NamedExports extends NamedExportsBase { 7 | /** Gets the export specifiers. */ 8 | getElements(): ExportSpecifier[] { 9 | return this.compilerNode.elements.map(e => this._getNodeFromCompilerNode(e)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/NamedImports.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | import { ImportSpecifier } from "./ImportSpecifier"; 4 | 5 | export const NamedImportsBase = Node; 6 | export class NamedImports extends NamedImportsBase { 7 | /** Gets the import specifiers. */ 8 | getElements(): ImportSpecifier[] { 9 | return this.compilerNode.elements.map(e => this._getNodeFromCompilerNode(e)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/results/FileReference.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TextRange } from "../../common"; 3 | import { SourceFile } from "../../module"; 4 | 5 | export class FileReference extends TextRange { 6 | /* @private */ 7 | constructor(compilerObject: ts.FileReference, sourceFile: SourceFile) { 8 | super(compilerObject, sourceFile); 9 | } 10 | 11 | /** Gets the referenced file name. */ 12 | getFileName() { 13 | return this.compilerObject.fileName; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/results/FileSystemRefreshResult.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Result of refreshing a source file from the file system. 3 | */ 4 | export enum FileSystemRefreshResult { 5 | /** The source file did not change. */ 6 | NoChange, 7 | /** The source file was updated from the file system. */ 8 | Updated, 9 | /** The source file was deleted. */ 10 | Deleted, 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/module/results/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./FileReference"; 2 | export * from "./FileSystemRefreshResult"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/name/ComputedPropertyName.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../common"; 3 | import { ExpressionedNode } from "../expression"; 4 | 5 | export const ComputedPropertyNameBase = ExpressionedNode(Node); 6 | export class ComputedPropertyName extends ComputedPropertyNameBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/name/PrivateIdentifier.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ReferenceFindableNode, RenameableNode } from "../base"; 3 | import { Node } from "../common"; 4 | import { CommonIdentifierBase } from "./base"; 5 | 6 | export const PrivateIdentifierBase = CommonIdentifierBase(ReferenceFindableNode(RenameableNode(Node))); 7 | export class PrivateIdentifier extends PrivateIdentifierBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/name/QualifiedName.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { EntityName } from "../aliases"; 3 | import { Node } from "../common"; 4 | import { Identifier } from "./Identifier"; 5 | 6 | export class QualifiedName extends Node { 7 | /** 8 | * Gets the left side of the qualified name. 9 | */ 10 | getLeft(): EntityName { 11 | return this._getNodeFromCompilerNode(this.compilerNode.left); 12 | } 13 | 14 | /** 15 | * Gets the right identifier of the qualified name. 16 | */ 17 | getRight(): Identifier { 18 | return this._getNodeFromCompilerNode(this.compilerNode.right); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/name/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CommonIdentifierBase"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/name/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./base"; 2 | export * from "./ComputedPropertyName"; 3 | export * from "./Identifier"; 4 | export * from "./PrivateIdentifier"; 5 | export * from "./QualifiedName"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/Block.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TextInsertableNode } from "../base"; 3 | import { Statement } from "./Statement"; 4 | import { StatementedNode } from "./StatementedNode"; 5 | 6 | const createBase = (ctor: T) => TextInsertableNode(StatementedNode(ctor)); 7 | export const BlockBase = createBase(Statement); 8 | export class Block extends BlockBase { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/CommentStatement.ts: -------------------------------------------------------------------------------- 1 | import { CompilerCommentStatement } from "../comment"; 2 | import { Statement } from "./Statement"; 3 | 4 | export class CommentStatement extends Statement { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/DebuggerStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Statement } from "./Statement"; 3 | 4 | export const DebuggerStatementBase = Statement; 5 | export class DebuggerStatement extends DebuggerStatementBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/DefaultClause.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { removeClausedNodeChild } from "../../../manipulation"; 3 | import { TextInsertableNode } from "../base"; 4 | import { Node } from "../common"; 5 | import { StatementedNode } from "./StatementedNode"; 6 | 7 | const createBase = (ctor: T) => TextInsertableNode(StatementedNode(ctor)); 8 | export const DefaultClauseBase = createBase(Node); 9 | export class DefaultClause extends DefaultClauseBase { 10 | /** 11 | * Removes the default clause. 12 | */ 13 | remove() { 14 | removeClausedNodeChild(this); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/DoStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ExpressionedNode } from "../expression"; 3 | import { IterationStatement } from "./IterationStatement"; 4 | 5 | export const DoStatementBase = ExpressionedNode(IterationStatement); 6 | export class DoStatement extends DoStatementBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/EmptyStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Statement } from "./Statement"; 3 | 4 | export const EmptyStatementBase = Statement; 5 | export class EmptyStatement extends EmptyStatementBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/ExpressionStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { JSDocableNode } from "../base"; 3 | import { ExpressionedNode } from "../expression"; 4 | import { Statement } from "./Statement"; 5 | 6 | export const ExpressionStatementBase = ExpressionedNode(JSDocableNode(Statement)); 7 | export class ExpressionStatement extends ExpressionStatementBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/ForInStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Expression, ExpressionedNode } from "../expression"; 3 | import { VariableDeclarationList } from "../variable"; 4 | import { IterationStatement } from "./IterationStatement"; 5 | 6 | export const ForInStatementBase = ExpressionedNode(IterationStatement); 7 | export class ForInStatement extends ForInStatementBase { 8 | /** 9 | * Gets this for in statement's initializer. 10 | */ 11 | getInitializer(): VariableDeclarationList | Expression { 12 | return this._getNodeFromCompilerNode(this.compilerNode.initializer); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/ForOfStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { AwaitableNode } from "../base"; 3 | import { Expression, ExpressionedNode } from "../expression"; 4 | import { VariableDeclarationList } from "../variable"; 5 | import { IterationStatement } from "./IterationStatement"; 6 | 7 | export const ForOfStatementBase = ExpressionedNode(AwaitableNode(IterationStatement)); 8 | export class ForOfStatement extends ForOfStatementBase { 9 | /** 10 | * Gets this for of statement's initializer. 11 | */ 12 | getInitializer(): VariableDeclarationList | Expression { 13 | return this._getNodeFromCompilerNode(this.compilerNode.initializer); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/IterationStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Statement } from "./Statement"; 3 | 4 | export class IterationStatement extends Statement { 5 | /** 6 | * Gets this iteration statement's statement. 7 | */ 8 | getStatement(): Statement { 9 | return this._getNodeFromCompilerNode(this.compilerNode.statement); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/NotEmittedStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Statement } from "./Statement"; 3 | 4 | export const NotEmittedStatementBase = Statement; 5 | export class NotEmittedStatement extends NotEmittedStatementBase { 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/ReturnStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ExpressionableNode } from "../expression"; 3 | import { Statement } from "./Statement"; 4 | 5 | export const ReturnStatementBase = ExpressionableNode(Statement); 6 | export class ReturnStatement extends ReturnStatementBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/Statement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { removeStatementedNodeChild } from "../../../manipulation"; 3 | import { ChildOrderableNode } from "../base"; 4 | import { Node } from "../common"; 5 | 6 | export const StatementBase = ChildOrderableNode(Node); 7 | export class Statement extends StatementBase { 8 | /** 9 | * Removes the statement. 10 | */ 11 | remove() { 12 | removeStatementedNodeChild(this); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/ThrowStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ExpressionedNode } from "../expression"; 3 | import { Statement } from "./Statement"; 4 | 5 | export const ThrowStatementBase = ExpressionedNode(Statement); 6 | export class ThrowStatement extends ThrowStatementBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/WhileStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ExpressionedNode } from "../expression"; 3 | import { IterationStatement } from "./IterationStatement"; 4 | 5 | export const WhileStatementBase = ExpressionedNode(IterationStatement); 6 | export class WhileStatement extends WhileStatementBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/statement/WithStatement.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ExpressionedNode } from "../expression"; 3 | import { Statement } from "./Statement"; 4 | 5 | export const WithStatementBase = ExpressionedNode(Statement); 6 | export class WithStatement extends WithStatementBase { 7 | /** 8 | * Gets this with statement's statement. 9 | */ 10 | getStatement(): Statement { 11 | return this._getNodeFromCompilerNode(this.compilerNode.statement); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/ArrayTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class ArrayTypeNode extends TypeNode { 5 | /** 6 | * Gets the array type node's element type node. 7 | */ 8 | getElementTypeNode(): TypeNode { 9 | return this._getNodeFromCompilerNode(this.compilerNode.elementType); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/ConstructorTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { ModifierableNode } from "../base"; 3 | import { AbstractableNode } from "../class"; 4 | import { FunctionOrConstructorTypeNodeBase } from "./FunctionOrConstructorTypeNodeBase"; 5 | 6 | export const ConstructorTypeNodeBase = AbstractableNode(ModifierableNode(FunctionOrConstructorTypeNodeBase)); 7 | export class ConstructorTypeNode extends ConstructorTypeNodeBase { 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/ExpressionWithTypeArguments.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { LeftHandSideExpressionedNode } from "../expression"; 3 | import { NodeWithTypeArguments } from "./TypeNode"; 4 | 5 | export const ExpressionWithTypeArgumentsBase = LeftHandSideExpressionedNode(NodeWithTypeArguments); 6 | export class ExpressionWithTypeArguments extends ExpressionWithTypeArgumentsBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/FunctionOrConstructorTypeNodeBase.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { SignaturedDeclaration } from "../base"; 3 | import { TypeNode } from "./TypeNode"; 4 | 5 | export const FunctionOrConstructorTypeNodeBaseBase = SignaturedDeclaration(TypeNode); 6 | export class FunctionOrConstructorTypeNodeBase 7 | extends FunctionOrConstructorTypeNodeBaseBase 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/FunctionTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeParameteredNode } from "../base"; 3 | import { FunctionOrConstructorTypeNodeBase } from "./FunctionOrConstructorTypeNodeBase"; 4 | 5 | export const FunctionTypeNodeBase = TypeParameteredNode(FunctionOrConstructorTypeNodeBase); 6 | export class FunctionTypeNode extends FunctionTypeNodeBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/InferTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class InferTypeNode extends TypeNode { 5 | /** 6 | * Gets the infer type node's type parameter. 7 | * 8 | * Ex. In `infer R` returns `R`. 9 | */ 10 | getTypeParameter() { 11 | return this._getNodeFromCompilerNode(this.compilerNode.typeParameter); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/IntersectionTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class IntersectionTypeNode extends TypeNode { 5 | /** 6 | * Gets the intersection type nodes. 7 | */ 8 | getTypeNodes(): TypeNode[] { 9 | return this.compilerNode.types.map(t => this._getNodeFromCompilerNode(t)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/RestTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class RestTypeNode extends TypeNode { 5 | /** Gets the rest type node's inner type. */ 6 | getTypeNode() { 7 | return this._getNodeFromCompilerNode(this.compilerNode.type); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/ThisTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class ThisTypeNode extends TypeNode { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/TupleTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class TupleTypeNode extends TypeNode { 5 | /** 6 | * Gets the tuple element type nodes. 7 | */ 8 | getElements() { 9 | return this.compilerNode.elements.map(t => this._getNodeFromCompilerNode(t)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/TypeLiteralNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeElementMemberedNode } from "../base"; 3 | import { TypeNode } from "./TypeNode"; 4 | 5 | export const TypeLiteralNodeBase = TypeElementMemberedNode(TypeNode); 6 | export class TypeLiteralNode extends TypeLiteralNodeBase { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/TypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeArgumentedNode } from "../base"; 3 | import { Node } from "../common"; 4 | 5 | export class TypeNode extends Node { 6 | } 7 | 8 | export const NodeWithTypeArgumentsBase = TypeArgumentedNode(TypeNode); 9 | export class NodeWithTypeArguments extends NodeWithTypeArgumentsBase { 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/TypeOperatorTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class TypeOperatorTypeNode extends TypeNode { 5 | /** Gets the operator of the type node. */ 6 | getOperator() { 7 | return this.compilerNode.operator; 8 | } 9 | 10 | /** Gets the node within the type operator. */ 11 | getTypeNode(): TypeNode { 12 | return this._getNodeFromCompilerNode(this.compilerNode.type); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/TypeQueryNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { EntityName } from "../aliases"; 3 | import { NodeWithTypeArguments } from "./TypeNode"; 4 | 5 | export class TypeQueryNode extends NodeWithTypeArguments { 6 | /** 7 | * Gets the expression name. 8 | */ 9 | getExprName(): EntityName { 10 | return this._getNodeFromCompilerNode(this.compilerNode.exprName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/TypeReferenceNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { EntityName } from "../aliases"; 3 | import { NodeWithTypeArguments } from "./TypeNode"; 4 | 5 | export class TypeReferenceNode extends NodeWithTypeArguments { 6 | /** 7 | * Gets the type name. 8 | */ 9 | getTypeName(): EntityName { 10 | return this._getNodeFromCompilerNode(this.compilerNode.typeName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/type/UnionTypeNode.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { TypeNode } from "./TypeNode"; 3 | 4 | export class UnionTypeNode extends TypeNode { 5 | /** 6 | * Gets the union type nodes. 7 | */ 8 | getTypeNodes(): TypeNode[] { 9 | return this.compilerNode.types.map(t => this._getNodeFromCompilerNode(t)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CommentNodeParser"; 2 | export * from "./ExtendedParser"; 3 | export * from "./isComment"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/utils/isComment.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | 3 | export function isComment(node: { kind: ts.SyntaxKind }) { 4 | return node.kind === ts.SyntaxKind.SingleLineCommentTrivia 5 | || node.kind === ts.SyntaxKind.MultiLineCommentTrivia; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/variable/VariableDeclarationKind.ts: -------------------------------------------------------------------------------- 1 | export enum VariableDeclarationKind { 2 | Var = "var", 3 | Let = "let", 4 | Const = "const", 5 | AwaitUsing = "await using", 6 | Using = "using", 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/ast/variable/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./VariableDeclaration"; 2 | export * from "./VariableDeclarationKind"; 3 | export * from "./VariableDeclarationList"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ast"; 2 | export * from "./symbols"; 3 | export * from "./tools"; 4 | export * from "./types"; 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/symbols/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Signature"; 2 | export * from "./Symbol"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/tools/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./inputs"; 2 | export * from "./LanguageService"; 3 | export * from "./Program"; 4 | export * from "./results"; 5 | export * from "./TypeChecker"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/tools/inputs/FormatCodeSettings.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | 3 | export interface FormatCodeSettings extends ts.FormatCodeSettings { 4 | ensureNewLineAtEndOfFile?: boolean; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/tools/inputs/UserPreferences.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | 3 | /** 4 | * User preferences for refactoring. 5 | */ 6 | export interface UserPreferences extends ts.UserPreferences { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/tools/inputs/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./FormatCodeSettings"; 2 | export * from "./RenameOptions"; 3 | export * from "./UserPreferences"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/tools/results/RenameLocation.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { DocumentSpan } from "./DocumentSpan"; 3 | 4 | /** 5 | * Rename location. 6 | */ 7 | export class RenameLocation extends DocumentSpan { 8 | /** Gets the text to insert before the rename. */ 9 | getPrefixText() { 10 | return this._compilerObject.prefixText; 11 | } 12 | 13 | /** Gets the text to insert after the rename. */ 14 | getSuffixText() { 15 | return this._compilerObject.suffixText; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/compiler/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Type"; 2 | export * from "./TypeParameter"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/factories/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CompilerFactory"; 2 | export * from "./ForgetfulNodeCache"; 3 | export * from "./InProjectCoordinator"; 4 | export * from "./kindToWrapperMappings"; 5 | export * from "./StructurePrinterFactory"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/fileSystem/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Directory"; 2 | export * from "./DirectoryCoordinator"; 3 | export * from "./DirectoryEmitResult"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/code/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getNewInsertCode"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/FormattingKind.ts: -------------------------------------------------------------------------------- 1 | export enum FormattingKind { 2 | Newline, 3 | Blankline, 4 | Space, 5 | None, 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/getClassMemberFormatting.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../../compiler"; 2 | import { FormattingKind } from "./FormattingKind"; 3 | 4 | export function getClassMemberFormatting(parent: Node, member: Node) { 5 | if (Node.isAmbientable(parent) && parent.isAmbient()) 6 | return FormattingKind.Newline; 7 | 8 | if (hasBody(member)) 9 | return FormattingKind.Blankline; 10 | 11 | return FormattingKind.Newline; 12 | } 13 | 14 | function hasBody(node: Node) { 15 | if (Node.isBodyable(node) && node.getBody() != null) 16 | return true; 17 | if (Node.isBodied(node)) 18 | return true; 19 | return false; 20 | } 21 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/getFormattingKindText.ts: -------------------------------------------------------------------------------- 1 | import { errors } from "@ts-morph/common"; 2 | import { FormattingKind } from "./FormattingKind"; 3 | 4 | export function getFormattingKindText(formattingKind: FormattingKind, opts: { newLineKind: string }) { 5 | switch (formattingKind) { 6 | case FormattingKind.Space: 7 | return " "; 8 | case FormattingKind.Newline: 9 | return opts.newLineKind; 10 | case FormattingKind.Blankline: 11 | return opts.newLineKind + opts.newLineKind; 12 | case FormattingKind.None: 13 | return ""; 14 | default: 15 | throw new errors.NotImplementedError(`Not implemented formatting kind: ${formattingKind}`); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/getInterfaceMemberFormatting.ts: -------------------------------------------------------------------------------- 1 | import { InterfaceDeclaration, Node } from "../../compiler"; 2 | import { FormattingKind } from "./FormattingKind"; 3 | 4 | export function getInterfaceMemberFormatting(parent: InterfaceDeclaration, member: Node) { 5 | return FormattingKind.Newline; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/getStatementedNodeChildFormatting.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../../compiler"; 2 | import { FormattingKind } from "./FormattingKind"; 3 | import { hasBody } from "./hasBody"; 4 | 5 | export function getStatementedNodeChildFormatting(parent: Node, member: Node) { 6 | if (hasBody(member)) 7 | return FormattingKind.Blankline; 8 | 9 | return FormattingKind.Newline; 10 | } 11 | 12 | export function getClausedNodeChildFormatting(parent: Node, member: Node) { 13 | return FormattingKind.Newline; 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/hasBody.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../../compiler"; 2 | 3 | export function hasBody(node: Node) { 4 | if (Node.isBodyable(node) && node.hasBody()) 5 | return true; 6 | if (Node.isBodied(node)) 7 | return true; 8 | 9 | return Node.isInterfaceDeclaration(node) || Node.isClassDeclaration(node) || Node.isEnumDeclaration(node); 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/formatting/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./FormattingKind"; 2 | export * from "./getClassMemberFormatting"; 3 | export * from "./getFormattingKindText"; 4 | export * from "./getGeneralFormatting"; 5 | export * from "./getInterfaceMemberFormatting"; 6 | export * from "./getStatementedNodeChildFormatting"; 7 | export * from "./getTextFromFormattingEdits"; 8 | export * from "./hasBody"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/helpers/getEndIndexFromArray.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | 3 | /** 4 | * Gets the end index from a possibly undefined array. 5 | * @param array - Array that could possibly be undefined. 6 | */ 7 | export function getEndIndexFromArray(array: readonly any[] | ts.NodeArray | undefined) { 8 | return array?.length ?? 0; 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/helpers/getNodesToReturn.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../../compiler"; 2 | 3 | export function getNodesToReturn(oldChildren: T[] | number, newChildren: T[], index: number, allowCommentNodes: boolean) { 4 | const oldChildCount = typeof oldChildren === "number" ? oldChildren : oldChildren.length; 5 | const newLength = newChildren.length - oldChildCount; 6 | const result: T[] = []; 7 | for (let i = 0; i < newLength; i++) { 8 | const currentChild = newChildren[index + i]; 9 | if (allowCommentNodes || !Node.isCommentNode(currentChild)) 10 | result.push(currentChild); 11 | } 12 | return result; 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./appendCommaToText"; 2 | export * from "./getEndIndexFromArray"; 3 | export * from "./getInsertPosFromIndex"; 4 | export * from "./getMixinStructureFunctions"; 5 | export * from "./getNodesToReturn"; 6 | export * from "./getRangeWithoutCommentsFromArray"; 7 | export * from "./getStructureFunctions"; 8 | export * from "./verifyAndGetIndex"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./code"; 2 | export * from "./formatting"; 3 | export * from "./helpers"; 4 | export * from "./manipulations"; 5 | export * from "./nodeHandlers"; 6 | export * from "./textChecks"; 7 | export * from "./textManipulators"; 8 | export * from "./textSeek"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/manipulations/ManipulationError.ts: -------------------------------------------------------------------------------- 1 | import { errors } from "@ts-morph/common"; 2 | 3 | /** Occurs when there is a problem doing a manipulation. */ 4 | export class ManipulationError extends errors.InvalidOperationError { 5 | constructor( 6 | public readonly filePath: string, 7 | public readonly oldText: string, 8 | public readonly newText: string, 9 | errorMessage: string, 10 | ) { 11 | super(errorMessage); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/manipulations/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./insertion"; 2 | export * from "./ManipulationError"; 3 | export * from "./move"; 4 | export * from "./removal"; 5 | export * from "./replaction"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/nodeHandlers/NodeHandler.ts: -------------------------------------------------------------------------------- 1 | import { ts } from "@ts-morph/common"; 2 | import { Node } from "../../compiler"; 3 | 4 | /** 5 | * Handler for replacing node. 6 | */ 7 | export interface NodeHandler { 8 | handleNode(currentNode: Node, newNode: ts.Node, newSourceFile: ts.SourceFile): void; 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/nodeHandlers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ChangeChildOrderParentHandler"; 2 | export * from "./DefaultParentHandler"; 3 | export * from "./ForgetChangedNodeHandler"; 4 | export * from "./NodeHandler"; 5 | export * from "./NodeHandlerFactory"; 6 | export * from "./NodeHandlerHelper"; 7 | export * from "./ParentFinderReplacementNodeHandler"; 8 | export * from "./RangeHandler"; 9 | export * from "./RangeParentHandler"; 10 | export * from "./StraightReplacementNodeHandler"; 11 | export * from "./TryOrForgetNodeHandler"; 12 | export * from "./UnwrapParentHandler"; 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/readme.md: -------------------------------------------------------------------------------- 1 | # Manipulation 2 | 3 | In this folder, most of the code is for changing the text and replacing an old tree with the new one. 4 | 5 | Directory overview: 6 | 7 | - `manipulations` - Functions used to do a manipulations. 8 | - `textManipulations` - Classes used to manipulate text. 9 | - `nodeHandlers` - Classes to replace a tree. 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textManipulators/FullReplacementTextManipulator.ts: -------------------------------------------------------------------------------- 1 | import { TextManipulator } from "./TextManipulator"; 2 | 3 | export class FullReplacementTextManipulator implements TextManipulator { 4 | readonly #newText: string; 5 | 6 | constructor(newText: string) { 7 | this.#newText = newText; 8 | } 9 | 10 | getNewText(inputText: string) { 11 | return this.#newText; 12 | } 13 | 14 | getTextForError(newText: string) { 15 | return newText; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textManipulators/TextManipulator.ts: -------------------------------------------------------------------------------- 1 | export interface TextManipulator { 2 | getNewText(inputText: string): string; 3 | getTextForError(newText: string): string; 4 | } 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textManipulators/UnchangedTextManipulator.ts: -------------------------------------------------------------------------------- 1 | import { TextManipulator } from "./TextManipulator"; 2 | 3 | export class UnchangedTextManipulator implements TextManipulator { 4 | getNewText(inputText: string) { 5 | return inputText; 6 | } 7 | 8 | getTextForError(newText: string) { 9 | return newText; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textManipulators/getTextForError.ts: -------------------------------------------------------------------------------- 1 | export function getTextForError(newText: string, pos: number, length = 0) { 2 | const startPos = Math.max(0, newText.lastIndexOf("\n", pos) - 100); 3 | let endPos = Math.min(newText.length, newText.indexOf("\n", pos + length)); 4 | endPos = endPos === -1 ? newText.length : Math.min(newText.length, endPos + 100); 5 | 6 | let text = ""; 7 | text += newText.substring(startPos, endPos); 8 | 9 | if (startPos !== 0) 10 | text = "..." + text; 11 | if (endPos !== newText.length) 12 | text += "..."; 13 | 14 | return text; 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textManipulators/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ChangingChildOrderTextManipulator"; 2 | export * from "./FullReplacementTextManipulator"; 3 | export * from "./getSpacingBetweenNodes"; 4 | export * from "./getTextForError"; 5 | export * from "./InsertionTextManipulator"; 6 | export * from "./RemoveChildrenTextManipulator"; 7 | export * from "./RemoveChildrenWithFormattingTextManipulator"; 8 | export * from "./RenameLocationTextManipulator"; 9 | export * from "./TextManipulator"; 10 | export * from "./UnchangedTextManipulator"; 11 | export * from "./UnwrapTextManipulator"; 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getNextMatchingPos.ts: -------------------------------------------------------------------------------- 1 | // todo: tests 2 | export function getNextMatchingPos(text: string, pos: number, condition: (charCode: number) => boolean) { 3 | while (pos < text.length) { 4 | const charCode = text.charCodeAt(pos); 5 | if (!condition(charCode)) 6 | pos++; 7 | else 8 | break; 9 | } 10 | 11 | return pos; 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getNextNonWhitespacePos.ts: -------------------------------------------------------------------------------- 1 | import { StringUtils } from "@ts-morph/common"; 2 | import { getNextMatchingPos } from "./getNextMatchingPos"; 3 | import { getPreviousMatchingPos } from "./getPreviousMatchingPos"; 4 | 5 | export function getNextNonWhitespacePos(text: string, pos: number) { 6 | return getNextMatchingPos(text, pos, isNotWhitespace); 7 | } 8 | 9 | export function getPreviousNonWhitespacePos(text: string, pos: number) { 10 | return getPreviousMatchingPos(text, pos, isNotWhitespace); 11 | } 12 | 13 | function isNotWhitespace(charCode: number) { 14 | return !StringUtils.isWhitespaceCharCode(charCode); 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPosAfterNewLine.ts: -------------------------------------------------------------------------------- 1 | export function getPosAfterNewLine(text: string, pos: number) { 2 | while (pos < text.length) { 3 | if (text[pos] === "\n") 4 | return pos + 1; 5 | pos++; 6 | } 7 | return pos; 8 | } 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPosAfterPreviousNonBlankLine.ts: -------------------------------------------------------------------------------- 1 | export function getPosAfterPreviousNonBlankLine(text: string, pos: number) { 2 | let newPos = pos; 3 | for (let i = pos - 1; i >= 0; i--) { 4 | if (text[i] === " " || text[i] === "\t") 5 | continue; 6 | if (text[i] === "\n") { 7 | newPos = i + 1; 8 | if (text[i - 1] === "\r") 9 | i--; 10 | continue; 11 | } 12 | 13 | return newPos; 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPosAtEndOfPreviousLine.ts: -------------------------------------------------------------------------------- 1 | export function getPosAtEndOfPreviousLine(fullText: string, pos: number) { 2 | while (pos > 0) { 3 | pos--; 4 | if (fullText[pos] === "\n") { 5 | if (fullText[pos - 1] === "\r") 6 | return pos - 1; 7 | return pos; 8 | } 9 | } 10 | 11 | return pos; 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPosAtEndOfPreviousLineOrNonWhitespace.ts: -------------------------------------------------------------------------------- 1 | export function getPosAtEndOfPreviousLineOrNonWhitespace(fullText: string, pos: number) { 2 | while (pos > 0) { 3 | pos--; 4 | 5 | const currentChar = fullText[pos]; 6 | if (currentChar === "\n") { 7 | if (fullText[pos - 1] === "\r") 8 | return pos - 1; 9 | return pos; 10 | } else if (currentChar !== " " && currentChar !== "\t") { 11 | return pos + 1; 12 | } 13 | } 14 | 15 | return pos; 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPosAtNextNonBlankLine.ts: -------------------------------------------------------------------------------- 1 | export function getPosAtNextNonBlankLine(text: string, pos: number) { 2 | let newPos = pos; 3 | for (let i = pos; i < text.length; i++) { 4 | if (text[i] === " " || text[i] === "\t") 5 | continue; 6 | if (text[i] === "\r" && text[i + 1] === "\n" || text[i] === "\n") { 7 | newPos = i + 1; 8 | if (text[i] === "\r") { 9 | i++; 10 | newPos++; 11 | } 12 | continue; 13 | } 14 | 15 | return newPos; 16 | } 17 | 18 | return newPos; 19 | } 20 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPosAtStartOfLineOrNonWhitespace.ts: -------------------------------------------------------------------------------- 1 | export function getPosAtStartOfLineOrNonWhitespace(fullText: string, pos: number) { 2 | while (pos > 0) { 3 | pos--; 4 | 5 | const currentChar = fullText[pos]; 6 | if (currentChar === "\n") 7 | return pos + 1; 8 | else if (currentChar !== " " && currentChar !== "\t") 9 | return pos + 1; 10 | } 11 | 12 | return pos; 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/getPreviousMatchingPos.ts: -------------------------------------------------------------------------------- 1 | // todo: tests 2 | export function getPreviousMatchingPos(text: string, pos: number, condition: (charCode: number) => boolean) { 3 | while (pos > 0) { 4 | const charCode = text.charCodeAt(pos - 1); 5 | if (!condition(charCode)) 6 | pos--; 7 | else 8 | break; 9 | } 10 | 11 | return pos; 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/manipulation/textSeek/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getNextMatchingPos"; 2 | export * from "./getNextNonWhitespacePos"; 3 | export * from "./getPosAfterNewLine"; 4 | export * from "./getPosAfterPreviousNonBlankLine"; 5 | export * from "./getPosAtEndOfPreviousLine"; 6 | export * from "./getPosAtEndOfPreviousLineOrNonWhitespace"; 7 | export * from "./getPosAtNextNonBlankLine"; 8 | export * from "./getPosAtStartOfLineOrNonWhitespace"; 9 | export * from "./getPreviousMatchingPos"; 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/next-major-deprecations.md: -------------------------------------------------------------------------------- 1 | # Deprecations in the next major 2 | 3 | - None 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/options/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ManipulationSettingsContainer"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./InitializerExpressionableNodeStructurePrinter"; 2 | export * from "./ModifierableNodeStructurePrinter"; 3 | export * from "./ReturnTypedNodeStructurePrinter"; 4 | export * from "./TypedNodeStructurePrinter"; 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/class/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ClassDeclarationStructurePrinter"; 2 | export * from "./ClassMemberStructurePrinter"; 3 | export * from "./ClassStaticBlockDeclarationStructurePrinter"; 4 | export * from "./ConstructorDeclarationStructurePrinter"; 5 | export * from "./GetAccessorDeclarationStructurePrinter"; 6 | export * from "./GetAndSetAccessorStructurePrinter"; 7 | export * from "./MethodDeclarationStructurePrinter"; 8 | export * from "./PropertyDeclarationStructurePrinter"; 9 | export * from "./SetAccessorDeclarationStructurePrinter"; 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/common/StringStructurePrinter.ts: -------------------------------------------------------------------------------- 1 | import { CodeBlockWriter } from "../../codeBlockWriter"; 2 | import { WriterFunction } from "../../types"; 3 | import { Printer } from "../Printer"; 4 | 5 | export type StringStructureToTextItem = string | WriterFunction; 6 | 7 | export class StringStructurePrinter extends Printer { 8 | printText(writer: CodeBlockWriter, textOrWriterFunc: StringStructureToTextItem) { 9 | if (typeof textOrWriterFunc === "string") 10 | writer.write(textOrWriterFunc); 11 | else 12 | textOrWriterFunc(writer); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./StringStructurePrinter"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/decorator/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./DecoratorStructurePrinter"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/doc/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JSDocStructurePrinter"; 2 | export * from "./JSDocTagStructurePrinter"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/enum/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./EnumDeclarationStructurePrinter"; 2 | export * from "./EnumMemberStructurePrinter"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/expression/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./object"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/expression/object/ShorthandPropertyAssignmentStructurePrinter.ts: -------------------------------------------------------------------------------- 1 | import { CodeBlockWriter } from "../../../codeBlockWriter"; 2 | import { OptionalKind, ShorthandPropertyAssignmentStructure } from "../../../structures"; 3 | import { NodePrinter } from "../../NodePrinter"; 4 | 5 | export class ShorthandPropertyAssignmentStructurePrinter extends NodePrinter> { 6 | protected printTextInternal(writer: CodeBlockWriter, structure: OptionalKind) { 7 | writer.write(`${structure.name}`); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/expression/object/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ObjectLiteralExpressionPropertyStructurePrinter"; 2 | export * from "./PropertyAssignmentStructurePrinter"; 3 | export * from "./ShorthandPropertyAssignmentStructurePrinter"; 4 | export * from "./SpreadAssignmentStructurePrinter"; 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/formatting/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./BlankLineFormattingStructuresPrinter"; 2 | export * from "./CommaNewLineSeparatedStructuresPrinter"; 3 | export * from "./CommaSeparatedStructuresPrinter"; 4 | export * from "./NewLineFormattingStructuresPrinter"; 5 | export * from "./SpaceFormattingStructuresPrinter"; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/function/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./FunctionDeclarationStructurePrinter"; 2 | export * from "./ParameterDeclarationStructurePrinter"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./writerUtils"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/helpers/writerUtils.ts: -------------------------------------------------------------------------------- 1 | import { StringUtils } from "@ts-morph/common"; 2 | import { CodeBlockWriter } from "../../codeBlockWriter"; 3 | import { CharCodes } from "../../utils"; 4 | 5 | export function isLastNonWhitespaceCharCloseBrace(writer: CodeBlockWriter) { 6 | return writer.iterateLastCharCodes(charCode => { 7 | if (charCode === CharCodes.CLOSE_BRACE) 8 | return true; 9 | else if (StringUtils.isWhitespaceCharCode(charCode)) 10 | return undefined; 11 | else 12 | return false; 13 | }) || false; 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./base"; 2 | export * from "./class"; 3 | export * from "./common"; 4 | export * from "./decorator"; 5 | export * from "./doc"; 6 | export * from "./enum"; 7 | export * from "./expression"; 8 | export * from "./formatting"; 9 | export * from "./function"; 10 | export * from "./interface"; 11 | export * from "./jsx"; 12 | export * from "./module"; 13 | export * from "./NodePrinter"; 14 | export * from "./Printer"; 15 | export * from "./statement"; 16 | export * from "./types"; 17 | export * from "./variable"; 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/interface/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CallSignatureDeclarationStructurePrinter"; 2 | export * from "./ConstructSignatureDeclarationStructurePrinter"; 3 | export * from "./IndexSignatureDeclarationStructurePrinter"; 4 | export * from "./InterfaceDeclarationStructurePrinter"; 5 | export * from "./MethodSignatureStructurePrinter"; 6 | export * from "./PropertySignatureStructurePrinter"; 7 | export * from "./TypeElementMemberedNodeStructurePrinter"; 8 | export * from "./TypeElementMemberStructurePrinter"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/jsx/JsxNamespacedNameStructurePrinter.ts: -------------------------------------------------------------------------------- 1 | import { CodeBlockWriter } from "../../codeBlockWriter"; 2 | import { JsxNamespacedNameStructure, OptionalKind } from "../../structures"; 3 | import { NodePrinter } from "../NodePrinter"; 4 | 5 | export class JsxNamespacedNameStructurePrinter extends NodePrinter { 6 | protected printTextInternal(writer: CodeBlockWriter, structure: JsxNamespacedNameStructure) { 7 | writer.write(structure.namespace).write(":").write(structure.name); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/jsx/JsxSpreadAttributeStructurePrinter.ts: -------------------------------------------------------------------------------- 1 | import { CodeBlockWriter } from "../../codeBlockWriter"; 2 | import { JsxSpreadAttributeStructure } from "../../structures"; 3 | import { NodePrinter } from "../NodePrinter"; 4 | 5 | export class JsxSpreadAttributeStructurePrinter extends NodePrinter { 6 | protected printTextInternal(writer: CodeBlockWriter, structure: JsxSpreadAttributeStructure) { 7 | writer.hangingIndent(() => { 8 | writer.write("{"); 9 | writer.write("..."); 10 | writer.write(structure.expression); 11 | writer.write("}"); 12 | }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/jsx/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JsxAttributeDeciderStructurePrinter"; 2 | export * from "./JsxAttributeStructurePrinter"; 3 | export * from "./JsxChildDeciderStructurePrinter"; 4 | export * from "./JsxElementStructurePrinter"; 5 | export * from "./JsxNamespacedNameStructurePrinter"; 6 | export * from "./JsxSelfClosingElementStructurePrinter"; 7 | export * from "./JsxSpreadAttributeStructurePrinter"; 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/module/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ExportAssignmentStructurePrinter"; 2 | export * from "./ExportDeclarationStructurePrinter"; 3 | export * from "./ImportAttributeStructurePrinter"; 4 | export * from "./ImportDeclarationStructurePrinter"; 5 | export * from "./ModuleDeclarationStructurePrinter"; 6 | export * from "./NamedImportExportSpecifierStructurePrinter"; 7 | export * from "./SourceFileStructurePrinter"; 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/statement/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./StatementedNodeStructurePrinter"; 2 | export * from "./StatementStructurePrinter"; 3 | export * from "./VariableStatementStructurePrinter"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./TypeAliasDeclarationStructurePrinter"; 2 | export * from "./TypeParameterDeclarationStructurePrinter"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structurePrinters/variable/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./VariableDeclarationStructurePrinter"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/AbstractableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface AbstractableNodeStructure { 2 | isAbstract?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/AmbientableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface AmbientableNodeStructure { 2 | hasDeclareKeyword?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/AsyncableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface AsyncableNodeStructure { 2 | isAsync?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/AwaitableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface AwaitableNodeStructure { 2 | isAwaited?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/DecoratableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { DecoratorStructure } from "../decorator"; 2 | import { OptionalKind } from "../types"; 3 | 4 | export interface DecoratableNodeStructure { 5 | decorators?: OptionalKind[]; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ExclamationTokenableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface ExclamationTokenableNodeStructure { 2 | hasExclamationToken?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ExportableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface ExportableNodeStructure { 2 | isExported?: boolean; 3 | isDefaultExport?: boolean; 4 | } 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ExtendsClauseableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | 3 | export interface ExtendsClauseableNodeStructure { 4 | extends?: (string | WriterFunction)[] | WriterFunction; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/GeneratorableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface GeneratorableNodeStructure { 2 | isGenerator?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ImplementsClauseableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | 3 | export interface ImplementsClauseableNodeStructure { 4 | implements?: (string | WriterFunction)[] | WriterFunction; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/InitializerExpressionableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | 3 | export interface InitializerExpressionableNodeStructure { 4 | initializer?: string | WriterFunction; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/JSDocableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { JSDocStructure } from "../doc"; 2 | import { OptionalKind } from "../types"; 3 | 4 | export interface JSDocableNodeStructure { 5 | docs?: (OptionalKind | string)[]; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/OverrideableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface OverrideableNodeStructure { 2 | hasOverrideKeyword?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ParameteredNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { ParameterDeclarationStructure } from "../function"; 2 | import { OptionalKind } from "../types"; 3 | 4 | export interface ParameteredNodeStructure { 5 | parameters?: OptionalKind[]; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/QuestionDotTokenableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface QuestionDotTokenableNodeStructure { 2 | hasQuestionDotToken?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/QuestionTokenableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface QuestionTokenableNodeStructure { 2 | hasQuestionToken?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ReadonlyableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface ReadonlyableNodeStructure { 2 | isReadonly?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ReturnTypedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | 3 | export interface ReturnTypedNodeStructure { 4 | returnType?: string | WriterFunction; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ScopeableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { Scope } from "../../compiler"; 2 | 3 | export interface ScopeableNodeStructure { 4 | scope?: Scope; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/ScopedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { Scope } from "../../compiler"; 2 | 3 | export interface ScopedNodeStructure { 4 | scope?: Scope; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/SignaturedDeclarationStructure.ts: -------------------------------------------------------------------------------- 1 | import { ParameteredNodeStructure } from "./ParameteredNodeStructure"; 2 | import { ReturnTypedNodeStructure } from "./ReturnTypedNodeStructure"; 3 | 4 | export interface SignaturedDeclarationStructure extends ParameteredNodeStructure, ReturnTypedNodeStructure { 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/StaticableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface StaticableNodeStructure { 2 | isStatic?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/TypeParameteredNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { TypeParameterDeclarationStructure } from "../type"; 2 | import { OptionalKind } from "../types"; 3 | 4 | export interface TypeParameteredNodeStructure { 5 | typeParameters?: (OptionalKind | string)[]; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/TypedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | 3 | export interface TypedNodeStructure { 4 | type?: string | WriterFunction; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/BindingNamedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface BindingNamedNodeStructure { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/ImportAttributeNamedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface ImportAttributeNamedNodeStructure { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/ModuleNamedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface ModuleNamedNodeStructure { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/NameableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface NameableNodeStructure { 2 | name?: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/NamedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface NamedNodeStructure { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/PropertyNameableNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface PropertyNameableNodeStructure { 2 | name?: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/PropertyNamedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface PropertyNamedNodeStructure { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/base/name/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./BindingNamedNodeStructure"; 2 | export * from "./ImportAttributeNamedNodeStructure"; 3 | export * from "./ModuleNamedNodeStructure"; 4 | export * from "./NameableNodeStructure"; 5 | export * from "./NamedNodeStructure"; 6 | export * from "./PropertyNameableNodeStructure"; 7 | export * from "./PropertyNamedNodeStructure"; 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/class/ClassStaticBlockDeclarationStructure.ts: -------------------------------------------------------------------------------- 1 | import { JSDocableNodeStructure } from "../base"; 2 | import { StatementedNodeStructure } from "../statement"; 3 | import { KindedStructure, Structure } from "../Structure.generated"; 4 | import { StructureKind } from "../StructureKind"; 5 | 6 | export interface ClassStaticBlockDeclarationStructure 7 | extends Structure, ClassStaticBlockDeclarationSpecificStructure, JSDocableNodeStructure, StatementedNodeStructure 8 | { 9 | } 10 | 11 | export interface ClassStaticBlockDeclarationSpecificStructure extends KindedStructure { 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/class/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ClassLikeDeclarationBaseStructure"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/class/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./base"; 2 | export * from "./ClassDeclarationStructure"; 3 | export * from "./ClassStaticBlockDeclarationStructure"; 4 | export * from "./ConstructorDeclarationStructure"; 5 | export * from "./GetAccessorDeclarationStructure"; 6 | export * from "./MethodDeclarationStructure"; 7 | export * from "./PropertyDeclarationStructure"; 8 | export * from "./SetAccessorDeclarationStructure"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/decorator/DecoratorStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface DecoratorStructure extends Structure, DecoratorSpecificStructure { 6 | } 7 | 8 | export interface DecoratorSpecificStructure extends KindedStructure { 9 | name: string; 10 | /** 11 | * Arguments for a decorator factory. 12 | * @remarks Provide an empty array to make the structure a decorator factory. 13 | */ 14 | arguments?: (string | WriterFunction)[] | WriterFunction; 15 | typeArguments?: string[]; 16 | } 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/decorator/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./DecoratorStructure"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/doc/JSDocTagStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface JSDocTagStructure extends Structure, JSDocTagSpecificStructure { 6 | } 7 | 8 | export interface JSDocTagSpecificStructure extends KindedStructure { 9 | /** The name for the JS doc tag that comes after the "at" symbol. */ 10 | tagName: string; 11 | /** The text that follows the tag name. */ 12 | text?: string | WriterFunction; 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/doc/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JSDocStructure"; 2 | export * from "./JSDocTagStructure"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/enum/EnumMemberStructure.ts: -------------------------------------------------------------------------------- 1 | import { InitializerExpressionableNodeStructure, JSDocableNodeStructure, PropertyNamedNodeStructure } from "../base"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface EnumMemberStructure 6 | extends Structure, EnumMemberSpecificStructure, PropertyNamedNodeStructure, JSDocableNodeStructure, InitializerExpressionableNodeStructure 7 | { 8 | } 9 | 10 | export interface EnumMemberSpecificStructure extends KindedStructure { 11 | /** Convenience property for setting the initializer. */ 12 | value?: number | string; 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/enum/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./EnumDeclarationStructure"; 2 | export * from "./EnumMemberStructure"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/expressioned/ExpressionedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../../types"; 2 | 3 | export interface ExpressionedNodeStructure { 4 | expression: string | WriterFunction; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/expressioned/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ExpressionedNodeStructure"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./expressioned"; 2 | export * from "./object"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/object/PropertyAssignmentStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../../types"; 2 | import { PropertyNamedNodeStructure } from "../../base"; 3 | import { KindedStructure, Structure } from "../../Structure.generated"; 4 | import { StructureKind } from "../../StructureKind"; 5 | 6 | export interface PropertyAssignmentStructure extends Structure, PropertyAssignmentSpecificStructure, PropertyNamedNodeStructure { 7 | } 8 | 9 | export interface PropertyAssignmentSpecificStructure extends KindedStructure { 10 | initializer: string | WriterFunction; 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/object/ShorthandPropertyAssignmentStructure.ts: -------------------------------------------------------------------------------- 1 | import { NamedNodeStructure } from "../../base"; 2 | import { KindedStructure, Structure } from "../../Structure.generated"; 3 | import { StructureKind } from "../../StructureKind"; 4 | 5 | export interface ShorthandPropertyAssignmentStructure extends Structure, ShorthandPropertyAssignmentSpecificStructure, NamedNodeStructure { 6 | } 7 | 8 | export interface ShorthandPropertyAssignmentSpecificStructure extends KindedStructure { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/object/SpreadAssignmentStructure.ts: -------------------------------------------------------------------------------- 1 | import { KindedStructure, Structure } from "../../Structure.generated"; 2 | import { StructureKind } from "../../StructureKind"; 3 | import { ExpressionedNodeStructure } from "../expressioned"; 4 | 5 | export interface SpreadAssignmentStructure extends Structure, SpreadAssignmentSpecificStructure, ExpressionedNodeStructure { 6 | } 7 | 8 | export interface SpreadAssignmentSpecificStructure extends KindedStructure { 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/expression/object/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./PropertyAssignmentStructure"; 2 | export * from "./ShorthandPropertyAssignmentStructure"; 3 | export * from "./SpreadAssignmentStructure"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/function/FunctionLikeDeclarationStructure.ts: -------------------------------------------------------------------------------- 1 | import { JSDocableNodeStructure, SignaturedDeclarationStructure, TypeParameteredNodeStructure } from "../base"; 2 | import { StatementedNodeStructure } from "../statement"; 3 | 4 | export interface FunctionLikeDeclarationStructure 5 | extends SignaturedDeclarationStructure, TypeParameteredNodeStructure, JSDocableNodeStructure, StatementedNodeStructure 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/function/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./FunctionDeclarationStructure"; 2 | export * from "./FunctionLikeDeclarationStructure"; 3 | export * from "./ParameterDeclarationStructure"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./aliases"; 2 | export * from "./base"; 3 | export * from "./class"; 4 | export * from "./decorator"; 5 | export * from "./doc"; 6 | export * from "./enum"; 7 | export * from "./expression"; 8 | export * from "./function"; 9 | export * from "./interface"; 10 | export * from "./jsx"; 11 | export * from "./module"; 12 | export * from "./statement"; 13 | export * from "./Structure.generated"; 14 | export * from "./StructureKind"; 15 | export * from "./type"; 16 | export * from "./types"; 17 | export * from "./utils"; 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/interface/CallSignatureDeclarationStructure.ts: -------------------------------------------------------------------------------- 1 | import { JSDocableNodeStructure, SignaturedDeclarationStructure, TypeParameteredNodeStructure } from "../base"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface CallSignatureDeclarationStructure 6 | extends Structure, CallSignatureDeclarationSpecificStructure, JSDocableNodeStructure, SignaturedDeclarationStructure, TypeParameteredNodeStructure 7 | { 8 | } 9 | 10 | export interface CallSignatureDeclarationSpecificStructure extends KindedStructure { 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/interface/ConstructSignatureDeclarationStructure.ts: -------------------------------------------------------------------------------- 1 | import { JSDocableNodeStructure, SignaturedDeclarationStructure, TypeParameteredNodeStructure } from "../base"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface ConstructSignatureDeclarationStructure 6 | extends Structure, ConstructSignatureDeclarationSpecificStructure, JSDocableNodeStructure, SignaturedDeclarationStructure, TypeParameteredNodeStructure 7 | { 8 | } 9 | 10 | export interface ConstructSignatureDeclarationSpecificStructure extends KindedStructure { 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/interface/IndexSignatureDeclarationStructure.ts: -------------------------------------------------------------------------------- 1 | import { JSDocableNodeStructure, ReadonlyableNodeStructure, ReturnTypedNodeStructure } from "../base"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface IndexSignatureDeclarationStructure 6 | extends Structure, IndexSignatureDeclarationSpecificStructure, JSDocableNodeStructure, ReadonlyableNodeStructure, ReturnTypedNodeStructure 7 | { 8 | } 9 | 10 | export interface IndexSignatureDeclarationSpecificStructure extends KindedStructure { 11 | keyName?: string; 12 | keyType?: string; 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/interface/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./CallSignatureDeclarationStructure"; 2 | export * from "./ConstructSignatureDeclarationStructure"; 3 | export * from "./IndexSignatureDeclarationStructure"; 4 | export * from "./InterfaceDeclarationStructure"; 5 | export * from "./MethodSignatureStructure"; 6 | export * from "./PropertySignatureStructure"; 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/JsxAttributeStructure.ts: -------------------------------------------------------------------------------- 1 | import { KindedStructure, Structure } from "../Structure.generated"; 2 | import { StructureKind } from "../StructureKind"; 3 | import { JsxNamespacedNameStructure } from "./JsxNamespacedNameStructure"; 4 | 5 | export interface JsxAttributeStructure extends Structure, JsxAttributeSpecificStructure { 6 | } 7 | 8 | export interface JsxAttributeSpecificStructure extends KindedStructure { 9 | name: string | JsxNamespacedNameStructure; 10 | initializer?: string; 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/JsxNamespacedNameStructure.ts: -------------------------------------------------------------------------------- 1 | export interface JsxNamespacedNameStructure { 2 | namespace: string; 3 | name: string; 4 | } 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/JsxSelfClosingElementStructure.ts: -------------------------------------------------------------------------------- 1 | import { KindedStructure, Structure } from "../Structure.generated"; 2 | import { StructureKind } from "../StructureKind"; 3 | import { JsxAttributedNodeStructure, JsxTagNamedNodeStructure } from "./base"; 4 | 5 | export interface JsxSelfClosingElementStructure 6 | extends Structure, JsxTagNamedNodeStructure, JsxSelfClosingElementSpecificStructure, JsxAttributedNodeStructure 7 | { 8 | } 9 | 10 | export interface JsxSelfClosingElementSpecificStructure extends KindedStructure { 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/JsxSpreadAttributeStructure.ts: -------------------------------------------------------------------------------- 1 | import { KindedStructure, Structure } from "../Structure.generated"; 2 | import { StructureKind } from "../StructureKind"; 3 | 4 | export interface JsxSpreadAttributeStructure extends Structure, JsxSpreadAttributeSpecificStructure { 5 | } 6 | 7 | export interface JsxSpreadAttributeSpecificStructure extends KindedStructure { 8 | expression: string; 9 | } 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/base/JsxAttributedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { OptionalKind } from "../../types"; 2 | import { JsxAttributeStructure } from "../JsxAttributeStructure"; 3 | import { JsxSpreadAttributeStructure } from "../JsxSpreadAttributeStructure"; 4 | 5 | export interface JsxAttributedNodeStructure { 6 | attributes?: (OptionalKind | JsxSpreadAttributeStructure)[]; 7 | } 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/base/JsxTagNamedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | export interface JsxTagNamedNodeStructure { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/base/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JsxAttributedNodeStructure"; 2 | export * from "./JsxTagNamedNodeStructure"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/jsx/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./base"; 2 | export * from "./JsxAttributeStructure"; 3 | export * from "./JsxElementStructure"; 4 | export * from "./JsxNamespacedNameStructure"; 5 | export * from "./JsxSelfClosingElementStructure"; 6 | export * from "./JsxSpreadAttributeStructure"; 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/module/ExportAssignmentStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | import { JSDocableNodeStructure } from "../base"; 3 | import { KindedStructure, Structure } from "../Structure.generated"; 4 | import { StructureKind } from "../StructureKind"; 5 | 6 | export interface ExportAssignmentStructure extends Structure, ExportAssignmentSpecificStructure, JSDocableNodeStructure { 7 | } 8 | 9 | export interface ExportAssignmentSpecificStructure extends KindedStructure { 10 | isExportEquals?: boolean; 11 | expression: string | WriterFunction; 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/module/ExportSpecifierStructure.ts: -------------------------------------------------------------------------------- 1 | import { KindedStructure, Structure } from "../Structure.generated"; 2 | import { StructureKind } from "../StructureKind"; 3 | 4 | export interface ExportSpecifierStructure extends Structure, ExportSpecifierSpecificStructure { 5 | } 6 | 7 | export interface ExportSpecifierSpecificStructure extends KindedStructure { 8 | name: string; 9 | alias?: string; 10 | isTypeOnly?: boolean; 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/module/ImportAttributeStructure.ts: -------------------------------------------------------------------------------- 1 | import { ImportAttributeNamedNodeStructure } from "../base"; 2 | import { KindedStructure, Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface ImportAttributeStructure extends Structure, ImportAttributeStructureSpecificStructure, ImportAttributeNamedNodeStructure { 6 | } 7 | 8 | export interface ImportAttributeStructureSpecificStructure extends KindedStructure { 9 | /** Expression value. Quote this when providing a string. */ 10 | value: string; 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/module/ImportSpecifierStructure.ts: -------------------------------------------------------------------------------- 1 | import { KindedStructure, Structure } from "../Structure.generated"; 2 | import { StructureKind } from "../StructureKind"; 3 | 4 | export interface ImportSpecifierStructure extends Structure, ImportSpecifierSpecificStructure { 5 | } 6 | 7 | export interface ImportSpecifierSpecificStructure extends KindedStructure { 8 | name: string; 9 | isTypeOnly?: boolean; 10 | alias?: string; 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/module/SourceFileStructure.ts: -------------------------------------------------------------------------------- 1 | import { StatementedNodeStructure } from "../statement"; 2 | import { Structure } from "../Structure.generated"; 3 | import { StructureKind } from "../StructureKind"; 4 | 5 | export interface SourceFileStructure extends Structure, SourceFileSpecificStructure, StatementedNodeStructure { 6 | } 7 | 8 | export interface SourceFileSpecificStructure { 9 | kind: StructureKind.SourceFile; 10 | } 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/module/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ExportAssignmentStructure"; 2 | export * from "./ExportDeclarationStructure"; 3 | export * from "./ExportSpecifierStructure"; 4 | export * from "./ImportAttributeStructure"; 5 | export * from "./ImportDeclarationStructure"; 6 | export * from "./ImportSpecifierStructure"; 7 | export * from "./ModuleDeclarationStructure"; 8 | export * from "./SourceFileStructure"; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/statement/StatementedNodeStructure.ts: -------------------------------------------------------------------------------- 1 | import { WriterFunction } from "../../types"; 2 | import { StatementStructures } from "../aliases"; 3 | 4 | export interface StatementedNodeStructure { 5 | statements?: (string | WriterFunction | StatementStructures)[] | string | WriterFunction; 6 | } 7 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/statement/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./StatementedNodeStructure"; 2 | export * from "./VariableDeclarationStructure"; 3 | export * from "./VariableStatementStructure"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/type/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./TypeAliasDeclarationStructure"; 2 | export * from "./TypeParameterDeclarationStructure"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/types.ts: -------------------------------------------------------------------------------- 1 | import { StructureKind } from "./StructureKind"; 2 | 3 | export type OptionalKind = 4 | & Pick> 5 | & Partial>; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/structures/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./forEachStructureChild"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/ast/expression/expressionTests.ts: -------------------------------------------------------------------------------- 1 | import { Expression } from "../../../../compiler"; 2 | 3 | describe("Expression", () => { 4 | // todo: tests 5 | }); 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/ast/interface/commentTypeElementTests.ts: -------------------------------------------------------------------------------- 1 | import { nameof } from "@ts-morph/common"; 2 | import { expect } from "chai"; 3 | import { CommentTypeElement, InterfaceDeclaration } from "../../../../compiler"; 4 | import { getInfoFromText } from "../../testHelpers"; 5 | 6 | describe("CommentTypeElement", () => { 7 | describe(nameof("remove"), () => { 8 | it("should remove the comment", () => { 9 | const { firstChild } = getInfoFromText("interface I {\n // test\n}"); 10 | firstChild.getMembersWithComments()[0].remove(); 11 | expect(firstChild.getText()).to.equal("interface I {\n}"); 12 | }); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/ast/type/thisTypeNodeTests.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxKind } from "@ts-morph/common"; 2 | import { expect } from "chai"; 3 | import { ThisTypeNode } from "../../../../compiler"; 4 | import { getInfoFromTextWithDescendant } from "../../testHelpers"; 5 | 6 | describe("ThisTypeNode", () => { 7 | function getNode(text: string) { 8 | return getInfoFromTextWithDescendant(text, SyntaxKind.ThisType); 9 | } 10 | 11 | it("should be able to get an instance of a ThisTypeNode", () => { 12 | const { descendant } = getNode("declare class Test { method(): this; }"); 13 | expect(descendant).to.be.instanceOf(ThisTypeNode); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/ast/type/typeQueryNodeTests.ts: -------------------------------------------------------------------------------- 1 | import { nameof, SyntaxKind } from "@ts-morph/common"; 2 | import { expect } from "chai"; 3 | import { TypeQueryNode } from "../../../../compiler"; 4 | import { getInfoFromText } from "../../testHelpers"; 5 | 6 | describe("TypeQueryNode", () => { 7 | function getTypeQueryNode(text: string) { 8 | const { sourceFile } = getInfoFromText(text); 9 | return sourceFile.getFirstDescendantByKindOrThrow(SyntaxKind.TypeQuery); 10 | } 11 | 12 | describe(nameof("getExprName"), () => { 13 | it("should get", () => { 14 | expect(getTypeQueryNode("const test: typeof Test").getExprName().getText(), "Test"); 15 | }); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/testHelpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./fillStructureWithDefaults"; 2 | export * from "./getInfoFromText"; 3 | export * from "./types"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/testHelpers/types.ts: -------------------------------------------------------------------------------- 1 | import { Structure, StructureKind } from "../../../structures"; 2 | 3 | export type OptionalKindAndTrivia = 4 | & Partial> 5 | & Omit; 6 | 7 | export type OptionalTrivia = 8 | & Partial> 9 | & Omit; 10 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/compiler/tools/diagnosticMessageChainTests.ts: -------------------------------------------------------------------------------- 1 | import { DiagnosticMessageChain } from "../../../compiler"; 2 | 3 | describe("DiagnosticMessageChain", () => { 4 | // todo: I don't know how to test this... 5 | }); 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0038tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { ClassDeclaration, PropertyDeclaration } from "../../compiler"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #38", () => { 6 | it("should set the initializer when it's a string", () => { 7 | const text = `class Identifier { 8 | public static readonly Version: string = "1.0"; 9 | }`; 10 | const { firstChild } = getInfoFromText(text); 11 | const prop = firstChild.getStaticProperties()[0] as PropertyDeclaration; 12 | prop.setInitializer(`"2.0"`); 13 | expect(firstChild.getFullText()).to.equal(text.replace("1", "2")); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0053tests.ts: -------------------------------------------------------------------------------- 1 | import { ClassDeclaration, PropertyDeclaration } from "../../compiler"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | const code = ` 5 | export class Class { 6 | prop = ""; 7 | 8 | constructor(param: Class) { 9 | } 10 | } 11 | `; 12 | 13 | describe("tests for issue #53", () => { 14 | const { firstChild } = getInfoFromText(code); 15 | 16 | it("should set the type", () => { 17 | const prop = firstChild.getInstanceProperty("prop")! as PropertyDeclaration; 18 | prop.setType("string"); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0089tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { ClassDeclaration } from "../../compiler"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #89", () => { 6 | it("should be able to set modifiers when a decorator exists", () => { 7 | const text = `/** Description */ 8 | @dec 9 | class Identifier { 10 | }`; 11 | const { firstChild, sourceFile } = getInfoFromText(text); 12 | firstChild.setIsExported(true); 13 | expect(sourceFile.getFullText()).to.equal(`/** Description */ 14 | @dec 15 | export class Identifier { 16 | }`); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0189tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #189", () => { 5 | it("should keep the comment at the beginning of the file", () => { 6 | const { sourceFile } = getInfoFromText(""); 7 | sourceFile.addStatements("/* test */"); 8 | sourceFile.addVariableStatement({ declarations: [{ name: "v" }] }); 9 | sourceFile.addImportDeclaration({ moduleSpecifier: "test" }); 10 | expect(sourceFile.getFullText()).to.deep.equal(`/* test */\nimport "test";\n\nlet v;\n`); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0265tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { ClassDeclaration } from "../../compiler"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #265", () => { 6 | it("should be able to handle getting static members when there exists a semicolon token", () => { 7 | const text = ` 8 | class Identifier { 9 | method() {}; 10 | }`; 11 | const { firstChild, sourceFile } = getInfoFromText(text); 12 | expect(() => firstChild.getStaticMembers()).to.not.throw(); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0312tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #312", () => { 5 | it("should still correctly add a function when the syntax is wrong like this", () => { 6 | const text = ` 7 | export type compilerVersions = "2.8.1" | "2.6.2" | "2.7.2"; 8 | 9 | export enum CompilerVersion { 10 | typescript = "2.8.1", 11 | typescript-2.6.2 = "2.6.2", 12 | typescript-2.7.2 = "2.7.2" 13 | }`; 14 | const { sourceFile } = getInfoFromText(text); 15 | expect(() => sourceFile.addFunction({ name: "func" })).to.not.throw(); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0335tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { FunctionDeclaration } from "../../compiler"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #335", () => { 6 | it("should be able to add statements at a half indentation level", () => { 7 | const text = ` 8 | function indentedF() { 9 | } 10 | `; 11 | const { firstChild, sourceFile } = getInfoFromText(text); 12 | firstChild.addStatements("return null;"); 13 | 14 | expect(sourceFile.getFullText()).to.equal(` 15 | function indentedF() { 16 | return null; 17 | } 18 | `); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0397tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #397", () => { 5 | it("should not error when getting properties from type", () => { 6 | const text = ` 7 | interface Foo { 8 | a: number, 9 | b: number, 10 | } 11 | export type Picked = Pick`; 12 | const { sourceFile } = getInfoFromText(text, { includeLibDts: true }); 13 | const typeAlias = sourceFile.getTypeAliasOrThrow("Picked"); 14 | 15 | expect(typeAlias.getType().getProperties().map(p => p.getName())).to.deep.equal(["a"]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0421tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #421", () => { 5 | it("should not remove a brace when adding a child to a namespace with dot notation", () => { 6 | const { sourceFile } = getInfoFromText("namespace Test.Test {\n}"); 7 | 8 | const namespaceDec = sourceFile.getModuleOrThrow("Test.Test"); 9 | namespaceDec.addEnum({ name: "Test" }); 10 | 11 | expect(sourceFile.getFullText()).to.equal("namespace Test.Test {\n enum Test {\n }\n}"); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0424tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #424", () => { 5 | it("should insert with correct indentation when the file has a BOM at the beginning", () => { 6 | const { sourceFile } = getInfoFromText("\ufeffmodule Test {\n enum Test {\n }\n}"); 7 | const enumDec = sourceFile.getModuleOrThrow("Test").getEnumOrThrow("Test"); 8 | 9 | enumDec.addMember({ name: "member", initializer: "5" }); 10 | 11 | expect(sourceFile.getFullText()).to.equal("module Test {\n enum Test {\n member = 5\n }\n}"); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0437tests.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxKind } from "@ts-morph/common"; 2 | import { expect } from "chai"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #437", () => { 6 | it("should not return undefined for findReferencesAsNodes", () => { 7 | const { sourceFile } = getInfoFromText("const f: { a: string; } = {a: '23'}; f['a'];"); 8 | const varDec = sourceFile.getVariableDeclarationOrThrow("f"); 9 | const results = varDec.getFirstDescendantByKindOrThrow(SyntaxKind.PropertySignature).findReferencesAsNodes(); 10 | 11 | expect(results.map(r => r.getText())).to.deep.equal(["a", "'a'"]); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0450tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #450", () => { 5 | it("should get the type without the import", () => { 6 | const { sourceFile, project } = getInfoFromText("import { Class } from './Class'; let c: Class;"); 7 | project.createSourceFile("Class.ts", "export class Class { prop: string; }"); 8 | const varDec = sourceFile.getVariableDeclarationOrThrow("c"); 9 | 10 | expect(varDec.getType().getText()).to.equal(`import("/Class").Class`); 11 | expect(varDec.getType().getText(varDec)).to.equal(`Class`); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0464tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { printNode } from "../../utils"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #464", () => { 6 | it("should print literals with printNode", () => { 7 | const text = `function test() { 8 | return 555; 9 | }`; 10 | const { sourceFile } = getInfoFromText(text); 11 | const func = sourceFile.getFunctionOrThrow("test"); 12 | expect(printNode(func.compilerNode)).to.equal(text); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0474tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #474", () => { 5 | it("should not error when organizing imports", () => { 6 | const { sourceFile } = getInfoFromText("class MyClass {\n}"); 7 | const classDec = sourceFile.getClassOrThrow("MyClass"); 8 | 9 | classDec.addProperties([{ 10 | name: "prop1", 11 | }, { 12 | leadingTrivia: writer => writer.newLine(), 13 | name: "prop2", 14 | }]); 15 | 16 | expect(classDec.getText()).to.equal(`class MyClass { 17 | prop1; 18 | 19 | prop2; 20 | }`); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0560tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #560", () => { 5 | it("should get declarations of import", () => { 6 | const { sourceFile } = getInfoFromText("enum Color { Red, Green, Blue }\nexport class LoginRequest { color: Color; }"); 7 | const prop = sourceFile.getClassOrThrow("LoginRequest").getPropertyOrThrow("color"); 8 | expect(prop.getType().isEnum()).to.be.true; 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0654tests.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxKind } from "@ts-morph/common"; 2 | import { expect } from "chai"; 3 | import { getInfoFromText } from "../compiler/testHelpers"; 4 | 5 | describe("tests for issue #654", () => { 6 | it("should add a new property where there exists a comment", () => { 7 | const { sourceFile } = getInfoFromText("const ole = {\n foo: 'foo',\n // c\n bar: 'bar'\n}"); 8 | const ole = sourceFile.getFirstDescendantByKindOrThrow(SyntaxKind.ObjectLiteralExpression); 9 | ole.addPropertyAssignment({ name: "baz", initializer: "'test'" }); 10 | expect(ole.getText()).to.equal(`{\n foo: 'foo',\n // c\n bar: 'bar',\n baz: 'test'\n}`); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/issues/0817tests.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getInfoFromText } from "../compiler/testHelpers"; 3 | 4 | describe("tests for issue #817", () => { 5 | it("should add a tag when the description is just a slash n", () => { 6 | const { sourceFile } = getInfoFromText(` 7 | class MyClass { 8 | }`); 9 | const classDec = sourceFile.getClassOrThrow("MyClass"); 10 | const jsDoc = classDec.addJsDoc({ description: "\n" }); 11 | jsDoc.addTag({ tagName: "myTag", text: "my text" }); 12 | expect(sourceFile.getFullText()).to.equal(` 13 | /** 14 | * @myTag my text 15 | */ 16 | class MyClass { 17 | }`); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/manipulation/getEndIndexFromArray.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { getEndIndexFromArray } from "../../manipulation"; 3 | 4 | describe("getEndIndexFromArray", () => { 5 | it("should return 0 when undefined", () => { 6 | expect(getEndIndexFromArray(undefined)).to.equal(0); 7 | }); 8 | 9 | it("should get the length when empty", () => { 10 | expect(getEndIndexFromArray([])).to.equal(0); 11 | }); 12 | 13 | it("should get the length when not empty", () => { 14 | expect(getEndIndexFromArray([1])).to.equal(1); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/testFiles/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./testClasses"; 2 | export * from "./testInterfaces"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/testFiles/testClasses.ts: -------------------------------------------------------------------------------- 1 | import { TestInterface } from "./testInterfaces"; 2 | 3 | export class TestClass implements TestInterface { 4 | name!: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/testFiles/testInterfaces.ts: -------------------------------------------------------------------------------- 1 | export interface TestInterface { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/testHelpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./fileSystemHostHelpers"; 2 | export * from "./getDefaultFormatCodeSettings"; 3 | export * from "./testDirectoryTree"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/tests/utils/newLineKindToStringTests.ts: -------------------------------------------------------------------------------- 1 | import { NewLineKind } from "@ts-morph/common"; 2 | import { expect } from "chai"; 3 | import { newLineKindToString } from "../../utils"; 4 | 5 | describe("newLineKindToString", () => { 6 | it("should return carriage return line feed for like", () => { 7 | expect(newLineKindToString(NewLineKind.CarriageReturnLineFeed)).to.equal("\r\n"); 8 | }); 9 | 10 | it("should return line feed for like", () => { 11 | expect(newLineKindToString(NewLineKind.LineFeed)).to.equal("\n"); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/types.ts: -------------------------------------------------------------------------------- 1 | import { CodeBlockWriter } from "./codeBlockWriter"; 2 | 3 | export type Constructor = new(...args: any[]) => T; 4 | export type InstanceOf = T extends new(...args: any[]) => infer U ? U : never; 5 | export type WriterFunction = (writer: CodeBlockWriter) => void; 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/CharCodes.ts: -------------------------------------------------------------------------------- 1 | export const CharCodes = { 2 | ASTERISK: "*".charCodeAt(0), 3 | NEWLINE: "\n".charCodeAt(0), 4 | CARRIAGE_RETURN: "\r".charCodeAt(0), 5 | SPACE: " ".charCodeAt(0), 6 | TAB: "\t".charCodeAt(0), 7 | CLOSE_BRACE: "}".charCodeAt(0), 8 | }; 9 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/compiler/ModuleUtils.ts: -------------------------------------------------------------------------------- 1 | import { StringUtils, SyntaxKind } from "@ts-morph/common"; 2 | import { SourceFile, Symbol } from "../../compiler"; 3 | 4 | export class ModuleUtils { 5 | private constructor() { 6 | } 7 | 8 | static isModuleSpecifierRelative(text: string) { 9 | return text.startsWith("./") 10 | || text.startsWith("../"); 11 | } 12 | 13 | static getReferencedSourceFileFromSymbol(symbol: Symbol) { 14 | const declarations = symbol.getDeclarations(); 15 | if (declarations.length === 0 || declarations[0].getKind() !== SyntaxKind.SourceFile) 16 | return undefined; 17 | return declarations[0] as SourceFile; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/compiler/getSymbolByNameOrFindFunction.ts: -------------------------------------------------------------------------------- 1 | import { Symbol } from "../../compiler/symbols/Symbol"; 2 | 3 | // todo: merge with getNamedNodeByNameOrFindFunction 4 | export function getSymbolByNameOrFindFunction(items: Symbol[], nameOrFindFunc: ((declaration: Symbol) => boolean) | string) { 5 | let findFunc: (declaration: Symbol) => boolean; 6 | 7 | if (typeof nameOrFindFunc === "string") 8 | findFunc = dec => dec.getName() === nameOrFindFunc; 9 | else 10 | findFunc = nameOrFindFunc; 11 | 12 | return items.find(findFunc); 13 | } 14 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/compiler/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getNodeByNameOrFindFunction"; 2 | export * from "./getParentSyntaxList"; 3 | export * from "./getSymbolByNameOrFindFunction"; 4 | export * from "./isNodeAmbientOrInAmbientContext"; 5 | export * from "./isStringKind"; 6 | export * from "./ModuleUtils"; 7 | export * from "./printNode"; 8 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/compiler/isStringKind.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxKind } from "@ts-morph/common"; 2 | 3 | /** 4 | * Gets if the kind is a string kind. 5 | * @param kind - Node kind. 6 | */ 7 | export function isStringKind(kind: SyntaxKind) { 8 | switch (kind) { 9 | case SyntaxKind.StringLiteral: 10 | case SyntaxKind.NoSubstitutionTemplateLiteral: 11 | case SyntaxKind.TemplateHead: 12 | case SyntaxKind.TemplateMiddle: 13 | case SyntaxKind.TemplateTail: 14 | return true; 15 | default: 16 | return false; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./AdvancedIterator"; 2 | export * from "./CharCodes"; 3 | export * from "./compiler"; 4 | export * from "./fillDefaultEditorSettings"; 5 | export * from "./fillDefaultFormatCodeSettings"; 6 | export * from "./getTextFromStringOrWriter"; 7 | export * from "./logging"; 8 | export * from "./namingValidator"; 9 | export * from "./newLineKindToString"; 10 | export * from "./references"; 11 | export * from "./setValueIfUndefined"; 12 | export * from "./tsconfig"; 13 | export * from "./TypeScriptVersionChecker"; 14 | export * from "./WriterUtils"; 15 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/logging/ConsoleLogger.ts: -------------------------------------------------------------------------------- 1 | import { EnableableLogger } from "./EnableableLogger"; 2 | 3 | export class ConsoleLogger extends EnableableLogger { 4 | protected logInternal(text: string) { 5 | console.log(text); 6 | } 7 | 8 | protected warnInternal(text: string) { 9 | console.warn(text); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/logging/EnableableLogger.ts: -------------------------------------------------------------------------------- 1 | import { Logger } from "./Logger"; 2 | 3 | export abstract class EnableableLogger implements Logger { 4 | #enabled = false; 5 | 6 | setEnabled(enabled: boolean) { 7 | this.#enabled = enabled; 8 | } 9 | 10 | log(text: string) { 11 | if (this.#enabled) 12 | this.logInternal(text); 13 | } 14 | 15 | warn(text: string) { 16 | if (this.#enabled) 17 | this.warnInternal(text); 18 | } 19 | 20 | protected abstract logInternal(text: string): void; 21 | protected abstract warnInternal(text: string): void; 22 | } 23 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/logging/Logger.ts: -------------------------------------------------------------------------------- 1 | export interface Logger { 2 | setEnabled(enabled: boolean): void; 3 | log(text: string): void; 4 | warn(text: string): void; 5 | } 6 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/logging/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ConsoleLogger"; 2 | export * from "./EnableableLogger"; 3 | export * from "./Logger"; 4 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/newLineKindToString.ts: -------------------------------------------------------------------------------- 1 | import { errors, NewLineKind } from "@ts-morph/common"; 2 | 3 | export function newLineKindToString(kind: NewLineKind) { 4 | switch (kind) { 5 | case NewLineKind.CarriageReturnLineFeed: 6 | return "\r\n"; 7 | case NewLineKind.LineFeed: 8 | return "\n"; 9 | default: 10 | throw new errors.NotImplementedError(`Not implemented newline kind: ${kind}`); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/references/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./LazyReferenceCoordinator"; 2 | export * from "./SourceFileReferenceContainer"; 3 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/setValueIfUndefined.ts: -------------------------------------------------------------------------------- 1 | export function setValueIfUndefined(obj: T, propertyName: U, defaultValue: T[U]) { 2 | if (typeof obj[propertyName] === "undefined") 3 | obj[propertyName] = defaultValue; 4 | } 5 | -------------------------------------------------------------------------------- /packages/ts-morph/src/utils/tsconfig/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./getCompilerOptionsFromTsConfig"; 2 | -------------------------------------------------------------------------------- /packages/ts-morph/tsconfig.declarations.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.common.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "rootDir": "./src", 6 | "outDir": "./lib", 7 | "emitDeclarationOnly": true 8 | }, 9 | "include": [ 10 | "./src" 11 | ], 12 | "exclude": [ 13 | "./src/tests" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/ts-morph/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.common.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "strict": true, 6 | "rootDir": "./src", 7 | "outDir": "./dist" 8 | }, 9 | "include": [ 10 | "./src" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/ts-morph/tsconfig.rollup.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "es2015", 5 | "moduleResolution": "node", 6 | "removeComments": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ts-morph 2 | 3 | [![CI](https://github.com/dsherret/ts-morph/workflows/CI/badge.svg)](https://github.com/dsherret/ts-morph/actions?query=workflow%3ACI) 4 | 5 | Monorepo for [ts-morph](packages/ts-morph) and related projects. 6 | 7 | ## Packages 8 | 9 | - [ts-morph](packages/ts-morph) - TypeScript Compiler API wrapper. Provides an easier way to programmatically navigate and manipulate TypeScript and JavaScript code. 10 | - [@ts-morph/bootstrap](packages/bootstrap) - Separate library for getting quickly setup with the Compiler API. 11 | 12 | ## Resources 13 | 14 | - [TypeScript AST Viewer](https://ts-ast-viewer.com) 15 | -------------------------------------------------------------------------------- /rfcs/README.md: -------------------------------------------------------------------------------- 1 | # RFCs 2 | 3 | This is a very loose RFC process. The implementation may slightly differ. 4 | 5 | [Issues](https://github.com/dsherret/ts-morph/issues?utf8=%E2%9C%93&q=label%3A%22requires+proposal%22+) 6 | 7 | ## Implemented 8 | 9 | - [RFC-0001](RFC-0001 - Inserting Into Statements Handling Comments.md) - Inserting into statements handling comments. 10 | 11 | ## In Progress 12 | 13 | - None 14 | -------------------------------------------------------------------------------- /tsconfig.common.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2022", 4 | "module": "CommonJS", 5 | "strict": true, 6 | "sourceMap": false, 7 | "removeComments": false, 8 | "forceConsistentCasingInFileNames": true, 9 | "esModuleInterop": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "noImplicitReturns": true, 12 | "newLine": "lf", 13 | "importHelpers": false 14 | }, 15 | "compileOnSave": false 16 | } 17 | --------------------------------------------------------------------------------