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
|
||||
const maybeKeyModifier = /*@__PURE__*/ makeMap('left,right')
|
||||
const isKeyboardEvent = /*@__PURE__*/ makeMap(
|
||||
`onkeyup,onkeydown,onkeypress`,
|
||||
true,
|
||||
)
|
||||
const isKeyboardEvent = /*@__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`)
|
||||
|
||||
const resolveModifiers = (
|
||||
key: ExpressionNode,
|
||||
|
|
@ -64,7 +61,9 @@ const resolveModifiers = (
|
|||
// runtimeModifiers: modifiers that needs runtime guards
|
||||
if (maybeKeyModifier(modifier)) {
|
||||
if (isStaticExp(key)) {
|
||||
if (isKeyboardEvent((key as SimpleExpressionNode).content)) {
|
||||
if (
|
||||
isKeyboardEvent((key as SimpleExpressionNode).content.toLowerCase())
|
||||
) {
|
||||
keyModifiers.push(modifier)
|
||||
} else {
|
||||
nonKeyModifiers.push(modifier)
|
||||
|
|
@ -133,7 +132,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
|||
if (
|
||||
keyModifiers.length &&
|
||||
// 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,
|
||||
|
|
|
|||
|
|
@ -7,12 +7,8 @@
|
|||
*/
|
||||
|
||||
/*! #__NO_SIDE_EFFECTS__ */
|
||||
export function makeMap(
|
||||
str: string,
|
||||
expectsLowerCase?: boolean,
|
||||
): (key: string) => boolean {
|
||||
const set = new Set(str.split(','))
|
||||
return expectsLowerCase
|
||||
? val => set.has(val.toLowerCase())
|
||||
: val => set.has(val)
|
||||
export function makeMap(str: string): (key: string) => boolean {
|
||||
const map = Object.create(null)
|
||||
for (const key of str.split(',')) map[key] = 1
|
||||
return val => val in map
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue