SizeOnlySource.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Source = require("./Source");
  7. /** @typedef {import("./Source").HashLike} HashLike */
  8. /** @typedef {import("./Source").MapOptions} MapOptions */
  9. /** @typedef {import("./Source").RawSourceMap} RawSourceMap */
  10. /** @typedef {import("./Source").SourceValue} SourceValue */
  11. class SizeOnlySource extends Source {
  12. /**
  13. * @param {number} size size
  14. */
  15. constructor(size) {
  16. super();
  17. /**
  18. * @private
  19. * @type {number}
  20. */
  21. this._size = size;
  22. }
  23. _error() {
  24. return new Error(
  25. "Content and Map of this Source is not available (only size() is supported)",
  26. );
  27. }
  28. /**
  29. * @returns {number} size
  30. */
  31. size() {
  32. return this._size;
  33. }
  34. /**
  35. * @returns {SourceValue} source
  36. */
  37. source() {
  38. throw this._error();
  39. }
  40. /**
  41. * @returns {Buffer} buffer
  42. */
  43. buffer() {
  44. throw this._error();
  45. }
  46. /**
  47. * @returns {Buffer[]} buffers
  48. */
  49. buffers() {
  50. throw this._error();
  51. }
  52. /**
  53. * @param {MapOptions=} options map options
  54. * @returns {RawSourceMap | null} map
  55. */
  56. // eslint-disable-next-line no-unused-vars
  57. map(options) {
  58. throw this._error();
  59. }
  60. /**
  61. * @param {HashLike} hash hash
  62. * @returns {void}
  63. */
  64. // eslint-disable-next-line no-unused-vars
  65. updateHash(hash) {
  66. throw this._error();
  67. }
  68. }
  69. module.exports = SizeOnlySource;