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