-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared interfaces for various AST nodes
Fixes #1401 and #1414. Adds `Dependency`, `SassDeclaration`, and `SassReference` interfaces, which expose some getters that multiple AST nodes have in common with a single type. These also add getters for common subspans (URL, name, and namespace) to the interfaces. To allow for `FunctionExpression` to have a common interface with the other two reference nodes, its old `name` getter has been renamed to `interpolatedName`, and the new `name` getter now is either just a string, or null if the name is interpolated.
- Loading branch information
Showing
22 changed files
with
208 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2021 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 'package:source_span/source_span.dart'; | ||
|
||
import '../node.dart'; | ||
|
||
/// A common interface any node that declares a Sass member. | ||
/// | ||
/// {@category AST} | ||
@sealed | ||
abstract class SassDeclaration extends SassNode { | ||
/// The name of the declaration, with underscores converted to hyphens. | ||
/// | ||
/// This does not include the `$` for variables. | ||
String get name; | ||
|
||
/// The span containing this declaration's name. | ||
/// | ||
/// This includes the `$` for variables. | ||
FileSpan get nameSpan; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2021 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 'package:source_span/source_span.dart'; | ||
|
||
import '../node.dart'; | ||
|
||
/// A common interface for [UseRule]s, [ForwardRule]s, and [DynamicImport]s. | ||
/// | ||
/// {@category AST} | ||
@sealed | ||
abstract class Dependency extends SassNode { | ||
/// The URL of the dependency this rule loads. | ||
Uri get url; | ||
|
||
/// The span of the URL for this dependency, including the quotes. | ||
FileSpan get urlSpan; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2021 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 'package:source_span/source_span.dart'; | ||
|
||
import '../node.dart'; | ||
|
||
/// A common interface any node that references a Sass member. | ||
/// | ||
/// {@category AST} | ||
@sealed | ||
abstract class SassReference extends SassNode { | ||
/// The namespace of the member being referenced, or `null` if it's referenced | ||
/// without a namespace. | ||
String? get namespace; | ||
|
||
/// The name of the member being referenced, with underscores converted to | ||
/// hyphens. | ||
/// | ||
/// For [VariableExpression]s and [IncludeRule]s, this will never be null. | ||
/// For [FunctionExpression]s, this will be null if the actual name is an | ||
/// interpolation (in which case this is a plain CSS function, not a reference | ||
/// to a Sass function). | ||
/// | ||
/// This does not include the `$` for variables. | ||
String? get name; | ||
|
||
/// The span containing this reference's name. | ||
/// | ||
/// For variables, this should include the `$`. | ||
FileSpan get nameSpan; | ||
|
||
/// The span containing this reference's namespace, or an empty span | ||
/// immediately before the name if the namespace is null. | ||
FileSpan get namespaceSpan; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.