Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ declare module "neo-async" {

// There are no typings for @webassemblyjs/ast
declare module "@webassemblyjs/ast" {
export type AST = TODO;
export class AST extends Node {
type: "Program";
body: [Module];
}
export interface Visitor {
ModuleImport?: (p: NodePath<ModuleImport>) => void;
ModuleExport?: (p: NodePath<ModuleExport>) => void;
Start?: (p: NodePath<Start>) => void;
Global?: (p: NodePath<Global>) => void;
}
export function traverse(ast: AST, visitor: Visitor): void;
export function traverse(node: Node, visitor: Visitor): void;
export class NodePath<T> {
node: T;
remove(): void;
Expand All @@ -169,9 +172,9 @@ declare module "@webassemblyjs/ast" {
index: Identifier;
}
export class Module extends Node {
id: TODO;
id: string;
fields: Node[];
metadata: TODO;
metadata?: Record<string, EXPECTED_ANY>;
}
export class ModuleImportDescription {
type: string;
Expand All @@ -189,7 +192,7 @@ declare module "@webassemblyjs/ast" {
name: string;
descr: ModuleExportDescr;
}
type Index = Identifier | NumberLiteral;
type Index = NumberLiteral;
export class ModuleExportDescr extends Node {
type: string;
exportType: string;
Expand Down Expand Up @@ -273,7 +276,10 @@ declare module "@webassemblyjs/ast" {
args: string[];
result: string[];
}
export function moduleContextFromModuleAST(module: Module): TODO;
export function moduleContextFromModuleAST(module: Module): {
getFunction(i: number): FuncSignature;
getStart(): Index;
};

// Node matcher
export function isGlobalType(n: Node): boolean;
Expand Down
4 changes: 3 additions & 1 deletion lib/DllEntryPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const DllEntryDependency = require("./dependencies/DllEntryDependency");
const EntryDependency = require("./dependencies/EntryDependency");

/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */

/** @typedef {string[]} Entries */
/** @typedef {{ name: string, filename: TODO }} Options */
/** @typedef {EntryOptions & { name: string }} Options */

const PLUGIN_NAME = "DllEntryPlugin";

Expand Down
5 changes: 3 additions & 2 deletions lib/DllPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class DllPlugin {
if (typeof entry !== "function") {
for (const name of Object.keys(entry)) {
/** @type {Options} */
const options = { name, filename: entry.filename };
const options = { name };
new DllEntryPlugin(
context,
/** @type {Entries} */ (entry[name].import),
/** @type {Entries} */
(entry[name].import),
options
).apply(compiler);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/ExternalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class ExternalModule extends Module {
this.buildInfo = {
strict: true,
topLevelDeclarations: new Set(),
module: compilation.outputOptions.module
javascriptModule: compilation.outputOptions.module
};
const { request, externalType } = this._getRequestAndExternalType();
this.buildMeta.exportsType = "dynamic";
Expand All @@ -605,7 +605,7 @@ class ExternalModule extends Module {
}
break;
case "module":
if (this.buildInfo.module) {
if (this.buildInfo.javascriptModule) {
if (!Array.isArray(request) || request.length === 1) {
this.buildMeta.exportsType = "namespace";
canMangle = true;
Expand Down Expand Up @@ -760,7 +760,7 @@ class ExternalModule extends Module {
case "commonjs-static":
return getSourceForCommonJsExternal(request);
case "node-commonjs":
return /** @type {BuildInfo} */ (this.buildInfo).module
return /** @type {BuildInfo} */ (this.buildInfo).javascriptModule
? getSourceForCommonJsExternalInNodeModule(
request,
/** @type {string} */
Expand Down Expand Up @@ -792,7 +792,7 @@ class ExternalModule extends Module {
case "script":
return getSourceForScriptExternal(request, runtimeTemplate);
case "module": {
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
if (!(/** @type {BuildInfo} */ (this.buildInfo).javascriptModule)) {
if (!runtimeTemplate.supportsDynamicImport()) {
throw new Error(
`The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
Expand Down
12 changes: 11 additions & 1 deletion lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/** @typedef {import("./ChunkGraph")} ChunkGraph */
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
/** @typedef {import("./Compilation")} Compilation */
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
Expand All @@ -21,6 +22,15 @@
/** @typedef {import("./util/Hash")} Hash */
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */

/**
* @template T
* @typedef {import("./InitFragment")<T>} InitFragment
*/

/** @typedef {Map<"url", { [key: string]: string }> & Map<"fullContentHash", string> & Map<"contentHash", string> & Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"chunkInitFragments", InitFragment<GenerateContext>[]>} KnownGenerateContextData */

/** @typedef {KnownGenerateContextData & Record<string, EXPECTED_ANY>} GenerateContextData */

/**
* @typedef {object} GenerateContext
* @property {DependencyTemplates} dependencyTemplates mapping from dependencies to templates
Expand All @@ -32,7 +42,7 @@
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
* @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
* @property {string} type which kind of code should be generated
* @property {() => Map<string, TODO>=} getData get access to the code generation data
* @property {() => GenerateContextData=} getData get access to the code generation data
*/

/**
Expand Down
1 change: 0 additions & 1 deletion lib/JavascriptMetaInfoPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class JavascriptMetaInfoPlugin {
/** @type {BuildInfo} */
(parser.state.module.buildInfo);
buildInfo.moduleConcatenationBailout = "eval()";
buildInfo.usingEval = true;
const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
if (currentSymbol) {
InnerGraph.addUsage(parser.state, null, currentSymbol);
Expand Down
8 changes: 5 additions & 3 deletions lib/LoaderOptionsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ class LoaderOptionsPlugin {
// If no options are set then generate empty options object
if (typeof options !== "object") options = {};
if (!options.test) {
/** @type {TODO} */
/** @type {Partial<RegExp>} */
const defaultTrueMockRegExp = {
test: () => true
};

/** @type {RegExp} */
options.test = defaultTrueMockRegExp;
options.test =
/** @type {RegExp} */
(defaultTrueMockRegExp);
}
this.options = options;
}
Expand Down Expand Up @@ -75,7 +77,7 @@ class LoaderOptionsPlugin {
continue;
}

/** @type {TODO} */
/** @type {LoaderContext<EXPECTED_ANY> & Record<string, EXPECTED_ANY>} */
(context)[key] = options[key];
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const makeSerializable = require("./util/makeSerializable");
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("./WebpackError")} WebpackError */
/** @typedef {import("./json/JsonData")} JsonData */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("./util/Hash")} Hash */
Expand Down Expand Up @@ -116,6 +117,7 @@ const makeSerializable = require("./util/makeSerializable");
* @property {boolean=} sideEffectFree
* @property {Record<string, string>=} exportsFinalName
* @property {boolean=} isCSSModule
* @property {Record<string, string>=} jsIncompatibleExports
*/

/**
Expand All @@ -134,13 +136,17 @@ const makeSerializable = require("./util/makeSerializable");
* @property {LazySet<string>=} buildDependencies using in NormalModule
* @property {ValueCacheVersions=} valueDependencies using in NormalModule
* @property {Record<string, Source>=} assets using in NormalModule
* @property {Map<string, AssetInfo | undefined>=} assetsInfo using in NormalModule
* @property {string=} hash using in NormalModule
* @property {(Snapshot | null)=} snapshot using in ContextModule
* @property {string=} fullContentHash for assets modules
* @property {string=} filename for assets modules
* @property {Map<string, AssetInfo | undefined>=} assetsInfo for assets modules
* @property {boolean=} dataUrl for assets modules
* @property {AssetInfo=} assetInfo for assets modules
* @property {boolean=} javascriptModule for external modules
* @property {boolean=} active for lazy compilation modules
* @property {CssData=} cssData for css modules
* @property {JsonData=} jsonData for json modules
* @property {Set<string>=} topLevelDeclarations top level declaration names
*/

Expand Down
6 changes: 3 additions & 3 deletions lib/MultiCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ module.exports = class MultiCompiler {
* @deprecated This method should have been private
* @param {Compiler[]} compilers the child compilers
* @param {RunWithDependenciesHandler} fn a handler to run for each compiler
* @param {Callback<MultiStats>} callback the compiler's handler
* @param {Callback<Stats[]>} callback the compiler's handler
* @returns {void}
*/
runWithDependencies(compilers, fn, callback) {
Expand Down Expand Up @@ -355,7 +355,7 @@ module.exports = class MultiCompiler {
return readyCompilers;
};
/**
* @param {Callback<MultiStats>} callback callback
* @param {Callback<Stats[]>} callback callback
* @returns {void}
*/
const runCompilers = callback => {
Expand All @@ -370,7 +370,7 @@ module.exports = class MultiCompiler {
});
},
(err, results) => {
callback(err, /** @type {TODO} */ (results));
callback(err, results);
}
);
};
Expand Down
37 changes: 16 additions & 21 deletions lib/NormalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const memoize = require("./util/memoize");
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
/** @typedef {import("./Generator")} Generator */
/** @typedef {import("./Generator").GenerateErrorFn} GenerateErrorFn */
/** @typedef {import("./Generator").GenerateContextData} GenerateContextData */
/** @typedef {import("./Module").BuildInfo} BuildInfo */
/** @typedef {import("./Module").BuildMeta} BuildMeta */
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
Expand All @@ -79,7 +80,7 @@ const memoize = require("./util/memoize");
/** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
/** @typedef {import("./ModuleGraph")} ModuleGraph */
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
/** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes} JavaScriptModuleTypes */
/** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
/** @typedef {import("./NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
/** @typedef {import("./NormalModuleFactory").ResourceSchemeData} ResourceSchemeData */
Expand Down Expand Up @@ -148,12 +149,14 @@ const contextifySourceUrl = (context, source, associatedObjectForCache) => {

/**
* @param {string} context absolute context path
* @param {RawSourceMap} sourceMap a source map
* @param {string | RawSourceMap} sourceMap a source map
* @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached
* @returns {RawSourceMap} new source map
* @returns {string | RawSourceMap} new source map
*/
const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
if (!Array.isArray(sourceMap.sources)) return sourceMap;
if (typeof sourceMap === "string" || !Array.isArray(sourceMap.sources)) {
return sourceMap;
}
const { sourceRoot } = sourceMap;
/** @type {(source: string) => string} */
const mapper = !sourceRoot
Expand Down Expand Up @@ -218,7 +221,7 @@ makeSerializable(
"NonErrorEmittedError"
);

/** @typedef {[string | Buffer, string | SourceMapSource, PreparsedAst]} Result */
/** @typedef {[string | Buffer, string | RawSourceMap | undefined, PreparsedAst | undefined]} Result */

/**
* @typedef {object} NormalModuleCompilationHooks
Expand All @@ -235,7 +238,7 @@ makeSerializable(
/**
* @typedef {object} NormalModuleCreateData
* @property {string=} layer an optional layer in which the module is
* @property {JavaScriptModuleTypes | ""} type module type. When deserializing, this is set to an empty string "".
* @property {ModuleTypes | ""} type module type. When deserializing, this is set to an empty string "".
* @property {string} request request string
* @property {string} userRequest request intended by user (without loaders from config)
* @property {string} rawRequest request without resolving
Expand All @@ -254,8 +257,6 @@ makeSerializable(
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
const compilationHooksMap = new WeakMap();

/** @typedef {Map<string, EXPECTED_ANY>} CodeGeneratorData */

class NormalModule extends Module {
/**
* @param {Compilation} compilation the compilation
Expand Down Expand Up @@ -396,7 +397,7 @@ class NormalModule extends Module {
this._isEvaluatingSideEffects = false;
/** @type {WeakSet<ModuleGraph> | undefined} */
this._addedSideEffectsBailout = undefined;
/** @type {CodeGeneratorData} */
/** @type {GenerateContextData} */
this._codeGeneratorData = new Map();
}

Expand Down Expand Up @@ -855,7 +856,7 @@ class NormalModule extends Module {
/**
* @param {string} context the compilation context
* @param {string | Buffer} content the content
* @param {(string | SourceMapSource | null)=} sourceMap an optional source map
* @param {(string | RawSourceMap | null)=} sourceMap an optional source map
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
* @returns {Source} the created source
*/
Expand All @@ -876,11 +877,7 @@ class NormalModule extends Module {
return new SourceMapSource(
content,
contextifySourceUrl(context, identifier, associatedObjectForCache),
contextifySourceMap(
context,
/** @type {TODO} */ (sourceMap),
associatedObjectForCache
)
contextifySourceMap(context, sourceMap, associatedObjectForCache)
);
}

Expand Down Expand Up @@ -914,10 +911,10 @@ class NormalModule extends Module {

/**
* @param {Error | null} err err
* @param {(Result | null)=} _result result
* @param {(Result | null)=} result_ result
* @returns {void}
*/
const processResult = (err, _result) => {
const processResult = (err, result_) => {
if (err) {
if (!(err instanceof Error)) {
err = new NonErrorEmittedError(err);
Expand All @@ -933,7 +930,8 @@ class NormalModule extends Module {
return callback(error);
}
const result = hooks.processResult.call(
/** @type {Result} */ (_result),
/** @type {Result} */
(result_),
this
);
const source = result[0];
Expand Down Expand Up @@ -1455,9 +1453,6 @@ class NormalModule extends Module {
runtimeRequirements.add(RuntimeGlobals.thisAsExports);
}

/**
* @type {() => CodeGeneratorData}
*/
const getData = () => this._codeGeneratorData;

const sources = new Map();
Expand Down
2 changes: 1 addition & 1 deletion lib/NormalModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class NormalModuleFactory extends ModuleFactory {
generator: new HookMap(
() => new SyncHook(["generator", "generatorOptions"])
),
/** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module | void>>} */
/** @type {HookMap<SyncBailHook<[CreateData, ResolveData], Module | void>>} */
createModuleClass: new HookMap(
() => new SyncBailHook(["createData", "resolveData"])
)
Expand Down
Loading
Loading