Skip to content

Commit 6b3ae00

Browse files
authored
feat(es/transforms): Expose tsEnumIsMutable to JS (#10716)
1 parent c9eee0b commit 6b3ae00

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

.changeset/rich-phones-explode.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc: patch
4+
---
5+
6+
feat: expose tsEnumIsMutable to js API

crates/swc/src/config/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ impl Options {
526526
};
527527

528528
let verbatim_module_syntax = transform.verbatim_module_syntax.into_bool();
529+
let ts_enum_is_mutable = transform.ts_enum_is_mutable.into_bool();
529530

530531
let charset = cfg.jsc.output.charset.or_else(|| {
531532
if js_minify.as_ref()?.format.ascii_only {
@@ -777,6 +778,7 @@ impl Options {
777778
import_export_assign_config,
778779
verbatim_module_syntax,
779780
native_class_properties,
781+
ts_enum_is_mutable,
780782
..Default::default()
781783
};
782784

@@ -1557,6 +1559,9 @@ pub struct TransformConfig {
15571559

15581560
#[serde(default)]
15591561
pub decorator_version: Option<DecoratorVersion>,
1562+
1563+
#[serde(default)]
1564+
pub ts_enum_is_mutable: BoolConfig<false>,
15601565
}
15611566

15621567
#[derive(Debug, Default, Clone, Serialize, Deserialize, Merge)]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript"
5+
},
6+
"transform": {
7+
"tsEnumIsMutable": true
8+
}
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum Foo {
2+
hello = 42,
3+
}
4+
5+
Foo.hello = 0;
6+
7+
console.log(Foo.hello);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var Foo = /*#__PURE__*/ function(Foo) {
2+
Foo[Foo["hello"] = 42] = "hello";
3+
return Foo;
4+
}(Foo || {});
5+
Foo.hello = 0;
6+
console.log(Foo.hello);

packages/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ export interface TransformConfig {
879879
*/
880880
verbatimModuleSyntax?: boolean;
881881

882+
tsEnumIsMutable?: boolean;
882883
}
883884

884885
export interface ReactConfig {

0 commit comments

Comments
 (0)