-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
feat(compiler-core): allow directive modifiers to be dynamic (fix #8281) #12913
base: minor
Are you sure you want to change the base?
Conversation
I developed on top of the main branch but the guidelines say to submit against minor. Now I have this extra commits in my history. Not sure how to handle this |
fixed by merging main into the minor branch. |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-ssr
@vue/compiler-sfc
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Thank you very much for your contribution. This PR is really great. I did a quick test and found the following issues.
the following template <template>
<Comp v-model.[mod]="msg"/>
</template> should be compiled to: _createVNode($setup["Comp"], {
modelValue: $setup.msg,
"onUpdate:modelValue": _cache[1] || (_cache[1] = $event => (($setup.msg) = $event)),
- modelModifiers: { "$setup.mod": true }
+ modelModifiers: Object.assign({}, $setup.mod)
}, null, 8 /* PROPS */, ["modelValue"])
the following template <template>
<Comp v-model.number.[mod]="msg"/>
</template> should be compiled to: _createVNode($setup["Comp"], {
modelValue: $setup.msg,
"onUpdate:modelValue": _cache[1] || (_cache[1] = $event => (($setup.msg) = $event)),
- modelModifiers: { number: true, "$setup.mod": true }
+ modelModifiers: Object.assign({number:true}, $setup.mod)
}, null, 8 /* PROPS */, ["modelValue"])
the following template should not cause a compilation error. see Playground with this PR <Comp v-model.[{ number: true }]="msg"/> |
@edison1105 thanks for the super fast feedback. Am I correct to assume, that your failing cases are specific to the v-model directive or does it happen with any other? (it shouldnt) For the last error: The "expression missing" error shadows the "whitespace forbidden" error. The same happens if you use whitespaces in the dynamic argument: When I tried try this with the template-explorer it correctly showed the error for other directives that are not v-on or v-model: Since this is already bahavior thats valid for args, maybe its ok for modifiers as well? Wdyt? I am not against allowing spaces in dynamic args and modifiers but I am pretty sure it would break formatters and syntax highlighters. I guess thats also the reason why its not supported. I would have written a test for that as well but I couldnt find where to put it. |
I have a bit of duplicated code now. Let me know if I should refactor that and if so, where I put helper functions for such things |
fix #8281
This PR adds dynamic modifiers for directives
It also adds error states for empty modifiers (
v-foo.="5"
) and handles empty dynamic modifiers or invalid values e.g.v-foo.[]="5"
,v-foo.[123]="5"
.I skipped modifiers with invalid values. I am not sure if that is a problem. Otherwise codegen would be corrupted (it was before for empty values already. That's also fixed with that).
I also had to change modifiers to be an Expression instead of SimpleExpression so that I can use parseExpression with it. That means I had to cast to SimpleExpression at a few places