( rawOpts: string, optsStartIndex: number, )
| 94 | } |
| 95 | |
| 96 | async function parseWorkerOptions( |
| 97 | rawOpts: string, |
| 98 | optsStartIndex: number, |
| 99 | ): Promise<WorkerOptions> { |
| 100 | let opts: WorkerOptions = {} |
| 101 | try { |
| 102 | opts = evalValue<WorkerOptions>(rawOpts) |
| 103 | } catch { |
| 104 | const optsNode = ( |
| 105 | (await parseAstAsync(`(${rawOpts})`)) |
| 106 | .body[0] as ESTree.ExpressionStatement |
| 107 | ).expression |
| 108 | |
| 109 | const type = extractWorkerTypeFromAst(optsNode, optsStartIndex) |
| 110 | if (type) { |
| 111 | return { type } |
| 112 | } |
| 113 | |
| 114 | throw err( |
| 115 | 'Vite is unable to parse the worker options as the value is not static. ' + |
| 116 | 'To ignore this error, please use /* @vite-ignore */ in the worker options.', |
| 117 | optsStartIndex, |
| 118 | ) |
| 119 | } |
| 120 | |
| 121 | if (opts == null) { |
| 122 | return {} |
| 123 | } |
| 124 | |
| 125 | if (typeof opts !== 'object') { |
| 126 | throw err( |
| 127 | `Expected worker options to be an object, got ${typeof opts}`, |
| 128 | optsStartIndex, |
| 129 | ) |
| 130 | } |
| 131 | |
| 132 | return opts |
| 133 | } |
| 134 | |
| 135 | async function getWorkerType( |
| 136 | raw: string, |
no test coverage detected