]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: test slotFunction codegen
authorEvan You <yyx990803@gmail.com>
Sat, 28 Sep 2019 17:12:41 +0000 (13:12 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 28 Sep 2019 17:12:41 +0000 (13:12 -0400)
packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap
packages/compiler-core/__tests__/codegen.spec.ts

index ffeada4ccb127879368945dff56c8bbf8bfda4d5..527f8b1093d7eab071acabd0d8acb42693441d59 100644 (file)
@@ -1,5 +1,18 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`compiler: codegen SlotFunctionExpression 1`] = `
+"
+return function render() {
+  with (this) {
+    return _createVNode(Comp, 0, {
+      default: ({ foo }) => [
+        _toString(foo)
+      ]
+    })
+  }
+}"
+`;
+
 exports[`compiler: codegen callExpression + objectExpression + arrayExpression 1`] = `
 "
 return function render() {
index 1ab8afc66cc7845917cf1e9ec338dab5fbdd64a9..19a1f0b18e39ade5035c61abf43bba6c1835813a 100644 (file)
@@ -457,6 +457,80 @@ describe('compiler: codegen', () => {
     expect(code).toMatchSnapshot()
   })
 
+  test('SlotFunctionExpression', () => {
+    const { code } = generate(
+      createRoot({
+        children: [
+          {
+            type: NodeTypes.ELEMENT,
+            tagType: ElementTypes.COMPONENT,
+            ns: Namespaces.HTML,
+            isSelfClosing: false,
+            tag: `Comp`,
+            loc: mockLoc,
+            props: [],
+            children: [],
+            codegenNode: {
+              type: NodeTypes.JS_CALL_EXPRESSION,
+              loc: mockLoc,
+              callee: `_${CREATE_VNODE}`,
+              arguments: [
+                `Comp`,
+                `0`,
+                {
+                  type: NodeTypes.JS_OBJECT_EXPRESSION,
+                  loc: mockLoc,
+                  properties: [
+                    {
+                      type: NodeTypes.JS_PROPERTY,
+                      loc: mockLoc,
+                      key: {
+                        type: NodeTypes.SIMPLE_EXPRESSION,
+                        isStatic: true,
+                        content: `default`,
+                        loc: mockLoc
+                      },
+                      value: {
+                        type: NodeTypes.JS_SLOT_FUNCTION,
+                        loc: mockLoc,
+                        params: {
+                          type: NodeTypes.SIMPLE_EXPRESSION,
+                          isStatic: false,
+                          content: `{ foo }`,
+                          loc: mockLoc
+                        },
+                        returns: [
+                          {
+                            type: NodeTypes.INTERPOLATION,
+                            loc: mockLoc,
+                            content: {
+                              type: NodeTypes.SIMPLE_EXPRESSION,
+                              isStatic: false,
+                              content: `foo`,
+                              loc: mockLoc
+                            }
+                          }
+                        ]
+                      }
+                    }
+                  ]
+                }
+              ]
+            }
+          }
+        ]
+      })
+    )
+    expect(code).toMatch(
+      `return _createVNode(Comp, 0, {
+      default: ({ foo }) => [
+        _toString(foo)
+      ]
+    })`
+    )
+    expect(code).toMatchSnapshot()
+  })
+
   test('callExpression + objectExpression + arrayExpression', () => {
     function createElementWithCodegen(
       args: CallExpression['arguments']