feat: add semantic CSS stylesheets (#3274)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
Amruth Pillai
2026-07-30 12:39:15 +02:00
committed by GitHub
co-authored by Cursor Agent
parent 4ac19f81b3
commit d2ffbf9618
320 changed files with 78393 additions and 2915 deletions
@@ -0,0 +1,68 @@
import { describe, expect, it } from "vitest";
import { compileStylesheet } from "./compile";
describe("compileStylesheet", () => {
it("compiles canonical version-one source", () => {
const result = compileStylesheet({
languageVersion: 1,
text: "@version 1;\nsection { color: #123456; }\n",
});
expect(result.program?.languageVersion).toBe(1);
expect(result.diagnostics).toEqual([]);
});
it("warns when version-one source omits the directive", () => {
const result = compileStylesheet({ languageVersion: 1, text: "section { color: red; }" });
expect(result.diagnostics).toContainEqual(
expect.objectContaining({ code: "MISSING_VERSION_DIRECTIVE", severity: "warning" }),
);
});
it("rejects a directive that disagrees with persisted metadata", () => {
const result = compileStylesheet({ languageVersion: 1, text: "@version 2;" });
expect(result.program).toBeNull();
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "VERSION_MISMATCH", severity: "error" }));
});
it("rejects duplicate directives", () => {
const result = compileStylesheet({ languageVersion: 1, text: "@version 1;\n@version 1;" });
expect(result.program).toBeNull();
expect(result.diagnostics).toContainEqual(
expect.objectContaining({ code: "DUPLICATE_VERSION_DIRECTIVE", severity: "error" }),
);
});
it("rejects malformed directives", () => {
const result = compileStylesheet({ languageVersion: 1, text: "@version one;" });
expect(result.program).toBeNull();
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "INVALID_VERSION", severity: "error" }));
});
it("rejects non-positive directives", () => {
const result = compileStylesheet({ languageVersion: 1, text: "@version 0;" });
expect(result.program).toBeNull();
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "INVALID_VERSION", severity: "error" }));
});
it("rejects unsupported persisted language versions", () => {
const result = compileStylesheet({ languageVersion: 2, text: "@version 2;" });
expect(result.program).toBeNull();
expect(result.diagnostics).toContainEqual(
expect.objectContaining({ code: "UNSUPPORTED_VERSION", severity: "error" }),
);
});
it("does not compile a recovered CSS error", () => {
const result = compileStylesheet({ languageVersion: 1, text: "@version 1;\nsection { color red; }" });
expect(result.program).toBeNull();
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "CSS_PARSE_ERROR", severity: "error" }));
});
});