Skip to content

Commit 1e3ecbd

Browse files
clydinalan-agius4
authored andcommitted
perf(@ngtools/webpack): avoid bootstrap conversion AST traversal where possible
To support AOT compilation the Angular bootstrap call needs to be converted from using `platform-browser-dynamic` to `platform-browser`. This transform was previously being executed against every source file within the program regardless of the presence of `platformBrowserDynamic`. An initial check is now performed that can avoid AST traversal when the bootstrapping call is not present in a file. (cherry picked from commit 4fa8392)
1 parent 3184eb0 commit 1e3ecbd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/ngtools/webpack/src/ivy/transformation.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export function mergeTransformers(
7474
return result;
7575
}
7676

77+
/**
78+
* The name of the Angular platform that should be replaced within
79+
* bootstrap call expressions to support AOT.
80+
*/
81+
const PLATFORM_BROWSER_DYNAMIC_NAME = 'platformBrowserDynamic';
82+
7783
export function replaceBootstrap(
7884
getTypeChecker: () => ts.TypeChecker,
7985
): ts.TransformerFactory<ts.SourceFile> {
@@ -86,7 +92,7 @@ export function replaceBootstrap(
8692
const visitNode: ts.Visitor = (node: ts.Node) => {
8793
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
8894
const target = node.expression;
89-
if (target.text === 'platformBrowserDynamic') {
95+
if (target.text === PLATFORM_BROWSER_DYNAMIC_NAME) {
9096
if (!bootstrapNamespace) {
9197
bootstrapNamespace = nodeFactory.createUniqueName('__NgCli_bootstrap_');
9298
bootstrapImport = nodeFactory.createImportDeclaration(
@@ -115,6 +121,10 @@ export function replaceBootstrap(
115121
};
116122

117123
return (sourceFile: ts.SourceFile) => {
124+
if (!sourceFile.text.includes(PLATFORM_BROWSER_DYNAMIC_NAME)) {
125+
return sourceFile;
126+
}
127+
118128
let updatedSourceFile = ts.visitEachChild(sourceFile, visitNode, context);
119129

120130
if (bootstrapImport) {

0 commit comments

Comments
 (0)