From 1d4d18d9db5a9266c9c1cb57ff1f79358f5b34fb Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 2 Apr 2015 14:40:49 -0700 Subject: [PATCH] refactor(render): user render compiler --- modules/angular2/core.js | 4 +- modules/angular2/src/core/application.js | 8 +- .../angular2/src/core/compiler/compiler.js | 275 ++++--- .../src/core/compiler/css_processor.js | 71 -- .../src/core/compiler/element_binder.js | 12 +- .../src/core/compiler/element_injector.js | 4 +- .../core/compiler/pipeline/compile_control.js | 58 -- .../core/compiler/pipeline/compile_element.js | 227 ------ .../compiler/pipeline/compile_pipeline.js | 46 -- .../core/compiler/pipeline/compile_step.js | 10 - .../core/compiler/pipeline/default_steps.js | 45 -- .../compiler/pipeline/directive_parser.js | 88 --- .../pipeline/element_binder_builder.js | 164 ----- .../pipeline/element_binding_marker.js | 49 -- .../pipeline/property_binding_parser.js | 97 --- .../proto_element_injector_builder.js | 84 --- .../compiler/pipeline/proto_view_builder.js | 84 --- .../pipeline/text_interpolation_parser.js | 44 -- .../core/compiler/pipeline/view_splitter.js | 121 --- .../src/core/compiler/proto_view_factory.js | 200 +++++ .../src/core/compiler/shadow_dom_strategy.js | 315 +------- .../src/core/compiler/string_utils.js | 16 - .../src/core/compiler/template_loader.js | 78 -- modules/angular2/src/core/compiler/view.js | 13 +- modules/angular2/src/dom/html_adapter.dart | 2 +- modules/angular2/src/facade/collection.dart | 2 +- modules/angular2/src/render/api.js | 19 +- .../src/render/dom/compiler/compiler.js | 7 +- .../render/dom/compiler/directive_parser.js | 9 +- .../dom/compiler/property_binding_parser.js | 2 - .../render/dom/compiler/template_loader.js | 2 + .../src/render/dom/compiler/view_splitter.js | 10 +- .../dom/shadow_dom/shadow_dom_compile_step.js | 2 +- .../src/render/dom/view/element_binder.js | 11 +- .../property_setter_factory.js | 0 .../src/render/dom/view/proto_view.js | 10 +- .../src/render/dom/view/proto_view_builder.js | 79 +- modules/angular2/src/render/dom/view/view.js | 2 +- .../angular2/src/test_lib/test_injector.js | 6 +- .../template_compiler/generator.dart | 10 +- .../core/compiler/compiler_browser_spec.js | 9 - .../core/compiler/compiler_common_tests.js | 444 ----------- .../compiler_html5lib.server.spec.dart | 11 - .../test/core/compiler/compiler_spec.js | 488 ++++++++++++ .../test/core/compiler/css_processor_spec.js | 112 --- .../test/core/compiler/integration_spec.js | 6 +- .../pipeline/directive_parser_spec.js | 288 -------- .../pipeline/element_binder_builder_spec.js | 694 ------------------ .../pipeline/element_binding_marker_spec.js | 130 ---- .../core/compiler/pipeline/pipeline_spec.js | 179 ----- .../pipeline/property_binding_parser_spec.js | 124 ---- .../proto_element_injector_builder_spec.js | 217 ------ .../pipeline/proto_view_builder_spec.js | 116 --- .../text_interpolation_parser_spec.js | 75 -- .../compiler/pipeline/view_splitter_spec.js | 177 ----- .../shadow_dom_emulation_integration_spec.js | 25 +- .../core/compiler/shadow_dom_strategy_spec.js | 176 +---- .../core/compiler/template_loader_spec.js | 98 --- .../angular2/test/core/compiler/view_spec.js | 11 +- modules/angular2/test/directives/if_spec.js | 6 +- .../test/directives/non_bindable_spec.js | 6 +- .../angular2/test/directives/switch_spec.js | 12 +- .../angular2/test/forms/integration_spec.js | 9 +- .../dom/compiler/directive_parser_spec.js | 12 +- .../render/dom/compiler/view_splitter_spec.js | 8 +- .../direct_dom_renderer_integration_spec.js | 4 +- .../property_setter_factory_spec.js | 2 +- .../src/compiler/compiler_benchmark.js | 6 +- .../src/largetable/largetable_benchmark.js | 15 +- .../src/naive_infinite_scroll/index.js | 15 +- modules/benchmarks/src/tree/tree_benchmark.js | 15 +- .../examples/src/hello_world/index_static.js | 15 +- 72 files changed, 1052 insertions(+), 4739 deletions(-) delete mode 100644 modules/angular2/src/core/compiler/css_processor.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/compile_control.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/compile_element.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/compile_pipeline.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/compile_step.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/default_steps.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/directive_parser.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/element_binder_builder.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/element_binding_marker.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/property_binding_parser.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/proto_element_injector_builder.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/proto_view_builder.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/text_interpolation_parser.js delete mode 100644 modules/angular2/src/core/compiler/pipeline/view_splitter.js create mode 100644 modules/angular2/src/core/compiler/proto_view_factory.js delete mode 100644 modules/angular2/src/core/compiler/string_utils.js delete mode 100644 modules/angular2/src/core/compiler/template_loader.js rename modules/angular2/src/render/dom/{compiler => view}/property_setter_factory.js (100%) delete mode 100644 modules/angular2/test/core/compiler/compiler_browser_spec.js delete mode 100644 modules/angular2/test/core/compiler/compiler_common_tests.js delete mode 100644 modules/angular2/test/core/compiler/compiler_html5lib.server.spec.dart create mode 100644 modules/angular2/test/core/compiler/compiler_spec.js delete mode 100644 modules/angular2/test/core/compiler/css_processor_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/directive_parser_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/element_binding_marker_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/pipeline_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/property_binding_parser_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/proto_element_injector_builder_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/proto_view_builder_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/text_interpolation_parser_spec.js delete mode 100644 modules/angular2/test/core/compiler/pipeline/view_splitter_spec.js delete mode 100644 modules/angular2/test/core/compiler/template_loader_spec.js rename modules/angular2/test/render/dom/{compiler => view}/property_setter_factory_spec.js (96%) diff --git a/modules/angular2/core.js b/modules/angular2/core.js index e3c0820fe9..87419c5b70 100644 --- a/modules/angular2/core.js +++ b/modules/angular2/core.js @@ -6,10 +6,12 @@ export * from './src/core/annotations/di'; export * from './src/core/compiler/compiler'; -export * from './src/core/compiler/template_loader'; +// TODO(tbosch): remove this once render migration is complete +export * from 'angular2/src/render/dom/compiler/template_loader'; export * from './src/core/compiler/private_component_loader'; export * from './src/core/compiler/private_component_location'; export * from './src/core/compiler/view'; export * from './src/core/compiler/view_container'; export * from './src/core/dom/element'; + diff --git a/modules/angular2/src/core/application.js b/modules/angular2/src/core/application.js index 55f6f11b5e..fac037c01a 100644 --- a/modules/angular2/src/core/application.js +++ b/modules/angular2/src/core/application.js @@ -7,9 +7,10 @@ import {ProtoView} from './compiler/view'; import {Reflector, reflector} from 'angular2/src/reflection/reflection'; import {Parser, Lexer, ChangeDetection, dynamicChangeDetection, jitChangeDetection} from 'angular2/change_detection'; import {ExceptionHandler} from './exception_handler'; -import {TemplateLoader} from './compiler/template_loader'; +import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; import {TemplateResolver} from './compiler/template_resolver'; import {DirectiveMetadataReader} from './compiler/directive_metadata_reader'; +import {DirectiveBinding} from './compiler/element_injector'; import {List, ListWrapper} from 'angular2/src/facade/collection'; import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone'; @@ -24,7 +25,6 @@ import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mappe import {UrlResolver} from 'angular2/src/services/url_resolver'; import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver'; import {StyleInliner} from 'angular2/src/render/dom/shadow_dom/style_inliner'; -import {CssProcessor} from 'angular2/src/core/compiler/css_processor'; import {Component} from 'angular2/src/core/annotations/annotations'; import {PrivateComponentLoader} from 'angular2/src/core/compiler/private_component_loader'; import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability'; @@ -74,7 +74,8 @@ function _injectorBindings(appComponentType): List { return compiler.compile(appComponentAnnotatedType.type).then( (protoView) => { var appProtoView = ProtoView.createRootProtoView(protoView, appElement, - appComponentAnnotatedType, changeDetection.createProtoChangeDetector('root'), + DirectiveBinding.createFromType(appComponentAnnotatedType.type, appComponentAnnotatedType.annotation), + changeDetection.createProtoChangeDetector('root'), strategy); // The light Dom of the app element is not considered part of // the angular application. Thus the context and lightDomInjector are @@ -112,7 +113,6 @@ function _injectorBindings(appComponentType): List { UrlResolver, StyleUrlResolver, StyleInliner, - bind(CssProcessor).toFactory(() => new CssProcessor(null), []), PrivateComponentLoader, Testability, ]; diff --git a/modules/angular2/src/core/compiler/compiler.js b/modules/angular2/src/core/compiler/compiler.js index 0423e11303..19661492dd 100644 --- a/modules/angular2/src/core/compiler/compiler.js +++ b/modules/angular2/src/core/compiler/compiler.js @@ -6,18 +6,22 @@ import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection import {ChangeDetection, Parser} from 'angular2/change_detection'; import {DirectiveMetadataReader} from './directive_metadata_reader'; +import {Component, Viewport, DynamicComponent, Decorator} from '../annotations/annotations'; import {ProtoView} from './view'; -import {CompilePipeline} from './pipeline/compile_pipeline'; -import {CompileElement} from './pipeline/compile_element'; -import {createDefaultSteps} from './pipeline/default_steps'; -import {TemplateLoader} from './template_loader'; +import {DirectiveBinding} from './element_injector'; import {TemplateResolver} from './template_resolver'; import {Template} from '../annotations/template'; import {ShadowDomStrategy} from './shadow_dom_strategy'; -import {CompileStep} from './pipeline/compile_step'; import {ComponentUrlMapper} from './component_url_mapper'; +import {ProtoViewFactory} from './proto_view_factory'; import {UrlResolver} from 'angular2/src/services/url_resolver'; -import {CssProcessor} from './css_processor'; + +import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; +import {DefaultStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory'; +import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; + +import * as rc from 'angular2/src/render/dom/compiler/compiler'; +import * as renderApi from 'angular2/src/render/api'; /** * Cache that stores the ProtoView of the template of a component. @@ -44,72 +48,51 @@ export class CompilerCache { } } -/** - * The compiler loads and translates the html templates of components into - * nested ProtoViews. To decompose its functionality it uses - * the CompilePipeline and the CompileSteps. - * - * @publicModule angular2/template - */ -@Injectable() -export class Compiler { + +// TODO(tbosch): rename this class to Compiler +// and remove the current Compiler when core uses the render views. +export class NewCompiler { _reader: DirectiveMetadataReader; - _parser:Parser; _compilerCache:CompilerCache; - _changeDetection:ChangeDetection; - _templateLoader:TemplateLoader; _compiling:Map; - _shadowDomStrategy: ShadowDomStrategy; _templateResolver: TemplateResolver; _componentUrlMapper: ComponentUrlMapper; _urlResolver: UrlResolver; _appUrl: string; - _cssProcessor: CssProcessor; + _renderer: renderApi.Renderer; + _protoViewFactory:ProtoViewFactory; - constructor(changeDetection:ChangeDetection, - templateLoader:TemplateLoader, - reader: DirectiveMetadataReader, - parser:Parser, + constructor(reader: DirectiveMetadataReader, cache:CompilerCache, - shadowDomStrategy: ShadowDomStrategy, templateResolver: TemplateResolver, componentUrlMapper: ComponentUrlMapper, urlResolver: UrlResolver, - cssProcessor: CssProcessor) { - this._changeDetection = changeDetection; + renderer: renderApi.Renderer, + protoViewFactory: ProtoViewFactory) { this._reader = reader; - this._parser = parser; this._compilerCache = cache; - this._templateLoader = templateLoader; this._compiling = MapWrapper.create(); - this._shadowDomStrategy = shadowDomStrategy; this._templateResolver = templateResolver; this._componentUrlMapper = componentUrlMapper; this._urlResolver = urlResolver; this._appUrl = urlResolver.resolve(null, './'); - this._cssProcessor = cssProcessor; + this._renderer = renderer; + this._protoViewFactory = protoViewFactory; } - // todo(misko): should be private method - createSteps(component:Type, template: Template):List { - var dirMetadata = ListWrapper.map(this._flattenDirectives(template), - (d) => this._reader.read(d)); - - var cmpMetadata = this._reader.read(component); - - var templateUrl = this._templateLoader.getTemplateUrl(template); - - return createDefaultSteps(this._changeDetection, this._parser, cmpMetadata, dirMetadata, - this._shadowDomStrategy, templateUrl, this._cssProcessor); + _bindDirective(directive) { + var meta = this._reader.read(directive); + return DirectiveBinding.createFromType(meta.type, meta.annotation); } compile(component: Type):Promise { - var protoView = this._compile(component); + var protoView = this._compile(this._bindDirective(component)); return PromiseWrapper.isPromise(protoView) ? protoView : PromiseWrapper.resolve(protoView); } // TODO(vicb): union type return ProtoView or Promise - _compile(component: Type) { + _compile(componentBinding: DirectiveBinding) { + var component = componentBinding.key.token; var protoView = this._compilerCache.get(component); if (isPresent(protoView)) { // The component has already been compiled into a ProtoView, @@ -126,81 +109,112 @@ export class Compiler { } var template = this._templateResolver.resolve(component); + var directives = ListWrapper.map( + this._flattenDirectives(template), + (directive) => this._bindDirective(directive) + ); - var componentUrl = this._componentUrlMapper.getUrl(component); - var baseUrl = this._urlResolver.resolve(this._appUrl, componentUrl); - this._templateLoader.setBaseUrl(template, baseUrl); + pvPromise = this._compileNoRecurse(componentBinding, template, directives).then( (protoView) => { + // Populate the cache before compiling the nested components, + // so that components can reference themselves in their template. + this._compilerCache.set(component, protoView); + MapWrapper.delete(this._compiling, component); - var tplElement = this._templateLoader.load(template); - - if (PromiseWrapper.isPromise(tplElement)) { - pvPromise = PromiseWrapper.then(tplElement, - (el) => this._compileTemplate(template, el, component), - (_) => { throw new BaseException(`Failed to load the template for ${stringify(component)}`); } - ); - MapWrapper.set(this._compiling, component, pvPromise); - return pvPromise; - } - - return this._compileTemplate(template, tplElement, component); - } - - // TODO(vicb): union type return ProtoView or Promise - _compileTemplate(template: Template, tplElement, component: Type) { - var pipeline = new CompilePipeline(this.createSteps(component, template)); - var compileElements; - - try { - compileElements = pipeline.process(tplElement, stringify(component)); - } catch(ex) { - return PromiseWrapper.reject(ex); - } - - var protoView = compileElements[0].inheritedProtoView; - - // Populate the cache before compiling the nested components, - // so that components can reference themselves in their template. - this._compilerCache.set(component, protoView); - MapWrapper.delete(this._compiling, component); - - // Compile all the components from the template - var nestedPVPromises = []; - for (var i = 0; i < compileElements.length; i++) { - var ce = compileElements[i]; - if (ce.hasNestedView) { - this._compileNestedProtoView(ce, nestedPVPromises); + // Compile all the components from the template + var nestedPVPromises = this._compileNestedComponents(protoView); + if (nestedPVPromises.length > 0) { + // Returns ProtoView Promise when there are any asynchronous nested ProtoViews. + // The promise will resolved after nested ProtoViews are compiled. + return PromiseWrapper.then(PromiseWrapper.all(nestedPVPromises), + (_) => protoView, + (e) => { throw new BaseException(`${e} -> Failed to compile ${stringify(component)}`); } + ); } - } - - if (protoView.stylePromises.length > 0) { - // The protoView is ready after all asynchronous styles are ready - var syncProtoView = protoView; - protoView = PromiseWrapper.all(syncProtoView.stylePromises).then((_) => syncProtoView); - } - - if (nestedPVPromises.length > 0) { - // Returns ProtoView Promise when there are any asynchronous nested ProtoViews. - // The promise will resolved after nested ProtoViews are compiled. - return PromiseWrapper.then(PromiseWrapper.all(nestedPVPromises), - (_) => protoView, - (e) => { throw new BaseException(`${e.message} -> Failed to compile ${stringify(component)}`); } - ); - } - - return protoView; + return protoView; + }); + MapWrapper.set(this._compiling, component, pvPromise); + return pvPromise; } - _compileNestedProtoView(ce: CompileElement, promises: List) { - var protoView = this._compile(ce.componentDirective.type); - - if (PromiseWrapper.isPromise(protoView)) { - ListWrapper.push( - promises, - protoView.then(function(pv) { ce.inheritedElementBinder.nestedProtoView = pv;}) - ); + _compileNoRecurse(componentBinding, template, directives):Promise { + var component = componentBinding.key.token; + var componentUrl = this._urlResolver.resolve( + this._appUrl, this._componentUrlMapper.getUrl(component) + ); + var templateAbsUrl = null; + if (isPresent(template.url)) { + templateAbsUrl = this._urlResolver.resolve(componentUrl, template.url); } else { - ce.inheritedElementBinder.nestedProtoView = protoView; + // Note: If we have an inline template, we also need to send + // the url for the component to the renderer so that it + // is able to resolve urls in stylesheets. + templateAbsUrl = componentUrl; } + var renderTemplate = new renderApi.Template({ + componentId: stringify(component), + absUrl: templateAbsUrl, + inline: template.inline, + directives: ListWrapper.map(directives, this._buildRenderDirective) + }); + return this._renderer.compile(renderTemplate).then( (renderPv) => { + return this._protoViewFactory.createProtoView(componentBinding.annotation, renderPv, directives); + }); + } + + _compileNestedComponents(protoView, nestedPVPromises = null):List { + if (isBlank(nestedPVPromises)) { + nestedPVPromises = []; + } + ListWrapper.map(protoView.elementBinders, (elementBinder) => { + var nestedComponent = elementBinder.componentDirective; + if (isPresent(nestedComponent) && !(nestedComponent.annotation instanceof DynamicComponent)) { + var nestedCall = this._compile(nestedComponent); + if (PromiseWrapper.isPromise(nestedCall)) { + ListWrapper.push(nestedPVPromises, nestedCall.then( (nestedPv) => { + elementBinder.nestedProtoView = nestedPv; + })); + } else { + elementBinder.nestedProtoView = nestedCall; + } + } else if (isPresent(elementBinder.nestedProtoView)) { + this._compileNestedComponents(elementBinder.nestedProtoView, nestedPVPromises); + } + }); + return nestedPVPromises; + } + + _buildRenderDirective(directiveBinding) { + var ann = directiveBinding.annotation; + var renderType; + var compileChildren = true; + if ((ann instanceof Component) || (ann instanceof DynamicComponent)) { + renderType = renderApi.DirectiveMetadata.COMPONENT_TYPE; + } else if (ann instanceof Viewport) { + renderType = renderApi.DirectiveMetadata.VIEWPORT_TYPE; + } else if (ann instanceof Decorator) { + renderType = renderApi.DirectiveMetadata.DECORATOR_TYPE; + compileChildren = ann.compileChildren; + } + var setters = []; + var readAttributes = []; + ListWrapper.forEach(directiveBinding.dependencies, (dep) => { + if (isPresent(dep.propSetterName)) { + ListWrapper.push(setters, dep.propSetterName); + } + if (isPresent(dep.attributeName)) { + ListWrapper.push(readAttributes, dep.attributeName); + } + }); + return new renderApi.DirectiveMetadata({ + id: stringify(directiveBinding.key.token), + type: renderType, + selector: ann.selector, + compileChildren: compileChildren, + events: isPresent(ann.events) ? MapWrapper.createFromStringMap(ann.events) : null, + bind: isPresent(ann.bind) ? MapWrapper.createFromStringMap(ann.bind) : null, + setters: setters, + readAttributes: readAttributes + }); } _flattenDirectives(template: Template):List { @@ -225,4 +239,39 @@ export class Compiler { } - +// TODO(tbosch): delete this class once we use the render views +/** + * The compiler loads and translates the html templates of components into + * nested ProtoViews. To decompose its functionality it uses + * the render compiler. + * + * @publicModule angular2/template + */ +@Injectable() +export class Compiler extends NewCompiler { + constructor(changeDetection:ChangeDetection, + templateLoader:TemplateLoader, + reader: DirectiveMetadataReader, + parser:Parser, + cache:CompilerCache, + shadowDomStrategy: ShadowDomStrategy, + templateResolver: TemplateResolver, + componentUrlMapper: ComponentUrlMapper, + urlResolver: UrlResolver) { + super( + reader, + cache, + templateResolver, + componentUrlMapper, + urlResolver, + new DirectDomRenderer( + new rc.Compiler( + new DefaultStepFactory(parser, shadowDomStrategy.render), + templateLoader + ), + null, null + ), + new ProtoViewFactory(changeDetection, shadowDomStrategy) + ); + } +} diff --git a/modules/angular2/src/core/compiler/css_processor.js b/modules/angular2/src/core/compiler/css_processor.js deleted file mode 100644 index 81850e798f..0000000000 --- a/modules/angular2/src/core/compiler/css_processor.js +++ /dev/null @@ -1,71 +0,0 @@ -import {Injectable} from 'angular2/di'; -import {DOM} from 'angular2/src/dom/dom_adapter'; - -import {isPresent} from 'angular2/src/facade/lang'; -import {List} from 'angular2/src/facade/collection'; - -import {CompileStep} from './pipeline/compile_step'; -import {CompileElement} from './pipeline/compile_element'; -import {CompileControl} from './pipeline/compile_control'; - -import {ShadowDomStrategy} from './shadow_dom_strategy'; -import {DirectiveMetadata} from './directive_metadata'; - -/** - * Processes the ')); - - expect(results[0].ignoreBindings).toBe(false); - expect(results[1].ignoreBindings).toBe(true); - }); - - it('should execute the strategy step for style elements', () => { - var processedEls = []; - var compileStep = new MockStep((parent, current, control) => { - ListWrapper.push(processedEls, current.element); - }); - var strategy = new FakeShadowDomStrategy(compileStep); - - var cssProcessor = new CssProcessor(null); - var pipeline = createPipeline(cssProcessor, strategy, 'http://base'); - var results = pipeline.process(el('
')); - - expect(processedEls.length).toEqual(1); - expect(processedEls[0]).toBe(results[1].element); - }); - - it('should apply the given transformers', () => { - var strategy = new FakeShadowDomStrategy(null); - var cssProcessor = new CssProcessor([ - new FakeCssTransformer('/*transformer1 */'), - new FakeCssTransformer('/*transformer2 */'), - ]); - - var pipeline = createPipeline(cssProcessor, strategy, 'http://base'); - var results = pipeline.process(el('
')); - - expect(results[1].element).toHaveText('/*transformer1 *//*transformer2 */'); - }); - }); - }); -} - -class FakeShadowDomStrategy extends ShadowDomStrategy { - _compileStep: CompileStep; - - constructor(compileStep: CompileStep) { - super(); - this._compileStep = compileStep; - } - - getStyleCompileStep(cmpMetadata: DirectiveMetadata, templateUrl: string): CompileStep { - return this._compileStep; - } -} - -class MockStep extends CompileStep { - processClosure:Function; - constructor(process) { - super(); - this.processClosure = process; - } - process(parent:CompileElement, current:CompileElement, control:CompileControl) { - this.processClosure(parent, current, control); - } -} - -class FakeCssTransformer extends CssTransformer { - _css: string; - - constructor(css: string) { - super(); - this._css = css; - } - - transform(styleEl) { - var cssText = DOM.getText(styleEl); - cssText += this._css; - DOM.setText(styleEl, cssText); - } -} - -class SomeComponent {} diff --git a/modules/angular2/test/core/compiler/integration_spec.js b/modules/angular2/test/core/compiler/integration_spec.js index 5ca1ae083f..2d8a265369 100644 --- a/modules/angular2/test/core/compiler/integration_spec.js +++ b/modules/angular2/test/core/compiler/integration_spec.js @@ -25,12 +25,11 @@ import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_meta import {ShadowDomStrategy, EmulatedUnscopedShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy'; import {PrivateComponentLocation} from 'angular2/src/core/compiler/private_component_location'; import {PrivateComponentLoader} from 'angular2/src/core/compiler/private_component_loader'; -import {TemplateLoader} from 'angular2/src/core/compiler/template_loader'; +import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock'; import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; import {UrlResolver} from 'angular2/src/services/url_resolver'; import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver'; -import {CssProcessor} from 'angular2/src/core/compiler/css_processor'; import {EventManager} from 'angular2/src/render/dom/events/event_manager'; import {Decorator, Component, Viewport, DynamicComponent} from 'angular2/src/core/annotations/annotations'; @@ -56,8 +55,7 @@ export function main() { shadowDomStrategy, tplResolver, new ComponentUrlMapper(), - urlResolver, - new CssProcessor(null) + urlResolver ); } diff --git a/modules/angular2/test/core/compiler/pipeline/directive_parser_spec.js b/modules/angular2/test/core/compiler/pipeline/directive_parser_spec.js deleted file mode 100644 index 4ff6343c48..0000000000 --- a/modules/angular2/test/core/compiler/pipeline/directive_parser_spec.js +++ /dev/null @@ -1,288 +0,0 @@ -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'; -import {CompilePipeline} from 'angular2/src/core/compiler/pipeline/compile_pipeline'; -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, 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'; - -export function main() { - describe('DirectiveParser', () => { - var reader, directives; - - beforeEach( () => { - reader = new DirectiveMetadataReader(); - directives = [ - SomeDecorator, - SomeDecoratorIgnoringChildren, - SomeDecoratorWithBinding, - SomeViewport, - SomeViewport2, - SomeComponent, - SomeComponent2, - SomeComponent3, - SomeDynamicComponent, - SomeDynamicComponent2 - ]; - }); - - function createPipeline({propertyBindings, variableBindings}={}) { - var parser = new Parser(new Lexer()); - var annotatedDirectives = ListWrapper.create(); - for (var i=0; i { - if (isPresent(propertyBindings)) { - StringMapWrapper.forEach(propertyBindings, (v, k) => { - current.addPropertyBinding(k, parser.parseBinding(v, null)); - MapWrapper.set(current.attrs(), k, v); - }); - } - if (isPresent(variableBindings)) { - StringMapWrapper.forEach(variableBindings, (v, k) => { - current.addVariableBinding(k, v); - MapWrapper.set(current.attrs(), k, v); - }); - } - }), new DirectiveParser(annotatedDirectives)]); - } - - it('should not add directives if they are not used', () => { - var results = createPipeline().process(el('
')); - expect(results[0].decoratorDirectives).toBe(null); - expect(results[0].componentDirective).toBe(null); - expect(results[0].viewportDirective).toBe(null); - }); - - describe('component directives', () => { - it('should detect them in attributes', () => { - var results = createPipeline().process(el('
')); - expect(results[0].componentDirective).toEqual(reader.read(SomeComponent)); - }); - - it('component directives must be first in collected directives', () => { - var results = createPipeline().process(el('
')); - var dirs = results[0].getAllDirectives(); - expect(dirs.length).toEqual(2); - expect(dirs[0]).toEqual(reader.read(SomeComponent)); - expect(dirs[1]).toEqual(reader.read(SomeDecorator)); - }); - - it('should detect them in property bindings', () => { - var pipeline = createPipeline({propertyBindings: { - 'some-comp': 'someExpr' - }}); - var results = pipeline.process(el('
')); - expect(results[0].componentDirective).toEqual(reader.read(SomeComponent)); - }); - - it('should detect them in variable bindings', () => { - var pipeline = createPipeline({variableBindings: { - 'some-comp': 'someExpr' - }}); - var results = pipeline.process(el('
')); - expect(results[0].componentDirective).toEqual(reader.read(SomeComponent)); - }); - - it('should not allow multiple component directives on the same element', () => { - expect( () => { - createPipeline().process( - el('
') - ); - }).toThrowError('Multiple component directives not allowed on the same element - check
'); - }); - - it('should not allow component directives on