fix(PropertyBindingParser): detect bindings using full attribute name

Fixes #1001

Closes #1004
This commit is contained in:
Pawel Kozlowski 2015-03-18 21:27:46 +01:00 committed by Misko Hevery
parent 476386fb5b
commit e0710c4613
2 changed files with 20 additions and 1 deletions

View File

@ -17,7 +17,7 @@ import {CompileControl} from './compile_control';
// Group 7 = "#" // Group 7 = "#"
// Group 8 = identifier after "#" // Group 8 = identifier after "#"
var BIND_NAME_REGEXP = RegExpWrapper.create( var BIND_NAME_REGEXP = RegExpWrapper.create(
'^(?:(?:(bind)|(var)|(on))-(.+))|\\[([^\\]]+)\\]|\\(([^\\)]+)\\)|(#)(.+)'); '^(?:(?:(?:(bind)|(var)|(on))-(.+))|\\[([^\\]]+)\\]|\\(([^\\)]+)\\)|(#)(.+))$');
/** /**
* Parses the property bindings on a single element. * Parses the property bindings on a single element.

View File

@ -25,11 +25,20 @@ export function main() {
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b'); expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
}); });
it('should detect [] syntax only if an attribute name starts and ends with []', () => {
expect(createPipeline().process(el('<div z[a]="b"></div>'))[0].propertyBindings).toBe(null);
expect(createPipeline().process(el('<div [a]v="b"></div>'))[0].propertyBindings).toBe(null);
});
it('should detect bind- syntax', () => { it('should detect bind- syntax', () => {
var results = createPipeline().process(el('<div bind-a="b"></div>')); var results = createPipeline().process(el('<div bind-a="b"></div>'));
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b'); expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
}); });
it('should detect bind- syntax only if an attribute name starts with bind', () => {
expect(createPipeline().process(el('<div _bind-a="b"></div>'))[0].propertyBindings).toBe(null);
});
it('should detect interpolation syntax', () => { it('should detect interpolation syntax', () => {
// Note: we don't test all corner cases of interpolation as we assume shared functionality between text interpolation // Note: we don't test all corner cases of interpolation as we assume shared functionality between text interpolation
// and attribute interpolation. // and attribute interpolation.
@ -62,6 +71,11 @@ export function main() {
expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george'); expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
}); });
it('should detect variable bindings only if an attribute name starts with #', () => {
var results = createPipeline().process(el('<p b#george></p>'));
expect(results[0].variableBindings).toBe(null);
});
it('should detect () syntax', () => { it('should detect () syntax', () => {
var results = createPipeline().process(el('<div (click)="b()"></div>')); var results = createPipeline().process(el('<div (click)="b()"></div>'));
expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('b()'); expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('b()');
@ -70,6 +84,11 @@ export function main() {
expect(MapWrapper.get(results[0].eventBindings, 'click[]').source).toEqual('b()'); expect(MapWrapper.get(results[0].eventBindings, 'click[]').source).toEqual('b()');
}); });
it('should detect () syntax only if an attribute name starts and ends with ()', () => {
expect(createPipeline().process(el('<div z(a)="b()"></div>'))[0].propertyBindings).toBe(null);
expect(createPipeline().process(el('<div (a)v="b()"></div>'))[0].propertyBindings).toBe(null);
});
it('should parse event handlers using () syntax as actions', () => { it('should parse event handlers using () syntax as actions', () => {
var results = createPipeline().process(el('<div (click)="foo=bar"></div>')); var results = createPipeline().process(el('<div (click)="foo=bar"></div>'));
expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('foo=bar'); expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('foo=bar');