diff --git a/packages/core/src/compiler/compositionScoping.test.ts b/packages/core/src/compiler/compositionScoping.test.ts index 7985c9f809..75cde782ba 100644 --- a/packages/core/src/compiler/compositionScoping.test.ts +++ b/packages/core/src/compiler/compositionScoping.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it, vi } from "vitest"; import { parseHTML } from "linkedom"; import { + buildVariablesByCompScript, scopeCssToComposition, wrapInlineScriptWithErrorBoundary, wrapScopedCompositionScript, @@ -886,3 +887,60 @@ window.__timelines['intro'] = tl; expect(gsapTargets).toEqual([["HELLO"]]); }); }); + +/** + * The emitted statement is placed inside a ` breakout", () => { + /** Serialize into a document the way the compilers do, then re-parse it. */ + function scriptsAfterRoundTrip(body: string): string[] { + const { document } = parseHTML("
"); + const el = document.createElement("script"); + el.textContent = body; + document.body.appendChild(el); + const { document: reparsed } = parseHTML(document.toString()); + return [...reparsed.querySelectorAll("script")].map((s) => s.textContent ?? ""); + } + + it("does not let a variable VALUE close the script element", () => { + const body = buildVariablesByCompScript({ + "comp-a": { greeting: " { + const body = buildVariablesByCompScript({ + "comp-a": { " { + const body = buildVariablesByCompScript({ + " { + // Run the statement the way the browser does rather than string-slicing it. + const variables = { "comp-a": { greeting: "a b c" } }; + const body = buildVariablesByCompScript(variables) ?? ""; + const fakeWindow: Record