diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-02-25 06:48:14 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-24 14:48:14 -0500 |
commit | 2b7e28b591a6947f76ddf9a53f49eec8f1accc0f (patch) | |
tree | cfa8f32e1e5171642fc916d77a397937e901fc48 /cli/ops | |
parent | 5da7c7df1d8649ddb5628b4dc830aa8c23ccb488 (diff) |
feat: Add Deno.formatDiagnostics (#4032)
Diffstat (limited to 'cli/ops')
-rw-r--r-- | cli/ops/errors.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index 4dd4f1ca1..b5cc75f7a 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -1,5 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; +use crate::diagnostics::Diagnostic; use crate::fmt_errors::JSError; use crate::op_error::OpError; use crate::ops::json_op; @@ -18,6 +19,10 @@ pub fn init(i: &mut Isolate, s: &State) { "format_error", s.core_op(json_op(s.stateful_op(op_format_error))), ); + i.register_op( + "format_diagnostic", + s.core_op(json_op(s.stateful_op(op_format_diagnostic))), + ); } #[derive(Deserialize)] @@ -68,3 +73,15 @@ fn op_apply_source_map( "column": orig_column as u32, }))) } + +fn op_format_diagnostic( + _state: &State, + args: Value, + _zero_copy: Option<ZeroCopyBuf>, +) -> Result<JsonOp, OpError> { + if let Some(diagnostic) = Diagnostic::from_json_value(&args) { + Ok(JsonOp::Sync(json!(diagnostic.to_string()))) + } else { + Err(OpError::type_error("bad diagnostic".to_string())) + } +} |