Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature.use' into merge-use
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 24, 2019
2 parents b5de9d2 + 19cfb63 commit 174ef12
Show file tree
Hide file tree
Showing 37 changed files with 3,080 additions and 1,680 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
## 1.21.1
## 1.22.0

* Produce better stack traces when importing a file that contains a syntax
error.

* Make deprecation warnings for `!global` variable declarations that create new
variables clearer, especially in the case where the `!global` flag is
unnecessary because the variables are at the top level of the stylesheet.

### Dart API

* Add a `Value.realNull` getter, which returns Dart's `null` if the value is
Sass's null.

## 1.21.0

### Dart API
Expand Down
5 changes: 5 additions & 0 deletions lib/src/ast/css/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ class CssStylesheet extends CssParentNode {
// whole thing consistently represent mutation of the underlying data.
: children = UnmodifiableListView(children);

/// Creates an empty stylesheet with the given source URL.
CssStylesheet.empty({url})
: children = const [],
span = SourceFile.decoded(const [], url: url).span(0, 0);

T accept<T>(CssVisitor<T> visitor) => visitor.visitCssStylesheet(this);
}
1 change: 1 addition & 0 deletions lib/src/ast/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export 'sass/statement/each_rule.dart';
export 'sass/statement/error_rule.dart';
export 'sass/statement/extend_rule.dart';
export 'sass/statement/for_rule.dart';
export 'sass/statement/forward_rule.dart';
export 'sass/statement/function_rule.dart';
export 'sass/statement/if_rule.dart';
export 'sass/statement/import_rule.dart';
Expand Down
126 changes: 126 additions & 0 deletions lib/src/ast/sass/statement/forward_rule.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// 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:collection/collection.dart';
import 'package:source_span/source_span.dart';

import '../../../utils.dart';
import '../../../visitor/interface/statement.dart';
import '../expression/string.dart';
import '../statement.dart';

/// A `@forward` rule.
class ForwardRule implements Statement {
/// The URI of the module to forward.
///
/// If this is relative, it's relative to the containing file.
final Uri url;

/// The set of mixin and function names that may be accessed from the
/// forwarded module.
///
/// If this is empty, no mixins or functions may be accessed. If it's `null`,
/// it imposes no restrictions on which mixins and function may be accessed.
///
/// If this is non-`null`, [hiddenMixinsAndFunctions] and [hiddenVariables]
/// are guaranteed to both be `null` and [shownVariables] is guaranteed to be
/// non-`null`.
final Set<String> shownMixinsAndFunctions;

/// The set of variable names (without `$`) that may be accessed from the
/// forwarded module.
///
/// If this is empty, no variables may be accessed. If it's `null`, it imposes
/// no restrictions on which variables may be accessed.
///
/// If this is non-`null`, [hiddenMixinsAndFunctions] and [hiddenVariables]
/// are guaranteed to both be `null` and [shownMixinsAndFunctions] is
/// guaranteed to be non-`null`.
final Set<String> shownVariables;

/// The set of mixin and function names that may not be accessed from the
/// forwarded module.
///
/// If this is empty, any mixins or functions may be accessed. If it's `null`,
/// it imposes no restrictions on which mixins or functions may be accessed.
///
/// If this is non-`null`, [shownMixinsAndFunctions] and [shownVariables] are
/// guaranteed to both be `null` and [hiddenVariables] is guaranteed to be
/// non-`null`.
final Set<String> hiddenMixinsAndFunctions;

/// The set of variable names (without `$`) that may be accessed from the
/// forwarded module.
///
/// If this is empty, any variables may be accessed. If it's `null`, it
/// imposes no restrictions on which variables may be accessed.
///
/// If this is non-`null`, [shownMixinsAndFunctions] and [shownVariables] are
/// guaranteed to both be `null` and [hiddenMixinsAndFunctions] is guaranteed
/// to be non-`null`.
final Set<String> hiddenVariables;

/// The prefix to add to the beginning of the names of members of the used
/// module, or `null` if member names are used as-is.
final String prefix;

final FileSpan span;

/// Creates a `@forward` rule that allows all members to be accessed.
ForwardRule(this.url, this.span, {this.prefix})
: shownMixinsAndFunctions = null,
shownVariables = null,
hiddenMixinsAndFunctions = null,
hiddenVariables = null;

/// Creates a `@forward` rule that allows only members included in
/// [shownMixinsAndFunctions] and [shownVariables] to be accessed.
ForwardRule.show(this.url, Iterable<String> shownMixinsAndFunctions,
Iterable<String> shownVariables, this.span,
{this.prefix})
: shownMixinsAndFunctions =
UnmodifiableSetView(normalizedSet(shownMixinsAndFunctions)),
shownVariables = UnmodifiableSetView(normalizedSet(shownVariables)),
hiddenMixinsAndFunctions = null,
hiddenVariables = null;

/// Creates a `@forward` rule that allows only members not included in
/// [hiddenMixinsAndFunctions] and [hiddenVariables] to be accessed.
ForwardRule.hide(this.url, Iterable<String> hiddenMixinsAndFunctions,
Iterable<String> hiddenVariables, this.span,
{this.prefix})
: shownMixinsAndFunctions = null,
shownVariables = null,
hiddenMixinsAndFunctions =
UnmodifiableSetView(normalizedSet(hiddenMixinsAndFunctions)),
hiddenVariables = UnmodifiableSetView(normalizedSet(hiddenVariables));

T accept<T>(StatementVisitor<T> visitor) => visitor.visitForwardRule(this);

String toString() {
var buffer =
StringBuffer("@forward ${StringExpression.quoteText(url.toString())}");

if (shownMixinsAndFunctions != null) {
buffer
..write(" show ")
..write(_memberList(shownMixinsAndFunctions, shownVariables));
} else if (hiddenMixinsAndFunctions != null) {
buffer
..write(" hide ")
..write(_memberList(hiddenMixinsAndFunctions, hiddenVariables));
}

if (prefix != null) buffer.write(" as $prefix*");
buffer.write(";");
return buffer.toString();
}

/// Returns a combined list of names of the given members.
String _memberList(
Iterable<String> mixinsAndFunctions, Iterable<String> variables) =>
shownMixinsAndFunctions
.followedBy(shownVariables.map((name) => "\$$name"))
.join(", ");
}
Loading

0 comments on commit 174ef12

Please sign in to comment.