Skip to content
Permalink
Browse files
#9391 resolve super call discussion
  • Loading branch information
vankop committed Jul 15, 2019
1 parent bd7d95b commit bf1a24a9ab10e6d9b2240d41d90f86de9877ee19
Showing with 17 additions and 9 deletions.
  1. +2 −1 .eslintrc.js
  2. +14 −7 lib/AbstractMethodError.js
  3. +1 −1 test/AbstractMethodError.unittest.js
@@ -71,7 +71,8 @@ module.exports = {
};
return acc;
}, {})),
extends: "extends"
extends: "extends",
constructor: "constructor"
}
}
},
@@ -8,7 +8,19 @@ const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
* @returns {string} message
*/
function createMessage(method) {
return `Abstract method${method ? " " + method : ""}. Must be overriden.`;
return `Abstract method${method ? " " + method : ""}. Must be overridden.`;
}

/**
* @constructor
*/
function Message() {
this.stack = undefined;
Error.captureStackTrace(this);
/** @type {RegExpMatchArray} */
const match = this.stack.split("\n")[3].match(CURRENT_METHOD_REGEXP);

this.message = match && match[1] ? createMessage(match[1]) : createMessage();
}

/**
@@ -23,13 +35,8 @@ function createMessage(method) {
*/
class AbstractMethodError extends WebpackError {
constructor() {
super(createMessage());
super(new Message().message);
this.name = "AbstractMethodError";
/** @type {RegExpMatchArray} */
const match = this.stack.split("\n")[1].match(CURRENT_METHOD_REGEXP);
if (match && match[1]) {
this.message = createMessage(match[1]);
}
}
}

@@ -11,7 +11,7 @@ describe("WebpackError", () => {

class Child extends Foo {}

const expectedMessage = "Abstract method $1. Must be overriden.";
const expectedMessage = "Abstract method $1. Must be overridden.";

it("Should construct message with caller info", () => {
const fooClassError = new Foo().abstractMethod();

0 comments on commit bf1a24a

Please sign in to comment.