simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

ModuleWarning.js (1280B)


      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 class ModuleWarning extends WebpackError {
     13 	/**
     14 	 * @param {Error} warning error thrown
     15 	 * @param {{from?: string|null}} info additional info
     16 	 */
     17 	constructor(warning, { from = null } = {}) {
     18 		let message = "Module Warning";
     19 
     20 		if (from) {
     21 			message += ` (from ${from}):\n`;
     22 		} else {
     23 			message += ": ";
     24 		}
     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 		this.name = "ModuleWarning";
     35 		this.warning = warning;
     36 		this.details =
     37 			warning && typeof warning === "object" && warning.stack
     38 				? cleanUp(warning.stack, this.message)
     39 				: undefined;
     40 	}
     41 
     42 	serialize(context) {
     43 		const { write } = context;
     44 
     45 		write(this.warning);
     46 
     47 		super.serialize(context);
     48 	}
     49 
     50 	deserialize(context) {
     51 		const { read } = context;
     52 
     53 		this.warning = read();
     54 
     55 		super.deserialize(context);
     56 	}
     57 }
     58 
     59 makeSerializable(ModuleWarning, "webpack/lib/ModuleWarning");
     60 
     61 module.exports = ModuleWarning;