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.

49 lines
1.2 KiB

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. var SourceNode = require("source-map").SourceNode;
  7. var SourceMapConsumer = require("source-map").SourceMapConsumer;
  8. var SourceListMap = require("source-list-map").SourceListMap;
  9. var Source = require("./Source");
  10. class LineToLineMappedSource extends Source {
  11. constructor(value, name, originalSource) {
  12. super();
  13. this._value = value;
  14. this._name = name;
  15. this._originalSource = originalSource;
  16. }
  17. source() {
  18. return this._value;
  19. }
  20. node(options) {
  21. var value = this._value;
  22. var name = this._name;
  23. var lines = value.split("\n");
  24. var node = new SourceNode(null, null, null,
  25. lines.map(function(line, idx) {
  26. return new SourceNode(idx + 1, 0, name, (line + (idx != lines.length - 1 ? "\n" : "")));
  27. })
  28. );
  29. node.setSourceContent(name, this._originalSource);
  30. return node;
  31. }
  32. listMap(options) {
  33. return new SourceListMap(this._value, this._name, this._originalSource)
  34. }
  35. updateHash(hash) {
  36. hash.update(this._value);
  37. hash.update(this._originalSource);
  38. }
  39. }
  40. require("./SourceAndMapMixin")(LineToLineMappedSource.prototype);
  41. module.exports = LineToLineMappedSource;