Skip to content

Commit

Permalink
capricorn86#728@patch: use proxy for attributes getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Apr 25, 2023
1 parent 1a827e3 commit 0f56706
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/happy-dom/src/nodes/element/Element.ts
Expand Up @@ -255,7 +255,17 @@ 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 0f56706

Please sign in to comment.