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 source map can't concat in a single line #114

Open
ahabhgk opened this issue Sep 2, 2022 · 0 comments
Open

Add source map can't concat in a single line #114

ahabhgk opened this issue Sep 2, 2022 · 0 comments

Comments

@ahabhgk
Copy link
Contributor

ahabhgk commented Sep 2, 2022

Trying to concat "hello " and "world" in a single line, the minimal reproduce is here:

#[test]
fn reproduce() {
  let mut hello_map = SourceMap::new("/");
  let hello = hello_map.add_source("hello.txt");
  hello_map.set_source_content(hello as usize, "hello ");
  hello_map.add_mapping(
    0,
    0,
    Some(parcel_sourcemap::OriginalLocation {
      original_line: 0,
      original_column: 0,
      source: hello,
      name: None,
    }),
  );
  let mut world_map = SourceMap::new("/");
  let world = world_map.add_source("world.txt");
  world_map.set_source_content(world as usize, "world");
  world_map.add_mapping(
    0,
    0,
    Some(parcel_sourcemap::OriginalLocation {
      original_line: 0,
      original_column: 0,
      source: world,
      name: None,
    }),
  );
  let mut hello_world_map = SourceMap::new("/");
  hello_world_map.add_sourcemap(&mut hello_map, 0);
  hello_world_map.add_sourcemap(&mut world_map, 0);
  println!("{}", hello_world_map.to_json(None).unwrap()); // {"version":3,"sourceRoot":null,"mappings":"ACAA","sources":["hello.txt","world.txt"],"sourcesContent":["hello ","world"],"names":[]}
}

generated map: {"version":3,"sourceRoot":null,"mappings":"ACAA","sources":["hello.txt","world.txt"],"sourcesContent":["hello ","world"],"names":[]} }.
generated string: hello world.

"hello " will loose the mapping, "world" will map to "hello world".

Screen Shot 2022-09-02 at 17 01 55

Screen Shot 2022-09-02 at 17 01 33

playground link: https://evanw.github.io/source-map-visualization/#MTEAaGVsbG8gd29ybGQxMzIAeyJ2ZXJzaW9uIjozLCJzb3VyY2VSb290IjpudWxsLCJtYXBwaW5ncyI6IkFDQUEiLCJzb3VyY2VzIjpbImhlbGxvLnR4dCIsIndvcmxkLnR4dCJdLCJzb3VyY2VzQ29udGVudCI6WyJoZWxsbyAiLCJ3b3JsZCJdLCJuYW1lcyI6W119

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

No branches or pull requests

1 participant