From 5bbe537fc5145b665e4ed5ccca8962aa55bee075 Mon Sep 17 00:00:00 2001 From: Wesley Luyten Date: Sat, 25 Mar 2023 20:18:34 -0500 Subject: [PATCH] fix: optimize iife bundle output https://github.com/evanw/esbuild/issues/2416 --- package.json | 2 +- src/option.js | 8 +++++--- src/selectmenu.js | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 9ab2f3f..5a937b9 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "lint": "npx eslint src/*.js", "test": "wet run", "dev": "wet serve --redirect :examples/ & npm run build -- --watch", - "build": "esbuild src/polyfill.js --global-name=SelectMenuPolyfill --outdir=dist --bundle --minify-syntax --tree-shaking=true", + "build": "esbuild src/polyfill.js --outdir=dist --bundle --minify-syntax --tree-shaking=true", "prepublishOnly": "npm run build" }, "devDependencies": { diff --git a/src/option.js b/src/option.js index 77e5db9..0923ad0 100644 --- a/src/option.js +++ b/src/option.js @@ -35,9 +35,6 @@ template.innerHTML = /* html */` `; class OptionElement extends globalThis.HTMLElement { - static formAssociated = true; - static observedAttributes = ['disabled', 'selected']; - /** @see https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-dirtiness */ #dirty = false; #internals; @@ -146,6 +143,11 @@ class OptionElement extends globalThis.HTMLElement { } } +// Define as an external static so esbuild doesn't add unnecessary transforms +// see https://github.com/evanw/esbuild/issues/2416 +OptionElement.formAssociated = true; +OptionElement.observedAttributes = ['disabled', 'selected']; + if (!globalThis.customElements.get('x-option')) { globalThis.customElements.define('x-option', OptionElement); } diff --git a/src/selectmenu.js b/src/selectmenu.js index 45e887d..98caac7 100644 --- a/src/selectmenu.js +++ b/src/selectmenu.js @@ -127,9 +127,6 @@ template.innerHTML = /* html */` `; class SelectMenuElement extends globalThis.HTMLElement { - static formAssociated = true; - static observedAttributes = ['disabled', 'required', 'multiple']; - #internals; constructor() { @@ -464,6 +461,11 @@ class SelectMenuElement extends globalThis.HTMLElement { } } +// Define as an external static so esbuild doesn't add unnecessary transforms +// see https://github.com/evanw/esbuild/issues/2416 +SelectMenuElement.formAssociated = true; +SelectMenuElement.observedAttributes = ['disabled', 'required', 'multiple']; + function reposition(reference, popover) { let { style } = getCSSRule(reference.shadowRoot,