[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const { cleanUp } = require("./ErrorHelpers");
|
---|
| 9 | const WebpackError = require("./WebpackError");
|
---|
| 10 | const makeSerializable = require("./util/makeSerializable");
|
---|
| 11 |
|
---|
| 12 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
| 13 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
| 14 |
|
---|
| 15 | class ModuleWarning extends WebpackError {
|
---|
| 16 | /**
|
---|
| 17 | * @param {Error} warning error thrown
|
---|
| 18 | * @param {{from?: string|null}} info additional info
|
---|
| 19 | */
|
---|
| 20 | constructor(warning, { from = null } = {}) {
|
---|
| 21 | let message = "Module Warning";
|
---|
| 22 |
|
---|
| 23 | message += from ? ` (from ${from}):\n` : ": ";
|
---|
| 24 |
|
---|
| 25 | if (warning && typeof warning === "object" && warning.message) {
|
---|
| 26 | message += warning.message;
|
---|
| 27 | } else if (warning) {
|
---|
| 28 | message += String(warning);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | super(message);
|
---|
| 32 |
|
---|
| 33 | this.name = "ModuleWarning";
|
---|
| 34 | this.warning = warning;
|
---|
| 35 | this.details =
|
---|
| 36 | warning && typeof warning === "object" && warning.stack
|
---|
| 37 | ? cleanUp(warning.stack, this.message)
|
---|
| 38 | : undefined;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * @param {ObjectSerializerContext} context context
|
---|
| 43 | */
|
---|
| 44 | serialize(context) {
|
---|
| 45 | const { write } = context;
|
---|
| 46 |
|
---|
| 47 | write(this.warning);
|
---|
| 48 |
|
---|
| 49 | super.serialize(context);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * @param {ObjectDeserializerContext} context context
|
---|
| 54 | */
|
---|
| 55 | deserialize(context) {
|
---|
| 56 | const { read } = context;
|
---|
| 57 |
|
---|
| 58 | this.warning = read();
|
---|
| 59 |
|
---|
| 60 | super.deserialize(context);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | makeSerializable(ModuleWarning, "webpack/lib/ModuleWarning");
|
---|
| 65 |
|
---|
| 66 | module.exports = ModuleWarning;
|
---|