mirror of https://github.com/vuejs/core.git
refactor(compiler-vapor): split block & root ir node
This commit is contained in:
parent
531f4f0052
commit
0e0ee5b85e
|
@ -24,13 +24,13 @@ describe('compiler: element transform', () => {
|
|||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(code).contains('<div id=\\"foo\\" class=\\"bar\\"></div>"')
|
||||
expect(ir.effect.length).toBe(0)
|
||||
expect(ir.block.effect).lengthOf(0)
|
||||
})
|
||||
|
||||
test('v-bind="obj"', () => {
|
||||
const { code, ir } = compileWithElementTransform(`<div v-bind="obj" />`)
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ describe('compiler: element transform', () => {
|
|||
`<div id="foo" v-bind="obj" />`,
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ describe('compiler: element transform', () => {
|
|||
`<div v-bind="obj" id="foo" />`,
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -158,7 +158,7 @@ describe('compiler: element transform', () => {
|
|||
`<div id="foo" v-bind="obj" class="bar" />`,
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -225,7 +225,7 @@ describe('compiler: element transform', () => {
|
|||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
element: 1,
|
||||
|
@ -261,7 +261,7 @@ describe('compiler: element transform', () => {
|
|||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -306,7 +306,7 @@ describe('compiler: element transform', () => {
|
|||
|
||||
expect(code).toMatchSnapshot()
|
||||
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
|
|
@ -18,15 +18,15 @@ describe('compiler v-bind', () => {
|
|||
test('basic', () => {
|
||||
const { ir, code } = compileWithVBind(`<div v-bind:id="id"/>`)
|
||||
|
||||
expect(ir.dynamic.children[0]).toMatchObject({
|
||||
expect(ir.block.dynamic.children[0]).toMatchObject({
|
||||
id: 1,
|
||||
flags: DynamicFlag.REFERENCED,
|
||||
})
|
||||
expect(ir.template).toEqual(['<div></div>'])
|
||||
expect(ir.effect).lengthOf(1)
|
||||
expect(ir.effect[0].expressions).lengthOf(1)
|
||||
expect(ir.effect[0].operations).lengthOf(1)
|
||||
expect(ir.effect[0]).toMatchObject({
|
||||
expect(ir.block.effect).lengthOf(1)
|
||||
expect(ir.block.effect[0].expressions).lengthOf(1)
|
||||
expect(ir.block.effect[0].operations).lengthOf(1)
|
||||
expect(ir.block.effect[0]).toMatchObject({
|
||||
expressions: [
|
||||
{
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
|
@ -80,7 +80,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:id />`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_PROP,
|
||||
prop: {
|
||||
key: {
|
||||
|
@ -110,7 +110,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div :camel-case />`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_PROP,
|
||||
prop: {
|
||||
key: {
|
||||
|
@ -133,7 +133,7 @@ describe('compiler v-bind', () => {
|
|||
`<div v-bind:[id]="id" v-bind:[title]="title" />`,
|
||||
)
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_DYNAMIC_PROPS,
|
||||
element: 1,
|
||||
props: [
|
||||
|
@ -179,7 +179,7 @@ describe('compiler v-bind', () => {
|
|||
`<div v-bind:[id]="id" foo="bar" checked />`,
|
||||
)
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_DYNAMIC_PROPS,
|
||||
element: 1,
|
||||
props: [
|
||||
|
@ -267,7 +267,7 @@ describe('compiler v-bind', () => {
|
|||
test('.camel modifier', () => {
|
||||
const { ir, code } = compileWithVBind(`<div v-bind:foo-bar.camel="id"/>`)
|
||||
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `fooBar`,
|
||||
|
@ -292,7 +292,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:foo-bar.camel />`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `fooBar`,
|
||||
|
@ -315,7 +315,7 @@ describe('compiler v-bind', () => {
|
|||
test('.camel modifier w/ dynamic arg', () => {
|
||||
const { ir, code } = compileWithVBind(`<div v-bind:[foo].camel="id"/>`)
|
||||
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_DYNAMIC_PROPS,
|
||||
props: [
|
||||
[
|
||||
|
@ -350,7 +350,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:fooBar.prop="id"/>`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `fooBar`,
|
||||
|
@ -374,7 +374,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:fooBar.prop />`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `fooBar`,
|
||||
|
@ -398,7 +398,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:[fooBar].prop="id"/>`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_DYNAMIC_PROPS,
|
||||
props: [
|
||||
[
|
||||
|
@ -431,7 +431,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div .fooBar="id"/>`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `fooBar`,
|
||||
|
@ -455,7 +455,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div .fooBar />`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `fooBar`,
|
||||
|
@ -479,7 +479,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:foo-bar.attr="id"/>`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `foo-bar`,
|
||||
|
@ -503,7 +503,7 @@ describe('compiler v-bind', () => {
|
|||
const { ir, code } = compileWithVBind(`<div v-bind:foo-bar.attr />`)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
prop: {
|
||||
key: {
|
||||
content: `foo-bar`,
|
||||
|
|
|
@ -28,7 +28,7 @@ describe('compiler: v-for', () => {
|
|||
expect(vaporHelpers).contains('createFor')
|
||||
expect(helpers.size).toBe(0)
|
||||
expect(ir.template).toEqual(['<div></div>'])
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.FOR,
|
||||
id: 1,
|
||||
|
@ -43,7 +43,7 @@ describe('compiler: v-for', () => {
|
|||
key: undefined,
|
||||
index: undefined,
|
||||
render: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 0,
|
||||
},
|
||||
keyProperty: {
|
||||
|
@ -52,13 +52,13 @@ describe('compiler: v-for', () => {
|
|||
},
|
||||
},
|
||||
])
|
||||
expect(ir.returns).toEqual([1])
|
||||
expect(ir.dynamic).toMatchObject({
|
||||
expect(ir.block.returns).toEqual([1])
|
||||
expect(ir.block.dynamic).toMatchObject({
|
||||
id: 0,
|
||||
children: { 0: { id: 1 } },
|
||||
})
|
||||
expect(ir.effect).toEqual([])
|
||||
expect((ir.operation[0] as ForIRNode).render.effect).lengthOf(1)
|
||||
expect(ir.block.effect).toEqual([])
|
||||
expect((ir.block.operation[0] as ForIRNode).render.effect).lengthOf(1)
|
||||
})
|
||||
|
||||
test('multi effect', () => {
|
||||
|
|
|
@ -23,8 +23,8 @@ describe('v-html', () => {
|
|||
expect(vaporHelpers).contains('setHtml')
|
||||
expect(helpers.size).toBe(0)
|
||||
|
||||
expect(ir.operation).toEqual([])
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.operation).toEqual([])
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -65,8 +65,8 @@ describe('v-html', () => {
|
|||
// children should have been removed
|
||||
expect(ir.template).toEqual(['<div></div>'])
|
||||
|
||||
expect(ir.operation).toEqual([])
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.operation).toEqual([])
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ describe('compiler: v-if', () => {
|
|||
expect(helpers.size).toBe(0)
|
||||
|
||||
expect(ir.template).toEqual(['<div></div>'])
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.IF,
|
||||
id: 1,
|
||||
|
@ -42,20 +42,20 @@ describe('compiler: v-if', () => {
|
|||
isStatic: false,
|
||||
},
|
||||
positive: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 0,
|
||||
},
|
||||
},
|
||||
])
|
||||
expect(ir.returns).toEqual([1])
|
||||
expect(ir.block.returns).toEqual([1])
|
||||
|
||||
expect(ir.dynamic).toMatchObject({
|
||||
expect(ir.block.dynamic).toMatchObject({
|
||||
id: 0,
|
||||
children: { 0: { id: 1 } },
|
||||
})
|
||||
|
||||
expect(ir.effect).toEqual([])
|
||||
expect((ir.operation[0] as IfIRNode).positive.effect).lengthOf(1)
|
||||
expect(ir.block.effect).toEqual([])
|
||||
expect((ir.block.operation[0] as IfIRNode).positive.effect).lengthOf(1)
|
||||
|
||||
expect(code).matchSnapshot()
|
||||
})
|
||||
|
@ -68,8 +68,8 @@ describe('compiler: v-if', () => {
|
|||
|
||||
expect(ir.template).toEqual(['<div></div>hello<p></p>'])
|
||||
|
||||
expect(ir.effect).toEqual([])
|
||||
expect((ir.operation[0] as IfIRNode).positive.effect).toMatchObject([
|
||||
expect(ir.block.effect).toEqual([])
|
||||
expect((ir.block.operation[0] as IfIRNode).positive.effect).toMatchObject([
|
||||
{
|
||||
operations: [
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ describe('compiler: v-if', () => {
|
|||
],
|
||||
},
|
||||
])
|
||||
expect((ir.operation[0] as IfIRNode).positive.dynamic).toMatchObject({
|
||||
expect((ir.block.operation[0] as IfIRNode).positive.dynamic).toMatchObject({
|
||||
id: 2,
|
||||
children: { 2: { id: 3 } },
|
||||
})
|
||||
|
@ -98,7 +98,7 @@ describe('compiler: v-if', () => {
|
|||
)
|
||||
expect(code).matchSnapshot()
|
||||
expect(ir.template).toEqual(['<div>hello</div>'])
|
||||
expect(ir.returns).toEqual([1, 3])
|
||||
expect(ir.block.returns).toEqual([1, 3])
|
||||
})
|
||||
|
||||
test.todo('v-if with v-once')
|
||||
|
@ -112,9 +112,9 @@ describe('compiler: v-if', () => {
|
|||
expect(ir.template).toEqual(['<div></div>', '<p></p>'])
|
||||
|
||||
expect(vaporHelpers).contains('createIf')
|
||||
expect(ir.effect).lengthOf(0)
|
||||
expect(ir.block.effect).lengthOf(0)
|
||||
expect(helpers).lengthOf(0)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.IF,
|
||||
id: 1,
|
||||
|
@ -124,16 +124,16 @@ describe('compiler: v-if', () => {
|
|||
isStatic: false,
|
||||
},
|
||||
positive: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 0,
|
||||
},
|
||||
negative: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 1,
|
||||
},
|
||||
},
|
||||
])
|
||||
expect(ir.returns).toEqual([1])
|
||||
expect(ir.block.returns).toEqual([1])
|
||||
})
|
||||
|
||||
test('v-if + v-else-if', () => {
|
||||
|
@ -143,7 +143,7 @@ describe('compiler: v-if', () => {
|
|||
expect(code).matchSnapshot()
|
||||
expect(ir.template).toEqual(['<div></div>', '<p></p>'])
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.IF,
|
||||
id: 1,
|
||||
|
@ -153,7 +153,7 @@ describe('compiler: v-if', () => {
|
|||
isStatic: false,
|
||||
},
|
||||
positive: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 0,
|
||||
},
|
||||
negative: {
|
||||
|
@ -164,13 +164,13 @@ describe('compiler: v-if', () => {
|
|||
isStatic: false,
|
||||
},
|
||||
positive: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
])
|
||||
expect(ir.returns).toEqual([1])
|
||||
expect(ir.block.returns).toEqual([1])
|
||||
})
|
||||
|
||||
test('v-if + v-else-if + v-else', () => {
|
||||
|
@ -180,23 +180,23 @@ describe('compiler: v-if', () => {
|
|||
expect(code).matchSnapshot()
|
||||
expect(ir.template).toEqual(['<div></div>', '<p></p>', 'fine'])
|
||||
|
||||
expect(ir.returns).toEqual([1])
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.returns).toEqual([1])
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.IF,
|
||||
id: 1,
|
||||
positive: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 0,
|
||||
},
|
||||
negative: {
|
||||
type: IRNodeTypes.IF,
|
||||
positive: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 1,
|
||||
},
|
||||
negative: {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
type: IRNodeTypes.BLOCK,
|
||||
templateIndex: 2,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -22,9 +22,9 @@ describe('v-on', () => {
|
|||
|
||||
expect(vaporHelpers).contains('on')
|
||||
expect(helpers.size).toBe(0)
|
||||
expect(ir.effect).toEqual([])
|
||||
expect(ir.block.effect).toEqual([])
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
element: 1,
|
||||
|
@ -87,9 +87,9 @@ describe('v-on', () => {
|
|||
expect(vaporHelpers).contains('on')
|
||||
expect(vaporHelpers).contains('renderEffect')
|
||||
expect(helpers.size).toBe(0)
|
||||
expect(ir.operation).toEqual([])
|
||||
expect(ir.block.operation).toEqual([])
|
||||
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
element: 1,
|
||||
key: {
|
||||
|
@ -126,9 +126,9 @@ describe('v-on', () => {
|
|||
expect(vaporHelpers).contains('on')
|
||||
expect(vaporHelpers).contains('renderEffect')
|
||||
expect(helpers.size).toBe(0)
|
||||
expect(ir.operation).toEqual([])
|
||||
expect(ir.block.operation).toEqual([])
|
||||
|
||||
expect(ir.effect[0].operations[0]).toMatchObject({
|
||||
expect(ir.block.effect[0].operations[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
element: 1,
|
||||
key: {
|
||||
|
@ -152,9 +152,9 @@ describe('v-on', () => {
|
|||
|
||||
expect(vaporHelpers).contains('on')
|
||||
expect(helpers.size).toBe(0)
|
||||
expect(ir.effect).toEqual([])
|
||||
expect(ir.block.effect).toEqual([])
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
element: 1,
|
||||
|
@ -198,7 +198,7 @@ describe('v-on', () => {
|
|||
test('should handle multiple inline statement', () => {
|
||||
const { ir, code } = compileWithVOn(`<div @click="foo();bar()"/>`)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: 'foo();bar()' },
|
||||
|
@ -217,7 +217,7 @@ describe('v-on', () => {
|
|||
test('should handle multi-line statement', () => {
|
||||
const { code, ir } = compileWithVOn(`<div @click="\nfoo();\nbar()\n"/>`)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: '\nfoo();\nbar()\n' },
|
||||
|
@ -238,7 +238,7 @@ describe('v-on', () => {
|
|||
prefixIdentifiers: true,
|
||||
})
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: 'foo($event)' },
|
||||
|
@ -257,7 +257,7 @@ describe('v-on', () => {
|
|||
prefixIdentifiers: true,
|
||||
})
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: 'foo($event);bar()' },
|
||||
|
@ -274,7 +274,7 @@ describe('v-on', () => {
|
|||
test('should NOT wrap as function if expression is already function expression', () => {
|
||||
const { code, ir } = compileWithVOn(`<div @click="$event => foo($event)"/>`)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: '$event => foo($event)' },
|
||||
|
@ -291,7 +291,7 @@ describe('v-on', () => {
|
|||
{ expressionPlugins: ['typescript'] },
|
||||
)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: '(e: any): any => foo(e)' },
|
||||
|
@ -313,7 +313,7 @@ describe('v-on', () => {
|
|||
"/>`,
|
||||
)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: {
|
||||
|
@ -337,7 +337,7 @@ describe('v-on', () => {
|
|||
},
|
||||
)
|
||||
|
||||
expect(ir.operation[0]).toMatchObject({
|
||||
expect(ir.block.operation[0]).toMatchObject({
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: '$event => {i++;foo($event)}' },
|
||||
})
|
||||
|
@ -347,7 +347,7 @@ describe('v-on', () => {
|
|||
|
||||
test('should NOT wrap as function if expression is complex member expression', () => {
|
||||
const { ir, code } = compileWithVOn(`<div @click="a['b' + c]"/>`)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: `a['b' + c]` },
|
||||
|
@ -359,7 +359,7 @@ describe('v-on', () => {
|
|||
|
||||
test('complex member expression w/ prefixIdentifiers: true', () => {
|
||||
const { ir, code } = compileWithVOn(`<div @click="a['b' + c]"/>`)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: `a['b' + c]` },
|
||||
|
@ -375,7 +375,7 @@ describe('v-on', () => {
|
|||
prefixIdentifiers: true,
|
||||
})
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: { content: `e => foo(e)` },
|
||||
|
@ -419,7 +419,7 @@ describe('v-on', () => {
|
|||
)
|
||||
|
||||
expect(vaporHelpers).contains('on')
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
value: {
|
||||
|
@ -449,7 +449,7 @@ describe('v-on', () => {
|
|||
},
|
||||
)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
key: {
|
||||
|
@ -504,7 +504,7 @@ describe('v-on', () => {
|
|||
},
|
||||
)
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
element: 1,
|
||||
|
@ -533,7 +533,7 @@ describe('v-on', () => {
|
|||
const { code, ir } = compileWithVOn(`<div @keyup.exact="test"/>`, {
|
||||
prefixIdentifiers: true,
|
||||
})
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
modifiers: { nonKeys: ['exact'] },
|
||||
|
@ -548,7 +548,7 @@ describe('v-on', () => {
|
|||
prefixIdentifiers: true,
|
||||
})
|
||||
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
modifiers: {
|
||||
|
@ -567,7 +567,7 @@ describe('v-on', () => {
|
|||
prefixIdentifiers: true,
|
||||
})
|
||||
|
||||
expect(ir.effect[0].operations).toMatchObject([
|
||||
expect(ir.block.effect[0].operations).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
key: {
|
||||
|
@ -588,7 +588,7 @@ describe('v-on', () => {
|
|||
|
||||
test('should transform click.right', () => {
|
||||
const { code, ir } = compileWithVOn(`<div @click.right="test"/>`)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
key: {
|
||||
|
@ -608,7 +608,7 @@ describe('v-on', () => {
|
|||
const { code: code2, ir: ir2 } = compileWithVOn(
|
||||
`<div @[event].right="test"/>`,
|
||||
)
|
||||
expect(ir2.effect[0].operations).toMatchObject([
|
||||
expect(ir2.block.effect[0].operations).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
key: {
|
||||
|
@ -629,7 +629,7 @@ describe('v-on', () => {
|
|||
|
||||
test('should transform click.middle', () => {
|
||||
const { code, ir } = compileWithVOn(`<div @click.middle="test"/>`)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
key: {
|
||||
|
@ -650,7 +650,7 @@ describe('v-on', () => {
|
|||
`<div @[event].middle="test"/>`,
|
||||
)
|
||||
|
||||
expect(ir2.effect[0].operations).toMatchObject([
|
||||
expect(ir2.block.effect[0].operations).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_EVENT,
|
||||
key: {
|
||||
|
|
|
@ -26,8 +26,8 @@ describe('compiler: v-once', () => {
|
|||
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(helpers).lengthOf(0)
|
||||
expect(ir.effect).lengthOf(0)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.effect).lengthOf(0)
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.CREATE_TEXT_NODE,
|
||||
id: 1,
|
||||
|
@ -79,8 +79,8 @@ describe('compiler: v-once', () => {
|
|||
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(helpers).lengthOf(0)
|
||||
expect(ir.effect).lengthOf(0)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.effect).lengthOf(0)
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_PROP,
|
||||
element: 1,
|
||||
|
@ -110,8 +110,8 @@ describe('compiler: v-once', () => {
|
|||
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(helpers).lengthOf(0)
|
||||
expect(ir.effect).lengthOf(0)
|
||||
expect(ir.operation).toMatchObject([
|
||||
expect(ir.block.effect).lengthOf(0)
|
||||
expect(ir.block.operation).toMatchObject([
|
||||
{
|
||||
type: IRNodeTypes.SET_PROP,
|
||||
element: 1,
|
||||
|
@ -144,8 +144,8 @@ describe('compiler: v-once', () => {
|
|||
|
||||
expect(code).toMatchSnapshot()
|
||||
expect(helpers).lengthOf(0)
|
||||
expect(ir.effect).lengthOf(0)
|
||||
expect(ir.operation).lengthOf(0)
|
||||
expect(ir.block.effect).lengthOf(0)
|
||||
expect(ir.block.operation).lengthOf(0)
|
||||
})
|
||||
|
||||
test.todo('with hoistStatic: true')
|
||||
|
|
|
@ -23,9 +23,9 @@ describe('v-text', () => {
|
|||
expect(vaporHelpers).contains('setText')
|
||||
expect(helpers.size).toBe(0)
|
||||
|
||||
expect(ir.operation).toEqual([])
|
||||
expect(ir.block.operation).toEqual([])
|
||||
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ describe('v-text', () => {
|
|||
// children should have been removed
|
||||
expect(ir.template).toEqual(['<div></div>'])
|
||||
|
||||
expect(ir.effect).toMatchObject([
|
||||
expect(ir.block.effect).toMatchObject([
|
||||
{
|
||||
expressions: [
|
||||
{
|
||||
|
|
|
@ -118,7 +118,7 @@ export function generate(
|
|||
}
|
||||
|
||||
push(INDENT_START)
|
||||
push(...genBlockFunctionContent(ir, context))
|
||||
push(...genBlockFunctionContent(ir.block, context))
|
||||
push(INDENT_END, NEWLINE)
|
||||
|
||||
if (isSetupInlined) {
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
import {
|
||||
type BlockFunctionIRNode,
|
||||
IRNodeTypes,
|
||||
type RootIRNode,
|
||||
type WithDirectiveIRNode,
|
||||
} from '../ir'
|
||||
import { type BlockIRNode, IRNodeTypes, type WithDirectiveIRNode } from '../ir'
|
||||
import {
|
||||
type CodeFragment,
|
||||
INDENT_END,
|
||||
|
@ -18,7 +13,7 @@ import { genChildren } from './template'
|
|||
import { genMulti } from './utils'
|
||||
|
||||
export function genBlockFunction(
|
||||
oper: BlockFunctionIRNode,
|
||||
oper: BlockIRNode,
|
||||
context: CodegenContext,
|
||||
args: CodeFragment[] = [],
|
||||
customReturns?: (returns: CodeFragment[]) => CodeFragment[],
|
||||
|
@ -36,13 +31,7 @@ export function genBlockFunction(
|
|||
}
|
||||
|
||||
export function genBlockFunctionContent(
|
||||
{
|
||||
dynamic,
|
||||
effect,
|
||||
operation,
|
||||
templateIndex,
|
||||
returns,
|
||||
}: BlockFunctionIRNode | RootIRNode,
|
||||
{ dynamic, effect, operation, templateIndex, returns }: BlockIRNode,
|
||||
context: CodegenContext,
|
||||
customReturns?: (returns: CodeFragment[]) => CodeFragment[],
|
||||
): CodeFragment[] {
|
||||
|
|
|
@ -23,7 +23,7 @@ export function genIf(
|
|||
let negativeArg: false | CodeFragment[] = false
|
||||
|
||||
if (negative) {
|
||||
if (negative.type === IRNodeTypes.BLOCK_FUNCTION) {
|
||||
if (negative.type === IRNodeTypes.BLOCK) {
|
||||
negativeArg = genBlockFunction(negative, context)
|
||||
} else {
|
||||
negativeArg = ['() => ', ...genIf(negative!, context, true)]
|
||||
|
|
|
@ -15,7 +15,7 @@ import type {
|
|||
|
||||
export enum IRNodeTypes {
|
||||
ROOT,
|
||||
BLOCK_FUNCTION,
|
||||
BLOCK,
|
||||
|
||||
SET_PROP,
|
||||
SET_DYNAMIC_PROPS,
|
||||
|
@ -42,8 +42,8 @@ export interface BaseIRNode {
|
|||
|
||||
export type VaporHelper = keyof typeof import('@vue/runtime-vapor')
|
||||
|
||||
export interface BlockFunctionIRNode extends BaseIRNode {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION
|
||||
export interface BlockIRNode extends BaseIRNode {
|
||||
type: IRNodeTypes.BLOCK
|
||||
node: RootNode | TemplateChildNode
|
||||
templateIndex: number
|
||||
dynamic: IRDynamicInfo
|
||||
|
@ -52,19 +52,20 @@ export interface BlockFunctionIRNode extends BaseIRNode {
|
|||
returns: number[]
|
||||
}
|
||||
|
||||
export interface RootIRNode extends Omit<BlockFunctionIRNode, 'type'> {
|
||||
export interface RootIRNode {
|
||||
type: IRNodeTypes.ROOT
|
||||
node: RootNode
|
||||
source: string
|
||||
template: string[]
|
||||
block: BlockIRNode
|
||||
}
|
||||
|
||||
export interface IfIRNode extends BaseIRNode {
|
||||
type: IRNodeTypes.IF
|
||||
id: number
|
||||
condition: SimpleExpressionNode
|
||||
positive: BlockFunctionIRNode
|
||||
negative?: BlockFunctionIRNode | IfIRNode
|
||||
positive: BlockIRNode
|
||||
negative?: BlockIRNode | IfIRNode
|
||||
}
|
||||
|
||||
export interface ForIRNode extends BaseIRNode {
|
||||
|
@ -75,7 +76,7 @@ export interface ForIRNode extends BaseIRNode {
|
|||
key?: SimpleExpressionNode
|
||||
index?: SimpleExpressionNode
|
||||
keyProperty?: SimpleExpressionNode
|
||||
render: BlockFunctionIRNode
|
||||
render: BlockIRNode
|
||||
}
|
||||
|
||||
export interface IRProp extends Omit<DirectiveTransformResult, 'value'> {
|
||||
|
@ -187,8 +188,6 @@ export type OperationNode =
|
|||
| IfIRNode
|
||||
| ForIRNode
|
||||
|
||||
export type BlockIRNode = RootIRNode | BlockFunctionIRNode
|
||||
|
||||
export enum DynamicFlag {
|
||||
NONE = 0,
|
||||
/**
|
||||
|
|
|
@ -118,7 +118,7 @@ function createRootContext(
|
|||
parent: null,
|
||||
index: 0,
|
||||
root: null!, // set later
|
||||
block: root,
|
||||
block: root.block,
|
||||
enterBlock(ir) {
|
||||
const { block, template, dynamic, childrenTemplate } = this
|
||||
this.block = ir
|
||||
|
@ -134,7 +134,7 @@ function createRootContext(
|
|||
}
|
||||
},
|
||||
options: extend({}, defaultOptions, options),
|
||||
dynamic: root.dynamic,
|
||||
dynamic: root.block.dynamic,
|
||||
inVOnce: false,
|
||||
|
||||
increaseId: () => globalId++,
|
||||
|
@ -222,6 +222,9 @@ export function transform(
|
|||
node: root,
|
||||
source: root.source,
|
||||
template: [],
|
||||
block: {
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node: root,
|
||||
templateIndex: -1,
|
||||
dynamic: extend(genDefaultDynamic(), {
|
||||
flags: DynamicFlag.REFERENCED,
|
||||
|
@ -229,6 +232,7 @@ export function transform(
|
|||
effect: [],
|
||||
operation: [],
|
||||
returns: [],
|
||||
},
|
||||
}
|
||||
|
||||
const context = createRootContext(ir, root, options)
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
createStructuralDirectiveTransform,
|
||||
} from '../transform'
|
||||
import {
|
||||
type BlockFunctionIRNode,
|
||||
type BlockIRNode,
|
||||
DynamicFlag,
|
||||
type IRDynamicInfo,
|
||||
IRNodeTypes,
|
||||
|
@ -50,8 +50,8 @@ export function processFor(
|
|||
context.node = node = wrapTemplate(node, ['for'])
|
||||
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT
|
||||
const id = context.reference()
|
||||
const render: BlockFunctionIRNode = {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
const render: BlockIRNode = {
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node,
|
||||
templateIndex: -1,
|
||||
dynamic: extend(genDefaultDynamic(), {
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
createStructuralDirectiveTransform,
|
||||
} from '../transform'
|
||||
import {
|
||||
type BlockFunctionIRNode,
|
||||
type BlockIRNode,
|
||||
DynamicFlag,
|
||||
type IRDynamicInfo,
|
||||
IRNodeTypes,
|
||||
|
@ -140,11 +140,11 @@ export function processIf(
|
|||
export function createIfBranch(
|
||||
node: ElementNode,
|
||||
context: TransformContext<ElementNode>,
|
||||
): [BlockFunctionIRNode, () => void] {
|
||||
): [BlockIRNode, () => void] {
|
||||
context.node = node = wrapTemplate(node, ['if', 'else-if', 'else'])
|
||||
|
||||
const branch: BlockFunctionIRNode = {
|
||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||
const branch: BlockIRNode = {
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node,
|
||||
templateIndex: -1,
|
||||
dynamic: extend(genDefaultDynamic(), {
|
||||
|
|
Loading…
Reference in New Issue