From 760fa2ead15e5e5e0cea2a5456ad23f8a3b6576f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Fri, 9 Jun 2023 13:41:25 -0700 Subject: [PATCH] Add current stylesheet to loadedUrls when throwing parsing error (#1991) Co-authored-by: Natalie Weizenbaum --- CHANGELOG.md | 7 ++++++ lib/src/ast/sass/statement/stylesheet.dart | 25 ++++++++++++++-------- pubspec.yaml | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b754168ab..516a8d53e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.63.4 + +### Embedded Sass + +* Properly include the root stylesheet's URL in the set of loaded URLs when it + fails to parse. + ## 1.63.3 ### JavaScript API diff --git a/lib/src/ast/sass/statement/stylesheet.dart b/lib/src/ast/sass/statement/stylesheet.dart index b0acd1218..709509e0d 100644 --- a/lib/src/ast/sass/statement/stylesheet.dart +++ b/lib/src/ast/sass/statement/stylesheet.dart @@ -76,15 +76,22 @@ class Stylesheet extends ParentStatement> { /// Throws a [SassFormatException] if parsing fails. factory Stylesheet.parse(String contents, Syntax syntax, {Object? url, Logger? logger}) { - switch (syntax) { - case Syntax.sass: - return Stylesheet.parseSass(contents, url: url, logger: logger); - case Syntax.scss: - return Stylesheet.parseScss(contents, url: url, logger: logger); - case Syntax.css: - return Stylesheet.parseCss(contents, url: url, logger: logger); - default: - throw ArgumentError("Unknown syntax $syntax."); + try { + switch (syntax) { + case Syntax.sass: + return Stylesheet.parseSass(contents, url: url, logger: logger); + case Syntax.scss: + return Stylesheet.parseScss(contents, url: url, logger: logger); + case Syntax.css: + return Stylesheet.parseCss(contents, url: url, logger: logger); + default: + throw ArgumentError("Unknown syntax $syntax."); + } + } on SassException catch (error) { + var url = error.span.sourceUrl; + if (url == null || url.toString() == 'stdin') rethrow; + + throw error.withLoadedUrls(Set.unmodifiable({url})); } } diff --git a/pubspec.yaml b/pubspec.yaml index 7b3846ba5..2a416f0ed 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.63.3 +version: 1.63.4-dev description: A Sass implementation in Dart. homepage: https://github.com/sass/dart-sass