-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9391 from vankop/create-hash-typescript
esdoc(createHash)
- Loading branch information
Showing
12 changed files
with
145 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
|
||
const WebpackError = require("./WebpackError"); | ||
const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/; | ||
|
||
/** | ||
* @param {string=} method method name | ||
* @returns {string} message | ||
*/ | ||
function createMessage(method) { | ||
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(); | ||
} | ||
|
||
/** | ||
* Error for abstract method | ||
* @example | ||
* class FooClass { | ||
* abstractMethod() { | ||
* throw new AbstractMethodError(); // error message: Abstract method FooClass.abstractMethod. Must be overriden. | ||
* } | ||
* } | ||
* | ||
*/ | ||
class AbstractMethodError extends WebpackError { | ||
constructor() { | ||
super(new Message().message); | ||
this.name = "AbstractMethodError"; | ||
} | ||
} | ||
|
||
module.exports = AbstractMethodError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
const AbstractMethodError = require("../lib/AbstractMethodError"); | ||
|
||
describe("WebpackError", () => { | ||
class Foo { | ||
abstractMethod() { | ||
return new AbstractMethodError(); | ||
} | ||
} | ||
|
||
class Child extends Foo {} | ||
|
||
const expectedMessage = "Abstract method $1. Must be overridden."; | ||
|
||
it("Should construct message with caller info", () => { | ||
const fooClassError = new Foo().abstractMethod(); | ||
const childClassError = new Child().abstractMethod(); | ||
|
||
expect(fooClassError.message).toBe( | ||
expectedMessage.replace("$1", "Foo.abstractMethod") | ||
); | ||
expect(childClassError.message).toBe( | ||
expectedMessage.replace("$1", "Child.abstractMethod") | ||
); | ||
}); | ||
}); |