ts-simple-ast: adding stuff to class
const tsSimpleAst = require("ts-simple-ast")
const { stripIndent } = require('common-tags')
const {
default: Project,
SyntaxKind,
IndentationText,
} = tsSimpleAst
const project = new Project({useVirtualFileSystem: true, manipulationSettings: { indentationText: IndentationText.TwoSpaces }})
const file = project.createSourceFile(`test.ts`, stripIndent`
class Foo {
m1 () { }
}`)
const classDeclaration = file.getFirstDescendantByKindOrThrow(SyntaxKind.ClassDeclaration)
const syntaxList = classDeclaration.getFirstDescendantByKindOrThrow(SyntaxKind.SyntaxList)
syntaxList.insertChildText(0, writer => {
writer.write(`p1 = 1`)
})
console.log(file.getFullText())
no comments