Skip to content

Commit e9453a5

Browse files
fix(types): count hot/ in the report, type its inferred any and mark minify as installed later
1 parent 449181f commit e9453a5

10 files changed

Lines changed: 36 additions & 15 deletions

File tree

‎.changeset/220-typed-memo-cache.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": patch
33
---
44

5-
Type memo cache entries by key and fix the published `WeakTupleMap` and `ExportsInfo` signatures.
5+
Type memo cache entries by key and fix published type signatures.

‎hot/dev-server.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if (module.hot) {
4444
log("info", "[HMR] App is up to date.");
4545
}
4646
})
47-
.catch(function (err) {
47+
.catch(function (/** @type {Error} */ err) {
4848
var status = module.hot.status();
4949
if (["abort", "fail"].indexOf(status) >= 0) {
5050
log(

‎hot/lazy-compilation-web.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ if (typeof EventSource !== "function") {
1111
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
1212
/** @type {EventSource | undefined} */
1313
var activeEventSource;
14+
/** @type {Map<string, number>} */
1415
var activeKeys = new Map();
16+
/** @type {Set<(err: Error) => void>} */
1517
var errorHandlers = new Set();
1618

1719
var updateEventSource = function updateEventSource() {
@@ -74,7 +76,7 @@ exports.keepAlive = function (options) {
7476
return function () {
7577
errorHandlers.delete(onError);
7678
setTimeout(function () {
77-
var value = activeKeys.get(data);
79+
var value = /** @type {number} */ (activeKeys.get(data));
7880
if (value === 1) {
7981
activeKeys.delete(data);
8082
updateEventSource();

‎hot/only-dev-server.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (module.hot) {
6666
}
6767
});
6868
})
69-
.catch(function (err) {
69+
.catch(function (/** @type {Error} */ err) {
7070
var status = module.hot.status();
7171
if (["abort", "fail"].indexOf(status) >= 0) {
7272
log(

‎hot/poll.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (module.hot) {
2323
require("./log-apply-result")(updatedModules, updatedModules);
2424
checkForUpdate(true);
2525
})
26-
.catch(function (err) {
26+
.catch(function (/** @type {Error} */ err) {
2727
var status = module.hot.status();
2828
if (["abort", "fail"].indexOf(status) >= 0) {
2929
log("warning", "[HMR] Cannot apply update.");

‎hot/signal.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (module.hot) {
3737
return null;
3838
});
3939
})
40-
.catch(function (err) {
40+
.catch(function (/** @type {Error} */ err) {
4141
var status = module.hot.status();
4242
if (["abort", "fail"].indexOf(status) >= 0) {
4343
log("warning", "[HMR] Cannot apply update.");

‎lib/javascript/syntax-printer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const {
6262

6363
// cspell:ignore Mihai, Bazon, DEFNODE, endpos, endcol, sequencesize, lvalues, binop, loopcontrol, symbolref, funs, jridgewell, DEFMETHOD, Defun, defun, defuns, fnames, funarg, classnames, mangleable, unmangleable, NOINLINE, privatename, argnames, thedef, argname, bcatch, bfinally, MANGLEPROP, nlb, punc, Funarg, propmangle, preferrably, nondeferred, fargs, domprops, noin, Noin, DEFPRINT, defprint, dgimsuyv, nokeyword, etnriaoslucdfmhpgvybkwjxqz, ETNRIAOSLUCDFMHPGVYBKWJXQZ
6464

65-
/** @typedef {{ ast: Ast, minify: Minify, corrections?: Minifier["corrections"], improvements?: Minifier["improvements"], [key: string]: EXPECTED_ANY }} MinifierModules terser's own modules, naming those read once the phases install them */
65+
/** @typedef {{ ast: Ast, minify?: Minify, corrections?: Minifier["corrections"], improvements?: Minifier["improvements"], [key: string]: EXPECTED_ANY }} MinifierModules terser's own modules, naming those read once the phases install them */
6666
/**
6767
* terser's modules as the phases read them: what `createModules` builds, and
6868
* what each phase installs, read only by the phases after it.
@@ -70166,7 +70166,7 @@ const loadNow = () => {
7016670166
const modules = createModules();
7016770167
for (const phase of PHASES) phase.install(modules);
7016870168
loaded = {
70169-
minify: modules.minify,
70169+
minify: /** @type {Minify} */ (modules.minify),
7017070170
phases: PHASES.map((phase) => phase.name),
7017170171
corrections: modules.corrections,
7017270172
improvements: modules.improvements,

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12752,7 +12752,12 @@ x = a ** b ** c; x = (a ** b) ** c; x = (-a) ** b; x = a < b < c; x = a < (b < c
1275212752
const ours = /** @type {EXPECTED_ANY} */ (
1275312753
await writingAsTerser(() => minify(source, withTree()))
1275412754
);
12755-
const theirs = await terserResult(() => terser.minify(source, withTree()));
12755+
const theirs = await terserResult(() =>
12756+
/** @type {NonNullable<typeof terser.minify>} */ (terser.minify)(
12757+
source,
12758+
withTree()
12759+
)
12760+
);
1275612761
/**
1275712762
* @param {EXPECTED_ANY} tree a toplevel
1275812763
* @param {(tree: EXPECTED_ANY, visit: (node: EXPECTED_ANY) => void) => void} walk the walk of its tree's classes
@@ -20410,7 +20415,10 @@ describe("JavaScript minifier, what the tables leave out", () => {
2041020415
const write = async () => {
2041120416
const modules = createModules();
2041220417
for (const phase of PHASES) phase.install(modules);
20413-
return /** @type {string} */ ((await modules.minify(source, options())).code);
20418+
const minify = /** @type {NonNullable<typeof modules.minify>} */ (
20419+
modules.minify
20420+
);
20421+
return /** @type {string} */ ((await minify(source, options())).code);
2041420422
};
2041520423
const expected = await write();
2041620424
const saved = /** @type {PropertyDescriptor} */ (

‎tooling/type-coverage.js‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ const ts = require("typescript");
1414
const { base, baseAny, root } = require("./argv");
1515
const createTypeScriptProgram = require("./typescript-program");
1616

17-
const program = createTypeScriptProgram("tsconfig.json");
18-
const typeChecker = program.getTypeChecker();
17+
// `hot/` is a project of its own, so its files reach only that program.
18+
/** @type {[ts.SourceFile, ts.TypeChecker][]} */
19+
const sourceFiles = [];
20+
for (const configName of ["tsconfig.json", "tsconfig.hot.json"]) {
21+
const program = createTypeScriptProgram(configName);
22+
const checker = program.getTypeChecker();
23+
for (const sourceFile of program.getSourceFiles()) {
24+
sourceFiles.push([sourceFile, checker]);
25+
}
26+
}
1927

2028
/**
2129
* @typedef {object} Location
@@ -49,9 +57,12 @@ const ESCAPE_HATCH_DIRECTORIES = ["lib/", "hot/"];
4957
/** @type {Record<string, InferredAny[]>} */
5058
const inferredAnyByFile = {};
5159

52-
for (const sourceFile of program.getSourceFiles()) {
60+
/** @type {Set<string>} */
61+
const walkedFiles = new Set();
62+
for (const [sourceFile, typeChecker] of sourceFiles) {
5363
const file = sourceFile.fileName;
54-
if (!sourceFile.isDeclarationFile) {
64+
if (!sourceFile.isDeclarationFile && !walkedFiles.has(file)) {
65+
walkedFiles.add(file);
5566
/** @type {FileReport} */
5667
const rep = {
5768
path: path.sep !== "/" ? file.replace(/\//g, path.sep) : file,

‎types.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20226,7 +20226,7 @@ declare abstract class MinifierLabel {
2022620226
declare interface MinifierModules {
2022720227
[index: string]: any;
2022820228
ast: Ast;
20229-
minify: (
20229+
minify?: (
2023020230
sources: MinifySources,
2023120231
options?: MinifyOptions
2023220232
) => Promise<MinifyOutput>;

0 commit comments

Comments
 (0)