| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 351f24e commit 0f774df
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,19 +116,6 @@ export class ElementAst implements TemplateAst { | |||
| 116 | 116 | visit(visitor: TemplateAstVisitor, context: any): any { | |
| 117 | 117 | return visitor.visitElement(this, context); | |
| 118 | 118 | } | |
| 119 | - | ||
| 120 | - /** | ||
| 121 | - * Get the component associated with this element, if any. | ||
| 122 | - */ | ||
| 123 | - getComponent(): CompileDirectiveMetadata { | ||
| 124 | - for (var i = 0; i < this.directives.length; i++) { | ||
| 125 | - var dirAst = this.directives[i]; | ||
| 126 | - if (dirAst.directive.isComponent) { | ||
| 127 | - return dirAst.directive; | ||
| 128 | - } | ||
| 129 | - } | ||
| 130 | - return null; | ||
| 131 | - } | ||
| 132 | 119 | } | |
| 133 | 120 | ||
| 134 | 121 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -847,8 +847,9 @@ class ElementContext { | |||
| 847 | 847 | providerContext: ProviderElementContext): ElementContext { | |
| 848 | 848 | var matcher = new SelectorMatcher(); | |
| 849 | 849 | var wildcardNgContentIndex = null; | |
| 850 | - if (directives.length > 0 && directives[0].directive.isComponent) { | ||
| 851 | - var ngContentSelectors = directives[0].directive.template.ngContentSelectors; | ||
| 850 | + var component = directives.find(directive => directive.directive.isComponent); | ||
| 851 | + if (isPresent(component)) { | ||
| 852 | + var ngContentSelectors = component.directive.template.ngContentSelectors; | ||
| 852 | 853 | for (var i = 0; i < ngContentSelectors.length; i++) { | |
| 853 | 854 | var selector = ngContentSelectors[i]; | |
| 854 | 855 | if (StringWrapper.equals(selector, '*')) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,8 +200,8 @@ class ViewBuilderVisitor implements TemplateAstVisitor { | |||
| 200 | 200 | ||
| 201 | 201 | var renderNode = o.THIS_EXPR.prop(fieldName); | |
| 202 | 202 | ||
| 203 | - var component = ast.getComponent(); | ||
| 204 | 203 | var directives = ast.directives.map(directiveAst => directiveAst.directive); | |
| 204 | + var component = directives.find(directive => directive.isComponent); | ||
| 205 | 205 | var htmlAttrs = _readHtmlAttrs(ast.attrs); | |
| 206 | 206 | var attrNameAndValues = _mergeHtmlAndDirectiveAttrs(htmlAttrs, directives); | |
| 207 | 207 | for (var i = 0; i < attrNameAndValues.length; i++) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,8 +156,8 @@ export function castByValue<T>(input: any, value: T): T { | |||
| 156 | 156 | return <T>input; | |
| 157 | 157 | } | |
| 158 | 158 | ||
| 159 | - export const EMPTY_ARRAY = CONST_EXPR([]); | ||
| 160 | - export const EMPTY_MAP = CONST_EXPR({}); | ||
| 159 | + export const EMPTY_ARRAY = /*@ts2dart_const*/[]; | ||
| 160 | + export const EMPTY_MAP = /*@ts2dart_const*/ {}; | ||
| 161 | 161 | ||
| 162 | 162 | export function pureProxy1<P0, R>(fn: (p0: P0) => R): (p0: P0) => R { | |
| 163 | 163 | var result: R; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1027,6 +1027,14 @@ There is no directive with "exportAs" set to "dirA" ("<div [ERROR ->]#a="dirA">< | |||
| 1027 | 1027 | }) | |
| 1028 | 1028 | } | |
| 1029 | 1029 | ||
| 1030 | + function createDir(selector: string): CompileDirectiveMetadata { | ||
| 1031 | + return CompileDirectiveMetadata.create({ | ||
| 1032 | + selector: selector, | ||
| 1033 | + type: | ||
| 1034 | + new CompileTypeMetadata({moduleUrl: someModuleUrl, name: `SomeDir${compCounter++}`}) | ||
| 1035 | + }) | ||
| 1036 | + } | ||
| 1037 | + | ||
| 1030 | 1038 | describe('project text nodes', () => { | |
| 1031 | 1039 | it('should project text nodes with wildcard selector', () => { | |
| 1032 | 1040 | expect(humanizeContentProjection(parse('<div>hello</div>', [createComp('div', ['*'])]))) | |
@@ -1140,6 +1148,12 @@ There is no directive with "exportAs" set to "dirA" ("<div [ERROR ->]#a="dirA">< | |||
| 1140 | 1148 | .toEqual([['div', null], ['template', 1], ['a', null]]); | |
| 1141 | 1149 | }); | |
| 1142 | 1150 | }); | |
| 1151 | + | ||
| 1152 | + it('should support other directives before the component', () => { | ||
| 1153 | + expect(humanizeContentProjection( | ||
| 1154 | + parse('<div>hello</div>', [createDir('div'), createComp('div', ['*'])]))) | ||
| 1155 | + .toEqual([['div', null], ['#text(hello)', 0]]); | ||
| 1156 | + }); | ||
| 1143 | 1157 | }); | |
| 1144 | 1158 | ||
| 1145 | 1159 | describe('splitClasses', () => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ import { | |||
| 33 | 33 | OpaqueToken, | |
| 34 | 34 | Injector | |
| 35 | 35 | } from 'angular2/core'; | |
| 36 | + import {NgIf, NgClass} from 'angular2/common'; | ||
| 36 | 37 | import {CompilerConfig} from 'angular2/compiler'; | |
| 37 | 38 | ||
| 38 | 39 | export function main() { | |
@@ -170,6 +171,22 @@ function declareTests(isJit: boolean) { | |||
| 170 | 171 | }); | |
| 171 | 172 | })); | |
| 172 | 173 | ||
| 174 | + it('should support ngClass before a component and content projection inside of an ngIf', | ||
| 175 | + inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | ||
| 176 | + tcb.overrideView( | ||
| 177 | + MyComp, new ViewMetadata({ | ||
| 178 | + template: `A<cmp-content *ngIf="true" [ngClass]="'red'">B</cmp-content>C`, | ||
| 179 | + directives: [NgClass, NgIf, CmpWithNgContent] | ||
| 180 | + })) | ||
| 181 | + .createAsync(MyComp) | ||
| 182 | + .then((fixture) => { | ||
| 183 | + fixture.detectChanges(); | ||
| 184 | + expect(fixture.nativeElement).toHaveText('ABC'); | ||
| 185 | + async.done(); | ||
| 186 | + }); | ||
| 187 | + })); | ||
| 188 | + | ||
| 189 | + | ||
| 173 | 190 | }); | |
| 174 | 191 | } | |
| 175 | 192 | ||
@@ -187,3 +204,7 @@ class PlatformPipe implements PipeTransform { | |||
| 187 | 204 | class CustomPipe implements PipeTransform { | |
| 188 | 205 | transform(value: any): any { return 'someCustomPipe'; } | |
| 189 | 206 | } | |
| 207 | + | ||
| 208 | + @Component({selector: 'cmp-content', template: `<ng-content></ng-content>`}) | ||
| 209 | + class CmpWithNgContent { | ||
| 210 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -850,7 +850,6 @@ const COMPILER = [ | |||
| 850 | 850 | 'DirectiveAst.visit(visitor:TemplateAstVisitor, context:any):any', | |
| 851 | 851 | 'ElementAst', | |
| 852 | 852 | 'ElementAst.constructor(name:string, attrs:AttrAst[], inputs:BoundElementPropertyAst[], outputs:BoundEventAst[], references:ReferenceAst[], directives:DirectiveAst[], providers:ProviderAst[], hasViewContainer:boolean, children:TemplateAst[], ngContentIndex:number, sourceSpan:ParseSourceSpan)', | |
| 853 | - 'ElementAst.getComponent():CompileDirectiveMetadata', | ||
| 854 | 853 | 'ElementAst.visit(visitor:TemplateAstVisitor, context:any):any', | |
| 855 | 854 | 'EmbeddedTemplateAst', | |
| 856 | 855 | 'EmbeddedTemplateAst.constructor(attrs:AttrAst[], outputs:BoundEventAst[], references:ReferenceAst[], variables:VariableAst[], directives:DirectiveAst[], providers:ProviderAst[], hasViewContainer:boolean, children:TemplateAst[], ngContentIndex:number, sourceSpan:ParseSourceSpan)', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments