-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add option to include line and column numbers #28
Conversation
so that Travis can run the tests
to include the name of the parsed file in every `loc` object
i = newline.index; | ||
} | ||
column += str.length-i; | ||
} |
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.
i think we could replace most of this with something like str.split('\n').length
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.
That was my first take too. But I needed the index of the last matched \n
in order to calculate the column number.
going to do it a bit different so we cover all the nodes |
pushed add/pos if you want to help hack on that at all, I might not have more time tonight but should soon {
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "comment",
"comment": " foo ",
"position": {
"start": {
"line": 2
},
"end": {
"line": 4
}
}
},
{
"type": "rule",
"selectors": [
"body"
],
"declarations": [
{
"type": "comment",
"comment": "",
"position": {
"start": {
"line": 5
},
"end": {
"line": 5
}
}
},
{
"type": "declaration",
"property": "foo",
"value": "'bar'",
"position": {
"start": {
"line": 5
},
"end": {
"line": 6
}
}
},
{
"type": "declaration",
"property": "bar",
"value": "'baz'",
"position": {
"start": {
"line": 6
},
"end": {
"line": 7
}
}
}
],
"position": {
"start": {
"line": 4
},
"end": {
"line": 8
}
}
}
]
}
} |
Cool. I didn't include the other node types because the browser's dev tools only support rule-based mapping. But you're right, we should include the information for all nodes as this might be useful for other tools. I also like the idea of exposing both |
When
{ loc: true }
is passed as second argument allrule
nodes will include aloc
property that contains the line and column number of the first selector. This info is read by css-stringify and can be used to generate a source-map.