Skip to content

Commit b0bfdfe

Browse files
authored
Merge pull request #2555 from sass/elseif
Drop support for `@elseif`
2 parents 5591a84 + 0d228c5 commit b0bfdfe

File tree

6 files changed

+42
-167
lines changed

6 files changed

+42
-167
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
## 2.0.0
22

3+
* **Breaking change:** `@elseif` is no longer treated as equivalent to `@else
4+
if`, and is now treated like any other unknown plain CSS at-rule.
5+
36
* **Breaking change:** The `@-moz-document` rule no longer has any special
47
parsing associated with it. It is now parsed like any other unknown plain CSS
58
at-rule, where Sass features are only allowed within `#{}` interpolation.
6-
9+
710
### Bogus Combinators
811

912
* **Breaking change:** Selectors with more than one combinator in a row, such as

lib/src/deprecation.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ 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: cd61dac9558368fdb6f4221bb23d917003b61610
18+
// Checksum: e386251fa5eea522619d91ac98daf84dd474c29d
1919

2020
/// Deprecation for passing a string directly to meta.call().
2121
callString('call-string',
2222
deprecatedIn: '0.0.0',
2323
description: 'Passing a string directly to meta.call().'),
2424

2525
/// Deprecation for @elseif.
26-
elseif('elseif', deprecatedIn: '1.3.2', description: '@elseif.'),
26+
elseif('elseif',
27+
deprecatedIn: '1.3.2', obsoleteIn: '2.0.0', description: '@elseif.'),
2728

2829
/// Deprecation for @-moz-document.
2930
mozDocument('moz-document',

lib/src/parse/scss.dart

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:charcode/charcode.dart';
66

77
import '../ast/sass.dart';
8-
import '../deprecation.dart';
98
import '../interpolation_buffer.dart';
109
import '../util/character.dart';
1110
import 'stylesheet.dart';
@@ -39,25 +38,12 @@ class ScssParser extends StylesheetParser {
3938
bool scanElse(int ifIndentation) {
4039
var start = scanner.state;
4140
_whitespace();
42-
var beforeAt = scanner.state;
43-
if (scanner.scanChar($at)) {
44-
if (scanIdentifier('else', caseSensitive: true)) return true;
45-
if (scanIdentifier('elseif', caseSensitive: true)) {
46-
warnings.add((
47-
deprecation: Deprecation.elseif,
48-
message:
49-
'@elseif is deprecated and will not be supported in future Sass '
50-
'versions.\n'
51-
'\n'
52-
'Recommendation: @else if',
53-
span: scanner.spanFrom(beforeAt),
54-
));
55-
scanner.position -= 2;
56-
return true;
57-
}
41+
if (scanner.scanChar($at) && scanIdentifier('else', caseSensitive: true)) {
42+
return true;
43+
} else {
44+
scanner.state = start;
45+
return false;
5846
}
59-
scanner.state = start;
60-
return false;
6147
}
6248

6349
List<Statement> children(Statement child()) {

test/cli/shared/deprecations.dart

Lines changed: 29 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
2424
});
2525

2626
test("for an obsolete deprecation", () async {
27-
// TODO: test this when a deprecation is obsoleted
27+
var sass = await runSass([
28+
"--silence-deprecation=moz-document",
29+
"test.scss",
30+
]);
31+
expect(sass.stderr,
32+
emits(contains("moz-document deprecation is obsolete")));
33+
await sass.shouldExit(0);
2834
});
2935

3036
test("for an inactive future deprecation", () async {
@@ -107,45 +113,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
107113

108114
group("silences", () {
109115
group("a parse-time deprecation", () {
110-
setUp(
111-
() => d.file("test.scss", "@if true {} @elseif false {}").create(),
112-
);
113-
114-
test("in immediate mode", () async {
115-
var sass = await runSass([
116-
"--silence-deprecation=elseif",
117-
"test.scss",
118-
]);
119-
expect(sass.stderr, emitsDone);
120-
await sass.shouldExit(0);
121-
});
122-
123-
test("in watch mode", () async {
124-
var sass = await runSass([
125-
"--watch",
126-
"--poll",
127-
"--silence-deprecation=elseif",
128-
"test.scss:out.css",
129-
]);
130-
expect(sass.stderr, emitsDone);
131-
132-
await expectLater(
133-
sass.stdout,
134-
emitsThrough(endsWith('Compiled test.scss to out.css.')),
135-
);
136-
await sass.kill();
137-
});
138-
139-
test("in repl mode", () async {
140-
var sass = await runSass([
141-
"--interactive",
142-
"--silence-deprecation=strict-unary",
143-
]);
144-
expect(sass.stderr, emitsDone);
145-
sass.stdin.writeln("4 -(5)");
146-
await expectLater(sass.stdout, emitsInOrder([">> 4 -(5)", "-1"]));
147-
await sass.kill();
148-
});
116+
// TODO: Test this again once new deprecations are added post-2.0.0.
149117
});
150118

151119
group("an evaluation-time deprecation", () {
@@ -205,7 +173,13 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
205173
setUp(() => d.file("test.scss", "").create());
206174

207175
test("for an obsolete deprecation", () async {
208-
// TODO: test this when a deprecation is obsoleted
176+
var sass = await runSass([
177+
"--fatal-deprecation=moz-document",
178+
"test.scss",
179+
]);
180+
expect(sass.stderr,
181+
emits(contains("moz-document deprecation is obsolete")));
182+
await sass.shouldExit(0);
209183
});
210184

211185
test("for an inactive future deprecation", () async {
@@ -215,43 +189,15 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
215189
}, skip: true);
216190

217191
test("for a silent deprecation", () async {
218-
var sass = await runSass([
219-
"--fatal-deprecation=elseif",
220-
"--silence-deprecation=elseif",
221-
"test.scss",
222-
]);
223-
expect(sass.stderr, emits(contains("Ignoring setting to silence")));
224-
await sass.shouldExit(0);
192+
// TODO: Test this again once new deprecations are added post-2.0.0.
225193
});
226194

227195
test("in watch mode", () async {
228-
var sass = await runSass([
229-
"--watch",
230-
"--poll",
231-
"--fatal-deprecation=elseif",
232-
"--silence-deprecation=elseif",
233-
"test.scss:out.css",
234-
]);
235-
expect(sass.stderr, emits(contains("Ignoring setting to silence")));
236-
237-
await expectLater(
238-
sass.stdout,
239-
emitsThrough(endsWith('Compiled test.scss to out.css.')),
240-
);
241-
await sass.kill();
196+
// TODO: Test this again once new deprecations are added post-2.0.0.
242197
});
243198

244199
test("in repl mode", () async {
245-
var sass = await runSass([
246-
"--interactive",
247-
"--fatal-deprecation=elseif",
248-
"--silence-deprecation=elseif",
249-
]);
250-
await expectLater(
251-
sass.stderr,
252-
emits(contains("Ignoring setting to silence")),
253-
);
254-
await sass.kill();
200+
// TODO: Test this again once new deprecations are added post-2.0.0.
255201
});
256202
});
257203

@@ -299,54 +245,7 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
299245
});
300246

301247
group("a parse-time deprecation", () {
302-
setUp(
303-
() => d.file("test.scss", "@if true {} @elseif false {}").create(),
304-
);
305-
306-
test("in immediate mode", () async {
307-
var sass = await runSass(["--fatal-deprecation=elseif", "test.scss"]);
308-
expect(sass.stderr, emits(startsWith("Error: ")));
309-
await sass.shouldExit(65);
310-
});
311-
312-
test("in watch mode", () async {
313-
var sass = await runSass([
314-
"--watch",
315-
"--poll",
316-
"--fatal-deprecation=elseif",
317-
"test.scss:out.css",
318-
]);
319-
await expectLater(sass.stderr, emits(startsWith("Error: ")));
320-
await expectLater(
321-
sass.stdout,
322-
emitsInOrder([
323-
"Sass is watching for changes. Press Ctrl-C to stop.",
324-
"",
325-
]),
326-
);
327-
await sass.kill();
328-
});
329-
330-
test("in repl mode", () async {
331-
var sass = await runSass([
332-
"--interactive",
333-
"--fatal-deprecation=strict-unary",
334-
]);
335-
sass.stdin.writeln("4 -(5)");
336-
await expectLater(
337-
sass.stdout,
338-
emitsInOrder([
339-
">> 4 -(5)",
340-
emitsThrough(startsWith("Error: ")),
341-
emitsThrough(contains("Remove this setting")),
342-
]),
343-
);
344-
345-
// Verify that there's no output written for the previous line.
346-
sass.stdin.writeln("1");
347-
await expectLater(sass.stdout, emitsInOrder([">> 1", "1"]));
348-
await sass.kill();
349-
});
248+
// TODO: Test this again once new deprecations are added post-2.0.0.
350249
});
351250

352251
group("an evaluation-time deprecation", () {
@@ -451,8 +350,16 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
451350
});
452351
});
453352

454-
group("an obsolete deprecation", () {
455-
// TODO: test this when there are obsolete deprecations
353+
test("an obsolete deprecation", () async {
354+
var sass = await runSass([
355+
"--future-deprecation=moz-document",
356+
"test.scss",
357+
]);
358+
expect(
359+
sass.stderr,
360+
emits(contains("moz-document is not a future deprecation")),
361+
);
362+
await sass.shouldExit(0);
456363
});
457364

458365
group("a parse-time deprecation", () {

test/deprecations_test.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ void main() {
1515
_expectDeprecation("a { b: call(random)}", Deprecation.callString);
1616
});
1717

18-
// Deprecated in 1.3.2
19-
test("elseIf is violated by using @elseif instead of @else if", () {
20-
_expectDeprecation("@if false {} @elseif false {}", Deprecation.elseif);
21-
});
22-
2318
// Deprecated in 1.17.2
2419
test("newGlobal is violated by declaring a new variable with !global", () {
2520
_expectDeprecation(r"a {$foo: bar !global;}", Deprecation.newGlobal);

test/embedded/protocol_test.dart

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,24 +440,7 @@ void main() {
440440
});
441441

442442
test("for a parse-time deprecation warning", () async {
443-
process.send(compileString("@if true {} @elseif true {}"));
444-
445-
var logEvent = await getLogEvent(process);
446-
expect(logEvent.type, equals(LogEventType.DEPRECATION_WARNING));
447-
expect(
448-
logEvent.message,
449-
equals(
450-
'@elseif is deprecated and will not be supported in future Sass '
451-
'versions.\n'
452-
'\n'
453-
'Recommendation: @else if',
454-
),
455-
);
456-
expect(logEvent.span.text, equals("@elseif"));
457-
expect(logEvent.span.start, equals(location(12, 0, 12)));
458-
expect(logEvent.span.end, equals(location(19, 0, 19)));
459-
expect(logEvent.span.context, equals("@if true {} @elseif true {}"));
460-
expect(logEvent.stackTrace, "- 1:13 root stylesheet\n");
443+
// TODO: Test this again once new deprecations are added post-2.0.0.
461444
await process.kill();
462445
});
463446

0 commit comments

Comments
 (0)