https://github.com/confact/sourcemap
A sourcemap parser in crystal using vlq decoding
https://github.com/confact/sourcemap
crystal sourcemap sourcemaps
Last synced: 11 months ago
JSON representation
A sourcemap parser in crystal using vlq decoding
- Host: GitHub
- URL: https://github.com/confact/sourcemap
- Owner: confact
- License: mit
- Created: 2022-08-14T15:59:05.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-11T06:45:18.000Z (over 2 years ago)
- Last Synced: 2025-02-15T14:54:22.811Z (11 months ago)
- Topics: crystal, sourcemap, sourcemaps
- Language: Crystal
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sourcemap Parser
A sourcemap parser in crystal, using vlq encoding.
This repo use changed code from the repo [ConradIrwin/ruby-source_map](https://github.com/ConradIrwin/ruby-source_map). Thanks Conrad Irwin!
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
sourcemap:
github: confact/sourcemap
```
2. Run `shards install`
## Usage
```crystal
require "sourcemap"
```
Get a sourcemap from a sourcemap file:
```crystal
Sourcemap::Parser.from_file("sourcemap.js.map")
```
Get a sourcemap from a sourcemap json string:
```crystal
Sourcemap::Parser.from_string(sourcemap_string)
```
To get the mappings of the sourcemap:
```crystal
sourcemap = Sourcemap::Parser.from_file("sourcemap.js.map")
sourcemap.parsed_mappings
```
It will return an array of Sourcemap::Mapping. Those mappings can be used to get the original source code and the original line and column.
Retrive all mappings for a line and column:
```crystal
sourcemap = Sourcemap::Parser.from_file("sourcemap.js.map")
mapping = sourcemap.mapping_for(1, 1)
```
Get mappings for specific source file:
```crystal
sourcemap = Sourcemap::Parser.from_file("sourcemap.js.map")
sourcemap.mappings_for_source("sourcemap.js")
```
## Development
clone the repo and see the code and test the specs. the specs can be run with `crystal spec`
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Håkan](https://github.com/confact) - creator and maintainer