web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

  1. # sourcemap-codec
  2. Encode/decode the `mappings` property of a [sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit).
  3. ## Why?
  4. Sourcemaps are difficult to generate and manipulate, because the `mappings` property – the part that actually links the generated code back to the original source – is encoded using an obscure method called [Variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity). On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can't look at a segment in isolation – you have to understand the whole sourcemap.
  5. This package makes the process slightly easier.
  6. ## Installation
  7. ```bash
  8. npm install sourcemap-codec
  9. ```
  10. ## Usage
  11. ```js
  12. import { encode, decode } from 'sourcemap-codec';
  13. var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );
  14. assert.deepEqual( decoded, [
  15. // the first line (of the generated code) has no mappings,
  16. // as shown by the starting semi-colon (which separates lines)
  17. [],
  18. // the second line contains four (comma-separated) segments
  19. [
  20. // segments are encoded as you'd expect:
  21. // [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ]
  22. // i.e. the first segment begins at column 2, and maps back to the second column
  23. // of the second line (both zero-based) of the 0th source, and uses the 0th
  24. // name in the `map.names` array
  25. [ 2, 0, 2, 2, 0 ],
  26. // the remaining segments are 4-length rather than 5-length,
  27. // because they don't map a name
  28. [ 4, 0, 2, 4 ],
  29. [ 6, 0, 2, 5 ],
  30. [ 7, 0, 2, 7 ]
  31. ],
  32. // the final line contains two segments
  33. [
  34. [ 2, 1, 10, 19 ],
  35. [ 12, 1, 11, 20 ]
  36. ]
  37. ]);
  38. var encoded = encode( decoded );
  39. assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );
  40. ```
  41. # License
  42. MIT