Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

fgnass
Copy link
Contributor

@fgnass fgnass commented May 18, 2013

When { loc: true } is passed as second argument all rule nodes will include a loc 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.

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;
}
Copy link
Member

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

Copy link
Contributor Author

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.

@tj
Copy link
Member

tj commented May 21, 2013

going to do it a bit different so we cover all the nodes

@tj
Copy link
Member

tj commented May 22, 2013

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
          }
        }
      }
    ]
  }
}

@fgnass
Copy link
Contributor Author

fgnass commented May 22, 2013

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 start and end. Although this information isn't needed for the source map generation it still could be useful in other scenarios.

@tj tj closed this May 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants