Depends on what the formatter does when the code is syntactically invalid in the first place. It could just error out, but that might be annoying if the error is in an unrelated part of the file.
So a formatter might opt to format on a best-effort basis even in the presence of syntax problems, but then there's the risk of creating different semantics than intended (once the syntax problem is fixed).