LineToLineMappedSource.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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;