-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this 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.
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>
CodSpeed Performance ReportMerging #6701 will not alter performanceComparing Summary
|
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>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove
// ================================== | ||
// Astro-specific syntax nodes | ||
// ================================== | ||
|
||
// Astro expressions: {expression} | ||
HtmlAstroExpression = | ||
l_curly: '{' |
There was a problem hiding this comment.
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.
formatter: Some(html::formatter_enabled), | ||
search: Some(html::search_enabled), | ||
assist: Some(html::assist_enabled), | ||
linter: Some(html::linter_enabled), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 theprettier-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
prettier-plugin-astro
for compatibilityTest plan
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