mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
feat(angular xml): Support [prop] and (tap) bindings
This commit is contained in:
@ -251,8 +251,8 @@ function EasySAXParser() {
|
||||
continue
|
||||
};
|
||||
|
||||
if (w < 65 || w >122 || (w>90 && w<97) ) { // ожидаем символ
|
||||
//console.log('error attr 1')
|
||||
if ((w < 65 && w !== 40 && w !== 41) || // allow parens () -- used for angular syntax
|
||||
w > 122 || (w === 92 || (w > 93 && w < 97)) ) { // ожидаем символ
|
||||
return attr_res = false; // error. invalid char
|
||||
};
|
||||
|
||||
@ -263,10 +263,14 @@ function EasySAXParser() {
|
||||
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;
|
||||
};
|
||||
|
||||
if (w === 91 || w === 93 || w === 40 || w === 41 || w === 94) { // Angular special attribute chars:[]()^
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (w !== 61) { // "=" == 61
|
||||
//console.log('error 2');
|
||||
|
40
node-tests/test-angular-xml.ts
Normal file
40
node-tests/test-angular-xml.ts
Normal 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)');
|
||||
});
|
||||
});
|
@ -27,5 +27,4 @@ describe("xml parser", () => {
|
||||
assert.equal('TextField', last_element);
|
||||
assert.equal('hello', last_attrs['text']);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -242,4 +242,4 @@ export class XmlParser implements definition.XmlParser {
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user