Skip to content

Commit 3a300be

Browse files
authored
Merge pull request #690 from Cerdic/Issue/leafo/475v2
Fix proposal for #475: generate line number in wrapped media blocks w…
2 parents 1d93073 + d1bdc4f commit 3a300be

7 files changed

Lines changed: 83 additions & 40 deletions

File tree

src/Compiler.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,30 @@ protected function compileMedia(Block $media)
832832
$wrapped->children = $media->children;
833833

834834
$media->children = [[Type::T_BLOCK, $wrapped]];
835+
if (isset($this->lineNumberStyle)) {
836+
$annotation = $this->makeOutputBlock(Type::T_COMMENT);
837+
$annotation->depth = 0;
838+
839+
$file = $this->sourceNames[$media->sourceIndex];
840+
$line = $media->sourceLine;
841+
842+
switch ($this->lineNumberStyle) {
843+
case static::LINE_COMMENTS:
844+
$annotation->lines[] = '/* line ' . $line
845+
. ($file ? ', ' . $file : '')
846+
. ' */';
847+
break;
848+
849+
case static::DEBUG_INFO:
850+
$annotation->lines[] = '@media -sass-debug-info{'
851+
. ($file ? 'filename{font-family:"' . $file . '"}' : '')
852+
. 'line{font-family:' . $line . '}}';
853+
break;
854+
}
855+
856+
$this->scope->children[] = $annotation;
857+
}
858+
835859
}
836860

837861
$this->compileChildrenNoReturn($media->children, $this->scope);

tests/outputs_numbered/at_root.css

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ body .second {
4545
color: red; }
4646
/* line 49, inputs/at_root.scss */
4747
@media (min-width: 300px) {
48-
/* line 51, inputs/at_root.scss */
49-
.my-widget .inside-mq {
50-
inside-style: mq; } }
48+
/* line 50, inputs/at_root.scss */
49+
/* line 51, inputs/at_root.scss */
50+
.my-widget .inside-mq {
51+
inside-style: mq; } }
5152

5253
/* line 56, inputs/at_root.scss */
5354
.my-widget .outside-mq {
@@ -146,8 +147,9 @@ a.badge-secondary:focus, a.badge-secondary.focus {
146147
display: inline-block; }
147148

148149
@media (prefers-reduced-motion: reduce) {
149-
.badge {
150-
transition: none; } }
150+
/* line 194, inputs/at_root.scss */
151+
.badge {
152+
transition: none; } }
151153
/* line 210, inputs/at_root.scss */
152154
/* line 200, inputs/at_root.scss */
153155

tests/outputs_numbered/content.css

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
border-color: blue; }
1010

1111
@media only screen and (max-width: 480px) {
12-
/* line 32, inputs/content.scss */
13-
body {
14-
color: red; } }
12+
/* line 26, inputs/content.scss */
13+
/* line 32, inputs/content.scss */
14+
body {
15+
color: red; } }
1516
/* line 36, inputs/content.scss */
1617
#sidebar {
1718
width: 300px; }
@@ -20,9 +21,10 @@
2021
width: 100px; } }
2122

2223
@media only screen and (min-width: 40em) {
23-
/* line 51, inputs/content.scss */
24-
.grid-1 {
25-
width: 100%; }
24+
/* line 46, inputs/content.scss */
25+
/* line 51, inputs/content.scss */
26+
.grid-1 {
27+
width: 100%; }
2628
/* line 51, inputs/content.scss */
2729
.grid-2 {
2830
width: 100%; } }

tests/outputs_numbered/media.css

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,26 @@ div {
2424
color: blue; } }
2525

2626
@media (max-width: 940px) {
27-
color: red; }
27+
/* line 23, inputs/media.scss */
28+
color: red; }
2829

2930
@media not hello and (world) {
30-
color: blue;
31+
/* line 28, inputs/media.scss */
32+
color: blue;
3133
/* line 30, inputs/media.scss */
3234
pre {
3335
color: blue; } }
3436
@media not hello and (world) {
3537
@media butt {
36-
color: red;
38+
/* line 34, inputs/media.scss */
39+
color: red;
3740
/* line 36, inputs/media.scss */
3841
div {
3942
color: red; } } }
4043

4144
@media c {
42-
color: blue; }
45+
/* line 61, inputs/media.scss */
46+
color: blue; }
4347
/* line 70, inputs/media.scss */
4448
div {
4549
color: blue; }
@@ -51,10 +55,11 @@ width: 500px; } }
5155
div {
5256
position: absolute; }
5357
@media screen {
54-
div {
55-
top: 0;
56-
bottom: 8em;
57-
color: red; }
58+
/* line 90, inputs/media.scss */
59+
div {
60+
top: 0;
61+
bottom: 8em;
62+
color: red; }
5863
/* line 93, inputs/media.scss */
5964
div p {
6065
margin: 5px; }
@@ -71,23 +76,26 @@ color: green; } }
7176
background: #aaa; }
7277

7378
@media only screen and (max-width: 300px) {
74-
.button {
75-
width: 100px;
76-
height: 100px; } }
79+
/* line 110, inputs/media.scss */
80+
.button {
81+
width: 100px;
82+
height: 100px; } }
7783
/* line 116, inputs/media.scss */
7884
code {
7985
position: absolute; }
8086

8187
@media screen {
82-
code {
83-
height: 10px; }
88+
/* line 118, inputs/media.scss */
89+
code {
90+
height: 10px; }
8491
/* line 119, inputs/media.scss */
8592
code pre {
8693
height: 20px; } }
8794
/* line 126, inputs/media.scss */
8895
@media screen and (color: blue) {
89-
dt {
90-
height: 10px; } }
96+
/* line 128, inputs/media.scss */
97+
dt {
98+
height: 10px; } }
9199

92100
@media screen {
93101
/* line 136, inputs/media.scss */
@@ -138,18 +146,21 @@ code pre {
138146
@media not all and (max-width: 450px) {
139147
@media not all and (max-width: 690px) and (orientation: portrait) {
140148
@media (max-width: 1000px) {
141-
a {
142-
color: red; } } } }
149+
/* line 226, inputs/media.scss */
150+
a {
151+
color: red; } } } }
143152
/* line 233, inputs/media.scss */
144153

145154
@media not all and (max-width: 450px) {
146155
@media (max-width: 690px) and (orientation: portrait) and (max-width: 1000px) {
147-
a {
148-
color: red; } } }
156+
/* line 236, inputs/media.scss */
157+
a {
158+
color: red; } } }
149159
/* line 243, inputs/media.scss */
150160

151161
@media (max-width: 450px) {
152162
@media not all and (max-width: 690px) and (orientation: portrait) {
153163
@media not all and (max-width: 1000px) {
154-
a {
155-
color: red; } } } }
164+
/* line 246, inputs/media.scss */
165+
a {
166+
color: red; } } } }

tests/outputs_numbered/mixins.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ div.parameter-name-scope {
106106
color: red; } }
107107
/* line 190, inputs/mixins.scss */
108108
@media screen and (min-width:0\0) {
109-
.test {
110-
color: #000; } }
109+
/* line 186, inputs/mixins.scss */
110+
.test {
111+
color: #000; } }
111112
/* line 197, inputs/mixins.scss */
112113
div {
113114
content: "div";

tests/outputs_numbered/nested_mixins.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ div .container .bar {
1414
width: 12px; }
1515

1616
@media print, screen and (min-width:640px) {
17-
/* line 43, inputs/nested_mixins.scss */
18-
.position-left {
19-
color: red;
20-
background: yellow; } }
17+
/* line 33, inputs/nested_mixins.scss */
18+
/* line 43, inputs/nested_mixins.scss */
19+
.position-left {
20+
color: red;
21+
background: yellow; } }
2122

2223
@media print, screen and (min-width:640px) {
2324
/* line 45, inputs/nested_mixins.scss */

tests/outputs_numbered/scss_css.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,12 @@ rule2 {
364364
prop: val; } }
365365

366366
@media screen and (-webkit-min-device-pixel-ratio: 0) {
367-
a: b; }
367+
/* line 440, inputs/scss_css.scss */
368+
a: b; }
368369

369370
@media only screen, print and (foo: 0px) and (bar: flam(12px solid)) {
370-
a: b; }
371+
/* line 444, inputs/scss_css.scss */
372+
a: b; }
371373
/* line 448, inputs/scss_css.scss */
372374
:-moz-any(h1, h2, h3) {
373375
a: b; }

0 commit comments

Comments
 (0)