-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathfunction.dart
56 lines (44 loc) · 1.69 KB
/
function.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2016 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:meta/meta.dart';
import '../callable.dart';
import '../exception.dart';
import '../visitor/interface/value.dart';
import '../value.dart';
/// A SassScript function reference.
///
/// A function reference captures a function from the local environment so that
/// it may be passed between modules.
///
/// {@category Value}
@sealed
class SassFunction extends Value {
/// The callable that this function invokes.
///
/// Note that this is typed as an [AsyncCallable] so that it will work with
/// both synchronous and asynchronous evaluate visitors, but in practice the
/// synchronous evaluate visitor will crash if this isn't a [Callable].
final AsyncCallable callable;
/// The unique compile context for tracking if SassFunction and SassMixin
/// belongs to current compilation or not.
final Object? _compileContext;
SassFunction(this.callable) : _compileContext = null;
@internal
SassFunction.withCompileContext(this.callable, this._compileContext);
/// @nodoc
@internal
T accept<T>(ValueVisitor<T> visitor) => visitor.visitFunction(this);
SassFunction assertFunction([String? name]) => this;
@internal
SassFunction assertCompileContext(Object compileContext) {
if (_compileContext != null && _compileContext != compileContext) {
throw SassScriptException(
"$this does not belong to current compilation.");
}
return this;
}
bool operator ==(Object other) =>
other is SassFunction && callable == other.callable;
int get hashCode => callable.hashCode;
}