Skip to content

Commit

Permalink
#9391 resolve super call discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Jul 15, 2019
1 parent bd7d95b commit bf1a24a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -71,7 +71,8 @@ module.exports = {
};
return acc;
}, {})),
extends: "extends"
extends: "extends",
constructor: "constructor"
}
}
},
Expand Down
21 changes: 14 additions & 7 deletions lib/AbstractMethodError.js
Expand Up @@ -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();
}

/**
Expand All @@ -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]);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/AbstractMethodError.unittest.js
Expand Up @@ -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();
Expand Down

0 comments on commit bf1a24a

Please sign in to comment.