Skip to content

Commit

Permalink
fix v-model argument and modifier co-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Jan 26, 2024
1 parent 0cdf20b commit 9ce1f98
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
30 changes: 24 additions & 6 deletions visitor/src/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,33 @@ pub(crate) enum Directive {
}

pub(crate) fn parse_directive(jsx_attr: &JSXAttr, is_component: bool) -> Directive {
let (name, mut argument) = match &jsx_attr.name {
JSXAttrName::Ident(ident) => (&ident.sym, None),
let (name, argument, splitted) = match &jsx_attr.name {
JSXAttrName::Ident(ident) => {
let mut splitted = ident
.sym
.trim_start_matches('v')
.trim_start_matches('-')
.split('_');
(
splitted.next().unwrap_or(&*ident.sym).to_ascii_lowercase(),
splitted.next(),
splitted,
)
}
JSXAttrName::JSXNamespacedName(JSXNamespacedName { ns, name }) => {
(&ns.sym, Some(Expr::Lit(Lit::Str(quote_str!(&*name.sym)))))
let mut splitted = name.sym.split('_');
(
ns.sym
.trim_start_matches('v')
.trim_start_matches('-')
.to_ascii_lowercase(),
Some(splitted.next().unwrap_or(&*name.sym)),
splitted,
)
}
};
let name = name.trim_start_matches('v').trim_start_matches('-');
let mut splitted = name.split('_');
let name = splitted.next().unwrap_or(name).to_ascii_lowercase();

let mut argument = argument.map(|argument| Expr::Lit(Lit::Str(quote_str!(argument))));

match &*name {
"html" => return parse_v_html_directive(jsx_attr),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Child v-model:value_double={this.foo} />
11 changes: 11 additions & 0 deletions visitor/tests/fixture/v-model-with-arg-and-modifier/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
_createVNode(_resolveComponent("Child"), {
"value": this.foo,
"valueModifiers": {
"double": true
},
"onUpdate:value": ($event)=>this.foo = $event
}, null, 8, [
"value",
"onUpdate:value"
]);

0 comments on commit 9ce1f98

Please sign in to comment.