parent
50a74b1d91
commit
33b503720a
@ -9,8 +9,6 @@ import {CompileElement} from './compile_element';
|
|||||||
import {CompileControl} from './compile_control';
|
import {CompileControl} from './compile_control';
|
||||||
import {StringWrapper} from 'angular2/src/facade/lang';
|
import {StringWrapper} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
import {$BANG} from 'angular2/src/change_detection/parser/lexer';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits views at `<template>` elements or elements with `template` attribute:
|
* Splits views at `<template>` elements or elements with `template` attribute:
|
||||||
* For `<template>` elements:
|
* For `<template>` elements:
|
||||||
@ -44,19 +42,16 @@ export class ViewSplitter extends CompileStep {
|
|||||||
var templateBindings = MapWrapper.get(attrs, 'template');
|
var templateBindings = MapWrapper.get(attrs, 'template');
|
||||||
var hasTemplateBinding = isPresent(templateBindings);
|
var hasTemplateBinding = isPresent(templateBindings);
|
||||||
|
|
||||||
// look for template shortcuts such as !if="condition" and treat them as template="if condition"
|
// look for template shortcuts such as *if="condition" and treat them as template="if condition"
|
||||||
MapWrapper.forEach(attrs, (attrValue, attrName) => {
|
MapWrapper.forEach(attrs, (attrValue, attrName) => {
|
||||||
if (StringWrapper.charCodeAt(attrName, 0) == $BANG) {
|
if (StringWrapper.startsWith(attrName, '*')) {
|
||||||
var key = StringWrapper.substring(attrName, 1); // remove the bang
|
var key = StringWrapper.substring(attrName, 1); // remove the star
|
||||||
if (hasTemplateBinding) {
|
if (hasTemplateBinding) {
|
||||||
// 2nd template binding detected
|
// 2nd template binding detected
|
||||||
throw new BaseException(`Only one template directive per element is allowed: ` +
|
throw new BaseException(`Only one template directive per element is allowed: ` +
|
||||||
`${templateBindings} and ${key} cannot be used simultaneously ` +
|
`${templateBindings} and ${key} cannot be used simultaneously ` +
|
||||||
`in ${current.elementDescription}`);
|
`in ${current.elementDescription}`);
|
||||||
} else {
|
} else {
|
||||||
if (isBlank(parent)) {
|
|
||||||
throw new BaseException(`Template directives cannot be used on root components in ${current.elementDescription}`);
|
|
||||||
}
|
|
||||||
templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
|
templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
|
||||||
hasTemplateBinding = true;
|
hasTemplateBinding = true;
|
||||||
}
|
}
|
||||||
@ -72,37 +67,17 @@ export class ViewSplitter extends CompileStep {
|
|||||||
var currentElement:TemplateElement = current.element;
|
var currentElement:TemplateElement = current.element;
|
||||||
var viewRootElement:TemplateElement = viewRoot.element;
|
var viewRootElement:TemplateElement = viewRoot.element;
|
||||||
this._moveChildNodes(DOM.content(currentElement), DOM.content(viewRootElement));
|
this._moveChildNodes(DOM.content(currentElement), DOM.content(viewRootElement));
|
||||||
// viewRoot is a doesn't appear in the original template, so we associate
|
// viewRoot doesn't appear in the original template, so we associate
|
||||||
// the current element description to get a more meaninful message in case of error
|
// the current element description to get a more meaningful message in case of error
|
||||||
viewRoot.elementDescription = current.elementDescription;
|
viewRoot.elementDescription = current.elementDescription;
|
||||||
viewRoot.isViewRoot = true;
|
viewRoot.isViewRoot = true;
|
||||||
control.addChild(viewRoot);
|
control.addChild(viewRoot);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var attrs = current.attrs();
|
|
||||||
var templateBindings = MapWrapper.get(attrs, 'template');
|
|
||||||
var hasTemplateBinding = isPresent(templateBindings);
|
|
||||||
|
|
||||||
// look for template shortcuts such as *if="condition" and treat them as template="if condition"
|
|
||||||
MapWrapper.forEach(attrs, (attrValue, attrName) => {
|
|
||||||
if (StringWrapper.startsWith(attrName, '*')) {
|
|
||||||
var key = StringWrapper.substring(attrName, 1); // remove the bang
|
|
||||||
if (hasTemplateBinding) {
|
|
||||||
// 2nd template binding detected
|
|
||||||
throw new BaseException(`Only one template directive per element is allowed: ` +
|
|
||||||
`${templateBindings} and ${key} cannot be used simultaneously ` +
|
|
||||||
`in ${current.elementDescription}`);
|
|
||||||
} else {
|
|
||||||
templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
|
|
||||||
hasTemplateBinding = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (hasTemplateBinding) {
|
if (hasTemplateBinding) {
|
||||||
var newParent = new CompileElement(DOM.createTemplate(''));
|
var newParent = new CompileElement(DOM.createTemplate(''));
|
||||||
// newParent doesn't appear in the original template, so we associate
|
// newParent doesn't appear in the original template, so we associate
|
||||||
// the current element description to get a more meaninful message in case of error
|
// the current element description to get a more meaningful message in case of error
|
||||||
newParent.elementDescription = current.elementDescription;
|
newParent.elementDescription = current.elementDescription;
|
||||||
current.isViewRoot = true;
|
current.isViewRoot = true;
|
||||||
this._parseTemplateBindings(templateBindings, newParent);
|
this._parseTemplateBindings(templateBindings, newParent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user