From 8d0adf611bccfe8df20e79ca9e18b0ddcdc3f89d Mon Sep 17 00:00:00 2001 From: Fyodor Soikin Date: Thu, 6 Oct 2022 11:27:11 -0400 Subject: [PATCH] Review feedback Co-authored-by: David Ortner --- .../src/nodes/html-button-element/HTMLButtonElement.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/happy-dom/src/nodes/html-button-element/HTMLButtonElement.ts b/packages/happy-dom/src/nodes/html-button-element/HTMLButtonElement.ts index ebf727de..74afecf7 100644 --- a/packages/happy-dom/src/nodes/html-button-element/HTMLButtonElement.ts +++ b/packages/happy-dom/src/nodes/html-button-element/HTMLButtonElement.ts @@ -1,7 +1,11 @@ import HTMLElement from '../html-element/HTMLElement'; import IHTMLButtonElement from './IHTMLButtonElement'; +const BUTTON_TYPES = ['submit', 'reset', 'button', 'menu']; + /** + +We can improve performance a bit if we make the types as a constant. * HTML Button Element. * * Reference: @@ -54,7 +58,7 @@ export default class HTMLButtonElement extends HTMLElement implements IHTMLButto * @returns Type */ public get type(): string { - return this.sanitizeType(this.getAttributeNS(null, 'type')); + return this._sanitizeType(this.getAttributeNS(null, 'type')); } /** @@ -70,10 +74,10 @@ export default class HTMLButtonElement extends HTMLElement implements IHTMLButto * * @param type */ - private sanitizeType(type: string): string { + protected _sanitizeType(type: string): string { type = (type && type.toLowerCase()) || 'submit'; - if (!['submit', 'reset', 'button', 'menu'].includes(type)) { + if (! BUTTON_TYPES.includes(type)) { type = 'submit'; }