mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
fix(sdk,core): unrollDynamicAnimations rejects empty element list (R1 #1501b)
An empty `elements` array has no unrolled form — the writer would overwrite the loop/statement with zero tween calls, silently deleting the animation. - gsapWriterAcorn: unrollDynamicAnimations returns the script verbatim on an empty list (no-op instead of a destructive overwrite). - validateOp: reject unrollDynamicAnimations with empty elements as E_INVALID_ARGS so callers get a clean error rather than silent corruption. - Tests: writer no-op on []; validateOp E_INVALID_ARGS on []. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
f9bdd18fd5
commit
5b3db8de62
@@ -129,6 +129,14 @@ for (let i = 0; i < 2; i++) {
|
||||
expect(out).toContain('tl.to("#a"');
|
||||
expect(out).toContain('tl.to("#b"');
|
||||
});
|
||||
|
||||
it("an empty element list is a no-op, not an animation-deleting overwrite", () => {
|
||||
const parsed = parseGsapScriptAcornForWrite(LOOP);
|
||||
const targetId = parsed?.located.find((l) => l.animation.method === "to")?.id ?? "";
|
||||
// Empty elements has no unrolled form — overwriting the loop with zero calls
|
||||
// would silently delete the animation. Writer must return the script verbatim.
|
||||
expect(unrollDynamicAnimations(LOOP, targetId, [])).toBe(LOOP);
|
||||
});
|
||||
});
|
||||
|
||||
// ── R2 #1 — non-`for` loops must not leave preserved siblings with an unbound index var ──
|
||||
|
||||
@@ -2024,6 +2024,9 @@ export function unrollDynamicAnimations(
|
||||
animationId: string,
|
||||
elements: UnrollElement[],
|
||||
): string {
|
||||
// An empty element list has no unrolled form — replacing the loop/statement
|
||||
// with zero calls would silently delete the animation. No-op instead.
|
||||
if (elements.length === 0) return script;
|
||||
const parsed = parseGsapScriptAcornForWrite(script);
|
||||
if (!parsed) return script;
|
||||
const target = parsed.located.find((l) => l.id === animationId);
|
||||
|
||||
@@ -492,6 +492,20 @@ describe("Phase 3b ops", () => {
|
||||
if (!r2.ok) expect(r2.code).toBe("E_NO_GSAP_SCRIPT");
|
||||
});
|
||||
|
||||
it("unrollDynamicAnimations rejects an empty element list (would delete the animation)", () => {
|
||||
const parsed = parseMutable(
|
||||
`<div data-hf-id="hf-r" data-hf-root></div>` +
|
||||
`<script>var tl = gsap.timeline({ paused: true }); tl.to("#x", { x: 1 }, 0);</script>`,
|
||||
);
|
||||
const r = validateOp(parsed, {
|
||||
type: "unrollDynamicAnimations",
|
||||
animationId: "tw-1",
|
||||
elements: [],
|
||||
});
|
||||
expect(r.ok).toBe(false);
|
||||
if (!r.ok) expect(r.code).toBe("E_INVALID_ARGS");
|
||||
});
|
||||
|
||||
it("setClassStyle no longer throws — implemented in Phase 3b", () => {
|
||||
expect(() =>
|
||||
applyOp(fresh(), {
|
||||
|
||||
@@ -1114,7 +1114,6 @@ export function validateOp(parsed: ParsedDocument, op: EditOp): CanResult {
|
||||
case "setArcPath":
|
||||
case "updateArcSegment":
|
||||
case "removeArcPath":
|
||||
case "unrollDynamicAnimations":
|
||||
case "deleteAllForSelector":
|
||||
case "removeLabel":
|
||||
if (getGsapScript(parsed.document) === null)
|
||||
@@ -1124,6 +1123,20 @@ export function validateOp(parsed: ParsedDocument, op: EditOp): CanResult {
|
||||
"This composition does not use GSAP animations.",
|
||||
);
|
||||
return CAN_OK;
|
||||
case "unrollDynamicAnimations":
|
||||
if (getGsapScript(parsed.document) === null)
|
||||
return canErr(
|
||||
"E_NO_GSAP_SCRIPT",
|
||||
"No GSAP script block found in the composition.",
|
||||
"This composition does not use GSAP animations.",
|
||||
);
|
||||
if (op.elements.length === 0)
|
||||
return canErr(
|
||||
"E_INVALID_ARGS",
|
||||
"unrollDynamicAnimations requires at least one element.",
|
||||
"An empty element list would delete the animation; pass the resolved element list.",
|
||||
);
|
||||
return CAN_OK;
|
||||
default:
|
||||
return canErr("E_UNKNOWN_OP", `Unknown op type: "${(op as EditOp).type}".`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user