From fcd5422b4adaf99627ea0d675d98b2d9530c05ab Mon Sep 17 00:00:00 2001 From: ygj6 <7699524+ygj6@users.noreply.github.com> Date: Fri, 17 Sep 2021 01:45:55 +0800 Subject: [PATCH] fix(compile-sfc): add symbol judge in prop type checks. (#4594) fix #4592 --- .../__tests__/__snapshots__/compileScript.spec.ts.snap | 1 + packages/compiler-sfc/__tests__/compileScript.spec.ts | 3 +++ packages/compiler-sfc/src/compileScript.ts | 3 +++ 3 files changed, 7 insertions(+) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 29bfc58cddb..e7ffb34450b 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -971,6 +971,7 @@ export default /*#__PURE__*/_defineComponent({ interface: { type: Object, required: true }, alias: { type: Array, required: true }, method: { type: Function, required: true }, + symbol: { type: Symbol, required: true }, union: { type: [String, Number], required: true }, literalUnion: { type: String, required: true }, literalUnionNumber: { type: Number, required: true }, diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index d3a1282f4c5..bd654dfe9ee 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -706,6 +706,7 @@ const emit = defineEmits(['a', 'b']) interface: Test alias: Alias method(): void + symbol: symbol union: string | number literalUnion: 'foo' | 'bar' @@ -735,6 +736,7 @@ const emit = defineEmits(['a', 'b']) expect(content).toMatch(`interface: { type: Object, required: true }`) expect(content).toMatch(`alias: { type: Array, required: true }`) expect(content).toMatch(`method: { type: Function, required: true }`) + expect(content).toMatch(`symbol: { type: Symbol, required: true }`) expect(content).toMatch( `union: { type: [String, Number], required: true }` ) @@ -767,6 +769,7 @@ const emit = defineEmits(['a', 'b']) interface: BindingTypes.PROPS, alias: BindingTypes.PROPS, method: BindingTypes.PROPS, + symbol: BindingTypes.PROPS, union: BindingTypes.PROPS, literalUnion: BindingTypes.PROPS, literalUnionNumber: BindingTypes.PROPS, diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 609244232ef..3cc9705f730 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1541,6 +1541,9 @@ function inferRuntimeType( case 'TSIntersectionType': return ['Object'] + case 'TSSymbolKeyword': + return ['Symbol'] + default: return [`null`] // no runtime check }