chore:更换到主分支

This commit is contained in:
张益铭
2021-03-01 15:26:05 +08:00
parent 9064b372e8
commit 6a5f1810f9
3530 changed files with 59613 additions and 479452 deletions

View File

@@ -21,7 +21,6 @@ const SSR_RENDER_DYNAMIC_MODEL = Symbol(`ssrRenderDynamicModel`);
const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(`ssrGetDynamicModelProps`);
const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`);
const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`);
const SSR_RESOLVE_CSS_VARS = Symbol(`ssrResolveCssVars`);
const ssrHelpers = {
[SSR_INTERPOLATE]: `ssrInterpolate`,
[SSR_RENDER_VNODE]: `ssrRenderVNode`,
@@ -38,8 +37,7 @@ const ssrHelpers = {
[SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
[SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
[SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
[SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
[SSR_RESOLVE_CSS_VARS]: `ssrResolveCssVars`
[SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`
};
// Note: these are helpers imported from @vue/server-renderer
// make sure the names match!
@@ -49,14 +47,14 @@ compilerDom.registerRuntimeHelpers(ssrHelpers);
const ssrTransformIf = compilerDom.createStructuralDirectiveTransform(/^(if|else|else-if)$/, compilerDom.processIf);
// This is called during the 2nd transform pass to construct the SSR-specific
// codegen nodes.
function ssrProcessIf(node, context) {
function ssrProcessIf(node, context, disableNestedFragments = false) {
const [rootBranch] = node.branches;
const ifStatement = compilerDom.createIfStatement(rootBranch.condition, processIfBranch(rootBranch, context));
const ifStatement = compilerDom.createIfStatement(rootBranch.condition, processIfBranch(rootBranch, context, disableNestedFragments));
context.pushStatement(ifStatement);
let currentIf = ifStatement;
for (let i = 1; i < node.branches.length; i++) {
const branch = node.branches[i];
const branchBlockStatement = processIfBranch(branch, context);
const branchBlockStatement = processIfBranch(branch, context, disableNestedFragments);
if (branch.condition) {
// else-if
currentIf = currentIf.alternate = compilerDom.createIfStatement(branch.condition, branchBlockStatement);
@@ -72,9 +70,10 @@ function ssrProcessIf(node, context) {
]);
}
}
function processIfBranch(branch, context) {
function processIfBranch(branch, context, disableNestedFragments = false) {
const { children } = branch;
const needFragmentWrapper = (children.length !== 1 || children[0].type !== 1 /* ELEMENT */) &&
const needFragmentWrapper = !disableNestedFragments &&
(children.length !== 1 || children[0].type !== 1 /* ELEMENT */) &&
// optimize away nested fragments when the only child is a ForNode
!(children.length === 1 && children[0].type === 11 /* FOR */);
return processChildrenAsStatement(children, context, needFragmentWrapper);
@@ -84,17 +83,22 @@ function processIfBranch(branch, context) {
const ssrTransformFor = compilerDom.createStructuralDirectiveTransform('for', compilerDom.processFor);
// This is called during the 2nd transform pass to construct the SSR-specific
// codegen nodes.
function ssrProcessFor(node, context) {
const needFragmentWrapper = node.children.length !== 1 || node.children[0].type !== 1 /* ELEMENT */;
function ssrProcessFor(node, context, disableNestedFragments = false) {
const needFragmentWrapper = !disableNestedFragments &&
(node.children.length !== 1 || node.children[0].type !== 1 /* ELEMENT */);
const renderLoop = compilerDom.createFunctionExpression(compilerDom.createForLoopParams(node.parseResult));
renderLoop.body = processChildrenAsStatement(node.children, context, needFragmentWrapper);
// v-for always renders a fragment
context.pushStringPart(`<!--[-->`);
// v-for always renders a fragment unless explicitly disabled
if (!disableNestedFragments) {
context.pushStringPart(`<!--[-->`);
}
context.pushStatement(compilerDom.createCallExpression(context.helper(SSR_RENDER_LIST), [
node.source,
renderLoop
]));
context.pushStringPart(`<!--]-->`);
if (!disableNestedFragments) {
context.pushStringPart(`<!--]-->`);
}
}
const ssrTransformSlotOutlet = (node, context) => {
@@ -214,6 +218,39 @@ function ssrProcessSuspense(node, context) {
]));
}
function ssrProcessTransitionGroup(node, context) {
const tag = compilerDom.findProp(node, 'tag');
if (tag) {
if (tag.type === 7 /* DIRECTIVE */) {
// dynamic :tag
context.pushStringPart(`<`);
context.pushStringPart(tag.exp);
context.pushStringPart(`>`);
processChildren(node.children, context, false,
/**
* TransitionGroup has the special runtime behavior of flattening and
* concatenating all children into a single fragment (in order for them to
* be pathced using the same key map) so we need to account for that here
* by disabling nested fragment wrappers from being generated.
*/
true);
context.pushStringPart(`</`);
context.pushStringPart(tag.exp);
context.pushStringPart(`>`);
}
else {
// static tag
context.pushStringPart(`<${tag.value.content}>`);
processChildren(node.children, context, false, true);
context.pushStringPart(`</${tag.value.content}>`);
}
}
else {
// fragment
processChildren(node.children, context, true, true);
}
}
// We need to construct the slot functions in the 1st pass to ensure proper
// scope tracking, but the children of each slot cannot be processed until
// the 2nd pass, so we store the WIP slot functions in a weakmap during the 1st
@@ -309,9 +346,12 @@ function ssrProcessComponent(node, context) {
else if (component === compilerDom.SUSPENSE) {
return ssrProcessSuspense(node, context);
}
else if (component === compilerDom.TRANSITION_GROUP) {
return ssrProcessTransitionGroup(node, context);
}
else {
// real fall-through (e.g. KeepAlive): just render its children.
processChildren(node.children, context, component === compilerDom.TRANSITION_GROUP);
processChildren(node.children, context);
}
}
else {
@@ -395,11 +435,15 @@ function subTransform(node, options, parentContext) {
childContext.identifiers = { ...parentContext.identifiers };
// traverse
compilerDom.traverseNode(childRoot, childContext);
['helpers', 'components', 'directives', 'imports'].forEach(key => {
['helpers', 'components', 'directives'].forEach(key => {
childContext[key].forEach((value) => {
parentContext[key].add(value);
});
});
// imports/hoists are not merged because:
// - imports are only used for asset urls and should be consistent between
// node/client branches
// - hoists are not enabled for the client branch here
}
function clone(v) {
if (shared.isArray(v)) {
@@ -494,6 +538,10 @@ const ssrTransformElement = (node, context) => {
let dynamicStyleBinding = undefined;
for (let i = 0; i < node.props.length; i++) {
const prop = node.props[i];
// ignore true-value/false-value on input
if (node.tag === 'input' && isTrueFalseValue(prop)) {
continue;
}
// special cases with children override
if (prop.type === 7 /* DIRECTIVE */) {
if (prop.name === 'html' && prop.exp) {
@@ -527,6 +575,9 @@ const ssrTransformElement = (node, context) => {
if (compilerDom.isStaticExp(key)) {
let attrName = key.content;
// static key attr
if (attrName === 'key' || attrName === 'ref') {
continue;
}
if (attrName === 'class') {
openTag.push(` class="`, (dynamicClassBinding = compilerDom.createCallExpression(context.helper(SSR_RENDER_CLASS), [value])), `"`);
}
@@ -578,6 +629,9 @@ const ssrTransformElement = (node, context) => {
rawChildrenMap.set(node, shared.escapeHtml(prop.value.content));
}
else if (!hasDynamicVBind) {
if (prop.name === 'key' || prop.name === 'ref') {
continue;
}
// static prop
if (prop.name === 'class' && prop.value) {
staticClassBinding = JSON.stringify(prop.value.content);
@@ -598,6 +652,17 @@ const ssrTransformElement = (node, context) => {
node.ssrCodegenNode = compilerDom.createTemplateLiteral(openTag);
};
};
function isTrueFalseValue(prop) {
if (prop.type === 7 /* DIRECTIVE */) {
return (prop.name === 'bind' &&
prop.arg &&
compilerDom.isStaticExp(prop.arg) &&
(prop.arg.content === 'true-value' || prop.arg.content === 'false-value'));
}
else {
return prop.name === 'true-value' || prop.name === 'false-value';
}
}
function isTextareaWithValue(node, prop) {
return !!(node.tag === 'textarea' &&
prop.name === 'bind' &&
@@ -654,17 +719,12 @@ function ssrProcessElement(node, context) {
// passing it to codegen.
function ssrCodegenTransform(ast, options) {
const context = createSSRTransformContext(ast, options);
// inject <style vars> resolution
// inject SFC <style> CSS variables
// we do this instead of inlining the expression to ensure the vars are
// only resolved once per render
if (options.ssrCssVars) {
const varsExp = compilerDom.processExpression(compilerDom.createSimpleExpression(options.ssrCssVars, false), compilerDom.createTransformContext(compilerDom.createRoot([]), options));
context.body.push(compilerDom.createCompoundExpression([
`const _cssVars = _${ssrHelpers[SSR_RESOLVE_CSS_VARS]}(`,
varsExp,
options.scopeId ? `, ${JSON.stringify(options.scopeId)}` : ``,
`)`
]));
context.body.push(compilerDom.createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`]));
}
const isFragment = ast.children.length > 1 && ast.children.some(c => !compilerDom.isText(c));
processChildren(ast.children, context, isFragment);
@@ -721,7 +781,7 @@ function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
// ensure child inherits parent helpers
return createSSRTransformContext(parent.root, parent.options, parent.helpers, withSlotScopeId);
}
function processChildren(children, context, asFragment = false) {
function processChildren(children, context, asFragment = false, disableNestedFragments = false) {
if (asFragment) {
context.pushStringPart(`<!--[-->`);
}
@@ -761,10 +821,10 @@ function processChildren(children, context, asFragment = false) {
context.pushStringPart(compilerDom.createCallExpression(context.helper(SSR_INTERPOLATE), [child.content]));
break;
case 9 /* IF */:
ssrProcessIf(child, context);
ssrProcessIf(child, context, disableNestedFragments);
break;
case 11 /* FOR */:
ssrProcessFor(child, context);
ssrProcessFor(child, context, disableNestedFragments);
break;
case 10 /* IF_BRANCH */:
// no-op - handled by ssrProcessIf
@@ -831,12 +891,26 @@ const ssrTransformModel = (dir, node, context) => {
];
break;
case 'checkbox':
res.props = [
compilerDom.createObjectProperty(`checked`, compilerDom.createConditionalExpression(compilerDom.createCallExpression(`Array.isArray`, [model]), compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
model,
value
]), model))
];
const trueValueBinding = compilerDom.findProp(node, 'true-value');
if (trueValueBinding) {
const trueValue = trueValueBinding.type === 6 /* ATTRIBUTE */
? JSON.stringify(trueValueBinding.value.content)
: trueValueBinding.exp;
res.props = [
compilerDom.createObjectProperty(`checked`, compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
model,
trueValue
]))
];
}
else {
res.props = [
compilerDom.createObjectProperty(`checked`, compilerDom.createConditionalExpression(compilerDom.createCallExpression(`Array.isArray`, [model]), compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
model,
value
]), model))
];
}
break;
case 'file':
context.onError(compilerDom.createDOMCompilerError(55 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
@@ -941,7 +1015,6 @@ const ssrInjectCssVars = (node, context) => {
if (!parent || parent.type !== 0 /* ROOT */) {
return;
}
context.helper(SSR_RESOLVE_CSS_VARS);
if (node.type === 10 /* IF_BRANCH */) {
for (const child of node.children) {
injectCssVars(child);
@@ -956,14 +1029,28 @@ function injectCssVars(node) {
(node.tagType === 0 /* ELEMENT */ ||
node.tagType === 1 /* COMPONENT */) &&
!compilerDom.findDir(node, 'for')) {
node.props.push({
type: 7 /* DIRECTIVE */,
name: 'bind',
arg: undefined,
exp: compilerDom.createSimpleExpression(`_cssVars`, false),
modifiers: [],
loc: compilerDom.locStub
});
if (compilerDom.isBuiltInType(node.tag, 'Suspense')) {
for (const child of node.children) {
if (child.type === 1 /* ELEMENT */ &&
child.tagType === 3 /* TEMPLATE */) {
// suspense slot
child.children.forEach(injectCssVars);
}
else {
injectCssVars(child);
}
}
}
else {
node.props.push({
type: 7 /* DIRECTIVE */,
name: 'bind',
arg: undefined,
exp: compilerDom.createSimpleExpression(`_cssVars`, false),
modifiers: [],
loc: compilerDom.locStub
});
}
}
}

View File

@@ -1,34 +1,33 @@
{
"_args": [
[
"@vue/compiler-ssr@3.0.2",
"@vue/compiler-ssr@3.0.6",
"J:\\Github\\CURD-TS"
]
],
"_development": true,
"_from": "@vue/compiler-ssr@3.0.2",
"_id": "@vue/compiler-ssr@3.0.2",
"_from": "@vue/compiler-ssr@3.0.6",
"_id": "@vue/compiler-ssr@3.0.6",
"_inBundle": false,
"_integrity": "sha1-c69NJ0p5v8xyqZaptF8QcufeqiY=",
"_integrity": "sha1-cVY2HkxGXL7icjJ17cYelAZ45Hw=",
"_location": "/@vue/compiler-ssr",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@vue/compiler-ssr@3.0.2",
"raw": "@vue/compiler-ssr@3.0.6",
"name": "@vue/compiler-ssr",
"escapedName": "@vue%2fcompiler-ssr",
"scope": "@vue",
"rawSpec": "3.0.2",
"rawSpec": "3.0.6",
"saveSpec": null,
"fetchSpec": "3.0.2"
"fetchSpec": "3.0.6"
},
"_requiredBy": [
"/@vue/compiler-sfc",
"/@vue/server-renderer"
"/@vue/compiler-sfc"
],
"_resolved": "http://192.168.250.101:4873/@vue%2fcompiler-ssr/-/compiler-ssr-3.0.2.tgz",
"_spec": "3.0.2",
"_resolved": "http://192.168.250.101:4873/@vue%2fcompiler-ssr/-/compiler-ssr-3.0.6.tgz",
"_spec": "3.0.6",
"_where": "J:\\Github\\CURD-TS",
"author": {
"name": "Evan You"
@@ -43,8 +42,8 @@
]
},
"dependencies": {
"@vue/compiler-dom": "3.0.2",
"@vue/shared": "3.0.2"
"@vue/compiler-dom": "3.0.6",
"@vue/shared": "3.0.6"
},
"description": "@vue/compiler-ssr",
"files": [
@@ -63,5 +62,5 @@
"directory": "packages/compiler-ssr"
},
"types": "dist/compiler-ssr.d.ts",
"version": "3.0.2"
"version": "3.0.6"
}