選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SyncBailHook.js 970B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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, resultReturns, onDone, rethrowIfPossible }) {
  10. return this.callTapsSeries({
  11. onError: (i, err) => onError(err),
  12. onResult: (i, result, next) =>
  13. `if(${result} !== undefined) {\n${onResult(
  14. result
  15. )};\n} else {\n${next()}}\n`,
  16. resultReturns,
  17. onDone,
  18. rethrowIfPossible
  19. });
  20. }
  21. }
  22. const factory = new SyncBailHookCodeFactory();
  23. class SyncBailHook extends Hook {
  24. tapAsync() {
  25. throw new Error("tapAsync is not supported on a SyncBailHook");
  26. }
  27. tapPromise() {
  28. throw new Error("tapPromise is not supported on a SyncBailHook");
  29. }
  30. compile(options) {
  31. factory.setup(this, options);
  32. return factory.create(options);
  33. }
  34. }
  35. module.exports = SyncBailHook;