From fe901bf3f6da4ba9fd3cda73845cbea983d07d82 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Sun, 15 Oct 2023 23:05:42 -0700 Subject: [PATCH] [ast][lir] Fix late init declaration pretty printing --- crates/samlang-core/src/ast/lir.rs | 2 +- crates/samlang-core/src/ast/lir_tests.rs | 2 +- crates/samlang-core/src/compiler/lir_lowering.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/samlang-core/src/ast/lir.rs b/crates/samlang-core/src/ast/lir.rs index d55cd8af..cf8092c5 100644 --- a/crates/samlang-core/src/ast/lir.rs +++ b/crates/samlang-core/src/ast/lir.rs @@ -434,7 +434,7 @@ impl Statement { collector.push_str(name.as_str(heap)); collector.push_str(": "); type_.pretty_print(collector, heap, table); - collector.push_str("undefined as any;\n"); + collector.push_str(" = undefined as any;\n"); } Statement::LateInitAssignment { name, assigned_expression } => { Self::append_spaces(collector, level); diff --git a/crates/samlang-core/src/ast/lir_tests.rs b/crates/samlang-core/src/ast/lir_tests.rs index 60648ace..c0f9e5df 100644 --- a/crates/samlang-core/src/ast/lir_tests.rs +++ b/crates/samlang-core/src/ast/lir_tests.rs @@ -272,7 +272,7 @@ function __$f(v1: () => number): number {{ let f: number = big[0]; 0[0] = 0; let c = 0 as unknown as number; - let c: numberundefined as any; + let c: number = undefined as any; c = 0; break; bar = b2; diff --git a/crates/samlang-core/src/compiler/lir_lowering.rs b/crates/samlang-core/src/compiler/lir_lowering.rs index 0fa627a0..85a76299 100644 --- a/crates/samlang-core/src/compiler/lir_lowering.rs +++ b/crates/samlang-core/src/compiler/lir_lowering.rs @@ -1123,7 +1123,7 @@ function __$compiled_program_main(): number {{ let cast = 0 as unknown as number; finalV2 = 0; }} else {{ - let cast: numberundefined as any; + let cast: number = undefined as any; cast = 0; finalV2 = 0; }}