Skip to content

Commit

Permalink
refactor(ivy): remove the backpatch compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Apr 19, 2018
1 parent 22ec71f commit 0deb21e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 687 deletions.
8 changes: 3 additions & 5 deletions packages/compiler/src/aot/compiler.ts
Expand Up @@ -22,7 +22,6 @@ import * as o from '../output/output_ast';
import {ParseError} from '../parse_util';
import {compileNgModule as compileIvyModule} from '../render3/r3_module_compiler';
import {compilePipe as compileIvyPipe} from '../render3/r3_pipe_compiler';
import {OutputMode} from '../render3/r3_types';
import {compileComponent as compileIvyComponent, compileDirective as compileIvyDirective} from '../render3/r3_view_compiler';
import {CompiledStylesheet, StyleCompiler} from '../style_compiler';
import {SummaryResolver} from '../summary_resolver';
Expand Down Expand Up @@ -389,17 +388,16 @@ export class AotCompiler {
this._parseTemplate(directiveMetadata, module, module.transitiveModule.directives);
compileIvyComponent(
context, directiveMetadata, parsedPipes, parsedTemplate, this.reflector,
hostBindingParser, OutputMode.PartialClass);
hostBindingParser);
} else {
compileIvyDirective(
context, directiveMetadata, this.reflector, hostBindingParser, OutputMode.PartialClass);
compileIvyDirective(context, directiveMetadata, this.reflector, hostBindingParser);
}
});

pipes.forEach(pipeType => {
const pipeMetadata = this._metadataResolver.getPipeMetadata(pipeType);
if (pipeMetadata) {
compileIvyPipe(context, pipeMetadata, this.reflector, OutputMode.PartialClass);
compileIvyPipe(context, pipeMetadata, this.reflector);
}
});

Expand Down
106 changes: 0 additions & 106 deletions packages/compiler/src/render3/r3_back_patch_compiler.ts

This file was deleted.

37 changes: 13 additions & 24 deletions packages/compiler/src/render3/r3_pipe_compiler.ts
Expand Up @@ -13,15 +13,14 @@ import * as o from '../output/output_ast';
import {OutputContext, error} from '../util';

import {Identifiers as R3} from './r3_identifiers';
import {BUILD_OPTIMIZER_COLOCATE, OutputMode} from './r3_types';
import {BUILD_OPTIMIZER_COLOCATE} from './r3_types';
import {createFactory} from './r3_view_compiler';

/**
* Write a pipe definition to the output context.
*/
export function compilePipe(
outputCtx: OutputContext, pipe: CompilePipeMetadata, reflector: CompileReflector,
mode: OutputMode) {
outputCtx: OutputContext, pipe: CompilePipeMetadata, reflector: CompileReflector) {
const definitionMapValues: {key: string, quoted: boolean, value: o.Expression}[] = [];

// e.g. `name: 'myPipe'`
Expand All @@ -47,25 +46,15 @@ export function compilePipe(
const definitionFunction =
o.importExpr(R3.definePipe).callFn([o.literalMap(definitionMapValues)]);

if (mode === OutputMode.PartialClass) {
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */[new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */[o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */[],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */[]));
} else {
// Create back-patch definition.
const classReference = outputCtx.importExpr(pipe.type.reference);

// Create the back-patch statement
outputCtx.statements.push(
new o.CommentStmt(BUILD_OPTIMIZER_COLOCATE),
classReference.prop(definitionField).set(definitionFunction).toStmt());
}
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */[new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */[o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */[],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */[]));
}
8 changes: 0 additions & 8 deletions packages/compiler/src/render3/r3_types.ts
Expand Up @@ -6,14 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

/**
* The statement mode for the render, either as a class back-patch or as a partial class
*/
export const enum OutputMode {
PartialClass,
BackPatch,
}

/**
* Comment to insert above back-patch
*/
Expand Down
79 changes: 30 additions & 49 deletions packages/compiler/src/render3/r3_view_compiler.ts
Expand Up @@ -22,7 +22,7 @@ import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventA
import {OutputContext, error} from '../util';

import {Identifiers as R3} from './r3_identifiers';
import {BUILD_OPTIMIZER_COLOCATE, OutputMode} from './r3_types';
import {BUILD_OPTIMIZER_COLOCATE} from './r3_types';


/** Name of the context parameter passed into a template function */
Expand Down Expand Up @@ -50,7 +50,7 @@ const ID_SEPARATOR = '@@';

export function compileDirective(
outputCtx: OutputContext, directive: CompileDirectiveMetadata, reflector: CompileReflector,
bindingParser: BindingParser, mode: OutputMode) {
bindingParser: BindingParser) {
const definitionMapValues: {key: string, quoted: boolean, value: o.Expression}[] = [];

const field = (key: string, value: o.Expression | null) => {
Expand Down Expand Up @@ -87,34 +87,24 @@ export function compileDirective(
const definitionFunction =
o.importExpr(R3.defineDirective).callFn([o.literalMap(definitionMapValues)]);

if (mode === OutputMode.PartialClass) {
// Create the partial class to be merged with the actual class.
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */[new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */[o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */[],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */[]));
} else {
// Create back-patch definition.
const classReference = outputCtx.importExpr(directive.type.reference);

// Create the back-patch statement
outputCtx.statements.push(new o.CommentStmt(BUILD_OPTIMIZER_COLOCATE));
outputCtx.statements.push(
classReference.prop(definitionField).set(definitionFunction).toStmt());
}
// Create the partial class to be merged with the actual class.
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */[new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */[o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */[],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */[]));
}

export function compileComponent(
outputCtx: OutputContext, component: CompileDirectiveMetadata,
pipeSummaries: CompilePipeSummary[], template: TemplateAst[], reflector: CompileReflector,
bindingParser: BindingParser, mode: OutputMode) {
bindingParser: BindingParser) {
const definitionMapValues: {key: string, quoted: boolean, value: o.Expression}[] = [];

// Pipes and Directives found in the template
Expand Down Expand Up @@ -200,30 +190,21 @@ export function compileComponent(
const definitionField = outputCtx.constantPool.propertyNameOf(DefinitionKind.Component);
const definitionFunction =
o.importExpr(R3.defineComponent).callFn([o.literalMap(definitionMapValues)]);
if (mode === OutputMode.PartialClass) {
const className = identifierName(component.type) !;
className || error(`Cannot resolver the name of ${component.type}`);

// Create the partial class to be merged with the actual class.
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */[new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */[o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */[],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */[]));
} else {
const classReference = outputCtx.importExpr(component.type.reference);

// Create the back-patch statement
outputCtx.statements.push(
new o.CommentStmt(BUILD_OPTIMIZER_COLOCATE),
classReference.prop(definitionField).set(definitionFunction).toStmt());
}
const className = identifierName(component.type) !;
className || error(`Cannot resolver the name of ${component.type}`);

// Create the partial class to be merged with the actual class.
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */[new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */[o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */[],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */[]));
}

// TODO: Remove these when the things are fully supported
Expand Down

0 comments on commit 0deb21e

Please sign in to comment.