@loaders.gl/xml 3.4.13 → 3.4.15

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.
@@ -5,39 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.SAXParser = exports.ENTITIES = void 0;
8
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
9
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
10
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
11
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
12
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
17
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
- var DEFAULT_SAX_EVENTS = {
21
- ontext: function ontext() {},
22
- onprocessinginstruction: function onprocessinginstruction() {},
23
- onsgmldeclaration: function onsgmldeclaration() {},
24
- ondoctype: function ondoctype() {},
25
- oncomment: function oncomment() {},
26
- onopentagstart: function onopentagstart() {},
27
- onattribute: function onattribute() {},
28
- onopentag: function onopentag() {},
29
- onclosetag: function onclosetag() {},
30
- onopencdata: function onopencdata() {},
31
- oncdata: function oncdata() {},
32
- onclosecdata: function onclosecdata() {},
33
- onerror: function onerror() {},
34
- onend: function onend() {},
35
- onready: function onready() {},
36
- onscript: function onscript() {},
37
- onopennamespace: function onopennamespace() {},
38
- onclosenamespace: function onclosenamespace() {}
9
+ const DEFAULT_SAX_EVENTS = {
10
+ ontext: () => {},
11
+ onprocessinginstruction: () => {},
12
+ onsgmldeclaration: () => {},
13
+ ondoctype: () => {},
14
+ oncomment: () => {},
15
+ onopentagstart: () => {},
16
+ onattribute: () => {},
17
+ onopentag: () => {},
18
+ onclosetag: () => {},
19
+ onopencdata: () => {},
20
+ oncdata: () => {},
21
+ onclosecdata: () => {},
22
+ onerror: () => {},
23
+ onend: () => {},
24
+ onready: () => {},
25
+ onscript: () => {},
26
+ onopennamespace: () => {},
27
+ onclosenamespace: () => {}
39
28
  };
40
- var DEFAULT_SAX_PARSER_OPTIONS = _objectSpread(_objectSpread({}, DEFAULT_SAX_EVENTS), {}, {
29
+ const DEFAULT_SAX_PARSER_OPTIONS = {
30
+ ...DEFAULT_SAX_EVENTS,
41
31
  strict: false,
42
32
  MAX_BUFFER_LENGTH: 64 * 1024,
43
33
  lowercase: false,
@@ -48,14 +38,14 @@ var DEFAULT_SAX_PARSER_OPTIONS = _objectSpread(_objectSpread({}, DEFAULT_SAX_EVE
48
38
  position: undefined,
49
39
  trim: undefined,
50
40
  normalize: undefined
51
- });
52
- var EVENTS = ['text', 'processinginstruction', 'sgmldeclaration', 'doctype', 'comment', 'opentagstart', 'attribute', 'opentag', 'closetag', 'opencdata', 'cdata', 'closecdata', 'error', 'end', 'ready', 'script', 'opennamespace', 'closenamespace'];
53
- var BUFFERS = ['comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', 'procInstName', 'procInstBody', 'entity', 'attribName', 'attribValue', 'cdata', 'script'];
54
- var 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]/;
55
- var 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-]/;
56
- var 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]/;
57
- var 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-]/;
58
- var ENTITIES = {
41
+ };
42
+ const EVENTS = ['text', 'processinginstruction', 'sgmldeclaration', 'doctype', 'comment', 'opentagstart', 'attribute', 'opentag', 'closetag', 'opencdata', 'cdata', 'closecdata', 'error', 'end', 'ready', 'script', 'opennamespace', 'closenamespace'];
43
+ const BUFFERS = ['comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', 'procInstName', 'procInstBody', 'entity', 'attribName', 'attribValue', 'cdata', 'script'];
44
+ 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]/;
45
+ 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-]/;
46
+ 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]/;
47
+ 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-]/;
48
+ const ENTITIES = {
59
49
  amp: '&',
60
50
  gt: '>',
61
51
  lt: '<',
@@ -311,15 +301,16 @@ var ENTITIES = {
311
301
  diams: 9830
312
302
  };
313
303
  exports.ENTITIES = ENTITIES;
314
- Object.keys(ENTITIES).forEach(function (key) {
315
- var e = ENTITIES[key];
304
+ Object.keys(ENTITIES).forEach(key => {
305
+ const e = ENTITIES[key];
316
306
  ENTITIES[key] = typeof e === 'number' ? String.fromCharCode(e) : e;
317
307
  });
318
- var SAX = function () {
319
- function SAX() {
320
- (0, _classCallCheck2.default)(this, SAX);
308
+ class SAX {
309
+ constructor() {
321
310
  (0, _defineProperty2.default)(this, "EVENTS", EVENTS);
322
- (0, _defineProperty2.default)(this, "ENTITIES", _objectSpread({}, ENTITIES));
311
+ (0, _defineProperty2.default)(this, "ENTITIES", {
312
+ ...ENTITIES
313
+ });
323
314
  (0, _defineProperty2.default)(this, "events", void 0);
324
315
  (0, _defineProperty2.default)(this, "XML_ENTITIES", {
325
316
  amp: '&',
@@ -411,962 +402,901 @@ var SAX = function () {
411
402
  (0, _defineProperty2.default)(this, "script", '');
412
403
  (0, _defineProperty2.default)(this, "startTagPosition", 0);
413
404
  this.S = 0;
414
- for (var s in this.STATE) {
405
+ for (const s in this.STATE) {
415
406
  if (this.STATE.hasOwnProperty(s)) {
416
407
  this.STATE[this.STATE[s]] = s;
417
408
  }
418
409
  }
419
410
  this.S = this.STATE;
420
411
  }
421
- (0, _createClass2.default)(SAX, [{
422
- key: "write",
423
- value: function write(chunk) {
424
- if (this.error) {
425
- throw this.error;
426
- }
427
- if (this.closed) {
428
- return this.errorFunction('Cannot write after close. Assign an onready handler.');
429
- }
430
- if (chunk === null) {
431
- return this.end();
432
- }
433
- if ((0, _typeof2.default)(chunk) === 'object') {
434
- chunk = chunk.toString();
412
+ static charAt(chunk, i) {
413
+ let result = '';
414
+ if (i < chunk.length) {
415
+ result = chunk.charAt(i);
416
+ }
417
+ return result;
418
+ }
419
+ static isWhitespace(c) {
420
+ return c === ' ' || c === '\n' || c === '\r' || c === '\t';
421
+ }
422
+ static isQuote(c) {
423
+ return c === '"' || c === "'";
424
+ }
425
+ static isAttribEnd(c) {
426
+ return c === '>' || SAX.isWhitespace(c);
427
+ }
428
+ static isMatch(regex, c) {
429
+ return regex.test(c);
430
+ }
431
+ static notMatch(regex, c) {
432
+ return !SAX.isMatch(regex, c);
433
+ }
434
+ static qname(name, attribute) {
435
+ const i = name.indexOf(':');
436
+ const qualName = i < 0 ? ['', name] : name.split(':');
437
+ let prefix = qualName[0];
438
+ let local = qualName[1];
439
+ if (attribute && name === 'xmlns') {
440
+ prefix = 'xmlns';
441
+ local = '';
442
+ }
443
+ return {
444
+ prefix,
445
+ local
446
+ };
447
+ }
448
+ write(chunk) {
449
+ if (this.error) {
450
+ throw this.error;
451
+ }
452
+ if (this.closed) {
453
+ return this.errorFunction('Cannot write after close. Assign an onready handler.');
454
+ }
455
+ if (chunk === null) {
456
+ return this.end();
457
+ }
458
+ if (typeof chunk === 'object') {
459
+ chunk = chunk.toString();
460
+ }
461
+ let i = 0;
462
+ let c;
463
+ while (true) {
464
+ c = SAX.charAt(chunk, i++);
465
+ this.c = c;
466
+ if (!c) {
467
+ break;
435
468
  }
436
- var i = 0;
437
- var c;
438
- while (true) {
439
- c = SAX.charAt(chunk, i++);
440
- this.c = c;
441
- if (!c) {
442
- break;
443
- }
444
- if (this.trackPosition) {
445
- this.position++;
446
- if (c === '\n') {
447
- this.line++;
448
- this.column = 0;
449
- } else {
450
- this.column++;
451
- }
469
+ if (this.trackPosition) {
470
+ this.position++;
471
+ if (c === '\n') {
472
+ this.line++;
473
+ this.column = 0;
474
+ } else {
475
+ this.column++;
452
476
  }
453
- switch (this.state) {
454
- case this.S.BEGIN:
455
- this.state = this.S.BEGIN_WHITESPACE;
456
- if (c === "\uFEFF") {
457
- continue;
458
- }
459
- this.beginWhiteSpace(c);
460
- continue;
461
- case this.S.BEGIN_WHITESPACE:
462
- this.beginWhiteSpace(c);
477
+ }
478
+ switch (this.state) {
479
+ case this.S.BEGIN:
480
+ this.state = this.S.BEGIN_WHITESPACE;
481
+ if (c === '\uFEFF') {
463
482
  continue;
464
- case this.S.TEXT:
465
- if (this.sawRoot && !this.closedRoot) {
466
- var starti = i - 1;
467
- while (c && c !== '<' && c !== '&') {
468
- c = SAX.charAt(chunk, i++);
469
- if (c && this.trackPosition) {
470
- this.position++;
471
- if (c === '\n') {
472
- this.line++;
473
- this.column = 0;
474
- } else {
475
- this.column++;
476
- }
483
+ }
484
+ this.beginWhiteSpace(c);
485
+ continue;
486
+ case this.S.BEGIN_WHITESPACE:
487
+ this.beginWhiteSpace(c);
488
+ continue;
489
+ case this.S.TEXT:
490
+ if (this.sawRoot && !this.closedRoot) {
491
+ const starti = i - 1;
492
+ while (c && c !== '<' && c !== '&') {
493
+ c = SAX.charAt(chunk, i++);
494
+ if (c && this.trackPosition) {
495
+ this.position++;
496
+ if (c === '\n') {
497
+ this.line++;
498
+ this.column = 0;
499
+ } else {
500
+ this.column++;
477
501
  }
478
502
  }
479
- this.textNode += chunk.substring(starti, i - 1);
480
503
  }
481
- if (c === '<' && !(this.sawRoot && this.closedRoot && !this.strict)) {
482
- this.state = this.S.OPEN_WAKA;
483
- this.startTagPosition = this.position;
484
- } else {
485
- if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
486
- this.strictFail('Text data outside of root node.');
487
- }
488
- if (c === '&') {
489
- this.state = this.S.TEXT_ENTITY;
490
- } else {
491
- this.textNode += c;
492
- }
493
- }
494
- continue;
495
- case this.S.SCRIPT:
496
- if (c === '<') {
497
- this.state = this.S.SCRIPT_ENDING;
498
- } else {
499
- this.script += c;
500
- }
501
- continue;
502
- case this.S.SCRIPT_ENDING:
503
- if (c === '/') {
504
- this.state = this.S.CLOSE_TAG;
505
- } else {
506
- this.script += "<".concat(c);
507
- this.state = this.S.SCRIPT;
504
+ this.textNode += chunk.substring(starti, i - 1);
505
+ }
506
+ if (c === '<' && !(this.sawRoot && this.closedRoot && !this.strict)) {
507
+ this.state = this.S.OPEN_WAKA;
508
+ this.startTagPosition = this.position;
509
+ } else {
510
+ if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
511
+ this.strictFail('Text data outside of root node.');
508
512
  }
509
- continue;
510
- case this.S.OPEN_WAKA:
511
- if (c === '!') {
512
- this.state = this.S.SGML_DECL;
513
- this.sgmlDecl = '';
514
- } else if (SAX.isWhitespace(c)) {} else if (SAX.isMatch(nameStart, c)) {
515
- this.state = this.S.OPEN_TAG;
516
- this.tagName = c;
517
- } else if (c === '/') {
518
- this.state = this.S.CLOSE_TAG;
519
- this.tagName = '';
520
- } else if (c === '?') {
521
- this.state = this.S.PROC_INST;
522
- this.procInstName = this.procInstBody = '';
513
+ if (c === '&') {
514
+ this.state = this.S.TEXT_ENTITY;
523
515
  } else {
524
- this.strictFail('Unencoded <');
525
- if (this.startTagPosition + 1 < this.position) {
526
- var pad = this.position - this.startTagPosition;
527
- c = new Array(pad).join(' ') + c;
528
- }
529
- this.textNode += "<".concat(c);
530
- this.state = this.S.TEXT;
516
+ this.textNode += c;
531
517
  }
532
- continue;
533
- case this.S.SGML_DECL:
534
- if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
535
- this.emitNode('onopencdata');
536
- this.state = this.S.CDATA;
537
- this.sgmlDecl = '';
538
- this.cdata = '';
539
- } else if (this.sgmlDecl + c === '--') {
540
- this.state = this.S.COMMENT;
541
- this.comment = '';
542
- this.sgmlDecl = '';
543
- } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
544
- this.state = this.S.DOCTYPE;
545
- if (this.doctype || this.sawRoot) {
546
- this.strictFail('Inappropriately located doctype declaration');
547
- }
548
- this.doctype = '';
549
- this.sgmlDecl = '';
550
- } else if (c === '>') {
551
- this.emitNode('onsgmldeclaration', this.sgmlDecl);
552
- this.sgmlDecl = '';
553
- this.state = this.S.TEXT;
554
- } else if (SAX.isQuote(c)) {
555
- this.state = this.S.SGML_DECL_QUOTED;
556
- this.sgmlDecl += c;
557
- } else {
558
- this.sgmlDecl += c;
518
+ }
519
+ continue;
520
+ case this.S.SCRIPT:
521
+ if (c === '<') {
522
+ this.state = this.S.SCRIPT_ENDING;
523
+ } else {
524
+ this.script += c;
525
+ }
526
+ continue;
527
+ case this.S.SCRIPT_ENDING:
528
+ if (c === '/') {
529
+ this.state = this.S.CLOSE_TAG;
530
+ } else {
531
+ this.script += "<".concat(c);
532
+ this.state = this.S.SCRIPT;
533
+ }
534
+ continue;
535
+ case this.S.OPEN_WAKA:
536
+ if (c === '!') {
537
+ this.state = this.S.SGML_DECL;
538
+ this.sgmlDecl = '';
539
+ } else if (SAX.isWhitespace(c)) {} else if (SAX.isMatch(nameStart, c)) {
540
+ this.state = this.S.OPEN_TAG;
541
+ this.tagName = c;
542
+ } else if (c === '/') {
543
+ this.state = this.S.CLOSE_TAG;
544
+ this.tagName = '';
545
+ } else if (c === '?') {
546
+ this.state = this.S.PROC_INST;
547
+ this.procInstName = this.procInstBody = '';
548
+ } else {
549
+ this.strictFail('Unencoded <');
550
+ if (this.startTagPosition + 1 < this.position) {
551
+ const pad = this.position - this.startTagPosition;
552
+ c = new Array(pad).join(' ') + c;
559
553
  }
560
- continue;
561
- case this.S.SGML_DECL_QUOTED:
562
- if (c === this.q) {
563
- this.state = this.S.SGML_DECL;
564
- this.q = '';
554
+ this.textNode += "<".concat(c);
555
+ this.state = this.S.TEXT;
556
+ }
557
+ continue;
558
+ case this.S.SGML_DECL:
559
+ if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
560
+ this.emitNode('onopencdata');
561
+ this.state = this.S.CDATA;
562
+ this.sgmlDecl = '';
563
+ this.cdata = '';
564
+ } else if (this.sgmlDecl + c === '--') {
565
+ this.state = this.S.COMMENT;
566
+ this.comment = '';
567
+ this.sgmlDecl = '';
568
+ } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
569
+ this.state = this.S.DOCTYPE;
570
+ if (this.doctype || this.sawRoot) {
571
+ this.strictFail('Inappropriately located doctype declaration');
565
572
  }
573
+ this.doctype = '';
574
+ this.sgmlDecl = '';
575
+ } else if (c === '>') {
576
+ this.emitNode('onsgmldeclaration', this.sgmlDecl);
577
+ this.sgmlDecl = '';
578
+ this.state = this.S.TEXT;
579
+ } else if (SAX.isQuote(c)) {
580
+ this.state = this.S.SGML_DECL_QUOTED;
566
581
  this.sgmlDecl += c;
567
- continue;
568
- case this.S.DOCTYPE:
569
- if (c === '>') {
570
- this.state = this.S.TEXT;
571
- this.emitNode('ondoctype', this.doctype);
572
- this.doctype = true;
573
- } else {
574
- this.doctype += c;
575
- if (c === '[') {
576
- this.state = this.S.DOCTYPE_DTD;
577
- } else if (SAX.isQuote(c)) {
578
- this.state = this.S.DOCTYPE_QUOTED;
579
- this.q = c;
580
- }
581
- }
582
- continue;
583
- case this.S.DOCTYPE_QUOTED:
584
- this.doctype += c;
585
- if (c === this.q) {
586
- this.q = '';
587
- this.state = this.S.DOCTYPE;
588
- }
589
- continue;
590
- case this.S.DOCTYPE_DTD:
582
+ } else {
583
+ this.sgmlDecl += c;
584
+ }
585
+ continue;
586
+ case this.S.SGML_DECL_QUOTED:
587
+ if (c === this.q) {
588
+ this.state = this.S.SGML_DECL;
589
+ this.q = '';
590
+ }
591
+ this.sgmlDecl += c;
592
+ continue;
593
+ case this.S.DOCTYPE:
594
+ if (c === '>') {
595
+ this.state = this.S.TEXT;
596
+ this.emitNode('ondoctype', this.doctype);
597
+ this.doctype = true;
598
+ } else {
591
599
  this.doctype += c;
592
- if (c === ']') {
593
- this.state = this.S.DOCTYPE;
600
+ if (c === '[') {
601
+ this.state = this.S.DOCTYPE_DTD;
594
602
  } else if (SAX.isQuote(c)) {
595
- this.state = this.S.DOCTYPE_DTD_QUOTED;
603
+ this.state = this.S.DOCTYPE_QUOTED;
596
604
  this.q = c;
597
605
  }
598
- continue;
599
- case this.S.DOCTYPE_DTD_QUOTED:
600
- this.doctype += c;
601
- if (c === this.q) {
602
- this.state = this.S.DOCTYPE_DTD;
603
- this.q = '';
604
- }
605
- continue;
606
- case this.S.COMMENT:
607
- if (c === '-') {
608
- this.state = this.S.COMMENT_ENDING;
609
- } else {
610
- this.comment += c;
611
- }
612
- continue;
613
- case this.S.COMMENT_ENDING:
614
- if (c === '-') {
615
- this.state = this.S.COMMENT_ENDED;
616
- this.comment = this.textApplyOptions(this.comment);
617
- if (this.comment) {
618
- this.emitNode('oncomment', this.comment);
619
- }
620
- this.comment = '';
621
- } else {
622
- this.comment += "-".concat(c);
623
- this.state = this.S.COMMENT;
624
- }
625
- continue;
626
- case this.S.COMMENT_ENDED:
627
- if (c !== '>') {
628
- this.strictFail('Malformed comment');
629
- this.comment += "--".concat(c);
630
- this.state = this.S.COMMENT;
631
- } else {
632
- this.state = this.S.TEXT;
633
- }
634
- continue;
635
- case this.S.CDATA:
636
- if (c === ']') {
637
- this.state = this.S.CDATA_ENDING;
638
- } else {
639
- this.cdata += c;
640
- }
641
- continue;
642
- case this.S.CDATA_ENDING:
643
- if (c === ']') {
644
- this.state = this.S.CDATA_ENDING_2;
645
- } else {
646
- this.cdata += "]".concat(c);
647
- this.state = this.S.CDATA;
648
- }
649
- continue;
650
- case this.S.CDATA_ENDING_2:
651
- if (c === '>') {
652
- if (this.cdata) {
653
- this.emitNode('oncdata', this.cdata);
654
- }
655
- this.emitNode('onclosecdata');
656
- this.cdata = '';
657
- this.state = this.S.TEXT;
658
- } else if (c === ']') {
659
- this.cdata += ']';
660
- } else {
661
- this.cdata += "]]".concat(c);
662
- this.state = this.S.CDATA;
663
- }
664
- continue;
665
- case this.S.PROC_INST:
666
- if (c === '?') {
667
- this.state = this.S.PROC_INST_ENDING;
668
- } else if (SAX.isWhitespace(c)) {
669
- this.state = this.S.PROC_INST_BODY;
670
- } else {
671
- this.procInstName += c;
672
- }
673
- continue;
674
- case this.S.PROC_INST_BODY:
675
- if (!this.procInstBody && SAX.isWhitespace(c)) {
676
- continue;
677
- } else if (c === '?') {
678
- this.state = this.S.PROC_INST_ENDING;
679
- } else {
680
- this.procInstBody += c;
681
- }
682
- continue;
683
- case this.S.PROC_INST_ENDING:
684
- if (c === '>') {
685
- this.emitNode('onprocessinginstruction', {
686
- name: this.procInstName,
687
- body: this.procInstBody
688
- });
689
- this.procInstName = this.procInstBody = '';
690
- this.state = this.S.TEXT;
691
- } else {
692
- this.procInstBody += "?".concat(c);
693
- this.state = this.S.PROC_INST_BODY;
606
+ }
607
+ continue;
608
+ case this.S.DOCTYPE_QUOTED:
609
+ this.doctype += c;
610
+ if (c === this.q) {
611
+ this.q = '';
612
+ this.state = this.S.DOCTYPE;
613
+ }
614
+ continue;
615
+ case this.S.DOCTYPE_DTD:
616
+ this.doctype += c;
617
+ if (c === ']') {
618
+ this.state = this.S.DOCTYPE;
619
+ } else if (SAX.isQuote(c)) {
620
+ this.state = this.S.DOCTYPE_DTD_QUOTED;
621
+ this.q = c;
622
+ }
623
+ continue;
624
+ case this.S.DOCTYPE_DTD_QUOTED:
625
+ this.doctype += c;
626
+ if (c === this.q) {
627
+ this.state = this.S.DOCTYPE_DTD;
628
+ this.q = '';
629
+ }
630
+ continue;
631
+ case this.S.COMMENT:
632
+ if (c === '-') {
633
+ this.state = this.S.COMMENT_ENDING;
634
+ } else {
635
+ this.comment += c;
636
+ }
637
+ continue;
638
+ case this.S.COMMENT_ENDING:
639
+ if (c === '-') {
640
+ this.state = this.S.COMMENT_ENDED;
641
+ this.comment = this.textApplyOptions(this.comment);
642
+ if (this.comment) {
643
+ this.emitNode('oncomment', this.comment);
694
644
  }
695
- continue;
696
- case this.S.OPEN_TAG:
697
- if (SAX.isMatch(nameBody, c)) {
698
- this.tagName += c;
699
- } else {
700
- this.newTag();
701
- if (c === '>') {
702
- this.openTag();
703
- } else if (c === '/') {
704
- this.state = this.S.OPEN_TAG_SLASH;
705
- } else {
706
- if (!SAX.isWhitespace(c)) {
707
- this.strictFail('Invalid character in tag name');
708
- }
709
- this.state = this.S.ATTRIB;
710
- }
645
+ this.comment = '';
646
+ } else {
647
+ this.comment += "-".concat(c);
648
+ this.state = this.S.COMMENT;
649
+ }
650
+ continue;
651
+ case this.S.COMMENT_ENDED:
652
+ if (c !== '>') {
653
+ this.strictFail('Malformed comment');
654
+ this.comment += "--".concat(c);
655
+ this.state = this.S.COMMENT;
656
+ } else {
657
+ this.state = this.S.TEXT;
658
+ }
659
+ continue;
660
+ case this.S.CDATA:
661
+ if (c === ']') {
662
+ this.state = this.S.CDATA_ENDING;
663
+ } else {
664
+ this.cdata += c;
665
+ }
666
+ continue;
667
+ case this.S.CDATA_ENDING:
668
+ if (c === ']') {
669
+ this.state = this.S.CDATA_ENDING_2;
670
+ } else {
671
+ this.cdata += "]".concat(c);
672
+ this.state = this.S.CDATA;
673
+ }
674
+ continue;
675
+ case this.S.CDATA_ENDING_2:
676
+ if (c === '>') {
677
+ if (this.cdata) {
678
+ this.emitNode('oncdata', this.cdata);
711
679
  }
680
+ this.emitNode('onclosecdata');
681
+ this.cdata = '';
682
+ this.state = this.S.TEXT;
683
+ } else if (c === ']') {
684
+ this.cdata += ']';
685
+ } else {
686
+ this.cdata += "]]".concat(c);
687
+ this.state = this.S.CDATA;
688
+ }
689
+ continue;
690
+ case this.S.PROC_INST:
691
+ if (c === '?') {
692
+ this.state = this.S.PROC_INST_ENDING;
693
+ } else if (SAX.isWhitespace(c)) {
694
+ this.state = this.S.PROC_INST_BODY;
695
+ } else {
696
+ this.procInstName += c;
697
+ }
698
+ continue;
699
+ case this.S.PROC_INST_BODY:
700
+ if (!this.procInstBody && SAX.isWhitespace(c)) {
712
701
  continue;
713
- case this.S.OPEN_TAG_SLASH:
702
+ } else if (c === '?') {
703
+ this.state = this.S.PROC_INST_ENDING;
704
+ } else {
705
+ this.procInstBody += c;
706
+ }
707
+ continue;
708
+ case this.S.PROC_INST_ENDING:
709
+ if (c === '>') {
710
+ this.emitNode('onprocessinginstruction', {
711
+ name: this.procInstName,
712
+ body: this.procInstBody
713
+ });
714
+ this.procInstName = this.procInstBody = '';
715
+ this.state = this.S.TEXT;
716
+ } else {
717
+ this.procInstBody += "?".concat(c);
718
+ this.state = this.S.PROC_INST_BODY;
719
+ }
720
+ continue;
721
+ case this.S.OPEN_TAG:
722
+ if (SAX.isMatch(nameBody, c)) {
723
+ this.tagName += c;
724
+ } else {
725
+ this.newTag();
714
726
  if (c === '>') {
715
- this.openTag(true);
716
- this.closeTag();
717
- } else {
718
- this.strictFail('Forward-slash in opening tag not followed by >');
719
- this.state = this.S.ATTRIB;
720
- }
721
- continue;
722
- case this.S.ATTRIB:
723
- if (SAX.isWhitespace(c)) {
724
- continue;
725
- } else if (c === '>') {
726
727
  this.openTag();
727
728
  } else if (c === '/') {
728
729
  this.state = this.S.OPEN_TAG_SLASH;
729
- } else if (SAX.isMatch(nameStart, c)) {
730
- this.attribName = c;
731
- this.attribValue = '';
732
- this.state = this.S.ATTRIB_NAME;
733
730
  } else {
734
- this.strictFail('Invalid attribute name');
735
- }
736
- continue;
737
- case this.S.ATTRIB_NAME:
738
- if (c === '=') {
739
- this.state = this.S.ATTRIB_VALUE;
740
- } else if (c === '>') {
741
- this.strictFail('Attribute without value');
742
- this.attribValue = this.attribName;
743
- this.attrib();
744
- this.openTag();
745
- } else if (SAX.isWhitespace(c)) {
746
- this.state = this.S.ATTRIB_NAME_SAW_WHITE;
747
- } else if (SAX.isMatch(nameBody, c)) {
748
- this.attribName += c;
749
- } else {
750
- this.strictFail('Invalid attribute name');
751
- }
752
- continue;
753
- case this.S.ATTRIB_NAME_SAW_WHITE:
754
- if (c === '=') {
755
- this.state = this.S.ATTRIB_VALUE;
756
- } else if (SAX.isWhitespace(c)) {
757
- continue;
758
- } else {
759
- this.strictFail('Attribute without value');
760
- this.tag.attributes[this.attribName] = '';
761
- this.attribValue = '';
762
- this.emitNode('onattribute', {
763
- name: this.attribName,
764
- value: ''
765
- });
766
- this.attribName = '';
767
- if (c === '>') {
768
- this.openTag();
769
- } else if (SAX.isMatch(nameStart, c)) {
770
- this.attribName = c;
771
- this.state = this.S.ATTRIB_NAME;
772
- } else {
773
- this.strictFail('Invalid attribute name');
774
- this.state = this.S.ATTRIB;
731
+ if (!SAX.isWhitespace(c)) {
732
+ this.strictFail('Invalid character in tag name');
775
733
  }
734
+ this.state = this.S.ATTRIB;
776
735
  }
736
+ }
737
+ continue;
738
+ case this.S.OPEN_TAG_SLASH:
739
+ if (c === '>') {
740
+ this.openTag(true);
741
+ this.closeTag();
742
+ } else {
743
+ this.strictFail('Forward-slash in opening tag not followed by >');
744
+ this.state = this.S.ATTRIB;
745
+ }
746
+ continue;
747
+ case this.S.ATTRIB:
748
+ if (SAX.isWhitespace(c)) {
777
749
  continue;
778
- case this.S.ATTRIB_VALUE:
779
- if (SAX.isWhitespace(c)) {
780
- continue;
781
- } else if (SAX.isQuote(c)) {
782
- this.q = c;
783
- this.state = this.S.ATTRIB_VALUE_QUOTED;
784
- } else {
785
- this.strictFail('Unquoted attribute value');
786
- this.state = this.S.ATTRIB_VALUE_UNQUOTED;
787
- this.attribValue = c;
788
- }
789
- continue;
790
- case this.S.ATTRIB_VALUE_QUOTED:
791
- if (c !== this.q) {
792
- if (c === '&') {
793
- this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
794
- } else {
795
- this.attribValue += c;
796
- }
797
- continue;
798
- }
750
+ } else if (c === '>') {
751
+ this.openTag();
752
+ } else if (c === '/') {
753
+ this.state = this.S.OPEN_TAG_SLASH;
754
+ } else if (SAX.isMatch(nameStart, c)) {
755
+ this.attribName = c;
756
+ this.attribValue = '';
757
+ this.state = this.S.ATTRIB_NAME;
758
+ } else {
759
+ this.strictFail('Invalid attribute name');
760
+ }
761
+ continue;
762
+ case this.S.ATTRIB_NAME:
763
+ if (c === '=') {
764
+ this.state = this.S.ATTRIB_VALUE;
765
+ } else if (c === '>') {
766
+ this.strictFail('Attribute without value');
767
+ this.attribValue = this.attribName;
799
768
  this.attrib();
800
- this.q = '';
801
- this.state = this.S.ATTRIB_VALUE_CLOSED;
769
+ this.openTag();
770
+ } else if (SAX.isWhitespace(c)) {
771
+ this.state = this.S.ATTRIB_NAME_SAW_WHITE;
772
+ } else if (SAX.isMatch(nameBody, c)) {
773
+ this.attribName += c;
774
+ } else {
775
+ this.strictFail('Invalid attribute name');
776
+ }
777
+ continue;
778
+ case this.S.ATTRIB_NAME_SAW_WHITE:
779
+ if (c === '=') {
780
+ this.state = this.S.ATTRIB_VALUE;
781
+ } else if (SAX.isWhitespace(c)) {
802
782
  continue;
803
- case this.S.ATTRIB_VALUE_CLOSED:
804
- if (SAX.isWhitespace(c)) {
805
- this.state = this.S.ATTRIB;
806
- } else if (c === '>') {
783
+ } else {
784
+ this.strictFail('Attribute without value');
785
+ this.tag.attributes[this.attribName] = '';
786
+ this.attribValue = '';
787
+ this.emitNode('onattribute', {
788
+ name: this.attribName,
789
+ value: ''
790
+ });
791
+ this.attribName = '';
792
+ if (c === '>') {
807
793
  this.openTag();
808
- } else if (c === '/') {
809
- this.state = this.S.OPEN_TAG_SLASH;
810
794
  } else if (SAX.isMatch(nameStart, c)) {
811
- this.strictFail('No whitespace between attributes');
812
795
  this.attribName = c;
813
- this.attribValue = '';
814
796
  this.state = this.S.ATTRIB_NAME;
815
797
  } else {
816
798
  this.strictFail('Invalid attribute name');
799
+ this.state = this.S.ATTRIB;
817
800
  }
801
+ }
802
+ continue;
803
+ case this.S.ATTRIB_VALUE:
804
+ if (SAX.isWhitespace(c)) {
818
805
  continue;
819
- case this.S.ATTRIB_VALUE_UNQUOTED:
820
- if (!SAX.isAttribEnd(c)) {
821
- if (c === '&') {
822
- this.state = this.S.ATTRIB_VALUE_ENTITY_U;
823
- } else {
824
- this.attribValue += c;
825
- }
826
- continue;
827
- }
828
- this.attrib();
829
- if (c === '>') {
830
- this.openTag();
806
+ } else if (SAX.isQuote(c)) {
807
+ this.q = c;
808
+ this.state = this.S.ATTRIB_VALUE_QUOTED;
809
+ } else {
810
+ this.strictFail('Unquoted attribute value');
811
+ this.state = this.S.ATTRIB_VALUE_UNQUOTED;
812
+ this.attribValue = c;
813
+ }
814
+ continue;
815
+ case this.S.ATTRIB_VALUE_QUOTED:
816
+ if (c !== this.q) {
817
+ if (c === '&') {
818
+ this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
831
819
  } else {
832
- this.state = this.S.ATTRIB;
820
+ this.attribValue += c;
833
821
  }
834
822
  continue;
835
- case this.S.CLOSE_TAG:
836
- if (!this.tagName) {
837
- if (SAX.isWhitespace(c)) {
838
- continue;
839
- } else if (SAX.notMatch(nameStart, c)) {
840
- if (this.script) {
841
- this.script += "</".concat(c);
842
- this.state = this.S.SCRIPT;
843
- } else {
844
- this.strictFail('Invalid tagname in closing tag.');
845
- }
846
- } else {
847
- this.tagName = c;
848
- }
849
- } else if (c === '>') {
850
- this.closeTag();
851
- } else if (SAX.isMatch(nameBody, c)) {
852
- this.tagName += c;
853
- } else if (this.script) {
854
- this.script += "</".concat(this.tagName);
855
- this.tagName = '';
856
- this.state = this.S.SCRIPT;
823
+ }
824
+ this.attrib();
825
+ this.q = '';
826
+ this.state = this.S.ATTRIB_VALUE_CLOSED;
827
+ continue;
828
+ case this.S.ATTRIB_VALUE_CLOSED:
829
+ if (SAX.isWhitespace(c)) {
830
+ this.state = this.S.ATTRIB;
831
+ } else if (c === '>') {
832
+ this.openTag();
833
+ } else if (c === '/') {
834
+ this.state = this.S.OPEN_TAG_SLASH;
835
+ } else if (SAX.isMatch(nameStart, c)) {
836
+ this.strictFail('No whitespace between attributes');
837
+ this.attribName = c;
838
+ this.attribValue = '';
839
+ this.state = this.S.ATTRIB_NAME;
840
+ } else {
841
+ this.strictFail('Invalid attribute name');
842
+ }
843
+ continue;
844
+ case this.S.ATTRIB_VALUE_UNQUOTED:
845
+ if (!SAX.isAttribEnd(c)) {
846
+ if (c === '&') {
847
+ this.state = this.S.ATTRIB_VALUE_ENTITY_U;
857
848
  } else {
858
- if (!SAX.isWhitespace(c)) {
859
- this.strictFail('Invalid tagname in closing tag');
860
- }
861
- this.state = this.S.CLOSE_TAG_SAW_WHITE;
849
+ this.attribValue += c;
862
850
  }
863
851
  continue;
864
- case this.S.CLOSE_TAG_SAW_WHITE:
852
+ }
853
+ this.attrib();
854
+ if (c === '>') {
855
+ this.openTag();
856
+ } else {
857
+ this.state = this.S.ATTRIB;
858
+ }
859
+ continue;
860
+ case this.S.CLOSE_TAG:
861
+ if (!this.tagName) {
865
862
  if (SAX.isWhitespace(c)) {
866
863
  continue;
867
- }
868
- if (c === '>') {
869
- this.closeTag();
864
+ } else if (SAX.notMatch(nameStart, c)) {
865
+ if (this.script) {
866
+ this.script += "</".concat(c);
867
+ this.state = this.S.SCRIPT;
868
+ } else {
869
+ this.strictFail('Invalid tagname in closing tag.');
870
+ }
870
871
  } else {
871
- this.strictFail('Invalid characters in closing tag');
872
- }
873
- continue;
874
- case this.S.TEXT_ENTITY:
875
- case this.S.ATTRIB_VALUE_ENTITY_Q:
876
- case this.S.ATTRIB_VALUE_ENTITY_U:
877
- var returnState = void 0;
878
- var buffer = void 0;
879
- switch (this.state) {
880
- case this.S.TEXT_ENTITY:
881
- returnState = this.S.TEXT;
882
- buffer = 'textNode';
883
- break;
884
- case this.S.ATTRIB_VALUE_ENTITY_Q:
885
- returnState = this.S.ATTRIB_VALUE_QUOTED;
886
- buffer = 'attribValue';
887
- break;
888
- case this.S.ATTRIB_VALUE_ENTITY_U:
889
- returnState = this.S.ATTRIB_VALUE_UNQUOTED;
890
- buffer = 'attribValue';
891
- break;
892
- default:
893
- throw new Error("Unknown state: ".concat(this.state));
872
+ this.tagName = c;
894
873
  }
895
- if (c === ';') {
896
- this[buffer] += this.parseEntity();
897
- this.entity = '';
898
- this.state = returnState;
899
- } else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
900
- this.entity += c;
901
- } else {
902
- this.strictFail('Invalid character in entity name');
903
- this[buffer] += "&".concat(this.entity).concat(c);
904
- this.entity = '';
905
- this.state = returnState;
874
+ } else if (c === '>') {
875
+ this.closeTag();
876
+ } else if (SAX.isMatch(nameBody, c)) {
877
+ this.tagName += c;
878
+ } else if (this.script) {
879
+ this.script += "</".concat(this.tagName);
880
+ this.tagName = '';
881
+ this.state = this.S.SCRIPT;
882
+ } else {
883
+ if (!SAX.isWhitespace(c)) {
884
+ this.strictFail('Invalid tagname in closing tag');
906
885
  }
886
+ this.state = this.S.CLOSE_TAG_SAW_WHITE;
887
+ }
888
+ continue;
889
+ case this.S.CLOSE_TAG_SAW_WHITE:
890
+ if (SAX.isWhitespace(c)) {
907
891
  continue;
908
- default:
909
- throw new Error("Unknown state: ".concat(this.state));
910
- }
911
- }
912
- if (this.position >= this.bufferCheckPosition) {
913
- this.checkBufferLength();
892
+ }
893
+ if (c === '>') {
894
+ this.closeTag();
895
+ } else {
896
+ this.strictFail('Invalid characters in closing tag');
897
+ }
898
+ continue;
899
+ case this.S.TEXT_ENTITY:
900
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
901
+ case this.S.ATTRIB_VALUE_ENTITY_U:
902
+ let returnState;
903
+ let buffer;
904
+ switch (this.state) {
905
+ case this.S.TEXT_ENTITY:
906
+ returnState = this.S.TEXT;
907
+ buffer = 'textNode';
908
+ break;
909
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
910
+ returnState = this.S.ATTRIB_VALUE_QUOTED;
911
+ buffer = 'attribValue';
912
+ break;
913
+ case this.S.ATTRIB_VALUE_ENTITY_U:
914
+ returnState = this.S.ATTRIB_VALUE_UNQUOTED;
915
+ buffer = 'attribValue';
916
+ break;
917
+ default:
918
+ throw new Error("Unknown state: ".concat(this.state));
919
+ }
920
+ if (c === ';') {
921
+ this[buffer] += this.parseEntity();
922
+ this.entity = '';
923
+ this.state = returnState;
924
+ } else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
925
+ this.entity += c;
926
+ } else {
927
+ this.strictFail('Invalid character in entity name');
928
+ this[buffer] += "&".concat(this.entity).concat(c);
929
+ this.entity = '';
930
+ this.state = returnState;
931
+ }
932
+ continue;
933
+ default:
934
+ throw new Error("Unknown state: ".concat(this.state));
914
935
  }
915
- return this;
916
936
  }
917
- }, {
918
- key: "emit",
919
- value: function emit(event, data) {
920
- if (this.events.hasOwnProperty(event)) {
921
- var _eventName = event.replace(/^on/, '');
922
- this.events[event](data, _eventName, this);
923
- }
937
+ if (this.position >= this.bufferCheckPosition) {
938
+ this.checkBufferLength();
924
939
  }
925
- }, {
926
- key: "clearBuffers",
927
- value: function clearBuffers() {
928
- for (var i = 0, l = this.BUFFERS.length; i < l; i++) {
929
- this[this[i]] = '';
930
- }
940
+ return this;
941
+ }
942
+ emit(event, data) {
943
+ if (this.events.hasOwnProperty(event)) {
944
+ const eventName = event.replace(/^on/, '');
945
+ this.events[event](data, eventName, this);
931
946
  }
932
- }, {
933
- key: "flushBuffers",
934
- value: function flushBuffers() {
935
- this.closeText();
936
- if (this.cdata !== '') {
937
- this.emitNode('oncdata', this.cdata);
938
- this.cdata = '';
939
- }
940
- if (this.script !== '') {
941
- this.emitNode('onscript', this.script);
942
- this.script = '';
943
- }
947
+ }
948
+ clearBuffers() {
949
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
950
+ this[this[i]] = '';
944
951
  }
945
- }, {
946
- key: "end",
947
- value: function end() {
948
- if (this.sawRoot && !this.closedRoot) this.strictFail('Unclosed root tag');
949
- if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
950
- this.errorFunction('Unexpected end');
951
- }
952
- this.closeText();
953
- this.c = '';
954
- this.closed = true;
955
- this.emit('onend');
956
- return new SAXParser(this.opt);
952
+ }
953
+ flushBuffers() {
954
+ this.closeText();
955
+ if (this.cdata !== '') {
956
+ this.emitNode('oncdata', this.cdata);
957
+ this.cdata = '';
957
958
  }
958
- }, {
959
- key: "errorFunction",
960
- value: function errorFunction(er) {
961
- this.closeText();
962
- if (this.trackPosition) {
963
- er += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
964
- }
965
- var error = new Error(er);
966
- this.error = error;
967
- this.emit('onerror', error);
968
- return this;
959
+ if (this.script !== '') {
960
+ this.emitNode('onscript', this.script);
961
+ this.script = '';
969
962
  }
970
- }, {
971
- key: "attrib",
972
- value: function attrib() {
973
- if (!this.strict) {
974
- this.attribName = this.attribName[this.looseCase]();
975
- }
976
- if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
977
- this.attribName = this.attribValue = '';
978
- return;
979
- }
980
- if (this.opt.xmlns) {
981
- var qn = SAX.qname(this.attribName, true);
982
- var prefix = qn.prefix;
983
- var local = qn.local;
984
- if (prefix === 'xmlns') {
985
- if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
986
- this.strictFail("xml: prefix must be bound to ".concat(this.XML_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
987
- } else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
988
- this.strictFail("xmlns: prefix must be bound to ".concat(this.XMLNS_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
989
- } else {
990
- var tag = this.tag;
991
- var parent = this.tags[this.tags.length - 1] || this;
992
- if (tag.ns === parent.ns) {
993
- tag.ns = Object.create(parent.ns);
994
- }
995
- tag.ns[local] = this.attribValue;
996
- }
997
- }
998
- this.attribList.push([this.attribName, this.attribValue]);
999
- } else {
1000
- this.tag.attributes[this.attribName] = this.attribValue;
1001
- this.emitNode('onattribute', {
1002
- name: this.attribName,
1003
- value: this.attribValue
1004
- });
1005
- }
1006
- this.attribName = this.attribValue = '';
963
+ }
964
+ end() {
965
+ if (this.sawRoot && !this.closedRoot) this.strictFail('Unclosed root tag');
966
+ if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
967
+ this.errorFunction('Unexpected end');
1007
968
  }
1008
- }, {
1009
- key: "newTag",
1010
- value: function newTag() {
1011
- if (!this.strict) this.tagName = this.tagName[this.looseCase]();
1012
- var parent = this.tags[this.tags.length - 1] || this;
1013
- var tag = this.tag = {
1014
- name: this.tagName,
1015
- attributes: {}
1016
- };
1017
- if (this.opt.xmlns) {
1018
- tag.ns = parent.ns;
1019
- }
1020
- this.attribList.length = 0;
1021
- this.emitNode('onopentagstart', tag);
969
+ this.closeText();
970
+ this.c = '';
971
+ this.closed = true;
972
+ this.emit('onend');
973
+ return new SAXParser(this.opt);
974
+ }
975
+ errorFunction(er) {
976
+ this.closeText();
977
+ if (this.trackPosition) {
978
+ er += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
1022
979
  }
1023
- }, {
1024
- key: "parseEntity",
1025
- value: function parseEntity() {
1026
- var entity = this.entity;
1027
- var entityLC = entity.toLowerCase();
1028
- var num = NaN;
1029
- var numStr = '';
1030
- if (this.ENTITIES[entity]) {
1031
- return this.ENTITIES[entity];
1032
- }
1033
- if (this.ENTITIES[entityLC]) {
1034
- return this.ENTITIES[entityLC];
1035
- }
1036
- entity = entityLC;
1037
- if (entity.charAt(0) === '#') {
1038
- if (entity.charAt(1) === 'x') {
1039
- entity = entity.slice(2);
1040
- num = parseInt(entity, 16);
1041
- numStr = num.toString(16);
980
+ const error = new Error(er);
981
+ this.error = error;
982
+ this.emit('onerror', error);
983
+ return this;
984
+ }
985
+ attrib() {
986
+ if (!this.strict) {
987
+ this.attribName = this.attribName[this.looseCase]();
988
+ }
989
+ if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
990
+ this.attribName = this.attribValue = '';
991
+ return;
992
+ }
993
+ if (this.opt.xmlns) {
994
+ const qn = SAX.qname(this.attribName, true);
995
+ const prefix = qn.prefix;
996
+ const local = qn.local;
997
+ if (prefix === 'xmlns') {
998
+ if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
999
+ this.strictFail("xml: prefix must be bound to ".concat(this.XML_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
1000
+ } else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
1001
+ this.strictFail("xmlns: prefix must be bound to ".concat(this.XMLNS_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
1042
1002
  } else {
1043
- entity = entity.slice(1);
1044
- num = parseInt(entity, 10);
1045
- numStr = num.toString(10);
1003
+ const tag = this.tag;
1004
+ const parent = this.tags[this.tags.length - 1] || this;
1005
+ if (tag.ns === parent.ns) {
1006
+ tag.ns = Object.create(parent.ns);
1007
+ }
1008
+ tag.ns[local] = this.attribValue;
1046
1009
  }
1047
1010
  }
1048
- entity = entity.replace(/^0+/, '');
1049
- if (isNaN(num) || numStr.toLowerCase() !== entity) {
1050
- this.strictFail('Invalid character entity');
1051
- return "&".concat(this.entity, ";");
1052
- }
1053
- return String.fromCodePoint(num);
1011
+ this.attribList.push([this.attribName, this.attribValue]);
1012
+ } else {
1013
+ this.tag.attributes[this.attribName] = this.attribValue;
1014
+ this.emitNode('onattribute', {
1015
+ name: this.attribName,
1016
+ value: this.attribValue
1017
+ });
1054
1018
  }
1055
- }, {
1056
- key: "beginWhiteSpace",
1057
- value: function beginWhiteSpace(c) {
1058
- if (c === '<') {
1059
- this.state = this.S.OPEN_WAKA;
1060
- this.startTagPosition = this.position;
1061
- } else if (!SAX.isWhitespace(c)) {
1062
- this.strictFail('Non-whitespace before first tag.');
1063
- this.textNode = c;
1064
- this.state = this.S.TEXT;
1065
- } else {}
1019
+ this.attribName = this.attribValue = '';
1020
+ }
1021
+ newTag() {
1022
+ if (!this.strict) this.tagName = this.tagName[this.looseCase]();
1023
+ const parent = this.tags[this.tags.length - 1] || this;
1024
+ const tag = this.tag = {
1025
+ name: this.tagName,
1026
+ attributes: {}
1027
+ };
1028
+ if (this.opt.xmlns) {
1029
+ tag.ns = parent.ns;
1066
1030
  }
1067
- }, {
1068
- key: "strictFail",
1069
- value: function strictFail(message) {
1070
- if ((0, _typeof2.default)(this) !== 'object' || !(this instanceof SAXParser)) {
1071
- throw new Error('bad call to strictFail');
1072
- }
1073
- if (this.strict) {
1074
- this.errorFunction(message);
1031
+ this.attribList.length = 0;
1032
+ this.emitNode('onopentagstart', tag);
1033
+ }
1034
+ parseEntity() {
1035
+ let entity = this.entity;
1036
+ const entityLC = entity.toLowerCase();
1037
+ let num = NaN;
1038
+ let numStr = '';
1039
+ if (this.ENTITIES[entity]) {
1040
+ return this.ENTITIES[entity];
1041
+ }
1042
+ if (this.ENTITIES[entityLC]) {
1043
+ return this.ENTITIES[entityLC];
1044
+ }
1045
+ entity = entityLC;
1046
+ if (entity.charAt(0) === '#') {
1047
+ if (entity.charAt(1) === 'x') {
1048
+ entity = entity.slice(2);
1049
+ num = parseInt(entity, 16);
1050
+ numStr = num.toString(16);
1051
+ } else {
1052
+ entity = entity.slice(1);
1053
+ num = parseInt(entity, 10);
1054
+ numStr = num.toString(10);
1075
1055
  }
1076
1056
  }
1077
- }, {
1078
- key: "textApplyOptions",
1079
- value: function textApplyOptions(text) {
1080
- if (this.opt.trim) text = text.trim();
1081
- if (this.opt.normalize) text = text.replace(/\s+/g, ' ');
1082
- return text;
1057
+ entity = entity.replace(/^0+/, '');
1058
+ if (isNaN(num) || numStr.toLowerCase() !== entity) {
1059
+ this.strictFail('Invalid character entity');
1060
+ return "&".concat(this.entity, ";");
1083
1061
  }
1084
- }, {
1085
- key: "emitNode",
1086
- value: function emitNode(nodeType, data) {
1087
- if (this.textNode) this.closeText();
1088
- this.emit(nodeType, data);
1062
+ return String.fromCodePoint(num);
1063
+ }
1064
+ beginWhiteSpace(c) {
1065
+ if (c === '<') {
1066
+ this.state = this.S.OPEN_WAKA;
1067
+ this.startTagPosition = this.position;
1068
+ } else if (!SAX.isWhitespace(c)) {
1069
+ this.strictFail('Non-whitespace before first tag.');
1070
+ this.textNode = c;
1071
+ this.state = this.S.TEXT;
1072
+ } else {}
1073
+ }
1074
+ strictFail(message) {
1075
+ if (typeof this !== 'object' || !(this instanceof SAXParser)) {
1076
+ throw new Error('bad call to strictFail');
1089
1077
  }
1090
- }, {
1091
- key: "closeText",
1092
- value: function closeText() {
1093
- this.textNode = this.textApplyOptions(this.textNode);
1094
- if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
1095
- this.emit('ontext', this.textNode);
1096
- }
1097
- this.textNode = '';
1078
+ if (this.strict) {
1079
+ this.errorFunction(message);
1098
1080
  }
1099
- }, {
1100
- key: "checkBufferLength",
1101
- value: function checkBufferLength() {
1102
- var maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1103
- var maxActual = 0;
1104
- for (var i = 0, l = this.BUFFERS.length; i < l; i++) {
1105
- var _this$this$BUFFERS$i;
1106
- var len = ((_this$this$BUFFERS$i = this[this.BUFFERS[i]]) === null || _this$this$BUFFERS$i === void 0 ? void 0 : _this$this$BUFFERS$i.length) || 0;
1107
- if (len > maxAllowed) {
1108
- switch (this.BUFFERS[i]) {
1109
- case 'textNode':
1110
- this.closeText();
1111
- break;
1112
- case 'cdata':
1113
- this.emitNode('oncdata', this.cdata);
1114
- this.cdata = '';
1115
- break;
1116
- case 'script':
1117
- this.emitNode('onscript', this.script);
1118
- this.script = '';
1119
- break;
1120
- default:
1121
- this.errorFunction("Max buffer length exceeded: ".concat(this.BUFFERS[i]));
1122
- }
1081
+ }
1082
+ textApplyOptions(text) {
1083
+ if (this.opt.trim) text = text.trim();
1084
+ if (this.opt.normalize) text = text.replace(/\s+/g, ' ');
1085
+ return text;
1086
+ }
1087
+ emitNode(nodeType, data) {
1088
+ if (this.textNode) this.closeText();
1089
+ this.emit(nodeType, data);
1090
+ }
1091
+ closeText() {
1092
+ this.textNode = this.textApplyOptions(this.textNode);
1093
+ if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
1094
+ this.emit('ontext', this.textNode);
1095
+ }
1096
+ this.textNode = '';
1097
+ }
1098
+ checkBufferLength() {
1099
+ const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1100
+ let maxActual = 0;
1101
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1102
+ var _this$this$BUFFERS$i;
1103
+ const len = ((_this$this$BUFFERS$i = this[this.BUFFERS[i]]) === null || _this$this$BUFFERS$i === void 0 ? void 0 : _this$this$BUFFERS$i.length) || 0;
1104
+ if (len > maxAllowed) {
1105
+ switch (this.BUFFERS[i]) {
1106
+ case 'textNode':
1107
+ this.closeText();
1108
+ break;
1109
+ case 'cdata':
1110
+ this.emitNode('oncdata', this.cdata);
1111
+ this.cdata = '';
1112
+ break;
1113
+ case 'script':
1114
+ this.emitNode('onscript', this.script);
1115
+ this.script = '';
1116
+ break;
1117
+ default:
1118
+ this.errorFunction("Max buffer length exceeded: ".concat(this.BUFFERS[i]));
1123
1119
  }
1124
- maxActual = Math.max(maxActual, len);
1125
1120
  }
1126
- var m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1127
- this.bufferCheckPosition = m + this.position;
1121
+ maxActual = Math.max(maxActual, len);
1128
1122
  }
1129
- }, {
1130
- key: "openTag",
1131
- value: function openTag(selfClosing) {
1132
- if (this.opt.xmlns) {
1133
- var tag = this.tag;
1134
- var qn = SAX.qname(this.tagName);
1135
- tag.prefix = qn.prefix;
1136
- tag.local = qn.local;
1137
- tag.uri = tag.ns[qn.prefix] || '';
1138
- if (tag.prefix && !tag.uri) {
1139
- this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(this.tagName)));
1140
- tag.uri = qn.prefix;
1141
- }
1142
- var parent = this.tags[this.tags.length - 1] || this;
1143
- if (tag.ns && parent.ns !== tag.ns) {
1144
- var that = this;
1145
- Object.keys(tag.ns).forEach(function (p) {
1146
- that.emitNode('onopennamespace', {
1147
- prefix: p,
1148
- uri: tag.ns[p]
1149
- });
1123
+ const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1124
+ this.bufferCheckPosition = m + this.position;
1125
+ }
1126
+ openTag(selfClosing) {
1127
+ if (this.opt.xmlns) {
1128
+ const tag = this.tag;
1129
+ const qn = SAX.qname(this.tagName);
1130
+ tag.prefix = qn.prefix;
1131
+ tag.local = qn.local;
1132
+ tag.uri = tag.ns[qn.prefix] || '';
1133
+ if (tag.prefix && !tag.uri) {
1134
+ this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(this.tagName)));
1135
+ tag.uri = qn.prefix;
1136
+ }
1137
+ const parent = this.tags[this.tags.length - 1] || this;
1138
+ if (tag.ns && parent.ns !== tag.ns) {
1139
+ const that = this;
1140
+ Object.keys(tag.ns).forEach(p => {
1141
+ that.emitNode('onopennamespace', {
1142
+ prefix: p,
1143
+ uri: tag.ns[p]
1150
1144
  });
1151
- }
1152
- for (var i = 0, l = this.attribList.length; i < l; i++) {
1153
- var nv = this.attribList[i];
1154
- var name = nv[0];
1155
- var value = nv[1];
1156
- var qualName = SAX.qname(name, true);
1157
- var prefix = qualName.prefix;
1158
- var local = qualName.local;
1159
- var uri = prefix === '' ? '' : tag.ns[prefix] || '';
1160
- var a = {
1161
- name: name,
1162
- value: value,
1163
- prefix: prefix,
1164
- local: local,
1165
- uri: uri
1166
- };
1167
- if (prefix && prefix !== 'xmlns' && !uri) {
1168
- this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(prefix)));
1169
- a.uri = prefix;
1170
- }
1171
- this.tag.attributes[name] = a;
1172
- this.emitNode('onattribute', a);
1173
- }
1174
- this.attribList.length = 0;
1145
+ });
1175
1146
  }
1176
- this.tag.isSelfClosing = Boolean(selfClosing);
1177
- this.sawRoot = true;
1178
- this.tags.push(this.tag);
1179
- this.emitNode('onopentag', this.tag);
1180
- if (!selfClosing) {
1181
- if (!this.noscript && this.tagName.toLowerCase() === 'script') {
1182
- this.state = this.S.SCRIPT;
1183
- } else {
1184
- this.state = this.S.TEXT;
1147
+ for (let i = 0, l = this.attribList.length; i < l; i++) {
1148
+ const nv = this.attribList[i];
1149
+ const name = nv[0];
1150
+ const value = nv[1];
1151
+ const qualName = SAX.qname(name, true);
1152
+ const prefix = qualName.prefix;
1153
+ const local = qualName.local;
1154
+ const uri = prefix === '' ? '' : tag.ns[prefix] || '';
1155
+ const a = {
1156
+ name,
1157
+ value,
1158
+ prefix,
1159
+ local,
1160
+ uri
1161
+ };
1162
+ if (prefix && prefix !== 'xmlns' && !uri) {
1163
+ this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(prefix)));
1164
+ a.uri = prefix;
1185
1165
  }
1186
- this.tag = null;
1187
- this.tagName = '';
1166
+ this.tag.attributes[name] = a;
1167
+ this.emitNode('onattribute', a);
1188
1168
  }
1189
- this.attribName = this.attribValue = '';
1190
1169
  this.attribList.length = 0;
1191
1170
  }
1192
- }, {
1193
- key: "closeTag",
1194
- value: function closeTag() {
1195
- var _this = this;
1196
- if (!this.tagName) {
1197
- this.strictFail('Weird empty close tag.');
1198
- this.textNode += '</>';
1199
- this.state = this.S.TEXT;
1200
- return;
1201
- }
1202
- if (this.script) {
1203
- if (this.tagName !== 'script') {
1204
- this.script += "</".concat(this.tagName, ">");
1205
- this.tagName = '';
1206
- this.state = this.S.SCRIPT;
1207
- return;
1208
- }
1209
- this.emitNode('onscript', this.script);
1210
- this.script = '';
1211
- }
1212
- var t = this.tags.length;
1213
- var tagName = this.tagName;
1214
- if (!this.strict) {
1215
- tagName = tagName[this.looseCase]();
1216
- }
1217
- while (t--) {
1218
- var close = this.tags[t];
1219
- if (close.name !== tagName) {
1220
- this.strictFail('Unexpected close tag');
1221
- } else {
1222
- break;
1223
- }
1224
- }
1225
- if (t < 0) {
1226
- this.strictFail("Unmatched closing tag: ".concat(this.tagName));
1227
- this.textNode += "</".concat(this.tagName, ">");
1171
+ this.tag.isSelfClosing = Boolean(selfClosing);
1172
+ this.sawRoot = true;
1173
+ this.tags.push(this.tag);
1174
+ this.emitNode('onopentag', this.tag);
1175
+ if (!selfClosing) {
1176
+ if (!this.noscript && this.tagName.toLowerCase() === 'script') {
1177
+ this.state = this.S.SCRIPT;
1178
+ } else {
1228
1179
  this.state = this.S.TEXT;
1229
- return;
1230
- }
1231
- this.tagName = tagName;
1232
- var s = this.tags.length;
1233
- var _loop = function _loop() {
1234
- var tag = _this.tag = _this.tags.pop();
1235
- _this.tagName = _this.tag.name;
1236
- _this.emitNode('onclosetag', _this.tagName);
1237
- var x = {};
1238
- for (var i in tag.ns) {
1239
- if (tag.ns.hasOwnProperty(i)) {
1240
- x[i] = tag.ns[i];
1241
- }
1242
- }
1243
- var parent = _this.tags[_this.tags.length - 1] || _this;
1244
- if (_this.opt.xmlns && tag.ns !== parent.ns) {
1245
- var that = _this;
1246
- Object.keys(tag.ns).forEach(function (p) {
1247
- var n = tag.ns[p];
1248
- that.emitNode('onclosenamespace', {
1249
- prefix: p,
1250
- uri: n
1251
- });
1252
- });
1253
- }
1254
- };
1255
- while (s-- > t) {
1256
- _loop();
1257
1180
  }
1258
- if (t === 0) this.closedRoot = true;
1259
- this.tagName = this.attribValue = this.attribName = '';
1260
- this.attribList.length = 0;
1181
+ this.tag = null;
1182
+ this.tagName = '';
1183
+ }
1184
+ this.attribName = this.attribValue = '';
1185
+ this.attribList.length = 0;
1186
+ }
1187
+ closeTag() {
1188
+ if (!this.tagName) {
1189
+ this.strictFail('Weird empty close tag.');
1190
+ this.textNode += '</>';
1261
1191
  this.state = this.S.TEXT;
1192
+ return;
1262
1193
  }
1263
- }], [{
1264
- key: "charAt",
1265
- value: function charAt(chunk, i) {
1266
- var result = '';
1267
- if (i < chunk.length) {
1268
- result = chunk.charAt(i);
1194
+ if (this.script) {
1195
+ if (this.tagName !== 'script') {
1196
+ this.script += "</".concat(this.tagName, ">");
1197
+ this.tagName = '';
1198
+ this.state = this.S.SCRIPT;
1199
+ return;
1269
1200
  }
1270
- return result;
1271
- }
1272
- }, {
1273
- key: "isWhitespace",
1274
- value: function isWhitespace(c) {
1275
- return c === ' ' || c === '\n' || c === '\r' || c === '\t';
1201
+ this.emitNode('onscript', this.script);
1202
+ this.script = '';
1276
1203
  }
1277
- }, {
1278
- key: "isQuote",
1279
- value: function isQuote(c) {
1280
- return c === '"' || c === "'";
1204
+ let t = this.tags.length;
1205
+ let tagName = this.tagName;
1206
+ if (!this.strict) {
1207
+ tagName = tagName[this.looseCase]();
1281
1208
  }
1282
- }, {
1283
- key: "isAttribEnd",
1284
- value: function isAttribEnd(c) {
1285
- return c === '>' || SAX.isWhitespace(c);
1286
- }
1287
- }, {
1288
- key: "isMatch",
1289
- value: function isMatch(regex, c) {
1290
- return regex.test(c);
1291
- }
1292
- }, {
1293
- key: "notMatch",
1294
- value: function notMatch(regex, c) {
1295
- return !SAX.isMatch(regex, c);
1296
- }
1297
- }, {
1298
- key: "qname",
1299
- value: function qname(name, attribute) {
1300
- var i = name.indexOf(':');
1301
- var qualName = i < 0 ? ['', name] : name.split(':');
1302
- var prefix = qualName[0];
1303
- var local = qualName[1];
1304
- if (attribute && name === 'xmlns') {
1305
- prefix = 'xmlns';
1306
- local = '';
1209
+ while (t--) {
1210
+ const close = this.tags[t];
1211
+ if (close.name !== tagName) {
1212
+ this.strictFail('Unexpected close tag');
1213
+ } else {
1214
+ break;
1307
1215
  }
1308
- return {
1309
- prefix: prefix,
1310
- local: local
1311
- };
1312
1216
  }
1313
- }]);
1314
- return SAX;
1315
- }();
1316
- var SAXParser = function (_SAX) {
1317
- (0, _inherits2.default)(SAXParser, _SAX);
1318
- var _super = _createSuper(SAXParser);
1319
- function SAXParser(opt) {
1320
- var _this2;
1321
- (0, _classCallCheck2.default)(this, SAXParser);
1322
- _this2 = _super.call(this);
1323
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "opt", DEFAULT_SAX_PARSER_OPTIONS);
1324
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "events", DEFAULT_SAX_EVENTS);
1325
- _this2.clearBuffers();
1326
- _this2.opt = opt = _objectSpread(_objectSpread({}, _this2.opt), opt);
1327
- _this2.events = _objectSpread(_objectSpread({}, _this2.events), opt);
1328
- _this2.q = _this2.c = '';
1329
- _this2.opt.lowercase = _this2.opt.lowercase || _this2.opt.lowercasetags;
1330
- _this2.bufferCheckPosition = _this2.opt.MAX_BUFFER_LENGTH;
1331
- _this2.looseCase = _this2.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
1332
- _this2.tags = [];
1333
- _this2.closed = _this2.closedRoot = _this2.sawRoot = false;
1334
- _this2.tag = _this2.error = null;
1335
- _this2.strict = Boolean(_this2.opt.strict);
1336
- _this2.noscript = Boolean(_this2.opt.strict || _this2.opt.noscript);
1337
- _this2.state = _this2.S.BEGIN;
1338
- _this2.strictEntities = _this2.opt.strictEntities;
1339
- _this2.ENTITIES = _this2.strictEntities ? Object.create(_this2.XML_ENTITIES) : Object.create(_this2.ENTITIES);
1340
- _this2.attribList = [];
1341
- if (_this2.opt.xmlns) {
1342
- _this2.ns = Object.create(_this2.rootNS);
1217
+ if (t < 0) {
1218
+ this.strictFail("Unmatched closing tag: ".concat(this.tagName));
1219
+ this.textNode += "</".concat(this.tagName, ">");
1220
+ this.state = this.S.TEXT;
1221
+ return;
1343
1222
  }
1344
- _this2.trackPosition = _this2.opt.position !== false;
1345
- if (_this2.trackPosition) {
1346
- _this2.position = _this2.line = _this2.column = 0;
1223
+ this.tagName = tagName;
1224
+ let s = this.tags.length;
1225
+ while (s-- > t) {
1226
+ const tag = this.tag = this.tags.pop();
1227
+ this.tagName = this.tag.name;
1228
+ this.emitNode('onclosetag', this.tagName);
1229
+ const x = {};
1230
+ for (const i in tag.ns) {
1231
+ if (tag.ns.hasOwnProperty(i)) {
1232
+ x[i] = tag.ns[i];
1233
+ }
1234
+ }
1235
+ const parent = this.tags[this.tags.length - 1] || this;
1236
+ if (this.opt.xmlns && tag.ns !== parent.ns) {
1237
+ const that = this;
1238
+ Object.keys(tag.ns).forEach(p => {
1239
+ const n = tag.ns[p];
1240
+ that.emitNode('onclosenamespace', {
1241
+ prefix: p,
1242
+ uri: n
1243
+ });
1244
+ });
1245
+ }
1347
1246
  }
1348
- _this2.emit('onready');
1349
- return _this2;
1247
+ if (t === 0) this.closedRoot = true;
1248
+ this.tagName = this.attribValue = this.attribName = '';
1249
+ this.attribList.length = 0;
1250
+ this.state = this.S.TEXT;
1350
1251
  }
1351
- (0, _createClass2.default)(SAXParser, [{
1352
- key: "resume",
1353
- value: function resume() {
1354
- this.error = null;
1355
- return this;
1252
+ }
1253
+ class SAXParser extends SAX {
1254
+ constructor(opt) {
1255
+ super();
1256
+ (0, _defineProperty2.default)(this, "opt", DEFAULT_SAX_PARSER_OPTIONS);
1257
+ (0, _defineProperty2.default)(this, "events", DEFAULT_SAX_EVENTS);
1258
+ this.clearBuffers();
1259
+ this.opt = opt = {
1260
+ ...this.opt,
1261
+ ...opt
1262
+ };
1263
+ this.events = {
1264
+ ...this.events,
1265
+ ...opt
1266
+ };
1267
+ this.q = this.c = '';
1268
+ this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
1269
+ this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
1270
+ this.looseCase = this.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
1271
+ this.tags = [];
1272
+ this.closed = this.closedRoot = this.sawRoot = false;
1273
+ this.tag = this.error = null;
1274
+ this.strict = Boolean(this.opt.strict);
1275
+ this.noscript = Boolean(this.opt.strict || this.opt.noscript);
1276
+ this.state = this.S.BEGIN;
1277
+ this.strictEntities = this.opt.strictEntities;
1278
+ this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
1279
+ this.attribList = [];
1280
+ if (this.opt.xmlns) {
1281
+ this.ns = Object.create(this.rootNS);
1356
1282
  }
1357
- }, {
1358
- key: "close",
1359
- value: function close() {
1360
- return this.write(null);
1283
+ this.trackPosition = this.opt.position !== false;
1284
+ if (this.trackPosition) {
1285
+ this.position = this.line = this.column = 0;
1361
1286
  }
1362
- }, {
1363
- key: "flush",
1364
- value: function flush() {
1365
- this.flushBuffers();
1366
- }
1367
- }]);
1368
- return SAXParser;
1369
- }(SAX);
1287
+ this.emit('onready');
1288
+ }
1289
+ resume() {
1290
+ this.error = null;
1291
+ return this;
1292
+ }
1293
+ close() {
1294
+ return this.write(null);
1295
+ }
1296
+ flush() {
1297
+ this.flushBuffers();
1298
+ }
1299
+ }
1370
1300
  exports.SAXParser = SAXParser;
1371
1301
  (0, _defineProperty2.default)(SAXParser, "ENTITIES", ENTITIES);
1372
1302
  //# sourceMappingURL=sax.js.map