diff --git a/modules/benchmarks/src/compiler/compiler_benchmark.js b/modules/benchmarks/src/compiler/compiler_benchmark.js index 6eca478c1e..3b207c9012 100644 --- a/modules/benchmarks/src/compiler/compiler_benchmark.js +++ b/modules/benchmarks/src/compiler/compiler_benchmark.js @@ -1,7 +1,7 @@ import {DOM, document} from 'facade/dom'; import {isBlank, Type} from 'facade/lang'; import {MapWrapper} from 'facade/collection'; -import {AnnotatedType} from 'core/compiler/annotated_type'; +import {DirectiveMetadata} from 'core/compiler/directive_metadata'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; @@ -81,7 +81,7 @@ export function main() { var reader = new DirectiveMetadataReader(); var cache = new CompilerCache(); var compiler = new Compiler(null, reader, new Parser(new Lexer()), cache); - var annotatedComponent = reader.annotatedType(BenchmarkComponent); + var annotatedComponent = reader.read(BenchmarkComponent); var templateNoBindings = loadTemplate('templateNoBindings', COUNT); var templateWithBindings = loadTemplate('templateWithBindings', COUNT); diff --git a/modules/core/src/annotations/annotations.js b/modules/core/src/annotations/annotations.js index f6333023df..40f292329e 100644 --- a/modules/core/src/annotations/annotations.js +++ b/modules/core/src/annotations/annotations.js @@ -1,6 +1,7 @@ import {ABSTRACT, CONST, normalizeBlank} from 'facade/lang'; import {List} from 'facade/collection'; import {TemplateConfig} from './template_config'; +import {ShadowDomStrategy} from '../compiler/shadow_dom'; @ABSTRACT() @@ -35,6 +36,7 @@ export class Component extends Directive { lightDomServices:any; //List; shadowDomServices:any; //List; componentServices:any; //List; + shadowDom:any; //ShadowDomStrategy; @CONST() constructor({ @@ -44,7 +46,8 @@ export class Component extends Directive { lightDomServices, shadowDomServices, componentServices, - implementsTypes + implementsTypes, + shadowDom }:{ selector:String, bind:Object, @@ -52,7 +55,8 @@ export class Component extends Directive { lightDomServices:List, shadowDomServices:List, componentServices:List, - implementsTypes:List + implementsTypes:List, + shadowDom:ShadowDomStrategy }={}) { super({ @@ -65,6 +69,7 @@ export class Component extends Directive { this.lightDomServices = lightDomServices; this.shadowDomServices = shadowDomServices; this.componentServices = componentServices; + this.shadowDom = shadowDom; } } diff --git a/modules/core/src/application.js b/modules/core/src/application.js index fd6edabb6e..b7b29a132c 100644 --- a/modules/core/src/application.js +++ b/modules/core/src/application.js @@ -10,7 +10,7 @@ import {ChangeDetector} from 'change_detection/change_detector'; import {RecordRange} from 'change_detection/record_range'; import {TemplateLoader} from './compiler/template_loader'; import {DirectiveMetadataReader} from './compiler/directive_metadata_reader'; -import {AnnotatedType} from './compiler/annotated_type'; +import {DirectiveMetadata} from './compiler/directive_metadata'; import {List, ListWrapper} from 'facade/collection'; import {PromiseWrapper} from 'facade/async'; import {VmTurnZone} from 'core/zone/vm_turn_zone'; @@ -36,7 +36,7 @@ export function documentDependentBindings(appComponentType) { // TODO(rado): inspect annotation here and warn if there are bindings, // lightDomServices, and other component annotations that are skipped // for bootstrapping components. - return reader.annotatedType(appComponentType); + return reader.read(appComponentType); }, [DirectiveMetadataReader]), bind(appElementToken).toFactory((appComponentAnnotatedType, appDocument) => { diff --git a/modules/core/src/compiler/compiler.js b/modules/core/src/compiler/compiler.js index 50e82378fa..efadcdb305 100644 --- a/modules/core/src/compiler/compiler.js +++ b/modules/core/src/compiler/compiler.js @@ -11,7 +11,7 @@ import {CompilePipeline} from './pipeline/compile_pipeline'; import {CompileElement} from './pipeline/compile_element'; import {createDefaultSteps} from './pipeline/default_steps'; import {TemplateLoader} from './template_loader'; -import {AnnotatedType} from './annotated_type'; +import {DirectiveMetadata} from './directive_metadata'; import {Component} from '../annotations/annotations'; /** @@ -59,12 +59,12 @@ export class Compiler { this._compilerCache = cache; } - createSteps(component:AnnotatedType):List { + createSteps(component:DirectiveMetadata):List { var annotation: Component = component.annotation; var directives = annotation.template.directives; var annotatedDirectives = ListWrapper.create(); for (var i=0; i; hasElementPropertyBindings:boolean; nestedProtoView: ProtoView; events:Map; constructor( - protoElementInjector: ProtoElementInjector, componentDirective:AnnotatedType, templateDirective:AnnotatedType) { + protoElementInjector: ProtoElementInjector, componentDirective:DirectiveMetadata, templateDirective:DirectiveMetadata) { this.protoElementInjector = protoElementInjector; this.componentDirective = componentDirective; this.templateDirective = templateDirective; diff --git a/modules/core/src/compiler/pipeline/compile_element.js b/modules/core/src/compiler/pipeline/compile_element.js index a2bffb8102..cf4461b129 100644 --- a/modules/core/src/compiler/pipeline/compile_element.js +++ b/modules/core/src/compiler/pipeline/compile_element.js @@ -1,7 +1,7 @@ import {List, Map, ListWrapper, MapWrapper} from 'facade/collection'; import {Element, DOM} from 'facade/dom'; import {int, isBlank, isPresent} from 'facade/lang'; -import {AnnotatedType} from '../annotated_type'; +import {DirectiveMetadata} from '../directive_metadata'; import {Decorator} from '../../annotations/annotations'; import {Component} from '../../annotations/annotations'; import {Template} from '../../annotations/annotations'; @@ -24,9 +24,9 @@ export class CompileElement { propertyBindings:Map; eventBindings:Map; variableBindings:Map; - decoratorDirectives:List; - templateDirective:AnnotatedType; - componentDirective:AnnotatedType; + decoratorDirectives:List; + templateDirective:DirectiveMetadata; + componentDirective:DirectiveMetadata; isViewRoot:boolean; hasBindings:boolean; inheritedProtoView:ProtoView; @@ -110,7 +110,7 @@ export class CompileElement { MapWrapper.set(this.eventBindings, eventName, expression); } - addDirective(directive:AnnotatedType) { + addDirective(directive:DirectiveMetadata) { var annotation = directive.annotation; if (annotation instanceof Decorator) { if (isBlank(this.decoratorDirectives)) { diff --git a/modules/core/src/compiler/pipeline/compile_pipeline.js b/modules/core/src/compiler/pipeline/compile_pipeline.js index 087e0dd3f0..2ca7604152 100644 --- a/modules/core/src/compiler/pipeline/compile_pipeline.js +++ b/modules/core/src/compiler/pipeline/compile_pipeline.js @@ -4,7 +4,7 @@ import {Element, Node, DOM} from 'facade/dom'; import {CompileElement} from './compile_element'; import {CompileControl} from './compile_control'; import {CompileStep} from './compile_step'; -import {AnnotatedType} from '../annotated_type'; +import {DirectiveMetadata} from '../directive_metadata'; /** * CompilePipeline for executing CompileSteps recursively for diff --git a/modules/core/src/compiler/pipeline/compile_step.js b/modules/core/src/compiler/pipeline/compile_step.js index 6d3f81c8ea..98d99abe72 100644 --- a/modules/core/src/compiler/pipeline/compile_step.js +++ b/modules/core/src/compiler/pipeline/compile_step.js @@ -1,6 +1,6 @@ import {CompileElement} from './compile_element'; import {CompileControl} from './compile_control'; -import {AnnotatedType} from '../annotated_type'; +import {DirectiveMetadata} from '../directive_metadata'; /** * One part of the compile process. diff --git a/modules/core/src/compiler/pipeline/default_steps.js b/modules/core/src/compiler/pipeline/default_steps.js index 51952be99f..5537c8e46b 100644 --- a/modules/core/src/compiler/pipeline/default_steps.js +++ b/modules/core/src/compiler/pipeline/default_steps.js @@ -9,7 +9,7 @@ import {ElementBindingMarker} from './element_binding_marker'; import {ProtoViewBuilder} from './proto_view_builder'; import {ProtoElementInjectorBuilder} from './proto_element_injector_builder'; import {ElementBinderBuilder} from './element_binder_builder'; -import {AnnotatedType} from 'core/compiler/annotated_type'; +import {DirectiveMetadata} from 'core/compiler/directive_metadata'; import {stringify} from 'facade/lang'; /** @@ -17,8 +17,8 @@ import {stringify} from 'facade/lang'; * Takes in an HTMLElement and produces the ProtoViews, * ProtoElementInjectors and ElementBinders in the end. */ -export function createDefaultSteps(parser:Parser, compiledComponent: AnnotatedType, - directives: List) { +export function createDefaultSteps(parser:Parser, compiledComponent: DirectiveMetadata, + directives: List) { var compilationUnit = stringify(compiledComponent.type); return [ diff --git a/modules/core/src/compiler/pipeline/directive_parser.js b/modules/core/src/compiler/pipeline/directive_parser.js index c51a6b3e75..8c59feeed1 100644 --- a/modules/core/src/compiler/pipeline/directive_parser.js +++ b/modules/core/src/compiler/pipeline/directive_parser.js @@ -4,7 +4,7 @@ import {TemplateElement} from 'facade/dom'; import {SelectorMatcher} from '../selector'; import {CssSelector} from '../selector'; -import {AnnotatedType} from '../annotated_type'; +import {DirectiveMetadata} from '../directive_metadata'; import {Template} from '../../annotations/annotations'; import {Component} from '../../annotations/annotations'; import {CompileStep} from './compile_step'; @@ -28,13 +28,13 @@ import {CompileControl} from './compile_control'; */ export class DirectiveParser extends CompileStep { _selectorMatcher:SelectorMatcher; - constructor(directives:List) { + constructor(directives:List) { this._selectorMatcher = new SelectorMatcher(); for (var i=0; i= 0; --i) { DOM.insertAfter(sibling, view.nodes[i]); diff --git a/modules/core/test/compiler/compiler_spec.js b/modules/core/test/compiler/compiler_spec.js index 06f6b0464a..0839cbc911 100644 --- a/modules/core/test/compiler/compiler_spec.js +++ b/modules/core/test/compiler/compiler_spec.js @@ -66,7 +66,7 @@ export function main() { current.inheritedProtoView = new ProtoView(current.element, null); current.inheritedElementBinder = current.inheritedProtoView.bindElement(null); if (current.element === mainEl) { - current.componentDirective = reader.annotatedType(NestedComponent); + current.componentDirective = reader.read(NestedComponent); } }); compiler.compile(MainComponent, mainEl).then( (protoView) => { @@ -97,7 +97,7 @@ export function main() { var compiler = createCompiler( (parent, current, control) => { current.inheritedProtoView = new ProtoView(current.element, null); current.inheritedElementBinder = current.inheritedProtoView.bindElement(null); - current.componentDirective = reader.annotatedType(RecursiveComponent); + current.componentDirective = reader.read(RecursiveComponent); }); compiler.compile(RecursiveComponent, null).then( (protoView) => { expect(protoView.elementBinders[0].nestedProtoView).toBe(protoView); diff --git a/modules/core/test/compiler/directive_metadata_reader_spec.js b/modules/core/test/compiler/directive_metadata_reader_spec.js index 1adc2f16a0..45011f9383 100644 --- a/modules/core/test/compiler/directive_metadata_reader_spec.js +++ b/modules/core/test/compiler/directive_metadata_reader_spec.js @@ -1,7 +1,8 @@ import {ddescribe, describe, it, iit, expect, beforeEach} from 'test_lib/test_lib'; import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; -import {Decorator} from 'core/annotations/annotations'; -import {AnnotatedType} from 'core/compiler/annotated_type'; +import {Decorator, Component} from 'core/annotations/annotations'; +import {DirectiveMetadata} from 'core/compiler/directive_metadata'; +import {ShadowDomEmulated, ShadowDomNative} from 'core/compiler/shadow_dom'; @Decorator({ selector: 'someSelector' @@ -9,28 +10,50 @@ import {AnnotatedType} from 'core/compiler/annotated_type'; class SomeDirective { } +@Component({ + selector: 'someSelector' +}) +class ComponentWithoutExplicitShadowDomStrategy {} + +@Component({ + selector: 'someSelector', + shadowDom: ShadowDomEmulated +}) +class ComponentWithExplicitShadowDomStrategy {} + class SomeDirectiveWithoutAnnotation { } export function main() { describe("DirectiveMetadataReader", () => { - var rader; + var reader; beforeEach( () => { - rader = new DirectiveMetadataReader(); + reader = new DirectiveMetadataReader(); }); it('should read out the annotation', () => { - var annoatedDirective = rader.annotatedType(SomeDirective); - expect(annoatedDirective).toEqual( - new AnnotatedType(SomeDirective, new Decorator({selector: 'someSelector'}))); + var directiveMetadata = reader.read(SomeDirective); + expect(directiveMetadata).toEqual( + new DirectiveMetadata(SomeDirective, new Decorator({selector: 'someSelector'}), null)); }); it('should throw if not matching annotation is found', () => { expect(() => { - rader.annotatedType(SomeDirectiveWithoutAnnotation); + reader.read(SomeDirectiveWithoutAnnotation); }).toThrowError('No Directive annotation found on SomeDirectiveWithoutAnnotation'); }); + describe("shadow dom strategy", () => { + it('should return the provided shadow dom strategy when it is present', () => { + var directiveMetadata = reader.read(ComponentWithExplicitShadowDomStrategy); + expect(directiveMetadata.shadowDomStrategy).toEqual(ShadowDomEmulated); + }); + + it('should return Native otherwise', () => { + var directiveMetadata = reader.read(ComponentWithoutExplicitShadowDomStrategy); + expect(directiveMetadata.shadowDomStrategy).toEqual(ShadowDomNative); + }); + }); }); } \ No newline at end of file diff --git a/modules/core/test/compiler/pipeline/directive_parser_spec.js b/modules/core/test/compiler/pipeline/directive_parser_spec.js index 43a5bd7bf3..aa171ce03e 100644 --- a/modules/core/test/compiler/pipeline/directive_parser_spec.js +++ b/modules/core/test/compiler/pipeline/directive_parser_spec.js @@ -28,7 +28,7 @@ export function main() { var parser = new Parser(new Lexer()); var annotatedDirectives = ListWrapper.create(); for (var i=0; i { @@ -53,7 +53,7 @@ export function main() { describe('component directives', () => { it('should detect them in attributes', () => { var results = createPipeline().process(createElement('
')); - expect(results[0].componentDirective).toEqual(reader.annotatedType(SomeComponent)); + expect(results[0].componentDirective).toEqual(reader.read(SomeComponent)); }); it('should detect them in property bindings', () => { @@ -61,7 +61,7 @@ export function main() { 'some-comp': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].componentDirective).toEqual(reader.annotatedType(SomeComponent)); + expect(results[0].componentDirective).toEqual(reader.read(SomeComponent)); }); it('should detect them in variable bindings', () => { @@ -69,7 +69,7 @@ export function main() { 'some-comp': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].componentDirective).toEqual(reader.annotatedType(SomeComponent)); + expect(results[0].componentDirective).toEqual(reader.read(SomeComponent)); }); it('should not allow multiple component directives on the same element', () => { @@ -92,7 +92,7 @@ export function main() { describe('template directives', () => { it('should detect them in attributes', () => { var results = createPipeline().process(createElement('')); - expect(results[0].templateDirective).toEqual(reader.annotatedType(SomeTemplate)); + expect(results[0].templateDirective).toEqual(reader.read(SomeTemplate)); }); it('should detect them in property bindings', () => { @@ -100,7 +100,7 @@ export function main() { 'some-templ': 'someExpr' }}); var results = pipeline.process(createElement('')); - expect(results[0].templateDirective).toEqual(reader.annotatedType(SomeTemplate)); + expect(results[0].templateDirective).toEqual(reader.read(SomeTemplate)); }); it('should detect them in variable bindings', () => { @@ -108,7 +108,7 @@ export function main() { 'some-templ': 'someExpr' }}); var results = pipeline.process(createElement('')); - expect(results[0].templateDirective).toEqual(reader.annotatedType(SomeTemplate)); + expect(results[0].templateDirective).toEqual(reader.read(SomeTemplate)); }); it('should not allow multiple template directives on the same element', () => { @@ -131,7 +131,7 @@ export function main() { describe('decorator directives', () => { it('should detect them in attributes', () => { var results = createPipeline().process(createElement('
')); - expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]); + expect(results[0].decoratorDirectives).toEqual([reader.read(SomeDecorator)]); }); it('should detect them in property bindings', () => { @@ -139,7 +139,7 @@ export function main() { 'some-decor': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]); + expect(results[0].decoratorDirectives).toEqual([reader.read(SomeDecorator)]); }); it('should detect them in variable bindings', () => { @@ -147,7 +147,7 @@ export function main() { 'some-decor': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]); + expect(results[0].decoratorDirectives).toEqual([reader.read(SomeDecorator)]); }); it('should not allow decorator directives on