Skip to content

Commit c284199

Browse files
cscheidclaude
andauthored
Fix SCSS analysis failing on same-line prop:value declarations and consecutive semicolons (#14688)
* Fix SCSS analysis failing on same-line declarations with no space after colon (#14687) scss-parser cannot tokenize `prop:value` (no space after the colon) unless the value is a bare identifier. The existing workaround in analyzer/parse.ts only rescued declarations at line start, so rules like `.example {width:100px;}` reached the raw parser, cssVarsBlock threw SCSSParsingError, and the --quarto-scss-export-* block was silently dropped. Add a sibling rewrite covering declarations that follow `{` or `;` on the same line. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Fix SCSS analysis failing on consecutive semicolons (#11703) scss-parser throws on consecutive semicolons inside a block (an empty statement, valid CSS/SCSS), even when separated by whitespace or newlines, e.g. `a { b: 1;; }`. Collapse each run of semicolons into one before parsing, alongside the other analyzer text workarounds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 1dc7f4c commit c284199

7 files changed

Lines changed: 178 additions & 0 deletions

File tree

‎news/changelog-1.10.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ All changes included in 1.10:
103103

104104
- ([#6092](https://github.com/quarto-dev/quarto-cli/issues/6092)): Fix the `default-image-extension` being appended to an extensionless URL ending in a slash (e.g. `![](https://example.com/)`), which broke the embed/iframe image syntax.
105105
- ([#6651](https://github.com/quarto-dev/quarto-cli/issues/6651)): Fix dart-sass compilation failing in enterprise environments where `.bat` files are blocked by group policy.
106+
- ([#11703](https://github.com/quarto-dev/quarto-cli/issues/11703)): Fix SCSS color-variable export (`--quarto-scss-export-*`) being silently skipped when a theme rule contains consecutive semicolons (e.g. `max-height: 100% !important;;`).
106107
- ([#14255](https://github.com/quarto-dev/quarto-cli/issues/14255)): Fix shortcodes inside inline and display math expressions not being resolved.
107108
- ([#14342](https://github.com/quarto-dev/quarto-cli/issues/14342)): Work around TOCTOU race in Deno's `expandGlobSync` that can cause unexpected exceptions to be raised while traversing directories during project initialization.
108109
- ([#14445](https://github.com/quarto-dev/quarto-cli/issues/14445)): Fix intermittent `Uncaught (in promise) TypeError: Writable stream is closed or errored.` aborting renders on Linux. `execProcess` now awaits and swallows the rejection from `process.stdin.close()` when the child closes its stdin first. The captured stderr is now also surfaced when `typst-gather analyze` falls back to staging all packages, so failures are diagnosable without bypassing `quarto`.
@@ -116,3 +117,4 @@ All changes included in 1.10:
116117
- ([#14583](https://github.com/quarto-dev/quarto-cli/issues/14583)): Fix a shortcode used as an image source (e.g. `![]({{< meta logo >}})`) getting the `default-image-extension` appended, producing a doubled extension once the shortcode resolves.
117118
- ([#14595](https://github.com/quarto-dev/quarto-cli/issues/14595)): Fix reload preview in code-server environment
118119
- ([#14669](https://github.com/quarto-dev/quarto-cli/issues/14669)): Fix markdown output being deleted when `output-file` has an `.html` extension and an html format is paired with a markdown format.
120+
- ([#14687](https://github.com/quarto-dev/quarto-cli/issues/14687)): Fix SCSS color-variable export (`--quarto-scss-export-*`) being silently skipped when a theme rule places a declaration on the same line as the opening brace with no space after the colon (e.g. `.example {width:100px;}`).

‎src/core/sass/analyzer/parse.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ export const makeParserModule = (
2727
"$1$2 /* empty rule */ $3",
2828
);
2929

30+
// https://github.com/quarto-dev/quarto-cli/issues/11703
31+
// It also doesn't like consecutive semicolons inside a block
32+
// (an empty statement, valid CSS/SCSS), even across lines,
33+
// e.g. `a { b: 1;; }`. Collapse each run of semicolons into one.
34+
contents = contents.replaceAll(
35+
/;[\s;]*;/g,
36+
";",
37+
);
38+
3039
// it also really doesn't like statements that don't end in a semicolon
3140
// so, in case you are reading this code to understand why the parser is failing,
3241
// ensure that your SCSS has semicolons at the end of every statement.
@@ -40,6 +49,13 @@ export const makeParserModule = (
4049
/(^\s*[A-Za-z0-9-]+):([^ \n])/mg,
4150
"$1: $2",
4251
);
52+
// https://github.com/quarto-dev/quarto-cli/issues/14687
53+
// ... and the same when the declaration doesn't start a line but
54+
// follows `{` or `;`, e.g. `.example {width:100px;}`
55+
contents = contents.replaceAll(
56+
/([{;]\s*[A-Za-z0-9-]+):([^ \n])/g,
57+
"$1: $2",
58+
);
4359

4460
// scss-parser's tokenizer only handles ASCII identifier characters.
4561
// Non-ASCII codepoints are valid in both CSS and SCSS identifiers:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*-- scss:defaults --*/
2+
$issue-11703-color: #00ff00;
3+
4+
/*-- scss:rules --*/
5+
6+
/* A double semicolon (an empty statement, valid CSS/SCSS) used to break the
7+
SCSS analyzer (https://github.com/quarto-dev/quarto-cli/issues/11703). */
8+
.hanged {
9+
max-height: 100% !important;;
10+
}
11+
12+
#test-11703 {
13+
background-color: $issue-11703-color;
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*-- scss:defaults --*/
2+
$issue-14687-color: #ff0000;
3+
4+
/*-- scss:rules --*/
5+
6+
/* A declaration on the same line as the opening brace, with no space after
7+
the colon and a non-identifier value, used to break the SCSS analyzer
8+
(https://github.com/quarto-dev/quarto-cli/issues/14687). */
9+
.example {width:100px;}
10+
11+
#test-14687 {
12+
background-color: $issue-14687-color;
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "Double semicolon in SCSS rule"
3+
format:
4+
html:
5+
theme:
6+
- default
7+
- custom-11703.scss
8+
_quarto:
9+
tests:
10+
html:
11+
ensureCssRegexMatches:
12+
- ['--quarto-scss-export-issue-11703-color', '\.hanged']
13+
---
14+
15+
A theme rule containing a double semicolon (`max-height: 100% !important;;`)
16+
must not break the SCSS color variable export.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "One-line SCSS rule with no space after colon"
3+
format:
4+
html:
5+
theme:
6+
- default
7+
- custom-14687.scss
8+
_quarto:
9+
tests:
10+
html:
11+
ensureCssRegexMatches:
12+
- ['--quarto-scss-export-issue-14687-color', '\.example']
13+
---
14+
15+
A theme rule like `.example {width:100px;}` (declaration on the same line as
16+
the opening brace, no space after the colon) must not break the SCSS color
17+
variable export.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* scss-analyzer-parse.test.ts
3+
*
4+
* Tests for the SCSS static-analysis parser wrapper, in particular the
5+
* text-level workarounds in src/core/sass/analyzer/parse.ts that shield
6+
* the brittle third-party scss-parser from valid-but-oddly-formatted SCSS.
7+
* Validates fixes for:
8+
* https://github.com/quarto-dev/quarto-cli/issues/14687 (colon with no space)
9+
* https://github.com/quarto-dev/quarto-cli/issues/11703 (double semicolon)
10+
*
11+
* Copyright (C) 2020-2026 Posit Software, PBC
12+
*/
13+
14+
import { unitTest } from "../test.ts";
15+
import { assert } from "testing/asserts";
16+
import { parse } from "scss-parser";
17+
import { makeParserModule } from "../../src/core/sass/analyzer/parse.ts";
18+
import { cssVarsBlock } from "../../src/core/sass/add-css-vars.ts";
19+
20+
const { getSassAst } = makeParserModule(parse);
21+
22+
// SCSS snippets that are valid (Dart Sass compiles them) but used to make
23+
// the raw scss-parser throw. Each entry documents a shape the workarounds
24+
// in parse.ts must keep rescuing.
25+
const parseableSnippets: [string, string][] = [
26+
// issue #14687: declaration on the same line as `{`, no space after colon
27+
[".example {width:100px;}", "same-line declaration, numeric value"],
28+
[".example { width:100px; }", "same-line declaration, spaces inside braces"],
29+
[".example {width:$foo;}", "same-line declaration, variable value"],
30+
[".example {width:100px}", "same-line declaration, missing semicolon"],
31+
[".example {color:#fff;}", "same-line declaration, hex color value"],
32+
[".example {width:100%;}", "same-line declaration, percentage value"],
33+
[".example {margin:0;}", "same-line declaration, bare zero value"],
34+
[".example {width:.5em;}", "same-line declaration, leading-dot value"],
35+
[
36+
".example {width:100px;height:200px;}",
37+
"second declaration follows a semicolon on the same line",
38+
],
39+
["a:hover {width:100px;}", "pseudo-class selector before a one-line rule"],
40+
[
41+
"@media (min-width:600px) { body { margin:0; } }",
42+
"one-line media query with colon-no-space declarations",
43+
],
44+
[
45+
".x {background:url(data:image/png;base64,AAAA);}",
46+
"data: url payload containing colons and semicolons",
47+
],
48+
['.x {content:"{a:1}";}', "string value containing brace/colon characters"],
49+
// issue #11703: consecutive semicolons (empty statements) inside a block
50+
["a { b: 1;; }", "double semicolon after a declaration"],
51+
["a { b: 1; ; }", "semicolons separated by a space"],
52+
["a { b: 1;;; }", "triple semicolon"],
53+
["a { b: 1;\n;\n}", "semicolons separated by a newline"],
54+
[
55+
".hanged { max-height: 100% !important;; }",
56+
"double semicolon after !important (issue #11703 shape)",
57+
],
58+
// shapes that already worked before issue #14687; guard against regressions
59+
[".example {\n width:100px;\n}", "line-start declaration, no space after colon"],
60+
[".foo { &:hover {color:red;} }", "nested parent-selector rule on one line"],
61+
["$brand: #ff0000;\n.example {width:100px;}", "variable assignment plus one-line rule"],
62+
];
63+
64+
unitTest(
65+
"scss-analyzer - parses valid SCSS shapes that break raw scss-parser (issues #14687, #11703)",
66+
// deno-lint-ignore require-await
67+
async () => {
68+
for (const [snippet, description] of parseableSnippets) {
69+
try {
70+
const ast = getSassAst(snippet);
71+
assert(
72+
ast.type === "stylesheet",
73+
`Expected a stylesheet AST for: ${description}`,
74+
);
75+
} catch (e) {
76+
const message = e instanceof Error ? e.message : String(e);
77+
throw new Error(
78+
`getSassAst failed on "${snippet}" (${description}): ${message}`,
79+
);
80+
}
81+
}
82+
},
83+
);
84+
85+
unitTest(
86+
"scss-analyzer - cssVarsBlock exports colors despite one-line rules (issue #14687)",
87+
// deno-lint-ignore require-await
88+
async () => {
89+
const scss = [
90+
"$brand: #ff0000;",
91+
"$body-bg: $brand;",
92+
".example {width:100px;}",
93+
].join("\n");
94+
const block = cssVarsBlock(scss);
95+
assert(
96+
block.includes("--quarto-scss-export-brand:"),
97+
`Expected $brand to be exported as a CSS variable, got:\n${block}`,
98+
);
99+
},
100+
);

0 commit comments

Comments
 (0)