diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index ee00977c131..818ea02e303 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -658,12 +658,25 @@ exports[`SFC compile - `) + + `) assertCode(content) // should remove defineOptions import and call expect(content).not.toMatch('defineOptions') @@ -218,6 +218,18 @@ defineOptions({ name: 'FooApp' }) ) }) + test('empty argument', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`export default {`) + // should remove defineOptions import and call + expect(content).not.toMatch('defineOptions') + }) + it('should emit an error with two defineProps', () => { expect(() => compile(` @@ -249,6 +261,26 @@ defineOptions({ name: 'FooApp' }) ).toThrowError( '[@vue/compiler-sfc] defineOptions() cannot be used to declare emits. Use defineEmits() instead.' ) + + expect(() => + compile(` + + `) + ).toThrowError( + '[@vue/compiler-sfc] defineOptions() cannot be used to declare expose. Use defineExpose() instead.' + ) + + expect(() => + compile(` + + `) + ).toThrowError( + '[@vue/compiler-sfc] defineOptions() cannot be used to declare slots. Use defineSlots() instead.' + ) }) it('should emit an error with type generic', () => { @@ -262,6 +294,18 @@ defineOptions({ name: 'FooApp' }) '[@vue/compiler-sfc] defineOptions() cannot accept type arguments' ) }) + + it('should emit an error with type assertion', () => { + expect(() => + compile(` + + `) + ).toThrowError( + '[@vue/compiler-sfc] defineOptions() cannot be used to declare props. Use defineProps() instead.' + ) + }) }) test('defineExpose()', () => { diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 1f1385b25fd..0c9fd6bed97 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -702,9 +702,10 @@ export function compileScript( if (node.typeParameters) { error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node) } + if (!node.arguments[0]) return true hasDefineOptionsCall = true - optionsRuntimeDecl = node.arguments[0] + optionsRuntimeDecl = unwrapTSNode(node.arguments[0]) let propsOption = undefined let emitsOption = undefined