@@ -65,6 +65,7 @@ const memoize = require("./util/memoize");
6565/** @typedef {import("./DependencyTemplates") } DependencyTemplates */
6666/** @typedef {import("./Generator") } Generator */
6767/** @typedef {import("./Generator").GenerateErrorFn } GenerateErrorFn */
68+ /** @typedef {import("./Generator").GenerateContextData } GenerateContextData */
6869/** @typedef {import("./Module").BuildInfo } BuildInfo */
6970/** @typedef {import("./Module").BuildMeta } BuildMeta */
7071/** @typedef {import("./Module").CodeGenerationContext } CodeGenerationContext */
@@ -79,7 +80,7 @@ const memoize = require("./util/memoize");
7980/** @typedef {import("./Module").UnsafeCacheData } UnsafeCacheData */
8081/** @typedef {import("./ModuleGraph") } ModuleGraph */
8182/** @typedef {import("./ModuleGraphConnection").ConnectionState } ConnectionState */
82- /** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes } JavaScriptModuleTypes */
83+ /** @typedef {import("./ModuleTypeConstants").ModuleTypes } ModuleTypes */
8384/** @typedef {import("./NormalModuleFactory") } NormalModuleFactory */
8485/** @typedef {import("./NormalModuleFactory").ResourceDataWithData } ResourceDataWithData */
8586/** @typedef {import("./NormalModuleFactory").ResourceSchemeData } ResourceSchemeData */
@@ -148,12 +149,14 @@ const contextifySourceUrl = (context, source, associatedObjectForCache) => {
148149
149150/**
150151 * @param {string } context absolute context path
151- * @param {RawSourceMap } sourceMap a source map
152+ * @param {string | RawSourceMap } sourceMap a source map
152153 * @param {AssociatedObjectForCache= } associatedObjectForCache an object to which the cache will be attached
153- * @returns {RawSourceMap } new source map
154+ * @returns {string | RawSourceMap } new source map
154155 */
155156const contextifySourceMap = ( context , sourceMap , associatedObjectForCache ) => {
156- if ( ! Array . isArray ( sourceMap . sources ) ) return sourceMap ;
157+ if ( typeof sourceMap === "string" || ! Array . isArray ( sourceMap . sources ) ) {
158+ return sourceMap ;
159+ }
157160 const { sourceRoot } = sourceMap ;
158161 /** @type {(source: string) => string } */
159162 const mapper = ! sourceRoot
@@ -218,7 +221,7 @@ makeSerializable(
218221 "NonErrorEmittedError"
219222) ;
220223
221- /** @typedef {[string | Buffer, string | SourceMapSource , PreparsedAst] } Result */
224+ /** @typedef {[string | Buffer, string | RawSourceMap | undefined , PreparsedAst | undefined ] } Result */
222225
223226/**
224227 * @typedef {object } NormalModuleCompilationHooks
@@ -235,7 +238,7 @@ makeSerializable(
235238/**
236239 * @typedef {object } NormalModuleCreateData
237240 * @property {string= } layer an optional layer in which the module is
238- * @property {JavaScriptModuleTypes | "" } type module type. When deserializing, this is set to an empty string "".
241+ * @property {ModuleTypes | "" } type module type. When deserializing, this is set to an empty string "".
239242 * @property {string } request request string
240243 * @property {string } userRequest request intended by user (without loaders from config)
241244 * @property {string } rawRequest request without resolving
@@ -254,8 +257,6 @@ makeSerializable(
254257/** @type {WeakMap<Compilation, NormalModuleCompilationHooks> } */
255258const compilationHooksMap = new WeakMap ( ) ;
256259
257- /** @typedef {Map<string, EXPECTED_ANY> } CodeGeneratorData */
258-
259260class NormalModule extends Module {
260261 /**
261262 * @param {Compilation } compilation the compilation
@@ -396,7 +397,7 @@ class NormalModule extends Module {
396397 this . _isEvaluatingSideEffects = false ;
397398 /** @type {WeakSet<ModuleGraph> | undefined } */
398399 this . _addedSideEffectsBailout = undefined ;
399- /** @type {CodeGeneratorData } */
400+ /** @type {GenerateContextData } */
400401 this . _codeGeneratorData = new Map ( ) ;
401402 }
402403
@@ -855,7 +856,7 @@ class NormalModule extends Module {
855856 /**
856857 * @param {string } context the compilation context
857858 * @param {string | Buffer } content the content
858- * @param {(string | SourceMapSource | null)= } sourceMap an optional source map
859+ * @param {(string | RawSourceMap | null)= } sourceMap an optional source map
859860 * @param {AssociatedObjectForCache= } associatedObjectForCache object for caching
860861 * @returns {Source } the created source
861862 */
@@ -876,11 +877,7 @@ class NormalModule extends Module {
876877 return new SourceMapSource (
877878 content ,
878879 contextifySourceUrl ( context , identifier , associatedObjectForCache ) ,
879- contextifySourceMap (
880- context ,
881- /** @type {TODO } */ ( sourceMap ) ,
882- associatedObjectForCache
883- )
880+ contextifySourceMap ( context , sourceMap , associatedObjectForCache )
884881 ) ;
885882 }
886883
@@ -914,10 +911,10 @@ class NormalModule extends Module {
914911
915912 /**
916913 * @param {Error | null } err err
917- * @param {(Result | null)= } _result result
914+ * @param {(Result | null)= } result_ result
918915 * @returns {void }
919916 */
920- const processResult = ( err , _result ) => {
917+ const processResult = ( err , result_ ) => {
921918 if ( err ) {
922919 if ( ! ( err instanceof Error ) ) {
923920 err = new NonErrorEmittedError ( err ) ;
@@ -933,7 +930,8 @@ class NormalModule extends Module {
933930 return callback ( error ) ;
934931 }
935932 const result = hooks . processResult . call (
936- /** @type {Result } */ ( _result ) ,
933+ /** @type {Result } */
934+ ( result_ ) ,
937935 this
938936 ) ;
939937 const source = result [ 0 ] ;
@@ -1455,9 +1453,6 @@ class NormalModule extends Module {
14551453 runtimeRequirements . add ( RuntimeGlobals . thisAsExports ) ;
14561454 }
14571455
1458- /**
1459- * @type {() => CodeGeneratorData }
1460- */
14611456 const getData = ( ) => this . _codeGeneratorData ;
14621457
14631458 const sources = new Map ( ) ;
0 commit comments