Skip to content

Commit

Permalink
refactor(@ngtools/webpack): add return types to functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clydin committed Jan 14, 2025
1 parent 61e8185 commit 9cccb88
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/ngtools/webpack/src/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// This should be false for commited code.
const _benchmark = false;
/* eslint-disable no-console */
export function time(label: string) {
export function time(label: string): void {
if (_benchmark) {
console.time(label);
}
}

export function timeEnd(label: string) {
export function timeEnd(label: string): void {
if (_benchmark) {
console.timeEnd(label);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/src/ivy/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function augmentHostWithResources(
directTemplateLoading?: boolean;
inlineStyleFileExtension?: string;
} = {},
) {
): void {
const resourceHost = host as CompilerHost;

resourceHost.readResource = function (fileName: string) {
Expand Down
6 changes: 5 additions & 1 deletion packages/ngtools/webpack/src/ivy/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { AngularPluginSymbol, FileEmitterCollection } from './symbol';

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

export function angularWebpackLoader(this: LoaderContext<unknown>, content: string, map: string) {
export function angularWebpackLoader(
this: LoaderContext<unknown>,
content: string,
map: string,
): void {
const callback = this.async();
if (!callback) {
throw new Error('Invalid webpack version');
Expand Down
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/src/loaders/inline-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface CompilationWithInlineAngularResource extends Compilation {
[InlineAngularResourceSymbol]: string;
}

export default function (this: LoaderContext<{ data?: string }>) {
export default function (this: LoaderContext<{ data?: string }>): void {
const callback = this.async();
const { data } = this.getOptions();

Expand Down
12 changes: 6 additions & 6 deletions packages/ngtools/webpack/src/resource_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class WebpackResourceLoader {
}
}

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

// Update resource cache and modified resources
Expand Down Expand Up @@ -82,23 +82,23 @@ export class WebpackResourceLoader {
}
}

clearParentCompilation() {
clearParentCompilation(): void {
this._parentCompilation = undefined;
}

getModifiedResourceFiles() {
getModifiedResourceFiles(): Set<string> {
return this.modifiedResources;
}

getResourceDependencies(filePath: string) {
getResourceDependencies(filePath: string): Iterable<string> {
return this._fileDependencies.get(filePath) || [];
}

getAffectedResources(file: string) {
getAffectedResources(file: string): Iterable<string> {
return this._reverseDependencies.get(file) || [];
}

setAffectedResources(file: string, resources: Iterable<string>) {
setAffectedResources(file: string, resources: Iterable<string>): void {
this._reverseDependencies.set(file, new Set(resources));
}

Expand Down
9 changes: 6 additions & 3 deletions packages/ngtools/webpack/src/transformers/spec_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { basename } from 'path';
import * as ts from 'typescript';
import { basename } from 'node:path';
import ts from 'typescript';

// Test transform helpers.
const basefileName = 'test-file.ts';
Expand All @@ -18,7 +18,10 @@ export function createTypescriptContext(
useLibs = false,
extraCompilerOptions: ts.CompilerOptions = {},
jsxFile = false,
) {
): {
compilerHost: ts.CompilerHost;
program: ts.Program;
} {
const fileName = basefileName + (jsxFile ? 'x' : '');
// Set compiler options.
const compilerOptions: ts.CompilerOptions = {
Expand Down

0 comments on commit 9cccb88

Please sign in to comment.