Don't crash when passing includePaths with importer

Closes #412
This commit is contained in:
Natalie Weizenbaum 2018-07-23 16:20:06 -07:00
parent b5c9ed41b9
commit e1750216ee
5 changed files with 44 additions and 2 deletions

View File

@ -1,3 +1,9 @@
## 1.10.1
### Node JS API
* Don't crash when passing both `includePaths` and `importer`.
## 1.10.0
* When two `@media` rules' queries can't be merged, leave nested rules in place

View File

@ -259,7 +259,7 @@ NodeImporter _parseImporter(RenderOptions options, DateTime start) {
importers = [options.importer as JSFunction];
}
var includePaths = options.includePaths ?? [];
var includePaths = new List<String>.from(options.includePaths ?? []);
RenderContext context;
if (importers.isNotEmpty) {

View File

@ -1,5 +1,5 @@
name: sass
version: 1.10.0
version: 1.10.1
description: A Sass implementation in Dart.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/sass/dart-sass

View File

@ -4,11 +4,13 @@
import 'dart:async';
import 'dart:convert';
import 'dart:js_util';
import 'package:js/js.dart';
import 'package:test/test.dart';
import 'package:sass/src/io.dart';
import 'package:sass/src/node/function.dart';
import '../hybrid.dart';
import 'api.dart';
@ -60,6 +62,17 @@ Future<RenderError> renderError(RenderOptions options) {
String renderSync(RenderOptions options) =>
utf8.decode(sass.renderSync(options).css);
/// Like [renderSync], but goes through the untyped JS API.
///
/// This lets us test that we properly cast untyped collections without throwing
/// type errors.
String renderSyncJS(Map<String, Object> options) {
var result = _renderSyncJS.call(sass, jsify(options)) as RenderResult;
return utf8.decode(result.css);
}
final _renderSyncJS = new JSFunction("sass", "args", "return sass.renderSync(args);");
/// Asserts that rendering via [options] produces an error, and returns that
/// error.
RenderError renderSyncError(RenderOptions options) {

View File

@ -6,6 +6,7 @@
@Tags(const ['node'])
import 'dart:convert';
import 'dart:js';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
@ -420,6 +421,28 @@ a {
});
});
});
group("when called with a raw JS collection", () {
test("for includePaths", () {
expect(
renderSyncJS({
"data": "@import 'test'",
"includePaths": [sandbox]
}),
equalsIgnoringWhitespace('a { b: c; }'));
});
// Regression test for #412
test("for includePaths with an importer", () {
expect(
renderSyncJS({
"data": "@import 'test'",
"includePaths": [sandbox],
"importer": allowInterop((url, prev) => null)
}),
equalsIgnoringWhitespace('a { b: c; }'));
});
});
});
group("render()", () {