2016-01-04 04:42:56 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-01-09 11:48:49 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-22 19:05:58 +08:00
|
|
|
const { cleanUp } = require("./ErrorHelpers");
|
2018-07-30 23:08:51 +08:00
|
|
|
const WebpackError = require("./WebpackError");
|
2018-10-25 16:47:52 +08:00
|
|
|
const makeSerializable = require("./util/makeSerializable");
|
2017-03-22 20:00:57 +08:00
|
|
|
|
2017-03-25 05:17:47 +08:00
|
|
|
class ModuleWarning extends WebpackError {
|
2018-10-30 05:18:08 +08:00
|
|
|
constructor(warning, { from = null } = {}) {
|
2018-06-05 16:23:00 +08:00
|
|
|
let message = "Module Warning";
|
2018-10-25 16:47:52 +08:00
|
|
|
|
2018-03-02 17:56:34 +08:00
|
|
|
if (from) {
|
2018-06-05 16:43:10 +08:00
|
|
|
message += ` (from ${from}):\n`;
|
|
|
|
} else {
|
|
|
|
message += ": ";
|
2018-02-21 17:42:03 +08:00
|
|
|
}
|
2018-10-25 16:47:52 +08:00
|
|
|
|
2018-03-02 17:56:34 +08:00
|
|
|
if (warning && typeof warning === "object" && warning.message) {
|
2018-06-05 16:43:10 +08:00
|
|
|
message += warning.message;
|
2018-03-02 17:56:34 +08:00
|
|
|
} else if (warning) {
|
2018-06-05 16:43:10 +08:00
|
|
|
message += warning;
|
2018-02-22 20:57:20 +08:00
|
|
|
}
|
2018-10-25 16:47:52 +08:00
|
|
|
|
2018-06-05 16:23:00 +08:00
|
|
|
super(message);
|
2018-10-25 16:47:52 +08:00
|
|
|
|
2017-01-09 11:48:49 +08:00
|
|
|
this.name = "ModuleWarning";
|
|
|
|
this.warning = warning;
|
2018-02-25 09:00:20 +08:00
|
|
|
this.details =
|
|
|
|
warning && typeof warning === "object" && warning.stack
|
|
|
|
? cleanUp(warning.stack, this.message)
|
|
|
|
: undefined;
|
2017-02-16 03:55:54 +08:00
|
|
|
|
|
|
|
Error.captureStackTrace(this, this.constructor);
|
2017-01-09 11:48:49 +08:00
|
|
|
}
|
2018-10-25 16:47:52 +08:00
|
|
|
|
|
|
|
serialize(context) {
|
|
|
|
const { write } = context;
|
|
|
|
|
|
|
|
write(this.warning);
|
|
|
|
|
|
|
|
super.serialize(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
deserialize(context) {
|
|
|
|
const { read } = context;
|
|
|
|
|
|
|
|
this.warning = read();
|
|
|
|
|
|
|
|
super.deserialize(context);
|
|
|
|
}
|
2016-01-04 04:42:56 +08:00
|
|
|
}
|
|
|
|
|
2018-10-25 16:47:52 +08:00
|
|
|
makeSerializable(ModuleWarning, "webpack/lib/ModuleWarning");
|
|
|
|
|
2017-01-09 11:48:49 +08:00
|
|
|
module.exports = ModuleWarning;
|