Skip to content

Commit 409b630

Browse files
committed
0f774df fix(compiler): project using the right directive as component.
1 parent 286e780 commit 409b630

18 files changed

+133
-75
lines changed

BUILD_INFO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Sat Apr 30 01:44:32 UTC 2016
2-
5ff31f0713554440ccc91a57d7b52d7209096a10
1+
Sat Apr 30 03:04:37 UTC 2016
2+
0f774df81150524c399161272a6cd51d0d54aa7e

lib/src/compiler/identifiers.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import "package:angular2/src/core/linker/view_utils.dart"
1212
interpolate,
1313
checkBinding,
1414
castByValue,
15+
EMPTY_ARRAY,
16+
EMPTY_MAP,
1517
pureProxy1,
1618
pureProxy2,
1719
pureProxy3,
@@ -84,6 +86,8 @@ var impDevModeEqual = devModeEqual;
8486
var impInterpolate = interpolate;
8587
var impCheckBinding = checkBinding;
8688
var impCastByValue = castByValue;
89+
var impEMPTY_ARRAY = EMPTY_ARRAY;
90+
var impEMPTY_MAP = EMPTY_MAP;
8791

8892
class Identifiers {
8993
static var ViewUtils = new CompileIdentifierMetadata(
@@ -199,6 +203,14 @@ class Identifiers {
199203
name: "castByValue",
200204
moduleUrl: VIEW_UTILS_MODULE_URL,
201205
runtime: impCastByValue);
206+
static var EMPTY_ARRAY = new CompileIdentifierMetadata(
207+
name: "EMPTY_ARRAY",
208+
moduleUrl: VIEW_UTILS_MODULE_URL,
209+
runtime: impEMPTY_ARRAY);
210+
static var EMPTY_MAP = new CompileIdentifierMetadata(
211+
name: "EMPTY_MAP",
212+
moduleUrl: VIEW_UTILS_MODULE_URL,
213+
runtime: impEMPTY_MAP);
202214
static var pureProxies = [
203215
null,
204216
new CompileIdentifierMetadata(

lib/src/compiler/template_ast.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,6 @@ class ElementAst implements TemplateAst {
158158
dynamic visit(TemplateAstVisitor visitor, dynamic context) {
159159
return visitor.visitElement(this, context);
160160
}
161-
162-
/**
163-
* Get the component associated with this element, if any.
164-
*/
165-
CompileDirectiveMetadata getComponent() {
166-
for (var i = 0; i < this.directives.length; i++) {
167-
var dirAst = this.directives[i];
168-
if (dirAst.directive.isComponent) {
169-
return dirAst.directive;
170-
}
171-
}
172-
return null;
173-
}
174161
}
175162

176163
/**

lib/src/compiler/template_parser.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,11 @@ class ElementContext {
10111011
List<DirectiveAst> directives, ProviderElementContext providerContext) {
10121012
var matcher = new SelectorMatcher();
10131013
var wildcardNgContentIndex = null;
1014-
if (directives.length > 0 && directives[0].directive.isComponent) {
1015-
var ngContentSelectors =
1016-
directives[0].directive.template.ngContentSelectors;
1014+
var component = directives.firstWhere(
1015+
(directive) => directive.directive.isComponent,
1016+
orElse: () => null);
1017+
if (isPresent(component)) {
1018+
var ngContentSelectors = component.directive.template.ngContentSelectors;
10171019
for (var i = 0; i < ngContentSelectors.length; i++) {
10181020
var selector = ngContentSelectors[i];
10191021
if (StringWrapper.equals(selector, "*")) {

lib/src/compiler/view_compiler/compile_element.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ class CompileElement extends CompileNode {
388388
if (identical(requestingProviderType, ProviderAstType.Component)) {
389389
return this._compViewExpr.prop("ref");
390390
} else {
391-
return o.THIS_EXPR.prop("ref");
391+
return getPropertyInView(
392+
o.THIS_EXPR.prop("ref"), this.view, this.view.componentView);
392393
}
393394
}
394395
}

lib/src/compiler/view_compiler/compile_pipe.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class CompilePipe {
3333
var deps = this.meta.type.diDeps.map((diDep) {
3434
if (diDep.token
3535
.equalsTo(identifierToken(Identifiers.ChangeDetectorRef))) {
36-
return o.THIS_EXPR.prop("ref");
36+
return getPropertyInView(
37+
o.THIS_EXPR.prop("ref"), this.view, this.view.componentView);
3738
}
3839
return injectFromViewParentInjector(diDep.token, false);
3940
}).toList();

lib/src/compiler/view_compiler/compile_view.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import "util.dart"
2727
createPureProxy;
2828
import "../config.dart" show CompilerConfig;
2929
import "compile_binding.dart" show CompileBinding;
30+
import "../identifiers.dart" show Identifiers;
3031

3132
class CompileView implements NameResolver {
3233
CompileDirectiveMetadata component;
@@ -159,6 +160,9 @@ class CompileView implements NameResolver {
159160
}
160161

161162
o.Expression createLiteralArray(List<o.Expression> values) {
163+
if (identical(values.length, 0)) {
164+
return o.importExpr(Identifiers.EMPTY_ARRAY);
165+
}
162166
var proxyExpr =
163167
o.THIS_EXPR.prop('''_arr_${ this . literalArrayCount ++}''');
164168
List<o.FnParam> proxyParams = [];
@@ -179,6 +183,9 @@ class CompileView implements NameResolver {
179183

180184
o.Expression createLiteralMap(
181185
List<List<dynamic /* String | o . Expression */ >> entries) {
186+
if (identical(entries.length, 0)) {
187+
return o.importExpr(Identifiers.EMPTY_MAP);
188+
}
182189
var proxyExpr = o.THIS_EXPR.prop('''_map_${ this . literalMapCount ++}''');
183190
List<o.FnParam> proxyParams = [];
184191
List<List<dynamic /* String | o . Expression */ >> proxyReturnEntries = [];

lib/src/compiler/view_compiler/event_binder.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,9 @@ class CompileEventListener {
103103
listenToRenderer() {
104104
var listenExpr;
105105
var eventListener = o.THIS_EXPR.callMethod("eventHandler", [
106-
o.fn([
107-
this._eventParam
108-
], [
109-
new o.ReturnStatement(
110-
o.THIS_EXPR.callMethod(this._methodName, [EventHandlerVars.event]))
111-
], o.BOOL_TYPE)
106+
o.THIS_EXPR
107+
.prop(this._methodName)
108+
.callMethod(o.BuiltinMethod.bind, [o.THIS_EXPR])
112109
]);
113110
if (isPresent(this.eventTarget)) {
114111
listenExpr = ViewProperties.renderer.callMethod("listenGlobal", [
@@ -136,12 +133,9 @@ class CompileEventListener {
136133
'''subscription_${ this . compileElement . view . subscriptions . length}''');
137134
this.compileElement.view.subscriptions.add(subscription);
138135
var eventListener = o.THIS_EXPR.callMethod("eventHandler", [
139-
o.fn([
140-
this._eventParam
141-
], [
142-
o.THIS_EXPR
143-
.callMethod(this._methodName, [EventHandlerVars.event]).toStmt()
144-
])
136+
o.THIS_EXPR
137+
.prop(this._methodName)
138+
.callMethod(o.BuiltinMethod.bind, [o.THIS_EXPR])
145139
]);
146140
this.compileElement.view.createMethod.addStmt(subscription
147141
.set(directiveInstance

lib/src/compiler/view_compiler/view_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
215215
this.view.createMethod.addStmt(
216216
o.THIS_EXPR.prop(fieldName).set(createRenderNodeExpr).toStmt());
217217
var renderNode = o.THIS_EXPR.prop(fieldName);
218-
var component = ast.getComponent();
219218
var directives =
220219
ast.directives.map((directiveAst) => directiveAst.directive).toList();
220+
var component = directives.firstWhere((directive) => directive.isComponent,
221+
orElse: () => null);
221222
var htmlAttrs = _readHtmlAttrs(ast.attrs);
222223
var attrNameAndValues = _mergeHtmlAndDirectiveAttrs(htmlAttrs, directives);
223224
for (var i = 0; i < attrNameAndValues.length; i++) {

lib/src/core/linker/component_factory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ComponentRef_ extends ComponentRef {
9292
}
9393

9494
ChangeDetectorRef get changeDetectorRef {
95-
return this.hostView;
95+
return this._hostElement.parentView.ref;
9696
}
9797

9898
Type get componentType {

0 commit comments

Comments
 (0)