Skip to content

Commit

Permalink
refactor: don't use anyhow (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats authored Aug 12, 2024
1 parent 69c7b56 commit 774ec2b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ react = ["transforms", "swc_ecma_transforms_react", "swc_ecma_transforms_macros"
scopes = ["view", "utils", "visit"]
sourcemap = ["dprint-swc-ext/sourcemap"]
transforms = ["swc_ecma_loader", "swc_ecma_transforms_base"]
emit = ["anyhow", "base64", "codegen", "sourcemap"]
emit = ["base64", "codegen", "sourcemap", "dep:sourcemap"]
transpiling = ["emit", "proposal", "react", "transforms", "typescript", "utils", "visit"]
typescript = ["transforms", "swc_ecma_transforms_typescript"]
utils = ["swc_ecma_utils"]
view = ["dprint-swc-ext/view"]
visit = ["swc_ecma_visit", "swc_visit", "swc_visit_macros", "swc_macros_common"]

[dependencies]
anyhow = { version = "1.0.64", optional = true }
base64 = { version = "0.21.6", optional = true }
deno_media_type = "0.1.4"
deno_terminal = "0.1.1"
Expand Down Expand Up @@ -75,6 +74,8 @@ swc_macros_common = { version = "=0.3.13", optional = true }
swc_trace_macro = { version = "=0.1.3", optional = true }
swc_visit = { version = "=0.6.1", optional = true }
swc_visit_macros = { version = "=0.5.13", optional = true }
# just for error handling
sourcemap = { version = "9.0.0", optional = true }
thiserror = "1.0.58"

[dev-dependencies]
Expand Down
13 changes: 7 additions & 6 deletions src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::string::FromUtf8Error;

use anyhow::Result;
use base64::Engine;
use thiserror::Error;

Expand Down Expand Up @@ -83,9 +82,11 @@ pub struct EmittedSourceText {
#[derive(Debug, Error)]
pub enum EmitError {
#[error(transparent)]
SwcEmit(anyhow::Error),
SwcEmit(std::io::Error),
#[error(transparent)]
SourceMap(anyhow::Error),
SourceMap(sourcemap::Error),
#[error(transparent)]
SourceMapEncode(base64::EncodeSliceError),
}

/// Emits the program as a string of JavaScript code, possibly with the passed
Expand Down Expand Up @@ -120,7 +121,7 @@ pub fn emit(
};
program
.emit_with(&mut emitter)
.map_err(|e| EmitError::SwcEmit(e.into()))?;
.map_err(EmitError::SwcEmit)?;
}

let mut map: Option<Vec<u8>> = None;
Expand All @@ -141,14 +142,14 @@ pub fn emit(
}
source_map
.to_writer(&mut map_buf)
.map_err(|e| EmitError::SourceMap(e.into()))?;
.map_err(EmitError::SourceMap)?;

if emit_options.source_map == SourceMapOption::Inline {
// length is from the base64 crate examples
let mut inline_buf = vec![0; map_buf.len() * 4 / 3 + 4];
let size = base64::prelude::BASE64_STANDARD
.encode_slice(map_buf, &mut inline_buf)
.map_err(|err| EmitError::SourceMap(err.into()))?;
.map_err(EmitError::SourceMapEncode)?;
let inline_buf = &inline_buf[..size];
let prelude_text = "//# sourceMappingURL=data:application/json;base64,";
let src_has_trailing_newline = src_buf.ends_with(&[b'\n']);
Expand Down
1 change: 0 additions & 1 deletion src/transpiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::borrow::Cow;
use std::rc::Rc;
use std::sync::Arc;

use anyhow::Result;
use deno_media_type::MediaType;
use swc_ecma_visit::as_folder;
use thiserror::Error;
Expand Down

0 comments on commit 774ec2b

Please sign in to comment.