Skip to content

Commit 1073c7b

Browse files
authored
Generate deprecations list from the language repo (#2253)
This updates the Deprecation enum to be generated from spec/deprecations.yaml in the language repo.
1 parent fc24fec commit 1073c7b

File tree

12 files changed

+189
-62
lines changed

12 files changed

+189
-62
lines changed

.pubignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This should be identical to .gitignore except that it doesn't exclude
2-
# generated protobuf files.
2+
# generated Dart files.
33

44
.buildlog
55
.DS_Store

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.77.3
2+
3+
### Dart API
4+
5+
* `Deprecation.duplicateVariableFlags` has been deprecated and replaced with
6+
`Deprecation.duplicateVarFlags` to make it consistent with the
7+
`duplicate-var-flags` name used on the command line and in the JS API.
8+
19
## 1.77.2
210

311
* Don't emit deprecation warnings for functions and mixins beginning with `__`.

lib/src/deprecation.dart

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Google LLC. Use of this source code is governed by an
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

@@ -10,34 +10,42 @@ import 'util/nullable.dart';
1010

1111
/// A deprecated feature in the language.
1212
enum Deprecation {
13-
/// Deprecation for passing a string to `call` instead of `get-function`.
13+
// START AUTOGENERATED CODE
14+
//
15+
// DO NOT EDIT. This section was generated from the language repo.
16+
// See tool/grind/generate_deprecations.dart for details.
17+
//
18+
// Checksum: 22d9bdbe92eb39b3c0d6d64ebe1879a431c0037e
19+
20+
/// Deprecation for passing a string directly to meta.call().
1421
callString('call-string',
1522
deprecatedIn: '0.0.0',
1623
description: 'Passing a string directly to meta.call().'),
1724

18-
/// Deprecation for `@elseif`.
25+
/// Deprecation for @elseif.
1926
elseif('elseif', deprecatedIn: '1.3.2', description: '@elseif.'),
2027

21-
/// Deprecation for parsing `@-moz-document`.
28+
/// Deprecation for @-moz-document.
2229
mozDocument('moz-document',
2330
deprecatedIn: '1.7.2', description: '@-moz-document.'),
2431

25-
/// Deprecation for importers using relative canonical URLs.
26-
relativeCanonical('relative-canonical', deprecatedIn: '1.14.2'),
32+
/// Deprecation for imports using relative canonical URLs.
33+
relativeCanonical('relative-canonical',
34+
deprecatedIn: '1.14.2',
35+
description: 'Imports using relative canonical URLs.'),
2736

28-
/// Deprecation for declaring new variables with `!global`.
37+
/// Deprecation for declaring new variables with !global.
2938
newGlobal('new-global',
3039
deprecatedIn: '1.17.2',
3140
description: 'Declaring new variables with !global.'),
3241

33-
/// Deprecation for certain functions in the color module matching the
34-
/// behavior of their global counterparts for compatiblity reasons.
42+
/// Deprecation for using color module functions in place of plain CSS functions.
3543
colorModuleCompat('color-module-compat',
3644
deprecatedIn: '1.23.0',
3745
description:
3846
'Using color module functions in place of plain CSS functions.'),
3947

40-
/// Deprecation for treating `/` as division.
48+
/// Deprecation for / operator for division.
4149
slashDiv('slash-div',
4250
deprecatedIn: '1.33.0', description: '/ operator for division.'),
4351

@@ -46,46 +54,55 @@ enum Deprecation {
4654
deprecatedIn: '1.54.0',
4755
description: 'Leading, trailing, and repeated combinators.'),
4856

49-
/// Deprecation for ambiguous `+` and `-` operators.
57+
/// Deprecation for ambiguous + and - operators.
5058
strictUnary('strict-unary',
5159
deprecatedIn: '1.55.0', description: 'Ambiguous + and - operators.'),
5260

53-
/// Deprecation for passing invalid units to certain built-in functions.
61+
/// Deprecation for passing invalid units to built-in functions.
5462
functionUnits('function-units',
5563
deprecatedIn: '1.56.0',
5664
description: 'Passing invalid units to built-in functions.'),
5765

58-
/// Deprecation for passing percentages to the Sass abs() function.
59-
absPercent('abs-percent',
60-
deprecatedIn: '1.65.0',
61-
description: 'Passing percentages to the Sass abs() function.'),
62-
63-
duplicateVariableFlags('duplicate-var-flags',
66+
/// Deprecation for using !default or !global multiple times for one variable.
67+
duplicateVarFlags('duplicate-var-flags',
6468
deprecatedIn: '1.62.0',
6569
description:
6670
'Using !default or !global multiple times for one variable.'),
6771

72+
/// Deprecation for passing null as alpha in the ${isJS ? 'JS': 'Dart'} API.
6873
nullAlpha('null-alpha',
6974
deprecatedIn: '1.62.3',
7075
description: 'Passing null as alpha in the ${isJS ? 'JS' : 'Dart'} API.'),
7176

77+
/// Deprecation for passing percentages to the Sass abs() function.
78+
absPercent('abs-percent',
79+
deprecatedIn: '1.65.0',
80+
description: 'Passing percentages to the Sass abs() function.'),
81+
82+
/// Deprecation for using the current working directory as an implicit load path.
7283
fsImporterCwd('fs-importer-cwd',
7384
deprecatedIn: '1.73.0',
7485
description:
7586
'Using the current working directory as an implicit load path.'),
7687

88+
/// Deprecation for function and mixin names beginning with --.
7789
cssFunctionMixin('css-function-mixin',
7890
deprecatedIn: '1.76.0',
7991
description: 'Function and mixin names beginning with --.'),
8092

81-
@Deprecated('This deprecation name was never actually used.')
82-
calcInterp('calc-interp', deprecatedIn: null),
83-
84-
/// Deprecation for `@import` rules.
93+
/// Deprecation for @import rules.
8594
import.future('import', description: '@import rules.'),
8695

96+
// END AUTOGENERATED CODE
97+
8798
/// Used for deprecations coming from user-authored code.
88-
userAuthored('user-authored', deprecatedIn: null);
99+
userAuthored('user-authored', deprecatedIn: null),
100+
101+
@Deprecated('This deprecation name was never actually used.')
102+
calcInterp('calc-interp', deprecatedIn: null);
103+
104+
@Deprecated('Use duplicateVarFlags instead.')
105+
static const duplicateVariableFlags = duplicateVarFlags;
89106

90107
/// A unique ID for this deprecation in kebab case.
91108
///

lib/src/parse/stylesheet.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ abstract class StylesheetParser extends Parser {
235235
case 'default':
236236
if (guarded) {
237237
logger.warnForDeprecation(
238-
Deprecation.duplicateVariableFlags,
238+
Deprecation.duplicateVarFlags,
239239
'!default should only be written once for each variable.\n'
240240
'This will be an error in Dart Sass 2.0.0.',
241241
span: scanner.spanFrom(flagStart));
@@ -248,7 +248,7 @@ abstract class StylesheetParser extends Parser {
248248
scanner.spanFrom(flagStart));
249249
} else if (global) {
250250
logger.warnForDeprecation(
251-
Deprecation.duplicateVariableFlags,
251+
Deprecation.duplicateVarFlags,
252252
'!global should only be written once for each variable.\n'
253253
'This will be an error in Dart Sass 2.0.0.',
254254
span: scanner.spanFrom(flagStart));

pkg/sass_api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 10.4.3
2+
3+
* No user-visible changes.
4+
15
## 10.4.2
26

37
* No user-visible changes.

pkg/sass_api/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 10.4.2
5+
version: 10.4.3
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=3.0.0 <4.0.0"
1111

1212
dependencies:
13-
sass: 1.77.2
13+
sass: 1.77.3
1414

1515
dev_dependencies:
1616
dartdoc: ">=6.0.0 <9.0.0"

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.77.2
2+
version: 1.77.3
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

test/double_check_test.dart

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,39 @@
77
import 'dart:io';
88
import 'dart:convert';
99

10+
import 'package:crypto/crypto.dart';
1011
import 'package:path/path.dart' as p;
1112
import 'package:pub_semver/pub_semver.dart';
1213
import 'package:pubspec_parse/pubspec_parse.dart';
1314
import 'package:test/test.dart';
1415

16+
import '../tool/grind/generate_deprecations.dart' as deprecations;
1517
import '../tool/grind/synchronize.dart' as synchronize;
1618

1719
/// Tests that double-check that everything in the repo looks sensible.
1820
void main() {
19-
group("synchronized file is up-to-date:", () {
20-
synchronize.sources.forEach((sourcePath, targetPath) {
21-
test(targetPath, () {
22-
if (File(targetPath).readAsStringSync() !=
23-
synchronize.synchronizeFile(sourcePath)) {
24-
fail("$targetPath is out-of-date.\n"
25-
"Run `dart pub run grinder` to update it.");
26-
}
21+
group("up-to-date generated", () {
22+
group("synchronized file:", () {
23+
synchronize.sources.forEach((sourcePath, targetPath) {
24+
test(targetPath, () {
25+
if (File(targetPath).readAsStringSync() !=
26+
synchronize.synchronizeFile(sourcePath)) {
27+
fail("$targetPath is out-of-date.\n"
28+
"Run `dart run grinder` to update it.");
29+
}
30+
});
2731
});
2832
});
33+
34+
test("deprecations", () {
35+
var inputText = File(deprecations.yamlPath).readAsStringSync();
36+
var outputText = File(deprecations.dartPath).readAsStringSync();
37+
var checksum = sha1.convert(utf8.encode(inputText));
38+
if (!outputText.contains('// Checksum: $checksum')) {
39+
fail('${deprecations.dartPath} is out-of-date.\n'
40+
'Run `dart run grinder` to update it.');
41+
}
42+
});
2943
},
3044
// Windows sees different bytes than other OSes, possibly because of
3145
// newline normalization issues.

tool/grind.dart

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ import 'package:grinder/grinder.dart';
1111
import 'package:path/path.dart' as p;
1212
import 'package:source_span/source_span.dart';
1313

14+
import 'grind/generate_deprecations.dart';
1415
import 'grind/synchronize.dart';
1516
import 'grind/utils.dart';
1617

1718
export 'grind/bazel.dart';
1819
export 'grind/benchmark.dart';
1920
export 'grind/double_check.dart';
2021
export 'grind/frameworks.dart';
22+
export 'grind/generate_deprecations.dart';
2123
export 'grind/subpackages.dart';
2224
export 'grind/synchronize.dart';
25+
export 'grind/utils.dart';
2326

2427
void main(List<String> args) {
2528
pkg.humanName.value = "Dart Sass";
@@ -127,7 +130,7 @@ void main(List<String> args) {
127130
}
128131

129132
@DefaultTask('Compile async code and reformat.')
130-
@Depends(format, synchronize)
133+
@Depends(format, synchronize, deprecations)
131134
void all() {}
132135

133136
@Task('Run the Dart formatter.')
@@ -140,7 +143,7 @@ void npmInstall() =>
140143
run(Platform.isWindows ? "npm.cmd" : "npm", arguments: ["install"]);
141144

142145
@Task('Runs the tasks that are required for running tests.')
143-
@Depends(format, synchronize, protobuf, "pkg-npm-dev", npmInstall,
146+
@Depends(format, synchronize, protobuf, deprecations, "pkg-npm-dev", npmInstall,
144147
"pkg-standalone-dev")
145148
void beforeTest() {}
146149

@@ -213,9 +216,9 @@ String _readAndResolveMarkdown(String path) => File(path)
213216

214217
/// Returns a map from JS type declaration file names to their contnets.
215218
Map<String, String> _fetchJSTypes() {
216-
var languageRepo = _updateLanguageRepo();
219+
updateLanguageRepo();
217220

218-
var typeRoot = p.join(languageRepo, 'js-api-doc');
221+
var typeRoot = p.join('build/language', 'js-api-doc');
219222
return {
220223
for (var entry in Directory(typeRoot).listSync(recursive: true))
221224
if (entry is File && entry.path.endsWith('.d.ts'))
@@ -231,6 +234,7 @@ void _matchError(Match match, String message, {Object? url}) {
231234
}
232235

233236
@Task('Compile the protocol buffer definition to a Dart library.')
237+
@Depends(updateLanguageRepo)
234238
Future<void> protobuf() async {
235239
Directory('build').createSync(recursive: true);
236240

@@ -250,8 +254,6 @@ dart run protoc_plugin "\$@"
250254
run('chmod', arguments: ['a+x', 'build/protoc-gen-dart']);
251255
}
252256

253-
_updateLanguageRepo();
254-
255257
await runAsync("buf",
256258
arguments: ["generate"],
257259
runOptions: RunOptions(environment: {
@@ -321,19 +323,3 @@ String _updateHomebrewLanguageRevision(String formula) {
321323
match.group(0)!.replaceFirst(match.group(1)!, languageRepoRevision) +
322324
formula.substring(match.end);
323325
}
324-
325-
/// Clones the main branch of `github.com/sass/sass` and returns the path to the
326-
/// clone.
327-
///
328-
/// If the `UPDATE_SASS_SASS_REPO` environment variable is `false`, this instead
329-
/// assumes the repo that already exists at `build/language/sass`.
330-
/// `UPDATE_SASS_PROTOCOL` is also checked as a deprecated alias for
331-
/// `UPDATE_SASS_SASS_REPO`.
332-
String _updateLanguageRepo() =>
333-
// UPDATE_SASS_PROTOCOL is considered deprecated, because it doesn't apply as
334-
// generically to other tasks.
335-
Platform.environment['UPDATE_SASS_SASS_REPO'] != 'false' &&
336-
Platform.environment['UPDATE_SASS_PROTOCOL'] != 'false'
337-
? cloneOrCheckout("https://github.com/sass/sass.git", "main",
338-
name: 'language')
339-
: 'build/language';

tool/grind/double_check.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import 'dart:io';
66

77
import 'package:cli_pkg/cli_pkg.dart' as pkg;
8+
import 'package:collection/collection.dart';
89
import 'package:grinder/grinder.dart';
910
import 'package:path/path.dart' as p;
1011
import 'package:pub_api_client/pub_api_client.dart';
1112
import 'package:pubspec_parse/pubspec_parse.dart';
1213

13-
import 'package:sass/src/utils.dart';
14-
1514
import 'utils.dart';
1615

1716
@Task('Verify that the package is in a good state to release.')
@@ -21,7 +20,7 @@ Future<void> doubleCheckBeforeRelease() async {
2120
fail("GITHUB_REF $ref is different than pubspec version ${pkg.version}.");
2221
}
2322

24-
if (listEquals(pkg.version.preRelease, ["dev"])) {
23+
if (const ListEquality<Object?>().equals(pkg.version.preRelease, ["dev"])) {
2524
fail("${pkg.version} is a dev release.");
2625
}
2726

0 commit comments

Comments
 (0)