-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to format an export declaration so that each element is placed on a separate line? #153
Comments
I don't think I'm going to get into too much customization for these at the moment. I'm in the midst of a refactoring of the manipulation part of this library and would rather finish that first. In this scenario it's probably best to write it yourself for now: // untested, but should show the basic idea
sourceFile.addStatements(writer => {
writer.writeLine("export {");
filenames.forEach((filename, i) => {
writer.indent().write(filename).conditionalWrite(i !== filenames.length - 1, ",").newLine();
});
writer.writeLine("};");
}); |
Thank you. I've tried this code and it works! :) Though, I think that the support for different formatting options for all the different kinds of statements should be added someday. Some of the formatting options are already supported (the indentation text, the line endings etc.), and it would be great to have support for the different options the |
This will be a lot easier in the next post-16.0.x versions. You will be able to insert named exports and imports using a writer: // untested
exportsFile.addExportDeclaration({
namedExports: writer => {
writer.newLine();
filenames.forEach((filename, i) => {
writer.write(fileName).conditionalWrite(i !== filenames.length - 1, ",").newLine();
});
}
}); That's probably the best it's going to get. If you use that a lot, then I recommend extracting out the writing to a reusable function within your own code like so: // untested
exportsFile.addExportDeclaration({
namedExports: writeCommaSeparatedValuesOnNewLines(filenames)
});
// then in some file you can reuse
import { CodeBlockWriter } from "ts-simple-ast";
export function writeCommaSeparatedValuesOnNewLines(texts: string[]) {
return (writer: CodeBlockWriter) => {
writer.newLine();
texts.forEach((text, i) => {
writer.write(text).conditionalWrite(i !== texts.length - 1, ",").newLine();
});
};
} |
I'm trying to use
addExport()
to add a long list of exports to a file:This results in such an output (the whole statement is placed in one line):
However, I'd love to be able to format such a long statement so that each element is on its own line, to improve readability:
Is this possible?
The text was updated successfully, but these errors were encountered: