Skip to content

Commit

Permalink
refactor(ivy): minor refactoring / code clean-up (angular#27766)
Browse files Browse the repository at this point in the history
PR Close angular#27766
  • Loading branch information
gkalpak authored and kara committed Jan 4, 2019
1 parent 7eb2c41 commit d026b67
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/compiler/src/render3/view/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
const {name, value} = attr;
if (name === NON_BINDABLE_ATTR) {
isNonBindableMode = true;
} else if (name == 'style') {
} else if (name === 'style') {
stylingBuilder.registerStyleAttr(value);
} else if (name == 'class') {
} else if (name === 'class') {
stylingBuilder.registerClassAttr(value);
} else if (attr.i18n) {
i18nAttrs.push(attr);
Expand All @@ -516,7 +516,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver

element.inputs.forEach((input: t.BoundAttribute) => {
if (!stylingBuilder.registerBoundInput(input)) {
if (input.type == BindingType.Property) {
if (input.type === BindingType.Property) {
if (input.i18n) {
i18nAttrs.push(input);
} else {
Expand Down Expand Up @@ -733,7 +733,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
parameters.push(o.importExpr(R3.templateRefExtractor));
}

// handle property bindings e.g. p(1, 'forOf', ɵbind(ctx.items));
// handle property bindings e.g. p(1, 'ngForOf', ɵbind(ctx.items));
const context = o.variable(CONTEXT_NAME);
template.inputs.forEach(input => {
const value = input.value.visit(this._valueConverter);
Expand All @@ -756,7 +756,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
// Nested templates must not be visited until after their parent templates have completed
// processing, so they are queued here until after the initial pass. Otherwise, we wouldn't
// be able to support bindings in nested templates to local refs that occur after the
// template definition. e.g. <div *ngIf="showing"> {{ foo }} </div> <div #foo></div>
// template definition. e.g. <div *ngIf="showing">{{ foo }}</div> <div #foo></div>
this._nestedTemplateFns.push(() => {
const templateFunctionExpr = templateVisitor.buildTemplateFunction(
template.children, template.variables,
Expand Down Expand Up @@ -1453,7 +1453,7 @@ function createCssSelector(tag: string, attributes: {[name: string]: string}): C

cssSelector.addAttribute(name, value);
if (name.toLowerCase() === 'class') {
const classes = value.trim().split(/\s+/g);
const classes = value.trim().split(/\s+/);
classes.forEach(className => cssSelector.addClassName(className));
}
});
Expand Down Expand Up @@ -1570,8 +1570,10 @@ function isSingleElementTemplate(children: t.Node[]): children is[t.Element] {
return children.length === 1 && children[0] instanceof t.Element;
}

function isTextNode(node: t.Node): boolean {
return node instanceof t.Text || node instanceof t.BoundText || node instanceof t.Icu;
}

function hasTextChildrenOnly(children: t.Node[]): boolean {
return !children.find(
child =>
!(child instanceof t.Text || child instanceof t.BoundText || child instanceof t.Icu));
return children.every(isTextNode);
}

0 comments on commit d026b67

Please sign in to comment.