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