summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-05-03 19:45:57 +0200
committerGitHub <noreply@github.com>2022-05-03 19:45:57 +0200
commit3f08a40412d89bd54222ad51fc1aaeb508e2e5e7 (patch)
tree61c8cac3376e4ef7f842dd3267bfd7ada31806c3 /cli
parent5ddb83a4c2a5622d0ea173c0798550ae76e1fd69 (diff)
refactor: add core.formatLocationFilename, remove op_format_filename (#14474)
This commit moves "op_format_location" to "core/ops_builtin.rs" and removes "Deno.core.createPrepareStackTrace" in favor of "Deno.core.prepareStackTrace". Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/fmt_errors.rs31
-rw-r--r--cli/ops/errors.rs11
2 files changed, 4 insertions, 38 deletions
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs
index b29b97ea2..6f3a02f9e 100644
--- a/cli/fmt_errors.rs
+++ b/cli/fmt_errors.rs
@@ -4,36 +4,11 @@ use crate::colors::cyan;
use crate::colors::italic_bold;
use crate::colors::red;
use crate::colors::yellow;
-use deno_core::error::{JsError, JsStackFrame};
-use deno_core::url::Url;
+use deno_core::error::format_file_name;
+use deno_core::error::JsError;
+use deno_core::error::JsStackFrame;
const SOURCE_ABBREV_THRESHOLD: usize = 150;
-const DATA_URL_ABBREV_THRESHOLD: usize = 150;
-
-pub fn format_file_name(file_name: &str) -> String {
- if file_name.len() > DATA_URL_ABBREV_THRESHOLD {
- if let Ok(url) = Url::parse(file_name) {
- if url.scheme() == "data" {
- let data_path = url.path();
- if let Some(data_pieces) = data_path.split_once(',') {
- let data_length = data_pieces.1.len();
- if let Some(data_start) = data_pieces.1.get(0..20) {
- if let Some(data_end) = data_pieces.1.get(data_length - 20..) {
- return format!(
- "{}:{},{}......{}",
- url.scheme(),
- data_pieces.0,
- data_start,
- data_end
- );
- }
- }
- }
- }
- }
- }
- file_name.to_string()
-}
// Keep in sync with `/core/error.js`.
pub fn format_location(frame: &JsStackFrame) -> String {
diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs
index f0f5fce04..19c64c712 100644
--- a/cli/ops/errors.rs
+++ b/cli/ops/errors.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use crate::diagnostics::Diagnostics;
-use crate::fmt_errors::format_file_name;
use deno_core::error::AnyError;
use deno_core::op;
use deno_core::serde_json;
@@ -11,10 +10,7 @@ use deno_core::Extension;
pub fn init() -> Extension {
Extension::builder()
- .ops(vec![
- op_format_diagnostic::decl(),
- op_format_file_name::decl(),
- ])
+ .ops(vec![op_format_diagnostic::decl()])
.build()
}
@@ -23,8 +19,3 @@ fn op_format_diagnostic(args: Value) -> Result<Value, AnyError> {
let diagnostic: Diagnostics = serde_json::from_value(args)?;
Ok(json!(diagnostic.to_string()))
}
-
-#[op]
-fn op_format_file_name(file_name: String) -> Result<String, AnyError> {
- Ok(format_file_name(&file_name))
-}