Skip to content

Commit a2a6e11

Browse files
committed
Fixed nesting location
1 parent 382cda0 commit a2a6e11

5 files changed

+56
-55
lines changed

template-parser-helper.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = {
7979
function parseTemplateLiteralStyles(styles, input, range) {
8080
const offset = input.quasis[0].start;
8181
const source = input.css;
82-
const parseStyle = docFixer(source, input.parseOptions);
82+
const parseStyle = docFixer(offset, source, input.parseOptions);
8383

8484
const nodes = [];
8585
let index = range[0];
@@ -106,14 +106,15 @@ function parseTemplateLiteralStyles(styles, input, range) {
106106
}
107107

108108
class LocalFixer {
109-
constructor (lines, style, templateParse) {
109+
constructor (offset, lines, style, templateParse) {
110+
const startIndex = style.startIndex - offset
110111
let line = 0;
111-
let column = style.startIndex;
112+
let column = startIndex;
112113
lines.some((lineEndIndex, lineNumber) => {
113-
if (lineEndIndex >= style.startIndex) {
114+
if (lineEndIndex >= startIndex) {
114115
line = lineNumber--;
115116
if (lineNumber in lines) {
116-
column = style.startIndex - lines[lineNumber] - 1;
117+
column = startIndex - lines[lineNumber] - 1;
117118
}
118119
return true;
119120
}
@@ -177,7 +178,7 @@ class LocalFixer {
177178
}
178179
}
179180

180-
function docFixer (source, opts) {
181+
function docFixer (offset, source, opts) {
181182
let match;
182183
const lines = [];
183184
reNewLine.lastIndex = 0;
@@ -187,7 +188,7 @@ function docFixer (source, opts) {
187188
lines.push(source.length);
188189
return function parseStyle (style) {
189190
const parse = style.syntax ? style.syntax.parse : postcssParse
190-
return new LocalFixer(lines, style, parse).parse(opts);
191+
return new LocalFixer(offset, lines, style, parse).parse(opts);
191192
};
192193
}
193194

test/fixtures/styled-components-nesting-nesting.js.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"type": "decl",
8383
"source": {
8484
"start": {
85-
"line": 3,
85+
"line": 5,
8686
"column": 3
8787
},
8888
"input": {
@@ -99,7 +99,7 @@
9999
]
100100
},
101101
"end": {
102-
"line": 3,
102+
"line": 5,
103103
"column": 17
104104
}
105105
},
@@ -114,7 +114,7 @@
114114
"type": "literal",
115115
"source": {
116116
"start": {
117-
"line": 4,
117+
"line": 6,
118118
"column": 3
119119
},
120120
"input": {
@@ -147,14 +147,14 @@
147147
"type": "decl",
148148
"source": {
149149
"start": {
150-
"line": 3,
150+
"line": 7,
151151
"column": 4
152152
},
153153
"input": {
154154
"file": "styled-components-nesting-nesting.js"
155155
},
156156
"end": {
157-
"line": 3,
157+
"line": 7,
158158
"column": 21
159159
}
160160
},
@@ -167,8 +167,8 @@
167167
"file": "styled-components-nesting-nesting.js"
168168
},
169169
"start": {
170-
"line": 2,
171-
"column": 252
170+
"line": 6,
171+
"column": 9
172172
},
173173
"inline": false,
174174
"lang": "css"
@@ -192,8 +192,8 @@
192192
]
193193
},
194194
"start": {
195-
"line": 2,
196-
"column": 126
195+
"line": 4,
196+
"column": 8
197197
},
198198
"inline": false,
199199
"lang": "template-literal",

test/fixtures/styled-components-nesting.js.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@
9090
"type": "decl",
9191
"source": {
9292
"start": {
93-
"line": 3,
93+
"line": 5,
9494
"column": 3
9595
},
9696
"input": {
9797
"file": "styled-components-nesting.js"
9898
},
9999
"end": {
100-
"line": 3,
100+
"line": 5,
101101
"column": 17
102102
}
103103
},
@@ -110,8 +110,8 @@
110110
"file": "styled-components-nesting.js"
111111
},
112112
"start": {
113-
"line": 2,
114-
"column": 135
113+
"line": 4,
114+
"column": 19
115115
},
116116
"inline": false,
117117
"lang": "css"
@@ -164,14 +164,14 @@
164164
"type": "decl",
165165
"source": {
166166
"start": {
167-
"line": 3,
167+
"line": 8,
168168
"column": 3
169169
},
170170
"input": {
171171
"file": "styled-components-nesting.js"
172172
},
173173
"end": {
174-
"line": 3,
174+
"line": 8,
175175
"column": 20
176176
}
177177
},
@@ -184,8 +184,8 @@
184184
"file": "styled-components-nesting.js"
185185
},
186186
"start": {
187-
"line": 2,
188-
"column": 177
187+
"line": 7,
188+
"column": 20
189189
},
190190
"inline": false,
191191
"lang": "css"

test/fixtures/styled-components-nesting2.js.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@
8282
"type": "decl",
8383
"source": {
8484
"start": {
85-
"line": 3,
85+
"line": 5,
8686
"column": 3
8787
},
8888
"input": {
8989
"file": "styled-components-nesting2.js"
9090
},
9191
"end": {
92-
"line": 3,
92+
"line": 5,
9393
"column": 17
9494
}
9595
},
@@ -102,8 +102,8 @@
102102
"file": "styled-components-nesting2.js"
103103
},
104104
"start": {
105-
"line": 2,
106-
"column": 124
105+
"line": 4,
106+
"column": 8
107107
},
108108
"inline": false,
109109
"lang": "css"

test/fixtures/styled-components-nesting3.js.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@
8383
"source": {
8484
"start": {
8585
"line": 2,
86-
"column": 122
86+
"column": 47
8787
},
8888
"input": {
8989
"file": "styled-components-nesting3.js"
9090
},
9191
"end": {
9292
"line": 2,
93-
"column": 136
93+
"column": 61
9494
}
9595
},
9696
"prop": "color",
@@ -103,7 +103,7 @@
103103
},
104104
"start": {
105105
"line": 2,
106-
"column": 122
106+
"column": 47
107107
},
108108
"inline": false,
109109
"lang": "css"
@@ -215,15 +215,15 @@
215215
"type": "decl",
216216
"source": {
217217
"start": {
218-
"line": 3,
219-
"column": 195
218+
"line": 8,
219+
"column": 8
220220
},
221221
"input": {
222222
"file": "styled-components-nesting3.js"
223223
},
224224
"end": {
225-
"line": 3,
226-
"column": 209
225+
"line": 8,
226+
"column": 22
227227
}
228228
},
229229
"prop": "color",
@@ -235,8 +235,8 @@
235235
"file": "styled-components-nesting3.js"
236236
},
237237
"start": {
238-
"line": 3,
239-
"column": 195
238+
"line": 8,
239+
"column": 8
240240
},
241241
"inline": false,
242242
"lang": "css"
@@ -636,14 +636,14 @@
636636
"type": "decl",
637637
"source": {
638638
"start": {
639-
"line": 11,
639+
"line": 24,
640640
"column": 3
641641
},
642642
"input": {
643643
"file": "styled-components-nesting3.js"
644644
},
645645
"end": {
646-
"line": 11,
646+
"line": 24,
647647
"column": 20
648648
}
649649
},
@@ -658,14 +658,14 @@
658658
"type": "decl",
659659
"source": {
660660
"start": {
661-
"line": 12,
661+
"line": 25,
662662
"column": 3
663663
},
664664
"input": {
665665
"file": "styled-components-nesting3.js"
666666
},
667667
"end": {
668-
"line": 12,
668+
"line": 25,
669669
"column": 23
670670
}
671671
},
@@ -678,8 +678,8 @@
678678
"file": "styled-components-nesting3.js"
679679
},
680680
"start": {
681-
"line": 10,
682-
"column": 578
681+
"line": 23,
682+
"column": 34
683683
},
684684
"inline": false,
685685
"lang": "css"
@@ -791,15 +791,15 @@
791791
"type": "decl",
792792
"source": {
793793
"start": {
794-
"line": 28,
795-
"column": 701
794+
"line": 30,
795+
"column": 27
796796
},
797797
"input": {
798798
"file": "styled-components-nesting3.js"
799799
},
800800
"end": {
801-
"line": 28,
802-
"column": 711
801+
"line": 30,
802+
"column": 37
803803
}
804804
},
805805
"prop": "color",
@@ -811,8 +811,8 @@
811811
"file": "styled-components-nesting3.js"
812812
},
813813
"start": {
814-
"line": 28,
815-
"column": 701
814+
"line": 30,
815+
"column": 27
816816
},
817817
"inline": false,
818818
"lang": "css"
@@ -833,15 +833,15 @@
833833
"type": "decl",
834834
"source": {
835835
"start": {
836-
"line": 28,
837-
"column": 720
836+
"line": 30,
837+
"column": 46
838838
},
839839
"input": {
840840
"file": "styled-components-nesting3.js"
841841
},
842842
"end": {
843-
"line": 28,
844-
"column": 731
843+
"line": 30,
844+
"column": 57
845845
}
846846
},
847847
"prop": "color",
@@ -853,8 +853,8 @@
853853
"file": "styled-components-nesting3.js"
854854
},
855855
"start": {
856-
"line": 28,
857-
"column": 720
856+
"line": 30,
857+
"column": 46
858858
},
859859
"inline": false,
860860
"lang": "css"

0 commit comments

Comments
 (0)