Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve errors for invalid CSS values passed to CSS functions #1901

Merged
merged 2 commits into from
Mar 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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