Skip to content

Commit 33b5037

Browse files
Bertrand Laportemhevery
authored andcommitted
fix rebase glitch in PR angular#570
Closes angular#787
1 parent 50a74b1 commit 33b5037

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

modules/angular2/src/core/compiler/pipeline/view_splitter.js

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {CompileElement} from './compile_element';
99
import {CompileControl} from './compile_control';
1010
import {StringWrapper} from 'angular2/src/facade/lang';
1111

12-
import {$BANG} from 'angular2/src/change_detection/parser/lexer';
13-
1412
/**
1513
* Splits views at `<template>` elements or elements with `template` attribute:
1614
* For `<template>` elements:
@@ -44,19 +42,16 @@ export class ViewSplitter extends CompileStep {
4442
var templateBindings = MapWrapper.get(attrs, 'template');
4543
var hasTemplateBinding = isPresent(templateBindings);
4644

47-
// look for template shortcuts such as !if="condition" and treat them as template="if condition"
45+
// look for template shortcuts such as *if="condition" and treat them as template="if condition"
4846
MapWrapper.forEach(attrs, (attrValue, attrName) => {
49-
if (StringWrapper.charCodeAt(attrName, 0) == $BANG) {
50-
var key = StringWrapper.substring(attrName, 1); // remove the bang
47+
if (StringWrapper.startsWith(attrName, '*')) {
48+
var key = StringWrapper.substring(attrName, 1); // remove the star
5149
if (hasTemplateBinding) {
5250
// 2nd template binding detected
5351
throw new BaseException(`Only one template directive per element is allowed: ` +
54-
`${templateBindings} and ${key} cannot be used simultaneously ` +
55-
`in ${current.elementDescription}`);
52+
`${templateBindings} and ${key} cannot be used simultaneously ` +
53+
`in ${current.elementDescription}`);
5654
} else {
57-
if (isBlank(parent)) {
58-
throw new BaseException(`Template directives cannot be used on root components in ${current.elementDescription}`);
59-
}
6055
templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
6156
hasTemplateBinding = true;
6257
}
@@ -72,37 +67,17 @@ export class ViewSplitter extends CompileStep {
7267
var currentElement:TemplateElement = current.element;
7368
var viewRootElement:TemplateElement = viewRoot.element;
7469
this._moveChildNodes(DOM.content(currentElement), DOM.content(viewRootElement));
75-
// viewRoot is a doesn't appear in the original template, so we associate
76-
// the current element description to get a more meaninful message in case of error
70+
// viewRoot doesn't appear in the original template, so we associate
71+
// the current element description to get a more meaningful message in case of error
7772
viewRoot.elementDescription = current.elementDescription;
7873
viewRoot.isViewRoot = true;
7974
control.addChild(viewRoot);
8075
}
8176
} else {
82-
var attrs = current.attrs();
83-
var templateBindings = MapWrapper.get(attrs, 'template');
84-
var hasTemplateBinding = isPresent(templateBindings);
85-
86-
// look for template shortcuts such as *if="condition" and treat them as template="if condition"
87-
MapWrapper.forEach(attrs, (attrValue, attrName) => {
88-
if (StringWrapper.startsWith(attrName, '*')) {
89-
var key = StringWrapper.substring(attrName, 1); // remove the bang
90-
if (hasTemplateBinding) {
91-
// 2nd template binding detected
92-
throw new BaseException(`Only one template directive per element is allowed: ` +
93-
`${templateBindings} and ${key} cannot be used simultaneously ` +
94-
`in ${current.elementDescription}`);
95-
} else {
96-
templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
97-
hasTemplateBinding = true;
98-
}
99-
}
100-
});
101-
10277
if (hasTemplateBinding) {
10378
var newParent = new CompileElement(DOM.createTemplate(''));
10479
// newParent doesn't appear in the original template, so we associate
105-
// the current element description to get a more meaninful message in case of error
80+
// the current element description to get a more meaningful message in case of error
10681
newParent.elementDescription = current.elementDescription;
10782
current.isViewRoot = true;
10883
this._parseTemplateBindings(templateBindings, newParent);

0 commit comments

Comments
 (0)