feat(codegen): print readonly keyword for TSIndexSignature (#3791)

This commit is contained in:
Dunqing 2024-06-20 10:13:50 +00:00
parent 7d47fc3fcc
commit 2821e0e307
3 changed files with 16 additions and 2 deletions

View file

@ -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'[');
@ -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 {

View file

@ -0,0 +1,4 @@
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
? Object.freeze({})
: {}
export const EMPTY_ARR: readonly never[] = __DEV__ ? Object.freeze([]) : []

View file

@ -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)[];