@loaders.gl/xml 4.0.0-alpha.9 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1440 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.SAXParser = exports.ENTITIES = void 0;
5
- const DEFAULT_SAX_EVENTS = {
6
- ontext: () => { },
7
- onprocessinginstruction: () => { },
8
- onsgmldeclaration: () => { },
9
- ondoctype: () => { },
10
- oncomment: () => { },
11
- onopentagstart: () => { },
12
- onattribute: () => { },
13
- onopentag: () => { },
14
- onclosetag: () => { },
15
- onopencdata: () => { },
16
- oncdata: () => { },
17
- onclosecdata: () => { },
18
- onerror: () => { },
19
- onend: () => { },
20
- onready: () => { },
21
- onscript: () => { },
22
- onopennamespace: () => { },
23
- onclosenamespace: () => { }
24
- };
25
- const DEFAULT_SAX_PARSER_OPTIONS = {
26
- ...DEFAULT_SAX_EVENTS,
27
- strict: false,
28
- MAX_BUFFER_LENGTH: 64 * 1024,
29
- lowercase: false,
30
- lowercasetags: false,
31
- noscript: false,
32
- strictEntities: false,
33
- xmlns: undefined,
34
- position: undefined,
35
- trim: undefined,
36
- normalize: undefined
37
- };
38
- const EVENTS = [
39
- 'text',
40
- 'processinginstruction',
41
- 'sgmldeclaration',
42
- 'doctype',
43
- 'comment',
44
- 'opentagstart',
45
- 'attribute',
46
- 'opentag',
47
- 'closetag',
48
- 'opencdata',
49
- 'cdata',
50
- 'closecdata',
51
- 'error',
52
- 'end',
53
- 'ready',
54
- 'script',
55
- 'opennamespace',
56
- 'closenamespace'
57
- ];
58
- const BUFFERS = [
59
- 'comment',
60
- 'sgmlDecl',
61
- 'textNode',
62
- 'tagName',
63
- 'doctype',
64
- 'procInstName',
65
- 'procInstBody',
66
- 'entity',
67
- 'attribName',
68
- 'attribValue',
69
- 'cdata',
70
- 'script'
71
- ];
72
- const nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
73
- const nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
74
- const entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
75
- const entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
76
- exports.ENTITIES = {
77
- amp: '&',
78
- gt: '>',
79
- lt: '<',
80
- quot: '"',
81
- apos: "'",
82
- AElig: 198,
83
- Aacute: 193,
84
- Acirc: 194,
85
- Agrave: 192,
86
- Aring: 197,
87
- Atilde: 195,
88
- Auml: 196,
89
- Ccedil: 199,
90
- ETH: 208,
91
- Eacute: 201,
92
- Ecirc: 202,
93
- Egrave: 200,
94
- Euml: 203,
95
- Iacute: 205,
96
- Icirc: 206,
97
- Igrave: 204,
98
- Iuml: 207,
99
- Ntilde: 209,
100
- Oacute: 211,
101
- Ocirc: 212,
102
- Ograve: 210,
103
- Oslash: 216,
104
- Otilde: 213,
105
- Ouml: 214,
106
- THORN: 222,
107
- Uacute: 218,
108
- Ucirc: 219,
109
- Ugrave: 217,
110
- Uuml: 220,
111
- Yacute: 221,
112
- aacute: 225,
113
- acirc: 226,
114
- aelig: 230,
115
- agrave: 224,
116
- aring: 229,
117
- atilde: 227,
118
- auml: 228,
119
- ccedil: 231,
120
- eacute: 233,
121
- ecirc: 234,
122
- egrave: 232,
123
- eth: 240,
124
- euml: 235,
125
- iacute: 237,
126
- icirc: 238,
127
- igrave: 236,
128
- iuml: 239,
129
- ntilde: 241,
130
- oacute: 243,
131
- ocirc: 244,
132
- ograve: 242,
133
- oslash: 248,
134
- otilde: 245,
135
- ouml: 246,
136
- szlig: 223,
137
- thorn: 254,
138
- uacute: 250,
139
- ucirc: 251,
140
- ugrave: 249,
141
- uuml: 252,
142
- yacute: 253,
143
- yuml: 255,
144
- copy: 169,
145
- reg: 174,
146
- nbsp: 160,
147
- iexcl: 161,
148
- cent: 162,
149
- pound: 163,
150
- curren: 164,
151
- yen: 165,
152
- brvbar: 166,
153
- sect: 167,
154
- uml: 168,
155
- ordf: 170,
156
- laquo: 171,
157
- not: 172,
158
- shy: 173,
159
- macr: 175,
160
- deg: 176,
161
- plusmn: 177,
162
- sup1: 185,
163
- sup2: 178,
164
- sup3: 179,
165
- acute: 180,
166
- micro: 181,
167
- para: 182,
168
- middot: 183,
169
- cedil: 184,
170
- ordm: 186,
171
- raquo: 187,
172
- frac14: 188,
173
- frac12: 189,
174
- frac34: 190,
175
- iquest: 191,
176
- times: 215,
177
- divide: 247,
178
- OElig: 338,
179
- oelig: 339,
180
- Scaron: 352,
181
- scaron: 353,
182
- Yuml: 376,
183
- fnof: 402,
184
- circ: 710,
185
- tilde: 732,
186
- Alpha: 913,
187
- Beta: 914,
188
- Gamma: 915,
189
- Delta: 916,
190
- Epsilon: 917,
191
- Zeta: 918,
192
- Eta: 919,
193
- Theta: 920,
194
- Iota: 921,
195
- Kappa: 922,
196
- Lambda: 923,
197
- Mu: 924,
198
- Nu: 925,
199
- Xi: 926,
200
- Omicron: 927,
201
- Pi: 928,
202
- Rho: 929,
203
- Sigma: 931,
204
- Tau: 932,
205
- Upsilon: 933,
206
- Phi: 934,
207
- Chi: 935,
208
- Psi: 936,
209
- Omega: 937,
210
- alpha: 945,
211
- beta: 946,
212
- gamma: 947,
213
- delta: 948,
214
- epsilon: 949,
215
- zeta: 950,
216
- eta: 951,
217
- theta: 952,
218
- iota: 953,
219
- kappa: 954,
220
- lambda: 955,
221
- mu: 956,
222
- nu: 957,
223
- xi: 958,
224
- omicron: 959,
225
- pi: 960,
226
- rho: 961,
227
- sigmaf: 962,
228
- sigma: 963,
229
- tau: 964,
230
- upsilon: 965,
231
- phi: 966,
232
- chi: 967,
233
- psi: 968,
234
- omega: 969,
235
- thetasym: 977,
236
- upsih: 978,
237
- piv: 982,
238
- ensp: 8194,
239
- emsp: 8195,
240
- thinsp: 8201,
241
- zwnj: 8204,
242
- zwj: 8205,
243
- lrm: 8206,
244
- rlm: 8207,
245
- ndash: 8211,
246
- mdash: 8212,
247
- lsquo: 8216,
248
- rsquo: 8217,
249
- sbquo: 8218,
250
- ldquo: 8220,
251
- rdquo: 8221,
252
- bdquo: 8222,
253
- dagger: 8224,
254
- Dagger: 8225,
255
- bull: 8226,
256
- hellip: 8230,
257
- permil: 8240,
258
- prime: 8242,
259
- Prime: 8243,
260
- lsaquo: 8249,
261
- rsaquo: 8250,
262
- oline: 8254,
263
- frasl: 8260,
264
- euro: 8364,
265
- image: 8465,
266
- weierp: 8472,
267
- real: 8476,
268
- trade: 8482,
269
- alefsym: 8501,
270
- larr: 8592,
271
- uarr: 8593,
272
- rarr: 8594,
273
- darr: 8595,
274
- harr: 8596,
275
- crarr: 8629,
276
- lArr: 8656,
277
- uArr: 8657,
278
- rArr: 8658,
279
- dArr: 8659,
280
- hArr: 8660,
281
- forall: 8704,
282
- part: 8706,
283
- exist: 8707,
284
- empty: 8709,
285
- nabla: 8711,
286
- isin: 8712,
287
- notin: 8713,
288
- ni: 8715,
289
- prod: 8719,
290
- sum: 8721,
291
- minus: 8722,
292
- lowast: 8727,
293
- radic: 8730,
294
- prop: 8733,
295
- infin: 8734,
296
- ang: 8736,
297
- and: 8743,
298
- or: 8744,
299
- cap: 8745,
300
- cup: 8746,
301
- int: 8747,
302
- there4: 8756,
303
- sim: 8764,
304
- cong: 8773,
305
- asymp: 8776,
306
- ne: 8800,
307
- equiv: 8801,
308
- le: 8804,
309
- ge: 8805,
310
- sub: 8834,
311
- sup: 8835,
312
- nsub: 8836,
313
- sube: 8838,
314
- supe: 8839,
315
- oplus: 8853,
316
- otimes: 8855,
317
- perp: 8869,
318
- sdot: 8901,
319
- lceil: 8968,
320
- rceil: 8969,
321
- lfloor: 8970,
322
- rfloor: 8971,
323
- lang: 9001,
324
- rang: 9002,
325
- loz: 9674,
326
- spades: 9824,
327
- clubs: 9827,
328
- hearts: 9829,
329
- diams: 9830
330
- };
331
- Object.keys(exports.ENTITIES).forEach((key) => {
332
- const e = exports.ENTITIES[key];
333
- exports.ENTITIES[key] = typeof e === 'number' ? String.fromCharCode(e) : e;
334
- });
335
- /**
336
- * Internal helper class
337
- */
338
- class SAX {
339
- constructor() {
340
- this.EVENTS = EVENTS;
341
- this.ENTITIES = {
342
- // TODO: make it readonly, needed for entity-mega test
343
- // amp, gt, lt, quot and apos are resolved to strings instead of numerical
344
- // codes, IDK why
345
- ...exports.ENTITIES
346
- };
347
- this.XML_ENTITIES = {
348
- amp: '&',
349
- gt: '>',
350
- lt: '<',
351
- quot: '"',
352
- apos: "'"
353
- };
354
- this.S = 0;
355
- this.trackPosition = false;
356
- this.column = 0;
357
- this.line = 0;
358
- this.c = '';
359
- this.q = '';
360
- this.closed = false;
361
- this.tags = [];
362
- this.looseCase = '';
363
- this.closedRoot = false;
364
- this.sawRoot = false;
365
- this.strict = false;
366
- this.noscript = false;
367
- this.attribList = [];
368
- this.position = 0;
369
- this.STATE = {
370
- BEGIN: this.S++,
371
- BEGIN_WHITESPACE: this.S++,
372
- TEXT: this.S++,
373
- TEXT_ENTITY: this.S++,
374
- OPEN_WAKA: this.S++,
375
- SGML_DECL: this.S++,
376
- SGML_DECL_QUOTED: this.S++,
377
- DOCTYPE: this.S++,
378
- DOCTYPE_QUOTED: this.S++,
379
- DOCTYPE_DTD: this.S++,
380
- DOCTYPE_DTD_QUOTED: this.S++,
381
- COMMENT_STARTING: this.S++,
382
- COMMENT: this.S++,
383
- COMMENT_ENDING: this.S++,
384
- COMMENT_ENDED: this.S++,
385
- CDATA: this.S++,
386
- CDATA_ENDING: this.S++,
387
- CDATA_ENDING_2: this.S++,
388
- PROC_INST: this.S++,
389
- PROC_INST_BODY: this.S++,
390
- PROC_INST_ENDING: this.S++,
391
- OPEN_TAG: this.S++,
392
- OPEN_TAG_SLASH: this.S++,
393
- ATTRIB: this.S++,
394
- ATTRIB_NAME: this.S++,
395
- ATTRIB_NAME_SAW_WHITE: this.S++,
396
- ATTRIB_VALUE: this.S++,
397
- ATTRIB_VALUE_QUOTED: this.S++,
398
- ATTRIB_VALUE_CLOSED: this.S++,
399
- ATTRIB_VALUE_UNQUOTED: this.S++,
400
- ATTRIB_VALUE_ENTITY_Q: this.S++,
401
- ATTRIB_VALUE_ENTITY_U: this.S++,
402
- CLOSE_TAG: this.S++,
403
- CLOSE_TAG_SAW_WHITE: this.S++,
404
- SCRIPT: this.S++,
405
- SCRIPT_ENDING: this.S++ // <script> ... <
406
- };
407
- this.BUFFERS = BUFFERS;
408
- // private parser: (strict: boolean, opt: any) => SAXParser;
409
- this.CDATA = '[CDATA[';
410
- this.DOCTYPE = 'DOCTYPE';
411
- this.XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
412
- this.XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/';
413
- this.rootNS = {
414
- xml: this.XML_NAMESPACE,
415
- xmlns: this.XMLNS_NAMESPACE
416
- };
417
- this.textNode = '';
418
- this.entity = '';
419
- this.cdata = '';
420
- this.script = '';
421
- this.startTagPosition = 0;
422
- this.S = 0;
423
- for (const s in this.STATE) {
424
- if (this.STATE.hasOwnProperty(s)) {
425
- this.STATE[this.STATE[s]] = s;
426
- }
427
- }
428
- // shorthand
429
- this.S = this.STATE;
430
- }
431
- static charAt(chunk, i) {
432
- let result = '';
433
- if (i < chunk.length) {
434
- result = chunk.charAt(i);
435
- }
436
- return result;
437
- }
438
- static isWhitespace(c) {
439
- return c === ' ' || c === '\n' || c === '\r' || c === '\t';
440
- }
441
- static isQuote(c) {
442
- return c === '"' || c === "'";
443
- }
444
- static isAttribEnd(c) {
445
- return c === '>' || SAX.isWhitespace(c);
446
- }
447
- static isMatch(regex, c) {
448
- return regex.test(c);
449
- }
450
- static notMatch(regex, c) {
451
- return !SAX.isMatch(regex, c);
452
- }
453
- static qname(name, attribute) {
454
- const i = name.indexOf(':');
455
- const qualName = i < 0 ? ['', name] : name.split(':');
456
- let prefix = qualName[0];
457
- let local = qualName[1];
458
- // <x "xmlns"="http://foo">
459
- if (attribute && name === 'xmlns') {
460
- prefix = 'xmlns';
461
- local = '';
462
- }
463
- return { prefix, local };
464
- }
465
- write(chunk) {
466
- if (this.error) {
467
- throw this.error;
468
- }
469
- if (this.closed) {
470
- return this.errorFunction('Cannot write after close. Assign an onready handler.');
471
- }
472
- if (chunk === null) {
473
- return this.end();
474
- }
475
- if (typeof chunk === 'object') {
476
- chunk = chunk.toString();
477
- }
478
- let i = 0;
479
- let c;
480
- while (true) {
481
- c = SAX.charAt(chunk, i++);
482
- this.c = c;
483
- if (!c) {
484
- break;
485
- }
486
- if (this.trackPosition) {
487
- this.position++;
488
- if (c === '\n') {
489
- this.line++;
490
- this.column = 0;
491
- }
492
- else {
493
- this.column++;
494
- }
495
- }
496
- switch (this.state) {
497
- case this.S.BEGIN:
498
- this.state = this.S.BEGIN_WHITESPACE;
499
- if (c === '\uFEFF') {
500
- continue;
501
- }
502
- this.beginWhiteSpace(c);
503
- continue;
504
- case this.S.BEGIN_WHITESPACE:
505
- this.beginWhiteSpace(c);
506
- continue;
507
- case this.S.TEXT:
508
- if (this.sawRoot && !this.closedRoot) {
509
- const starti = i - 1;
510
- while (c && c !== '<' && c !== '&') {
511
- c = SAX.charAt(chunk, i++);
512
- if (c && this.trackPosition) {
513
- this.position++;
514
- if (c === '\n') {
515
- this.line++;
516
- this.column = 0;
517
- }
518
- else {
519
- this.column++;
520
- }
521
- }
522
- }
523
- this.textNode += chunk.substring(starti, i - 1);
524
- }
525
- if (c === '<' && !(this.sawRoot && this.closedRoot && !this.strict)) {
526
- this.state = this.S.OPEN_WAKA;
527
- this.startTagPosition = this.position;
528
- }
529
- else {
530
- if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
531
- this.strictFail('Text data outside of root node.');
532
- }
533
- if (c === '&') {
534
- this.state = this.S.TEXT_ENTITY;
535
- }
536
- else {
537
- this.textNode += c;
538
- }
539
- }
540
- continue;
541
- case this.S.SCRIPT:
542
- // only non-strict
543
- if (c === '<') {
544
- this.state = this.S.SCRIPT_ENDING;
545
- }
546
- else {
547
- this.script += c;
548
- }
549
- continue;
550
- case this.S.SCRIPT_ENDING:
551
- if (c === '/') {
552
- this.state = this.S.CLOSE_TAG;
553
- }
554
- else {
555
- this.script += `<${c}`;
556
- this.state = this.S.SCRIPT;
557
- }
558
- continue;
559
- case this.S.OPEN_WAKA:
560
- // either a /, ?, !, or text is coming next.
561
- if (c === '!') {
562
- this.state = this.S.SGML_DECL;
563
- this.sgmlDecl = '';
564
- }
565
- else if (SAX.isWhitespace(c)) {
566
- // wait for it...
567
- }
568
- else if (SAX.isMatch(nameStart, c)) {
569
- this.state = this.S.OPEN_TAG;
570
- this.tagName = c;
571
- }
572
- else if (c === '/') {
573
- this.state = this.S.CLOSE_TAG;
574
- this.tagName = '';
575
- }
576
- else if (c === '?') {
577
- this.state = this.S.PROC_INST;
578
- this.procInstName = this.procInstBody = '';
579
- }
580
- else {
581
- this.strictFail('Unencoded <');
582
- // if there was some whitespace, then add that in.
583
- if (this.startTagPosition + 1 < this.position) {
584
- const pad = this.position - this.startTagPosition;
585
- c = new Array(pad).join(' ') + c;
586
- }
587
- this.textNode += `<${c}`;
588
- this.state = this.S.TEXT;
589
- }
590
- continue;
591
- case this.S.SGML_DECL:
592
- if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
593
- this.emitNode('onopencdata');
594
- this.state = this.S.CDATA;
595
- this.sgmlDecl = '';
596
- this.cdata = '';
597
- }
598
- else if (this.sgmlDecl + c === '--') {
599
- this.state = this.S.COMMENT;
600
- this.comment = '';
601
- this.sgmlDecl = '';
602
- }
603
- else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
604
- this.state = this.S.DOCTYPE;
605
- if (this.doctype || this.sawRoot) {
606
- this.strictFail('Inappropriately located doctype declaration');
607
- }
608
- this.doctype = '';
609
- this.sgmlDecl = '';
610
- }
611
- else if (c === '>') {
612
- this.emitNode('onsgmldeclaration', this.sgmlDecl);
613
- this.sgmlDecl = '';
614
- this.state = this.S.TEXT;
615
- }
616
- else if (SAX.isQuote(c)) {
617
- this.state = this.S.SGML_DECL_QUOTED;
618
- this.sgmlDecl += c;
619
- }
620
- else {
621
- this.sgmlDecl += c;
622
- }
623
- continue;
624
- case this.S.SGML_DECL_QUOTED:
625
- if (c === this.q) {
626
- this.state = this.S.SGML_DECL;
627
- this.q = '';
628
- }
629
- this.sgmlDecl += c;
630
- continue;
631
- case this.S.DOCTYPE:
632
- if (c === '>') {
633
- this.state = this.S.TEXT;
634
- this.emitNode('ondoctype', this.doctype);
635
- this.doctype = true; // just remember that we saw it.
636
- }
637
- else {
638
- this.doctype += c;
639
- if (c === '[') {
640
- this.state = this.S.DOCTYPE_DTD;
641
- }
642
- else if (SAX.isQuote(c)) {
643
- this.state = this.S.DOCTYPE_QUOTED;
644
- this.q = c;
645
- }
646
- }
647
- continue;
648
- case this.S.DOCTYPE_QUOTED:
649
- this.doctype += c;
650
- if (c === this.q) {
651
- this.q = '';
652
- this.state = this.S.DOCTYPE;
653
- }
654
- continue;
655
- case this.S.DOCTYPE_DTD:
656
- this.doctype += c;
657
- if (c === ']') {
658
- this.state = this.S.DOCTYPE;
659
- }
660
- else if (SAX.isQuote(c)) {
661
- this.state = this.S.DOCTYPE_DTD_QUOTED;
662
- this.q = c;
663
- }
664
- continue;
665
- case this.S.DOCTYPE_DTD_QUOTED:
666
- this.doctype += c;
667
- if (c === this.q) {
668
- this.state = this.S.DOCTYPE_DTD;
669
- this.q = '';
670
- }
671
- continue;
672
- case this.S.COMMENT:
673
- if (c === '-') {
674
- this.state = this.S.COMMENT_ENDING;
675
- }
676
- else {
677
- this.comment += c;
678
- }
679
- continue;
680
- case this.S.COMMENT_ENDING:
681
- if (c === '-') {
682
- this.state = this.S.COMMENT_ENDED;
683
- this.comment = this.textApplyOptions(this.comment);
684
- if (this.comment) {
685
- this.emitNode('oncomment', this.comment);
686
- }
687
- this.comment = '';
688
- }
689
- else {
690
- this.comment += `-${c}`;
691
- this.state = this.S.COMMENT;
692
- }
693
- continue;
694
- case this.S.COMMENT_ENDED:
695
- if (c !== '>') {
696
- this.strictFail('Malformed comment');
697
- // allow <!-- blah -- bloo --> in non-strict mode,
698
- // which is a comment of " blah -- bloo "
699
- this.comment += `--${c}`;
700
- this.state = this.S.COMMENT;
701
- }
702
- else {
703
- this.state = this.S.TEXT;
704
- }
705
- continue;
706
- case this.S.CDATA:
707
- if (c === ']') {
708
- this.state = this.S.CDATA_ENDING;
709
- }
710
- else {
711
- this.cdata += c;
712
- }
713
- continue;
714
- case this.S.CDATA_ENDING:
715
- if (c === ']') {
716
- this.state = this.S.CDATA_ENDING_2;
717
- }
718
- else {
719
- this.cdata += `]${c}`;
720
- this.state = this.S.CDATA;
721
- }
722
- continue;
723
- case this.S.CDATA_ENDING_2:
724
- if (c === '>') {
725
- if (this.cdata) {
726
- this.emitNode('oncdata', this.cdata);
727
- }
728
- this.emitNode('onclosecdata');
729
- this.cdata = '';
730
- this.state = this.S.TEXT;
731
- }
732
- else if (c === ']') {
733
- this.cdata += ']';
734
- }
735
- else {
736
- this.cdata += `]]${c}`;
737
- this.state = this.S.CDATA;
738
- }
739
- continue;
740
- case this.S.PROC_INST:
741
- if (c === '?') {
742
- this.state = this.S.PROC_INST_ENDING;
743
- }
744
- else if (SAX.isWhitespace(c)) {
745
- this.state = this.S.PROC_INST_BODY;
746
- }
747
- else {
748
- this.procInstName += c;
749
- }
750
- continue;
751
- case this.S.PROC_INST_BODY:
752
- if (!this.procInstBody && SAX.isWhitespace(c)) {
753
- continue;
754
- }
755
- else if (c === '?') {
756
- this.state = this.S.PROC_INST_ENDING;
757
- }
758
- else {
759
- this.procInstBody += c;
760
- }
761
- continue;
762
- case this.S.PROC_INST_ENDING:
763
- if (c === '>') {
764
- this.emitNode('onprocessinginstruction', {
765
- name: this.procInstName,
766
- body: this.procInstBody
767
- });
768
- this.procInstName = this.procInstBody = '';
769
- this.state = this.S.TEXT;
770
- }
771
- else {
772
- this.procInstBody += `?${c}`;
773
- this.state = this.S.PROC_INST_BODY;
774
- }
775
- continue;
776
- case this.S.OPEN_TAG:
777
- if (SAX.isMatch(nameBody, c)) {
778
- this.tagName += c;
779
- }
780
- else {
781
- this.newTag();
782
- if (c === '>') {
783
- this.openTag();
784
- }
785
- else if (c === '/') {
786
- this.state = this.S.OPEN_TAG_SLASH;
787
- }
788
- else {
789
- if (!SAX.isWhitespace(c)) {
790
- this.strictFail('Invalid character in tag name');
791
- }
792
- this.state = this.S.ATTRIB;
793
- }
794
- }
795
- continue;
796
- case this.S.OPEN_TAG_SLASH:
797
- if (c === '>') {
798
- this.openTag(true);
799
- this.closeTag();
800
- }
801
- else {
802
- this.strictFail('Forward-slash in opening tag not followed by >');
803
- this.state = this.S.ATTRIB;
804
- }
805
- continue;
806
- case this.S.ATTRIB:
807
- // haven't read the attribute name yet.
808
- if (SAX.isWhitespace(c)) {
809
- continue;
810
- }
811
- else if (c === '>') {
812
- this.openTag();
813
- }
814
- else if (c === '/') {
815
- this.state = this.S.OPEN_TAG_SLASH;
816
- }
817
- else if (SAX.isMatch(nameStart, c)) {
818
- this.attribName = c;
819
- this.attribValue = '';
820
- this.state = this.S.ATTRIB_NAME;
821
- }
822
- else {
823
- this.strictFail('Invalid attribute name');
824
- }
825
- continue;
826
- case this.S.ATTRIB_NAME:
827
- if (c === '=') {
828
- this.state = this.S.ATTRIB_VALUE;
829
- }
830
- else if (c === '>') {
831
- this.strictFail('Attribute without value');
832
- this.attribValue = this.attribName;
833
- this.attrib();
834
- this.openTag();
835
- }
836
- else if (SAX.isWhitespace(c)) {
837
- this.state = this.S.ATTRIB_NAME_SAW_WHITE;
838
- }
839
- else if (SAX.isMatch(nameBody, c)) {
840
- this.attribName += c;
841
- }
842
- else {
843
- this.strictFail('Invalid attribute name');
844
- }
845
- continue;
846
- case this.S.ATTRIB_NAME_SAW_WHITE:
847
- if (c === '=') {
848
- this.state = this.S.ATTRIB_VALUE;
849
- }
850
- else if (SAX.isWhitespace(c)) {
851
- continue;
852
- }
853
- else {
854
- this.strictFail('Attribute without value');
855
- this.tag.attributes[this.attribName] = '';
856
- this.attribValue = '';
857
- this.emitNode('onattribute', {
858
- name: this.attribName,
859
- value: ''
860
- });
861
- this.attribName = '';
862
- if (c === '>') {
863
- this.openTag();
864
- }
865
- else if (SAX.isMatch(nameStart, c)) {
866
- this.attribName = c;
867
- this.state = this.S.ATTRIB_NAME;
868
- }
869
- else {
870
- this.strictFail('Invalid attribute name');
871
- this.state = this.S.ATTRIB;
872
- }
873
- }
874
- continue;
875
- case this.S.ATTRIB_VALUE:
876
- if (SAX.isWhitespace(c)) {
877
- continue;
878
- }
879
- else if (SAX.isQuote(c)) {
880
- this.q = c;
881
- this.state = this.S.ATTRIB_VALUE_QUOTED;
882
- }
883
- else {
884
- this.strictFail('Unquoted attribute value');
885
- this.state = this.S.ATTRIB_VALUE_UNQUOTED;
886
- this.attribValue = c;
887
- }
888
- continue;
889
- case this.S.ATTRIB_VALUE_QUOTED:
890
- if (c !== this.q) {
891
- if (c === '&') {
892
- this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
893
- }
894
- else {
895
- this.attribValue += c;
896
- }
897
- continue;
898
- }
899
- this.attrib();
900
- this.q = '';
901
- this.state = this.S.ATTRIB_VALUE_CLOSED;
902
- continue;
903
- case this.S.ATTRIB_VALUE_CLOSED:
904
- if (SAX.isWhitespace(c)) {
905
- this.state = this.S.ATTRIB;
906
- }
907
- else if (c === '>') {
908
- this.openTag();
909
- }
910
- else if (c === '/') {
911
- this.state = this.S.OPEN_TAG_SLASH;
912
- }
913
- else if (SAX.isMatch(nameStart, c)) {
914
- this.strictFail('No whitespace between attributes');
915
- this.attribName = c;
916
- this.attribValue = '';
917
- this.state = this.S.ATTRIB_NAME;
918
- }
919
- else {
920
- this.strictFail('Invalid attribute name');
921
- }
922
- continue;
923
- case this.S.ATTRIB_VALUE_UNQUOTED:
924
- if (!SAX.isAttribEnd(c)) {
925
- if (c === '&') {
926
- this.state = this.S.ATTRIB_VALUE_ENTITY_U;
927
- }
928
- else {
929
- this.attribValue += c;
930
- }
931
- continue;
932
- }
933
- this.attrib();
934
- if (c === '>') {
935
- this.openTag();
936
- }
937
- else {
938
- this.state = this.S.ATTRIB;
939
- }
940
- continue;
941
- case this.S.CLOSE_TAG:
942
- if (!this.tagName) {
943
- if (SAX.isWhitespace(c)) {
944
- continue;
945
- }
946
- else if (SAX.notMatch(nameStart, c)) {
947
- if (this.script) {
948
- this.script += `</${c}`;
949
- this.state = this.S.SCRIPT;
950
- }
951
- else {
952
- this.strictFail('Invalid tagname in closing tag.');
953
- }
954
- }
955
- else {
956
- this.tagName = c;
957
- }
958
- }
959
- else if (c === '>') {
960
- this.closeTag();
961
- }
962
- else if (SAX.isMatch(nameBody, c)) {
963
- this.tagName += c;
964
- }
965
- else if (this.script) {
966
- this.script += `</${this.tagName}`;
967
- this.tagName = '';
968
- this.state = this.S.SCRIPT;
969
- }
970
- else {
971
- if (!SAX.isWhitespace(c)) {
972
- this.strictFail('Invalid tagname in closing tag');
973
- }
974
- this.state = this.S.CLOSE_TAG_SAW_WHITE;
975
- }
976
- continue;
977
- case this.S.CLOSE_TAG_SAW_WHITE:
978
- if (SAX.isWhitespace(c)) {
979
- continue;
980
- }
981
- if (c === '>') {
982
- this.closeTag();
983
- }
984
- else {
985
- this.strictFail('Invalid characters in closing tag');
986
- }
987
- continue;
988
- case this.S.TEXT_ENTITY:
989
- case this.S.ATTRIB_VALUE_ENTITY_Q:
990
- case this.S.ATTRIB_VALUE_ENTITY_U:
991
- let returnState;
992
- let buffer;
993
- switch (this.state) {
994
- case this.S.TEXT_ENTITY:
995
- returnState = this.S.TEXT;
996
- buffer = 'textNode';
997
- break;
998
- case this.S.ATTRIB_VALUE_ENTITY_Q:
999
- returnState = this.S.ATTRIB_VALUE_QUOTED;
1000
- buffer = 'attribValue';
1001
- break;
1002
- case this.S.ATTRIB_VALUE_ENTITY_U:
1003
- returnState = this.S.ATTRIB_VALUE_UNQUOTED;
1004
- buffer = 'attribValue';
1005
- break;
1006
- default:
1007
- throw new Error(`Unknown state: ${this.state}`);
1008
- }
1009
- if (c === ';') {
1010
- this[buffer] += this.parseEntity();
1011
- this.entity = '';
1012
- this.state = returnState;
1013
- }
1014
- else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
1015
- this.entity += c;
1016
- }
1017
- else {
1018
- this.strictFail('Invalid character in entity name');
1019
- this[buffer] += `&${this.entity}${c}`;
1020
- this.entity = '';
1021
- this.state = returnState;
1022
- }
1023
- continue;
1024
- default:
1025
- throw new Error(`Unknown state: ${this.state}`);
1026
- }
1027
- } // while
1028
- if (this.position >= this.bufferCheckPosition) {
1029
- this.checkBufferLength();
1030
- }
1031
- return this;
1032
- }
1033
- emit(event, data) {
1034
- if (this.events.hasOwnProperty(event)) {
1035
- const eventName = event.replace(/^on/, '');
1036
- this.events[event](data, eventName, this);
1037
- }
1038
- }
1039
- clearBuffers() {
1040
- for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1041
- this[this[i]] = '';
1042
- }
1043
- }
1044
- flushBuffers() {
1045
- this.closeText();
1046
- if (this.cdata !== '') {
1047
- this.emitNode('oncdata', this.cdata);
1048
- this.cdata = '';
1049
- }
1050
- if (this.script !== '') {
1051
- this.emitNode('onscript', this.script);
1052
- this.script = '';
1053
- }
1054
- }
1055
- end() {
1056
- if (this.sawRoot && !this.closedRoot)
1057
- this.strictFail('Unclosed root tag');
1058
- if (this.state !== this.S.BEGIN &&
1059
- this.state !== this.S.BEGIN_WHITESPACE &&
1060
- this.state !== this.S.TEXT) {
1061
- this.errorFunction('Unexpected end');
1062
- }
1063
- this.closeText();
1064
- this.c = '';
1065
- this.closed = true;
1066
- this.emit('onend');
1067
- return new SAXParser(this.opt);
1068
- }
1069
- errorFunction(er) {
1070
- this.closeText();
1071
- if (this.trackPosition) {
1072
- er += `\nLine: ${this.line}\nColumn: ${this.column}\nChar: ${this.c}`;
1073
- }
1074
- const error = new Error(er);
1075
- this.error = error;
1076
- this.emit('onerror', error);
1077
- return this;
1078
- }
1079
- attrib() {
1080
- if (!this.strict) {
1081
- this.attribName = this.attribName[this.looseCase]();
1082
- }
1083
- if (this.attribList.indexOf(this.attribName) !== -1 ||
1084
- this.tag.attributes.hasOwnProperty(this.attribName)) {
1085
- this.attribName = this.attribValue = '';
1086
- return;
1087
- }
1088
- if (this.opt.xmlns) {
1089
- const qn = SAX.qname(this.attribName, true);
1090
- const prefix = qn.prefix;
1091
- const local = qn.local;
1092
- if (prefix === 'xmlns') {
1093
- // namespace binding attribute. push the binding into scope
1094
- if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
1095
- this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE}\n` + `Actual: ${this.attribValue}`);
1096
- }
1097
- else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
1098
- this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}\n` +
1099
- `Actual: ${this.attribValue}`);
1100
- }
1101
- else {
1102
- const tag = this.tag;
1103
- const parent = this.tags[this.tags.length - 1] || this;
1104
- if (tag.ns === parent.ns) {
1105
- tag.ns = Object.create(parent.ns);
1106
- }
1107
- tag.ns[local] = this.attribValue;
1108
- }
1109
- }
1110
- // defer onattribute events until all attributes have been seen
1111
- // so any new bindings can take effect. preserve attribute order
1112
- // so deferred events can be emitted in document order
1113
- this.attribList.push([this.attribName, this.attribValue]);
1114
- }
1115
- else {
1116
- // in non-xmlns mode, we can emit the event right away
1117
- this.tag.attributes[this.attribName] = this.attribValue;
1118
- this.emitNode('onattribute', {
1119
- name: this.attribName,
1120
- value: this.attribValue
1121
- });
1122
- }
1123
- this.attribName = this.attribValue = '';
1124
- }
1125
- newTag() {
1126
- if (!this.strict)
1127
- this.tagName = this.tagName[this.looseCase]();
1128
- const parent = this.tags[this.tags.length - 1] || this;
1129
- const tag = (this.tag = { name: this.tagName, attributes: {} });
1130
- // will be overridden if tag contains an xmlns="foo" or xmlns:foo="bar"
1131
- if (this.opt.xmlns) {
1132
- tag.ns = parent.ns;
1133
- }
1134
- this.attribList.length = 0;
1135
- this.emitNode('onopentagstart', tag);
1136
- }
1137
- parseEntity() {
1138
- let entity = this.entity;
1139
- const entityLC = entity.toLowerCase();
1140
- let num = NaN;
1141
- let numStr = '';
1142
- if (this.ENTITIES[entity]) {
1143
- return this.ENTITIES[entity];
1144
- }
1145
- if (this.ENTITIES[entityLC]) {
1146
- return this.ENTITIES[entityLC];
1147
- }
1148
- entity = entityLC;
1149
- if (entity.charAt(0) === '#') {
1150
- if (entity.charAt(1) === 'x') {
1151
- entity = entity.slice(2);
1152
- // TODO: remove tslint:disable
1153
- // tslint:disable-next-line
1154
- num = parseInt(entity, 16);
1155
- numStr = num.toString(16);
1156
- }
1157
- else {
1158
- entity = entity.slice(1);
1159
- // TODO: remove tslint:disable
1160
- // tslint:disable-next-line
1161
- num = parseInt(entity, 10);
1162
- numStr = num.toString(10);
1163
- }
1164
- }
1165
- entity = entity.replace(/^0+/, '');
1166
- if (isNaN(num) || numStr.toLowerCase() !== entity) {
1167
- this.strictFail('Invalid character entity');
1168
- return `&${this.entity};`;
1169
- }
1170
- return String.fromCodePoint(num);
1171
- }
1172
- beginWhiteSpace(c) {
1173
- if (c === '<') {
1174
- this.state = this.S.OPEN_WAKA;
1175
- this.startTagPosition = this.position;
1176
- }
1177
- else if (!SAX.isWhitespace(c)) {
1178
- // have to process this as a text node.
1179
- // weird, but happens.
1180
- this.strictFail('Non-whitespace before first tag.');
1181
- this.textNode = c;
1182
- this.state = this.S.TEXT;
1183
- }
1184
- else {
1185
- }
1186
- }
1187
- strictFail(message) {
1188
- if (typeof this !== 'object' || !(this instanceof SAXParser)) {
1189
- throw new Error('bad call to strictFail');
1190
- }
1191
- if (this.strict) {
1192
- this.errorFunction(message);
1193
- }
1194
- }
1195
- textApplyOptions(text) {
1196
- if (this.opt.trim)
1197
- text = text.trim();
1198
- if (this.opt.normalize)
1199
- text = text.replace(/\s+/g, ' ');
1200
- return text;
1201
- }
1202
- emitNode(nodeType, data) {
1203
- if (this.textNode)
1204
- this.closeText();
1205
- this.emit(nodeType, data);
1206
- }
1207
- closeText() {
1208
- this.textNode = this.textApplyOptions(this.textNode);
1209
- // TODO: figure out why this.textNode can be "" and "undefined"
1210
- if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
1211
- this.emit('ontext', this.textNode);
1212
- }
1213
- this.textNode = '';
1214
- }
1215
- checkBufferLength() {
1216
- const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1217
- let maxActual = 0;
1218
- for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1219
- const len = this[this.BUFFERS[i]]?.length || 0;
1220
- if (len > maxAllowed) {
1221
- // Text/cdata nodes can get big, and since they're buffered,
1222
- // we can get here under normal conditions.
1223
- // Avoid issues by emitting the text node now,
1224
- // so at least it won't get any bigger.
1225
- switch (this.BUFFERS[i]) {
1226
- case 'textNode':
1227
- this.closeText();
1228
- break;
1229
- case 'cdata':
1230
- this.emitNode('oncdata', this.cdata);
1231
- this.cdata = '';
1232
- break;
1233
- case 'script':
1234
- this.emitNode('onscript', this.script);
1235
- this.script = '';
1236
- break;
1237
- default:
1238
- this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[i]}`);
1239
- }
1240
- }
1241
- maxActual = Math.max(maxActual, len);
1242
- }
1243
- // schedule the next check for the earliest possible buffer overrun.
1244
- const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1245
- this.bufferCheckPosition = m + this.position;
1246
- }
1247
- openTag(selfClosing) {
1248
- if (this.opt.xmlns) {
1249
- // emit namespace binding events
1250
- const tag = this.tag;
1251
- // add namespace info to tag
1252
- const qn = SAX.qname(this.tagName);
1253
- tag.prefix = qn.prefix;
1254
- tag.local = qn.local;
1255
- tag.uri = tag.ns[qn.prefix] || '';
1256
- if (tag.prefix && !tag.uri) {
1257
- this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`);
1258
- tag.uri = qn.prefix;
1259
- }
1260
- const parent = this.tags[this.tags.length - 1] || this;
1261
- if (tag.ns && parent.ns !== tag.ns) {
1262
- const that = this;
1263
- Object.keys(tag.ns).forEach((p) => {
1264
- that.emitNode('onopennamespace', {
1265
- prefix: p,
1266
- uri: tag.ns[p]
1267
- });
1268
- });
1269
- }
1270
- // handle deferred onattribute events
1271
- // Note: do not apply default ns to attributes:
1272
- // http://www.w3.org/TR/REC-xml-names/#defaulting
1273
- for (let i = 0, l = this.attribList.length; i < l; i++) {
1274
- const nv = this.attribList[i];
1275
- const name = nv[0];
1276
- const value = nv[1];
1277
- const qualName = SAX.qname(name, true);
1278
- const prefix = qualName.prefix;
1279
- const local = qualName.local;
1280
- const uri = prefix === '' ? '' : tag.ns[prefix] || '';
1281
- const a = {
1282
- name,
1283
- value,
1284
- prefix,
1285
- local,
1286
- uri
1287
- };
1288
- // if there's any attributes with an undefined namespace,
1289
- // then fail on them now.
1290
- if (prefix && prefix !== 'xmlns' && !uri) {
1291
- this.strictFail(`Unbound namespace prefix: ${JSON.stringify(prefix)}`);
1292
- a.uri = prefix;
1293
- }
1294
- this.tag.attributes[name] = a;
1295
- this.emitNode('onattribute', a);
1296
- }
1297
- this.attribList.length = 0;
1298
- }
1299
- this.tag.isSelfClosing = Boolean(selfClosing);
1300
- // process the tag
1301
- this.sawRoot = true;
1302
- this.tags.push(this.tag);
1303
- this.emitNode('onopentag', this.tag);
1304
- if (!selfClosing) {
1305
- // special case for <script> in non-strict mode.
1306
- if (!this.noscript && this.tagName.toLowerCase() === 'script') {
1307
- this.state = this.S.SCRIPT;
1308
- }
1309
- else {
1310
- this.state = this.S.TEXT;
1311
- }
1312
- this.tag = null;
1313
- this.tagName = '';
1314
- }
1315
- this.attribName = this.attribValue = '';
1316
- this.attribList.length = 0;
1317
- }
1318
- closeTag() {
1319
- if (!this.tagName) {
1320
- this.strictFail('Weird empty close tag.');
1321
- this.textNode += '</>';
1322
- this.state = this.S.TEXT;
1323
- return;
1324
- }
1325
- if (this.script) {
1326
- if (this.tagName !== 'script') {
1327
- this.script += `</${this.tagName}>`;
1328
- this.tagName = '';
1329
- this.state = this.S.SCRIPT;
1330
- return;
1331
- }
1332
- this.emitNode('onscript', this.script);
1333
- this.script = '';
1334
- }
1335
- // first make sure that the closing tag actually exists.
1336
- // <a><b></c></b></a> will close everything, otherwise.
1337
- let t = this.tags.length;
1338
- let tagName = this.tagName;
1339
- if (!this.strict) {
1340
- tagName = tagName[this.looseCase]();
1341
- }
1342
- while (t--) {
1343
- const close = this.tags[t];
1344
- if (close.name !== tagName) {
1345
- // fail the first time in strict mode
1346
- this.strictFail('Unexpected close tag');
1347
- }
1348
- else {
1349
- break;
1350
- }
1351
- }
1352
- // didn't find it. we already failed for strict, so just abort.
1353
- if (t < 0) {
1354
- this.strictFail(`Unmatched closing tag: ${this.tagName}`);
1355
- this.textNode += `</${this.tagName}>`;
1356
- this.state = this.S.TEXT;
1357
- return;
1358
- }
1359
- this.tagName = tagName;
1360
- let s = this.tags.length;
1361
- while (s-- > t) {
1362
- const tag = (this.tag = this.tags.pop());
1363
- this.tagName = this.tag.name;
1364
- this.emitNode('onclosetag', this.tagName);
1365
- const x = {};
1366
- for (const i in tag.ns) {
1367
- if (tag.ns.hasOwnProperty(i)) {
1368
- x[i] = tag.ns[i];
1369
- }
1370
- }
1371
- const parent = this.tags[this.tags.length - 1] || this;
1372
- if (this.opt.xmlns && tag.ns !== parent.ns) {
1373
- // remove namespace bindings introduced by tag
1374
- const that = this;
1375
- Object.keys(tag.ns).forEach((p) => {
1376
- const n = tag.ns[p];
1377
- that.emitNode('onclosenamespace', { prefix: p, uri: n });
1378
- });
1379
- }
1380
- }
1381
- if (t === 0)
1382
- this.closedRoot = true;
1383
- this.tagName = this.attribValue = this.attribName = '';
1384
- this.attribList.length = 0;
1385
- this.state = this.S.TEXT;
1386
- }
1387
- }
1388
- /**
1389
- *
1390
- * @todo Weird inheritance, with some variables initialized in subclass
1391
- */
1392
- class SAXParser extends SAX {
1393
- constructor(opt) {
1394
- super();
1395
- this.opt = DEFAULT_SAX_PARSER_OPTIONS;
1396
- this.events = DEFAULT_SAX_EVENTS;
1397
- this.clearBuffers();
1398
- this.opt = opt = { ...this.opt, ...opt };
1399
- this.events = { ...this.events, ...opt };
1400
- this.q = this.c = '';
1401
- this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
1402
- this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
1403
- this.looseCase = this.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
1404
- this.tags = [];
1405
- this.closed = this.closedRoot = this.sawRoot = false;
1406
- this.tag = this.error = null;
1407
- this.strict = Boolean(this.opt.strict);
1408
- this.noscript = Boolean(this.opt.strict || this.opt.noscript);
1409
- this.state = this.S.BEGIN;
1410
- this.strictEntities = this.opt.strictEntities;
1411
- this.ENTITIES = this.strictEntities
1412
- ? Object.create(this.XML_ENTITIES)
1413
- : Object.create(this.ENTITIES);
1414
- this.attribList = [];
1415
- // namespaces form a prototype chain.
1416
- // it always points at the current tag,
1417
- // which protos to its parent tag.
1418
- if (this.opt.xmlns) {
1419
- this.ns = Object.create(this.rootNS);
1420
- }
1421
- // mostly just for error reporting
1422
- this.trackPosition = this.opt.position !== false;
1423
- if (this.trackPosition) {
1424
- this.position = this.line = this.column = 0;
1425
- }
1426
- this.emit('onready');
1427
- }
1428
- resume() {
1429
- this.error = null;
1430
- return this;
1431
- }
1432
- close() {
1433
- return this.write(null);
1434
- }
1435
- flush() {
1436
- this.flushBuffers();
1437
- }
1438
- }
1439
- SAXParser.ENTITIES = exports.ENTITIES;
1440
- exports.SAXParser = SAXParser;