fix filter

This commit is contained in:
Ivan Kopeykin 2021-09-15 18:43:47 +03:00
parent d0ee75b255
commit d6af29698e
1 changed files with 16 additions and 10 deletions

View File

@ -39,6 +39,14 @@ class WarnNonEsmSourceTypePlugin {
}
}
/**
* @param {NormalModule} module module
*/
warn(module) {
// TODO add type reason to NormalModule ?
module.addWarning(new NonEsmSourceTypeWarning(module.type));
}
/**
* @param {Compiler} compiler compiler
*/
@ -52,16 +60,14 @@ class WarnNonEsmSourceTypePlugin {
for (const module of modules) {
const type = module.type;
if (type !== "javascript/esm" && type.startsWith("javascript/")) {
if (
this.filterFunction &&
!this.filterFunction(
/** @type {NormalModule} */ (module).resource
)
)
continue;
// TODO add type reason to NormalModule ?
module.addWarning(new NonEsmSourceTypeWarning(type));
const normalModule = /** @type {NormalModule} */ (module);
if (this.filterFunction) {
if (this.filterFunction(normalModule.resource)) {
this.warn(normalModule);
}
} else {
this.warn(normalModule);
}
}
}
}