-
Notifications
You must be signed in to change notification settings - Fork 347
/
declaration.dart
46 lines (39 loc) · 1.62 KB
/
declaration.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
// 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 'package:source_span/source_span.dart';
import '../../../value.dart';
import '../../../visitor/interface/modifiable_css.dart';
import '../declaration.dart';
import '../value.dart';
import 'node.dart';
/// A modifiable version of [CssDeclaration] for use in the evaluation step.
class ModifiableCssDeclaration extends ModifiableCssNode
implements CssDeclaration {
final CssValue<String> name;
final CssValue<Value> value;
final bool parsedAsCustomProperty;
final FileSpan valueSpanForMap;
final FileSpan span;
bool get isCustomProperty => name.value.startsWith('--');
/// Returns a new CSS declaration with the given properties.
ModifiableCssDeclaration(this.name, this.value, this.span,
{required bool parsedAsCustomProperty, FileSpan? valueSpanForMap})
: parsedAsCustomProperty = parsedAsCustomProperty,
valueSpanForMap = valueSpanForMap ?? value.span {
if (parsedAsCustomProperty) {
if (!isCustomProperty) {
throw ArgumentError(
'parsedAsCustomProperty must be false if name doesn\'t begin with '
'"--".');
} else if (value.value is! SassString) {
throw ArgumentError(
'If parsedAsCustomProperty is true, value must contain a SassString '
'(was `$value` of type ${value.value.runtimeType}).');
}
}
}
T accept<T>(ModifiableCssVisitor<T> visitor) =>
visitor.visitCssDeclaration(this);
String toString() => "$name: $value;";
}