diff options
Diffstat (limited to 'vanilla/node_modules/css-tree/lib/utils/create-custom-error.js')
| -rw-r--r-- | vanilla/node_modules/css-tree/lib/utils/create-custom-error.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/vanilla/node_modules/css-tree/lib/utils/create-custom-error.js b/vanilla/node_modules/css-tree/lib/utils/create-custom-error.js new file mode 100644 index 0000000..dba122f --- /dev/null +++ b/vanilla/node_modules/css-tree/lib/utils/create-custom-error.js @@ -0,0 +1,14 @@ +export function createCustomError(name, message) { + // use Object.create(), because some VMs prevent setting line/column otherwise + // (iOS Safari 10 even throws an exception) + const error = Object.create(SyntaxError.prototype); + const errorStack = new Error(); + + return Object.assign(error, { + name, + message, + get stack() { + return (errorStack.stack || '').replace(/^(.+\n){1,3}/, `${name}: ${message}\n`); + } + }); +}; |
