fix(swc): Fix sourceMap option of minify (#2380)

This commit is contained in:
Donny/강동윤 2021-10-09 00:01:09 +09:00 committed by GitHub
parent cf1235ece1
commit 486c689504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View File

@ -543,7 +543,7 @@ pub struct JsMinifyOptions {
pub toplevel: bool,
#[serde(default)]
pub source_map: bool,
pub source_map: BoolOrObject<TerserSourceMapOption>,
#[serde(default)]
pub output_path: Option<String>,
@ -551,6 +551,22 @@ pub struct JsMinifyOptions {
#[serde(default)]
pub inline_sources_content: bool,
}
/// `jsc.minify.sourceMap`
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct TerserSourceMapOption {
#[serde(default)]
pub filename: Option<String>,
#[serde(default)]
pub url: Option<String>,
#[serde(default)]
pub root: Option<String>,
#[serde(default)]
pub content: Option<String>,
}
/// `jsc.minify.format`.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]

View File

@ -908,10 +908,20 @@ impl Compiler {
self.run(|| {
let target = opts.ecma.clone().into();
let orig = if opts.source_map {
self.get_orig_src_map(&fm, &InputSourceMap::Bool(true), true)?
} else {
None
let (source_map, orig) = match &opts.source_map {
BoolOrObject::Bool(false) => (SourceMapsConfig::Bool(false), None),
BoolOrObject::Bool(true) => (SourceMapsConfig::Bool(true), None),
BoolOrObject::Obj(obj) => {
let orig = obj
.content
.as_ref()
.map(|s| sourcemap::SourceMap::from_slice(s.as_bytes()));
let orig = match orig {
Some(v) => Some(v?),
None => None,
};
(SourceMapsConfig::Bool(true), orig)
}
};
let min_opts = MinifyOptions {
@ -980,7 +990,7 @@ impl Compiler {
opts.output_path.clone().map(From::from),
opts.inline_sources_content,
target,
SourceMapsConfig::Bool(opts.source_map),
source_map,
&source_map_names,
orig.as_ref(),
true,