Skip to content

Commit

Permalink
fix(cli): Use the --source-maps option (#6708)
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimetodie committed Dec 23, 2022
1 parent 7fcc978 commit 24cd384
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bindings/swc_cli/src/commands/compile.rs
Expand Up @@ -13,7 +13,7 @@ use rayon::prelude::*;
use relative_path::RelativePath;
use swc_core::{
base::{
config::{Config, ConfigFile, Options},
config::{ConfigFile, Options, SourceMapsConfig},
try_with_handler, Compiler, HandlerOpts, TransformOutput,
},
common::{
Expand Down Expand Up @@ -266,28 +266,32 @@ struct InputContext {
#[swc_trace]
impl CompileOptions {
fn build_transform_options(&self, file_path: &Option<&Path>) -> anyhow::Result<Options> {
let base_options = Options::default();
let base_config = Config::default();

let config_file = self.config_file.as_ref().map(|config_file_path| {
ConfigFile::Str(config_file_path.to_string_lossy().to_string())
});

let mut ret = Options {
config: Config { ..base_config },
let mut options = Options {
config_file,
..base_options
..Options::default()
};

if let Some(file_path) = *file_path {
ret.filename = file_path.to_str().unwrap_or_default().to_owned();
options.filename = file_path.to_str().unwrap_or_default().to_owned();
}

if let Some(env_name) = &self.env_name {
ret.env_name = env_name.to_string();
options.env_name = env_name.to_string();
}

if let Some(source_maps) = &self.source_maps {
options.source_maps = Some(match source_maps.as_str() {
"false" => SourceMapsConfig::Bool(false),
"true" => SourceMapsConfig::Bool(true),
value => SourceMapsConfig::Str(value.to_string()),
});
}

Ok(ret)
Ok(options)
}

/// Create canonical list of inputs to be processed across stdin / single
Expand Down

0 comments on commit 24cd384

Please sign in to comment.