diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-08-19 19:13:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-19 19:13:43 +0200 |
commit | be1e7ab5320c0a110998818c3916c79b39710613 (patch) | |
tree | 91b54be5cc70507ce65cf1846c953938a3f234b2 /cli/swc_util.rs | |
parent | 1507a8cf2d8bce8c3596583b995fea4914a99203 (diff) |
refactor: move cli/doc/ to separate crate (#7103)
Diffstat (limited to 'cli/swc_util.rs')
-rw-r--r-- | cli/swc_util.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cli/swc_util.rs b/cli/swc_util.rs index d1115e024..13d165113 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -1,6 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::msg::MediaType; use deno_core::ErrBox; +use serde::Serialize; use std::error::Error; use std::fmt; use std::rc::Rc; @@ -31,6 +32,31 @@ use swc_ecmascript::transforms::fixer; use swc_ecmascript::transforms::typescript; use swc_ecmascript::visit::FoldWith; +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct Location { + pub filename: String, + pub line: usize, + pub col: usize, +} + +impl Into<Location> for swc_common::Loc { + fn into(self) -> Location { + use swc_common::FileName::*; + + let filename = match &self.file.name { + Real(path_buf) => path_buf.to_string_lossy().to_string(), + Custom(str_) => str_.to_string(), + _ => panic!("invalid filename"), + }; + + Location { + filename, + line: self.line, + col: self.col_display, + } + } +} + struct DummyHandler; impl swc_ecmascript::codegen::Handlers for DummyHandler {} |