wip(ssr): initial scaffold for compiler-ssr

This commit is contained in:
Evan You
2020-02-02 00:05:27 -05:00
parent 34e61197c7
commit efbbd19b3d
26 changed files with 496 additions and 36 deletions

View File

@@ -0,0 +1,15 @@
import { NodeTransform, NodeTypes, ElementTypes } from '@vue/compiler-dom'
export const ssrTransformComponent: NodeTransform = (node, context) => {
if (
node.type === NodeTypes.ELEMENT &&
node.tagType === ElementTypes.COMPONENT
) {
return function ssrPostTransformComponent() {
// generate a _push(_renderComponent) call
// dynamic component as well
// !check if we need to bail out for slots
// TODO also handle scopeID here
}
}
}

View File

@@ -0,0 +1,70 @@
import {
NodeTransform,
NodeTypes,
ElementTypes,
TemplateLiteral,
createTemplateLiteral
} from '@vue/compiler-dom'
import { escapeHtml } from '@vue/server-renderer/src'
/*
## Simple Element
``` html
<div></div>
```
``` js
return function render(_ctx, _push, _parent) {
_push(`<div></div>`)
}
```
## Consecutive Elements
``` html
<div>
<span></span>
</div>
<div></div>
```
``` js
return function render(_ctx, _push, _parent) {
_push(`<div><span></span></div><div></div>`)
}
```
*/
export const ssrTransformElement: NodeTransform = (node, context) => {
if (
node.type === NodeTypes.ELEMENT &&
node.tagType === ElementTypes.ELEMENT
) {
return function ssrPostTransformElement() {
// element
// generate the template literal representing the open tag.
const openTag: TemplateLiteral['elements'] = [`<${node.tag}`]
for (let i = 0; i < node.props.length; i++) {
const prop = node.props[i]
if (prop.type === NodeTypes.DIRECTIVE) {
const directiveTransform = context.directiveTransforms[prop.name]
if (directiveTransform) {
// TODO directive transforms
} else {
// no corresponding ssr directive transform found.
// TODO emit error
}
} else {
// static prop
openTag.push(
` ${prop.name}` +
(prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
)
}
}
openTag.push(`>`)
node.ssrCodegenNode = createTemplateLiteral(openTag)
}
}
}

View File

@@ -0,0 +1,3 @@
import { NodeTransform } from '@vue/compiler-dom'
export const ssrTransformSlotOutlet: NodeTransform = () => {}

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1,3 @@
import { NodeTransform } from '@vue/compiler-dom'
export const ssrTransformFor: NodeTransform = () => {}

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1,3 @@
import { NodeTransform } from '@vue/compiler-dom'
export const ssrTransformIf: NodeTransform = () => {}

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1 @@
// TODO

View File

@@ -0,0 +1 @@
// TODO