From 0878a6cc395e79f255064bf9d4b572519029f8fb Mon Sep 17 00:00:00 2001 From: Louis-Dominique Dubeau Date: Mon, 9 Jul 2018 15:15:44 -0400 Subject: [PATCH] refactor: drop the ``parser`` function, rename SAXParser BREAKING CHANGE: The ``parser`` function is removed. Just create a new instance with ``new``. ``SAXParser`` is now ``SaxesParser.`` So ``new require("saxes").SaxesParser(...)``. --- README.md | 2 +- examples/example.js | 2 +- lib/saxes.js | 7 ++----- test/conformance.js | 2 +- test/index.js | 2 +- test/not-string.js | 2 +- test/parser-position.js | 2 +- test/xml-declaration.js | 2 +- 8 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 210f3903..5939a329 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ guest. ```javascript var saxes = require("./lib/saxes"), - parser = saxes.parser(); + parser = new saxes.SaxesParser(); parser.onerror = function (e) { // an error happened. diff --git a/examples/example.js b/examples/example.js index 54452d28..745c52c6 100644 --- a/examples/example.js +++ b/examples/example.js @@ -6,7 +6,7 @@ const fs = require("fs"); const path = require("path"); const saxes = require("../lib/saxes"); -const parser = saxes.parser(); +const parser = new saxes.SaxesParser(); function inspector(ev) { return function handler(data) { diff --git a/lib/saxes.js b/lib/saxes.js index 0cac4b7e..4b9f56d8 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -134,7 +134,7 @@ function isQuote(c) { return c === "\"" || c === "'"; } -class SAXParser { +class SaxesParser { /** * @param {Object} opt The parser options. */ @@ -1684,7 +1684,4 @@ ${JSON.stringify(this.tagName)}.`); } } -exports.parser = function parser(opt) { - return new SAXParser(opt); -}; -exports.SAXParser = SAXParser; +exports.SaxesParser = SaxesParser; diff --git a/test/conformance.js b/test/conformance.js index 3a2ffde3..12b2830e 100644 --- a/test/conformance.js +++ b/test/conformance.js @@ -139,7 +139,7 @@ class SaxesDriver extends BaseDriver { return this.resourceLoader.loadFile(resolvedURI) .then((source) => { const errors = []; - const parser = saxes.parser({ + const parser = new saxes.SaxesParser({ xmlns: !test.forbidsNamespaces, }); parser.onerror = (err) => { diff --git a/test/index.js b/test/index.js index e6b4e3de..d4277c2a 100644 --- a/test/index.js +++ b/test/index.js @@ -9,7 +9,7 @@ const saxes = require("../lib/saxes"); exports.test = function test(options) { const { xml, name, expect: expected, fn } = options; it(name, () => { - const parser = saxes.parser(options.opt); + const parser = new saxes.SaxesParser(options.opt); let expectedIx = 0; for (const ev of saxes.EVENTS) { // eslint-disable-next-line no-loop-func diff --git a/test/not-string.js b/test/not-string.js index 3ce18b94..855db1dd 100644 --- a/test/not-string.js +++ b/test/not-string.js @@ -4,7 +4,7 @@ const { expect } = require("chai"); const saxes = require("../"); it("parses a buffer", () => { - const parser = saxes.parser(); + const parser = new saxes.SaxesParser(); let seen = false; parser.onopentag = (node) => { expect(node).to.deep.equal({ name: "x", attributes: {}, isSelfClosing: false }); diff --git a/test/parser-position.js b/test/parser-position.js index 4ec37c54..9781c004 100644 --- a/test/parser-position.js +++ b/test/parser-position.js @@ -6,7 +6,7 @@ const { test } = require("."); function testPosition(name, chunks, expectedEvents) { it(name, () => { - const parser = saxes.parser(); + const parser = new saxes.SaxesParser(); for (const expectation of expectedEvents) { parser[`on${expectation[0]}`] = function handler() { // eslint-disable-next-line guard-for-in diff --git a/test/xml-declaration.js b/test/xml-declaration.js index 193858c7..3191ca75 100644 --- a/test/xml-declaration.js +++ b/test/xml-declaration.js @@ -157,7 +157,7 @@ describe("xml declaration", () => { }); it("well-formed", () => { - const parser = saxes.parser(); + const parser = new saxes.SaxesParser(); let seen = false; parser.onopentagstart = () => { expect(parser.xmlDecl).to.deep.equal({