您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SourceMapSource.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 SourceMapGenerator = require("source-map").SourceMapGenerator;
  9. var SourceListMap = require("source-list-map").SourceListMap;
  10. var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
  11. var Source = require("./Source");
  12. var applySourceMap = require("./applySourceMap");
  13. class SourceMapSource extends Source {
  14. constructor(value, name, sourceMap, originalSource, innerSourceMap, removeOriginalSource) {
  15. super();
  16. this._value = value;
  17. this._name = name;
  18. this._sourceMap = sourceMap;
  19. this._originalSource = originalSource;
  20. this._innerSourceMap = innerSourceMap;
  21. this._removeOriginalSource = removeOriginalSource;
  22. }
  23. source() {
  24. return this._value;
  25. }
  26. node(options) {
  27. var sourceMap = this._sourceMap;
  28. var node = SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
  29. node.setSourceContent(this._name, this._originalSource);
  30. var innerSourceMap = this._innerSourceMap;
  31. if(innerSourceMap) {
  32. node = applySourceMap(node, new SourceMapConsumer(innerSourceMap), this._name, this._removeOriginalSource);
  33. }
  34. return node;
  35. }
  36. listMap(options) {
  37. options = options || {};
  38. if(options.module === false)
  39. return new SourceListMap(this._value, this._name, this._value);
  40. return fromStringWithSourceMap(this._value, typeof this._sourceMap === "string" ? JSON.parse(this._sourceMap) : this._sourceMap);
  41. }
  42. updateHash(hash) {
  43. hash.update(this._value);
  44. if(this._originalSource)
  45. hash.update(this._originalSource);
  46. }
  47. }
  48. require("./SourceAndMapMixin")(SourceMapSource.prototype);
  49. module.exports = SourceMapSource;