mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 22:34:21 +08:00
refactor(@ngtools/webpack): assert catch clause variable type before usage
Prepares the `@ngtools/webpack` package for the eventual change of enabling the TypeScript `useUnknownInCatchVariables` option. This option provides additional code safety by ensuring that the catch clause variable is the proper type before attempting to access its properties. Similar changes will be needed in the other packages in the repository prior to enabling `useUnknownInCatchVariables`.
This commit is contained in:
parent
9b1a36a9d6
commit
263626280f
@ -6,6 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import * as vm from 'vm';
|
||||
import type { Asset, Compilation } from 'webpack';
|
||||
@ -115,6 +116,7 @@ export class WebpackResourceLoader {
|
||||
const {
|
||||
EntryPlugin,
|
||||
NormalModule,
|
||||
WebpackError,
|
||||
library,
|
||||
node,
|
||||
sources,
|
||||
@ -208,8 +210,9 @@ export class WebpackResourceLoader {
|
||||
compilation.assets[outputFilePath] = new sources.RawSource(output);
|
||||
}
|
||||
} catch (error) {
|
||||
assert(error instanceof Error, 'catch clause variable is not an Error instance');
|
||||
// Use compilation errors, as otherwise webpack will choke
|
||||
compilation.errors.push(error);
|
||||
compilation.errors.push(new WebpackError(error.message));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user