Packages

ts-morph

28.0.0 · 12 Apr 2026MIT46.3M / weekRepositoryHomepagenpmAtom feed

Your version

3.0.0

major29 Jun 2019Where it was published

3.1.3 is the newest release of 3.x.

In short

5 breaking16 new2 faster7 fixed5 internal

  • Breaking

    renameNode and renameLocations are removed from the language service. To be consistent, the language service should not have methods that manipulate nodes.

  • Breaking

    SourceFile#getTypeReferenceDirectives() and #getReferencedFiles() now return the objects similar to what the compiler api returns.

  • Breaking

    Node#forEachChild is now aligned with the compiler API (same with forEachDescendant). These methods now stop when a value is returned in a callback and they will return the returned value.

  • Breaking

    The ObjectLiteralElementMemberStructures alias is now called ObjectLiteralExpressionPropertyStructures. This is a more correct name as an object literal expression has "properties" rather than "members" in the compiler api.

  • Breaking

    Renamed StructureTypeGuards methods to remove word Node and Declaration in certain cases.

Release note

The section about ts-morph of a note shared by several packages.

Bug Fixes

  • Incorrect type resolution behaviour when providing a tsconfig.json file path and having a different current working directory.

  • Comment nodes are no longer accidentally returned in some scenarios.

  • ClassLike and TypeElementMembered nodes would not get the correct "add" index when a comment member node was present.

  • Comment node parser now correctly returns comments on next line after tailing comma in object literal expressions.

  • Fix issues with Node#getText({ trimLeadingIndentation: true }) indenting more than it should.

  • ObjectLiteralExpression insert should insert around comment nodes. (c3b9f28), closes #605

  • Support nodes that may not have a source file (ex. globalThis node returned from a symbol)

Features

  • Add Symbol#getExportSymbol and TypeChecker#getExportSymbolOfSymbol.

  • Add methods Node#getLocals, #getLocalByName, #getLocalByNameOrThrow

  • Add ability to insert comments on enum declarations.

  • Add insertMember-like methods to ClassLikeDeclarationBase.

  • Add insertMember-like methods to TypeElementMemberedNode.

  • ObjectLiteralExpression#insertProperties and similar methods.

  • Add writer.withHangingIndent(() => {}). Also better hanging indent printing (a544e55), closes #616

  • Add Writers alias for WriterFunctions.

  • Writers.returnStatement should do hanging indent in certain cases.

  • RenameLocation - Support prefixText and suffixText when renaming.

  • RenameLocation - Add getPrefixText() and getSuffixText()

  • Add Node#getSymbolsInScope(meaning) and TypeChecker#getSymbolsInScope(node, meaning).

  • Add TypeGuards.isCommentNode.

  • Add WriterFunctions.assertion.

  • Smart comma insertion when printing comma separated values with comments.

  • Upgrade to code-block-writer 9.4.0.

Performance Improvements

  • Remove some internal regular expressions.

  • Improve performance of SourceFile#indent() and deindent().

Breaking changes

  • Breaking

    renameNode and renameLocations are removed from the language service. To be consistent, the language service should not have methods that manipulate nodes.

  • Breaking

    SourceFile#getTypeReferenceDirectives() and #getReferencedFiles() now return the objects similar to what the compiler api returns.

  • Breaking

    Node#forEachChild is now aligned with the compiler API (same with forEachDescendant). These methods now stop when a value is returned in a callback and they will return the returned value.

  • Breaking

    The ObjectLiteralElementMemberStructures alias is now called ObjectLiteralExpressionPropertyStructures. This is a more correct name as an object literal expression has "properties" rather than "members" in the compiler api.

  • Breaking

    Renamed StructureTypeGuards methods to remove word Node and Declaration in certain cases.

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.