getsentry / rust-sourcemap

A library for rust that implements basic sourcemap handling
Other
224 stars 27 forks source link

results from SourceMap::lookup_token is not correct #7

Closed Brooooooklyn closed 6 years ago

Brooooooklyn commented 6 years ago

you can find a playground project in https://github.com/Brooooooklyn/sourcemap-issue

and yarn && yarn start to see the follow result:

let s = sm.lookup_token(1, 113946).unwrap()
println!("content: {}, column: {}", s.get_source().unwrap(), s.get_src_line());
// '../static/js/main.4a1cd49f.js', 2357

and the result from https://www.npmjs.com/package/source-map:

const jsDecoder = new SourceMapConsumer(sourcemap)
const jsResult = jsDecoder.originalPositionFor({
  line: 1,
  column: 113946
})

console.log(jsResult)
// { source: 'service.ts', line: 10, column: 0, name: null }
Brooooooklyn commented 6 years ago

@mitsuhiko

mitsuhiko commented 6 years ago

The line and column are zero indexed on lookup. Presumably you are passing wrong data.

Brooooooklyn commented 6 years ago

that's wired, because the same file is decoded correctly by https://www.npmjs.com/package/source-map

mitsuhiko commented 6 years ago

@Brooooooklyn not sure what you mean. this library intentionally uses zero indexed values so you are passing the wrong values into the lookup functions.

mitsuhiko commented 6 years ago

To clarify that: if you want to look up line 1 and column 1 you need to pass (0, 0) and not (1, 1).

Brooooooklyn commented 6 years ago

Oh, I get it , sorry for my misunderstanding.