Add type guard for NormalModule
This commit is contained in:
parent
caefde17ab
commit
23bd3d7bd4
|
@ -7,6 +7,7 @@
|
|||
|
||||
const { RawSource } = require("webpack-sources");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const NormalModule = require("./NormalModule");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
|
@ -38,12 +39,18 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
|
|||
);
|
||||
moduleTemplate.hooks.module.tap(
|
||||
"EvalSourceMapDevToolModuleTemplatePlugin",
|
||||
(source, module) => {
|
||||
(source, m) => {
|
||||
const cachedSource = cache.get(source);
|
||||
if (cachedSource !== undefined) {
|
||||
return cachedSource;
|
||||
}
|
||||
|
||||
if (!(m instanceof NormalModule)) {
|
||||
return source;
|
||||
}
|
||||
|
||||
const module = /** @type {NormalModule} */ (m);
|
||||
|
||||
if (!matchModule(module.resource)) {
|
||||
return source;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"use strict";
|
||||
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const NormalModule = require("./NormalModule");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
|
||||
|
@ -38,7 +39,11 @@ class LoaderOptionsPlugin {
|
|||
compiler.hooks.compilation.tap("LoaderOptionsPlugin", compilation => {
|
||||
compilation.hooks.normalModuleLoader.tap(
|
||||
"LoaderOptionsPlugin",
|
||||
(context, module) => {
|
||||
(context, m) => {
|
||||
if (!(m instanceof NormalModule)) {
|
||||
return;
|
||||
}
|
||||
const module = /** @type {NormalModule} */ m;
|
||||
const resource = module.resource;
|
||||
if (!resource) return;
|
||||
const i = resource.indexOf("?");
|
||||
|
|
|
@ -100,13 +100,6 @@ class Module extends DependenciesBlock {
|
|||
this.buildMeta = undefined;
|
||||
/** @type {object} */
|
||||
this.buildInfo = undefined;
|
||||
|
||||
// TODO refactor this -> options object filled from Factory
|
||||
this.useSourceMap = false;
|
||||
|
||||
// TODO figure out if this should be defined here instead of `NormalModule`.
|
||||
// Without this, type checking fails because the hooks use `Module`.
|
||||
this.resource = undefined;
|
||||
}
|
||||
|
||||
// TODO remove in webpack 6
|
||||
|
|
|
@ -117,6 +117,9 @@ class NormalModule extends Module {
|
|||
// Cache
|
||||
this._lastSuccessfulBuildMeta = {};
|
||||
this._forceBuild = true;
|
||||
|
||||
// TODO refactor this -> options object filled from Factory
|
||||
this.useSourceMap = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue