main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Ivan Kopeykin @vankop
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const WebpackError = require("./WebpackError");
|
---|
| 9 | const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * @param {string=} method method name
|
---|
| 13 | * @returns {string} message
|
---|
| 14 | */
|
---|
| 15 | function createMessage(method) {
|
---|
| 16 | return `Abstract method${method ? ` ${method}` : ""}. Must be overridden.`;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * @constructor
|
---|
| 21 | */
|
---|
| 22 | function Message() {
|
---|
| 23 | /** @type {string | undefined} */
|
---|
| 24 | this.stack = undefined;
|
---|
| 25 | Error.captureStackTrace(this);
|
---|
| 26 | /** @type {RegExpMatchArray | null} */
|
---|
| 27 | const match =
|
---|
| 28 | /** @type {string} */
|
---|
| 29 | (/** @type {unknown} */ (this.stack))
|
---|
| 30 | .split("\n")[3]
|
---|
| 31 | .match(CURRENT_METHOD_REGEXP);
|
---|
| 32 |
|
---|
| 33 | this.message = match && match[1] ? createMessage(match[1]) : createMessage();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * Error for abstract method
|
---|
| 38 | * @example
|
---|
| 39 | * ```js
|
---|
| 40 | * class FooClass {
|
---|
| 41 | * abstractMethod() {
|
---|
| 42 | * throw new AbstractMethodError(); // error message: Abstract method FooClass.abstractMethod. Must be overridden.
|
---|
| 43 | * }
|
---|
| 44 | * }
|
---|
| 45 | * ```
|
---|
| 46 | */
|
---|
| 47 | class AbstractMethodError extends WebpackError {
|
---|
| 48 | constructor() {
|
---|
| 49 | super(new Message().message);
|
---|
| 50 | this.name = "AbstractMethodError";
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | module.exports = AbstractMethodError;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.