mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 09:52:57 +03:00
fix(swc): Fix sourceMap
option of minify (#2380)
This commit is contained in:
parent
cf1235ece1
commit
486c689504
@ -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)]
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user