forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler): Support extracting deps functions for
defer
in …
…template pipeline Some `defer` blocks have external dependencies on other components or directives. These dependencies need to be extracted into deps functions, which either return local deps, or use a dynamic import for non-local deps. Template Pipeline can now generate these functions.
- Loading branch information
Showing
11 changed files
with
96 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/compiler/src/template/pipeline/src/phases/create_defer_deps_fns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import * as o from '../../../../output/output_ast'; | ||
import * as ir from '../../ir'; | ||
import {ComponentCompilationJob} from '../compilation'; | ||
|
||
/** | ||
* Create extracted deps functions for defer ops. | ||
*/ | ||
export function createDeferDepsFns(job: ComponentCompilationJob): void { | ||
for (const unit of job.units) { | ||
for (const op of unit.create) { | ||
if (op.kind === ir.OpKind.Defer) { | ||
if (op.metadata.deps.length === 0) { | ||
continue; | ||
} | ||
const dependencies: o.Expression[] = []; | ||
for (const dep of op.metadata.deps) { | ||
if (dep.isDeferrable) { | ||
// Callback function, e.g. `m () => m.MyCmp;`. | ||
const innerFn = o.arrowFn( | ||
[new o.FnParam('m', o.DYNAMIC_TYPE)], o.variable('m').prop(dep.symbolName)); | ||
|
||
// Dynamic import, e.g. `import('./a').then(...)`. | ||
const importExpr = | ||
(new o.DynamicImportExpr(dep.importPath!)).prop('then').callFn([innerFn]); | ||
dependencies.push(importExpr); | ||
} else { | ||
// Non-deferrable symbol, just use a reference to the type. | ||
dependencies.push(dep.type); | ||
} | ||
} | ||
const depsFnExpr = o.arrowFn([], o.literalArr(dependencies)); | ||
if (op.handle.slot === null) { | ||
throw new Error( | ||
'AssertionError: slot must be assigned bfore extracting defer deps functions'); | ||
} | ||
op.resolverFn = job.pool.getSharedFunctionReference( | ||
depsFnExpr, `${job.componentName}_Defer_${op.handle.slot}_DepsFn`); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters