@@ -171,6 +171,16 @@ where
171171 }
172172}
173173
174+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
175+ pub enum Source {
176+ /// Omit the source code.
177+ Omitted ,
178+ /// Compress the source code.
179+ Compressed ,
180+ /// Include source code but don't compress it.
181+ Uncompressed ,
182+ }
183+
174184/// Code generation option group.
175185/// This group gets configured from the [`CodegenOption`] enum.
176186//
@@ -180,8 +190,7 @@ where
180190pub struct CodegenOptionGroup {
181191 pub dynamic : bool ,
182192 pub wit : WitOptions ,
183- pub source : bool ,
184- pub source_compression : bool ,
193+ pub source : Source ,
185194 pub plugin : Option < PathBuf > ,
186195}
187196
@@ -190,8 +199,7 @@ impl Default for CodegenOptionGroup {
190199 Self {
191200 dynamic : false ,
192201 wit : WitOptions :: default ( ) ,
193- source : true ,
194- source_compression : true ,
202+ source : Source :: Compressed ,
195203 plugin : None ,
196204 }
197205 }
@@ -209,14 +217,12 @@ option_group! {
209217 /// Optional WIT world name for WIT file. Must be specified if WIT is
210218 /// file path is specified.
211219 WitWorld ( String ) ,
212- /// Embed the JavaScript source in a custom section in the generated
213- /// WebAssembly module.
214- Source ( bool ) ,
215- /// Enable source code compression, which generates smaller WebAssembly
216- /// files at the cost of increased compile time. This option has no effect
217- /// if the `source` shouldn't be embedded in the generated WebAssembly
218- /// module.
219- SourceCompression ( bool ) ,
220+ /// How to embed the JavaScript source in a custom section in the generated
221+ /// WebAssembly module. Options are `omitted`, `compressed`, and
222+ /// `uncompressed`. `compressed` enables source code compression which
223+ /// generates smaller WebAssembly files at the cost of increased compile
224+ /// time.
225+ Source ( Source ) ,
220226 /// Optional path to Javy plugin Wasm module. Required for dynamically
221227 /// linked modules. JavaScript config options are also not supported when
222228 /// using this parameter.
@@ -236,7 +242,6 @@ impl TryFrom<Vec<GroupOption<CodegenOption>>> for CodegenOptionGroup {
236242 let mut wit_specified = false ;
237243 let mut wit_world_specified = false ;
238244 let mut source_specified = false ;
239- let mut source_compression_specified = false ;
240245 let mut plugin_specified = false ;
241246
242247 for option in value. iter ( ) . flat_map ( |i| i. 0 . iter ( ) ) {
@@ -262,20 +267,13 @@ impl TryFrom<Vec<GroupOption<CodegenOption>>> for CodegenOptionGroup {
262267 wit_world = Some ( world) ;
263268 wit_world_specified = true ;
264269 }
265- CodegenOption :: Source ( enabled ) => {
270+ CodegenOption :: Source ( source ) => {
266271 if source_specified {
267272 bail ! ( "source can only be specified once" ) ;
268273 }
269- options. source = * enabled ;
274+ options. source = * source ;
270275 source_specified = true ;
271276 }
272- CodegenOption :: SourceCompression ( enabled) => {
273- if source_compression_specified {
274- bail ! ( "source-compression can only be specified once" ) ;
275- }
276- options. source_compression = * enabled;
277- source_compression_specified = true ;
278- }
279277 CodegenOption :: Plugin ( path) => {
280278 if plugin_specified {
281279 bail ! ( "plugin can only be specified once" ) ;
@@ -422,7 +420,7 @@ mod tests {
422420 use std:: path:: PathBuf ;
423421
424422 use crate :: {
425- commands:: { JsGroupOption , JsGroupValue } ,
423+ commands:: { JsGroupOption , JsGroupValue , Source } ,
426424 js_config:: JsConfig ,
427425 plugin:: PLUGIN_MODULE ,
428426 CliPlugin , Plugin , PluginKind ,
@@ -536,19 +534,21 @@ mod tests {
536534
537535 assert_eq ! ( group, expected) ;
538536
539- let raw = vec ! [ GroupOption ( vec![ CodegenOption :: Source ( false ) ] ) ] ;
537+ let raw = vec ! [ GroupOption ( vec![ CodegenOption :: Source ( Source :: Omitted ) ] ) ] ;
540538 let group: CodegenOptionGroup = raw. try_into ( ) ?;
541539 let expected = CodegenOptionGroup {
542- source : false ,
540+ source : Source :: Omitted ,
543541 ..Default :: default ( )
544542 } ;
545543
546544 assert_eq ! ( group, expected) ;
547545
548- let raw = vec ! [ GroupOption ( vec![ CodegenOption :: SourceCompression ( false ) ] ) ] ;
546+ let raw = vec ! [ GroupOption ( vec![ CodegenOption :: Source (
547+ Source :: Uncompressed ,
548+ ) ] ) ] ;
549549 let group: CodegenOptionGroup = raw. try_into ( ) ?;
550550 let expected = CodegenOptionGroup {
551- source_compression : false ,
551+ source : Source :: Uncompressed ,
552552 ..Default :: default ( )
553553 } ;
554554
@@ -597,13 +597,13 @@ mod tests {
597597 ) ;
598598
599599 let raw = vec ! [ GroupOption ( vec![
600- CodegenOption :: SourceCompression ( true ) ,
601- CodegenOption :: SourceCompression ( false ) ,
600+ CodegenOption :: Source ( Source :: Compressed ) ,
601+ CodegenOption :: Source ( Source :: Uncompressed ) ,
602602 ] ) ] ;
603603 let result: Result < CodegenOptionGroup , Error > = raw. try_into ( ) ;
604604 assert_eq ! (
605605 result. err( ) . unwrap( ) . to_string( ) ,
606- "source-compression can only be specified once"
606+ "source can only be specified once"
607607 ) ;
608608
609609 let raw = vec ! [ GroupOption ( vec![
0 commit comments