@@ -18,6 +18,9 @@ const {
1818} = require ( "tapable" ) ;
1919const Template = require ( "./Template" ) ;
2020
21+ /** @typedef {import("tapable").Hook } Hook */
22+ /** @typedef {import("webpack-sources").ConcatSource } ConcatSource */
23+
2124// require function shortcuts:
2225// __webpack_require__.s = the module id of the entry point
2326// __webpack_require__.c = the module cache
@@ -35,9 +38,15 @@ const Template = require("./Template");
3538// __webpack_require__.nc = the script nonce
3639
3740module . exports = class MainTemplate extends Tapable {
41+ /**
42+ *
43+ * @param {any= } outputOptions output options for the MainTemplate
44+ */
3845 constructor ( outputOptions ) {
3946 super ( ) ;
47+ /** @type {any? } */
4048 this . outputOptions = outputOptions || { } ;
49+ /** @type {{[hookName: string]: Hook} } */
4150 this . hooks = {
4251 renderManifest : new SyncWaterfallHook ( [ "result" , "options" ] ) ,
4352 modules : new SyncWaterfallHook ( [
@@ -104,6 +113,7 @@ module.exports = class MainTemplate extends Tapable {
104113 hotBootstrap : new SyncWaterfallHook ( [ "source" , "chunk" , "hash" ] )
105114 } ;
106115 this . hooks . startup . tap ( "MainTemplate" , ( source , chunk , hash ) => {
116+ /** @type {string[] } */
107117 const buf = [ ] ;
108118 if ( chunk . entryModule ) {
109119 buf . push ( "// Load entry module and return exports" ) ;
@@ -296,6 +306,11 @@ module.exports = class MainTemplate extends Tapable {
296306 this . requireFn = "__webpack_require__" ;
297307 }
298308
309+ /**
310+ *
311+ * @param {any } options render manifest options
312+ * @returns {any[] } returns render nanifest
313+ */
299314 getRenderManifest ( options ) {
300315 const result = [ ] ;
301316
@@ -304,6 +319,14 @@ module.exports = class MainTemplate extends Tapable {
304319 return result ;
305320 }
306321
322+ /**
323+ *
324+ * @param {string } hash hash to be used for render call
325+ * @param {any } chunk Chunk instance
326+ * @param {any } moduleTemplate ModuleTemplate instance for render
327+ * @param {any } dependencyTemplates DependencyTemplate[]s
328+ * @return {ConcatSource } the newly generated source from rendering
329+ */
307330 render ( hash , chunk , moduleTemplate , dependencyTemplates ) {
308331 const buf = [ ] ;
309332 buf . push (
@@ -349,6 +372,13 @@ module.exports = class MainTemplate extends Tapable {
349372 return new ConcatSource ( source , ";" ) ;
350373 }
351374
375+ /**
376+ *
377+ * @param {string } hash hash for render fn
378+ * @param {any } chunk Chunk instance for require
379+ * @param {(number|string)= } varModuleId module id
380+ * @return {any } the moduleRequire hook call return signature
381+ */
352382 renderRequireFunctionForModule ( hash , chunk , varModuleId ) {
353383 return this . hooks . moduleRequire . call (
354384 this . requireFn ,
@@ -358,6 +388,14 @@ module.exports = class MainTemplate extends Tapable {
358388 ) ;
359389 }
360390
391+ /**
392+ *
393+ * @param {string } hash hash for render add fn
394+ * @param {any } chunk Chunk instance for require add fn
395+ * @param {(string|number)= } varModuleId module id
396+ * @param {any } varModule Module instance
397+ * @return {any } renderAddModule call
398+ */
361399 renderAddModule ( hash , chunk , varModuleId , varModule ) {
362400 return this . hooks . addModule . call (
363401 `modules[${ varModuleId } ] = ${ varModule } ;` ,
@@ -368,6 +406,12 @@ module.exports = class MainTemplate extends Tapable {
368406 ) ;
369407 }
370408
409+ /**
410+ *
411+ * @param {string } hash string hash
412+ * @param {number } length length
413+ * @return {any } call hook return
414+ */
371415 renderCurrentHashCode ( hash , length ) {
372416 length = length || Infinity ;
373417 return this . hooks . currentHash . call (
@@ -376,6 +420,11 @@ module.exports = class MainTemplate extends Tapable {
376420 ) ;
377421 }
378422
423+ /**
424+ *
425+ * @param {object } options get public path options
426+ * @return {any } hook call
427+ */
379428 getPublicPath ( options ) {
380429 return this . hooks . assetPath . call (
381430 this . outputOptions . publicPath || "" ,
0 commit comments