-
-
Notifications
You must be signed in to change notification settings - Fork 38
fix(canon): anchor prop-type errors at the attribute name #3205
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a0dab46
fix(canon): anchor prop-type errors at the attribute name
ubugeeei 665cf37
fix(deps): bump pinned hono, svgo and pin fast-uri, @hono/node-server…
ubugeeei 2658c27
fix(deps): restore native-binaries catalog pins in lockfile
ubugeeei 333afd4
test(canon): cover kebab-case attribute-name anchoring
ubugeeei e135f67
test(perf): anchor misskey LSP prop-type mismatch at attribute name
ubugeeei 429e432
test(vize): anchor check-server prop-type diagnostic at attribute name
ubugeeei 6bbbb09
fix(canon): repin attribute-name anchors and split prop sources
ubugeeei b64c16d
test(tooling): anchor lsp parent prop diagnostic at attribute name
ubugeeei e1e4d64
test(canon): cover multibyte attribute-name source offsets
ubugeeei e5519ec
test(tooling): guard :count lookup before computing prop range
ubugeeei 744bcae
style(canon): rustfmt multibyte prop-source test
ubugeeei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
3 changes: 2 additions & 1 deletion
3
...vize_canon__batch__type_checker__tests__batch_type_checker_cross_file_vue_prop_error.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
96 changes: 96 additions & 0 deletions
96
crates/vize_canon/src/virtual_ts/expressions/prop_sources.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| //! Authored source ranges and generated values for component prop checks. | ||
| //! | ||
| //! These helpers translate one passed prop into the pieces check emission | ||
| //! needs: the escaped or rewritten generated value, the authored | ||
| //! attribute-name range that anchors child prop-type errors (matching | ||
| //! vue-tsc), and the authored value range that anchors errors inside the | ||
| //! bound expression. | ||
|
|
||
| use super::component_props::ComponentPropSource; | ||
| use super::reserved_props::rewrite_reserved_template_prop; | ||
| use vize_carton::FxHashSet; | ||
| use vize_carton::String; | ||
| use vize_croquis::croquis::PassedProp; | ||
| use vize_croquis::drawer::strip_js_comments; | ||
|
|
||
| fn push_ts_string_literal(out: &mut String, value: &str) { | ||
| out.push('"'); | ||
| for ch in value.chars() { | ||
| match ch { | ||
| '\\' => out.push_str("\\\\"), | ||
| '"' => out.push_str("\\\""), | ||
| '\n' => out.push_str("\\n"), | ||
| '\r' => out.push_str("\\r"), | ||
| '\t' => out.push_str("\\t"), | ||
| _ => out.push(ch), | ||
| } | ||
| } | ||
| out.push('"'); | ||
| } | ||
|
|
||
| pub(super) fn generated_prop_value( | ||
| prop: &PassedProp, | ||
| template_prop_names: &FxHashSet<String>, | ||
| ) -> Option<String> { | ||
| if !prop.is_dynamic { | ||
| let mut value = String::default(); | ||
| if let Some(static_value) = prop.value.as_ref() { | ||
| push_ts_string_literal(&mut value, static_value.as_str()); | ||
| } else { | ||
| value.push_str("true"); | ||
| } | ||
| return Some(value); | ||
| } | ||
|
|
||
| let value = strip_js_comments(prop.value.as_ref()?.as_str()); | ||
| let trimmed_value = value.as_ref().trim(); | ||
| let rewritten_value = rewrite_reserved_template_prop(trimmed_value, template_prop_names); | ||
| Some(rewritten_value.as_ref().map_or_else( | ||
| || String::from(value.as_ref()), | ||
| |s| String::from(s.as_str()), | ||
| )) | ||
| } | ||
|
|
||
| pub(super) fn prop_value_source_range( | ||
| source_context: ComponentPropSource<'_>, | ||
| prop: &PassedProp, | ||
| ) -> Option<std::ops::Range<usize>> { | ||
| let source = source_context.template?; | ||
| let value = prop.value.as_ref()?.as_str(); | ||
| let prop_start = prop.start as usize; | ||
| let prop_end = prop.end as usize; | ||
| let raw_prop = source.get(prop_start..prop_end)?; | ||
| let relative_start = raw_prop.rfind(value)?; | ||
| let source_start = source_context.offset as usize + prop_start + relative_start; | ||
| Some(source_start..source_start + value.len()) | ||
| } | ||
|
|
||
| /// Returns the authored range of the attribute name itself — `msg` inside | ||
| /// `:msg="expr"`, `v-bind:msg="expr"`, or `msg="text"`. | ||
| /// | ||
| /// vue-tsc anchors prop-type diagnostics at the attribute name, so the | ||
| /// synthetic check identifier maps here for byte-identical positions. | ||
| pub(super) fn prop_name_source_range( | ||
| source_context: ComponentPropSource<'_>, | ||
| prop: &PassedProp, | ||
| ) -> Option<std::ops::Range<usize>> { | ||
| let source = source_context.template?; | ||
| let prop_start = prop.start as usize; | ||
| let raw_prop = source.get(prop_start..prop.end as usize)?; | ||
| let name_region = raw_prop.split('=').next().unwrap_or(raw_prop); | ||
| let name = prop.name.as_str(); | ||
| // The authored name sits right after the binding prefix; matching there | ||
| // (instead of searching) keeps names like `bind` from anchoring inside | ||
| // `v-bind:` and modifiers like `.sync` from stealing the match. | ||
| let prefix_len = if let Some(rest) = name_region.strip_prefix("v-bind:") { | ||
| rest.starts_with(name).then_some("v-bind:".len())? | ||
| } else if let Some(rest) = name_region.strip_prefix(':') { | ||
| rest.starts_with(name).then_some(1)? | ||
| } else if name_region.starts_with(name) { | ||
| 0 | ||
| } else { | ||
| name_region.find(name)? | ||
| }; | ||
| let source_start = source_context.offset as usize + prop_start + prefix_len; | ||
| Some(source_start..source_start + name.len()) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.