From a5b2427d07d7c391d4d6745563385c1784c3f6eb Mon Sep 17 00:00:00 2001 From: Eric Kwoka <43540491+ekwoka@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:53:05 +0400 Subject: [PATCH] :bug: Allows Class methods/props to be exposed as the root data component --- packages/alpinejs/src/scope.js | 6 ++--- tests/cypress/integration/scope.spec.js | 29 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/alpinejs/src/scope.js b/packages/alpinejs/src/scope.js index 7028b5e96..e1f36feb5 100644 --- a/packages/alpinejs/src/scope.js +++ b/packages/alpinejs/src/scope.js @@ -48,7 +48,7 @@ let mergeProxyTrap = { if (name == Symbol.unscopables) return false; return objects.some((obj) => - Object.prototype.hasOwnProperty.call(obj, name) + Reflect.has(obj, name) ); }, @@ -57,7 +57,7 @@ let mergeProxyTrap = { return Reflect.get( objects.find((obj) => - Object.prototype.hasOwnProperty.call(obj, name) + Reflect.has(obj, name) ) || {}, name, thisProxy @@ -66,7 +66,7 @@ let mergeProxyTrap = { set({ objects }, name, value, thisProxy) { const target = objects.find((obj) => - Object.prototype.hasOwnProperty.call(obj, name) + Reflect.has(obj, name) ) || objects[objects.length - 1]; const descriptor = Object.getOwnPropertyDescriptor(target, name); if (descriptor?.set && descriptor?.get) diff --git a/tests/cypress/integration/scope.spec.js b/tests/cypress/integration/scope.spec.js index b5fcfbbf9..3efa0d3fc 100644 --- a/tests/cypress/integration/scope.spec.js +++ b/tests/cypress/integration/scope.spec.js @@ -56,3 +56,32 @@ test( get("span#two").should(haveText("foobar")); } ); + +test( + "allows accessing class methods", + [ + html` + +
+ +
+ `, + ], + ({ get }) => { + get("button").should(haveText("0")); + get("button").click(); + get("button").should(haveText("1")); + } +); +