Skip to content

Commit

Permalink
Fix @import url("...") in plain CSS (#2398)
Browse files Browse the repository at this point in the history
Closes #2397
  • Loading branch information
nex3 authored Oct 18, 2024
1 parent 60d440a commit 76cfd6b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.80.3

* Fix a bug where `@import url("...")` would crash in plain CSS files.

* Improve consistency of how warnings are emitted by different parts of the
compiler. This should result in minimal user-visible changes, but different
types of warnings should now respond more reliably to flags like `--quiet`,
Expand Down
31 changes: 27 additions & 4 deletions lib/src/parse/css.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:string_scanner/string_scanner.dart';

import '../ast/sass.dart';
import '../functions.dart';
import '../interpolation_buffer.dart';
import 'scss.dart';

/// The set of all function names disallowed in plain CSS.
Expand Down Expand Up @@ -86,16 +87,38 @@ class CssParser extends ScssParser {
ImportRule _cssImportRule(LineScannerState start) {
var urlStart = scanner.state;
var url = switch (scanner.peekChar()) {
$u || $U => dynamicUrl() as StringExpression,
$u || $U => switch (dynamicUrl()) {
StringExpression string => string.text,
InterpolatedFunctionExpression(
:var name,
arguments: ArgumentInvocation(
positional: [StringExpression string],
named: Map(isEmpty: true),
rest: null,
keywordRest: null,
),
:var span
) =>
(InterpolationBuffer()
..addInterpolation(name)
..writeCharCode($lparen)
..addInterpolation(string.asInterpolation())
..writeCharCode($rparen))
.interpolation(span),
// This shouldn't be reachable.
var expression =>
error("Unsupported plain CSS import.", expression.span)
},
_ => StringExpression(interpolatedString().asInterpolation(static: true))
.text
};

whitespace();
var modifiers = tryImportModifiers();
expectStatementSeparator("@import rule");
return ImportRule([
StaticImport(url.text, scanner.spanFrom(urlStart), modifiers: modifiers)
], scanner.spanFrom(start));
return ImportRule(
[StaticImport(url, scanner.spanFrom(urlStart), modifiers: modifiers)],
scanner.spanFrom(start));
}

ParenthesizedExpression parentheses() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.80.3-dev
version: 1.80.3
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit 76cfd6b

Please sign in to comment.