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

Method contentWithInterceptors

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

Source from the content-addressed store, hash-verified

105 }
106
107 contentWithInterceptors(options) {
108 if (this.options.interceptors.length > 0) {
109 const { onError, onResult, onDone } = options;
110 let code = "";
111 for (let i = 0; i < this.options.interceptors.length; i++) {
112 const interceptor = this.options.interceptors[i];
113 if (interceptor.call) {
114 code += `${this.getInterceptor(i)}.call(${this.args({
115 before: interceptor.context ? "_context" : undefined
116 })});\n`;
117 }
118 }
119 code += this.content(
120 Object.assign(options, {
121 onError:
122 onError &&
123 ((err) => {
124 let code = "";
125 for (let i = 0; i < this.options.interceptors.length; i++) {
126 const interceptor = this.options.interceptors[i];
127 if (interceptor.error) {
128 code += `${this.getInterceptor(i)}.error(${err});\n`;
129 }
130 }
131 code += onError(err);
132 return code;
133 }),
134 onResult:
135 onResult &&
136 ((result) => {
137 let code = "";
138 for (let i = 0; i < this.options.interceptors.length; i++) {
139 const interceptor = this.options.interceptors[i];
140 if (interceptor.result) {
141 code += `${this.getInterceptor(i)}.result(${result});\n`;
142 }
143 }
144 code += onResult(result);
145 return code;
146 }),
147 onDone:
148 onDone &&
149 (() => {
150 let code = "";
151 for (let i = 0; i < this.options.interceptors.length; i++) {
152 const interceptor = this.options.interceptors[i];
153 if (interceptor.done) {
154 code += `${this.getInterceptor(i)}.done();\n`;
155 }
156 }
157 code += onDone();
158 return code;
159 })
160 })
161 );
162 return code;
163 }
164 return this.content(options);

Callers 1

createMethod · 0.95

Calls 3

getInterceptorMethod · 0.95
argsMethod · 0.95
contentMethod · 0.45

Tested by

no test coverage detected