Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to map a statement input to multiple statements #1532

Open
sureshjoshi opened this issue Apr 24, 2024 · 0 comments
Open

How to map a statement input to multiple statements #1532

sureshjoshi opened this issue Apr 24, 2024 · 0 comments

Comments

@sureshjoshi
Copy link

Great library! I ported from the regular typescript compiler for some of the nice bells and whistles.

However, I'm run into a "problem" that I have workarounds for, but I'm having a hard time believing there isn't a proper solution for.

I have a function of the form:

export function doThisThing(statement: ExpressionStatement): ExpressionStatement[]

Which will take in some line of code, and emit it as multiple expressions according to some rules.

I can't seem to find a ts-morph createExpressionStatement type of method, so I tried to use the ts factory.

newStatements.push(ts.factory.createExpressionStatement(...))

One problem with this is related to typing of ts.ExpressionStatement vs ExpressionStatement, but that's fine.

However, when I try to getText(), I get the following error:

Error: Debug Failure. False expression: Node must have a real position for this operation

I get that there is no associated source file, but shouldn't there be some way to extract the textual representation of a successfully created ExpressionStatement? I can't even add it to a source file, because to do that, I need to use stringified statements, which runs into the same problem.

The end goal here is to split up my project into more testable pieces, but it looks like I have to pass around SourceFile to every method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant