FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(angular xml): Support [prop] and (tap) bindings · NativeScript/NativeScript@fdd8c9b · GitHub

Commit fdd8c9b

Browse files
committed
feat(angular xml): Support [prop] and (tap) bindings
1 parent 2a2c0e5 commit fdd8c9b

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎js-libs/easysax/easysax.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ function EasySAXParser() {
251251
continue
252252
};
253253

254-
if (w < 65 || w >122 || (w>90 && w<97) ) { // ожидаем символ
255-
//console.log('error attr 1')
254+
if ((w < 65 && w !== 40 && w !== 41) || // allow parens () -- used for angular syntax
255+
w > 122 || (w === 92 || (w > 93 && w < 97)) ) { // ожидаем символ
256256
return attr_res = false; // error. invalid char
257257
};
258258

@@ -263,10 +263,14 @@ function EasySAXParser() {
263263
continue;
264264
};
265265

266-
if (w===32 || (w > 8 && w<14) ) { // \f\n\r\t\v пробел
266+
if (w === 32 || (w > 8 && w < 14) ) { // \f\n\r\t\v пробел
267267
continue;
268268
};
269269

270+
if (w === 91 || w === 93 || w === 40 || w === 41 || w === 94) { // Angular special attribute chars:[]()^
271+
continue;
272+
}
273+
270274

271275
if (w !== 61) { // "=" == 61
272276
//console.log('error 2');

‎node-tests/test-angular-xml.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {assert} from "chai";
2+
import xml = require('xml');
3+
4+
describe("angular xml parser", () => {
5+
let last_element = null;
6+
let last_attrs = null;
7+
let parser = null;
8+
9+
beforeEach(() => {
10+
parser = new xml.XmlParser(function (event: xml.ParserEvent) {
11+
switch (event.eventType) {
12+
case xml.ParserEventType.StartElement:
13+
last_element = event.elementName;
14+
last_attrs = event.attributes;
15+
break;
16+
}
17+
});
18+
});
19+
20+
it("parses [property] binding", () => {
21+
parser.parse("<TextField [text]='somevar' />");
22+
23+
assert.equal('TextField', last_element);
24+
assert.equal(last_attrs['[text]'], 'somevar');
25+
});
26+
27+
it("parses (event) binding", () => {
28+
parser.parse("<TextField (tap)='onTap(blah)' />");
29+
30+
assert.equal('TextField', last_element);
31+
assert.equal(last_attrs['(tap)'], 'onTap(blah)');
32+
});
33+
34+
it("parsers (^event) binding", () => {
35+
parser.parse("<TextField (^tap)='onTap(blah)' />");
36+
37+
assert.equal('TextField', last_element);
38+
assert.equal(last_attrs['(^tap)'], 'onTap(blah)');
39+
});
40+
});

‎node-tests/test-xml.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ describe("xml parser", () => {
2727
assert.equal('TextField', last_element);
2828
assert.equal('hello', last_attrs['text']);
2929
});
30-
3130
});

‎xml/xml.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,4 @@ export class XmlParser implements definition.XmlParser {
242242

243243
return s;
244244
}
245-
}
245+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL