Skip to content

Commit a33795e

Browse files
authored
Merge pull request #2 from gfmio/bugfix/remove-node-type-def-1
Merge bugfix/remove-node-type-def-1 into master
2 parents caa4690 + 7f86521 commit a33795e

34 files changed

+6245
-8185
lines changed

.editorconfig

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,23 @@ end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10+
printWidth = 80
1011

11-
[*.{ts,tsx,js,jsx,json}]
12-
indent_size = 4
12+
[*.{ts,tsx,js,jsx,json,json5}]
1313
curly_bracket_next_line = true
1414
spaces_around_operators = true
1515
spaces_around_brackets = outside
1616
indent_brace_style = K&R
17-
max_line_length = 120
1817

19-
[{package.json,.travis.yml}]
20-
indent_size = 2
18+
[*.{ts,js}]
19+
max_line_length = 80
2120

22-
# XML Project Files
23-
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
24-
indent_size = 2
21+
[*.{tsx,jsx}]
22+
max_line_length = 120
23+
24+
[*.{json,json5}]
25+
max_line_length = 120
2526

2627
# Markdown Files
2728
[*.md]
2829
trim_trailing_whitespace = false
29-
30-
# Web Files
31-
[*.{htm,html,css,scss,less}]
32-
indent_size = 2
33-
insert_final_newline = true
34-
35-
# Bash Files
36-
[*.sh]
37-
end_of_line = lf

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ tests
44
.editorconfig
55
.gitignore
66
.npmignore
7+
.prettierrc.toml
78
package-lock.json
89
tslint.json

.prettierrc.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
arrowParens = "always"
2+
bracketSpacing = true
3+
insertPragma = false
4+
jsxBracketSameLine = false
5+
printWidth = 80
6+
proseWrap = "always"
7+
requirePragma = false
8+
semi = true
9+
singleQuote = false
10+
tabWidth = 2
11+
trailingComma = "all"
12+
13+
[[overrides]]
14+
files = ["*.ts", "*.js"]
15+
[overrides.options]
16+
printWidth = 80
17+
18+
[[overrides]]
19+
files = ["*.tsx", ".jsx"]
20+
[overrides.options]
21+
printWidth = 120
22+
23+
[[overrides]]
24+
files = ["*.json", "*.json5"]
25+
[overrides.options]
26+
printWidth = 120
27+
28+
[[overrides]]
29+
files = "*.md"
30+
[overrides.options]
31+
# proseWrap = "never"

README.md

Lines changed: 181 additions & 88 deletions
Large diffs are not rendered by default.

lib/cjs.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference types="node" />
21
export declare class ExtendableError extends Error {
3-
public name: string;
4-
public message: string;
5-
public stack?: string;
2+
public name: string;
3+
public message: string;
4+
public stack?: string;
65
}
76
export default ExtendableError;

lib/cjs.js

Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,95 +6,114 @@ var helpers = require("./helpers");
66
var setPrototypeOf = helpers.setPrototypeOf;
77
var getPrototypeOf = helpers.getPrototypeOf;
88
var defineProperty = helpers.defineProperty;
9-
var hasOwnProperty = helpers.hasOwnProperty;
109
var objectCreate = helpers.objectCreate;
1110

1211
// Small test for IE6-8, which checks if the environment prints errors "nicely"
13-
// If not, a toString() method to be added to the error objects with formatting like in more modern browsers
14-
var uglyErrorPrinting = (new Error()).toString() === "[object Error]";
12+
// If not, a toString() method to be added to the error objects with formatting
13+
// like in more modern browsers
14+
var uglyErrorPrinting = new Error().toString() === "[object Error]";
1515

1616
// For compatibility
1717
var extendableErrorName = "";
1818

1919
function ExtendableError(message) {
20-
// Get the constructor
21-
var originalConstructor = this.constructor;
22-
// Get the constructor name from the non-standard name property. If undefined (on old IEs), it uses the string representation
23-
// of the function to extract the name. This should work in all cases, except for directly instantiated ExtendableError objects,
24-
// for which the name of the ExtendableError class / function is used
25-
var constructorName = originalConstructor.name || (function() {
26-
var constructorNameMatch = originalConstructor.toString().match(/^function\s*([^\s(]+)/);
27-
return constructorNameMatch === null ? (extendableErrorName ? extendableErrorName : "Error") : constructorNameMatch[1];
20+
// Get the constructor
21+
var originalConstructor = this.constructor;
22+
// Get the constructor name from the non-standard name property. If undefined
23+
// (on old IEs), it uses the string representation of the function to extract
24+
// the name. This should work in all cases, except for directly instantiated
25+
// ExtendableError objects, for which the name of the ExtendableError class /
26+
// function is used
27+
var constructorName =
28+
originalConstructor.name ||
29+
(function() {
30+
var constructorNameMatch = originalConstructor
31+
.toString()
32+
.match(/^function\s*([^\s(]+)/);
33+
return constructorNameMatch === null
34+
? extendableErrorName
35+
? extendableErrorName
36+
: "Error"
37+
: constructorNameMatch[1];
2838
})();
29-
// If the constructor name is "Error", ...
30-
var constructorNameIsError = constructorName === "Error";
31-
// change it to the name of the ExtendableError class / function
32-
var name = constructorNameIsError ? extendableErrorName : constructorName;
39+
// If the constructor name is "Error", ...
40+
var constructorNameIsError = constructorName === "Error";
41+
// change it to the name of the ExtendableError class / function
42+
var name = constructorNameIsError ? extendableErrorName : constructorName;
3343

34-
// Obtain a new Error instance. This also sets the message property already.
35-
var instance = Error.apply(this, arguments);
44+
// Obtain a new Error instance. This also sets the message property already.
45+
var instance = Error.apply(this, arguments);
3646

37-
// Set the prototype of this to the prototype of instance
38-
setPrototypeOf(instance, getPrototypeOf(this));
47+
// Set the prototype of this to the prototype of instance
48+
setPrototypeOf(instance, getPrototypeOf(this));
3949

40-
// On old IEs, the instance will not extend our subclasses this way. The fix is to use this from the function call instead.
41-
if (!(instance instanceof originalConstructor) || !(instance instanceof ExtendableError)) {
42-
var instance = this;
43-
Error.apply(this, arguments);
44-
defineProperty(instance, "message", {
45-
configurable: true,
46-
enumerable: false,
47-
value: message,
48-
writable: true
49-
});
50-
}
51-
52-
// define the name property
53-
defineProperty(instance, "name", {
54-
configurable: true,
55-
enumerable: false,
56-
value: name,
57-
writable: true
50+
// On old IEs, the instance will not extend our subclasses this way. The fix is to use this from the function call instead.
51+
if (
52+
!(instance instanceof originalConstructor) ||
53+
!(instance instanceof ExtendableError)
54+
) {
55+
var instance = this;
56+
Error.apply(this, arguments);
57+
defineProperty(instance, "message", {
58+
configurable: true,
59+
enumerable: false,
60+
value: message,
61+
writable: true,
5862
});
63+
}
64+
65+
// define the name property
66+
defineProperty(instance, "name", {
67+
configurable: true,
68+
enumerable: false,
69+
value: name,
70+
writable: true,
71+
});
5972

60-
// Use Error.captureStackTrace on V8 to capture the proper stack trace excluding any of our error classes
61-
if (Error.captureStackTrace) {
62-
Error.captureStackTrace(instance, constructorNameIsError ? ExtendableError : originalConstructor);
63-
}
64-
// instance.stack can still be undefined, in which case the best solution is to create a new Error object and get it from there
65-
if (instance.stack === undefined) {
66-
var err = new Error(message);
67-
err.name = instance.name;
68-
instance.stack = err.stack;
69-
}
73+
// Use Error.captureStackTrace on V8 to capture the proper stack trace excluding any of our error classes
74+
if (Error.captureStackTrace) {
75+
Error.captureStackTrace(
76+
instance,
77+
constructorNameIsError ? ExtendableError : originalConstructor,
78+
);
79+
}
80+
// instance.stack can still be undefined, in which case the best solution is to create a new Error object and get it from there
81+
if (instance.stack === undefined) {
82+
var err = new Error(message);
83+
err.name = instance.name;
84+
instance.stack = err.stack;
85+
}
7086

71-
// If the environment does not have a proper string representation (IE), provide an alternative toString()
72-
if (uglyErrorPrinting) {
73-
defineProperty(instance, "toString", {
74-
configurable: true,
75-
enumerable: false,
76-
value: function toString() {
77-
return (this.name || "Error") + (typeof this.message === "undefined" ? "" : ": " + this.message);
78-
},
79-
writable: true
80-
});
81-
}
87+
// If the environment does not have a proper string representation (IE), provide an alternative toString()
88+
if (uglyErrorPrinting) {
89+
defineProperty(instance, "toString", {
90+
configurable: true,
91+
enumerable: false,
92+
value: function toString() {
93+
return (
94+
(this.name || "Error") +
95+
(typeof this.message === "undefined" ? "" : ": " + this.message)
96+
);
97+
},
98+
writable: true,
99+
});
100+
}
82101

83-
// We're done!
84-
return instance;
102+
// We're done!
103+
return instance;
85104
}
86105

87106
// Get the name of the ExtendableError function or use the string literal
88107
extendableErrorName = ExtendableError.name || "ExtendableError";
89108

90109
// Set the prototype of ExtendableError to an Error object
91110
ExtendableError.prototype = objectCreate(Error.prototype, {
92-
constructor: {
93-
value: Error,
94-
enumerable: false,
95-
writable: true,
96-
configurable: true
97-
}
111+
constructor: {
112+
value: Error,
113+
enumerable: false,
114+
writable: true,
115+
configurable: true,
116+
},
98117
});
99118

100119
// Export

lib/es.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference types="node" />
21
export declare class ExtendableError extends Error {
3-
public name: string;
4-
public message: string;
5-
public stack?: string;
2+
public name: string;
3+
public message: string;
4+
public stack?: string;
65
}
76
export default ExtendableError;

lib/es.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
"use strict";
22

33
class ExtendableError extends Error {
4-
constructor(...params) {
5-
super(...params);
6-
var message = params.length > 0 && typeof params[0] === "string" ? params[0] : "";
4+
constructor(...params) {
5+
super(...params);
6+
var message =
7+
params.length > 0 && typeof params[0] === "string" ? params[0] : "";
78

8-
// Replace Error with ClassName of the constructor, if it has not been overwritten already
9-
if ((this.name === undefined) || (this.name === "Error")) {
10-
Object.defineProperty(this, "name", {
11-
configurable: true,
12-
enumerable: false,
13-
value: this.constructor.name,
14-
writable: true
15-
});
16-
}
9+
// Replace Error with ClassName of the constructor, if it has not been overwritten already
10+
if (this.name === undefined || this.name === "Error") {
11+
Object.defineProperty(this, "name", {
12+
configurable: true,
13+
enumerable: false,
14+
value: this.constructor.name,
15+
writable: true,
16+
});
17+
}
1718

18-
Object.defineProperty(this, "message", {
19-
configurable: true,
20-
enumerable: false,
21-
value: message,
22-
writable: true
23-
});
19+
Object.defineProperty(this, "message", {
20+
configurable: true,
21+
enumerable: false,
22+
value: message,
23+
writable: true,
24+
});
2425

25-
Object.defineProperty(this, "stack", {
26-
configurable: true,
27-
enumerable: false,
28-
value: "",
29-
writable: true
30-
});
26+
Object.defineProperty(this, "stack", {
27+
configurable: true,
28+
enumerable: false,
29+
value: "",
30+
writable: true,
31+
});
3132

32-
// Maintains proper stack trace for where our error was thrown (only available on V8)
33-
if (Error.captureStackTrace) {
34-
Error.captureStackTrace(this, this.constructor);
35-
} else if (this.stack === "") {
36-
this.stack = (new Error(message)).stack;
37-
}
33+
// Maintains proper stack trace for where our error was thrown (only available on V8)
34+
if (Error.captureStackTrace) {
35+
Error.captureStackTrace(this, this.constructor);
36+
} else if (this.stack === "") {
37+
this.stack = new Error(message).stack;
3838
}
39+
}
3940
}
4041

4142
exports.ExtendableError = ExtendableError;

0 commit comments

Comments
 (0)