Skip to content
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(runtime-core): Add ”InversionValue“ peculiarity,makes it easier to pass false to props #12280

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/compiler-core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const tokenizer = new Tokenizer(stack, {
ondirname(start, end) {
const raw = getSlice(start, end)
const name =
raw === '.' || raw === ':'
raw === '.' || raw === ':' || raw === '!'
? 'bind'
: raw === '@'
? 'on'
Expand Down Expand Up @@ -353,6 +353,11 @@ const tokenizer = new Tokenizer(stack, {
}
} else {
// directive
const { rawName } = currentProp
if (rawName && rawName[0] === '!' && currentAttrValue === '') {
currentProp.rawName = `:${rawName.slice(1)}`
currentAttrValue = 'false'
}
let expParseMode = ExpParseMode.Normal
if (!__BROWSER__) {
if (currentProp.name === 'for') {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-core/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ export default class Tokenizer {
c === CharCodes.Dot ||
c === CharCodes.Colon ||
c === CharCodes.At ||
c === CharCodes.Number
c === CharCodes.Number ||
c === CharCodes.ExclamationMark
) {
this.cbs.ondirname(this.index, this.index + 1)
this.state = State.InDirArg
Expand Down
47 changes: 47 additions & 0 deletions packages/vue/examples/codemeow/useInversionValue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script src="../../dist/vue.global.js"></script>
<script>
const { reactive, computed } = Vue

const AxisLabel = {
template: '<text>{{stat}} {{stat===false}} {{wode}}</text>',
props: {
stat: {
default: true,
type: Boolean
},
wode: {
default: false,
type: Boolean
}
},
setup(props) {
return {

}
},
}
</script>


<div id="demo">
<div class="zzz">
<input type="text" !value>
<axis-label !stat :nihao="false" wode></axis-label>
</div>
</div>

<script>
const { createApp } = Vue
createApp({
components: {
AxisLabel,
},
setup() {
return {}
},
}).mount('#demo')
</script>

<style>

</style>