Skip to content

Commit

Permalink
refactor(compiler): Reorder binding kinds and flags code
Browse files Browse the repository at this point in the history
Reorder this bit of helper code above `ingestBindings`, so that `ingestBindings` and `ingestBinding` can be viewed together.
  • Loading branch information
dylhunn committed Dec 9, 2023
1 parent ae08500 commit 604b22d
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,39 @@ function convertAstWithInterpolation(
return expression;
}

// TODO: Can we populate Template binding kinds in ingest?
const BINDING_KINDS = new Map<e.BindingType, ir.BindingKind>([
[e.BindingType.Property, ir.BindingKind.Property],
[e.BindingType.Attribute, ir.BindingKind.Attribute],
[e.BindingType.Class, ir.BindingKind.ClassName],
[e.BindingType.Style, ir.BindingKind.StyleProperty],
[e.BindingType.Animation, ir.BindingKind.Animation],
]);

enum BindingFlags {
None = 0b000,

/**
* The binding is to a static text literal and not to an expression.
*/
TextValue = 0b0001,

/**
* The binding belongs to the `<ng-template>` side of a `t.Template`.
*/
BindingTargetsTemplate = 0b0010,

/**
* The binding is on a structural directive.
*/
IsStructuralTemplateAttribute = 0b0100,

/**
* The binding is on a `t.Template`.
*/
OnNgTemplateElement = 0b1000,
}

/**
* Checks whether the given template is a plain ng-template (as opposed to another kind of template
* such as a structural directive template or control flow template). This is checked based on the
Expand Down Expand Up @@ -880,41 +913,6 @@ function ingestBindings(
}
}

// TODO: Can we populate Template binding kinds in ingest?
const BINDING_KINDS = new Map<e.BindingType, ir.BindingKind>([
[e.BindingType.Property, ir.BindingKind.Property],
[e.BindingType.Attribute, ir.BindingKind.Attribute],
[e.BindingType.Class, ir.BindingKind.ClassName],
[e.BindingType.Style, ir.BindingKind.StyleProperty],
[e.BindingType.Animation, ir.BindingKind.Animation],
]);

enum BindingFlags {
None = 0b000,

/**
* The binding is to a static text literal and not to an expression.
*/
TextValue = 0b0001,

/**
* The binding belongs to the `<ng-template>` side of a `t.Template`.
*/
BindingTargetsTemplate = 0b0010,

/**
* The binding is on a structural directive.
*/
IsStructuralTemplateAttribute = 0b0100,

/**
* The binding is on a `t.Template`.
*/
OnNgTemplateElement = 0b1000,
}



function createBinding(
view: ViewCompilationUnit, xref: ir.XrefId, name: string, value: e.AST|o.Expression,
type: e.BindingType, unit: string|null, securityContext: SecurityContext,
Expand Down

0 comments on commit 604b22d

Please sign in to comment.