dart-sass/lib/src/value/boolean.dart

36 lines
1022 B
Dart
Raw Normal View History

2016-05-25 05:01:43 +02:00
// 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.
2016-08-15 08:51:29 +02:00
import '../visitor/interface/value.dart';
2016-05-25 05:01:43 +02:00
import '../value.dart';
2016-10-15 11:57:29 +02:00
/// The SassScript `true` value.
2016-06-04 01:31:29 +02:00
const sassTrue = const SassBoolean._(true);
2016-10-15 11:57:29 +02:00
/// The SassScript `false` value.
2016-06-04 01:31:29 +02:00
const sassFalse = const SassBoolean._(false);
2016-05-25 05:01:43 +02:00
2016-10-15 11:57:29 +02:00
/// A SassScript boolean value.
2016-06-04 01:31:29 +02:00
class SassBoolean extends Value {
2016-10-15 11:57:29 +02:00
/// Whether this value is `true` or `false`.
2016-05-25 05:01:43 +02:00
final bool value;
2016-08-28 23:26:40 +02:00
bool get isTruthy => value;
2016-10-15 11:57:29 +02:00
/// Returns a [SassBoolean] corresponding to [value].
///
/// This just returns [sassTrue] or [sassFalse]; it doesn't allocate a new
/// value.
2016-06-04 01:31:29 +02:00
factory SassBoolean(bool value) => value ? sassTrue : sassFalse;
2016-05-25 05:01:43 +02:00
2016-06-04 01:31:29 +02:00
const SassBoolean._(this.value);
2016-05-25 05:01:43 +02:00
2016-05-28 01:09:03 +02:00
/*=T*/ accept/*<T>*/(ValueVisitor/*<T>*/ visitor) =>
visitor.visitBoolean(this);
2016-09-20 23:59:53 +02:00
SassBoolean assertBoolean([String name]) => this;
2016-05-25 05:01:43 +02:00
Value unaryNot() => value ? sassFalse : sassTrue;
}