fix(linter): skip linting astro scripts with non JS script types#21954
Open
fix(linter): skip linting astro scripts with non JS script types#21954
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect linting/parsing of non-JavaScript <script> tags in .astro files (e.g., type="importmap"), and reduces duplicated tag-attribute parsing logic by reusing a shared attribute parser between Astro and Svelte partial loaders.
Changes:
- Add shared
<script>attribute parsing utilities (AttributeValue,find_attribute) to the partial loader module. - Refactor Svelte partial loader to reuse the shared attribute parser.
- Update Astro partial loader to (a) use the robust closing-angle finder and (b) skip
<script>blocks whosetypeis not a JavaScript type; add tests for the new behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/oxc_linter/src/loader/partial_loader/svelte.rs | Switches Svelte to reuse the shared <script> attribute parser (removes local duplicate implementation). |
| crates/oxc_linter/src/loader/partial_loader/mod.rs | Introduces shared AttributeValue + find_attribute helpers for parsing <script> tag attributes. |
| crates/oxc_linter/src/loader/partial_loader/astro.rs | Uses find_script_closing_angle, adds JS type filtering logic, and adds tests to ensure non-JS script types are skipped. |
| js_start = pointer; | ||
|
|
||
| // check for the / of a self closing script tag | ||
| if self.source_text.chars().nth(js_start - 2) == Some('/') { |
| AttributeValue::Empty | ||
| }; | ||
|
|
||
| if name == target { |
Comment on lines
+120
to
+131
| fn is_javascript_script(content: &str) -> bool { | ||
| match find_attribute(content, "type") { | ||
| Some(AttributeValue::Empty) | None => true, | ||
| Some(AttributeValue::Value(value)) => matches!( | ||
| value.trim().to_ascii_lowercase().as_str(), | ||
| "" | "module" | ||
| | "text/javascript" | ||
| | "application/javascript" | ||
| | "text/ecmascript" | ||
| | "application/ecmascript" | ||
| ), | ||
| } |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #21942
Astro script tags with non-JavaScript type values are now skipped by the partial loader, so import maps and JSON scripts are not parsed as TypeScript. The shared script attribute parser is reused with Svelte to avoid duplicating tag parsing logic.