(err: ErrorPayload['err'], links = true)
| 218 | closeOnEsc: (e: KeyboardEvent) => void |
| 219 | |
| 220 | constructor(err: ErrorPayload['err'], links = true) { |
| 221 | super() |
| 222 | this.root = this.attachShadow({ mode: 'open' }) |
| 223 | this.root.appendChild(createTemplate()) |
| 224 | |
| 225 | codeframeRE.lastIndex = 0 |
| 226 | const hasFrame = err.frame && codeframeRE.test(err.frame) |
| 227 | const message = hasFrame |
| 228 | ? err.message.replace(codeframeRE, '') |
| 229 | : err.message |
| 230 | if (err.plugin) { |
| 231 | this.text('.plugin', `[plugin:${err.plugin}] `) |
| 232 | } |
| 233 | this.text('.message-body', message.trim()) |
| 234 | |
| 235 | const [file] = (err.loc?.file || err.id || 'unknown file').split(`?`) |
| 236 | if (err.loc) { |
| 237 | this.text('.file', `${file}:${err.loc.line}:${err.loc.column}`, links) |
| 238 | } else if (err.id) { |
| 239 | this.text('.file', file) |
| 240 | } |
| 241 | |
| 242 | if (hasFrame) { |
| 243 | this.text('.frame', err.frame!.trim()) |
| 244 | } |
| 245 | this.text('.stack', err.stack, links) |
| 246 | |
| 247 | this.root.querySelector('.window')!.addEventListener('click', (e) => { |
| 248 | e.stopPropagation() |
| 249 | }) |
| 250 | |
| 251 | this.addEventListener('click', () => { |
| 252 | this.close() |
| 253 | }) |
| 254 | |
| 255 | this.closeOnEsc = (e: KeyboardEvent) => { |
| 256 | if (e.key === 'Escape' || e.code === 'Escape') { |
| 257 | this.close() |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | document.addEventListener('keydown', this.closeOnEsc) |
| 262 | } |
| 263 | |
| 264 | text(selector: string, text: string, linkFiles = false): void { |
| 265 | const el = this.root.querySelector(selector)! |
nothing calls this directly
no test coverage detected