Skip to content

A new compiler for Astro #1356

@Princesseuh

Description

@Princesseuh

Summary

Create a new compiler for Astro, without HTML correction, easier to maintain, more correct, and adopt it as the official Astro compiler going forward.

Background & Motivation

The Astro compiler turns .astro files into JavaScript modules, for Astro to then execute.

The current implementation, written in Go, has been serving us since Astro 0.21 After several years of production use, a few things have become clear:

  • Maintenance has stalled. The codebase is hard to onboard onto, and the team has not been successful in finding contributors (internal or external) who are both willing and able to maintain Go code. Issues sit open for long periods, because nobody on the core team is comfortable owning fixes there.
  • Proper architecture and tooling is needed. The Go compiler uses its own HTML parsing, does its TS understanding itself, has its own (although forked from esbuild) CSS parsing, etc. A lot of tooling now exists that we can rely on instead of owning ourselves, especially in the Rust ecosystem, reducing our surface area to cover ourselves and reducing bugs.
  • HTML correction has been a long-standing source of bugs. The behavior surprises users, makes debugging harder, and is increasingly out of step with how modern frameworks treat author-written markup.
  • JSX-style strictness is often more valuable than HTML's behavior. HTML is on purpose lenient with regards to unclosed tags and attributes, but the vast majority of the time this only results in broken or unexpected results in the browser.

Goals

  • Create a new official compiler for Astro.
  • Make the new compiler maintainable by the current team and approachable for new contributors.
  • Reach feature and behavior parity with the current Go compiler for everything that is not explicitly being dropped, so that existing Astro projects continue to build without needing changes in most cases.
  • Match or exceed the current compiler's performance on real-world Astro projects.
  • Run in every environment Astro itself supports today.
  • Supports semantically invalid HTML structures, but reject (what is commonly perceived as) syntactically invalid ones.

Non-Goals

  • HTML correction is intentionally being dropped. The new compiler will not silently rewrite author markup to be "valid HTML". Behavior changes from this will be documented as part of the migration, but reintroducing correction is out of scope.
  • Supporting syntactically invalid HTML. Unclosed tags like <div>Hello will now results in an error, like they would in JSX, so will unterminated attributes: <div class="Hello >World</div>
  • No new language features. This proposal is specifically about replacing the implementation, not about extending the .astro syntax. Any syntax-level changes are separate proposals.
  • TSX output. A compiler for Astro itself and a compiler for the TSX output needed by the language server has different requirements. As such, I propose to focus this new effort on what's needed for runtime, and consider more relevant and suited alternatives for the language-server down the line.
  • AST parity. The Go compiler returned its own AST format, completely different from other tools. As part of relying on existing libraries, we could now return a more standard AST.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Stage 2: Accepted Proposals, No RFC

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions