8000 Enable strict inference · NTrentini/dart-sass@79e9bbd · GitHub
[go: up one dir, main page]

Skip to content

Commit 79e9bbd

Browse files
committed
Enable strict inference
1 parent 1340ba7 commit 79e9bbd

File tree

10 files changed

+36
-29
lines changed

10 files changed

+36
-29
lines changed

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
analyzer:
22
strong-mode:
33
implicit-casts: false
4+
language:
5+
strict-inference: true
46
errors:
57
missing_js_lib_annotation: ignore
68
deprecated_member_use_from_same_package: ignore

lib/src/importer/node/implementation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class NodeImporter {
184184
/// Calls an importer that may or may not be asynchronous.
185185
Future<Object> _callImporterAsync(
186186
JSFunction importer, String url, String previousString) async {
187-
var completer = Completer();
187+
var completer = Completer<Object>();
188188

189189
var result = call3(importer, _context, url, previousString,
190190
allowInterop(completer.complete));

lib/src/node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ List<AsyncCallable> _parseFunctions(RenderOptions options,
225225
} else {
226226
result.add(AsyncBuiltInCallable.parsed(tuple.item1, tuple.item2,
227227
(arguments) async {
228-
var completer = Completer();
228+
var completer = Completer<Object>();
229229
var jsArguments = [
230230
...arguments.map(wrapValue),
231231
allowInterop(([result]) => completer.complete(result))

lib/src/utils.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,18 @@ int codeUnitIndexToCodepointIndex(String string, int codeUnitIndex) {
165165
}
166166

167167
/// Returns whether [list1] and [list2] have the same contents.
168-
bool listEquals<T>(List<T> list1, List<T> list2) =>
169-
const ListEquality().equals(list1, list2);
168+
bool listEquals(List list1, List list2) =>
169+
const ListEquality<Object>().equals(list1, list2);
170170

171171
/// Returns a hash code for [list] that matches [listEquals].
172-
int listHash(List list) => const ListEquality().hash(list);
172+
int listHash(List list) => const ListEquality<Object>().hash(list);
173+
174+
/// Returns whether [map1] and [map2] have the same contents.
175+
bool mapEquals(Map map1, Map map2) =>
176+
const MapEquality<Object, Object>().equals(map1, map2);
177+
178+
/// Returns a hash code for [map] that matches [mapEquals].
179+
int mapHash(Map map) => const MapEquality<Object, Object>().hash(map);
173180

174181
/// Returns a stack frame for the given [span] with the given [member] name.
175182
///

lib/src/value/map.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'package:collection/collection.dart';
6-
75
import '../visitor/interface/value.dart';
86
import '../value.dart';
7+
import '../utils.dart';
98
import 'external/value.dart' as ext;
109

1110
class SassMap extends Value implements ext.SassMap {
@@ -33,11 +32,9 @@ class SassMap extends Value implements ext.SassMap {
3332
SassMap assertMap([String name]) => this;
3433

3534
bool operator ==(other) =>
36-
(other is SassMap &&
37-
const MapEquality().equals(other.contents, contents)) ||
35+
(other is SassMap && mapEquals(other.contents, contents)) ||
3836
(contents.isEmpty && other is SassList && other.asList.isEmpty);
3937

40-
int get hashCode => contents.isEmpty
41-
? const SassList.empty().hashCode
42-
: const MapEquality().hash(contents);
38+
int get hashCode =>
39+
contents.isEmpty ? const SassList.empty().hashCode : mapHash(contents);
4340
}

test/node_api/function_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void main() {
180180
data: "a {b: foo()}",
181181
functions: jsify({
182182
"foo": allowInterop((done) {
183-
Future.delayed(Duration.zero).then((_) {
183+
Timer(Duration.zero, () {
184184
done(callConstructor(sass.types.Number, [1]));
185185
});
186186
})
@@ -210,7 +210,7 @@ void main() {
210210
data: "a {b: foo()}",
211211
functions: jsify({
212212
"foo": allowInterop((done) {
213-
Future.delayed(Duration.zero).then((_) {
213+
Timer(Duration.zero, () {
214214
done(JSError("aw beans"));
215215
});
216216
})
@@ -223,7 +223,7 @@ void main() {
223223
data: "a {b: foo()}",
224224
functions: jsify({
225225
"foo": allowInterop((done) {
226-
Future.delayed(Duration.zero).then((_) {
226+
Timer(Duration.zero, () {
227227
done(callConstructor(sass.types.Error, ["aw beans"]));
228228
});
229229
})
@@ -236,7 +236,7 @@ void main() {
236236
data: "a {b: foo()}",
237237
functions: jsify({
238238
"foo": allowInterop((done) {
239-
Future.delayed(Duration.zero).then((_) {
239+
Timer(Duration.zero, () {
240240
done(null);
241241
});
242242
})
@@ -249,7 +249,7 @@ void main() {
249249
data: "a {b: foo()}",
250250
functions: jsify({
251251
"foo": allowInterop((done) {
252-
Future.delayed(Duration.zero).then((_) {
252+
Timer(Duration.zero, () {
253253
done();
254254
});
255255
})
@@ -291,7 +291,7 @@ void main() {
291291
data: "a {b: foo()}",
292292
functions: jsify({
293293
"foo": allowInterop((done) {
294-
Future.delayed(Duration.zero).then((_) {
294+
Timer(Duration.zero, () {
295295
done(callConstructor(sass.types.Number, [1]));
296296
});
297297
})
@@ -313,7 +313,7 @@ void main() {
313313
data: "a {b: foo()}",
314314
functions: jsify({
315315
"foo": allowInterop((done) {
316-
Future.delayed(Duration.zero).then((_) {
316+
Timer(Duration.zero, () {
317317
done(JSError("aw beans"));
318318
});
319319
})
@@ -327,7 +327,7 @@ void main() {
327327
data: "a {b: foo()}",
328328
functions: jsify({
329329
"foo": allowInterop((done) {
330-
Future.delayed(Duration.zero).then((_) {
330+
Timer(Duration.zero, () {
331331
done(null);
332332
});
333333
})
@@ -341,7 +341,7 @@ void main() {
341341
data: "a {b: foo()}",
342342
functions: jsify({
343343
"foo": allowInterop((done) {
344-
Future.delayed(Duration.zero).then((_) {
344+
Timer(Duration.zero, () {
345345
done();
346346
});
347347
})

test/node_api/importer_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ void main() {
589589
render(RenderOptions(
590590
data: "@import 'foo'",
591591
importer: allowInterop((_, __, done) {
592-
Future.delayed(Duration.zero).then((_) {
592+
Timer(Duration.zero, () {
593593
done(NodeImporterResult(contents: 'a {b: c}'));
594594
});
595595
}))),
@@ -601,7 +601,7 @@ void main() {
601601
renderError(RenderOptions(
602602
data: "@import 'foo'",
603603
importer: allowInterop((_, __, done) {
604-
Future.delayed(Duration.zero).then((_) {
604+
Timer(Duration.zero, () {
605605
done(JSError('oh no'));
606606
});
607607
}))),
@@ -651,7 +651,7 @@ void main() {
651651
render(RenderOptions(
652652
data: "@import 'foo'",
653653
importer: allowInterop((_, __, done) {
654-
Future.delayed(Duration.zero).then((_) {
654+
Timer(Duration.zero, () {
655655
done(NodeImporterResult(contents: 'a {b: c}'));
656656
});
657657
}),
@@ -686,7 +686,7 @@ void main() {
686686
renderError(RenderOptions(
687687
data: "@import 'foo'",
688688
importer: allowInterop((_, __, done) {
689-
Future.delayed(Duration.zero).then((_) {
689+
Timer(Duration.zero, () {
690690
done(JSError('oh no'));
691691
});
692692
}),

test/node_api/value/null_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'utils.dart';
1414

1515
void main() {
1616
group("from a parameter", () {
17-
var value;
17+
Object value;
1818
setUp(() {
1919
value = parseValue("null");
2020
});

tool/grind/npm.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ npmReleasePackage() => _npm(release: true);
6969
void _npm({@required bool release}) {
7070
var json = {
7171
...(jsonDecode(File('package/package.json').readAsStringSync())
72-
as Map<String, dynamic>),
72+
as Map<String, Object>),
7373
"version": version
7474
};
7575

tool/grind/sanity_check.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
import 'dart:io';
66

7-
import 'package:collection/collection.dart';
87
import 'package:grinder/grinder.dart';
98
import 'package:pub_semver/pub_semver.dart';
109

10+
import 'package:sass/src/utils.dart';
11+
1112
import 'utils.dart';
1213

1314
@Task('Verify that the package is in a good state to release.')
@@ -17,7 +18,7 @@ sanityCheckBeforeRelease() {
1718
fail("TRAVIS_TAG $travisTag is different than pubspec version $version.");
1819
}
1920

20-
if (const ListEquality().equals(Version.parse(version).preRelease, ["dev"])) {
21+
if (listEquals(Version.parse(version).preRelease, ["dev"])) {
2122
fail("$version is a dev release.");
2223
}
2324

0 commit comments

Comments
 (0)
0