-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix source indices for Sass interpolated selectors #244
base: master
Are you sure you want to change the base?
Conversation
let class2 = tree.nodes[0].nodes[1]; | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
splitWords
parser method because the previous one didn't use the correct indices when multiple tokens were involved.