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
11 changes: 7 additions & 4 deletions packages/lint/src/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,21 +549,24 @@ describe("texture_mask_asset_not_found declarations", () => {
},
);

it("reads long runs of unclosed urls in valid and malformed stylesheets in well under two seconds", async () => {
it("reads long runs of unclosed urls in valid and malformed stylesheets in linear time", async () => {
// A linear scan lints these stylesheets in about 0.1 s on a laptop. A quadratic one takes
// over 10 s, because it reads to the end of broken.css after each unclosed url(. The cap
// leaves room for slow shared CI runners.
const links =
'<link rel="stylesheet" href="nested.css"><link rel="stylesheet" href="broken.css">';
const project = makeProject(validHtml().replace("<body>", `<head>${links}</head><body>`));
writeFileSync(
join(project, "nested.css"),
`a{background:${"url(".repeat(40_000)}${")".repeat(40_000)}}`,
);
writeFileSync(join(project, "broken.css"), `a{${"mask-image:url(".repeat(3_000)}`);
writeFileSync(join(project, "broken.css"), `a{${"mask-image:url(".repeat(30_000)}`);

const started = performance.now();
await lintProject(project);

expect(performance.now() - started).toBeLessThan(2000);
});
expect(performance.now() - started).toBeLessThan(4000);
}, 60_000);
});

describe("template shell style sources", () => {
Expand Down
8 changes: 3 additions & 5 deletions packages/lint/src/rules/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
isSafeMediaUrl,
} from "@hyperframes/parsers/composition";
import { COMPOSITION_ATTRIBUTES, readClipTiming } from "@hyperframes/parsers/composition-contract";
import { rawCssUrlMatches } from "@hyperframes/parsers/css-url-scans";
import { resolveCompositionDuration } from "@hyperframes/parsers/composition-duration";
import {
readAuthoredDurationSeconds,
Expand Down Expand Up @@ -132,11 +133,8 @@ function isCompositionRootOrMount(rawTag: string): boolean {
// rules that consume this — the helper just yields raw URL values.
function extractCssUrlReferences(css: string): string[] {
const out: string[] = [];
const noComments = replaceBlockComments(css, "");
const urlPattern = /\burl\(\s*(["']?)([^)"']+)\1\s*\)/g;
let m: RegExpExecArray | null;
while ((m = urlPattern.exec(noComments)) !== null) {
const raw = (m[2] ?? "").trim();
for (const { parts } of rawCssUrlMatches(replaceBlockComments(css, ""))) {
const raw = (parts[2] ?? "").trim();
if (raw) out.push(raw);
}
return out;
Expand Down
Loading