Skip to content

Commit

Permalink
split the eror-raising part of constructor into separate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
fathonysl committed Oct 23, 2024
1 parent 202a9ce commit 7802d4d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Parser {
*/
constructor(xml: string, options: ParserOptions = {}) {
let doc = this.document = new XmlDocument();
let scanner = this.scanner = new StringScanner(xml);
this.scanner = new StringScanner(xml);

this.currentNode = doc;
this.options = options;
Expand All @@ -40,8 +40,12 @@ export class Parser {
doc.start = 0;
doc.end = xml.length;
}

this.startParse();
}

scanner.consumeStringFast('\uFEFF'); // byte order mark
startParse() {
this.scanner.consumeStringFast('\uFEFF'); // byte order mark
this.consumeProlog();

if (!this.consumeElement()) {
Expand All @@ -50,7 +54,7 @@ export class Parser {

while (this.consumeMisc()) {} // eslint-disable-line no-empty

if (!scanner.isEnd) {
if (!this.scanner.isEnd) {
throw this.error('Extra content at the end of the document');
}
}
Expand Down

0 comments on commit 7802d4d

Please sign in to comment.