Stylesheet.parse constructor

Stylesheet.parse(
  1. String contents,
  2. Syntax syntax, {
  3. Object? url,
  4. Logger? logger,
})

Parses a stylesheet from contents according to syntax.

If passed, url is the name of the file from which contents comes.

Throws a SassFormatException if parsing fails.

Implementation

factory Stylesheet.parse(String contents, Syntax syntax,
    {Object? url, Logger? logger}) {
  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, stackTrace) {
    var url = error.span.sourceUrl;
    if (url == null || url.toString() == 'stdin') rethrow;

    throw throwWithTrace(
        error.withLoadedUrls(Set.unmodifiable({url})), error, stackTrace);
  }
}