Skip to content

Commit 76cfd6b

Browse files
authored
Fix @import url("...") in plain CSS (#2398)
Closes #2397
1 parent 60d440a commit 76cfd6b

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 1.80.3
22

3+
* Fix a bug where `@import url("...")` would crash in plain CSS files.
4+
35
* Improve consistency of how warnings are emitted by different parts of the
46
compiler. This should result in minimal user-visible changes, but different
57
types of warnings should now respond more reliably to flags like `--quiet`,

lib/src/parse/css.dart

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:string_scanner/string_scanner.dart';
77

88
import '../ast/sass.dart';
99
import '../functions.dart';
10+
import '../interpolation_buffer.dart';
1011
import 'scss.dart';
1112

1213
/// The set of all function names disallowed in plain CSS.
@@ -86,16 +87,38 @@ class CssParser extends ScssParser {
8687
ImportRule _cssImportRule(LineScannerState start) {
8788
var urlStart = scanner.state;
8889
var url = switch (scanner.peekChar()) {
89-
$u || $U => dynamicUrl() as StringExpression,
90+
$u || $U => switch (dynamicUrl()) {
91+
StringExpression string => string.text,
92+
InterpolatedFunctionExpression(
93+
:var name,
94+
arguments: ArgumentInvocation(
95+
positional: [StringExpression string],
96+
named: Map(isEmpty: true),
97+
rest: null,
98+
keywordRest: null,
99+
),
100+
:var span
101+
) =>
102+
(InterpolationBuffer()
103+
..addInterpolation(name)
104+
..writeCharCode($lparen)
105+
..addInterpolation(string.asInterpolation())
106+
..writeCharCode($rparen))
107+
.interpolation(span),
108+
// This shouldn't be reachable.
109+
var expression =>
110+
error("Unsupported plain CSS import.", expression.span)
111+
},
90112
_ => StringExpression(interpolatedString().asInterpolation(static: true))
113+
.text
91114
};
92115

93116
whitespace();
94117
var modifiers = tryImportModifiers();
95118
expectStatementSeparator("@import rule");
96-
return ImportRule([
97-
StaticImport(url.text, scanner.spanFrom(urlStart), modifiers: modifiers)
98-
], scanner.spanFrom(start));
119+
return ImportRule(
120+
[StaticImport(url, scanner.spanFrom(urlStart), modifiers: modifiers)],
121+
scanner.spanFrom(start));
99122
}
100123

101124
ParenthesizedExpression parentheses() {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.80.3-dev
2+
version: 1.80.3
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)