@@ -6593,25 +6593,42 @@ function createPromiseCallback () {
6593
6593
}
6594
6594
6595
6595
/**
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
6599
6608
*/
6600
6609
function getVNodeAstChildren(ast) {
6601
6610
var children = null;
6602
6611
if (ast.type === 'CallExpression') {
6603
6612
try {
6604
6613
children = ast.arguments.filter(function (v) { return v.type === 'ArrayExpression'; })[0];
6605
6614
} catch(e) {
6606
- console.error('获取虚拟 dom 子元素失败,请查看 ast ', ast);
6615
+ console.error('To get the virtual DOM sub-element failed, see AST ', ast);
6607
6616
}
6608
6617
}
6609
6618
return children
6610
6619
}
6611
6620
6612
6621
/**
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
6615
6632
*/
6616
6633
function isSSRNodeAst(ast) {
6617
6634
return ast && types.isCallExpression(ast) &&
@@ -6620,6 +6637,15 @@ function isSSRNodeAst(ast) {
6620
6637
ast.callee.property.name === '_ssrNode'
6621
6638
}
6622
6639
6640
+ /**
6641
+ * English:
6642
+ * Recursively obtain the leftmost string in a string splicing expression
6643
+ *
6644
+ * 中文:
6645
+ * 递归获取字符串拼接表达式中最左边的字符串
6646
+ *
6647
+ * @param {Object} ast
6648
+ */
6623
6649
function getLeftStringLiteral(ast) {
6624
6650
if (types.isBinaryExpression(ast)) {
6625
6651
return getLeftStringLiteral(ast.left)
@@ -6628,6 +6654,15 @@ function getLeftStringLiteral(ast) {
6628
6654
}
6629
6655
}
6630
6656
6657
+ /**
6658
+ * English:
6659
+ * Recursively obtain the rightmost string in a string splicing expression
6660
+ *
6661
+ * 中文:
6662
+ * 递归获取字符串拼接表达式中最右边的字符串
6663
+ *
6664
+ * @param {Object} ast
6665
+ */
6631
6666
function getRightStringLiteral(ast) {
6632
6667
if (types.isBinaryExpression(ast)) {
6633
6668
return getRightStringLiteral(ast.right)
@@ -6637,33 +6672,43 @@ function getRightStringLiteral(ast) {
6637
6672
}
6638
6673
6639
6674
/**
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'
6641
6685
*/
6642
6686
function binaryExpressionPlus(left, right) {
6643
- // 两个都是纯字符串,直接做字符串拼接
6644
6687
if (types.isStringLiteral(left) && types.isStringLiteral(right)) {
6645
6688
return types.stringLiteral(left.value + right.value)
6646
6689
}
6647
- // 左边是纯字符串,右边是表达式
6648
6690
else if (types.isStringLiteral(left) && types.isBinaryExpression(right)) {
6649
6691
var mostLeft = getLeftStringLiteral(right);
6650
6692
mostLeft.value = left.value + mostLeft.value;
6651
6693
return right
6652
6694
}
6653
- // 左边是表达式,右边是纯字符串
6654
6695
else if (types.isBinaryExpression(left) && types.isStringLiteral(right)) {
6655
6696
var mostRight = getRightStringLiteral(left);
6656
6697
mostRight.value = mostRight.value + right.value;
6657
6698
return left
6658
6699
}
6659
- // 两边都是表达式
6660
6700
else {
6661
6701
return types.binaryExpression('+', left, right)
6662
6702
}
6663
6703
}
6664
6704
6665
6705
/**
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
+ *
6667
6712
* @param {Object} ast
6668
6713
*/
6669
6714
function getStatisAstComponentValue(ast) {
@@ -6684,9 +6729,20 @@ function getStatisAstComponentValue(ast) {
6684
6729
}
6685
6730
6686
6731
/**
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
6690
6746
*/
6691
6747
function getVNodeRenderAst(ast) {
6692
6748
var vNodeAst;
@@ -6704,11 +6760,16 @@ function getVNodeRenderAst(ast) {
6704
6760
}
6705
6761
6706
6762
/**
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:
6709
6770
* vm._ssrNode('<div id="xx"/>')
6710
- * @param {*} node
6711
- * @param {* } node
6771
+ *
6772
+ * @param {Object } node ast
6712
6773
*/
6713
6774
function isSSRNodeCallExpression(node) {
6714
6775
if (!types.isCallExpression(node)) {
@@ -6728,8 +6789,13 @@ function isSSRNodeCallExpression(node) {
6728
6789
}
6729
6790
6730
6791
/**
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:
6733
6799
* _c("div", [_vm._v("8")])
6734
6800
* @param {*} node
6735
6801
*/
@@ -6751,8 +6817,13 @@ function isCCallExpression(node) {
6751
6817
}
6752
6818
6753
6819
/**
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:
6756
6827
* _vm._l()
6757
6828
* @param {*} node
6758
6829
*/
@@ -9584,12 +9655,6 @@ function rewriteTraceLine (trace, mapConsumers) {
9584
9655
/* */
9585
9656
var vm$1 = require('vm');
9586
9657
9587
- /**
9588
- * ast.ssrString 如果有值,则表示当前节点是静态节点,但不一定表示子节点是静态节点
9589
- * ast.ssrStatic === true,表示当前节点和子节点都是静态节点
9590
- * ast.unMatchedAst === true,表示当前节点没有匹配到抽象语法树,这种情况只有当节点和子节点全部都为静态,才做优化
9591
- */
9592
-
9593
9658
9594
9659
9595
9660
var PatchContext = function PatchContext (options) {
@@ -22850,7 +22915,7 @@ function getParserClass(pluginsFromOptions) {
22850
22915
exports.parse = parse;
22851
22916
exports.parseExpression = parseExpression;
22852
22917
exports.tokTypes = types;
22853
- //# sourceMappingURL=index.js.map
22918
+
22854
22919
});
22855
22920
22856
22921
unwrapExports(lib);
@@ -22995,7 +23060,7 @@ function renderStartingTag$1 (node, context, activeInstance) {
22995
23060
/**
22996
23061
* 计算条件表达式的语法树的值
22997
23062
* @param {context} context 抽象语法树的上下文
22998
- * @param {Object} ast 抽象语法树
23063
+ * @param {Object} ast
22999
23064
*/
23000
23065
23001
23066
function calcuConditionalExpression(context, ast) {
@@ -23056,11 +23121,11 @@ function setVNodeChildrenAst(node, ast, context) {
23056
23121
/**
23057
23122
* 比较组件节点
23058
23123
* 所有其他类型都经过 patchComponent 产生
23059
- * ssr 推导优化通过截取 _render 函数,仅执行必要的 render 达到渲染提速的目的
23060
23124
*
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
23064
23129
*/
23065
23130
function patchComponent(staticVNode, dynamicVNode, patchContext, isRoot) {
23066
23131
var ast = staticVNode.ast;
@@ -23125,9 +23190,10 @@ function patchComponent(staticVNode, dynamicVNode, patchContext, isRoot) {
23125
23190
/**
23126
23191
* 比较异步组件
23127
23192
*
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
23131
23197
*/
23132
23198
function patchAsyncComponent(staticVNode, dynamicVNode, patchContext, isRoot) {
23133
23199
var ast = staticVNode.ast;
@@ -23231,9 +23297,9 @@ function getResolevdNode(node, comp) {
23231
23297
/**
23232
23298
* 比较字符串型节点,这种节点为 ssr 特有,是模板编译器的一种渲染优化
23233
23299
*
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
23237
23303
*/
23238
23304
function patchStringNode(staticVNode, dynamicVNode, patchContext) {
23239
23305
var ast = staticVNode.ast;
@@ -23266,10 +23332,10 @@ function patchStringNode(staticVNode, dynamicVNode, patchContext) {
23266
23332
/**
23267
23333
* 比较元素节点
23268
23334
*
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
23273
23339
*/
23274
23340
function patchElement(staticVNode, dynamicVNode, patchContext, isRoot) {
23275
23341
if (isTrue(isRoot)) {
@@ -23317,42 +23383,29 @@ function patchElement(staticVNode, dynamicVNode, patchContext, isRoot) {
23317
23383
23318
23384
/**
23319
23385
* 对比虚拟 dom ,收集静态节点与动态节点
23320
- * 静态节点拼接成字符串
23321
- * 动态节点包装成执行函数
23322
- *
23323
- * 注意:
23324
- * 1. 服务端的 diff 算法,算出不同之后,并不会操作当前 dynamicVNode,因为当前的 dynamicVNode 沾染了用户数据,
23325
- * 但是 dynamicVNode 的 parentVNode 仍然是静态节点,推导优化通过 dynamicVNode.parentVNode + 当前
23326
- * 用户上下文 生成动态的字符串。
23327
- * 2. 为了确保用户数据安全,所有作为字符串生成参数的 VNode ,只能用 dynamicVNode
23328
23386
*
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
23332
23391
*/
23333
23392
function patchNode(staticVNode, dynamicVNode, patchContext, isRoot) {
23334
23393
23335
23394
var ast = staticVNode.ast;
23336
23395
23337
- // 字符串节点,这是模板引擎对ssr的一种优化
23338
23396
if (staticVNode.isString && dynamicVNode.isString) {
23339
23397
patchStringNode(staticVNode, dynamicVNode, patchContext);
23340
23398
}
23341
- // 组件节点,ssr 性能瓶颈
23342
23399
else if (isDef(staticVNode.componentOptions) && isDef(dynamicVNode.componentOptions)) {
23343
23400
patchComponent(staticVNode, dynamicVNode, patchContext, isRoot);
23344
23401
}
23345
- // 元素节点
23346
23402
else if (isDef(staticVNode.tag) && isDef(dynamicVNode.tag)) {
23347
23403
patchElement(staticVNode, dynamicVNode, patchContext, isRoot);
23348
23404
}
23349
- // 注释节点/异步组件
23350
23405
else if (isTrue(staticVNode.isComment) && isTrue(dynamicVNode.isComment)) {
23351
- // 异步组件
23352
23406
if (isDef(staticVNode.asyncFactory) && isDef(dynamicVNode.asyncFactory)) {
23353
23407
patchAsyncComponent(staticVNode, dynamicVNode, patchContext, isRoot);
23354
23408
}
23355
- // 注释节点
23356
23409
else {
23357
23410
if (staticVNode.text === dynamicVNode.text) {
23358
23411
ast.ssrString = "<!--" + (staticVNode.text) + "-->";
@@ -23361,7 +23414,6 @@ function patchNode(staticVNode, dynamicVNode, patchContext, isRoot) {
23361
23414
patchContext.next();
23362
23415
}
23363
23416
}
23364
- // 文本节点
23365
23417
else if (isDef(staticVNode.text) && isDef(dynamicVNode.text)){
23366
23418
var staticText = staticVNode.raw ? staticVNode.text : escape(String(staticVNode.text));
23367
23419
var dynamicText = dynamicVNode.raw ? dynamicVNode.text : escape(String(dynamicVNode.text));
@@ -23381,9 +23433,19 @@ function createPatchFunction (ref) {
23381
23433
var isUnaryTag = ref.isUnaryTag;
23382
23434
var cache = ref.cache;
23383
23435
23436
+ /**
23437
+ * 中文:
23438
+ * VNode diff
23439
+ * 如果检测到节点是静态的,修改的是静态组件的 ast (staticAst)
23440
+ * 如果检测到节点是动态的
23441
+ * staticAst 不做任何网络请求
23442
+ * ast.ssrString 如果有值,则表示当前节点是静态节点,但不一定表示子节点是静态节点
23443
+ * ast.ssrStatic === true,表示当前节点和子节点都是静态节点
23444
+ * ast.unMatchedAst === true,表示当前节点没有匹配到抽象语法树,这种情况只有当节点和子节点全部都为静态,才做优化
23445
+ */
23384
23446
return function patcher (
23385
- staticComponent, // 静态实例
23386
- dynamiComponent, // 动态实例
23447
+ staticComponent,
23448
+ dynamiComponent,
23387
23449
userContext,
23388
23450
done
23389
23451
) {
0 commit comments