-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathbuilt_in.dart
66 lines (57 loc) · 2.11 KB
/
built_in.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
57
58
59
60
61
62
63
64
65
66
// Copyright 2019 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 'dart:collection';
import '../ast/css.dart';
import '../ast/node.dart';
import '../callable.dart';
import '../exception.dart';
import '../extend/extension_store.dart';
import '../module.dart';
import '../value.dart';
/// A module provided by Sass, available under the special `sass:` URL space.
final class BuiltInModule<T extends AsyncCallable> implements Module<T> {
final Uri url;
final Map<String, T> functions;
final Map<String, T> mixins;
final Map<String, Value> variables;
List<Module<T>> get upstream => const [];
Map<String, AstNode> get variableNodes => const {};
ExtensionStore get extensionStore => ExtensionStore.empty;
CssStylesheet get css => CssStylesheet.empty(url: url);
Map<Module<T>, List<CssComment>> get preModuleComments => const {};
bool get transitivelyContainsCss => false;
bool get transitivelyContainsExtensions => false;
BuiltInModule(
String name, {
Iterable<T>? functions,
Iterable<T>? mixins,
Map<String, Value>? variables,
}) : url = Uri(scheme: "sass", path: name),
functions = _callableMap(functions),
mixins = _callableMap(mixins),
variables =
variables == null ? const {} : UnmodifiableMapView(variables);
/// Returns a map from [callables]' names to their values.
static Map<String, T> _callableMap<T extends AsyncCallable>(
Iterable<T>? callables,
) =>
UnmodifiableMapView(
callables == null
? {}
: UnmodifiableMapView({
for (var callable in callables) callable.name: callable,
}),
);
void setVariable(String name, Value value, AstNode nodeWithSpan) {
if (!variables.containsKey(name)) {
throw SassScriptException("Undefined variable.");
}
throw SassScriptException("Cannot modify built-in variable.");
}
Object variableIdentity(String name) {
assert(variables.containsKey(name));
return this;
}
Module<T> cloneCss() => this;
}