Skip to content

Commit

Permalink
fix: use proxy for attributes getter (capricorn86#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Apr 25, 2023
1 parent 1a827e3 commit 25d3742
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/happy-dom/src/nodes/element/Element.ts
Expand Up @@ -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
);
}
})
}

/**
Expand Down

0 comments on commit 25d3742

Please sign in to comment.