Description
When running an app in AOT mode, formatting (mostly whitespace in form of newlines) is not preserved. That's because AST transformations alone are not enough and the AOT compiler runs a type check that will error due to missing properties, even though the properties were created on the AST. We are talking about properties that a decorator (ObservableEvent
) will create at runtime. It's important to keep in mind that source files are immutable, this means any transformations are not reflected back to the actual text (sourceFile.getText()
) of the source file. However, this is important and therefore the current solution uses a printer to get an updated text version of the transformed AST which we then store back into the internal source file cache.
Here's an excerpt from the code (can be found in webpack-compiler-host.ts
) that uses the printer:
if (isAOT && isComponentFile(sf)) {
const aotTransformers = [inlineTemplateTransformer, addSourcePropertiesTransformer];
const sfTransformed = ts.transform(sf, aotTransformers).transformed[0];
const newFileContent = printFileContent(sfTransformed);
sf = ts.createSourceFile(fileName, newFileContent, languageVersion);
}
It would be great if we found a solution that preserves whitespace.
Remarks
Even though the formatting is not preserved, we believe it's not a deal breaker and shouldn't stop you from using this library. Serving your app with AOT enabled shouldn't be the default development environment and it should only be used to test your app. You can still look at the source maps, add breakpoints and debug your application. So no real downsides other than missing new lines.