streamChunks.js 906 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const streamChunksOfRawSource = require("./streamChunksOfRawSource");
  7. const streamChunksOfSourceMap = require("./streamChunksOfSourceMap");
  8. module.exports = (source, options, onChunk, onSource, onName) => {
  9. if (typeof source.streamChunks === "function") {
  10. return source.streamChunks(options, onChunk, onSource, onName);
  11. } else {
  12. const sourceAndMap = source.sourceAndMap(options);
  13. if (sourceAndMap.map) {
  14. return streamChunksOfSourceMap(
  15. sourceAndMap.source,
  16. sourceAndMap.map,
  17. onChunk,
  18. onSource,
  19. onName,
  20. !!(options && options.finalSource),
  21. !!(options && options.columns !== false)
  22. );
  23. } else {
  24. return streamChunksOfRawSource(
  25. sourceAndMap.source,
  26. onChunk,
  27. onSource,
  28. onName,
  29. !!(options && options.finalSource)
  30. );
  31. }
  32. }
  33. };