Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/core/src/compiler/compositionScoping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ body { margin: 0; }
expect(variablesByComp["card-1"]).toEqual({ title: "Pro" });
});

it("preserves static methods on classes exposed through window", () => {
const { document } = parseHTML(`<div data-composition-id="scene"></div>`);
class FakeTexts {
static mountChars() {
return "ok";
}
}
const fakeWindow: Record<string, unknown> = {
document,
__timelines: {},
Texts: FakeTexts,
};
const wrapped = wrapScopedCompositionScript(
`window.__capturedMountCharsType = typeof window.Texts?.mountChars;`,
"scene",
);

new Function("window", wrapped)(fakeWindow);

expect(fakeWindow.__capturedMountCharsType).toBe("function");
});

it("executes document and GSAP selectors inside the composition root", () => {
const { document } = parseHTML(`
<div data-composition-id="scene" data-start="intro"><h1 class="title">Scene</h1></div>
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/compiler/compositionScoping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@
? new Proxy(window, {
get: function(target, prop, receiver) {
if (prop === "__timelines") return __hfGetTimelineRegistry();
var value = Reflect.get(target, prop, target);
return typeof value === "function" ? value.bind(target) : value;
return Reflect.get(target, prop, target);
},
set: function(target, prop, value, receiver) {
if (prop === "__timelines") {
Expand Down Expand Up @@ -488,7 +487,7 @@
try {
(function(document, gsap, window, __hyperframes) {
${source}
}).call(window, __hfScopedDocument, __hfScopedGsap, __hfScopedWindow, __hfScopedHyperframes);

Check warning

Code scanning / CodeQL

Unsafe code constructed from library input Medium

This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
This string concatenation which depends on
library input
is later
interpreted as code
.
} catch (_err) {
console.error(__hfErrorLabel, __hfCompId, _err);
}
Expand Down
Loading