(event)
| 371 | } |
| 372 | |
| 373 | handleEvent(event) { |
| 374 | if (event.type === "change") { |
| 375 | try { |
| 376 | if (this.format === "lex") { |
| 377 | const start = performance.now(); |
| 378 | const tokens = lex(this.code); |
| 379 | this.dispatchEvent( |
| 380 | new MetricEvent("parseend", performance.now() - start), |
| 381 | ); |
| 382 | this.view.dispatch( |
| 383 | this.view.state.update({ |
| 384 | changes: { |
| 385 | from: 0, |
| 386 | to: this.view.state.doc.length, |
| 387 | insert: JSON.stringify(tokens, null, 2), |
| 388 | }, |
| 389 | }), |
| 390 | ); |
| 391 | this.dispatchEvent(new CsskitDiagnosticEvent([])); |
| 392 | } else if (this.format === "errors") { |
| 393 | const start = performance.now(); |
| 394 | const { diagnostics } = parse(this.code); |
| 395 | this.dispatchEvent(new MetricEvent("parseend", performance.now() - start)); |
| 396 | const report = parse_error_report(this.code); |
| 397 | this.view.dispatch( |
| 398 | this.view.state.update({ |
| 399 | changes: { |
| 400 | from: 0, |
| 401 | to: this.view.state.doc.length, |
| 402 | insert: report, |
| 403 | }, |
| 404 | }), |
| 405 | ); |
| 406 | this.dispatchEvent(new CsskitDiagnosticEvent(diagnostics)); |
| 407 | } else if (this.format === "format") { |
| 408 | const start = performance.now(); |
| 409 | const formatted = format(this.code, this.formatOptions); |
| 410 | this.dispatchEvent( |
| 411 | new MetricEvent("parseend", performance.now() - start), |
| 412 | ); |
| 413 | this.view.dispatch( |
| 414 | this.view.state.update({ |
| 415 | changes: { |
| 416 | from: 0, |
| 417 | to: this.view.state.doc.length, |
| 418 | insert: formatted, |
| 419 | }, |
| 420 | }), |
| 421 | ); |
| 422 | this.dispatchEvent(new CsskitDiagnosticEvent([])); |
| 423 | } else if (this.format === "minify") { |
| 424 | const start = performance.now(); |
| 425 | const minified = minify(this.code); |
| 426 | this.dispatchEvent( |
| 427 | new MetricEvent("parseend", performance.now() - start), |
| 428 | ); |
| 429 | this.dispatchEvent( |
| 430 | new MetricEvent("minify", minified.length, "bytes"), |
no test coverage detected