* Parses comment options. * @param {Range} range range of the comment * @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: Comment })[] | null }} result
(range)
| 5583 | * @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: Comment })[] | null }} result |
| 5584 | */ |
| 5585 | parseCommentOptions(range) { |
| 5586 | const comments = this.getComments(range); |
| 5587 | if (comments.length === 0) { |
| 5588 | return EMPTY_COMMENT_OPTIONS; |
| 5589 | } |
| 5590 | /** @type {Record<string, EXPECTED_ANY>} */ |
| 5591 | const options = {}; |
| 5592 | /** @type {(Error & { comment: Comment })[]} */ |
| 5593 | const errors = []; |
| 5594 | for (const comment of comments) { |
| 5595 | const { value } = comment; |
| 5596 | if (value && webpackCommentRegExp.test(value)) { |
| 5597 | // try compile only if webpack options comment is present |
| 5598 | try { |
| 5599 | for (let [key, val] of Object.entries( |
| 5600 | vm.runInContext( |
| 5601 | `(function(){return {${value}};})()`, |
| 5602 | this.magicCommentContext |
| 5603 | ) |
| 5604 | )) { |
| 5605 | if (typeof val === "object" && val !== null) { |
| 5606 | val = |
| 5607 | val.constructor.name === "RegExp" |
| 5608 | ? new RegExp(val) |
| 5609 | : JSON.parse(JSON.stringify(val)); |
| 5610 | } |
| 5611 | options[key] = val; |
| 5612 | } |
| 5613 | } catch (err) { |
| 5614 | const newErr = new Error(String(/** @type {Error} */ (err).message)); |
| 5615 | newErr.stack = String(/** @type {Error} */ (err).stack); |
| 5616 | Object.assign(newErr, { comment }); |
| 5617 | errors.push(/** @type {(Error & { comment: Comment })} */ (newErr)); |
| 5618 | } |
| 5619 | } |
| 5620 | } |
| 5621 | return { options, errors }; |
| 5622 | } |
| 5623 | |
| 5624 | /** |
| 5625 | * Finds the root object of a member expression chain without allocating the |
nothing calls this directly
no test coverage detected