Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl<'a> Codegen<'a> {
pub fn build(mut self, program: &Program<'a>) -> CodegenReturn {
self.quote = if self.options.single_quote { Quote::Single } else { Quote::Double };
self.source_text = Some(program.source_text);
self.indent = self.options.initial_indent;
self.code.reserve(program.source_text.len());
self.build_comments(&program.comments);
if let Some(path) = &self.options.source_map_path {
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_codegen/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub struct CodegenOptions {
///
/// Default is `1`.
pub indent_width: usize,

/// Initial indentation level for generated code.
///
/// Default is `0`.
pub initial_indent: u32,
}

impl Default for CodegenOptions {
Expand All @@ -49,6 +54,7 @@ impl Default for CodegenOptions {
source_map_path: None,
indent_char: IndentChar::default(),
indent_width: DEFAULT_INDENT_WIDTH,
initial_indent: 0,
}
}
}
Expand All @@ -63,6 +69,7 @@ impl CodegenOptions {
source_map_path: None,
indent_char: IndentChar::default(),
indent_width: DEFAULT_INDENT_WIDTH,
initial_indent: 0,
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_codegen/tests/integration/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,11 @@ fn indentation() {
..CodegenOptions::default()
},
);

// Test initial indent with 1
test_options(
"let foo = 1;",
"\tlet foo = 1;\n",
CodegenOptions { initial_indent: 1, ..CodegenOptions::default() },
);
}
Loading