Skip to content

Commit 735109f

Browse files
authored
Deprecate passing a relative URL to compileString() *et al* (#2567)
This also clarifies the documentation on how loads work in the entrypoint file.
1 parent c4b0138 commit 735109f

11 files changed

+83
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.88.0
2+
3+
* Deprecate passing a relative URL to `compileString()` and related functions.
4+
15
## 1.87.0
26

37
* **Potentially breaking bug fix:** When a plain CSS file with a top-level

lib/sass.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export 'src/evaluation_context.dart' show warn;
4949
///
5050
/// Imports are resolved by trying, in order:
5151
///
52-
/// * Loading a file relative to [path].
52+
/// * **For relative URLs only:** the URL resolved relative to the current
53+
/// stylesheet's canonical URL, passed to the importer that loaded the current
54+
/// stylesheet.
5355
///
5456
/// * Each importer in [importers].
5557
///
@@ -147,7 +149,14 @@ CompileResult compileToResult(
147149
///
148150
/// Imports are resolved by trying, in order:
149151
///
150-
/// * The given [importer], with the imported URL resolved relative to [url].
152+
/// * **For relative URLs only:** the URL resolved relative to the current
153+
/// stylesheet's canonical URL, passed to the importer that loaded the current
154+
/// stylesheet.
155+
///
156+
/// For the entrypoint file, [url] is the canonical URL and [importer] is the
157+
/// importer that loaded it. If [url] is a `file:` URL and [importer] is null,
158+
/// it defaults to a [FilesystemImporter] that loads relative URLs from the
159+
/// filesystem.
151160
///
152161
/// * Each importer in [importers].
153162
///

lib/src/async_compile.dart

+10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ Future<CompileResult> compileStringAsync(
133133

134134
var stylesheet = Stylesheet.parse(source, syntax ?? Syntax.scss, url: url);
135135

136+
if (stylesheet.span.sourceUrl case Uri(scheme: '')
137+
when nodeImporter == null) {
138+
deprecationLogger.warnForDeprecation(
139+
Deprecation.compileStringRelativeUrl,
140+
'Passing a relative `url` argument (${stylesheet.span.sourceUrl}) to '
141+
'compileString() or related functions is deprecated and will be an error '
142+
'in Dart Sass 2.0.0.',
143+
);
144+
}
145+
136146
var result = await _compileStylesheet(
137147
stylesheet,
138148
logger,

lib/src/compile.dart

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_compile.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: ef3310e5d44fa5a9411c9416fb36f51741dfe6ad
8+
// Checksum: d305a0f75e329a29f5aff734ac31ce145fd3b8d5
99
//
1010
// ignore_for_file: unused_import
1111

@@ -142,6 +142,16 @@ CompileResult compileString(
142142

143143
var stylesheet = Stylesheet.parse(source, syntax ?? Syntax.scss, url: url);
144144

145+
if (stylesheet.span.sourceUrl case Uri(scheme: '')
146+
when nodeImporter == null) {
147+
deprecationLogger.warnForDeprecation(
148+
Deprecation.compileStringRelativeUrl,
149+
'Passing a relative `url` argument (${stylesheet.span.sourceUrl}) to '
150+
'compileString() or related functions is deprecated and will be an error '
151+
'in Dart Sass 2.0.0.',
152+
);
153+
}
154+
145155
var result = _compileStylesheet(
146156
stylesheet,
147157
logger,

lib/src/deprecation.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum Deprecation {
1515
// DO NOT EDIT. This section was generated from the language repo.
1616
// See tool/grind/generate_deprecations.dart for details.
1717
//
18-
// Checksum: 3639e60773866019c018ae16267c8f23e4df86cf
18+
// Checksum: c57ab2eb07ab1df48581b8484ef9bdbad0ddceaa
1919

2020
/// Deprecation for passing a string directly to meta.call().
2121
callString(
@@ -173,6 +173,13 @@ enum Deprecation {
173173
description: 'Functions named "type".',
174174
),
175175

176+
/// Deprecation for passing a relative url to compileString().
177+
compileStringRelativeUrl(
178+
'compile-string-relative-url',
179+
deprecatedIn: '1.88.0',
180+
description: 'Passing a relative url to compileString().',
181+
),
182+
176183
// END AUTOGENERATED CODE
177184

178185
/// Used for deprecations coming from user-authored code.

pkg/sass-parser/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.20
2+
3+
* No user-visible changes.
4+
15
## 0.4.19
26

37
* No user-visible changes.

pkg/sass-parser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-parser",
3-
"version": "0.4.19",
3+
"version": "0.4.20",
44
"description": "A PostCSS-compatible wrapper of the official Sass parser",
55
"repository": "sass/sass",
66
"author": "Google Inc.",

pkg/sass_api/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 15.5.0
2+
3+
* No user-visible changes.
4+
15
## 15.4.0
26

37
* No user-visible changes.

pkg/sass_api/pubspec.yaml

+2-2
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: 15.4.0
5+
version: 15.5.0
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

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

1212
dependencies:
13-
sass: 1.87.0
13+
sass: 1.88.0
1414

1515
dev_dependencies:
1616
dartdoc: ^8.0.14

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.87.0
2+
version: 1.88.0
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

test/deprecations_test.dart

+27-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ void main() {
8888
});
8989
});
9090

91+
group("compileStringRelativeUrl is violated by", () {
92+
test("a fully relative URL", () {
93+
_expectDeprecationCallback(
94+
() => compileStringToResult("a {b: c}",
95+
url: "foo",
96+
fatalDeprecations: {Deprecation.compileStringRelativeUrl}),
97+
Deprecation.compileStringRelativeUrl);
98+
});
99+
100+
test("a root-relative URL", () {
101+
_expectDeprecationCallback(
102+
() => compileStringToResult("a {b: c}",
103+
url: "/foo",
104+
fatalDeprecations: {Deprecation.compileStringRelativeUrl}),
105+
Deprecation.compileStringRelativeUrl);
106+
});
107+
});
108+
91109
// Deprecated in various Sass versions <=1.56.0
92110
group("functionUnits is violated by", () {
93111
test("a hue with a non-angle unit", () {
@@ -136,9 +154,16 @@ void main() {
136154
}
137155

138156
/// Confirms that [source] will error if [deprecation] is fatal.
139-
void _expectDeprecation(String source, Deprecation deprecation) {
157+
void _expectDeprecation(String source, Deprecation deprecation) =>
158+
_expectDeprecationCallback(
159+
() => compileStringToResult(source, fatalDeprecations: {deprecation}),
160+
deprecation);
161+
162+
/// Confirms that [callback] will produce a fatal deprecation error for
163+
/// [deprecation].
164+
void _expectDeprecationCallback(void callback(), Deprecation deprecation) {
140165
try {
141-
compileStringToResult(source, fatalDeprecations: {deprecation});
166+
callback();
142167
} catch (e) {
143168
if (e.toString().contains("$deprecation deprecation to be fatal")) return;
144169
fail('Unexpected error: $e');

0 commit comments

Comments
 (0)