summaryrefslogtreecommitdiff
path: root/cli/ast
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ast')
-rw-r--r--cli/ast/bundle_hook.rs8
-rw-r--r--cli/ast/mod.rs16
-rw-r--r--cli/ast/transforms.rs3
3 files changed, 13 insertions, 14 deletions
diff --git a/cli/ast/bundle_hook.rs b/cli/ast/bundle_hook.rs
index 8e5b56c32..6b29bd8dd 100644
--- a/cli/ast/bundle_hook.rs
+++ b/cli/ast/bundle_hook.rs
@@ -14,18 +14,12 @@ impl Hook for BundleHook {
) -> Result<Vec<deno_ast::swc::ast::KeyValueProp>, AnyError> {
use deno_ast::swc::ast;
- // we use custom file names, and swc "wraps" these in `<` and `>` so, we
- // want to strip those back out.
- let mut value = module_record.file_name.to_string();
- value.pop();
- value.remove(0);
-
Ok(vec![
ast::KeyValueProp {
key: ast::PropName::Ident(ast::Ident::new("url".into(), span)),
value: Box::new(ast::Expr::Lit(ast::Lit::Str(ast::Str {
span,
- value: value.into(),
+ value: module_record.file_name.to_string().into(),
kind: ast::StrKind::Synthesized,
has_escape: false,
}))),
diff --git a/cli/ast/mod.rs b/cli/ast/mod.rs
index 57117bf7b..7a05b9caf 100644
--- a/cli/ast/mod.rs
+++ b/cli/ast/mod.rs
@@ -74,6 +74,7 @@ impl From<deno_ast::swc::common::Loc> for Location {
let filename = match &swc_loc.file.name {
Real(path_buf) => path_buf.to_string_lossy().to_string(),
Custom(str_) => str_.to_string(),
+ Url(url) => url.to_string(),
_ => panic!("invalid filename"),
};
@@ -117,6 +118,8 @@ pub struct EmitOptions {
/// Should the source map be inlined in the emitted code file, or provided
/// as a separate file. Defaults to `true`.
pub inline_source_map: bool,
+ /// Should the sources be inlined in the source map. Defaults to `true`.
+ pub inline_sources: bool,
// Should a corresponding .map file be created for the output. This should be
// false if inline_source_map is true. Defaults to `false`.
pub source_map: bool,
@@ -139,6 +142,7 @@ impl Default for EmitOptions {
emit_metadata: false,
imports_not_used_as_values: ImportsNotUsedAsValues::Remove,
inline_source_map: true,
+ inline_sources: true,
source_map: false,
jsx_factory: "React.createElement".into(),
jsx_fragment_factory: "React.Fragment".into(),
@@ -162,6 +166,7 @@ impl From<config_file::TsConfig> for EmitOptions {
emit_metadata: options.emit_decorator_metadata,
imports_not_used_as_values,
inline_source_map: options.inline_source_map,
+ inline_sources: options.inline_sources,
source_map: options.source_map,
jsx_factory: options.jsx_factory,
jsx_fragment_factory: options.jsx_fragment_factory,
@@ -204,7 +209,8 @@ pub fn transpile(
) -> Result<(String, Option<String>), AnyError> {
let program: Program = (*parsed_source.program()).clone();
let source_map = Rc::new(SourceMap::default());
- let file_name = FileName::Custom(parsed_source.specifier().to_string());
+ let specifier = resolve_url_or_path(parsed_source.specifier())?;
+ let file_name = FileName::Url(specifier);
source_map
.new_source_file(file_name, parsed_source.source().text().to_string());
let comments = parsed_source.comments().as_single_threaded(); // needs to be mutable
@@ -284,7 +290,7 @@ pub fn transpile(
/// A low level function which transpiles a source module into an swc
/// SourceFile.
pub fn transpile_module(
- specifier: &str,
+ specifier: &ModuleSpecifier,
source: &str,
media_type: MediaType,
emit_options: &EmitOptions,
@@ -292,10 +298,8 @@ pub fn transpile_module(
cm: Rc<SourceMap>,
) -> Result<(Rc<deno_ast::swc::common::SourceFile>, Module), AnyError> {
let source = strip_bom(source);
- let source_file = cm.new_source_file(
- FileName::Custom(specifier.to_string()),
- source.to_string(),
- );
+ let source_file =
+ cm.new_source_file(FileName::Url(specifier.clone()), source.to_string());
let input = StringInput::from(&*source_file);
let comments = SingleThreadedComments::default();
let syntax = get_syntax(media_type);
diff --git a/cli/ast/transforms.rs b/cli/ast/transforms.rs
index 142f27093..5e5e20802 100644
--- a/cli/ast/transforms.rs
+++ b/cli/ast/transforms.rs
@@ -260,6 +260,7 @@ mod test {
use deno_ast::swc::parser::TsConfig;
use deno_ast::swc::visit::Fold;
use deno_ast::swc::visit::FoldWith;
+ use deno_ast::ModuleSpecifier;
use std::rc::Rc;
use super::*;
@@ -434,7 +435,7 @@ mod test {
fn parse(src: &str) -> (Rc<SourceMap>, Module) {
let source_map = Rc::new(SourceMap::default());
let source_file = source_map.new_source_file(
- FileName::Custom("file.ts".to_string()),
+ FileName::Url(ModuleSpecifier::parse("file:///test.ts").unwrap()),
src.to_string(),
);
let input = StringInput::from(&*source_file);