Skip to content

Commit

Permalink
refactor(compiler-vapor): split block & root ir node
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Feb 22, 2024
1 parent 531f4f0 commit 0e0ee5b
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('compiler: element transform', () => {
)
expect(code).toMatchSnapshot()

expect(ir.effect).toMatchObject([
expect(ir.block.effect).toMatchObject([
{
expressions: [
{
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('compiler: element transform', () => {

expect(code).toMatchSnapshot()

expect(ir.effect).toMatchObject([
expect(ir.block.effect).toMatchObject([
{
expressions: [
{
Expand Down
38 changes: 19 additions & 19 deletions packages/compiler-vapor/__tests__/transforms/vBind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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`,
Expand All @@ -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`,
Expand All @@ -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: [
[
Expand Down Expand Up @@ -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`,
Expand All @@ -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`,
Expand All @@ -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: [
[
Expand Down Expand Up @@ -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`,
Expand All @@ -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`,
Expand All @@ -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`,
Expand All @@ -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`,
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler-vapor/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,7 +43,7 @@ describe('compiler: v-for', () => {
key: undefined,
index: undefined,
render: {
type: IRNodeTypes.BLOCK_FUNCTION,
type: IRNodeTypes.BLOCK,
templateIndex: 0,
},
keyProperty: {
Expand All @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler-vapor/__tests__/transforms/vHtml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down
Loading

0 comments on commit 0e0ee5b

Please sign in to comment.