Skip to content

Commit

Permalink
Rename to ts_enum_is_mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 13, 2023
1 parent 984edca commit 1eda4f6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
30 changes: 7 additions & 23 deletions crates/swc_ecma_transforms_typescript/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Config {
#[serde(default)]
pub verbatim_module_syntax: bool,
Expand All @@ -19,25 +19,13 @@ pub struct Config {
#[serde(default)]
pub import_export_assign_config: TsImportExportAssignConfig,

/// An optimization that inlines TS enum member values within
/// the same module. This assumes the enum member values are
/// never modified.
/// Disables an optimization that inlines TS enum member values
/// within the same module that assumes the enum member values
/// are never modified.
///
/// Defaults to true.
#[serde(default = "true_by_default")]
pub ts_enum_is_readonly: bool,
}

impl Default for Config {
fn default() -> Self {
Self {
verbatim_module_syntax: false,
import_not_used_as_values: Default::default(),
no_empty_export: false,
import_export_assign_config: Default::default(),
ts_enum_is_readonly: true,
}
}
/// Defaults to false.
#[serde(default)]
pub ts_enum_is_mutable: bool,
}

#[derive(Debug, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -90,7 +78,3 @@ pub enum ImportsNotUsedAsValues {

#[deprecated = "ImportNotUsedAsValues is renamed to ImportsNotUsedAsValues"]
pub type ImportNotUsedAsValues = ImportsNotUsedAsValues;

const fn true_by_default() -> bool {
true
}
8 changes: 4 additions & 4 deletions crates/swc_ecma_transforms_typescript/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) struct Transform {
top_level_ctxt: SyntaxContext,

import_export_assign_config: TsImportExportAssignConfig,
ts_enum_is_readonly: bool,
ts_enum_is_mutable: bool,
verbatim_module_syntax: bool,

namespace_id: Option<Id>,
Expand All @@ -65,14 +65,14 @@ pub(crate) struct Transform {
pub fn transform(
top_level_mark: Mark,
import_export_assign_config: TsImportExportAssignConfig,
ts_enum_is_readonly: bool,
ts_enum_is_mutable: bool,
verbatim_module_syntax: bool,
) -> impl Fold + VisitMut {
as_folder(Transform {
top_level_mark,
top_level_ctxt: SyntaxContext::empty().apply_mark(top_level_mark),
import_export_assign_config,
ts_enum_is_readonly,
ts_enum_is_mutable,
verbatim_module_syntax,
..Default::default()
})
Expand All @@ -84,7 +84,7 @@ impl VisitMut for Transform {
fn visit_mut_program(&mut self, n: &mut Program) {
n.visit_mut_children_with(self);

if self.ts_enum_is_readonly && !self.record.is_empty() {
if !self.ts_enum_is_mutable && !self.record.is_empty() {
let record = mem::take(&mut self.record);
n.visit_mut_children_with(&mut InlineEnum::new(record));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_typescript/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl VisitMut for TypeScript {
n.visit_mut_with(&mut transform(
self.top_level_mark,
self.config.import_export_assign_config,
self.config.ts_enum_is_readonly,
self.config.ts_enum_is_mutable,
self.config.verbatim_module_syntax,
));

Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_transforms_typescript/tests/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4557,13 +4557,13 @@ test!(
Syntax::Typescript(TsConfig::default()),
|_| tr_config(
Some(typescript::Config {
ts_enum_is_readonly: false,
ts_enum_is_mutable: true,
..Default::default()
}),
None,
true,
),
ts_enum_is_readonly_false,
ts_enum_is_mutable_true,
r#"
enum D {
A,
Expand Down

0 comments on commit 1eda4f6

Please sign in to comment.