mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(lint): read a sub-composition mount's timing through the parser (#8037)
`subcomposition_blanks_before_host` read `data-start` and `data-duration` with a raw `Number()`, so a mount with a reference start (`intro + 0.5`) looked like it started at 0 and was reported as leaving a blank tail that may not exist. A negative start was measured from the raw value, so the reported gap and the `data-duration` fix hint were wrong in the other direction. Read the mount through `readClipTiming`, the same contract parser the renderer uses: a runtime-resolved start is skipped (its end cannot be known statically), and a negative start is measured from zero.
This commit is contained in:
@@ -1836,6 +1836,30 @@ ${Array.from({ length: 10 }, (_, i) => ` <div class="clip" data-start="${i}"
|
||||
expect(find(result.findings)).toBeDefined();
|
||||
});
|
||||
|
||||
it("stays silent when the mount resolves its start at runtime", async () => {
|
||||
const html = `<html><body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="20">
|
||||
<div class="clip" id="intro" data-start="0" data-duration="15"></div>
|
||||
<div data-composition-id="sub" data-composition-src="compositions/sub.html" data-start="intro + 0.5" data-duration="5"></div>
|
||||
</div>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html, { filePath: "/project/index.html" });
|
||||
expect(find(result.findings)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("measures a negative start from zero, as the renderer does", async () => {
|
||||
const html = `<html><body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="10">
|
||||
<div data-composition-id="sub" data-composition-src="compositions/sub.html" data-start="-2" data-duration="3"></div>
|
||||
</div>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html, { filePath: "/project/index.html" });
|
||||
const finding = find(result.findings);
|
||||
expect(finding?.message).toContain("ends at 3s");
|
||||
expect(finding?.message).toContain("~7s");
|
||||
expect(finding?.fixHint).toContain("data-duration to 10");
|
||||
});
|
||||
|
||||
it("stays silent on an intentional short intro followed by another clip", async () => {
|
||||
const html = `<html><body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="60">
|
||||
|
||||
@@ -1461,11 +1461,11 @@ export const compositionRules: Array<(ctx: LintContext) => HyperframeLintFinding
|
||||
const timed = tags
|
||||
.filter((tag) => tag.index !== rootTag.index && readAttr(tag.raw, "data-start") !== null)
|
||||
.map((tag) => {
|
||||
const start = Number(readAttr(tag.raw, "data-start")) || 0;
|
||||
const dur = Number(readAttr(tag.raw, "data-duration"));
|
||||
const end = Number.isFinite(dur) && dur > 0 ? start + dur : Infinity;
|
||||
return { tag, start, end };
|
||||
});
|
||||
const timing = readTagTiming(tag.raw);
|
||||
if (timing.start === null) return null;
|
||||
return { tag, start: timing.start, end: timing.end ?? Infinity };
|
||||
})
|
||||
.filter((row): row is { tag: OpenTag; start: number; end: number } => row !== null);
|
||||
|
||||
// `tags` is a flat list (no nesting depth), so a timed element nested
|
||||
// *inside* a candidate slot is treated as a tail-covering sibling rather
|
||||
|
||||
Reference in New Issue
Block a user