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.

90 lines
2.4 KiB

4 years ago
  1. # source-list-map
  2. ## API
  3. ### Example
  4. ``` js
  5. var SourceListMap = require("source-list-map").SourceListMap;
  6. // Create a new map
  7. var map = new SourceListMap();
  8. // Add generated code that is map line to line to some soure
  9. map.add("Generated\ncode1\n", "source-code.js", "Orginal\nsource");
  10. // Add generated code that isn't mapped
  11. map.add("Generated\ncode2\n");
  12. // Get SourceMap and generated source
  13. map.toStringWithSourceMap({ file: "generated-code.js" });
  14. // {
  15. // source: 'Generated\ncode1\nGenerated\ncode2\n',
  16. // map: {
  17. // version: 3,
  18. // file: 'generated-code.js',
  19. // sources: [ 'source-code.js' ],
  20. // sourcesContent: [ 'Orginal\nsource' ],
  21. // mappings: 'AAAA;AACA;;;'
  22. // }
  23. // }
  24. // Convert existing SourceMap into SourceListMap
  25. // (Only the first mapping per line is preserved)
  26. var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
  27. var map = fromStringWithSourceMap("Generated\ncode", { version: 3, ... });
  28. ```
  29. ### `new SourceListMap()`
  30. ### `SourceListMap.prototype.add`
  31. ``` js
  32. SourceListMap.prototype.add(generatedCode: string)
  33. SourceListMap.prototype.add(generatedCode: string, source: string, originalSource: string)
  34. SourceListMap.prototype.add(sourceListMap: SourceListMap)
  35. ```
  36. Append some stuff.
  37. ### `SourceListMap.prototype.prepend`
  38. ``` js
  39. SourceListMap.prototype.prepend(generatedCode: string)
  40. SourceListMap.prototype.prepend(generatedCode: string, source: string, originalSource: string)
  41. SourceListMap.prototype.prepend(sourceListMap: SourceListMap)
  42. ```
  43. Prepend some stuff.
  44. ### `SourceListMap.prototype.toString()`
  45. Get generated code.
  46. ### `SourceListMap.prototype.toStringWithSourceMap`
  47. ``` js
  48. SourceListMap.prototype.toStringWithSourceMap(options: object)
  49. ```
  50. Get generated code and SourceMap. `options` can contains `file` property which defines the `file` property of the SourceMap.
  51. ### `SourceListMap.prototype.mapGeneratedCode`
  52. ``` js
  53. SourceListMap.prototype.mapGeneratedCode(fn: function) : SourceListMap
  54. ```
  55. Applies `fn` to each generated code block (per line). The returned value is set as new generated code. Returns a new SourceListMap.
  56. Removing and adding lines is supported. The SourceMap complexity will increase when doing this.
  57. ## Test
  58. [![Build Status](https://travis-ci.org/webpack/source-list-map.svg)](https://travis-ci.org/webpack/source-list-map)
  59. ## License
  60. Copyright (c) 2017 JS Foundation
  61. MIT (http://www.opensource.org/licenses/mit-license.php)