summaryrefslogtreecommitdiff
path: root/cli/ast.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-10-07 22:43:44 +1100
committerGitHub <noreply@github.com>2020-10-07 22:43:44 +1100
commit99aa23b8ddd73ab6332430c2ba7c44792fad3886 (patch)
tree4f71b92a09e04602738165dbc941f1ef1c3d5b02 /cli/ast.rs
parentcb3a3a1e951d0eef9e2d095f87eaaa2f5ea160ad (diff)
refactor(cli): remove TextDocument (#7850)
Diffstat (limited to 'cli/ast.rs')
-rw-r--r--cli/ast.rs31
1 files changed, 10 insertions, 21 deletions
diff --git a/cli/ast.rs b/cli/ast.rs
index 61c534e95..e3b45a6fd 100644
--- a/cli/ast.rs
+++ b/cli/ast.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-use crate::file_fetcher::TextDocument;
use crate::media_type::MediaType;
use deno_core::error::AnyError;
@@ -247,7 +246,7 @@ impl ParsedModule {
pub fn transpile(
self,
options: &TranspileOptions,
- ) -> Result<(TextDocument, Option<TextDocument>)> {
+ ) -> Result<(String, Option<String>)> {
let program = Program::Module(self.module);
let jsx_pass = react::react(
@@ -297,7 +296,7 @@ impl ParsedModule {
program.emit_with(&mut emitter)?;
}
let mut src = String::from_utf8(buf)?;
- let mut map: Option<TextDocument> = None;
+ let mut map: Option<String> = None;
{
let mut buf = Vec::new();
self
@@ -310,10 +309,10 @@ impl ParsedModule {
let encoded_map = base64::encode(buf);
src.push_str(&encoded_map);
} else {
- map = Some(TextDocument::from(buf));
+ map = Some(String::from_utf8(buf)?);
}
}
- Ok((src.into(), map))
+ Ok((src, map))
}
}
@@ -439,14 +438,10 @@ mod tests {
let (code, maybe_map) = module
.transpile(&TranspileOptions::default())
.expect("could not strip types");
- assert!(code
- .to_string()
- .unwrap()
- .starts_with("var D;\n(function(D) {\n"));
- assert!(code
- .to_string()
- .unwrap()
- .contains("\n//# sourceMappingURL=data:application/json;base64,"));
+ assert!(code.starts_with("var D;\n(function(D) {\n"));
+ assert!(
+ code.contains("\n//# sourceMappingURL=data:application/json;base64,")
+ );
assert!(maybe_map.is_none());
}
@@ -467,10 +462,7 @@ mod tests {
let (code, _) = module
.transpile(&TranspileOptions::default())
.expect("could not strip types");
- assert!(code
- .to_string()
- .unwrap()
- .contains("React.createElement(\"div\", null"));
+ assert!(code.contains("React.createElement(\"div\", null"));
}
#[test]
@@ -501,9 +493,6 @@ mod tests {
let (code, _) = module
.transpile(&TranspileOptions::default())
.expect("could not strip types");
- assert!(code
- .to_string()
- .unwrap()
- .contains("_applyDecoratedDescriptor("));
+ assert!(code.contains("_applyDecoratedDescriptor("));
}
}