fix(compiler): add missing support to string literals

Fixes #531
Closes #559
This commit is contained in:
Marc Laval
2015-02-05 20:13:32 +01:00
parent 6dbfe0dc2e
commit cf169f13a0
8 changed files with 73 additions and 8 deletions

View File

@ -79,6 +79,10 @@ export class Parser {
return new ASTWithSource(new Interpolation(strings, expressions), input, location);
}
wrapLiteralPrimitive(input:string, location:any):ASTWithSource {
return new ASTWithSource(new LiteralPrimitive(input), input, location);
}
}
class _ParseAST {

View File

@ -35,6 +35,6 @@ export function createDefaultSteps(
new ElementBindingMarker(),
new ProtoViewBuilder(changeDetection, shadowDomStrategy),
new ProtoElementInjectorBuilder(),
new ElementBinderBuilder()
new ElementBinderBuilder(parser, compilationUnit)
];
}

View File

@ -1,4 +1,4 @@
import {isPresent, BaseException} from 'angular2/src/facade/lang';
import {isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
import {List, MapWrapper} from 'angular2/src/facade/collection';
import {TemplateElement} from 'angular2/src/facade/dom';
import {SelectorMatcher} from '../selector';
@ -50,7 +50,10 @@ export class DirectiveParser extends CompileStep {
cssSelector.addClassName(classList[i]);
}
MapWrapper.forEach(attrs, (attrValue, attrName) => {
cssSelector.addAttribute(attrName, attrValue);
if (isBlank(current.propertyBindings) ||
isPresent(current.propertyBindings) && !MapWrapper.contains(current.propertyBindings, attrName)) {
cssSelector.addAttribute(attrName, attrValue);
}
});
if (isPresent(current.propertyBindings)) {
MapWrapper.forEach(current.propertyBindings, (expression, prop) => {

View File

@ -86,6 +86,13 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
* with the flag `isViewRoot`.
*/
export class ElementBinderBuilder extends CompileStep {
_parser:Parser;
_compilationUnit:any;
constructor(parser:Parser, compilationUnit:any) {
this._parser = parser;
this._compilationUnit = compilationUnit;
}
process(parent:CompileElement, current:CompileElement, control:CompileControl) {
var elementBinder = null;
if (current.hasBindings) {
@ -149,13 +156,19 @@ export class ElementBinderBuilder extends CompileStep {
var directive = ListWrapper.get(directives, directiveIndex);
var annotation = directive.annotation;
if (isBlank(annotation.bind)) continue;
var _this = this;
StringMapWrapper.forEach(annotation.bind, function (dirProp, elProp) {
var expression = isPresent(compileElement.propertyBindings) ?
MapWrapper.get(compileElement.propertyBindings, elProp) :
null;
if (isBlank(expression)) {
throw new BaseException("No element binding found for property '" + elProp
var attributeValue = MapWrapper.get(compileElement.attrs(), elProp);
if (isPresent(attributeValue)) {
expression = _this._parser.wrapLiteralPrimitive(attributeValue, _this._compilationUnit);
} else {
throw new BaseException("No element binding found for property '" + elProp
+ "' which is required by directive '" + stringify(directive.type) + "'");
}
}
var len = dirProp.length;
var dirBindingName = dirProp;