This repository has been archived by the owner on Oct 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Methods editing #184
Comments
Hey, right now this library can only get the main structure of the code and not the individual statements. That might be added sometime in the future. It's for that reason that if you read a file and write it out, it won't include the statements. For example: Current Behaviour // V:\\MyClass.ts
export class MyClass {
myMethod(myParameter: string) {
console.log("blah blah blah... original code in here");
}
}
Outputs: export class MyClass {
myMethod(myParameter: string) {
}
} Writing Your Own Method/Function Body HOWEVER, you can do this:
Outputs: export class MyClass {
myMethod(myParameter: string) {
console.log('something');
}
} |
My workaround `
` |
After seeing your solution, I think it would be useful if there was a flag in this library that made it include the import {getInfoFromFiles} from "ts-type-info";
import * as ts from "typescript";
const result = getInfoFromFiles([fileName], { includeTsNodes: true });
const file = result.getFile(fileName);
const method = file.getClass("MyClass").getMethod("myMethod");
method.onWriteFunctionBody = writer => {
const methodNode = methodDef.tsNode as ts.MethodDeclaration;
methodNode.body.statements.forEach(statement => {
writer.writeLine(statement.getText());
});
}; I just opened #185. |
Thanks! |
This will be in 6.1 (releasing in a little bit). I just committed a test that shows a working example and updated my example in this issue. |
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
How i can get body of class method then modify and write it?
The text was updated successfully, but these errors were encountered: