From 85c5ec4126df61bd5aaf9f773c37111cee26d6cb Mon Sep 17 00:00:00 2001
From: sorry <247076126@qq.com>
Date: Sat, 1 Jul 2023 17:07:05 +0800
Subject: [PATCH 1/3] test(defineProps): add intersection type test
---
.../__snapshots__/defineProps.spec.ts.snap | 131 ++++++++++++++++++
.../compileScript/defineProps.spec.ts | 70 ++++++++++
2 files changed, 201 insertions(+)
diff --git a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap
index 30e00e518b2..27c82973733 100644
--- a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap
+++ b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap
@@ -147,6 +147,87 @@ export default /*#__PURE__*/_defineComponent({
+return { }
+}
+
+})"
+`;
+
+exports[`defineProps > w/ extends interface 2`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+interface Bar extends Foo { y?: number }
+ interface Props extends Bar {
+ z: number
+ y: string
+ }
+
+ interface Foo { x?: number }
+
+export default /*#__PURE__*/_defineComponent({
+ props: {
+ z: { type: Number, required: true },
+ y: { type: String, required: true },
+ x: { type: Number, required: false }
+ },
+ setup(__props: any, { expose: __expose }) {
+ __expose();
+
+
+
+return { }
+}
+
+})"
+`;
+
+exports[`defineProps > w/ extends intersection Type 1`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+type Foo = {
+ x?: number;
+ };
+ interface Props extends Foo {
+ z: number
+ y: string
+ }
+
+export default /*#__PURE__*/_defineComponent({
+ props: {
+ z: { type: Number, required: true },
+ y: { type: String, required: true },
+ x: { type: Number, required: false }
+ },
+ setup(__props: any, { expose: __expose }) {
+ __expose();
+
+
+
+return { }
+}
+
+})"
+`;
+
+exports[`defineProps > w/ extends intersection type 1`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+type Foo = {
+ x?: number;
+ };
+ interface Props extends Foo {
+ z: number
+ y: string
+ }
+
+export default /*#__PURE__*/_defineComponent({
+ props: {
+ z: { type: Number, required: true },
+ y: { type: String, required: true },
+ x: { type: Number, required: false }
+ },
+ setup(__props: any, { expose: __expose }) {
+ __expose();
+
+
+
return { }
}
@@ -182,6 +263,56 @@ export default /*#__PURE__*/_defineComponent({
+return { }
+}
+
+})"
+`;
+
+exports[`defineProps > w/ intersection Type 1`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+type Foo = {
+ x?: number;
+ };
+ type Bar = {
+ y: string;
+ };
+
+export default /*#__PURE__*/_defineComponent({
+ props: {
+ x: { type: Number, required: false },
+ y: { type: String, required: true }
+ },
+ setup(__props: any, { expose: __expose }) {
+ __expose();
+
+
+
+return { }
+}
+
+})"
+`;
+
+exports[`defineProps > w/ intersection type 1`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+type Foo = {
+ x?: number;
+ };
+ type Bar = {
+ y: string;
+ };
+
+export default /*#__PURE__*/_defineComponent({
+ props: {
+ x: { type: Number, required: false },
+ y: { type: String, required: true }
+ },
+ setup(__props: any, { expose: __expose }) {
+ __expose();
+
+
+
return { }
}
diff --git a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
index 43f54b0aa1e..ecd3a3ee38c 100644
--- a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
+++ b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
@@ -258,6 +258,76 @@ const props = defineProps({ foo: String })
})
})
+ test('w/ extends interface', () => {
+ const { content, bindings } = compile(`
+
+
+ `)
+ assertCode(content)
+ expect(content).toMatch(`z: { type: Number, required: true }`)
+ expect(content).toMatch(`y: { type: String, required: true }`)
+ expect(content).toMatch(`x: { type: Number, required: false }`)
+ expect(bindings).toStrictEqual({
+ x: BindingTypes.PROPS,
+ y: BindingTypes.PROPS,
+ z: BindingTypes.PROPS
+ })
+ })
+
+ test('w/ extends intersection type', () => {
+ const { content, bindings } = compile(`
+
+ `)
+ assertCode(content)
+ expect(content).toMatch(`z: { type: Number, required: true }`)
+ expect(content).toMatch(`y: { type: String, required: true }`)
+ expect(content).toMatch(`x: { type: Number, required: false }`)
+ expect(bindings).toStrictEqual({
+ x: BindingTypes.PROPS,
+ y: BindingTypes.PROPS,
+ z: BindingTypes.PROPS
+ })
+ })
+
+ test('w/ intersection type', () => {
+ const { content, bindings } = compile(`
+
+ `)
+ assertCode(content)
+ expect(content).toMatch(`y: { type: String, required: true }`)
+ expect(content).toMatch(`x: { type: Number, required: false }`)
+ expect(bindings).toStrictEqual({
+ x: BindingTypes.PROPS,
+ y: BindingTypes.PROPS
+ })
+ })
+
test('w/ exported interface', () => {
const { content, bindings } = compile(`
-
- `)
- assertCode(content)
- expect(content).toMatch(`z: { type: Number, required: true }`)
- expect(content).toMatch(`y: { type: String, required: true }`)
- expect(content).toMatch(`x: { type: Number, required: false }`)
- expect(bindings).toStrictEqual({
- x: BindingTypes.PROPS,
- y: BindingTypes.PROPS,
- z: BindingTypes.PROPS
- })
- })
-
test('w/ extends intersection type', () => {
const { content, bindings } = compile(`