diff --git a/lib/dependencies/CommonJsImportsParserPlugin.js b/lib/dependencies/CommonJsImportsParserPlugin.js index 5a6e5faa4cd..e74e5c9743b 100644 --- a/lib/dependencies/CommonJsImportsParserPlugin.js +++ b/lib/dependencies/CommonJsImportsParserPlugin.js @@ -236,7 +236,8 @@ class CommonJsImportsParserPlugin { parser.parseCommentOptions(expr.range); if (commentErrors) { - for (const { cause: e, comment } of commentErrors) { + for (const e of commentErrors) { + const { comment } = e; parser.state.module.addWarning( new CommentCompilationWarning( `Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`, diff --git a/lib/dependencies/ImportParserPlugin.js b/lib/dependencies/ImportParserPlugin.js index 3dc84bd83af..718b0482828 100644 --- a/lib/dependencies/ImportParserPlugin.js +++ b/lib/dependencies/ImportParserPlugin.js @@ -55,7 +55,8 @@ class ImportParserPlugin { parser.parseCommentOptions(expr.range); if (commentErrors) { - for (const { cause: e, comment } of commentErrors) { + for (const e of commentErrors) { + const { comment } = e; parser.state.module.addWarning( new CommentCompilationWarning( `Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`, diff --git a/lib/dependencies/WorkerPlugin.js b/lib/dependencies/WorkerPlugin.js index a5a51a48154..5b68d84c06a 100644 --- a/lib/dependencies/WorkerPlugin.js +++ b/lib/dependencies/WorkerPlugin.js @@ -203,7 +203,8 @@ class WorkerPlugin { parser.parseCommentOptions(expr.range); if (commentErrors) { - for (const { cause: e, comment } of commentErrors) { + for (const e of commentErrors) { + const { comment } = e; parser.state.module.addWarning( new CommentCompilationWarning( `Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`, diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index 780c2de03a7..61d3eafe470 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -3635,6 +3635,7 @@ class JavascriptParser extends Parser { return EMPTY_COMMENT_OPTIONS; } let options = {}; + /** @type {unknown[]} */ let errors = []; for (const comment of comments) { const { value } = comment; @@ -3651,7 +3652,10 @@ class JavascriptParser extends Parser { options[key] = val; } } catch (e) { - errors.push({ comment, cause: e }); + const newErr = new Error(String(e.message)); + newErr.stack = String(e.stack); + newErr.comment = comment; + errors.push(newErr); } } } diff --git a/types.d.ts b/types.d.ts index 10e2a474b77..251d0adfd3d 100644 --- a/types.d.ts +++ b/types.d.ts @@ -5476,9 +5476,7 @@ declare class JavascriptParser extends Parser { evaluatedVariable(tagInfo?: any): VariableInfo; parseCommentOptions( range?: any - ): - | { options: null; errors: null } - | { options: object; errors: { comment: any; cause: unknown }[] }; + ): { options: null; errors: null } | { options: object; errors: unknown[] }; extractMemberExpressionChain(expression: MemberExpression): { members: string[]; object: