Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(compiler): add ConstantPool to template pipeline compilations
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.
  • Loading branch information
alxhub committed May 9, 2023
commit 2f592b9106d09dceac7e81375bd485f982f102d2
2 changes: 1 addition & 1 deletion packages/compiler/src/render3/view/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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);
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler/src/template/pipeline/src/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
Expand Down