Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to null safety (WIP) #1253

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions lib/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// We strongly recommend importing this library with the prefix `sass`.
library sass;

import 'package:package_config/package_config_types.dart';
import 'package:source_maps/source_maps.dart';

import 'src/async_import_cache.dart';
Expand All @@ -14,7 +15,6 @@ import 'src/exception.dart';
import 'src/import_cache.dart';
import 'src/importer.dart';
import 'src/logger.dart';
import 'src/sync_package_resolver.dart';
import 'src/syntax.dart';
import 'src/visitor/serialize.dart';

Expand Down Expand Up @@ -48,11 +48,11 @@ export 'src/warn.dart' show warn;
/// * Each load path specified in the `SASS_PATH` environment variable, which
/// should be semicolon-separated on Windows and colon-separated elsewhere.
///
/// * `package:` resolution using [packageResolver], which is a
/// [`SyncPackageResolver`][] from the `package_resolver` package. Note that
/// * `package:` resolution using [packageConfig], which is a
/// [`PackageConfig`][] from the `package_resolver` package. Note that
/// this is a shorthand for adding a [PackageImporter] to [importers].
///
/// [`SyncPackageResolver`]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html
/// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html
///
/// Dart functions that can be called from Sass may be passed using [functions].
/// Each [Callable] defines a top-level function that will be invoked when the
Expand Down Expand Up @@ -90,7 +90,7 @@ String compile(String path,
Logger logger,
Iterable<Importer> importers,
Iterable<String> loadPaths,
SyncPackageResolver packageResolver,
PackageConfig packageConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a BC break that requires releasing it as dart-sass 2.0.0 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but we're only making this change because package_resolver is archived and incompatible with the latest versions of other Dart packages. Since this only affects a limited (at this point, possibly non-existent) subset of Dart API users and pub's version resolution will prevent them from updating to any version of Dart Sass that depends on the null-safe versions of these packages anyway, I think the current plan is to make this change without bumping the major version.

Iterable<Callable> functions,
OutputStyle style,
void sourceMap(SingleMapping map),
Expand All @@ -99,9 +99,7 @@ String compile(String path,
var result = c.compile(path,
logger: logger,
importCache: ImportCache(importers,
logger: logger,
loadPaths: loadPaths,
packageResolver: packageResolver),
logger: logger, loadPaths: loadPaths, packageConfig: packageConfig),
functions: functions,
style: style,
sourceMap: sourceMap != null,
Expand Down Expand Up @@ -132,11 +130,11 @@ String compile(String path,
/// * Each load path specified in the `SASS_PATH` environment variable, which
/// should be semicolon-separated on Windows and colon-separated elsewhere.
///
/// * `package:` resolution using [packageResolver], which is a
/// [`SyncPackageResolver`][] from the `package_resolver` package. Note that
/// * `package:` resolution using [packageConfig], which is a
/// [`PackageConfig`][] from the `package_resolver` package. Note that
/// this is a shorthand for adding a [PackageImporter] to [importers].
///
/// [`SyncPackageResolver`]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html
/// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html
///
/// Dart functions that can be called from Sass may be passed using [functions].
/// Each [Callable] defines a top-level function that will be invoked when the
Expand Down Expand Up @@ -178,7 +176,7 @@ String compileString(String source,
bool color = false,
Logger logger,
Iterable<Importer> importers,
SyncPackageResolver packageResolver,
PackageConfig packageConfig,
Iterable<String> loadPaths,
Iterable<Callable> functions,
OutputStyle style,
Expand All @@ -192,9 +190,7 @@ String compileString(String source,
syntax: syntax ?? (indented ? Syntax.sass : Syntax.scss),
logger: logger,
importCache: ImportCache(importers,
logger: logger,
packageResolver: packageResolver,
loadPaths: loadPaths),
logger: logger, packageConfig: packageConfig, loadPaths: loadPaths),
functions: functions,
style: style,
importer: importer,
Expand All @@ -214,7 +210,7 @@ Future<String> compileAsync(String path,
{bool color = false,
Logger logger,
Iterable<AsyncImporter> importers,
SyncPackageResolver packageResolver,
PackageConfig packageConfig,
Iterable<String> loadPaths,
Iterable<AsyncCallable> functions,
OutputStyle style,
Expand All @@ -223,9 +219,7 @@ Future<String> compileAsync(String path,
var result = await c.compileAsync(path,
logger: logger,
importCache: AsyncImportCache(importers,
logger: logger,
loadPaths: loadPaths,
packageResolver: packageResolver),
logger: logger, loadPaths: loadPaths, packageConfig: packageConfig),
functions: functions,
style: style,
sourceMap: sourceMap != null);
Expand All @@ -243,7 +237,7 @@ Future<String> compileStringAsync(String source,
bool color = false,
Logger logger,
Iterable<AsyncImporter> importers,
SyncPackageResolver packageResolver,
PackageConfig packageConfig,
Iterable<String> loadPaths,
Iterable<AsyncCallable> functions,
OutputStyle style,
Expand All @@ -257,9 +251,7 @@ Future<String> compileStringAsync(String source,
syntax: syntax ?? (indented ? Syntax.sass : Syntax.scss),
logger: logger,
importCache: AsyncImportCache(importers,
logger: logger,
packageResolver: packageResolver,
loadPaths: loadPaths),
logger: logger, packageConfig: packageConfig, loadPaths: loadPaths),
functions: functions,
style: style,
importer: importer,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/argument_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ArgumentDeclaration implements SassNode {

/// Returns [span] expanded to include an identifier immediately before the
/// declaration, if possible.
FileSpan get spanWithName {
FileSpan/*!*/ get spanWithName {
var text = span.file.getText(0);

// Move backwards through and whitspace between the name and the arguments.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/argument_invocation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ArgumentInvocation implements SassNode {
bool get isEmpty => positional.isEmpty && named.isEmpty && rest == null;

ArgumentInvocation(
Iterable<Expression> positional, Map<String, Expression> named, this.span,
Iterable<Expression/*!*/> positional, Map<String, Expression/*!*/> named, this.span,
{this.rest, this.keywordRest})
: positional = List.unmodifiable(positional),
named = Map.unmodifiable(named) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/at_root_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AtRootQuery {
AtRootQueryParser(contents, url: url, logger: logger).parse();

/// Returns whether [this] excludes [node].
bool excludes(CssParentNode node) {
bool excludes(CssParentNode/*!*/ node) {
if (_all) return !include;
if (node is CssStyleRule) return excludesStyleRules;
if (node is CssMediaRule) return excludesName("media");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/configured_variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConfiguredVariable implements SassNode {
final String name;

/// The variable's value.
final Expression expression;
final Expression/*!*/ expression;

/// Whether the variable can be further configured by outer modules.
///
Expand Down
4 changes: 2 additions & 2 deletions lib/src/ast/sass/expression/binary_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class BinaryOperationExpression implements Expression {
final BinaryOperator operator;

/// The left-hand operand.
final Expression left;
final Expression /*!*/ left;

/// The right-hand operand.
final Expression right;
final Expression /*!*/ right;

/// Whether this is a [BinaryOperator.dividedBy] operation that may be
/// interpreted as slash-separated numbers.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/expression/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../expression.dart';
/// A color literal.
class ColorExpression implements Expression {
/// The value of this color.
final SassColor value;
final SassColor/*!*/ value;

FileSpan get span => value.originalSpan;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/expression/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ListExpression implements Expression {

final FileSpan span;

ListExpression(Iterable<Expression> contents, ListSeparator separator,
ListExpression(Iterable<Expression/*!*/> contents, ListSeparator separator,
{bool brackets = false, FileSpan span})
: this._(List.unmodifiable(contents), separator, brackets, span);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/expression/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MapExpression implements Expression {

final FileSpan span;

MapExpression(Iterable<Tuple2<Expression, Expression>> pairs, this.span)
MapExpression(Iterable<Tuple2<Expression/*!*/, Expression/*!*/>> pairs, this.span)
: pairs = List.unmodifiable(pairs);

T accept<T>(ExpressionVisitor<T> visitor) => visitor.visitMapExpression(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/expression/parenthesized.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../expression.dart';
/// An expression wrapped in parentheses.
class ParenthesizedExpression implements Expression {
/// The internal expression.
final Expression expression;
final Expression/*!*/ expression;

final FileSpan span;

Expand Down
8 changes: 4 additions & 4 deletions lib/src/ast/sass/expression/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StringExpression implements Expression {

/// Returns Sass source for a quoted string that, when evaluated, will have
/// [text] as its contents.
static String quoteText(String text) =>
static String/*!*/ quoteText(String text) =>
StringExpression.plain(text, null, quotes: true)
.asInterpolation(static: true)
.asPlain;
Expand All @@ -51,9 +51,9 @@ class StringExpression implements Expression {
Interpolation asInterpolation({bool static = false, int quote}) {
if (!hasQuotes) return text;

quote ??= hasQuotes ? _bestQuote() : null;
quote ??= _bestQuote();
var buffer = InterpolationBuffer();
if (quote != null) buffer.writeCharCode(quote);
buffer.writeCharCode(quote);
for (var value in text.contents) {
assert(value is Expression || value is String);
if (value is Expression) {
Expand Down Expand Up @@ -85,7 +85,7 @@ class StringExpression implements Expression {
}
}
}
if (quote != null) buffer.writeCharCode(quote);
buffer.writeCharCode(quote);

return buffer.interpolation(text.span);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/ast/sass/expression/unary_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import '../expression.dart';
/// A unary operator, as in `+$var` or `not fn()`.
class UnaryOperationExpression implements Expression {
/// The operator being invoked.
final UnaryOperator operator;
final UnaryOperator/*!*/ operator;

/// The operand.
final Expression operand;
final Expression/*!*/ operand;

final FileSpan span;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/expression/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import '../expression.dart';
/// constructed dynamically, as for the `call()` function.
class ValueExpression implements Expression {
/// The embedded value.
final Value value;
final Value/*!*/ value;

final FileSpan span;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/interpolation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Interpolation implements SassNode {
return first is String ? first : '';
}

Interpolation(Iterable<Object /* String | Expression */ > contents, this.span)
Interpolation(Iterable<Object/*!*/ /* String | Expression */ > contents, this.span)
: contents = List.unmodifiable(contents) {
for (var i = 0; i < this.contents.length; i++) {
if (this.contents[i] is! String && this.contents[i] is! Expression) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/at_root_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AtRootRule extends ParentStatement {

final FileSpan span;

AtRootRule(Iterable<Statement> children, this.span, {this.query})
AtRootRule(Iterable<Statement/*!*/> children, this.span, {this.query})
: super(List.unmodifiable(children));

T accept<T>(StatementVisitor<T> visitor) => visitor.visitAtRootRule(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/at_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AtRule extends ParentStatement {

final FileSpan span;

AtRule(this.name, this.span, {this.value, Iterable<Statement> children})
AtRule(this.name, this.span, {this.value, Iterable<Statement/*!*/> children})
: super(children == null ? null : List.unmodifiable(children));

T accept<T>(StatementVisitor<T> visitor) => visitor.visitAtRule(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/callable_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class CallableDeclaration extends ParentStatement {
final FileSpan span;

CallableDeclaration(
this.name, this.arguments, Iterable<Statement> children, this.span,
this.name, this.arguments, Iterable<Statement/*!*//*!*/> children, this.span,
{SilentComment comment})
: comment = comment,
super(List.unmodifiable(children));
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/content_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'callable_declaration.dart';

/// An anonymous block of code that's invoked for a [ContentRule].
class ContentBlock extends CallableDeclaration {
ContentBlock(ArgumentDeclaration arguments, Iterable<Statement> children,
ContentBlock(ArgumentDeclaration arguments, Iterable<Statement/*!*/> children,
FileSpan span)
: super(null /* name */, arguments, children, span);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/use_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UseRule implements Statement {
{Iterable<ConfiguredVariable> configuration})
: configuration = configuration == null
? const []
: List.unmodifiable(configuration) {
: List<ConfiguredVariable>.unmodifiable(configuration) {
for (var variable in this.configuration) {
if (variable.isGuarded) {
throw ArgumentError.value(variable, "configured variable",
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/while_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WhileRule extends ParentStatement {
final FileSpan span;

WhileRule(this.condition, Iterable<Statement> children, this.span)
: super(List.unmodifiable(children));
: super(List<Statement>.unmodifiable(children));

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

Expand Down
4 changes: 2 additions & 2 deletions lib/src/ast/sass/supports_condition/declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import '../supports_condition.dart';
/// supported.
class SupportsDeclaration implements SupportsCondition {
/// The name of the declaration being tested.
final Expression name;
final Expression/*!*/ name;

/// The value of the declaration being tested.
final Expression value;
final Expression/*!*/ value;

final FileSpan span;

Expand Down
2 changes: 0 additions & 2 deletions lib/src/async_compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'importer.dart';
import 'importer/node.dart';
import 'io.dart';
import 'logger.dart';
import 'sync_package_resolver.dart';
import 'syntax.dart';
import 'utils.dart';
import 'visitor/async_evaluate.dart';
Expand Down Expand Up @@ -77,7 +76,6 @@ Future<CompileResult> compileStringAsync(String source,
NodeImporter nodeImporter,
Iterable<AsyncImporter> importers,
Iterable<String> loadPaths,
SyncPackageResolver packageResolver,
AsyncImporter importer,
Iterable<AsyncCallable> functions,
OutputStyle style,
Expand Down
Loading