mirror of https://github.com/vuejs/core.git
refactor: remove rarely used argument in makeMap + optimize perf
This commit is contained in:
parent
dad6738099
commit
b1430f250d
|
|
@ -28,10 +28,7 @@ const isNonKeyModifier = /*@__PURE__*/ makeMap(
|
||||||
)
|
)
|
||||||
// left & right could be mouse or key modifiers based on event type
|
// left & right could be mouse or key modifiers based on event type
|
||||||
const maybeKeyModifier = /*@__PURE__*/ makeMap('left,right')
|
const maybeKeyModifier = /*@__PURE__*/ makeMap('left,right')
|
||||||
const isKeyboardEvent = /*@__PURE__*/ makeMap(
|
const isKeyboardEvent = /*@__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`)
|
||||||
`onkeyup,onkeydown,onkeypress`,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
const resolveModifiers = (
|
const resolveModifiers = (
|
||||||
key: ExpressionNode,
|
key: ExpressionNode,
|
||||||
|
|
@ -64,7 +61,9 @@ const resolveModifiers = (
|
||||||
// runtimeModifiers: modifiers that needs runtime guards
|
// runtimeModifiers: modifiers that needs runtime guards
|
||||||
if (maybeKeyModifier(modifier)) {
|
if (maybeKeyModifier(modifier)) {
|
||||||
if (isStaticExp(key)) {
|
if (isStaticExp(key)) {
|
||||||
if (isKeyboardEvent((key as SimpleExpressionNode).content)) {
|
if (
|
||||||
|
isKeyboardEvent((key as SimpleExpressionNode).content.toLowerCase())
|
||||||
|
) {
|
||||||
keyModifiers.push(modifier)
|
keyModifiers.push(modifier)
|
||||||
} else {
|
} else {
|
||||||
nonKeyModifiers.push(modifier)
|
nonKeyModifiers.push(modifier)
|
||||||
|
|
@ -133,7 +132,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
||||||
if (
|
if (
|
||||||
keyModifiers.length &&
|
keyModifiers.length &&
|
||||||
// if event name is dynamic, always wrap with keys guard
|
// if event name is dynamic, always wrap with keys guard
|
||||||
(!isStaticExp(key) || isKeyboardEvent(key.content))
|
(!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))
|
||||||
) {
|
) {
|
||||||
handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
||||||
handlerExp,
|
handlerExp,
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
export function makeMap(
|
export function makeMap(str: string): (key: string) => boolean {
|
||||||
str: string,
|
const map = Object.create(null)
|
||||||
expectsLowerCase?: boolean,
|
for (const key of str.split(',')) map[key] = 1
|
||||||
): (key: string) => boolean {
|
return val => val in map
|
||||||
const set = new Set(str.split(','))
|
|
||||||
return expectsLowerCase
|
|
||||||
? val => set.has(val.toLowerCase())
|
|
||||||
: val => set.has(val)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue