-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathdeprecation.dart
127 lines (101 loc) · 4.61 KB
/
deprecation.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2022 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';
import 'io.dart';
import 'util/nullable.dart';
/// A deprecated feature in the language.
enum Deprecation {
/// Deprecation for passing a string to `call` instead of `get-function`.
callString('call-string',
deprecatedIn: '0.0.0',
description: 'Passing a string directly to meta.call().'),
/// Deprecation for `@elseif`.
elseif('elseif', deprecatedIn: '1.3.2', description: '@elseif.'),
/// Deprecation for parsing `@-moz-document`.
mozDocument('moz-document',
deprecatedIn: '1.7.2', description: '@-moz-document.'),
/// Deprecation for importers using relative canonical URLs.
relativeCanonical('relative-canonical', deprecatedIn: '1.14.2'),
/// Deprecation for declaring new variables with `!global`.
newGlobal('new-global',
deprecatedIn: '1.17.2',
description: 'Declaring new variables with !global.'),
/// Deprecation for certain functions in the color module matching the
/// behavior of their global counterparts for compatiblity reasons.
colorModuleCompat('color-module-compat',
deprecatedIn: '1.23.0',
description:
'Using color module functions in place of plain CSS functions.'),
/// Deprecation for treating `/` as division.
slashDiv('slash-div',
deprecatedIn: '1.33.0', description: '/ operator for division.'),
/// Deprecation for leading, trailing, and repeated combinators.
bogusCombinators('bogus-combinators',
deprecatedIn: '1.54.0',
description: 'Leading, trailing, and repeated combinators.'),
/// Deprecation for ambiguous `+` and `-` operators.
strictUnary('strict-unary',
deprecatedIn: '1.55.0', description: 'Ambiguous + and - operators.'),
/// Deprecation for passing invalid units to certain built-in functions.
functionUnits('function-units',
deprecatedIn: '1.56.0',
description: 'Passing invalid units to built-in functions.'),
duplicateVariableFlags('duplicate-var-flags',
deprecatedIn: '1.62.0',
description:
'Using !default or !global multiple times for one variable.'),
nullAlpha('null-alpha',
deprecatedIn: '1.62.3',
description: 'Passing null as alpha in the ${isJS ? 'JS' : 'Dart'} API.'),
/// Deprecation for `@import` rules.
import.future('import', description: '@import rules.'),
/// Used for deprecations coming from user-authored code.
userAuthored('user-authored', deprecatedIn: null);
/// A unique ID for this deprecation in kebab case.
///
/// This is used to refer to the deprecation on the command line.
final String id;
/// Underlying version string used by [deprecatedIn].
///
/// This is necessary because [Version] doesn't have a constant constructor,
/// so we can't use it directly as an enum property.
final String? _deprecatedIn;
/// The Dart Sass version this feature was first deprecated in.
///
/// For deprecations that have existed in all versions of Dart Sass, this
/// should be 0.0.0. For deprecations not related to a specific Sass version,
/// this should be null.
Version? get deprecatedIn => _deprecatedIn.andThen(Version.parse);
/// A description of this deprecation that will be displayed in the CLI usage.
///
/// If this is null, the given deprecation will not be listed.
final String? description;
/// Whether this deprecation will occur in the future.
///
/// If this is true, `deprecatedIn` will be null, since we do not yet know
/// what version of Dart Sass this deprecation will be live in.
final bool isFuture;
/// Constructs a regular deprecation.
const Deprecation(this.id, {required String? deprecatedIn, this.description})
: _deprecatedIn = deprecatedIn,
isFuture = false;
/// Constructs a future deprecation.
const Deprecation.future(this.id, {this.description})
: _deprecatedIn = null,
isFuture = true;
@override
String toString() => id;
/// Returns the deprecation with a given ID, or null if none exists.
static Deprecation? fromId(String id) => Deprecation.values
.firstWhereOrNull((deprecation) => deprecation.id == id);
/// Returns the set of all deprecations done in or before [version].
static Set<Deprecation> forVersion(Version version) {
var range = VersionRange(max: version, includeMax: true);
return {
for (var deprecation in Deprecation.values)
if (deprecation.deprecatedIn.andThen(range.allows) ?? false) deprecation
};
}
}