Skip to content

Commit

Permalink
Improve errors for invalid CSS values passed to CSS functions (#1901)
Browse files Browse the repository at this point in the history
Closes #1769
  • Loading branch information
nex3 authored Mar 3, 2023
1 parent eb1ced1 commit f022e02
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Pull `@font-face` to the root rather than bubbling the style rule selector
inwards.

* Improve error messages for invalid CSS values passed to plain CSS functions.

### Embedded Sass

* Improve the performance of starting up a compilation.
Expand Down
38 changes: 24 additions & 14 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2622,22 +2622,32 @@ class _EvaluateVisitor
}

var buffer = StringBuffer("${callable.name}(");
var first = true;
for (var argument in arguments.positional) {
if (first) {
first = false;
} else {
buffer.write(", ");
}
try {
var first = true;
for (var argument in arguments.positional) {
if (first) {
first = false;
} else {
buffer.write(", ");
}

buffer.write(await _evaluateToCss(argument));
}
buffer.write(await _evaluateToCss(argument));
}

var restArg = arguments.rest;
if (restArg != null) {
var rest = await restArg.accept(this);
if (!first) buffer.write(", ");
buffer.write(_serialize(rest, restArg));
var restArg = arguments.rest;
if (restArg != null) {
var rest = await restArg.accept(this);
if (!first) buffer.write(", ");
buffer.write(_serialize(rest, restArg));
}
} on SassRuntimeException catch (error) {
if (!error.message.endsWith("isn't a valid CSS value.")) rethrow;
throw MultiSpanSassRuntimeException(
error.message,
error.span,
"value",
{nodeWithSpan.span: "unknown function treated as plain CSS"},
error.trace);
}
buffer.writeCharCode($rparen);

Expand Down
40 changes: 25 additions & 15 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 73b7fb0f310d090dee2b3383f7b08c095e5fb1c0
// Checksum: 4cdc21090d758118f0250f6efb2e6bdb0df5f337
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -2605,22 +2605,32 @@ class _EvaluateVisitor
}

var buffer = StringBuffer("${callable.name}(");
var first = true;
for (var argument in arguments.positional) {
if (first) {
first = false;
} else {
buffer.write(", ");
}
try {
var first = true;
for (var argument in arguments.positional) {
if (first) {
first = false;
} else {
buffer.write(", ");
}

buffer.write(_evaluateToCss(argument));
}
buffer.write(_evaluateToCss(argument));
}

var restArg = arguments.rest;
if (restArg != null) {
var rest = restArg.accept(this);
if (!first) buffer.write(", ");
buffer.write(_serialize(rest, restArg));
var restArg = arguments.rest;
if (restArg != null) {
var rest = restArg.accept(this);
if (!first) buffer.write(", ");
buffer.write(_serialize(rest, restArg));
}
} on SassRuntimeException catch (error) {
if (!error.message.endsWith("isn't a valid CSS value.")) rethrow;
throw MultiSpanSassRuntimeException(
error.message,
error.span,
"value",
{nodeWithSpan.span: "unknown function treated as plain CSS"},
error.trace);
}
buffer.writeCharCode($rparen);

Expand Down

0 comments on commit f022e02

Please sign in to comment.