Skip to content

Commit

Permalink
feat(codegen): print readonly keyword for TSIndexSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jun 20, 2024
1 parent 07fb853 commit 30adc9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3025,8 +3025,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSSignature<'a> {
Self::TSIndexSignature(signature) => signature.gen(p, ctx),
Self::TSPropertySignature(signature) => {
if signature.readonly {
p.print_str(b"readonly");
p.print_hard_space();
p.print_str(b"readonly ");
}
if signature.computed {
p.print(b'[');
Expand Down Expand Up @@ -3191,6 +3190,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSTypeParameterInstantiation<'a> {

impl<'a, const MINIFY: bool> Gen<MINIFY> for TSIndexSignature<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
if self.readonly {
p.print_str(b"readonly ");
}
p.print_str(b"[");
for (index, parameter) in self.parameters.iter().enumerate() {
if index != 0 {
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_isolated_declarations/tests/fixtures/readonly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
? Object.freeze({})
: {}
export const EMPTY_ARR: readonly never[] = __DEV__ ? Object.freeze([]) : []
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/readonly.ts
---
==================== .D.TS ====================

export declare const EMPTY_OBJ: {readonly [key: string]: any};
export declare const EMPTY_ARR: readonly (never)[];

0 comments on commit 30adc9e

Please sign in to comment.