refactor(compiler): refine codegen node types
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`compiler: codegen ArrayExpression 1`] = `
|
||||
"
|
||||
return function render() {
|
||||
with (this) {
|
||||
return [
|
||||
foo,
|
||||
bar(baz)
|
||||
]
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`compiler: codegen ConditionalExpression 1`] = `
|
||||
"
|
||||
return function render() {
|
||||
@@ -13,7 +25,7 @@ return function render() {
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`compiler: codegen Element (callExpression + objectExpression + arrayExpression) 1`] = `
|
||||
exports[`compiler: codegen Element (callExpression + objectExpression + TemplateChildNode[]) 1`] = `
|
||||
"
|
||||
return function render() {
|
||||
with (this) {
|
||||
@@ -23,10 +35,7 @@ return function render() {
|
||||
[foo + bar]: bar
|
||||
}, [
|
||||
_createVNode(\\"p\\", { \\"some-key\\": \\"foo\\" })
|
||||
], [
|
||||
foo,
|
||||
_createVNode(\\"p\\")
|
||||
])
|
||||
], 16)
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,9 @@ import {
|
||||
createInterpolation,
|
||||
createSequenceExpression,
|
||||
createCallExpression,
|
||||
createConditionalExpression
|
||||
createConditionalExpression,
|
||||
IfCodegenNode,
|
||||
ForCodegenNode
|
||||
} from '../src'
|
||||
import {
|
||||
CREATE_VNODE,
|
||||
@@ -22,6 +24,7 @@ import {
|
||||
RESOLVE_COMPONENT
|
||||
} from '../src/runtimeHelpers'
|
||||
import { createElementWithCodegen } from './testUtils'
|
||||
import { PatchFlags } from 'vue'
|
||||
|
||||
function createRoot(options: Partial<RootNode> = {}): RootNode {
|
||||
return {
|
||||
@@ -205,7 +208,7 @@ describe('compiler: codegen', () => {
|
||||
codegenNode: createSequenceExpression([
|
||||
createSimpleExpression('foo', false),
|
||||
createSimpleExpression('bar', false)
|
||||
])
|
||||
]) as IfCodegenNode
|
||||
}
|
||||
})
|
||||
)
|
||||
@@ -227,7 +230,7 @@ describe('compiler: codegen', () => {
|
||||
codegenNode: createSequenceExpression([
|
||||
createSimpleExpression('foo', false),
|
||||
createSimpleExpression('bar', false)
|
||||
])
|
||||
]) as ForCodegenNode
|
||||
}
|
||||
})
|
||||
)
|
||||
@@ -235,7 +238,7 @@ describe('compiler: codegen', () => {
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('Element (callExpression + objectExpression + arrayExpression)', () => {
|
||||
test('Element (callExpression + objectExpression + TemplateChildNode[])', () => {
|
||||
const { code } = generate(
|
||||
createRoot({
|
||||
codegenNode: createElementWithCodegen([
|
||||
@@ -283,19 +286,8 @@ describe('compiler: codegen', () => {
|
||||
)
|
||||
])
|
||||
],
|
||||
// ArrayExpression
|
||||
createArrayExpression(
|
||||
[
|
||||
'foo',
|
||||
{
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
loc: locStub,
|
||||
callee: CREATE_VNODE,
|
||||
arguments: [`"p"`]
|
||||
}
|
||||
],
|
||||
locStub
|
||||
)
|
||||
// flag
|
||||
PatchFlags.FULL_PROPS + ''
|
||||
])
|
||||
})
|
||||
)
|
||||
@@ -306,10 +298,23 @@ describe('compiler: codegen', () => {
|
||||
[foo + bar]: bar
|
||||
}, [
|
||||
_${helperNameMap[CREATE_VNODE]}("p", { "some-key": "foo" })
|
||||
], [
|
||||
], ${PatchFlags.FULL_PROPS})`)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('ArrayExpression', () => {
|
||||
const { code } = generate(
|
||||
createRoot({
|
||||
codegenNode: createArrayExpression([
|
||||
createSimpleExpression(`foo`, false),
|
||||
createCallExpression(`bar`, [`baz`])
|
||||
])
|
||||
})
|
||||
)
|
||||
expect(code).toMatch(`return [
|
||||
foo,
|
||||
_${helperNameMap[CREATE_VNODE]}("p")
|
||||
])`)
|
||||
bar(baz)
|
||||
]`)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
NodeTypes,
|
||||
CallExpression,
|
||||
ElementNode,
|
||||
locStub,
|
||||
Namespaces,
|
||||
ElementTypes
|
||||
ElementTypes,
|
||||
ElementCodegenNode
|
||||
} from '../src'
|
||||
import { CREATE_VNODE } from '../src/runtimeHelpers'
|
||||
import { isString } from '@vue/shared'
|
||||
@@ -39,7 +39,7 @@ export function createObjectMatcher(obj: any) {
|
||||
}
|
||||
|
||||
export function createElementWithCodegen(
|
||||
args: CallExpression['arguments']
|
||||
args: ElementCodegenNode['arguments']
|
||||
): ElementNode {
|
||||
return {
|
||||
type: NodeTypes.ELEMENT,
|
||||
|
||||
Reference in New Issue
Block a user