SizeOnlySource.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. size() {
  29. return this._size;
  30. }
  31. /**
  32. * @returns {SourceValue} source
  33. */
  34. source() {
  35. throw this._error();
  36. }
  37. /**
  38. * @returns {Buffer} buffer
  39. */
  40. buffer() {
  41. throw this._error();
  42. }
  43. /**
  44. * @param {MapOptions=} options map options
  45. * @returns {RawSourceMap | null} map
  46. */
  47. // eslint-disable-next-line no-unused-vars
  48. map(options) {
  49. throw this._error();
  50. }
  51. /**
  52. * @param {HashLike} hash hash
  53. * @returns {void}
  54. */
  55. // eslint-disable-next-line no-unused-vars
  56. updateHash(hash) {
  57. throw this._error();
  58. }
  59. }
  60. module.exports = SizeOnlySource;