-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b953ec8
commit 0c2adfe
Showing
15 changed files
with
900 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1 +1,12 @@ | ||
<template>Count</template> | ||
<script lang="tsx"> | ||
import { defineComponent, ref } from 'vue' | ||
export default defineComponent({ | ||
props: { | ||
value: String, | ||
}, | ||
setup(props) { | ||
return <div>{props.value}</div> | ||
}, | ||
}) | ||
</script> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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,102 @@ | ||
import { | ||
ErrorCodes, | ||
createCompilerError, | ||
resolveModifiers, | ||
} from '@vue/compiler-dom' | ||
import { extend, makeMap } from '@vue/shared' | ||
import { IRNodeTypes, type KeyOverride, type SetEventIRNode } from '../ir' | ||
import { | ||
isComponentNode, | ||
resolveExpression, | ||
resolveLocation, | ||
resolveSimpleExpression, | ||
} from '../utils' | ||
import { EMPTY_EXPRESSION } from './utils' | ||
import type { DirectiveTransform } from '../transform' | ||
|
||
const delegatedEvents = /*#__PURE__*/ makeMap( | ||
'beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,' + | ||
'keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,' + | ||
'pointermove,pointerout,pointerover,pointerup,touchend,touchmove,' + | ||
'touchstart', | ||
) | ||
|
||
export const transformVOn: DirectiveTransform = (dir, node, context) => { | ||
const { name, loc, value } = dir | ||
if (name.type === 'JSXNamespacedName') return | ||
const isComponent = isComponentNode(node) | ||
|
||
const [nameString, ...modifiers] = name.name | ||
.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()) | ||
.split('_') | ||
|
||
if (!value && !modifiers.length) { | ||
context.options.onError( | ||
createCompilerError( | ||
ErrorCodes.X_V_ON_NO_EXPRESSION, | ||
resolveLocation(loc, context), | ||
), | ||
) | ||
} | ||
|
||
let arg = resolveSimpleExpression(nameString, true, dir.name.loc) | ||
const exp = resolveExpression(dir.value, context) | ||
|
||
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = | ||
resolveModifiers( | ||
arg.isStatic ? `on${nameString}` : arg, | ||
modifiers, | ||
null, | ||
resolveLocation(loc, context), | ||
) | ||
|
||
let keyOverride: KeyOverride | undefined | ||
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === 'click' | ||
const delegate = | ||
arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content) | ||
|
||
// normalize click.right and click.middle since they don't actually fire | ||
if (nonKeyModifiers.includes('middle')) { | ||
if (keyOverride) { | ||
// TODO error here | ||
} | ||
if (isStaticClick) { | ||
arg = extend({}, arg, { content: 'mouseup' }) | ||
} else if (!arg.isStatic) { | ||
keyOverride = ['click', 'mouseup'] | ||
} | ||
} | ||
if (nonKeyModifiers.includes('right')) { | ||
if (isStaticClick) { | ||
arg = extend({}, arg, { content: 'contextmenu' }) | ||
} else if (!arg.isStatic) { | ||
keyOverride = ['click', 'contextmenu'] | ||
} | ||
} | ||
|
||
if (isComponent) { | ||
const handler = exp || EMPTY_EXPRESSION | ||
return { | ||
key: arg, | ||
value: handler, | ||
handler: true, | ||
} | ||
} | ||
|
||
const operation: SetEventIRNode = { | ||
type: IRNodeTypes.SET_EVENT, | ||
element: context.reference(), | ||
key: arg, | ||
value: exp, | ||
modifiers: { | ||
keys: keyModifiers, | ||
nonKeys: nonKeyModifiers, | ||
options: eventOptionModifiers, | ||
}, | ||
keyOverride, | ||
delegate, | ||
effect: !arg.isStatic, | ||
} | ||
|
||
context.registerEffect([arg], operation) | ||
} |
This file contains 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 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
Oops, something went wrong.