feat(core): speed up view creation via code gen for view factories.

BREAKING CHANGE:
- Platform pipes can only contain types and arrays of types,
  but no bindings any more.
- When using transformers, platform pipes need to be specified explicitly
  in the pubspec.yaml via the new config option
  `platform_pipes`.
- `Compiler.compileInHost` now returns a `HostViewFactoryRef`
- Component view is not yet created when component constructor is called.
  -> use `onInit` lifecycle callback to access the view of a component
- `ViewRef#setLocal` has been moved to new type `EmbeddedViewRef`
- `internalView` is gone, use `EmbeddedViewRef.rootNodes` to access
  the root nodes of an embedded view
- `renderer.setElementProperty`, `..setElementStyle`, `..setElementAttribute` now
  take a native element instead of an ElementRef
- `Renderer` interface now operates on plain native nodes,
  instead of `RenderElementRef`s or `RenderViewRef`s

Closes #5993
This commit is contained in:
Tobias Bosch
2015-12-02 10:35:51 -08:00
parent a08f50badd
commit 7ae23adaff
191 changed files with 6476 additions and 10232 deletions

View File

@ -21,6 +21,7 @@ import {
} from 'angular2/src/compiler/template_parser';
import {
CompileDirectiveMetadata,
CompilePipeMetadata,
CompileTypeMetadata,
CompileTemplateMetadata
} from 'angular2/src/compiler/directive_metadata';
@ -69,8 +70,12 @@ export function main() {
{selector: '[ngIf]', type: new CompileTypeMetadata({name: 'NgIf'}), inputs: ['ngIf']});
}));
function parse(template: string, directives: CompileDirectiveMetadata[]): TemplateAst[] {
return parser.parse(template, directives, 'TestComp');
function parse(template: string, directives: CompileDirectiveMetadata[],
pipes: CompilePipeMetadata[] = null): TemplateAst[] {
if (pipes === null) {
pipes = [];
}
return parser.parse(template, directives, pipes, 'TestComp');
}
describe('template transform', () => {
@ -938,15 +943,29 @@ Property binding a not used by any directive on an embedded template ("[ERROR ->
it('should support directive property', () => {
var dirA = CompileDirectiveMetadata.create(
{selector: 'div', type: new CompileTypeMetadata({name: 'DirA'}), inputs: ['aProp']});
expect(humanizeTplAstSourceSpans(parse('<div [aProp]="foo | bar"></div>', [dirA])))
expect(humanizeTplAstSourceSpans(parse('<div [aProp]="foo"></div>', [dirA])))
.toEqual([
[ElementAst, 'div', '<div [aProp]="foo | bar">'],
[DirectiveAst, dirA, '<div [aProp]="foo | bar">'],
[BoundDirectivePropertyAst, 'aProp', '(foo | bar)', '[aProp]="foo | bar"']
[ElementAst, 'div', '<div [aProp]="foo">'],
[DirectiveAst, dirA, '<div [aProp]="foo">'],
[BoundDirectivePropertyAst, 'aProp', 'foo', '[aProp]="foo"']
]);
});
});
describe('pipes', () => {
it('should allow pipes that have been defined as dependencies', () => {
var testPipe =
new CompilePipeMetadata({name: 'test', type: new CompileTypeMetadata({name: 'DirA'})});
expect(() => parse('{{a | test}}', [], [testPipe])).not.toThrow();
});
it('should report pipes as error that have not been defined as dependencies', () => {
expect(() => parse('{{a | test}}', [])).toThrowError(`Template parse errors:
The pipe 'test' could not be found ("[ERROR ->]{{a | test}}"): TestComp@0:0`);
});
});
});
}