feat(compiler): added the DynamicComponent annotation

This commit is contained in:
vsavkin
2015-03-13 11:33:57 -07:00
parent 1872b03fb8
commit b69f3043e0
8 changed files with 90 additions and 11 deletions
@@ -114,6 +114,7 @@ export function runCompilerCommonTests() {
var compiler = createCompiler( (parent, current, control) => {
if (DOM.hasClass(current.element, 'nested')) {
current.componentDirective = reader.read(NestedComponent);
current.hasNestedView = true;
current.inheritedProtoView = parent.inheritedProtoView;
current.inheritedElementBinder = current.inheritedProtoView.bindElement(null, 0, null);
} else {
@@ -163,6 +164,7 @@ export function runCompilerCommonTests() {
it('should allow recursive components', inject([AsyncTestCompleter], (async) => {
var compiler = createCompiler( (parent, current, control) => {
current.hasNestedView = true;
current.inheritedProtoView = new ProtoView(current.element, null, null);
current.inheritedElementBinder = current.inheritedProtoView.bindElement(null, 0, null);
current.componentDirective = reader.read(RecursiveComponent);
@@ -191,6 +193,7 @@ export function runCompilerCommonTests() {
var compiler = createCompiler((parent, current, control) => {
if (DOM.hasClass(current.element, 'parent')) {
current.hasNestedView = true;
current.componentDirective = reader.read(NestedComponent);
current.inheritedProtoView = parent.inheritedProtoView;
current.inheritedElementBinder = current.inheritedProtoView.bindElement(null, 0, null);
@@ -1,4 +1,4 @@
import {describe, beforeEach, it, expect, iit, ddescribe, el} from 'angular2/test_lib';
import {describe, beforeEach, it, xit, expect, iit, ddescribe, el} from 'angular2/test_lib';
import {isPresent, assertionsEnabled} from 'angular2/src/facade/lang';
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {DirectiveParser} from 'angular2/src/core/compiler/pipeline/directive_parser';
@@ -6,7 +6,7 @@ import {CompilePipeline} from 'angular2/src/core/compiler/pipeline/compile_pipel
import {CompileStep} from 'angular2/src/core/compiler/pipeline/compile_step';
import {CompileElement} from 'angular2/src/core/compiler/pipeline/compile_element';
import {CompileControl} from 'angular2/src/core/compiler/pipeline/compile_control';
import {Component, Decorator, Viewport} from 'angular2/src/core/annotations/annotations';
import {Component, DynamicComponent, Decorator, Viewport} from 'angular2/src/core/annotations/annotations';
import {Template} from 'angular2/src/core/annotations/template';
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
import {Lexer, Parser} from 'angular2/change_detection';
@@ -24,7 +24,9 @@ export function main() {
SomeViewport,
SomeViewport2,
SomeComponent,
SomeComponent2
SomeComponent2,
SomeDynamicComponent,
SomeDynamicComponent2
];
});
@@ -105,6 +107,29 @@ export function main() {
});
});
describe("dynamic component directives", () => {
it('should detect dynamic component', () => {
var results = createPipeline().process(el('<div some-dynamic-comp></div>'));
expect(results[0].componentDirective).toEqual(reader.read(SomeDynamicComponent));
});
it('should not allow multiple dynamic component directives on the same element', () => {
expect( () => {
createPipeline().process(
el('<div some-dynamic-comp some-dynamic-comp2></div>')
);
}).toThrowError(new RegExp('Multiple component directives not allowed on the same element'));
});
it('should not allow component and dynamic directives on the same element', () => {
expect( () => {
createPipeline().process(
el('<div some-dynamic-comp some-comp></div>')
);
}).toThrowError(new RegExp('Multiple component directives not allowed on the same element'));
});
});
describe('viewport directives', () => {
it('should detect them in attributes', () => {
var results = createPipeline().process(el('<template some-templ></template>'));
@@ -236,8 +261,17 @@ class SomeComponent {}
@Component({selector: '[some-comp2]'})
class SomeComponent2 {}
@DynamicComponent({selector: '[some-dynamic-comp]'})
class SomeDynamicComponent {}
@DynamicComponent({selector: '[some-dynamic-comp2]'})
class SomeDynamicComponent2 {}
@Component()
@Template({
directives: [SomeDecorator, SomeViewport, SomeViewport2, SomeComponent, SomeComponent2]
directives: [SomeDecorator, SomeViewport, SomeViewport2,
SomeComponent, SomeComponent2,
SomeDynamicComponent, SomeDynamicComponent2
]
})
class MyComp {}
@@ -101,7 +101,6 @@ export function main() {
}).process(el('<div></div>'));
assertBinding(results[0], true);
});
});
}