From 1fe164b80f0dcde15a6ed9bc3b9db58f7a479358 Mon Sep 17 00:00:00 2001 From: Veera <32646674+veera-sivarajan@users.noreply.github.com> Date: Mon, 4 Dec 2023 01:52:06 -0500 Subject: [PATCH] Fix a Parser Idempotency Issue (#3172) * Fix a Parser Idempotency Issue This PR fixes #3133 by correctly implementing `ToIndentedString` for `with` statement. It also replaces the existing `ToInternedString` implementation because it is implemented for all types implementing `ToIndentedString` in `boa_interner/src/lib.rs`. * Add test for with statement formatting --------- Co-authored-by: raskad <32105367+raskad@users.noreply.github.com> --- boa_ast/src/statement/with.rs | 12 ++++++------ boa_parser/src/parser/tests/format/statement.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/boa_ast/src/statement/with.rs b/boa_ast/src/statement/with.rs index 82b969099b..4aad4e2659 100644 --- a/boa_ast/src/statement/with.rs +++ b/boa_ast/src/statement/with.rs @@ -4,7 +4,7 @@ use crate::{ try_break, visitor::{VisitWith, Visitor, VisitorMut}, }; -use boa_interner::{Interner, ToInternedString}; +use boa_interner::{Interner, ToIndentedString, ToInternedString}; use core::ops::ControlFlow; /// The `with` statement extends the scope chain for a statement. @@ -52,12 +52,12 @@ impl From for Statement { } } -impl ToInternedString for With { - fn to_interned_string(&self, interner: &Interner) -> String { +impl ToIndentedString for With { + fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String { format!( - "with ({}) {{{}}}", - self.expression.to_interned_string(interner), - self.statement.to_interned_string(interner) + "with ({}) {}", + self.expression().to_interned_string(interner), + self.statement().to_indented_string(interner, indentation) ) } } diff --git a/boa_parser/src/parser/tests/format/statement.rs b/boa_parser/src/parser/tests/format/statement.rs index 8e5ff43c5b..4854e2a041 100644 --- a/boa_parser/src/parser/tests/format/statement.rs +++ b/boa_parser/src/parser/tests/format/statement.rs @@ -122,3 +122,15 @@ fn switch() { "#, ); } + +#[test] +fn with() { + test_formatting( + r#" + with (this) { + { + } + } + "#, + ); +}