kristoff-it / superhtml

HTML Language Server & Templating Language Library
MIT License
172 stars 11 forks source link

Leave AST with errors unformatted #1

Closed Arnau478 closed 2 months ago

Arnau478 commented 2 months ago

Trying to format an AST with errors resulted in an assertion failure. This fix makes it so that it returns the unchanged source.

With this, some failing unit tests on src/html/Ast.zig work as intended.

kristoff-it commented 2 months ago

Considering that formatting the AST has a side effect (writes to a stream), I think it's better to consider it a programming error to try to format an AST that contains errors. Sure, returning the current bytes is not wrong, but if we tempt programmers by not forcing them to check errors first, they will inadvertently (or purposefully) just use the formatting call as a "noop" that might actually be expensive (eg in an LSP setting it means sending the full document back to the editor, which might also trigger a reparsing job in turn).