Skip to content

Use AST instead of ejs templates for generators #2113

@clayrisser

Description

@clayrisser

I think it would be better to generate code from an abstract syntax tree rather than using templates.

In the past, I have found the @babel/generator to be a solid choice for generating code from AST, however, that would not work for typescript. Perhaps, the getTextOfNode() method in the typescript compiler utilities would do the job.

https://github.com/Microsoft/TypeScript/blob/aa3734c14834afb454c49bc956489980d990a765/src/compiler/utilities.ts#L503

This is definitely a much more flexible approach because it conforms to the user's style of choice. It also allows for dynamically modifying existing files without the huge risk of destroying code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions