Skip to content

Commit

Permalink
feat: support lang="tsx" for vue sfc (#2788)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 authored May 10, 2024
1 parent 49cace8 commit 12cbf02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- biome check .
+ biome check # You can run the command without the path
```

### Configuration

### Editors
Expand All @@ -40,6 +40,9 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Parser

#### Enhancements

- `lang="tsx"` is now supported in Vue Single File Components. [#2765](https://github.com/biomejs/biome/issues/2765) Contributed by @dyc3

## 1.7.3 (2024-05-06)

Expand Down
11 changes: 6 additions & 5 deletions crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,11 @@ pub(crate) fn parse_lang_from_script_opening_tag(script_opening_tag: &str) -> La
let attribute_value = lang_attribute.initializer()?.value().ok()?;
let attribute_inner_string =
attribute_value.as_jsx_string()?.inner_string_text().ok()?;
if attribute_inner_string.text() == "ts" {
Some(Language::TypeScript {
match attribute_inner_string.text() {
"ts" | "tsx" => Some(Language::TypeScript {
definition_file: false,
})
} else {
None
}),
_ => None,
}
})
})
Expand Down Expand Up @@ -580,11 +579,13 @@ fn test_svelte_script_lang() {
fn test_vue_script_lang() {
const VUE_JS_SCRIPT_OPENING_TAG: &str = r#"<script>"#;
const VUE_TS_SCRIPT_OPENING_TAG: &str = r#"<script lang="ts">"#;
const VUE_TSX_SCRIPT_OPENING_TAG: &str = r#"<script lang="tsx">"#;
const VUE_SETUP_JS_SCRIPT_OPENING_TAG: &str = r#"<script setup>"#;
const VUE_SETUP_TS_SCRIPT_OPENING_TAG: &str = r#"<script setup lang="ts">"#;

assert!(parse_lang_from_script_opening_tag(VUE_JS_SCRIPT_OPENING_TAG).is_javascript());
assert!(parse_lang_from_script_opening_tag(VUE_TS_SCRIPT_OPENING_TAG).is_typescript());
assert!(parse_lang_from_script_opening_tag(VUE_TSX_SCRIPT_OPENING_TAG).is_typescript());
assert!(parse_lang_from_script_opening_tag(VUE_SETUP_JS_SCRIPT_OPENING_TAG).is_javascript());
assert!(parse_lang_from_script_opening_tag(VUE_SETUP_TS_SCRIPT_OPENING_TAG).is_typescript());
}

0 comments on commit 12cbf02

Please sign in to comment.