This commit is contained in:
Natalie Weizenbaum 2018-06-25 13:47:34 -07:00
parent 6733567f91
commit f9f0d0e5da
5 changed files with 18 additions and 24 deletions

View File

@ -9,12 +9,11 @@ import 'package:path/path.dart' as p;
import 'package:tuple/tuple.dart';
import '../../io.dart';
import '../../node/function.dart';
import '../../node/importer_result.dart';
import '../../node/utils.dart';
import '../utils.dart';
typedef _Importer(String url, String prev, [void done(result)]);
/// An importer that encapsulates Node Sass's import logic.
///
/// This isn't a normal [Importer] because Node Sass's import behavior isn't
@ -46,10 +45,9 @@ class NodeImporter {
final List<String> _includePaths;
/// The importer functions passed in by the user.
final List<_Importer> _importers;
final List<JSFunction> _importers;
NodeImporter(this._context, Iterable<String> includePaths,
Iterable<_Importer> importers)
NodeImporter(this._context, Iterable<String> includePaths, Iterable importers)
: _includePaths = new List.unmodifiable(includePaths),
_importers = new List.unmodifiable(importers);
@ -137,8 +135,8 @@ class NodeImporter {
: new Tuple2(readFile(resolved), p.toUri(resolved).toString());
}
/// Converts an [_Importer]'s return [value] to a tuple that can be returned
/// by [load].
/// Converts an importer's return [value] to a tuple that can be returned by
/// [load].
Tuple2<String, String> _handleImportResult(
String url, Uri previous, Object value) {
if (isJSError(value)) throw value;
@ -164,7 +162,7 @@ class NodeImporter {
/// Calls an importer that may or may not be asynchronous.
Future<Object> _callImporterAsync(
_Importer importer, String url, String previousString) async {
JSFunction importer, String url, String previousString) async {
var completer = new Completer();
var result = call3(importer, _context, url, previousString,

View File

@ -6,11 +6,9 @@ import 'dart:async';
import 'package:tuple/tuple.dart';
typedef _Importer(String url, String prev, [void done(result)]);
class NodeImporter {
NodeImporter(Object context, Iterable<String> includePaths,
Iterable<_Importer> importers);
NodeImporter(
Object context, Iterable<String> includePaths, Iterable importers);
Tuple2<String, String> load(String url, Uri previous) => null;

View File

@ -19,6 +19,7 @@ import 'executable.dart' as executable;
import 'importer/node.dart';
import 'node/error.dart';
import 'node/exports.dart';
import 'node/function.dart';
import 'node/render_context.dart';
import 'node/render_context_options.dart';
import 'node/render_options.dart';
@ -30,8 +31,6 @@ import 'parse/scss.dart';
import 'value.dart';
import 'visitor/serialize.dart';
typedef _Importer(String url, String prev, [void done(result)]);
/// The entrypoint for Node.js.
///
/// This sets up exports that can be called from JS. These include a private
@ -251,13 +250,13 @@ List<AsyncCallable> _parseFunctions(RenderOptions options,
/// Parses [importer] and [includePaths] from [RenderOptions] into a
/// [NodeImporter].
NodeImporter _parseImporter(RenderOptions options, DateTime start) {
List<_Importer> importers;
List<JSFunction> importers;
if (options.importer == null) {
importers = [];
} else if (options.importer is List) {
importers = (options.importer as List).cast();
} else {
importers = [options.importer as _Importer];
importers = [options.importer as JSFunction];
}
var includePaths = options.includePaths ?? [];
@ -294,7 +293,7 @@ NodeImporter _parseImporter(RenderOptions options, DateTime start) {
}));
if (isUndefined(result)) return options.fiber.yield();
return result;
}) as _Importer;
}) as JSFunction;
}).toList();
}

View File

@ -5,7 +5,7 @@
import 'package:js/js.dart';
@JS("Function")
class JSFunction {
class JSFunction implements Function {
external JSFunction(String arg1, [String arg2, String arg3]);
// Note that this just invokes the function with the given arguments, rather

View File

@ -40,14 +40,13 @@ external Function get _JSError;
bool isJSError(value) => instanceof(value, _JSError);
/// Invokes [function] with [thisArg] as `this`.
R call2<R, A1, A2>(
R function(A1 arg1, A2 arg2), Object thisArg, A1 arg1, A2 arg2) =>
(function as JSFunction).apply(thisArg, [arg1, arg2]) as R;
Object call2(JSFunction function, Object thisArg, Object arg1, Object arg2) =>
function.apply(thisArg, [arg1, arg2]);
/// Invokes [function] with [thisArg] as `this`.
R call3<R, A1, A2, A3>(R function(A1 arg1, A2 arg2, A3 arg3), Object thisArg,
A1 arg1, A2 arg2, A3 arg3) =>
(function as JSFunction).apply(thisArg, [arg1, arg2, arg3]) as R;
Object call3(JSFunction function, Object thisArg, Object arg1, Object arg2,
Object arg3) =>
function.apply(thisArg, [arg1, arg2, arg3]);
@JS("Object.keys")
external List<String> _keys(Object object);