mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 22:02:00 +01:00
Add a ModifiableCssVisitor
This lets us traverse a modifiable CSS tree while preserving the fact that it's modifiable.
This commit is contained in:
parent
14787d86e0
commit
511e525619
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'node.dart';
|
||||
import 'value.dart';
|
||||
|
||||
@ -18,4 +19,6 @@ abstract class CssAtRule extends CssParentNode {
|
||||
/// This implies `children.isEmpty`, but the reverse is not true—for a rule
|
||||
/// like `@foo {}`, [children] is empty but [isChildless] is `false`.
|
||||
bool get isChildless;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssAtRule(this);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'node.dart';
|
||||
|
||||
/// A plain CSS comment.
|
||||
@ -14,4 +15,6 @@ abstract class CssComment extends CssNode {
|
||||
/// Whether this comment starts with `/*!` and so should be preserved even in
|
||||
/// compressed mode.
|
||||
bool get isPreserved;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssComment(this);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../value.dart';
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'node.dart';
|
||||
import 'value.dart';
|
||||
|
||||
@ -22,4 +23,6 @@ abstract class CssDeclaration extends CssNode {
|
||||
/// where that variable was declared whereas [value.span] is the span where
|
||||
/// the variable was used. Otherwise, this is identical to [value.span].
|
||||
FileSpan get valueSpanForMap;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssDeclaration(this);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'media_query.dart';
|
||||
import 'node.dart';
|
||||
import 'value.dart';
|
||||
@ -18,4 +19,6 @@ abstract class CssImport extends CssNode {
|
||||
|
||||
/// The media query attached to this import.
|
||||
List<CssMediaQuery> get media;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssImport(this);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'node.dart';
|
||||
import 'value.dart';
|
||||
|
||||
@ -11,4 +12,6 @@ import 'value.dart';
|
||||
abstract class CssKeyframeBlock extends CssParentNode {
|
||||
/// The selector for this block.
|
||||
CssValue<List<String>> get selector;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssKeyframeBlock(this);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'media_query.dart';
|
||||
import 'node.dart';
|
||||
|
||||
@ -11,4 +12,6 @@ abstract class CssMediaRule extends CssParentNode {
|
||||
///
|
||||
/// This is never empty.
|
||||
List<CssMediaQuery> get queries;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssMediaRule(this);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../at_rule.dart';
|
||||
import '../value.dart';
|
||||
import 'node.dart';
|
||||
@ -20,7 +20,7 @@ class ModifiableCssAtRule extends ModifiableCssParentNode implements CssAtRule {
|
||||
{bool childless = false, this.value})
|
||||
: isChildless = childless;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssAtRule(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) => visitor.visitCssAtRule(this);
|
||||
|
||||
ModifiableCssAtRule copyWithoutChildren() =>
|
||||
ModifiableCssAtRule(name, span, childless: isChildless, value: value);
|
||||
|
@ -5,7 +5,7 @@
|
||||
import 'package:charcode/charcode.dart';
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../comment.dart';
|
||||
import 'node.dart';
|
||||
|
||||
@ -18,5 +18,5 @@ class ModifiableCssComment extends ModifiableCssNode implements CssComment {
|
||||
|
||||
ModifiableCssComment(this.text, this.span);
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssComment(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) => visitor.visitCssComment(this);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../value.dart';
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../declaration.dart';
|
||||
import '../value.dart';
|
||||
import 'node.dart';
|
||||
@ -22,5 +22,6 @@ class ModifiableCssDeclaration extends ModifiableCssNode
|
||||
{FileSpan valueSpanForMap})
|
||||
: valueSpanForMap = valueSpanForMap ?? span;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssDeclaration(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) =>
|
||||
visitor.visitCssDeclaration(this);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../import.dart';
|
||||
import '../media_query.dart';
|
||||
import '../value.dart';
|
||||
@ -29,5 +29,5 @@ class ModifiableCssImport extends ModifiableCssNode implements CssImport {
|
||||
{this.supports, Iterable<CssMediaQuery> media})
|
||||
: media = media == null ? null : List.unmodifiable(media);
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssImport(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) => visitor.visitCssImport(this);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../keyframe_block.dart';
|
||||
import '../value.dart';
|
||||
import 'node.dart';
|
||||
@ -17,7 +17,8 @@ class ModifiableCssKeyframeBlock extends ModifiableCssParentNode
|
||||
|
||||
ModifiableCssKeyframeBlock(this.selector, this.span);
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssKeyframeBlock(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) =>
|
||||
visitor.visitCssKeyframeBlock(this);
|
||||
|
||||
ModifiableCssKeyframeBlock copyWithoutChildren() =>
|
||||
ModifiableCssKeyframeBlock(selector, span);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../media_query.dart';
|
||||
import '../media_rule.dart';
|
||||
import 'node.dart';
|
||||
@ -22,7 +22,8 @@ class ModifiableCssMediaRule extends ModifiableCssParentNode
|
||||
}
|
||||
}
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssMediaRule(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) =>
|
||||
visitor.visitCssMediaRule(this);
|
||||
|
||||
ModifiableCssMediaRule copyWithoutChildren() =>
|
||||
ModifiableCssMediaRule(queries, span);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../at_rule.dart';
|
||||
import '../node.dart';
|
||||
import '../style_rule.dart';
|
||||
@ -57,7 +57,7 @@ abstract class ModifiableCssNode extends CssNode {
|
||||
}
|
||||
}
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor);
|
||||
|
||||
/// Removes [this] from [parent]'s child list.
|
||||
///
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../../selector.dart';
|
||||
import '../style_rule.dart';
|
||||
import 'node.dart';
|
||||
@ -28,7 +28,8 @@ class ModifiableCssStyleRule extends ModifiableCssParentNode
|
||||
: selector = selector,
|
||||
originalSelector = originalSelector ?? selector.value;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssStyleRule(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) =>
|
||||
visitor.visitCssStyleRule(this);
|
||||
|
||||
ModifiableCssStyleRule copyWithoutChildren() =>
|
||||
ModifiableCssStyleRule(selector, span,
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../stylesheet.dart';
|
||||
import 'node.dart';
|
||||
|
||||
@ -15,7 +15,8 @@ class ModifiableCssStylesheet extends ModifiableCssParentNode
|
||||
|
||||
ModifiableCssStylesheet(this.span);
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssStylesheet(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) =>
|
||||
visitor.visitCssStylesheet(this);
|
||||
|
||||
ModifiableCssStylesheet copyWithoutChildren() =>
|
||||
ModifiableCssStylesheet(span);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/css.dart';
|
||||
import '../../../visitor/interface/modifiable_css.dart';
|
||||
import '../supports_rule.dart';
|
||||
import '../value.dart';
|
||||
import 'node.dart';
|
||||
@ -17,7 +17,8 @@ class ModifiableCssSupportsRule extends ModifiableCssParentNode
|
||||
|
||||
ModifiableCssSupportsRule(this.condition, this.span);
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssSupportsRule(this);
|
||||
T accept<T>(ModifiableCssVisitor<T> visitor) =>
|
||||
visitor.visitCssSupportsRule(this);
|
||||
|
||||
ModifiableCssSupportsRule copyWithoutChildren() =>
|
||||
ModifiableCssSupportsRule(condition, span);
|
||||
|
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import '../selector.dart';
|
||||
import 'node.dart';
|
||||
import 'value.dart';
|
||||
@ -14,4 +15,6 @@ import 'value.dart';
|
||||
abstract class CssStyleRule extends CssParentNode {
|
||||
/// The selector for this rule.
|
||||
CssValue<SelectorList> get selector;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssStyleRule(this);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../visitor/interface/css.dart';
|
||||
import 'node.dart';
|
||||
import 'value.dart';
|
||||
|
||||
@ -9,4 +10,6 @@ import 'value.dart';
|
||||
abstract class CssSupportsRule extends CssParentNode {
|
||||
/// The supports condition.
|
||||
CssValue<String> get condition;
|
||||
|
||||
T accept<T>(CssVisitor<T> visitor) => visitor.visitCssSupportsRule(this);
|
||||
}
|
||||
|
@ -3,11 +3,12 @@
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import '../../ast/css.dart';
|
||||
import 'modifiable_css.dart';
|
||||
|
||||
/// An interface for [visitors][] that traverse CSS statements.
|
||||
///
|
||||
/// [visitors]: https://en.wikipedia.org/wiki/Visitor_pattern
|
||||
abstract class CssVisitor<T> {
|
||||
abstract class CssVisitor<T> implements ModifiableCssVisitor<T> {
|
||||
T visitCssAtRule(CssAtRule node);
|
||||
T visitCssComment(CssComment node);
|
||||
T visitCssDeclaration(CssDeclaration node);
|
||||
|
20
lib/src/visitor/interface/modifiable_css.dart
Normal file
20
lib/src/visitor/interface/modifiable_css.dart
Normal file
@ -0,0 +1,20 @@
|
||||
// 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 '../../ast/css/modifiable.dart';
|
||||
|
||||
/// An interface for [visitors][] that traverse CSS statements.
|
||||
///
|
||||
/// [visitors]: https://en.wikipedia.org/wiki/Visitor_pattern
|
||||
abstract class ModifiableCssVisitor<T> {
|
||||
T visitCssAtRule(ModifiableCssAtRule node);
|
||||
T visitCssComment(ModifiableCssComment node);
|
||||
T visitCssDeclaration(ModifiableCssDeclaration node);
|
||||
T visitCssImport(ModifiableCssImport node);
|
||||
T visitCssKeyframeBlock(ModifiableCssKeyframeBlock node);
|
||||
T visitCssMediaRule(ModifiableCssMediaRule node);
|
||||
T visitCssStyleRule(ModifiableCssStyleRule node);
|
||||
T visitCssStylesheet(ModifiableCssStylesheet node);
|
||||
T visitCssSupportsRule(ModifiableCssSupportsRule node);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user