Skip to content

Commit

Permalink
Emit all warnings in the evaluator (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak authored Oct 18, 2024
1 parent 01b2a5b commit 60d440a
Show file tree
Hide file tree
Showing 43 changed files with 340 additions and 396 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.80.3

* Improve consistency of how warnings are emitted by different parts of the
compiler. This should result in minimal user-visible changes, but different
types of warnings should now respond more reliably to flags like `--quiet`,
`--verbose`, and `--silence-deprecation`.

## 1.80.2

* Fix a bug where deprecation warnings were incorrectly emitted for the
Expand Down
12 changes: 6 additions & 6 deletions bin/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ Future<void> main(List<String> args) async {
return;
}

// Eagerly check these so that we fail here and don't hang in watch mode.
options.silenceDeprecations;
options.futureDeprecations;
options.fatalDeprecations;

var graph = StylesheetGraph(ImportCache(
importers: [...options.pkgImporters, FilesystemImporter.noLoadPath],
loadPaths: options.loadPaths,
logger: ImportCache.wrapLogger(
options.logger,
options.silenceDeprecations,
options.fatalDeprecations,
options.futureDeprecations)));
loadPaths: options.loadPaths));
if (options.watch) {
await watch(options, graph);
return;
Expand Down
12 changes: 0 additions & 12 deletions lib/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ CompileResult compileToResult(String path,
logger: logger,
importCache: ImportCache(
importers: importers,
logger: ImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
loadPaths: loadPaths,
packageConfig: packageConfig),
functions: functions,
Expand Down Expand Up @@ -224,9 +221,6 @@ CompileResult compileStringToResult(String source,
logger: logger,
importCache: ImportCache(
importers: importers,
logger: ImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
packageConfig: packageConfig,
loadPaths: loadPaths),
functions: functions,
Expand Down Expand Up @@ -265,9 +259,6 @@ Future<CompileResult> compileToResultAsync(String path,
logger: logger,
importCache: AsyncImportCache(
importers: importers,
logger: AsyncImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
loadPaths: loadPaths,
packageConfig: packageConfig),
functions: functions,
Expand Down Expand Up @@ -310,9 +301,6 @@ Future<CompileResult> compileStringToResultAsync(String source,
logger: logger,
importCache: AsyncImportCache(
importers: importers,
logger: AsyncImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
packageConfig: packageConfig,
loadPaths: loadPaths),
functions: functions,
Expand Down
6 changes: 2 additions & 4 deletions lib/src/ast/css/media_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://opensource.org/licenses/MIT.

import '../../interpolation_map.dart';
import '../../logger.dart';
import '../../parse/media_query.dart';
import '../../utils.dart';

Expand Down Expand Up @@ -44,9 +43,8 @@ final class CssMediaQuery {
///
/// Throws a [SassFormatException] if parsing fails.
static List<CssMediaQuery> parseList(String contents,
{Object? url, Logger? logger, InterpolationMap? interpolationMap}) =>
MediaQueryParser(contents,
url: url, logger: logger, interpolationMap: interpolationMap)
{Object? url, InterpolationMap? interpolationMap}) =>
MediaQueryParser(contents, url: url, interpolationMap: interpolationMap)
.parse();

/// Creates a media query specifies a type and, optionally, conditions.
Expand Down
6 changes: 2 additions & 4 deletions lib/src/ast/sass/argument_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:source_span/source_span.dart';

import '../../exception.dart';
import '../../logger.dart';
import '../../parse/scss.dart';
import '../../util/character.dart';
import '../../util/span.dart';
Expand Down Expand Up @@ -71,9 +70,8 @@ final class ArgumentDeclaration implements SassNode {
/// If passed, [url] is the name of the file from which [contents] comes.
///
/// Throws a [SassFormatException] if parsing fails.
factory ArgumentDeclaration.parse(String contents,
{Object? url, Logger? logger}) =>
ScssParser(contents, url: url, logger: logger).parseArgumentDeclaration();
factory ArgumentDeclaration.parse(String contents, {Object? url}) =>
ScssParser(contents, url: url).parseArgumentDeclaration();

/// Throws a [SassScriptException] if [positional] and [names] aren't valid
/// for this argument declaration.
Expand Down
5 changes: 2 additions & 3 deletions lib/src/ast/sass/at_root_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:collection/collection.dart';

import '../../exception.dart';
import '../../interpolation_map.dart';
import '../../logger.dart';
import '../../parse/at_root_query.dart';
import '../css.dart';

Expand Down Expand Up @@ -58,8 +57,8 @@ final class AtRootQuery {
///
/// Throws a [SassFormatException] if parsing fails.
factory AtRootQuery.parse(String contents,
{Object? url, Logger? logger, InterpolationMap? interpolationMap}) =>
AtRootQueryParser(contents, url: url, logger: logger).parse();
{Object? url, InterpolationMap? interpolationMap}) =>
AtRootQueryParser(contents, url: url).parse();

/// Returns whether `this` excludes [node].
///
Expand Down
5 changes: 2 additions & 3 deletions lib/src/ast/sass/expression.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:meta/meta.dart';

import '../../exception.dart';
import '../../logger.dart';
import '../../parse/scss.dart';
import '../../visitor/interface/expression.dart';
import '../../visitor/is_calculation_safe.dart';
Expand Down Expand Up @@ -50,6 +49,6 @@ abstract class Expression implements SassNode {
/// If passed, [url] is the name of the file from which [contents] comes.
///
/// Throws a [SassFormatException] if parsing fails.
factory Expression.parse(String contents, {Object? url, Logger? logger}) =>
ScssParser(contents, url: url, logger: logger).parseExpression();
factory Expression.parse(String contents, {Object? url}) =>
ScssParser(contents, url: url).parseExpression().$1;
}
45 changes: 29 additions & 16 deletions lib/src/ast/sass/statement/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'dart:collection';
import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

import '../../../deprecation.dart';
import '../../../exception.dart';
import '../../../logger.dart';
import '../../../parse/css.dart';
import '../../../parse/sass.dart';
import '../../../parse/scss.dart';
Expand Down Expand Up @@ -46,16 +46,25 @@ final class Stylesheet extends ParentStatement<List<Statement>> {
List<ForwardRule> get forwards => UnmodifiableListView(_forwards);
final _forwards = <ForwardRule>[];

/// List of warnings discovered while parsing this stylesheet, to be emitted
/// during evaluation once we have a proper logger to use.
///
/// @nodoc
@internal
final List<ParseTimeWarning> parseTimeWarnings;

Stylesheet(Iterable<Statement> children, FileSpan span)
: this.internal(children, span);
: this.internal(children, span, []);

/// A separate internal constructor that allows [plainCss] to be set.
///
/// @nodoc
@internal
Stylesheet.internal(Iterable<Statement> children, this.span,
List<ParseTimeWarning> parseTimeWarnings,
{this.plainCss = false})
: super(List.unmodifiable(children)) {
: parseTimeWarnings = UnmodifiableListView(parseTimeWarnings),
super(List.unmodifiable(children)) {
loop:
for (var child in this.children) {
switch (child) {
Expand All @@ -81,16 +90,15 @@ final class Stylesheet extends ParentStatement<List<Statement>> {
/// If passed, [url] is the name of the file from which [contents] comes.
///
/// Throws a [SassFormatException] if parsing fails.
factory Stylesheet.parse(String contents, Syntax syntax,
{Object? url, Logger? logger}) {
factory Stylesheet.parse(String contents, Syntax syntax, {Object? url}) {
try {
switch (syntax) {
case Syntax.sass:
return Stylesheet.parseSass(contents, url: url, logger: logger);
return Stylesheet.parseSass(contents, url: url);
case Syntax.scss:
return Stylesheet.parseScss(contents, url: url, logger: logger);
return Stylesheet.parseScss(contents, url: url);
case Syntax.css:
return Stylesheet.parseCss(contents, url: url, logger: logger);
return Stylesheet.parseCss(contents, url: url);
}
} on SassException catch (error, stackTrace) {
var url = error.span.sourceUrl;
Expand All @@ -106,28 +114,33 @@ final class Stylesheet extends ParentStatement<List<Statement>> {
/// If passed, [url] is the name of the file from which [contents] comes.
///
/// Throws a [SassFormatException] if parsing fails.
factory Stylesheet.parseSass(String contents,
{Object? url, Logger? logger}) =>
SassParser(contents, url: url, logger: logger).parse();
factory Stylesheet.parseSass(String contents, {Object? url}) =>
SassParser(contents, url: url).parse();

/// Parses an SCSS stylesheet from [contents].
///
/// If passed, [url] is the name of the file from which [contents] comes.
///
/// Throws a [SassFormatException] if parsing fails.
factory Stylesheet.parseScss(String contents,
{Object? url, Logger? logger}) =>
ScssParser(contents, url: url, logger: logger).parse();
factory Stylesheet.parseScss(String contents, {Object? url}) =>
ScssParser(contents, url: url).parse();

/// Parses a plain CSS stylesheet from [contents].
///
/// If passed, [url] is the name of the file from which [contents] comes.
///
/// Throws a [SassFormatException] if parsing fails.
factory Stylesheet.parseCss(String contents, {Object? url, Logger? logger}) =>
CssParser(contents, url: url, logger: logger).parse();
factory Stylesheet.parseCss(String contents, {Object? url}) =>
CssParser(contents, url: url).parse();

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

String toString() => children.join(" ");
}

/// Record type for a warning discovered while parsing a stylesheet.
typedef ParseTimeWarning = ({
Deprecation? deprecation,
FileSpan span,
String message
});
5 changes: 2 additions & 3 deletions lib/src/ast/sass/statement/use_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

import '../../../exception.dart';
import '../../../logger.dart';
import '../../../parse/scss.dart';
import '../../../util/span.dart';
import '../../../visitor/interface/statement.dart';
Expand Down Expand Up @@ -56,8 +55,8 @@ final class UseRule extends Statement implements SassDependency {
///
/// @nodoc
@internal
factory UseRule.parse(String contents, {Object? url, Logger? logger}) =>
ScssParser(contents, url: url, logger: logger).parseUseRule();
factory UseRule.parse(String contents, {Object? url}) =>
ScssParser(contents, url: url).parseUseRule().$1;

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

Expand Down
6 changes: 2 additions & 4 deletions lib/src/ast/sass/statement/variable_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

import '../../../exception.dart';
import '../../../logger.dart';
import '../../../parse/scss.dart';
import '../../../utils.dart';
import '../../../util/span.dart';
Expand Down Expand Up @@ -81,9 +80,8 @@ final class VariableDeclaration extends Statement implements SassDeclaration {
///
/// @nodoc
@internal
factory VariableDeclaration.parse(String contents,
{Object? url, Logger? logger}) =>
ScssParser(contents, url: url, logger: logger).parseVariableDeclaration();
factory VariableDeclaration.parse(String contents, {Object? url}) =>
ScssParser(contents, url: url).parseVariableDeclaration().$1;

T accept<T>(StatementVisitor<T> visitor) =>
visitor.visitVariableDeclaration(this);
Expand Down
6 changes: 2 additions & 4 deletions lib/src/ast/selector/complex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

import '../../extend/functions.dart';
import '../../logger.dart';
import '../../parse/selector.dart';
import '../../utils.dart';
import '../../visitor/interface/selector.dart';
Expand Down Expand Up @@ -88,9 +87,8 @@ final class ComplexSelector extends Selector {
///
/// Throws a [SassFormatException] if parsing fails.
factory ComplexSelector.parse(String contents,
{Object? url, Logger? logger, bool allowParent = true}) =>
SelectorParser(contents,
url: url, logger: logger, allowParent: allowParent)
{Object? url, bool allowParent = true}) =>
SelectorParser(contents, url: url, allowParent: allowParent)
.parseComplexSelector();

T accept<T>(SelectorVisitor<T> visitor) => visitor.visitComplexSelector(this);
Expand Down
6 changes: 2 additions & 4 deletions lib/src/ast/selector/compound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:meta/meta.dart';

import '../../extend/functions.dart';
import '../../logger.dart';
import '../../parse/selector.dart';
import '../../utils.dart';
import '../../visitor/interface/selector.dart';
Expand Down Expand Up @@ -69,9 +68,8 @@ final class CompoundSelector extends Selector {
///
/// Throws a [SassFormatException] if parsing fails.
factory CompoundSelector.parse(String contents,
{Object? url, Logger? logger, bool allowParent = true}) =>
SelectorParser(contents,
url: url, logger: logger, allowParent: allowParent)
{Object? url, bool allowParent = true}) =>
SelectorParser(contents, url: url, allowParent: allowParent)
.parseCompoundSelector();

T accept<T>(SelectorVisitor<T> visitor) =>
Expand Down
3 changes: 0 additions & 3 deletions lib/src/ast/selector/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:meta/meta.dart';
import '../../exception.dart';
import '../../extend/functions.dart';
import '../../interpolation_map.dart';
import '../../logger.dart';
import '../../parse/selector.dart';
import '../../utils.dart';
import '../../util/iterable.dart';
Expand Down Expand Up @@ -68,13 +67,11 @@ final class SelectorList extends Selector {
/// Throws a [SassFormatException] if parsing fails.
factory SelectorList.parse(String contents,
{Object? url,
Logger? logger,
InterpolationMap? interpolationMap,
bool allowParent = true,
bool plainCss = false}) =>
SelectorParser(contents,
url: url,
logger: logger,
interpolationMap: interpolationMap,
allowParent: allowParent,
plainCss: plainCss)
Expand Down
6 changes: 2 additions & 4 deletions lib/src/ast/selector/simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:meta/meta.dart';

import '../../exception.dart';
import '../../logger.dart';
import '../../parse/selector.dart';
import '../selector.dart';

Expand Down Expand Up @@ -54,9 +53,8 @@ abstract base class SimpleSelector extends Selector {
///
/// Throws a [SassFormatException] if parsing fails.
factory SimpleSelector.parse(String contents,
{Object? url, Logger? logger, bool allowParent = true}) =>
SelectorParser(contents,
url: url, logger: logger, allowParent: allowParent)
{Object? url, bool allowParent = true}) =>
SelectorParser(contents, url: url, allowParent: allowParent)
.parseSimpleSelector();

/// Returns a new [SimpleSelector] based on `this`, as though it had been
Expand Down
7 changes: 3 additions & 4 deletions lib/src/async_compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ Future<CompileResult> compileAsync(String path,
Stylesheet? stylesheet;
if (nodeImporter == null &&
(syntax == null || syntax == Syntax.forPath(path))) {
importCache ??= AsyncImportCache.none(logger: logger);
importCache ??= AsyncImportCache.none();
stylesheet = (await importCache.importCanonical(
FilesystemImporter.cwd, p.toUri(canonicalize(path)),
originalUrl: p.toUri(path)))!;
} else {
stylesheet = Stylesheet.parse(
readFile(path), syntax ?? Syntax.forPath(path),
url: p.toUri(path), logger: logger);
url: p.toUri(path));
}

var result = await _compileStylesheet(
Expand Down Expand Up @@ -120,8 +120,7 @@ Future<CompileResult> compileStringAsync(String source,
limitRepetition: !verbose)
..validate();

var stylesheet =
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);
var stylesheet = Stylesheet.parse(source, syntax ?? Syntax.scss, url: url);

var result = await _compileStylesheet(
stylesheet,
Expand Down
Loading

0 comments on commit 60d440a

Please sign in to comment.