Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

ts-simple-ast: adding stuff to class

node v8.17.0
version: master
endpointsharetweet
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())
Loading…

no comments

    sign in to comment