-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
README update and directory update and other
- Loading branch information
Jerman.xie
authored and
Jerman.xie
committed
Nov 27, 2019
1 parent
f33c344
commit ac47ccc
Showing
741 changed files
with
128,300 additions
and
623 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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
整个项目代码基于 https://github.com/vuejs/vue | ||
整个项目代码Clone于 https://github.com/vuejs/vue | ||
|
||
- src目录为官方原代码目录,未做修改(用于对比) | ||
- src | ||
- 与src-bak的文件目录一样,只是添加了自己的理解和注释 | ||
|
||
- src-read为已经看过的原码路径,与src内的文件一一对应,添加了相对应的中文注释。项目都是基于官方的注释翻译,或基于自己的理解添加,如有问题欢迎提 Issues 指正! | ||
- 在src目录改,主要便于启动dev开发模式,便于console输出 | ||
|
||
- 每个目录添加了README.md文件 | ||
|
||
- src-bak | ||
|
||
- 目录为官方原代码目录,未做修改(用于对比) | ||
|
||
|
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
Large diffs are not rendered by default.
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* @flow */ | ||
|
||
const range = 2 | ||
|
||
export function generateCodeFrame ( | ||
source: string, | ||
start: number = 0, | ||
end: number = source.length | ||
): string { | ||
const lines = source.split(/\r?\n/) | ||
let count = 0 | ||
const res = [] | ||
for (let i = 0; i < lines.length; i++) { | ||
count += lines[i].length + 1 | ||
if (count >= start) { | ||
for (let j = i - range; j <= i + range || end > count; j++) { | ||
if (j < 0 || j >= lines.length) continue | ||
res.push(`${j + 1}${repeat(` `, 3 - String(j + 1).length)}| ${lines[j]}`) | ||
const lineLength = lines[j].length | ||
if (j === i) { | ||
// push underline | ||
const pad = start - (count - lineLength) + 1 | ||
const length = end > count ? lineLength - pad : end - start | ||
res.push(` | ` + repeat(` `, pad) + repeat(`^`, length)) | ||
} else if (j > i) { | ||
if (end > count) { | ||
const length = Math.min(end - count, lineLength) | ||
res.push(` | ` + repeat(`^`, length)) | ||
} | ||
count += lineLength + 1 | ||
} | ||
} | ||
break | ||
} | ||
} | ||
return res.join('\n') | ||
} | ||
|
||
function repeat (str, n) { | ||
let result = '' | ||
if (n > 0) { | ||
while (true) { // eslint-disable-line | ||
if (n & 1) result += str | ||
n >>>= 1 | ||
if (n <= 0) break | ||
str += str | ||
} | ||
} | ||
return result | ||
} |
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,190 @@ | ||
/* @flow */ | ||
|
||
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/ | ||
const fnInvokeRE = /\([^)]*?\);*$/ | ||
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/ | ||
|
||
// KeyboardEvent.keyCode aliases | ||
const keyCodes: { [key: string]: number | Array<number> } = { | ||
esc: 27, | ||
tab: 9, | ||
enter: 13, | ||
space: 32, | ||
up: 38, | ||
left: 37, | ||
right: 39, | ||
down: 40, | ||
'delete': [8, 46] | ||
} | ||
|
||
// KeyboardEvent.key aliases | ||
const keyNames: { [key: string]: string | Array<string> } = { | ||
// #7880: IE11 and Edge use `Esc` for Escape key name. | ||
esc: ['Esc', 'Escape'], | ||
tab: 'Tab', | ||
enter: 'Enter', | ||
// #9112: IE11 uses `Spacebar` for Space key name. | ||
space: [' ', 'Spacebar'], | ||
// #7806: IE11 uses key names without `Arrow` prefix for arrow keys. | ||
up: ['Up', 'ArrowUp'], | ||
left: ['Left', 'ArrowLeft'], | ||
right: ['Right', 'ArrowRight'], | ||
down: ['Down', 'ArrowDown'], | ||
// #9112: IE11 uses `Del` for Delete key name. | ||
'delete': ['Backspace', 'Delete', 'Del'] | ||
} | ||
|
||
// #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 | ||
const genGuard = condition => `if(${condition})return null;` | ||
|
||
const modifierCode: { [key: string]: string } = { | ||
stop: '$event.stopPropagation();', | ||
prevent: '$event.preventDefault();', | ||
self: genGuard(`$event.target !== $event.currentTarget`), | ||
ctrl: genGuard(`!$event.ctrlKey`), | ||
shift: genGuard(`!$event.shiftKey`), | ||
alt: genGuard(`!$event.altKey`), | ||
meta: genGuard(`!$event.metaKey`), | ||
left: genGuard(`'button' in $event && $event.button !== 0`), | ||
middle: genGuard(`'button' in $event && $event.button !== 1`), | ||
right: genGuard(`'button' in $event && $event.button !== 2`) | ||
} | ||
|
||
export function genHandlers ( | ||
events: ASTElementHandlers, | ||
isNative: boolean | ||
): string { | ||
const prefix = isNative ? 'nativeOn:' : 'on:' | ||
let staticHandlers = `` | ||
let dynamicHandlers = `` | ||
for (const name in events) { | ||
const handlerCode = genHandler(events[name]) | ||
if (events[name] && events[name].dynamic) { | ||
dynamicHandlers += `${name},${handlerCode},` | ||
} else { | ||
staticHandlers += `"${name}":${handlerCode},` | ||
} | ||
} | ||
staticHandlers = `{${staticHandlers.slice(0, -1)}}` | ||
if (dynamicHandlers) { | ||
return prefix + `_d(${staticHandlers},[${dynamicHandlers.slice(0, -1)}])` | ||
} else { | ||
return prefix + staticHandlers | ||
} | ||
} | ||
|
||
// Generate handler code with binding params on Weex | ||
/* istanbul ignore next */ | ||
function genWeexHandler (params: Array<any>, handlerCode: string) { | ||
let innerHandlerCode = handlerCode | ||
const exps = params.filter(exp => simplePathRE.test(exp) && exp !== '$event') | ||
const bindings = exps.map(exp => ({ '@binding': exp })) | ||
const args = exps.map((exp, i) => { | ||
const key = `$_${i + 1}` | ||
innerHandlerCode = innerHandlerCode.replace(exp, key) | ||
return key | ||
}) | ||
args.push('$event') | ||
return '{\n' + | ||
`handler:function(${args.join(',')}){${innerHandlerCode}},\n` + | ||
`params:${JSON.stringify(bindings)}\n` + | ||
'}' | ||
} | ||
|
||
function genHandler (handler: ASTElementHandler | Array<ASTElementHandler>): string { | ||
if (!handler) { | ||
return 'function(){}' | ||
} | ||
|
||
if (Array.isArray(handler)) { | ||
return `[${handler.map(handler => genHandler(handler)).join(',')}]` | ||
} | ||
|
||
const isMethodPath = simplePathRE.test(handler.value) | ||
const isFunctionExpression = fnExpRE.test(handler.value) | ||
const isFunctionInvocation = simplePathRE.test(handler.value.replace(fnInvokeRE, '')) | ||
|
||
if (!handler.modifiers) { | ||
if (isMethodPath || isFunctionExpression) { | ||
return handler.value | ||
} | ||
/* istanbul ignore if */ | ||
if (__WEEX__ && handler.params) { | ||
return genWeexHandler(handler.params, handler.value) | ||
} | ||
return `function($event){${ | ||
isFunctionInvocation ? `return ${handler.value}` : handler.value | ||
}}` // inline statement | ||
} else { | ||
let code = '' | ||
let genModifierCode = '' | ||
const keys = [] | ||
for (const key in handler.modifiers) { | ||
if (modifierCode[key]) { | ||
genModifierCode += modifierCode[key] | ||
// left/right | ||
if (keyCodes[key]) { | ||
keys.push(key) | ||
} | ||
} else if (key === 'exact') { | ||
const modifiers: ASTModifiers = (handler.modifiers: any) | ||
genModifierCode += genGuard( | ||
['ctrl', 'shift', 'alt', 'meta'] | ||
.filter(keyModifier => !modifiers[keyModifier]) | ||
.map(keyModifier => `$event.${keyModifier}Key`) | ||
.join('||') | ||
) | ||
} else { | ||
keys.push(key) | ||
} | ||
} | ||
if (keys.length) { | ||
code += genKeyFilter(keys) | ||
} | ||
// Make sure modifiers like prevent and stop get executed after key filtering | ||
if (genModifierCode) { | ||
code += genModifierCode | ||
} | ||
const handlerCode = isMethodPath | ||
? `return ${handler.value}($event)` | ||
: isFunctionExpression | ||
? `return (${handler.value})($event)` | ||
: isFunctionInvocation | ||
? `return ${handler.value}` | ||
: handler.value | ||
/* istanbul ignore if */ | ||
if (__WEEX__ && handler.params) { | ||
return genWeexHandler(handler.params, code + handlerCode) | ||
} | ||
return `function($event){${code}${handlerCode}}` | ||
} | ||
} | ||
|
||
function genKeyFilter (keys: Array<string>): string { | ||
return ( | ||
// make sure the key filters only apply to KeyboardEvents | ||
// #9441: can't use 'keyCode' in $event because Chrome autofill fires fake | ||
// key events that do not have keyCode property... | ||
`if(!$event.type.indexOf('key')&&` + | ||
`${keys.map(genFilterCode).join('&&')})return null;` | ||
) | ||
} | ||
|
||
function genFilterCode (key: string): string { | ||
const keyVal = parseInt(key, 10) | ||
if (keyVal) { | ||
return `$event.keyCode!==${keyVal}` | ||
} | ||
const keyCode = keyCodes[key] | ||
const keyName = keyNames[key] | ||
return ( | ||
`_k($event.keyCode,` + | ||
`${JSON.stringify(key)},` + | ||
`${JSON.stringify(keyCode)},` + | ||
`$event.key,` + | ||
`${JSON.stringify(keyName)}` + | ||
`)` | ||
) | ||
} |
Oops, something went wrong.