Skip to content

Commit

Permalink
Check for Value before and after simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Jul 13, 2023
1 parent b292fb8 commit e300e41
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/src/node/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,24 @@ List<AsyncCallable> _parseFunctions(Object? functions, {bool asynch = false}) {
if (!asynch) {
late Callable callable;
callable = Callable.fromSignature(signature, (arguments) {
var result =
simplify((callback as Function)(toJSArray(arguments)) as Object);
if (result is Value) return result;
var result = (callback as Function)(toJSArray(arguments));
if (isPromise(result)) {
throw 'Invalid return value for custom function '
'"${callable.name}":\n'
'Promises may only be returned for sass.compileAsync() and '
'sass.compileStringAsync().';
} else {
throw 'Invalid return value for custom function '
'"${callable.name}": $result is not a sass.Value.';
}
if (result is Value) {
var simplified = simplify(result);
if (simplified is! Value) {
throw 'Custom function "${callable.name}" '
'returned an object that cannot be simplified to a '
'sass.Value.';
}
return simplified;
}
throw 'Invalid return value for custom function '
'"${callable.name}": $result is not a sass.Value.';
});
result.add(callable);
} else {
Expand All @@ -281,9 +287,15 @@ List<AsyncCallable> _parseFunctions(Object? functions, {bool asynch = false}) {
if (isPromise(result)) {
result = await promiseToFuture<Object>(result as Promise);
}

var simplified = simplify(result as Object);
if (simplified is Value) return simplified;
if (result is Value) {
var simplified = simplify(result);
if (simplified is! Value) {
throw 'Custom function "${callable.name}" '
'returned an object that cannot be simplified to a '
'sass.Value.';
}
return simplified;
}
throw 'Invalid return value for custom function '
'"${callable.name}": $result is not a sass.Value.';
});
Expand Down

0 comments on commit e300e41

Please sign in to comment.