Fix source indices for Sass interpolated selectors#244
Fix source indices for Sass interpolated selectors#244p-szm wants to merge 4 commits intopostcss:masterfrom
Conversation
| t.deepEqual(class2.value, 'is-$(network)'); | ||
| t.deepEqual(class2.type, 'class'); | ||
| t.deepEqual(class2.source.start.column, 6); | ||
| // t.deepEqual(class2.source.end.column, 19); // Fail - 10 |
There was a problem hiding this comment.
This still fails because the splitWords method processes this selector as [".icon", ".is-$"] and there is another place in the code that adds the rest of the selector in (I believe it's the pseudoselector code). I'm not sure how to fix this.
| const current = this.currToken; | ||
| const sourceIndex = current[TOKEN.START_POS] + indices[i]; | ||
| const {NodeConstructor, value, startToken, endToken, startIndex, endIndex} = node; | ||
| const sourceIndex = startToken[TOKEN.START_POS] + startIndex; |
There was a problem hiding this comment.
This was basically the fix - we're now using startToken and endToken which are correctly computed for each class/id/tag, instead of always using this.currToken
| if (current.lastIndexOf('\\') === current.length - 1) { | ||
| const token = this.currToken; | ||
| tokensList.push(token); | ||
| if (this.content(token).endsWith('\\')) { |
There was a problem hiding this comment.
This should be equivalent to current.lastIndexOf('\\') === current.length - 1, apart from the case when current is equal to "". I think we never get empty strings here though, but let me know if I'm wrong.
There was a problem hiding this comment.
But also I'm not sure if this condition is ever true. The coverage report says that this if statement never evaluates to true during tests (both in this PR and also on base), and I haven't been able to write a test that hits this.
I tried parsing .#{$classname1}\\$classname2, but it gets tokenized as ["/#{", "$", "classname1}\\$classname2"] and not as ["/#{", "$", "classname1}\\", "$", "classname2"], so maybe the tokenizer handles this already?
|
@alexander-akait is this something you would consider merging, or should we close this out? |
Fixes #243
I had to rewrite most of the
splitWordsparser method because the previous one didn't use the correct indices when multiple tokens were involved.