Describe the bug
Version: latest
To Reproduce
const { Project, StructureKind } = require("ts-morph");
const project = new Project({});
const classFile = project.createSourceFile("src/MyClass.ts", `
class Foo {
/**
*
*/
}
`);
const classNode = classFile.getClasses()[0];
classNode.addConstructor({
statements: "console.log('i am constructor');",
});

Expected behavior
no error
Interesting. So what's happening here is that the code changes to something like this:
class Foo {
/**
*
*/
constructor() {
}
}
...which means that the constructor takes ownership of the jsdoc. So previously the class had 1 jsdoc child and now it also has 1 child (the constructor).
Thanks for reporting and providing an easy reproduction! I'll add some special case handling for this scenario.
For now, a workaround should be to just insert before the jsdoc using classNode.insertConstructor.
I've gotta hijack this to tell you that I love how you explain the bug when you understand it, @dsherret! Keep up the great work maintaining the lib :)
Thanks @lazarljubenovic! I have been taking a bit of a break from working on ts-morph, but I will get back to it very soon. I'll probably do a quick release to fix this bug over the weekend though.
@dsherret Thanks for your work 鉂わ笍. I want to know when there will be a new version released, since i noticed that you fixed this bug in master, but the default branch is latest.
@paranoidjk sorry, I was waiting for the TS 3.8 release. I'll do a release this weekend 馃檪