Skip to content

Commit e7201a8

Browse files
committed
refactor(@ngtools/webpack): add return types to functions
Functions that are exported from files within the `@ngtools/webpack` package now contain return types. This improves code readability as well as being a requirement for eventual isolated declarations usage. (cherry picked from commit 9cccb88)
1 parent f55d777 commit e7201a8

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

packages/ngtools/webpack/src/benchmark.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
// This should be false for commited code.
1212
const _benchmark = false;
1313
/* eslint-disable no-console */
14-
export function time(label: string) {
14+
export function time(label: string): void {
1515
if (_benchmark) {
1616
console.time(label);
1717
}
1818
}
1919

20-
export function timeEnd(label: string) {
20+
export function timeEnd(label: string): void {
2121
if (_benchmark) {
2222
console.timeEnd(label);
2323
}

packages/ngtools/webpack/src/ivy/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function augmentHostWithResources(
2121
directTemplateLoading?: boolean;
2222
inlineStyleFileExtension?: string;
2323
} = {},
24-
) {
24+
): void {
2525
const resourceHost = host as CompilerHost;
2626

2727
resourceHost.readResource = function (fileName: string) {

packages/ngtools/webpack/src/ivy/loader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { AngularPluginSymbol, FileEmitterCollection } from './symbol';
1212

1313
const JS_FILE_REGEXP = /\.[cm]?js$/;
1414

15-
export function angularWebpackLoader(this: LoaderContext<unknown>, content: string, map: string) {
15+
export function angularWebpackLoader(
16+
this: LoaderContext<unknown>,
17+
content: string,
18+
map: string,
19+
): void {
1620
const callback = this.async();
1721
if (!callback) {
1822
throw new Error('Invalid webpack version');

packages/ngtools/webpack/src/loaders/inline-resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface CompilationWithInlineAngularResource extends Compilation {
1616
[InlineAngularResourceSymbol]: string;
1717
}
1818

19-
export default function (this: LoaderContext<{ data?: string }>) {
19+
export default function (this: LoaderContext<{ data?: string }>): void {
2020
const callback = this.async();
2121
const { data } = this.getOptions();
2222

packages/ngtools/webpack/src/resource_loader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class WebpackResourceLoader {
4646
}
4747
}
4848

49-
update(parentCompilation: Compilation, changedFiles?: Iterable<string>) {
49+
update(parentCompilation: Compilation, changedFiles?: Iterable<string>): void {
5050
this._parentCompilation = parentCompilation;
5151

5252
// Update resource cache and modified resources
@@ -82,23 +82,23 @@ export class WebpackResourceLoader {
8282
}
8383
}
8484

85-
clearParentCompilation() {
85+
clearParentCompilation(): void {
8686
this._parentCompilation = undefined;
8787
}
8888

89-
getModifiedResourceFiles() {
89+
getModifiedResourceFiles(): Set<string> {
9090
return this.modifiedResources;
9191
}
9292

93-
getResourceDependencies(filePath: string) {
93+
getResourceDependencies(filePath: string): Iterable<string> {
9494
return this._fileDependencies.get(filePath) || [];
9595
}
9696

97-
getAffectedResources(file: string) {
97+
getAffectedResources(file: string): Iterable<string> {
9898
return this._reverseDependencies.get(file) || [];
9999
}
100100

101-
setAffectedResources(file: string, resources: Iterable<string>) {
101+
setAffectedResources(file: string, resources: Iterable<string>): void {
102102
this._reverseDependencies.set(file, new Set(resources));
103103
}
104104

packages/ngtools/webpack/src/transformers/spec_helpers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { basename } from 'path';
10-
import * as ts from 'typescript';
9+
import { basename } from 'node:path';
10+
import ts from 'typescript';
1111

1212
// Test transform helpers.
1313
const basefileName = 'test-file.ts';
@@ -18,7 +18,10 @@ export function createTypescriptContext(
1818
useLibs = false,
1919
extraCompilerOptions: ts.CompilerOptions = {},
2020
jsxFile = false,
21-
) {
21+
): {
22+
compilerHost: ts.CompilerHost;
23+
program: ts.Program;
24+
} {
2225
const fileName = basefileName + (jsxFile ? 'x' : '');
2326
// Set compiler options.
2427
const compilerOptions: ts.CompilerOptions = {

0 commit comments

Comments
 (0)