mirror of https://github.com/vuejs/core.git
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,
|
TemplateLiteral,
|
||||||
createCallExpression,
|
createCallExpression,
|
||||||
createTemplateLiteral,
|
createTemplateLiteral,
|
||||||
locStub,
|
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
TemplateChildNode,
|
TemplateChildNode,
|
||||||
ElementTypes
|
ElementTypes,
|
||||||
|
createBlockStatement
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import { isString } from '@vue/shared'
|
import { isString } from '@vue/shared'
|
||||||
|
|
||||||
|
@ -30,11 +30,7 @@ export function ssrCodegenTransform(ast: RootNode) {
|
||||||
context.pushStringPart(`<!---->`)
|
context.pushStringPart(`<!---->`)
|
||||||
}
|
}
|
||||||
|
|
||||||
ast.codegenNode = {
|
ast.codegenNode = createBlockStatement(context.body)
|
||||||
type: NodeTypes.JS_BLOCK_STATEMENT,
|
|
||||||
loc: locStub,
|
|
||||||
body: context.body
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SSRTransformContext = ReturnType<typeof createSSRTransformContext>
|
type SSRTransformContext = ReturnType<typeof createSSRTransformContext>
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
TemplateLiteral,
|
TemplateLiteral,
|
||||||
createTemplateLiteral
|
createTemplateLiteral
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import { escapeHtml } from '@vue/server-renderer/src'
|
import { escapeHtml } from '@vue/server-renderer'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
## Simple Element
|
## Simple Element
|
||||||
|
|
Loading…
Reference in New Issue