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

@ -543,6 +543,12 @@ export function main() {
expect(ast.expressions[1].name).toEqual('b');
});
});
describe('wrapLiteralPrimitive', () => {
it('should wrap a literal primitive', () => {
expect(createParser().wrapLiteralPrimitive("foo", null).eval(null)).toEqual("foo");
});
});
});
}

View File

@ -65,14 +65,23 @@ export function main() {
});
it('should consume directive watch expression change.', (done) => {
compiler.compile(MyComp, el('<div my-dir [elprop]="ctxProp"></div>')).then((pv) => {
var tpl =
'<div>' +
'<div my-dir [elprop]="ctxProp"></div>' +
'<div my-dir elprop="Hi there!"></div>' +
'<div my-dir elprop="Hi {{\'there!\'}}"></div>' +
'<div my-dir elprop="One more {{ctxProp}}"></div>' +
'</div>'
compiler.compile(MyComp, el(tpl)).then((pv) => {
createView(pv);
ctx.ctxProp = 'Hello World!';
cd.detectChanges();
var elInj = view.elementInjectors[0];
expect(elInj.get(MyDir).dirProp).toEqual('Hello World!');
expect(view.elementInjectors[0].get(MyDir).dirProp).toEqual('Hello World!');
expect(view.elementInjectors[1].get(MyDir).dirProp).toEqual('Hi there!');
expect(view.elementInjectors[2].get(MyDir).dirProp).toEqual('Hi there!');
expect(view.elementInjectors[3].get(MyDir).dirProp).toEqual('One more Hello World!');
done();
});
});

View File

@ -24,6 +24,7 @@ export function main() {
directives = [
SomeDecorator,
SomeDecoratorIgnoringChildren,
SomeDecoratorWithBinding,
SomeTemplate,
SomeTemplate2,
SomeComponent,
@ -182,6 +183,15 @@ export function main() {
);
}).toThrowError('Only template directives are allowed on <template> elements!');
});
it('should not instantiate decorator directive twice', () => {
var pipeline = createPipeline({propertyBindings: {
'some-decor-with-binding': 'someExpr'
}});
var results = pipeline.process(el('<div some-decor-with-binding="foo"></div>'));
expect(results[0].decoratorDirectives.length).toEqual(1);
expect(results[0].decoratorDirectives).toEqual([reader.read(SomeDecoratorWithBinding)]);
});
});
});
}
@ -208,6 +218,14 @@ class SomeDecorator {}
class SomeDecoratorIgnoringChildren {
}
@Decorator({
selector: '[some-decor-with-binding]',
bind: {
'some-decor-with-binding': 'foo'
}
})
class SomeDecoratorWithBinding {}
@Template({
selector: '[some-templ]'
})

View File

@ -73,7 +73,7 @@ export function main() {
} else if (isPresent(parent)) {
current.inheritedProtoView = parent.inheritedProtoView;
}
}), new ElementBinderBuilder()
}), new ElementBinderBuilder(parser, null)
]);
}
@ -312,6 +312,18 @@ export function main() {
expect(view.elementInjectors[1].get(SomeDecoratorDirectiveWithBinding).decorProp).toBe('a');
});
it('should bind to string literals', () => {
var directives = [SomeDecoratorDirectiveWithBinding];
var protoElementInjector = new ProtoElementInjector(null, 0, directives);
var pipeline = createPipeline({directives: directives, protoElementInjector: protoElementInjector});
var results = pipeline.process(el('<div viewroot directives boundprop1="foo"></div>'));
var pv = results[0].inheritedProtoView;
instantiateView(pv);
changeDetector.detectChanges();
expect(view.elementInjectors[0].get(SomeDecoratorDirectiveWithBinding).decorProp).toEqual('foo');
});
describe('errors', () => {
it('should throw if there is no element property bindings for a directive property binding', () => {