Skip to content

Commit

Permalink
Work around dart-lang/sdk#41259 (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Apr 21, 2020
1 parent bf35513 commit 83ec64a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/src/ast/sass/statement/forward_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ForwardRule implements Statement {
Iterable<String> mixinsAndFunctions, Iterable<String> variables) =>
[
if (shownMixinsAndFunctions != null) ...shownMixinsAndFunctions,
if (shownVariables != null) for (var name in shownVariables) "\$$name"
if (shownVariables != null)
for (var name in shownVariables) "\$$name"
].join(", ");
}
3 changes: 2 additions & 1 deletion lib/src/async_environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,8 @@ class _EnvironmentModule implements Module {
if (otherMaps.isEmpty) return localMap;

var allMaps = [
for (var map in otherMaps) if (map.isNotEmpty) map,
for (var map in otherMaps)
if (map.isNotEmpty) map,
localMap
];
if (allMaps.length == 1) return localMap;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_environment.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: bf1542d44f45a40a1f56c8eec3046c61ee32c36a
// Checksum: d304e1c5208019bca99df0678c3fdb4d09776a2b
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -983,7 +983,8 @@ class _EnvironmentModule implements Module<Callable> {
if (otherMaps.isEmpty) return localMap;

var allMaps = [
for (var map in otherMaps) if (map.isNotEmpty) map,
for (var map in otherMaps)
if (map.isNotEmpty) map,
localMap
];
if (allMaps.length == 1) return localMap;
Expand Down
12 changes: 11 additions & 1 deletion lib/src/node/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ bool isUndefined(Object value) => _isUndefined.call(value) as bool;

final _isUndefined = JSFunction("value", "return value === undefined;");

/// Returns whether or not [value] is an instance of [type] according to JS.
///
/// TODO(nweiz): Remove this when dart-lang/sdk#41259 is fixed in all supported
/// SDKs.
bool jsInstanceOf(Object value, Object type) =>
_jsInstanceOf.call(value, type) as bool;

final _jsInstanceOf =
JSFunction("value", "type", "return value instanceof type;");

@JS("Error")
external Function get jsErrorConstructor;

/// Returns whether [value] is a JS Error object.
bool isJSError(Object value) => instanceof(value, jsErrorConstructor);
bool isJSError(Object value) => jsInstanceOf(value, jsErrorConstructor);

/// Invokes [function] with [thisArg] as `this`.
Object call2(JSFunction function, Object thisArg, Object arg1, Object arg2) =>
Expand Down
5 changes: 4 additions & 1 deletion lib/src/util/limited_map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class LimitedMapView<K, V> extends UnmodifiableMapBase<K, V> {
///
/// The [blocklist] must have the same notion of equality as the [map].
LimitedMapView.blocklist(this._map, Set<K> blocklist)
: _keys = {for (var key in _map.keys) if (!blocklist.contains(key)) key};
: _keys = {
for (var key in _map.keys)
if (!blocklist.contains(key)) key
};

V operator [](Object key) => _keys.contains(key) ? _map[key] : null;
bool containsKey(Object key) => _keys.contains(key);
Expand Down
6 changes: 4 additions & 2 deletions test/node_api/value/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:js_util';
import 'package:js/js.dart';
import 'package:test/test.dart';

import 'package:sass/src/node/utils.dart';

import '../api.dart';
import '../utils.dart';

Expand All @@ -25,5 +27,5 @@ T parseValue<T>(String source) {
}

/// A matcher that matches values that are JS `instanceof` [type].
Matcher isJSInstanceOf(Function type) =>
predicate((value) => instanceof(value, type), "to be an instance of $type");
Matcher isJSInstanceOf(Object type) => predicate(
(value) => jsInstanceOf(value, type), "to be an instance of $type");

0 comments on commit 83ec64a

Please sign in to comment.