-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move keyName alias map to compiler
- Loading branch information
Showing
3 changed files
with
35 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/ | ||
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/ | ||
|
||
// keyCode aliases | ||
// KeyboardEvent.keyCode aliases | ||
const keyCodes: { [key: string]: number | Array<number> } = { | ||
esc: 27, | ||
tab: 9, | ||
|
@@ -16,6 +16,19 @@ const keyCodes: { [key: string]: number | Array<number> } = { | |
'delete': [8, 46] | ||
} | ||
|
||
// KeyboardEvent.key aliases | ||
const keyNames: { [key: string]: string | Array<string> } = { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yyx990803
Author
Member
|
||
esc: 'Escape', | ||
tab: 'Tab', | ||
enter: 'Enter', | ||
space: ' ', | ||
up: 'ArrowUp', | ||
left: 'ArrowLeft', | ||
right: 'ArrowRight', | ||
down: 'ArrowDown', | ||
'delete': ['Backspace', 'Delete'] | ||
} | ||
|
||
// #4868: modifiers that prevent the execution of the listener | ||
// need to explicitly return null so that we can determine whether to remove | ||
// the listener for .once | ||
|
@@ -140,11 +153,14 @@ function genFilterCode (key: string): string { | |
if (keyVal) { | ||
return `$event.keyCode!==${keyVal}` | ||
} | ||
const code = keyCodes[key] | ||
const keyCode = keyCodes[key] | ||
const keyName = keyNames[key] | ||
return ( | ||
`_k($event.keyCode,` + | ||
`${JSON.stringify(key)},` + | ||
`${JSON.stringify(code)},` + | ||
`$event.key)` | ||
`${JSON.stringify(keyCode)},` + | ||
`$event.key,` + | ||
`${JSON.stringify(keyName)}` + | ||
`)` | ||
) | ||
} |
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
May I know what's the benefit from moving keyName alias map to compiler? It cause increased compiled file size.