Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Feb 8, 2022
1 parent afdb254 commit b531eb6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 76 deletions.
3 changes: 1 addition & 2 deletions lib/ChunkGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);

/** @typedef {(c: Chunk, chunkGraph: ChunkGraph) => boolean} ChunkFilterPredicate */
/** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
/** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */

/**
* @typedef {Object} ChunkSizeOptions
Expand Down Expand Up @@ -1180,8 +1181,6 @@ class ChunkGraph {
return cgc.dependentHashModules;
}

/** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */

/**
* @param {Chunk} chunk the chunk
* @returns {Iterable<EntryModuleWithChunkGroup>} iterable of modules (do not modify)
Expand Down
133 changes: 63 additions & 70 deletions lib/css/CssLoadingRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,78 +274,71 @@ class CssLoadingRuntimeModule extends RuntimeModule {
"",
withLoading
? Template.asString([
`${fn}.css = ${runtimeTemplate.basicFunction(
"chunkId, promises",
hasCssMatcher !== false
? [
"// css chunk loading",
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
'if(installedChunkData !== 0) { // 0 means "already installed".',
Template.indent([
"",
'// a Promise means "currently loading".',
"if(installedChunkData) {",
Template.indent([
"promises.push(installedChunkData[2]);"
]),
"} else {",
Template.indent([
hasCssMatcher === true
? "if(true) { // all chunks have CSS"
: `if(${hasCssMatcher("chunkId")}) {`,
`${fn}.css = ${runtimeTemplate.basicFunction("chunkId, promises", [
"// css chunk loading",
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
'if(installedChunkData !== 0) { // 0 means "already installed".',
Template.indent([
"",
'// a Promise means "currently loading".',
"if(installedChunkData) {",
Template.indent(["promises.push(installedChunkData[2]);"]),
"} else {",
Template.indent([
hasCssMatcher === true
? "if(true) { // all chunks have CSS"
: `if(${hasCssMatcher("chunkId")}) {`,
Template.indent([
"// setup Promise in chunk cache",
`var promise = new Promise(${runtimeTemplate.expressionFunction(
`installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
"resolve, reject"
)});`,
"promises.push(installedChunkData[2] = promise);",
"",
"// start chunk loading",
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
"// create error before stack unwound to get useful stacktrace later",
"var error = new Error();",
`var loadingEnded = ${runtimeTemplate.basicFunction(
"event",
[
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
Template.indent([
"// setup Promise in chunk cache",
`var promise = new Promise(${runtimeTemplate.expressionFunction(
`installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
"resolve, reject"
)});`,
"promises.push(installedChunkData[2] = promise);",
"",
"// start chunk loading",
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
"// create error before stack unwound to get useful stacktrace later",
"var error = new Error();",
`var loadingEnded = ${runtimeTemplate.basicFunction(
"event",
[
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
Template.indent([
"installedChunkData = installedChunks[chunkId];",
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
"if(installedChunkData) {",
Template.indent([
'if(event.type !== "load") {',
Template.indent([
"var errorType = event && event.type;",
"var realSrc = event && event.target && event.target.src;",
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
"error.name = 'ChunkLoadError';",
"error.type = errorType;",
"error.request = realSrc;",
"installedChunkData[1](error);"
]),
"} else {",
Template.indent([
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
"installedChunkData[0]();"
]),
"}"
]),
"}"
]),
"}"
]
)};`,
"var link = loadStylesheet(chunkId, url, loadingEnded);"
"installedChunkData = installedChunks[chunkId];",
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
"if(installedChunkData) {",
Template.indent([
'if(event.type !== "load") {',
Template.indent([
"var errorType = event && event.type;",
"var realSrc = event && event.target && event.target.src;",
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
"error.name = 'ChunkLoadError';",
"error.type = errorType;",
"error.request = realSrc;",
"installedChunkData[1](error);"
]),
"} else {",
Template.indent([
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
"installedChunkData[0]();"
]),
"}"
]),
"}"
]),
"} else installedChunks[chunkId] = 0;"
]),
"}"
]),
"}"
]
: "installedChunks[chunkId] = 0;"
)};`
"}"
]
)};`,
"var link = loadStylesheet(chunkId, url, loadingEnded);"
]),
"} else installedChunks[chunkId] = 0;"
]),
"}"
]),
"}"
])};`
])
: "// no chunk loading",
"",
Expand Down
5 changes: 3 additions & 2 deletions lib/javascript/StartupHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { getAllChunks } = require("./ChunkHelpers");
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
/** @typedef {import("../ChunkGroup")} ChunkGroup */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
/** @typedef {(string|number)[]} EntryItem */
Expand All @@ -23,7 +24,7 @@ const EXPORT_PREFIX = "var __webpack_exports__ = ";
/**
* @param {ChunkGraph} chunkGraph chunkGraph
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
* @param {import("../ChunkGraph").EntryModuleWithChunkGroup[]} entries entries
* @param {EntryModuleWithChunkGroup[]} entries entries
* @param {Chunk} chunk chunk
* @param {boolean} passive true: passive startup with on chunks loaded
* @returns {string} runtime code
Expand Down Expand Up @@ -101,7 +102,7 @@ exports.generateEntryStartup = (
/**
* @param {Hash} hash the hash to update
* @param {ChunkGraph} chunkGraph chunkGraph
* @param {import("../ChunkGraph").EntryModuleWithChunkGroup[]} entries entries
* @param {EntryModuleWithChunkGroup[]} entries entries
* @param {Chunk} chunk chunk
* @returns {void}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/util/compileBooleanMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const toSimpleString = str => {

/**
* @param {Record<string|number, boolean>} map value map
* @returns {true|false|function(string): string} true/false, when unconditionally true/false, or a template function to determine the value at runtime
* @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime
*/
const compileBooleanMatcher = map => {
const positiveItems = Object.keys(map).filter(i => map[i]);
Expand Down
2 changes: 1 addition & 1 deletion lib/util/deterministicGrouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {

// return the results
return result.map(group => {
/** @type {GroupedItems} */
/** @type {GroupedItems<T>} */
return {
key: group.key,
items: group.nodes.map(node => node.item),
Expand Down

0 comments on commit b531eb6

Please sign in to comment.