mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

PR-URL: https://github.com/nodejs/node/pull/57704 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
24 lines
756 B
JavaScript
24 lines
756 B
JavaScript
"use strict";
|
|
export function isSwcError(error) {
|
|
return error.code !== void 0;
|
|
}
|
|
export function wrapAndReThrowSwcError(error) {
|
|
const errorHints = `${error.filename}:${error.startLine}
|
|
${error.snippet}
|
|
`;
|
|
switch (error.code) {
|
|
case "UnsupportedSyntax": {
|
|
const unsupportedSyntaxError = new Error(error.message);
|
|
unsupportedSyntaxError.name = "UnsupportedSyntaxError";
|
|
unsupportedSyntaxError.stack = `${errorHints}${unsupportedSyntaxError.stack}`;
|
|
throw unsupportedSyntaxError;
|
|
}
|
|
case "InvalidSyntax": {
|
|
const syntaxError = new SyntaxError(error.message);
|
|
syntaxError.stack = `${errorHints}${syntaxError.stack}`;
|
|
throw syntaxError;
|
|
}
|
|
default:
|
|
throw new Error(error.message);
|
|
}
|
|
}
|