Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Use the compile --source-maps option #6708

Merged
merged 2 commits into from Dec 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()),
realtimetodie marked this conversation as resolved.
Show resolved Hide resolved
});
}

Ok(ret)
Ok(options)
}

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