Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ed4a64

Browse filesBrowse files
fix: types
1 parent 6801022 commit 0ed4a64
Copy full SHA for 0ed4a64
Expand file treeCollapse file tree

30 files changed

+379
-87
lines changed
Open diff view settings
Collapse file

‎declarations.d.ts‎

Copy file name to clipboardExpand all lines: declarations.d.ts
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,17 @@ declare module "neo-async" {
147147

148148
// There are no typings for @webassemblyjs/ast
149149
declare module "@webassemblyjs/ast" {
150-
export type AST = TODO;
150+
export class AST extends Node {
151+
type: "Program";
152+
body: [Module];
153+
}
151154
export interface Visitor {
152155
ModuleImport?: (p: NodePath<ModuleImport>) => void;
153156
ModuleExport?: (p: NodePath<ModuleExport>) => void;
154157
Start?: (p: NodePath<Start>) => void;
155158
Global?: (p: NodePath<Global>) => void;
156159
}
157-
export function traverse(ast: AST, visitor: Visitor): void;
160+
export function traverse(node: Node, visitor: Visitor): void;
158161
export class NodePath<T> {
159162
node: T;
160163
remove(): void;
@@ -169,9 +172,9 @@ declare module "@webassemblyjs/ast" {
169172
index: Identifier;
170173
}
171174
export class Module extends Node {
172-
id: TODO;
175+
id: string;
173176
fields: Node[];
174-
metadata: TODO;
177+
metadata?: Record<string, EXPECTED_ANY>;
175178
}
176179
export class ModuleImportDescription {
177180
type: string;
@@ -189,7 +192,7 @@ declare module "@webassemblyjs/ast" {
189192
name: string;
190193
descr: ModuleExportDescr;
191194
}
192-
type Index = Identifier | NumberLiteral;
195+
type Index = NumberLiteral;
193196
export class ModuleExportDescr extends Node {
194197
type: string;
195198
exportType: string;
@@ -273,7 +276,10 @@ declare module "@webassemblyjs/ast" {
273276
args: string[];
274277
result: string[];
275278
}
276-
export function moduleContextFromModuleAST(module: Module): TODO;
279+
export function moduleContextFromModuleAST(module: Module): {
280+
getFunction(i: number): FuncSignature;
281+
getStart(): Index;
282+
};
277283

278284
// Node matcher
279285
export function isGlobalType(n: Node): boolean;
Collapse file

‎lib/DllEntryPlugin.js‎

Copy file name to clipboardExpand all lines: lib/DllEntryPlugin.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ const DllEntryDependency = require("./dependencies/DllEntryDependency");
1010
const EntryDependency = require("./dependencies/EntryDependency");
1111

1212
/** @typedef {import("./Compiler")} Compiler */
13+
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
14+
1315
/** @typedef {string[]} Entries */
14-
/** @typedef {{ name: string, filename: TODO }} Options */
16+
/** @typedef {EntryOptions & { name: string }} Options */
1517

1618
const PLUGIN_NAME = "DllEntryPlugin";
1719

Collapse file

‎lib/DllPlugin.js‎

Copy file name to clipboardExpand all lines: lib/DllPlugin.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ class DllPlugin {
4848
if (typeof entry !== "function") {
4949
for (const name of Object.keys(entry)) {
5050
/** @type {Options} */
51-
const options = { name, filename: entry.filename };
51+
const options = { name };
5252
new DllEntryPlugin(
5353
context,
54-
/** @type {Entries} */ (entry[name].import),
54+
/** @type {Entries} */
55+
(entry[name].import),
5556
options
5657
).apply(compiler);
5758
}
Collapse file

‎lib/ExternalModule.js‎

Copy file name to clipboardExpand all lines: lib/ExternalModule.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class ExternalModule extends Module {
588588
this.buildInfo = {
589589
strict: true,
590590
topLevelDeclarations: new Set(),
591-
module: compilation.outputOptions.module
591+
javascriptModule: compilation.outputOptions.module
592592
};
593593
const { request, externalType } = this._getRequestAndExternalType();
594594
this.buildMeta.exportsType = "dynamic";
@@ -605,7 +605,7 @@ class ExternalModule extends Module {
605605
}
606606
break;
607607
case "module":
608-
if (this.buildInfo.module) {
608+
if (this.buildInfo.javascriptModule) {
609609
if (!Array.isArray(request) || request.length === 1) {
610610
this.buildMeta.exportsType = "namespace";
611611
canMangle = true;
@@ -760,7 +760,7 @@ class ExternalModule extends Module {
760760
case "commonjs-static":
761761
return getSourceForCommonJsExternal(request);
762762
case "node-commonjs":
763-
return /** @type {BuildInfo} */ (this.buildInfo).module
763+
return /** @type {BuildInfo} */ (this.buildInfo).javascriptModule
764764
? getSourceForCommonJsExternalInNodeModule(
765765
request,
766766
/** @type {string} */
@@ -792,7 +792,7 @@ class ExternalModule extends Module {
792792
case "script":
793793
return getSourceForScriptExternal(request, runtimeTemplate);
794794
case "module": {
795-
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
795+
if (!(/** @type {BuildInfo} */ (this.buildInfo).javascriptModule)) {
796796
if (!runtimeTemplate.supportsDynamicImport()) {
797797
throw new Error(
798798
`The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
Collapse file

‎lib/Generator.js‎

Copy file name to clipboardExpand all lines: lib/Generator.js
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/** @typedef {import("./ChunkGraph")} ChunkGraph */
1010
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
1111
/** @typedef {import("./Compilation")} Compilation */
12+
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
1213
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
1314
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
1415
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
@@ -21,6 +22,15 @@
2122
/** @typedef {import("./util/Hash")} Hash */
2223
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
2324

25+
/**
26+
* @template T
27+
* @typedef {import("./InitFragment")<T>} InitFragment
28+
*/
29+
30+
/** @typedef {Map<"url", { [key: string]: string }> & Map<"fullContentHash", string> & Map<"contentHash", string> & Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"chunkInitFragments", InitFragment<GenerateContext>[]>} KnownGenerateContextData */
31+
32+
/** @typedef {KnownGenerateContextData & Record<string, EXPECTED_ANY>} GenerateContextData */
33+
2434
/**
2535
* @typedef {object} GenerateContext
2636
* @property {DependencyTemplates} dependencyTemplates mapping from dependencies to templates
@@ -32,7 +42,7 @@
3242
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
3343
* @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
3444
* @property {string} type which kind of code should be generated
35-
* @property {() => Map<string, TODO>=} getData get access to the code generation data
45+
* @property {() => GenerateContextData=} getData get access to the code generation data
3646
*/
3747

3848
/**
Collapse file

‎lib/JavascriptMetaInfoPlugin.js‎

Copy file name to clipboardExpand all lines: lib/JavascriptMetaInfoPlugin.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class JavascriptMetaInfoPlugin {
3838
/** @type {BuildInfo} */
3939
(parser.state.module.buildInfo);
4040
buildInfo.moduleConcatenationBailout = "eval()";
41-
buildInfo.usingEval = true;
4241
const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
4342
if (currentSymbol) {
4443
InnerGraph.addUsage(parser.state, null, currentSymbol);
Collapse file

‎lib/LoaderOptionsPlugin.js‎

Copy file name to clipboardExpand all lines: lib/LoaderOptionsPlugin.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ class LoaderOptionsPlugin {
3939
// If no options are set then generate empty options object
4040
if (typeof options !== "object") options = {};
4141
if (!options.test) {
42-
/** @type {TODO} */
42+
/** @type {Partial<RegExp>} */
4343
const defaultTrueMockRegExp = {
4444
test: () => true
4545
};
4646

4747
/** @type {RegExp} */
48-
options.test = defaultTrueMockRegExp;
48+
options.test =
49+
/** @type {RegExp} */
50+
(defaultTrueMockRegExp);
4951
}
5052
this.options = options;
5153
}
@@ -75,7 +77,7 @@ class LoaderOptionsPlugin {
7577
continue;
7678
}
7779

78-
/** @type {TODO} */
80+
/** @type {LoaderContext<EXPECTED_ANY> & Record<string, EXPECTED_ANY>} */
7981
(context)[key] = options[key];
8082
}
8183
}
Collapse file

‎lib/Module.js‎

Copy file name to clipboardExpand all lines: lib/Module.js
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const makeSerializable = require("./util/makeSerializable");
4040
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
4141
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
4242
/** @typedef {import("./WebpackError")} WebpackError */
43+
/** @typedef {import("./json/JsonData")} JsonData */
4344
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
4445
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
4546
/** @typedef {import("./util/Hash")} Hash */
@@ -116,6 +117,7 @@ const makeSerializable = require("./util/makeSerializable");
116117
* @property {boolean=} sideEffectFree
117118
* @property {Record<string, string>=} exportsFinalName
118119
* @property {boolean=} isCSSModule
120+
* @property {Record<string, string>=} jsIncompatibleExports
119121
*/
120122

121123
/**
@@ -134,13 +136,17 @@ const makeSerializable = require("./util/makeSerializable");
134136
* @property {LazySet<string>=} buildDependencies using in NormalModule
135137
* @property {ValueCacheVersions=} valueDependencies using in NormalModule
136138
* @property {Record<string, Source>=} assets using in NormalModule
139+
* @property {Map<string, AssetInfo | undefined>=} assetsInfo using in NormalModule
137140
* @property {string=} hash using in NormalModule
138141
* @property {(Snapshot | null)=} snapshot using in ContextModule
139142
* @property {string=} fullContentHash for assets modules
140143
* @property {string=} filename for assets modules
141-
* @property {Map<string, AssetInfo | undefined>=} assetsInfo for assets modules
142144
* @property {boolean=} dataUrl for assets modules
145+
* @property {AssetInfo=} assetInfo for assets modules
146+
* @property {boolean=} javascriptModule for external modules
147+
* @property {boolean=} active for lazy compilation modules
143148
* @property {CssData=} cssData for css modules
149+
* @property {JsonData=} jsonData for json modules
144150
* @property {Set<string>=} topLevelDeclarations top level declaration names
145151
*/
146152

Collapse file

‎lib/MultiCompiler.js‎

Copy file name to clipboardExpand all lines: lib/MultiCompiler.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ module.exports = class MultiCompiler {
324324
* @deprecated This method should have been private
325325
* @param {Compiler[]} compilers the child compilers
326326
* @param {RunWithDependenciesHandler} fn a handler to run for each compiler
327-
* @param {Callback<MultiStats>} callback the compiler's handler
327+
* @param {Callback<Stats[]>} callback the compiler's handler
328328
* @returns {void}
329329
*/
330330
runWithDependencies(compilers, fn, callback) {
@@ -355,7 +355,7 @@ module.exports = class MultiCompiler {
355355
return readyCompilers;
356356
};
357357
/**
358-
* @param {Callback<MultiStats>} callback callback
358+
* @param {Callback<Stats[]>} callback callback
359359
* @returns {void}
360360
*/
361361
const runCompilers = callback => {
@@ -370,7 +370,7 @@ module.exports = class MultiCompiler {
370370
});
371371
},
372372
(err, results) => {
373-
callback(err, /** @type {TODO} */ (results));
373+
callback(err, results);
374374
}
375375
);
376376
};
Collapse file

‎lib/NormalModule.js‎

Copy file name to clipboardExpand all lines: lib/NormalModule.js
+16-21Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
155156
const 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>} */
255258
const compilationHooksMap = new WeakMap();
256259

257-
/** @typedef {Map<string, EXPECTED_ANY>} CodeGeneratorData */
258-
259260
class 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.