Show how to add factory generated statements
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Is this the way to do it?
```ts
import { Project, ts, printNode } from "ts-morph";
const tsVariableStatement = ts.factory.createVariableStatement(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(
ts.factory.createIdentifier("resolvers"),
undefined,
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("Resolvers"),
undefined
),
ts.factory.createObjectLiteralExpression(
[ts.factory.createPropertyAssignment(
ts.factory.createIdentifier("Profile"),
ts.factory.createObjectLiteralExpression(
[ts.factory.createPropertyAssignment(
ts.factory.createIdentifier("name"),
ts.factory.createArrowFunction(
undefined,
undefined,
[ts.factory.createParameterDeclaration(
undefined,
undefined,
undefined,
ts.factory.createIdentifier("user"),
undefined,
undefined,
undefined
)],
undefined,
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
ts.factory.createTemplateExpression(
ts.factory.createTemplateHead(
"",
""
),
[
ts.factory.createTemplateSpan(
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier("user"),
ts.factory.createIdentifier("firstName")
),
ts.factory.createTemplateMiddle(
" ",
" "
)
),
ts.factory.createTemplateSpan(
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier("user"),
ts.factory.createIdentifier("lastName")
),
ts.factory.createTemplateTail(
"",
""
)
)
]
)
)
)],
true
)
)],
true
)
)],
ts.NodeFlags.Const
)
)
sourceFile.addStatements([writer =>
writer.write(printNode( tsVariableStatement))
);
```
Contributor guide
Assessment
This issue has not been assessed yet.