| [9af201e] | 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 makeSerializable = require("../util/makeSerializable");
|
|---|
| 10 | const WebpackError = require("./WebpackError");
|
|---|
| 11 |
|
|---|
| 12 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|---|
| 13 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|---|
| 14 |
|
|---|
| 15 | class ModuleWarning extends WebpackError {
|
|---|
| 16 | /**
|
|---|
| 17 | * Creates an instance of ModuleWarning.
|
|---|
| 18 | * @param {Error} warning error thrown
|
|---|
| 19 | * @param {{ from?: string | null }} info additional info
|
|---|
| 20 | */
|
|---|
| 21 | constructor(warning, { from = null } = {}) {
|
|---|
| 22 | let message = "Module Warning";
|
|---|
| 23 |
|
|---|
| 24 | message += from ? ` (from ${from}):\n` : ": ";
|
|---|
| 25 |
|
|---|
| 26 | if (warning && typeof warning === "object" && warning.message) {
|
|---|
| 27 | message += warning.message;
|
|---|
| 28 | } else if (warning) {
|
|---|
| 29 | message += String(warning);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | super(message);
|
|---|
| 33 |
|
|---|
| 34 | /** @type {string} */
|
|---|
| 35 | this.name = "ModuleWarning";
|
|---|
| 36 | this.warning = warning;
|
|---|
| 37 | this.details =
|
|---|
| 38 | warning && typeof warning === "object" && warning.stack
|
|---|
| 39 | ? cleanUp(warning.stack, this.message)
|
|---|
| 40 | : undefined;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * Serializes this instance into the provided serializer context.
|
|---|
| 45 | * @param {ObjectSerializerContext} context context
|
|---|
| 46 | */
|
|---|
| 47 | serialize(context) {
|
|---|
| 48 | const { write } = context;
|
|---|
| 49 |
|
|---|
| 50 | write(this.warning);
|
|---|
| 51 |
|
|---|
| 52 | super.serialize(context);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | /**
|
|---|
| 56 | * Restores this instance from the provided deserializer context.
|
|---|
| 57 | * @param {ObjectDeserializerContext} context context
|
|---|
| 58 | */
|
|---|
| 59 | deserialize(context) {
|
|---|
| 60 | const { read } = context;
|
|---|
| 61 |
|
|---|
| 62 | this.warning = read();
|
|---|
| 63 |
|
|---|
| 64 | super.deserialize(context);
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | makeSerializable(ModuleWarning, "webpack/lib/errors/ModuleWarning");
|
|---|
| 69 |
|
|---|
| 70 | /** @type {typeof ModuleWarning} */
|
|---|
| 71 | module.exports = ModuleWarning;
|
|---|