From 8ab4f29d0a323ed57a43df854868a4a4070cbbde Mon Sep 17 00:00:00 2001 From: Lukas Bach Date: Tue, 25 Apr 2023 07:43:43 +0000 Subject: [PATCH] #728:@patch: use proxy for attributes getter. --- packages/happy-dom/src/nodes/element/Element.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/happy-dom/src/nodes/element/Element.ts b/packages/happy-dom/src/nodes/element/Element.ts index 8a34c7eae..6b9e57038 100644 --- a/packages/happy-dom/src/nodes/element/Element.ts +++ b/packages/happy-dom/src/nodes/element/Element.ts @@ -255,7 +255,15 @@ export default class Element extends Node implements IElement { * @returns Attributes. */ public get attributes(): INamedNodeMap { - return Object.assign(new NamedNodeMap(this), Object.values(this._attributes), this._attributes); + const nodeMap = new NamedNodeMap(this); + return new Proxy(nodeMap, { + get: (target, name) => { + return target[name] || ( + typeof name === "string" || typeof name === "number" + ? this._attributes[name] : undefined + ); + } + }) } /**