From 7802d4de8e31126f398b42e7d99a3e5fd95434a4 Mon Sep 17 00:00:00 2001 From: Fathony L Date: Wed, 23 Oct 2024 19:35:14 +0700 Subject: [PATCH] split the eror-raising part of constructor into separate method. --- src/lib/Parser.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/Parser.ts b/src/lib/Parser.ts index 05e77ac..20946a1 100644 --- a/src/lib/Parser.ts +++ b/src/lib/Parser.ts @@ -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; @@ -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()) { @@ -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'); } }