Skip to content

Commit e8dc361

Browse files
authored
Merge pull request webpack#7299 from webpack/feature/type-compiler-compilation-save
chore(types): Add JSDoc To Compiler, Compilation, and Connected Classes Types
2 parents ccf56e4 + 0bd9df8 commit e8dc361

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1286
-386
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ module.exports = {
3232
"valid-jsdoc": ["error", {
3333
"prefer": {
3434
"return": "returns",
35+
"prop": "property",
3536
"memberof": "DONTUSE",
3637
"class": "DONTUSE",
38+
"extends": "DONTUSE",
3739
"inheritdoc": "DONTUSE",
3840
"description": "DONTUSE",
3941
"readonly": "DONTUSE"

.github/ISSUE_TEMPLATE/Bug_report.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
---
2-
name: Bug report
3-
about: Create a report to help us improve
4-
---
5-
6-
<!-- Please don't delete this template because we'll close your issue -->
7-
<!-- Before creating an issue please make sure you are using the latest version of webpack. -->
8-
9-
# Bug report
10-
11-
<!-- Please ask questions on StackOverflow or the webpack Gitter. -->
12-
<!-- https://stackoverflow.com/questions/ask?tags=webpack -->
13-
<!-- https://gitter.im/webpack/webpack -->
14-
<!-- Issues which contain questions or support requests will be closed. -->
15-
16-
**What is the current behavior?**
17-
18-
19-
**If the current behavior is a bug, please provide the steps to reproduce.**
20-
21-
22-
<!-- A great way to do this is to provide your configuration via a GitHub repository -->
23-
<!-- The most helpful is a minimal reproduction with instructions on how to reproduce -->
24-
<!-- Repositories with too many files or large `webpack.config.js` files are not suitable -->
25-
<!-- Please only add small code snippets directly into this issue -->
26-
<!-- https://gist.github.com is a good place for longer code snippets -->
27-
<!-- If your issue is caused by a plugin or loader, please create an issue on the loader/plugin repository instead -->
28-
29-
**What is the expected behavior?**
30-
31-
32-
<!-- "It should work" is not a helpful explanation -->
33-
<!-- Explain exactly how it should behave -->
34-
35-
**Other relevant information:**
36-
webpack version:
37-
Node.js version:
38-
Operating System:
39-
Additional tools:
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
---
5+
6+
<!-- Please don't delete this template because we'll close your issue -->
7+
<!-- Before creating an issue please make sure you are using the latest version of webpack. -->
8+
9+
# Bug report
10+
11+
<!-- Please ask questions on StackOverflow or the webpack Gitter. -->
12+
<!-- https://stackoverflow.com/questions/ask?tags=webpack -->
13+
<!-- https://gitter.im/webpack/webpack -->
14+
<!-- Issues which contain questions or support requests will be closed. -->
15+
16+
**What is the current behavior?**
17+
18+
19+
**If the current behavior is a bug, please provide the steps to reproduce.**
20+
21+
22+
<!-- A great way to do this is to provide your configuration via a GitHub repository -->
23+
<!-- The most helpful is a minimal reproduction with instructions on how to reproduce -->
24+
<!-- Repositories with too many files or large `webpack.config.js` files are not suitable -->
25+
<!-- Please only add small code snippets directly into this issue -->
26+
<!-- https://gist.github.com is a good place for longer code snippets -->
27+
<!-- If your issue is caused by a plugin or loader, please create an issue on the loader/plugin repository instead -->
28+
29+
**What is the expected behavior?**
30+
31+
32+
<!-- "It should work" is not a helpful explanation -->
33+
<!-- Explain exactly how it should behave -->
34+
35+
**Other relevant information:**
36+
webpack version:
37+
Node.js version:
38+
Operating System:
39+
Additional tools:
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
---
2-
name: Feature request
3-
about: Suggest an idea for this project
4-
5-
---
6-
7-
<!-- Please don't delete this template or we'll close your issue -->
8-
9-
## Feature request
10-
11-
<!-- Issues which contain questions or support requests will be closed. -->
12-
<!-- Before creating an issue please make sure you are using the latest version of webpack. -->
13-
<!-- Check if this feature need to be implemented in a plugin or loader instead -->
14-
<!-- If yes: file the issue on the plugin/loader repo -->
15-
<!-- Features related to the development server should be filed on this repo instead -->
16-
17-
**What is the expected behavior?**
18-
19-
20-
**What is motivation or use case for adding/changing the behavior?**
21-
22-
23-
**How should this be implemented in your opinion?**
24-
25-
26-
**Are you willing to work on this yourself?**
27-
yes
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
<!-- Please don't delete this template or we'll close your issue -->
8+
9+
## Feature request
10+
11+
<!-- Issues which contain questions or support requests will be closed. -->
12+
<!-- Before creating an issue please make sure you are using the latest version of webpack. -->
13+
<!-- Check if this feature need to be implemented in a plugin or loader instead -->
14+
<!-- If yes: file the issue on the plugin/loader repo -->
15+
<!-- Features related to the development server should be filed on this repo instead -->
16+
17+
**What is the expected behavior?**
18+
19+
20+
**What is motivation or use case for adding/changing the behavior?**
21+
22+
23+
**How should this be implemented in your opinion?**
24+
25+
26+
**Are you willing to work on this yourself?**
27+
yes

.github/ISSUE_TEMPLATE/Other.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
---
2-
name: Other
3-
about: Something else
4-
5-
---
6-
7-
<!-- Bug reports and Feature requests must use other templates, or will be closed -->
8-
<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->
9-
<!-- Issues which contain questions or support requests will be closed. -->
1+
---
2+
name: Other
3+
about: Something else
4+
5+
---
6+
7+
<!-- Bug reports and Feature requests must use other templates, or will be closed -->
8+
<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->
9+
<!-- Issues which contain questions or support requests will be closed. -->

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
!examples/**/webpack.config.js
1414
!schemas/**/*.js
1515
!declarations.d.ts
16+
!tsconfig.json

declarations.d.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,100 @@ declare namespace NodeJS {
77
}
88
}
99

10+
11+
declare module "neo-async" {
12+
export interface Dictionary<T> {
13+
[key: string]: T;
14+
}
15+
export type IterableCollection<T> = T[] | IterableIterator<T> | Dictionary<T>;
16+
17+
export interface ErrorCallback<T> {
18+
(err?: T): void;
19+
}
20+
export interface AsyncBooleanResultCallback<E> {
21+
(err?: E, truthValue?: boolean): void;
22+
}
23+
export interface AsyncResultCallback<T, E> {
24+
(err?: E, result?: T): void;
25+
}
26+
export interface AsyncResultArrayCallback<T, E> {
27+
(err?: E, results?: Array<T | undefined>): void;
28+
}
29+
export interface AsyncResultObjectCallback<T, E> {
30+
(err: E | undefined, results: Dictionary<T | undefined>): void;
31+
}
32+
33+
export interface AsyncFunction<T, E> {
34+
(callback: (err?: E, result?: T) => void): void;
35+
}
36+
export interface AsyncFunctionEx<T, E> {
37+
(callback: (err?: E, ...results: T[]) => void): void;
38+
}
39+
export interface AsyncIterator<T, E> {
40+
(item: T, callback: ErrorCallback<E>): void;
41+
}
42+
export interface AsyncForEachOfIterator<T, E> {
43+
(item: T, key: number | string, callback: ErrorCallback<E>): void;
44+
}
45+
export interface AsyncResultIterator<T, R, E> {
46+
(item: T, callback: AsyncResultCallback<R, E>): void;
47+
}
48+
export interface AsyncMemoIterator<T, R, E> {
49+
(memo: R | undefined, item: T, callback: AsyncResultCallback<R, E>): void;
50+
}
51+
export interface AsyncBooleanIterator<T, E> {
52+
(item: T, callback: AsyncBooleanResultCallback<E>): void;
53+
}
54+
55+
export interface AsyncWorker<T, E> {
56+
(task: T, callback: ErrorCallback<E>): void;
57+
}
58+
export interface AsyncVoidFunction<E> {
59+
(callback: ErrorCallback<E>): void;
60+
}
61+
62+
export type AsyncAutoTasks<R extends Dictionary<any>, E> = {
63+
[K in keyof R]: AsyncAutoTask<R[K], R, E>
64+
};
65+
export type AsyncAutoTask<R1, R extends Dictionary<any>, E> =
66+
| AsyncAutoTaskFunctionWithoutDependencies<R1, E>
67+
| (keyof R | AsyncAutoTaskFunction<R1, R, E>)[];
68+
export interface AsyncAutoTaskFunctionWithoutDependencies<R1, E> {
69+
(cb: AsyncResultCallback<R1, E> | ErrorCallback<E>): void;
70+
}
71+
export interface AsyncAutoTaskFunction<R1, R extends Dictionary<any>, E> {
72+
(results: R, cb: AsyncResultCallback<R1, E> | ErrorCallback<E>): void;
73+
}
74+
75+
export function each<T, E>(
76+
arr: IterableCollection<T>,
77+
iterator: AsyncIterator<T, E>,
78+
callback?: ErrorCallback<E>
79+
): void;
80+
81+
export function map<T, R, E>(
82+
arr: T[] | IterableIterator<T>,
83+
iterator: AsyncResultIterator<T, R, E>,
84+
callback?: AsyncResultArrayCallback<R, E>
85+
): void;
86+
export function map<T, R, E>(
87+
arr: Dictionary<T>,
88+
iterator: AsyncResultIterator<T, R, E>,
89+
callback?: AsyncResultArrayCallback<R, E>
90+
): void;
91+
92+
export function parallel<T, E>(
93+
tasks: Array<AsyncFunction<T, E>>,
94+
callback?: AsyncResultArrayCallback<T, E>
95+
): void;
96+
export function parallel<T, E>(
97+
tasks: Dictionary<AsyncFunction<T, E>>,
98+
callback?: AsyncResultObjectCallback<T, E>
99+
): void;
100+
101+
export const forEach: typeof each;
102+
}
103+
10104
// There are no typings for @webassemblyjs/ast
11105
declare module "@webassemblyjs/ast" {
12106
export function traverse(

lib/AsyncDependenciesBlock.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
Author Tobias Koppers @sokra
44
*/
55
"use strict";
6+
67
const DependenciesBlock = require("./DependenciesBlock");
78

9+
/** @typedef {import("./ChunkGroup")} ChunkGroup */
10+
/** @typedef {import("./Module")} Module */
11+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
12+
/** @typedef {import("./util/createHash").Hash} Hash */
13+
/** @typedef {TODO} GroupOptions */
14+
815
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
16+
/**
17+
* @param {GroupOptions} groupOptions options for the group
18+
* @param {Module} module the Module object
19+
* @param {DependencyLocation=} loc the line of code
20+
* @param {TODO=} request the request
21+
*/
922
constructor(groupOptions, module, loc, request) {
1023
super();
1124
if (typeof groupOptions === "string") {
@@ -14,28 +27,50 @@ module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
1427
groupOptions = { name: undefined };
1528
}
1629
this.groupOptions = groupOptions;
30+
/** @type {ChunkGroup=} */
1731
this.chunkGroup = undefined;
1832
this.module = module;
1933
this.loc = loc;
2034
this.request = request;
35+
/** @type {DependenciesBlock} */
36+
this.parent = undefined;
2137
}
2238

39+
/**
40+
* @returns {string} The name of the chunk
41+
*/
2342
get chunkName() {
2443
return this.groupOptions.name;
2544
}
2645

46+
/**
47+
* @param {string} value The new chunk name
48+
* @returns {void}
49+
*/
2750
set chunkName(value) {
2851
this.groupOptions.name = value;
2952
}
3053

54+
/**
55+
* @returns {never} this throws and should never be called
56+
*/
3157
get chunks() {
3258
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
3359
}
3460

61+
/**
62+
* @param {never} value setter value
63+
* @returns {never} this is going to throw therefore we should throw type
64+
* assertions by returning never
65+
*/
3566
set chunks(value) {
3667
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
3768
}
3869

70+
/**
71+
* @param {Hash} hash the hash used to track block changes, from "crypto" module
72+
* @returns {void}
73+
*/
3974
updateHash(hash) {
4075
hash.update(JSON.stringify(this.groupOptions));
4176
hash.update(
@@ -50,16 +85,25 @@ module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
5085
super.updateHash(hash);
5186
}
5287

88+
/**
89+
* @returns {void}
90+
*/
5391
disconnect() {
5492
this.chunkGroup = undefined;
5593
super.disconnect();
5694
}
5795

96+
/**
97+
* @returns {void}
98+
*/
5899
unseal() {
59100
this.chunkGroup = undefined;
60101
super.unseal();
61102
}
62103

104+
/**
105+
* @returns {void}
106+
*/
63107
sortItems() {
64108
super.sortItems();
65109
}

lib/AutomaticPrefetchPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AutomaticPrefetchPlugin {
3030
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
3131
lastModules = compilation.modules
3232
.filter(m => m instanceof NormalModule)
33-
.map(m => ({
33+
.map((/** @type {NormalModule} */ m) => ({
3434
context: m.context,
3535
request: m.request
3636
}));

0 commit comments

Comments
 (0)