test(compiler-ssr): test for ssr element transform
This commit is contained in:
parent
8fd9e9ba97
commit
327670a034
@ -0,0 +1,25 @@
|
||||
import { compile } from '../../src'
|
||||
|
||||
function getElementString(src: string): string {
|
||||
return compile(src).code.match(/_push\((.*)\)/)![1]
|
||||
}
|
||||
|
||||
describe('ssr transform element', () => {
|
||||
test('basic elements', () => {
|
||||
expect(getElementString(`<div></div>`)).toMatchInlineSnapshot(
|
||||
`"\`<div></div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('static attrs', () => {
|
||||
expect(
|
||||
getElementString(`<div id="foo" class="bar"></div>`)
|
||||
).toMatchInlineSnapshot(`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`)
|
||||
})
|
||||
|
||||
test('nested elements', () => {
|
||||
expect(
|
||||
getElementString(`<div><span></span><span></span></div>`)
|
||||
).toMatchInlineSnapshot(`"\`<div><span></span><span></span></div>\`"`)
|
||||
})
|
||||
})
|
@ -5,10 +5,10 @@ import {
|
||||
TemplateLiteral,
|
||||
createCallExpression,
|
||||
createTemplateLiteral,
|
||||
locStub,
|
||||
NodeTypes,
|
||||
TemplateChildNode,
|
||||
ElementTypes
|
||||
ElementTypes,
|
||||
createBlockStatement
|
||||
} from '@vue/compiler-dom'
|
||||
import { isString } from '@vue/shared'
|
||||
|
||||
@ -30,11 +30,7 @@ export function ssrCodegenTransform(ast: RootNode) {
|
||||
context.pushStringPart(`<!---->`)
|
||||
}
|
||||
|
||||
ast.codegenNode = {
|
||||
type: NodeTypes.JS_BLOCK_STATEMENT,
|
||||
loc: locStub,
|
||||
body: context.body
|
||||
}
|
||||
ast.codegenNode = createBlockStatement(context.body)
|
||||
}
|
||||
|
||||
type SSRTransformContext = ReturnType<typeof createSSRTransformContext>
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
TemplateLiteral,
|
||||
createTemplateLiteral
|
||||
} from '@vue/compiler-dom'
|
||||
import { escapeHtml } from '@vue/server-renderer/src'
|
||||
import { escapeHtml } from '@vue/server-renderer'
|
||||
|
||||
/*
|
||||
## Simple Element
|
||||
|
Loading…
Reference in New Issue
Block a user