Skip to content

Commit e6de223

Browse files
committed
docs: add some comments, remove some useless functions
1 parent 62772a9 commit e6de223

File tree

4 files changed

+253
-164
lines changed

4 files changed

+253
-164
lines changed

packages/vue-ssr-jit/build.dev.js

Lines changed: 127 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6593,25 +6593,42 @@ function createPromiseCallback () {
65936593
}
65946594

65956595
/**
6596-
* 获取抽象语法树中创造 VNode 的函数参数中的数组参数,数组参数里定义了子节点的渲染函数
6597-
* 用处:当对比得出当前节点为静态节点,则删除当前节点,提升子节点
6598-
* @param {Ast} ast 抽象语法树
6596+
* Engligh:
6597+
* Get the array of parameters in the function argument, which defines the rendering function for the child node
6598+
*
6599+
* 中文:
6600+
* 获取 ast 中生成 VNode 的函数参数中的数组参数,数组参数里定义了子节点的渲染函数
6601+
*
6602+
* Example:
6603+
* source code: _c("div", [_c("router-view")], 1)
6604+
*
6605+
* return [_c("router-view")]
6606+
*
6607+
* @param {Object} ast
65996608
*/
66006609
function getVNodeAstChildren(ast) {
66016610
var children = null;
66026611
if (ast.type === 'CallExpression') {
66036612
try {
66046613
children = ast.arguments.filter(function (v) { return v.type === 'ArrayExpression'; })[0];
66056614
} catch(e) {
6606-
console.error('获取虚拟 dom 子元素失败,请查看 ast', ast);
6615+
console.error('To get the virtual DOM sub-element failed, see AST', ast);
66076616
}
66086617
}
66096618
return children
66106619
}
66116620

66126621
/**
6613-
* 当前节点是否是 ssrNode 函数节点
6614-
* @param {Ast} ast 抽象语法树
6622+
* English:
6623+
* Detects if the ast fragment is an ssrNode function node.
6624+
*
6625+
* 中文:
6626+
* 检测 ast 片段是否是 ssrNode 函数节点。
6627+
*
6628+
* Example:
6629+
* _vm._ssrNode("<div>vue-ssr-jit</div>")
6630+
*
6631+
* @param {Object} ast
66156632
*/
66166633
function isSSRNodeAst(ast) {
66176634
return ast && types.isCallExpression(ast) &&
@@ -6620,6 +6637,15 @@ function isSSRNodeAst(ast) {
66206637
ast.callee.property.name === '_ssrNode'
66216638
}
66226639

6640+
/**
6641+
* English:
6642+
* Recursively obtain the leftmost string in a string splicing expression
6643+
*
6644+
* 中文:
6645+
* 递归获取字符串拼接表达式中最左边的字符串
6646+
*
6647+
* @param {Object} ast
6648+
*/
66236649
function getLeftStringLiteral(ast) {
66246650
if (types.isBinaryExpression(ast)) {
66256651
return getLeftStringLiteral(ast.left)
@@ -6628,6 +6654,15 @@ function getLeftStringLiteral(ast) {
66286654
}
66296655
}
66306656

6657+
/**
6658+
* English:
6659+
* Recursively obtain the rightmost string in a string splicing expression
6660+
*
6661+
* 中文:
6662+
* 递归获取字符串拼接表达式中最右边的字符串
6663+
*
6664+
* @param {Object} ast
6665+
*/
66316666
function getRightStringLiteral(ast) {
66326667
if (types.isBinaryExpression(ast)) {
66336668
return getRightStringLiteral(ast.right)
@@ -6637,33 +6672,43 @@ function getRightStringLiteral(ast) {
66376672
}
66386673

66396674
/**
6640-
* 优化过的加法表达式,相邻的字符串类型直接进行字符拼接,不需要加法拼接
6675+
* English:
6676+
* Optimized string splicing expressions, where adjacent string types are merged directly into a single string, no splicing required
6677+
*
6678+
* 中文:
6679+
* 优化过的字符串拼接表达式,相邻的字符串类型直接合并成一个字符串,不需要拼接
6680+
*
6681+
* Example:
6682+
* 'a' + 'b' --> 'ab'
6683+
* 'a' + 'b' + c --> 'ab' + c
6684+
* a + 'b' + 'c' --> a + 'bc'
66416685
*/
66426686
function binaryExpressionPlus(left, right) {
6643-
// 两个都是纯字符串,直接做字符串拼接
66446687
if (types.isStringLiteral(left) && types.isStringLiteral(right)) {
66456688
return types.stringLiteral(left.value + right.value)
66466689
}
6647-
// 左边是纯字符串,右边是表达式
66486690
else if (types.isStringLiteral(left) && types.isBinaryExpression(right)) {
66496691
var mostLeft = getLeftStringLiteral(right);
66506692
mostLeft.value = left.value + mostLeft.value;
66516693
return right
66526694
}
6653-
// 左边是表达式,右边是纯字符串
66546695
else if (types.isBinaryExpression(left) && types.isStringLiteral(right)) {
66556696
var mostRight = getRightStringLiteral(left);
66566697
mostRight.value = mostRight.value + right.value;
66576698
return left
66586699
}
6659-
// 两边都是表达式
66606700
else {
66616701
return types.binaryExpression('+', left, right)
66626702
}
66636703
}
66646704

66656705
/**
6666-
* 检测组件的抽象语法树是否是静态的
6706+
* English:
6707+
* Returns the value of the node if the ast fragment is confirmed as a static node by diff, otherwise returns ''
6708+
*
6709+
* 中文:
6710+
* 如果 ast 片段经过 diff 确认是静态节点,则返回节点的值,否则返回 ''
6711+
*
66676712
* @param {Object} ast
66686713
*/
66696714
function getStatisAstComponentValue(ast) {
@@ -6684,9 +6729,20 @@ function getStatisAstComponentValue(ast) {
66846729
}
66856730

66866731
/**
6687-
* 获取抽象语法树中创造 VNode 的函数节点
6688-
* 注意只有被添加了 ssrKey 的节点才可做后续的优化
6689-
* @param {Ast} ast 抽象语法树
6732+
* English:
6733+
* Get function call expression for generating VNode in ast fragment
6734+
*
6735+
* 中文:
6736+
* 获取 ast 片段中生成 VNode 的函数调用表达式
6737+
*
6738+
* Example:
6739+
* function render() {
6740+
* return _c('div')
6741+
* }
6742+
*
6743+
* ---> _c('div')
6744+
*
6745+
* @param {Object} ast
66906746
*/
66916747
function getVNodeRenderAst(ast) {
66926748
var vNodeAst;
@@ -6704,11 +6760,16 @@ function getVNodeRenderAst(ast) {
67046760
}
67056761

67066762
/**
6707-
* check if a call expression named ssrNode
6708-
* match code example:
6763+
* English:
6764+
* Detects if the function name of the function call expression is _ssrNode
6765+
*
6766+
* 中文:
6767+
* 检测函数调用表达式的函数名是否为 _ssrNode
6768+
*
6769+
* Example:
67096770
* vm._ssrNode('<div id="xx"/>')
6710-
* @param {*} node
6711-
* @param {*} node
6771+
*
6772+
* @param {Object} node ast
67126773
*/
67136774
function isSSRNodeCallExpression(node) {
67146775
if (!types.isCallExpression(node)) {
@@ -6728,8 +6789,13 @@ function isSSRNodeCallExpression(node) {
67286789
}
67296790

67306791
/**
6731-
* check if a call expression has name '_c'
6732-
* match code example:
6792+
* English:
6793+
* Detects if the function name of the function call expression is _c
6794+
*
6795+
* 中文:
6796+
* 检测函数调用表达式的函数名是否为 _c
6797+
*
6798+
* Example:
67336799
* _c("div", [_vm._v("8")])
67346800
* @param {*} node
67356801
*/
@@ -6751,8 +6817,13 @@ function isCCallExpression(node) {
67516817
}
67526818

67536819
/**
6754-
* check if a call expression has name '_l'
6755-
* match code example:
6820+
* English:
6821+
* Detects if the function name of the function call expression is _c
6822+
*
6823+
* 中文:
6824+
* 检测函数调用表达式的函数名是否为 _c
6825+
*
6826+
* Example:
67566827
* _vm._l()
67576828
* @param {*} node
67586829
*/
@@ -9584,12 +9655,6 @@ function rewriteTraceLine (trace, mapConsumers) {
95849655
/* */
95859656
var vm$1 = require('vm');
95869657

9587-
/**
9588-
* ast.ssrString 如果有值,则表示当前节点是静态节点,但不一定表示子节点是静态节点
9589-
* ast.ssrStatic === true,表示当前节点和子节点都是静态节点
9590-
* ast.unMatchedAst === true,表示当前节点没有匹配到抽象语法树,这种情况只有当节点和子节点全部都为静态,才做优化
9591-
*/
9592-
95939658

95949659

95959660
var PatchContext = function PatchContext (options) {
@@ -22850,7 +22915,7 @@ function getParserClass(pluginsFromOptions) {
2285022915
exports.parse = parse;
2285122916
exports.parseExpression = parseExpression;
2285222917
exports.tokTypes = types;
22853-
//# sourceMappingURL=index.js.map
22918+
2285422919
});
2285522920

2285622921
unwrapExports(lib);
@@ -22995,7 +23060,7 @@ function renderStartingTag$1 (node, context, activeInstance) {
2299523060
/**
2299623061
* 计算条件表达式的语法树的值
2299723062
* @param {context} context 抽象语法树的上下文
22998-
* @param {Object} ast 抽象语法树
23063+
* @param {Object} ast
2299923064
*/
2300023065

2300123066
function calcuConditionalExpression(context, ast) {
@@ -23056,11 +23121,11 @@ function setVNodeChildrenAst(node, ast, context) {
2305623121
/**
2305723122
* 比较组件节点
2305823123
* 所有其他类型都经过 patchComponent 产生
23059-
* ssr 推导优化通过截取 _render 函数,仅执行必要的 render 达到渲染提速的目的
2306023124
*
23061-
* @param {VNode} staticVNode 没做任何数据请求的静态虚拟 DOM
23062-
* @param {VNode} dynamicVNode 接收首屏数据请求的动态虚拟 DOM
23063-
* @param {PatchContext} patchContext 虚拟 DOM 上下文
23125+
* @param {VNode} staticVNode VNode that didn't make any data requests.
23126+
* @param {VNode} dynamicVNode VNode populated with asynchronous data
23127+
* @param {PatchContext} patchContext VNode context,record patch data
23128+
* @param {boolean} isRoot The root node adds the additional property SSR_ATTR
2306423129
*/
2306523130
function patchComponent(staticVNode, dynamicVNode, patchContext, isRoot) {
2306623131
var ast = staticVNode.ast;
@@ -23125,9 +23190,10 @@ function patchComponent(staticVNode, dynamicVNode, patchContext, isRoot) {
2312523190
/**
2312623191
* 比较异步组件
2312723192
*
23128-
* @param {VNode} staticVNode 没做任何数据请求的静态虚拟 DOM
23129-
* @param {VNode} dynamicVNode 接收首屏数据请求的动态虚拟 DOM
23130-
* @param {PatchContext} patchContext 虚拟 DOM 上下文
23193+
* @param {VNode} staticVNode VNode that didn't make any data requests.
23194+
* @param {VNode} dynamicVNode VNode populated with asynchronous data
23195+
* @param {PatchContext} patchContext VNode context,record patch data
23196+
* @param {boolean} isRoot The root node adds the additional property SSR_ATTR
2313123197
*/
2313223198
function patchAsyncComponent(staticVNode, dynamicVNode, patchContext, isRoot) {
2313323199
var ast = staticVNode.ast;
@@ -23231,9 +23297,9 @@ function getResolevdNode(node, comp) {
2323123297
/**
2323223298
* 比较字符串型节点,这种节点为 ssr 特有,是模板编译器的一种渲染优化
2323323299
*
23234-
* @param {VNode} staticVNode 没做任何数据请求的静态虚拟 DOM
23235-
* @param {VNode} dynamicVNode 接收首屏数据请求的动态虚拟 DOM
23236-
* @param {PatchContext} patchContext 虚拟 DOM 上下文
23300+
* @param {VNode} staticVNode VNode that didn't make any data requests.
23301+
* @param {VNode} dynamicVNode VNode populated with asynchronous data
23302+
* @param {PatchContext} patchContext VNode context,record patch data
2323723303
*/
2323823304
function patchStringNode(staticVNode, dynamicVNode, patchContext) {
2323923305
var ast = staticVNode.ast;
@@ -23266,10 +23332,10 @@ function patchStringNode(staticVNode, dynamicVNode, patchContext) {
2326623332
/**
2326723333
* 比较元素节点
2326823334
*
23269-
* @param {VNode} staticVNode 没做任何数据请求的静态虚拟 DOM
23270-
* @param {VNode} dynamicVNode 接收首屏数据请求的动态虚拟 DOM
23271-
* @param {PatchContext} patchContext 虚拟 DOM 上下文
23272-
* @param {ast} ast 当前渲染函数的抽象语法树
23335+
* @param {VNode} staticVNode VNode that didn't make any data requests.
23336+
* @param {VNode} dynamicVNode VNode populated with asynchronous data
23337+
* @param {PatchContext} patchContext VNode context,record patch data
23338+
* @param {boolean} isRoot The root node adds the additional property SSR_ATTR
2327323339
*/
2327423340
function patchElement(staticVNode, dynamicVNode, patchContext, isRoot) {
2327523341
if (isTrue(isRoot)) {
@@ -23317,42 +23383,29 @@ function patchElement(staticVNode, dynamicVNode, patchContext, isRoot) {
2331723383

2331823384
/**
2331923385
* 对比虚拟 dom ,收集静态节点与动态节点
23320-
* 静态节点拼接成字符串
23321-
* 动态节点包装成执行函数
23322-
*
23323-
* 注意:
23324-
* 1. 服务端的 diff 算法,算出不同之后,并不会操作当前 dynamicVNode,因为当前的 dynamicVNode 沾染了用户数据,
23325-
* 但是 dynamicVNode 的 parentVNode 仍然是静态节点,推导优化通过 dynamicVNode.parentVNode + 当前
23326-
* 用户上下文 生成动态的字符串。
23327-
* 2. 为了确保用户数据安全,所有作为字符串生成参数的 VNode ,只能用 dynamicVNode
2332823386
*
23329-
* @param {VNode} staticVNode 没做任何数据请求的静态虚拟 DOM
23330-
* @param {VNode} dynamicVNode 接收首屏数据请求的动态虚拟 DOM
23331-
* @param {PatchContext} patchContext 虚拟 DOM 上下文
23387+
* @param {VNode} staticVNode VNode that didn't make any data requests.
23388+
* @param {VNode} dynamicVNode VNode populated with asynchronous data
23389+
* @param {PatchContext} patchContext VNode context,record patch data
23390+
* @param {boolean} isRoot The root node adds the additional property SSR_ATTR
2333223391
*/
2333323392
function patchNode(staticVNode, dynamicVNode, patchContext, isRoot) {
2333423393

2333523394
var ast = staticVNode.ast;
2333623395

23337-
// 字符串节点,这是模板引擎对ssr的一种优化
2333823396
if (staticVNode.isString && dynamicVNode.isString) {
2333923397
patchStringNode(staticVNode, dynamicVNode, patchContext);
2334023398
}
23341-
// 组件节点,ssr 性能瓶颈
2334223399
else if (isDef(staticVNode.componentOptions) && isDef(dynamicVNode.componentOptions)) {
2334323400
patchComponent(staticVNode, dynamicVNode, patchContext, isRoot);
2334423401
}
23345-
// 元素节点
2334623402
else if (isDef(staticVNode.tag) && isDef(dynamicVNode.tag)) {
2334723403
patchElement(staticVNode, dynamicVNode, patchContext, isRoot);
2334823404
}
23349-
// 注释节点/异步组件
2335023405
else if (isTrue(staticVNode.isComment) && isTrue(dynamicVNode.isComment)) {
23351-
// 异步组件
2335223406
if (isDef(staticVNode.asyncFactory) && isDef(dynamicVNode.asyncFactory)) {
2335323407
patchAsyncComponent(staticVNode, dynamicVNode, patchContext, isRoot);
2335423408
}
23355-
// 注释节点
2335623409
else {
2335723410
if (staticVNode.text === dynamicVNode.text) {
2335823411
ast.ssrString = "<!--" + (staticVNode.text) + "-->";
@@ -23361,7 +23414,6 @@ function patchNode(staticVNode, dynamicVNode, patchContext, isRoot) {
2336123414
patchContext.next();
2336223415
}
2336323416
}
23364-
// 文本节点
2336523417
else if (isDef(staticVNode.text) && isDef(dynamicVNode.text)){
2336623418
var staticText = staticVNode.raw ? staticVNode.text : escape(String(staticVNode.text));
2336723419
var dynamicText = dynamicVNode.raw ? dynamicVNode.text : escape(String(dynamicVNode.text));
@@ -23381,9 +23433,19 @@ function createPatchFunction (ref) {
2338123433
var isUnaryTag = ref.isUnaryTag;
2338223434
var cache = ref.cache;
2338323435

23436+
/**
23437+
* 中文:
23438+
* VNode diff
23439+
* 如果检测到节点是静态的,修改的是静态组件的 ast (staticAst)
23440+
* 如果检测到节点是动态的
23441+
* staticAst 不做任何网络请求
23442+
* ast.ssrString 如果有值,则表示当前节点是静态节点,但不一定表示子节点是静态节点
23443+
* ast.ssrStatic === true,表示当前节点和子节点都是静态节点
23444+
* ast.unMatchedAst === true,表示当前节点没有匹配到抽象语法树,这种情况只有当节点和子节点全部都为静态,才做优化
23445+
*/
2338423446
return function patcher (
23385-
staticComponent, // 静态实例
23386-
dynamiComponent, // 动态实例
23447+
staticComponent,
23448+
dynamiComponent,
2338723449
userContext,
2338823450
done
2338923451
) {

src/server/patch-context.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ import {
99
import generate from '@babel/generator'
1010
import { ssrRender } from 'core/instance/render'
1111

12-
/**
13-
* ast.ssrString 如果有值,则表示当前节点是静态节点,但不一定表示子节点是静态节点
14-
* ast.ssrStatic === true,表示当前节点和子节点都是静态节点
15-
* ast.unMatchedAst === true,表示当前节点没有匹配到抽象语法树,这种情况只有当节点和子节点全部都为静态,才做优化
16-
*/
17-
1812
type PatchState = {
1913
type: 'Element';
2014
rendered: number;

0 commit comments

Comments
 (0)