Browse Source

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>
pull/3498/head
Veera 1 year ago committed by GitHub
parent
commit
1fe164b80f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      boa_ast/src/statement/with.rs
  2. 12
      boa_parser/src/parser/tests/format/statement.rs

12
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<With> 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)
)
}
}

12
boa_parser/src/parser/tests/format/statement.rs

@ -122,3 +122,15 @@ fn switch() {
"#,
);
}
#[test]
fn with() {
test_formatting(
r#"
with (this) {
{
}
}
"#,
);
}

Loading…
Cancel
Save