dsherret / dsherret/ts-morph

Using ts-morph in transform plugin

Open
#537 8 comments 3 reactions 0 assignees View on GitHub
question
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

I am trying to use `ts-morph` to create a custom transformer that will enhance the limited TypeScript reflection system.

The raw TS API is really hard to use without proper docs and tutorials but I've tried your API and it's great and have all I need, works great using a standalone Project API.

In transformer signature I can use `createWrappedNode` and pass `program.getTypeChecker()` to read all the types info of class properties but I'm not able to manipulate the class node, even simple things like rename throws an error:

> A language service is required for this operation. This might occur when manipulating or getting type information from a node that was not added to a Project object and created via createWrappedNode. Please submit a bug report if you don't believe a language service should be required for this operation.

**Describe the solution you'd like**

It would be nice if some manipulations could work without language service (as it's possible to use `ts.updateFooBar` API to do it) as I think it's not possible to get a language service from Program, TransformationContext or SourceFile which are available in transform plugin hooks.

**Describe alternatives you've considered**

Using the raw compiler API... all I need is a way to pass additional data to the decorator factory call or emit a function call in the end of the file/class node + add import on top of file.

Contributor guide

Open the contributing guide

Research direction

Start with the transform plugin hooks and the use of createWrappedNode described in the issue, then compare the available Program, TransformationContext, and SourceFile APIs with the raw compiler API. A complete solution would define which manipulations can work without a language service and how transformer users can pass decorator data or emit calls and imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.