SyncBailHook.js 960 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Hook = require("./Hook");
  7. const HookCodeFactory = require("./HookCodeFactory");
  8. class SyncBailHookCodeFactory extends HookCodeFactory {
  9. content({ onError, onResult, onDone, rethrowIfPossible }) {
  10. return this.callTapsSeries({
  11. onError: (i, err) => onError(err),
  12. onResult: (i, result, next) => `if(${result} !== undefined) {\n${onResult(result)};\n} else {\n${next()}}\n`,
  13. onDone,
  14. rethrowIfPossible
  15. });
  16. }
  17. }
  18. const factory = new SyncBailHookCodeFactory();
  19. class SyncBailHook extends Hook {
  20. tapAsync() {
  21. throw new Error("tapAsync is not supported on a SyncBailHook");
  22. }
  23. tapPromise() {
  24. throw new Error("tapPromise is not supported on a SyncBailHook");
  25. }
  26. compile(options) {
  27. factory.setup(this, options);
  28. return factory.create(options);
  29. }
  30. }
  31. module.exports = SyncBailHook;