refactor(compiler): add ConstantPool to template pipeline compilations (#50118)

This commit adds the `ConstantPool` to `ComponentCompilation`, making it
available to all phases of the template pipeline. Constant extraction is a
common operation in pipeline phases.

PR Close #50118
This commit is contained in:
Alex Rickabaugh 2023-05-01 16:58:04 -07:00 committed by Dylan Hunn
parent 11469b58c3
commit 1928cd82d9
3 changed files with 7 additions and 4 deletions

View file

@ -234,7 +234,7 @@ export function compileComponentFromMetadata(
} else {
// This path compiles the template using the prototype template pipeline. First the template is
// ingested into IR:
const tpl = ingest(meta.name, meta.template.nodes);
const tpl = ingest(meta.name, meta.template.nodes, constantPool);
// Then the IR is transformed to prepare it for cod egeneration.
transformTemplate(tpl);

View file

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ConstantPool} from '../../../constant_pool';
import * as o from '../../../output/output_ast';
import * as ir from '../ir';
@ -36,7 +37,7 @@ export class ComponentCompilation {
*/
readonly root: ViewCompilation;
constructor(readonly componentName: string) {
constructor(readonly componentName: string, readonly pool: ConstantPool) {
// Allocate the root view.
const root = new ViewCompilation(this, this.allocateXrefId(), null);
this.views.set(root.xref, root);

View file

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ConstantPool} from '../../../constant_pool';
import * as e from '../../../expression_parser/ast';
import * as o from '../../../output/output_ast';
import * as t from '../../../render3/r3_ast';
@ -18,8 +19,9 @@ import {BINARY_OPERATORS} from './conversion';
* Process a template AST and convert it into a `ComponentCompilation` in the intermediate
* representation.
*/
export function ingest(componentName: string, template: t.Node[]): ComponentCompilation {
const cpl = new ComponentCompilation(componentName);
export function ingest(
componentName: string, template: t.Node[], constantPool: ConstantPool): ComponentCompilation {
const cpl = new ComponentCompilation(componentName, constantPool);
ingestNodes(cpl.root, template);
return cpl;
}