Skip to content

Commit 6552666

Browse files
authored
Merge pull request #422 from sass/include-path-cast
Don't crash when passing includePaths with importer
2 parents b5c9ed4 + 628cf7b commit 6552666

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.10.1
2+
3+
### Node JS API
4+
5+
* Don't crash when passing both `includePaths` and `importer`.
6+
17
## 1.10.0
28

39
* When two `@media` rules' queries can't be merged, leave nested rules in place

lib/src/node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ NodeImporter _parseImporter(RenderOptions options, DateTime start) {
259259
importers = [options.importer as JSFunction];
260260
}
261261

262-
var includePaths = options.includePaths ?? [];
262+
var includePaths = new List<String>.from(options.includePaths ?? []);
263263

264264
RenderContext context;
265265
if (importers.isNotEmpty) {

lib/src/node/render_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RenderOptions {
1313
external String get data;
1414
external dynamic get importer;
1515
external dynamic get functions;
16-
external List<String> get includePaths;
16+
external List get includePaths; // contains Strings
1717
external bool get indentedSyntax;
1818
external bool get omitSourceMapUrl;
1919
external String get outFile;

lib/src/node/render_result.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RenderResultStats {
2424
external int get start;
2525
external int get end;
2626
external int get duration;
27-
external List<String> get includedFiles;
27+
external List get includedFiles; // contains Strings
2828

2929
external factory RenderResultStats(
3030
{String entry,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.10.0
2+
version: 1.10.1
33
description: A Sass implementation in Dart.
44
author: Dart Team <[email protected]>
55
homepage: https://github.com/sass/dart-sass

test/node_api/utils.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7+
import 'dart:js_util';
78

89
import 'package:js/js.dart';
910
import 'package:test/test.dart';
1011

1112
import 'package:sass/src/io.dart';
13+
import 'package:sass/src/node/function.dart';
1214

1315
import '../hybrid.dart';
1416
import 'api.dart';
@@ -60,6 +62,18 @@ Future<RenderError> renderError(RenderOptions options) {
6062
String renderSync(RenderOptions options) =>
6163
utf8.decode(sass.renderSync(options).css);
6264

65+
/// Like [renderSync], but goes through the untyped JS API.
66+
///
67+
/// This lets us test that we properly cast untyped collections without throwing
68+
/// type errors.
69+
String renderSyncJS(Map<String, Object> options) {
70+
var result = _renderSyncJS.call(sass, jsify(options)) as RenderResult;
71+
return utf8.decode(result.css);
72+
}
73+
74+
final _renderSyncJS =
75+
new JSFunction("sass", "args", "return sass.renderSync(args);");
76+
6377
/// Asserts that rendering via [options] produces an error, and returns that
6478
/// error.
6579
RenderError renderSyncError(RenderOptions options) {

test/node_api_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@Tags(const ['node'])
77

88
import 'dart:convert';
9+
import 'dart:js';
910

1011
import 'package:path/path.dart' as p;
1112
import 'package:test/test.dart';
@@ -420,6 +421,28 @@ a {
420421
});
421422
});
422423
});
424+
425+
group("when called with a raw JS collection", () {
426+
test("for includePaths", () {
427+
expect(
428+
renderSyncJS({
429+
"data": "@import 'test'",
430+
"includePaths": [sandbox]
431+
}),
432+
equalsIgnoringWhitespace('a { b: c; }'));
433+
});
434+
435+
// Regression test for #412
436+
test("for includePaths with an importer", () {
437+
expect(
438+
renderSyncJS({
439+
"data": "@import 'test'",
440+
"includePaths": [sandbox],
441+
"importer": allowInterop((url, prev) => null)
442+
}),
443+
equalsIgnoringWhitespace('a { b: c; }'));
444+
});
445+
});
423446
});
424447

425448
group("render()", () {

0 commit comments

Comments
 (0)