Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkSupport made static #5336

Open
wants to merge 1 commit into
base: public-js-api
Choose a base branch
from

Conversation

patrickpatrickpatrick
Copy link
Contributor

@patrickpatrickpatrick patrickpatrickpatrick commented Sep 19, 2024

What

Specify that checkSupport of GOVUKFrontendComponent is static instead of private.

Why

Change in approach to how we allow people to run their own function to check if a component is supported. This change means now components that extend GOVUKFrontendComponent can overload checkSupport (as can be seen in the tests).

Fixes #5225 (comment)

@patrickpatrickpatrick patrickpatrickpatrick changed the base branch from main to public-js-api September 19, 2024 15:27
Copy link

github-actions bot commented Sep 19, 2024

📋 Stats

File sizes

File Size
dist/govuk-frontend-development.min.css 118.52 KiB
dist/govuk-frontend-development.min.js 44.62 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 94.25 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 88.51 KiB
packages/govuk-frontend/dist/govuk/all.mjs 1.1 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 1.36 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 118.5 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 44.61 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.55 KiB
packages/govuk-frontend/dist/govuk/init.mjs 6.9 KiB

Modules

File Size (bundled) Size (minified)
all.mjs 84.64 KiB 42.39 KiB
accordion.mjs 25.08 KiB 12.96 KiB
button.mjs 7.55 KiB 3.26 KiB
character-count.mjs 23.97 KiB 10.49 KiB
checkboxes.mjs 7.41 KiB 3.4 KiB
error-summary.mjs 9.46 KiB 4.02 KiB
exit-this-page.mjs 18.68 KiB 9.83 KiB
header.mjs 6.04 KiB 3.17 KiB
notification-banner.mjs 7.83 KiB 3.19 KiB
password-input.mjs 16.71 KiB 7.82 KiB
radios.mjs 6.4 KiB 2.95 KiB
service-navigation.mjs 6.02 KiB 3.26 KiB
skip-link.mjs 5.96 KiB 2.75 KiB
tabs.mjs 11.62 KiB 6.63 KiB

View stats and visualisations on the review app


Action run for b9051c2

Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little misunderstanding on the staticness of the checkSupport method, sorry 😔 I've clarified in the comments 😊

Comment on lines 52 to 56
* @protected
* @static
* @throws {SupportError} when the components are not supported
*/
checkSupport() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue This only documents the method as static, but the method itself is not static from a JavaScript point of view (it's interesting that TypeScript does not pick up on that, actually, that'll be something to remember).

Suggested change
* @protected
* @static
* @throws {SupportError} when the components are not supported
*/
checkSupport() {
* @protected
* @throws {SupportError} when the components are not supported
*/
static checkSupport() {

Having the method static will help avoid overloading the console with errors when a component is repeated multiple times on the page (like the Copy button on the Design System page), letting createAll do a single initial check before looping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if we want to be able to call it from createAll, it needs to be not @protected, completely didn't think of that 😅

Suggested change
* @protected
* @static
* @throws {SupportError} when the components are not supported
*/
checkSupport() {
* @throws {SupportError} when the components are not supported
*/
static checkSupport() {

const result = createAll(MockComponentWithCheckSupport)
expect(checkSupportMock).toHaveBeenCalled()
expect(result).toStrictEqual([])
expect(global.console.log).toHaveBeenCalledWith(expect.any(Error))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion Is there a way we can check this is the error thrown by the support mock (for example, comparing the text of the error)?

Comment on lines +230 to 234
class MockComponent extends GOVUKFrontendComponent {
constructor(...args) {
super(...args)
this.args = args
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot to update this here 🙌🏻

Comment on lines 304 to 308
class MockComponentWithCheckSupport extends MockComponent {
checkSupport() {
checkSupportMock()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion Possibly a long shot, but does jest.spyOn let us avoid creating one class per test with the method being static?

const checkSupportMock = jest.spyOn(MockComponent, 'checkSupport')

@patrickpatrickpatrick patrickpatrickpatrick changed the title checkSupport made static and protected checkSupport made static Sep 20, 2024
Copy link

github-actions bot commented Sep 20, 2024

JavaScript changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
index 19e286ee0..af244b5a2 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
@@ -124,10 +124,11 @@ class InitError extends GOVUKFrontendError {
 }
 class GOVUKFrontendComponent {
     constructor(e) {
-        this.checkSupport(), this.checkInitialised(e);
-        const t = this.constructor.moduleName;
-        if ("string" != typeof t) throw new InitError(t);
-        t && (null == e || e.setAttribute(`data-${t}-init`, ""))
+        const t = this.constructor;
+        t.checkSupport(), this.checkInitialised(e);
+        const n = t.moduleName;
+        if ("string" != typeof n) throw new InitError(n);
+        n && (null == e || e.setAttribute(`data-${n}-init`, ""))
     }
     checkInitialised(e) {
         const t = this.constructor.moduleName;
@@ -135,10 +136,10 @@ class GOVUKFrontendComponent {
                 return e instanceof HTMLElement && e.hasAttribute(`data-${t}-init`)
             }(e, t)) throw new InitError(t)
     }
-    checkSupport() {
+    static checkSupport() {
         if (!this.isSupported()) throw new SupportError
     }
-    isSupported() {
+    static isSupported() {
         return isSupported()
     }
 }

Action run for b9051c2

Copy link

github-actions bot commented Sep 20, 2024

Other changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.js b/packages/govuk-frontend/dist/govuk/all.bundle.js
index 1c67edb22..fcd657aef 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.js
@@ -250,9 +250,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -265,7 +266,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -277,7 +278,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.mjs b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
index f8c1c3ed1..00755f4f3 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
@@ -244,9 +244,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -259,7 +260,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -271,7 +272,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js
index 0b96e7125..6aef2961c 100644
--- a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js
@@ -184,9 +184,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -199,7 +200,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -211,7 +212,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs
index 4c4530f84..37122ee11 100644
--- a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs
@@ -178,9 +178,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -193,7 +194,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -205,7 +206,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
index 07424eb65..d0e654868 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
@@ -184,9 +184,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -199,7 +200,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -211,7 +212,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
index d9412f41d..e2db63442 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
@@ -178,9 +178,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -193,7 +194,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -205,7 +206,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js
index 76ce4eea5..2140cebbe 100644
--- a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js
@@ -215,9 +215,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -230,7 +231,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -242,7 +243,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
index 34ee63460..bb397778c 100644
--- a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
@@ -209,9 +209,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -224,7 +225,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -236,7 +237,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js
index b77f9b743..e0bf50623 100644
--- a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js
@@ -95,9 +95,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -110,7 +111,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -122,7 +123,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs
index e3c1fd925..94dfdfd13 100644
--- a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs
@@ -89,9 +89,10 @@ function isSupported($scope = document.body) {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -104,7 +105,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -116,7 +117,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js
index 99c71b5ff..60d384bbd 100644
--- a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js
@@ -214,9 +214,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -229,7 +230,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -241,7 +242,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs
index 8600154f1..f9ad9135c 100644
--- a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs
@@ -208,9 +208,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -223,7 +224,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -235,7 +236,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js
index fb4533397..a5678a3aa 100644
--- a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js
@@ -184,9 +184,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -199,7 +200,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -211,7 +212,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs
index 714daefad..b4ec7e15a 100644
--- a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs
@@ -178,9 +178,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -193,7 +194,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -205,7 +206,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js
index 5bbcbe1be..acb129345 100644
--- a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js
@@ -103,9 +103,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -118,7 +119,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -130,7 +131,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs
index 224c11925..045334b44 100644
--- a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs
@@ -97,9 +97,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -112,7 +113,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -124,7 +125,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js
index 6a44dd11c..747facf0d 100644
--- a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js
@@ -208,9 +208,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -223,7 +224,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -235,7 +236,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs
index 7b0c12d39..7791aaf42 100644
--- a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs
@@ -202,9 +202,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -217,7 +218,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -229,7 +230,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js
index 38adb9a52..b91746274 100644
--- a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js
@@ -189,9 +189,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -204,7 +205,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -216,7 +217,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs
index a0465d235..d879b7d0d 100644
--- a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs
@@ -183,9 +183,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -198,7 +199,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -210,7 +211,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js
index 7444eea07..104642f67 100644
--- a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js
@@ -95,9 +95,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -110,7 +111,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -122,7 +123,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs
index 1fd810d35..87f322300 100644
--- a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs
@@ -89,9 +89,10 @@ function isSupported($scope = document.body) {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -104,7 +105,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -116,7 +117,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js
index 09499031c..6dc2c1114 100644
--- a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js
@@ -103,9 +103,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -118,7 +119,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -130,7 +131,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs
index c944b0639..8b59ea714 100644
--- a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs
@@ -97,9 +97,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -112,7 +113,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -124,7 +125,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js
index 29e6e9727..01160b0a4 100644
--- a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js
@@ -125,9 +125,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -140,7 +141,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -152,7 +153,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs
index b5b902021..c3164c7bb 100644
--- a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs
@@ -119,9 +119,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -134,7 +135,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -146,7 +147,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js
index 3400748c8..fd8c828d9 100644
--- a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js
@@ -109,9 +109,10 @@
 
   class GOVUKFrontendComponent {
     constructor($module) {
-      this.checkSupport();
+      const childConstructor = this.constructor;
+      childConstructor.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const moduleName = childConstructor.moduleName;
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -124,7 +125,7 @@
         throw new InitError(moduleName);
       }
     }
-    checkSupport() {
+    static checkSupport() {
       if (!this.isSupported()) {
         throw new SupportError();
       }
@@ -136,7 +137,7 @@
      * @protected
      * @returns {boolean} whether the components are supported
      */
-    isSupported() {
+    static isSupported() {
       return isSupported();
     }
   }
diff --git a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs
index fb5ce2526..48bfd4fae 100644
--- a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs
@@ -103,9 +103,10 @@ class InitError extends GOVUKFrontendError {
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -118,7 +119,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -130,7 +131,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }
diff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs b/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
index 2bf203f9d..0f9c966d1 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
@@ -3,9 +3,10 @@ import { InitError, SupportError } from './errors/index.mjs';
 
 class GOVUKFrontendComponent {
   constructor($module) {
-    this.checkSupport();
+    const childConstructor = this.constructor;
+    childConstructor.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const moduleName = childConstructor.moduleName;
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -18,7 +19,7 @@ class GOVUKFrontendComponent {
       throw new InitError(moduleName);
     }
   }
-  checkSupport() {
+  static checkSupport() {
     if (!this.isSupported()) {
       throw new SupportError();
     }
@@ -30,7 +31,7 @@ class GOVUKFrontendComponent {
    * @protected
    * @returns {boolean} whether the components are supported
    */
-  isSupported() {
+  static isSupported() {
     return isSupported();
   }
 }

Action run for b9051c2

`checkSupport` of `GOVUKFrontend` can be overloaded by classes that
extend it. Added tests for `createAll` when `checkSupport` has been
overloaded.
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ace! Thanks for all the updates! 🙌🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants