From f064bcc84531625c1fa32cd73e1b30cf69deb887 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Thu, 22 Jan 2026 17:42:01 +0100 Subject: [PATCH] maint(core mockup-parser): Remove jQuery and outdated $.nodeName usage. --- src/core/mockup-parser.js | 10 +++++---- src/core/mockup-parser.test.js | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/core/mockup-parser.test.js diff --git a/src/core/mockup-parser.js b/src/core/mockup-parser.js index 65de6478a..7aeda3e99 100644 --- a/src/core/mockup-parser.js +++ b/src/core/mockup-parser.js @@ -1,4 +1,3 @@ -import $ from "jquery"; var parser = { getOptions($el, patternName, options) { @@ -12,7 +11,7 @@ var parser = { */ options = options || {}; // get options from parent element first, stop if element tag name is 'body' - if ($el.length !== 0 && !$.nodeName($el[0], "body")) { + if ($el.length !== 0 && $el[0].nodeName !== "BODY") { options = this.getOptions($el.parent(), patternName, options); } // collect all options from element @@ -23,7 +22,7 @@ var parser = { // parse options if string if (typeof elOptions === "string") { const tmpOptions = {}; - $.each(elOptions.split(";"), function (i, item) { + elOptions.split(";").forEach(item => { item = item.split(":"); item.reverse(); let key = item.pop(); @@ -37,7 +36,10 @@ var parser = { } } } - return $.extend(true, {}, options, elOptions); + return { + ...options, + ...elOptions, + } }, }; diff --git a/src/core/mockup-parser.test.js b/src/core/mockup-parser.test.js new file mode 100644 index 000000000..e6874af24 --- /dev/null +++ b/src/core/mockup-parser.test.js @@ -0,0 +1,40 @@ +import $ from "jquery"; +import mockupParser from "./mockup-parser"; + +describe("The mockup-parser", function () { + it("parses the data attribute of a single node", function () { + const $el = $(` + + mockup parser test + `); + const options = mockupParser.getOptions($el, "testpattern"); + expect(options.option1).toBe("value1"); + expect(options.option2).toBe("value2"); + }); + it("parses the data attribute of nested nodes", function () { + const $el = $(` +
+ + nested mockup parser test + +
`); + const options = mockupParser.getOptions($el, "testpattern"); + expect(options.parentOption1).toBe("value1"); + expect(options.parentOption2).toBe("value2"); + expect(options.option1).toBe(undefined); + expect(options.option2).toBe(undefined); + }); + it("parses the data attribute of a single node and preserves injected options", function () { + const $el = $(` + + mockup parser test + + `); + const options = mockupParser.getOptions($el, "testpattern", { + injectedOption: "injectedValue", + }); + expect(options.option1).toBe("value1"); + expect(options.option2).toBe("value2"); + expect(options.injectedOption).toBe("injectedValue"); + }); +});