MCPcopy
hub / github.com/webpack/tapable / create

Method create

lib/HookCodeFactory.js:14–77  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

12 }
13
14 create(options) {
15 this.init(options);
16 let fn;
17 switch (options.type) {
18 case "sync":
19 fn = new Function(
20 this.args(),
21 `"use strict";\n${this.header()}${this.contentWithInterceptors({
22 onError: (err) => `throw ${err};\n`,
23 onResult: (result) => `return ${result};\n`,
24 resultReturns: true,
25 onDone: () => "",
26 rethrowIfPossible: true
27 })}`
28 );
29 break;
30 case "async":
31 fn = new Function(
32 this.args({
33 after: "_callback"
34 }),
35 `"use strict";\n${this.header()}${this.contentWithInterceptors({
36 onError: (err) => `_callback(${err});\n`,
37 onResult: (result) => `_callback(null, ${result});\n`,
38 onDone: () => "_callback();\n"
39 })}`
40 );
41 break;
42 case "promise": {
43 let errorHelperUsed = false;
44 const content = this.contentWithInterceptors({
45 onError: (err) => {
46 errorHelperUsed = true;
47 return `_error(${err});\n`;
48 },
49 onResult: (result) => `_resolve(${result});\n`,
50 onDone: () => "_resolve();\n"
51 });
52 let code = "";
53 code += '"use strict";\n';
54 code += this.header();
55 code += "return new Promise((function(_resolve, _reject) {\n";
56 if (errorHelperUsed) {
57 code += "var _sync = true;\n";
58 code += "function _error(_err) {\n";
59 code += "if(_sync)\n";
60 code +=
61 "_resolve(Promise.resolve().then((function() { throw _err; })));\n";
62 code += "else\n";
63 code += "_reject(_err);\n";
64 code += "};\n";
65 }
66 code += content;
67 if (errorHelperUsed) {
68 code += "_sync = false;\n";
69 }
70 code += "}));\n";
71 fn = new Function(this.args(), code);

Callers 10

COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80
COMPILEFunction · 0.80

Calls 5

initMethod · 0.95
argsMethod · 0.95
headerMethod · 0.95
deinitMethod · 0.95

Tested by

no test coverage detected