-
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 (#1445)
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.
- Loading branch information
Showing
30 changed files
with
425 additions
and
119 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
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 for 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 SassDependency 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
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,35 @@ | ||
// 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 '../../../visitor/interface/expression.dart'; | ||
import '../expression.dart'; | ||
import '../argument_invocation.dart'; | ||
import '../callable_invocation.dart'; | ||
import '../interpolation.dart'; | ||
|
||
/// An interpolated function invocation. | ||
/// | ||
/// This is always a plain CSS function. | ||
/// | ||
/// {@category AST} | ||
@sealed | ||
class InterpolatedFunctionExpression implements Expression, CallableInvocation { | ||
/// The name of the function being invoked. | ||
final Interpolation name; | ||
|
||
/// The arguments to pass to the function. | ||
final ArgumentInvocation arguments; | ||
|
||
final FileSpan span; | ||
|
||
InterpolatedFunctionExpression(this.name, this.arguments, this.span); | ||
|
||
T accept<T>(ExpressionVisitor<T> visitor) => | ||
visitor.visitInterpolatedFunctionExpression(this); | ||
|
||
String toString() => '$name$arguments'; | ||
} |
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,33 @@ | ||
// 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 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. | ||
/// | ||
/// 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, null if [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
Oops, something went wrong.