feat(angular xml): Support [prop] and (tap) bindings

This commit is contained in:
Hristo Deshev
2015-06-04 17:13:18 +03:00
parent 2a2c0e5c31
commit fdd8c9b116
4 changed files with 48 additions and 5 deletions

View File

@ -251,8 +251,8 @@ function EasySAXParser() {
continue continue
}; };
if (w < 65 || w >122 || (w>90 && w<97) ) { // ожидаем символ if ((w < 65 && w !== 40 && w !== 41) || // allow parens () -- used for angular syntax
//console.log('error attr 1') w > 122 || (w === 92 || (w > 93 && w < 97)) ) { // ожидаем символ
return attr_res = false; // error. invalid char return attr_res = false; // error. invalid char
}; };
@ -263,10 +263,14 @@ function EasySAXParser() {
continue; continue;
}; };
if (w===32 || (w > 8 && w<14) ) { // \f\n\r\t\v пробел if (w === 32 || (w > 8 && w < 14) ) { // \f\n\r\t\v пробел
continue; continue;
}; };
if (w === 91 || w === 93 || w === 40 || w === 41 || w === 94) { // Angular special attribute chars:[]()^
continue;
}
if (w !== 61) { // "=" == 61 if (w !== 61) { // "=" == 61
//console.log('error 2'); //console.log('error 2');

View File

@ -0,0 +1,40 @@
import {assert} from "chai";
import xml = require('xml');
describe("angular xml parser", () => {
let last_element = null;
let last_attrs = null;
let parser = null;
beforeEach(() => {
parser = new xml.XmlParser(function (event: xml.ParserEvent) {
switch (event.eventType) {
case xml.ParserEventType.StartElement:
last_element = event.elementName;
last_attrs = event.attributes;
break;
}
});
});
it("parses [property] binding", () => {
parser.parse("<TextField [text]='somevar' />");
assert.equal('TextField', last_element);
assert.equal(last_attrs['[text]'], 'somevar');
});
it("parses (event) binding", () => {
parser.parse("<TextField (tap)='onTap(blah)' />");
assert.equal('TextField', last_element);
assert.equal(last_attrs['(tap)'], 'onTap(blah)');
});
it("parsers (^event) binding", () => {
parser.parse("<TextField (^tap)='onTap(blah)' />");
assert.equal('TextField', last_element);
assert.equal(last_attrs['(^tap)'], 'onTap(blah)');
});
});

View File

@ -27,5 +27,4 @@ describe("xml parser", () => {
assert.equal('TextField', last_element); assert.equal('TextField', last_element);
assert.equal('hello', last_attrs['text']); assert.equal('hello', last_attrs['text']);
}); });
}); });

View File

@ -242,4 +242,4 @@ export class XmlParser implements definition.XmlParser {
return s; return s;
} }
} }