+
Skip to content

feat(parse/astro): add astro parser / formatter #6701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

emilienbidet
Copy link

@emilienbidet emilienbidet commented Jul 4, 2025

Summary

This PR adds initial Astro parser and formatter support to Biome, providing a foundation for handling .astro files. The implementation was generated by Claude Code and inspired by the prettier-plugin-astro repository to help quick-start Astro support in Biome.

Motivation

I really love using Biome for its speed and comprehensive tooling, and I would like to use it with Astro projects. This contribution aims to bridge that gap by providing basic Astro file support.

What's been done

  • Added Astro syntax parsing capabilities
  • Implemented basic Astro file formatting
  • Created foundational structure for Astro language support
  • Based implementation on patterns from prettier-plugin-astro for compatibility

Test plan

  • Test Astro file parsing with various syntax patterns
  • Test Astro file formatting maintains correct structure
  • Verify integration with existing Biome toolchain
  • Run existing test suite to ensure no regressions

Notes

This is an initial implementation to get Astro support started. Further refinements and feature additions can be made in follow-up PRs based on community feedback and usage patterns.

🤖 Generated with Claude Code

Copy link

changeset-bot bot commented Jul 4, 2025

⚠️ No Changeset found

Latest commit: 19992d1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added A-Project Area: project A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools labels Jul 4, 2025
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing immediately sticks out to me as particularly problematic, from a code perspective. This PR does adequately follow the project's patterns and conventions.

However, I'm not sure this is the direction we want to go architecturally. This PR effectively seeks to duplicate the effort of the HTML parser and formatter. We do want to be able to reuse that logic, because its a lot of work to maintain multiple implementations of effectively the same thing.

@ematipico
Copy link
Member

@dyc3 is right, and in fact we want to extend the HTML parser, and handle vue/svelte/astro files.

In fact, in this PR we already implemented the parsing of Astro frontmatter in Astro files #6689

That's the direction we're taking

emilienbidet and others added 6 commits July 6, 2025 18:14
Add Astro-specific syntax nodes to HTML grammar:
- HtmlAstroExpression for {expr} syntax
- HtmlAstroShorthandAttribute for {name} syntax
- HtmlAstroSpreadAttribute for {...props} syntax
- HtmlAstroExpressionAttribute for name={expr} syntax
- HtmlAstroTemplateLiteralAttribute for name={`template`} syntax
- HtmlAstroFragment for Astro fragment syntax

This extends the HTML parser to handle Astro expressions and attributes
as requested by maintainers, avoiding code duplication by reusing the
HTML parser infrastructure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Regenerate HTML syntax files with new Astro syntax nodes:
- Add Astro syntax kinds to HtmlSyntaxKind enum
- Add missing HTML_JS_CONTENT and HTML_TEMPLATE_LITERAL_CONTENT kinds
- Update T\! macro to support new tokens: { } ` ...
- Generate AST node structs for all Astro syntax nodes

These generated files enable the parser to create proper AST nodes
for Astro expressions and attributes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add support for Astro-specific tokens in HTML lexer:
- Support { } tokens in Regular and OutsideTag contexts
- Support backtick (`) tokens for template literals
- Add consume_dot_or_dot_dot_dot() for spread operator (...)
- Tokens are properly recognized in both tag and content contexts

This enables the lexer to tokenize Astro expressions like {name},
{...props}, and {`template`} while maintaining HTML compatibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive parsing support for Astro syntax:

- parse_astro_expression() for {expr} in content
- parse_astro_shorthand_attribute() for {name} attributes
- parse_astro_spread_attribute() for {...props} attributes
- parse_astro_expression_attribute() for name={expr}
- parse_astro_template_literal_attribute() for name={`template`}
- Component vs element detection logic (PascalCase detection)

Integrate parsing functions into ElementList and AttributeList:
- ElementList handles Astro expressions in content
- AttributeList handles all Astro attribute types
- Enhanced attribute_initializer to support Astro expressions

This provides complete parsing of Astro's unique syntax while
extending the existing HTML parser infrastructure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Generate and update HTML formatter for Astro syntax nodes:

- Run codegen to generate formatter files for all Astro nodes
- Update any/attribute.rs and any/element.rs to handle Astro cases
- Update attribute_list.rs to format Astro attributes
- All Astro formatters use format_verbatim_node() for now

This ensures that Astro syntax can be formatted without compilation
errors, providing basic formatting support while maintaining the
structure of Astro expressions and attributes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add lexer tests covering all Astro syntax features:

- astro_expression_simple: Basic {name} expressions
- astro_spread_attribute: Spread syntax {...props}
- astro_expression_attribute: Attribute expressions name={value}
- astro_template_literal: Template literals with backticks
- astro_frontmatter_fence: Frontmatter --- blocks
- astro_component_tag: PascalCase component recognition
- astro_complex_expression: Complex JavaScript expressions
- astro_mixed_attributes: Mixed HTML and Astro attributes

Tests validate proper tokenization in various HTML contexts
and ensure lexer correctly identifies Astro-specific tokens
while maintaining HTML compatibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added the L-HTML Language: HTML label Jul 6, 2025
@emilienbidet emilienbidet requested a review from dyc3 July 6, 2025 16:29
Copy link

codspeed-hq bot commented Jul 6, 2025

CodSpeed Performance Report

Merging #6701 will not alter performance

Comparing emilienbidet:main (19992d1) with main (52e36ae)

Summary

✅ 114 untouched benchmarks

emilienbidet and others added 2 commits July 6, 2025 18:38
Regenerate the HTML formatter generated.rs file to include complete
AsFormat trait implementations for all Astro syntax nodes.

This fixes the CI build errors where the formatter couldn't find
format() methods for Astro nodes. The codegen command now properly
generates all necessary trait implementations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rser

Remove standalone Astro parser infrastructure and fully integrate
Astro support into the HTML parser as requested by maintainers:

- Remove biome_astro_parser, biome_astro_syntax, biome_astro_factory, biome_astro_formatter
- Update service handlers to use HTML parser for Astro files
- Update factory files after grammar regeneration
- Remove Astro configuration from separate module

This completes the transition from duplicate standalone parsers
to extending the HTML parser infrastructure, addressing maintainer
feedback to avoid code duplication.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS L-JSON Language: JSON and super languages L-Grit Language: GritQL labels Jul 6, 2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this got in here, but this file needs to be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

Comment on lines +157 to +163
// ==================================
// Astro-specific syntax nodes
// ==================================

// Astro expressions: {expression}
HtmlAstroExpression =
l_curly: '{'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these, I think it would be better to prefix them with just Astro instead of HtmlAstro. This would be more consistent with how js and ts nodes are named.

Comment on lines +70 to +73
formatter: Some(html::formatter_enabled),
search: Some(html::search_enabled),
assist: Some(html::assist_enabled),
linter: Some(html::linter_enabled),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's refrain from making public facing changes for now. We haven't made enough progress to do that yet -- if we were to merge this we would regress in functionality.

@@ -81,10 +90,11 @@ fn parse_element(p: &mut HtmlParser) -> ParsedSyntax {

p.bump(T![<]);
let opening_tag_name = p.cur_text().to_string();
let should_be_self_closing = VOID_ELEMENTS
let is_component = is_astro_component(&opening_tag_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to have astro specific logic gated behind a parser option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of new logic here that is not covered by snapshot tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter A-Parser Area: parser A-Project Area: project A-Tooling Area: internal tools L-CSS Language: CSS L-Grit Language: GritQL L-HTML Language: HTML L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载