mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/config): Add jsc.output.charset
(#4708)
This commit is contained in:
parent
494343456d
commit
bf5ba28471
@ -633,6 +633,7 @@ impl Options {
|
||||
comments: comments.cloned(),
|
||||
preserve_comments,
|
||||
emit_source_map_columns: cfg.emit_source_map_columns.into_bool(),
|
||||
output: cfg.jsc.output,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1099,6 +1100,8 @@ pub struct BuiltInput<P: swc_ecma_visit::Fold> {
|
||||
|
||||
pub inline_sources_content: bool,
|
||||
pub emit_source_map_columns: bool,
|
||||
|
||||
pub output: JscOutputConfig,
|
||||
}
|
||||
|
||||
/// `jsc` in `.swcrc`.
|
||||
@ -1143,6 +1146,31 @@ pub struct JscConfig {
|
||||
|
||||
#[serde(default)]
|
||||
pub preserve_all_comments: BoolConfig<false>,
|
||||
|
||||
#[serde(default)]
|
||||
pub output: JscOutputConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, Merge)]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
pub struct JscOutputConfig {
|
||||
#[serde(default)]
|
||||
pub charset: Option<OutputCharset>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
pub enum OutputCharset {
|
||||
#[serde(rename = "utf8")]
|
||||
Utf8,
|
||||
#[serde(rename = "ascii")]
|
||||
Ascii,
|
||||
}
|
||||
|
||||
impl Default for OutputCharset {
|
||||
fn default() -> Self {
|
||||
OutputCharset::Utf8
|
||||
}
|
||||
}
|
||||
|
||||
/// `jsc.experimental` in `.swcrc`
|
||||
|
@ -121,7 +121,7 @@ use std::{
|
||||
use anyhow::{bail, Context, Error};
|
||||
use atoms::JsWord;
|
||||
use common::{collections::AHashMap, comments::SingleThreadedComments, errors::HANDLER};
|
||||
use config::{IsModule, JsMinifyCommentOption, JsMinifyOptions};
|
||||
use config::{IsModule, JsMinifyCommentOption, JsMinifyOptions, OutputCharset};
|
||||
use json_comments::StripComments;
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::Serialize;
|
||||
@ -884,6 +884,7 @@ impl Compiler {
|
||||
inline_sources_content: config.inline_sources_content,
|
||||
comments: config.comments,
|
||||
emit_source_map_columns: config.emit_source_map_columns,
|
||||
output: config.output,
|
||||
};
|
||||
|
||||
let orig = if config.source_maps.enabled() {
|
||||
@ -1129,7 +1130,11 @@ impl Compiler {
|
||||
config.minify,
|
||||
config.comments.as_ref().map(|v| v as _),
|
||||
config.emit_source_map_columns,
|
||||
false,
|
||||
config
|
||||
.output
|
||||
.charset
|
||||
.map(|v| matches!(v, OutputCharset::Ascii))
|
||||
.unwrap_or(false),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
8
crates/swc/tests/fixture/issues-4xxx/4697/1/input/.swcrc
Normal file
8
crates/swc/tests/fixture/issues-4xxx/4697/1/input/.swcrc
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"jsc": {
|
||||
"target": "es2021",
|
||||
"output": {
|
||||
"charset": "ascii"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
const foo = "❤️";
|
@ -0,0 +1 @@
|
||||
const foo = "\u2764\uFE0F";
|
5
crates/swc/tests/fixture/issues-4xxx/4697/2/input/.swcrc
Normal file
5
crates/swc/tests/fixture/issues-4xxx/4697/2/input/.swcrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"jsc": {
|
||||
"target": "es2021"
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
const foo = "❤️";
|
@ -0,0 +1 @@
|
||||
const foo = "❤️";
|
@ -755,6 +755,7 @@ fn should_visit() {
|
||||
inline_sources_content: config.inline_sources_content,
|
||||
comments: config.comments,
|
||||
emit_source_map_columns: config.emit_source_map_columns,
|
||||
output: config.output,
|
||||
};
|
||||
|
||||
if config.minify {
|
||||
|
@ -143,13 +143,9 @@ fn shopify_2_same_opt() {
|
||||
target: Some(EsVersion::Es5),
|
||||
loose: false.into(),
|
||||
keep_class_names: false.into(),
|
||||
base_url: Default::default(),
|
||||
paths: Default::default(),
|
||||
minify: None,
|
||||
experimental: Default::default(),
|
||||
lints: Default::default(),
|
||||
assumptions: Default::default(),
|
||||
preserve_all_comments: false.into(),
|
||||
..Default::default()
|
||||
},
|
||||
module: None,
|
||||
minify: false.into(),
|
||||
|
Loading…
Reference in New Issue
Block a user