Conversation
|
a14544d to
86f6dff
Compare
WalkthroughAdds first‑class support for inline/template expressions by renaming JsExpressionSnipped→JsExpressionSnippet and introducing JsExpressionTemplateRoot; parser now parses Vue/Svelte/Astro template expressions as single-expression roots, with new diagnostics for template-expression errors. Formatter and generated code updated to match the renamed node and to format the new template-root. Linter/semantic updates: JsFileSource now exposes template-expression semantics, no_useless_lone_block_statements now uses file_source, and no_unused_variables consults embedded value references to avoid false positives. Tests for Astro, Svelte and Vue linting were added. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In
`@crates/biome_js_analyze/src/lint/complexity/no_useless_lone_block_statements.rs`:
- Line 147: Remove the stray dbg!(&statement); call in
no_useless_lone_block_statements.rs (the debug print that spams stderr during
lint runs); simply delete that dbg! invocation (or replace it with a proper
trace/log call if structured logging is needed) so the linter no longer emits
debug output for the `statement` variable.
- Around line 150-153: The JsExpressionStatement match arm is inverted: change
the condition on AnyJsStatement::JsExpressionStatement from
"!file_source.is_embedded_source()" to "file_source.is_embedded_source()" so
embedded sources are suppressed (treated as useful) while regular JS still flags
lone expression statements; update the match arm that currently reads
AnyJsStatement::JsExpressionStatement(_) => !file_source.is_embedded_source()
accordingly.
crates/biome_js_analyze/src/lint/complexity/no_useless_lone_block_statements.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/complexity/no_useless_lone_block_statements.rs
Show resolved
Hide resolved
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
dyc3
left a comment
There was a problem hiding this comment.
This does not fix the noUselessLoneBlockStatements issue. I think I know what's happening though.
Given this snippet:
<div {...props} transition:slide={{ duration }}>
{@render children?.()}
</div>{ duration } gets parsed as if its a full js doc:
JsModule {
bom_token: missing (optional),
interpreter_token: missing (optional),
directives: JsDirectiveList [],
items: JsModuleItemList [
JsBlockStatement {
l_curly_token: L_CURLY@0..2 "{" [] [Whitespace(" ")],
statements: JsStatementList [
JsExpressionStatement {
expression: JsIdentifierExpression {
name: JsReferenceIdentifier {
value_token: IDENT@2..11 "duration" [] [Whitespace(" ")],
},
},
semicolon_token: missing (optional),
},
],
r_curly_token: R_CURLY@11..12 "}" [] [],
},
],
eof_token: EOF@12..12 "" [] [],
}
If I make it a little different, { duration: 200 }, it thinks duration: is a label, and I get a bunch of false positives for noConfusingLabels.
I think the correct fix for this is to have some other entry point into the js parser to make it so that these get parsed as a JsObjectExpression (which is what it's supposed to be).
Yeah, good catch, I believe we so. |
|
@dyc3 I updated the description of the PR, because I changed completely how the feature should work. |
|
Going to merge this, but let me know if you have some feedback. The PR addresses the concerns |
Summary
Closes #8904
Closes #8903
In order to fix the issues, I had to rethink how JS snippets are parsed. Up until now, they were parsed as normal JS files, which turned out be incorrect, because things like
{{ duration: 400 }}were incorrectly parserd.It's safe to assume that JS snippets inside a HTML-ish language should be parsed as an expression, because they must return a value. Hence, I added a new root to the JS language, very much like the root we use for embedded templates. I decided to use a new root to avoid possible conflicts with the semantics and the possible evolution of the feature.
The code has been created via AI, and carefully steerred toward the correct implementation.
Test Plan
Added new tests.
I updated the parsing infra of the JS parser so that we can simulate snippets, using the suffix
.inline_expr..Docs
Not needed