@@ -49,7 +49,7 @@ import {
4949} from './script/defineEmits'
5050import { DEFINE_EXPOSE , processDefineExpose } from './script/defineExpose'
5151import { DEFINE_OPTIONS , processDefineOptions } from './script/defineOptions'
52- import { processDefineSlots } from './script/defineSlots'
52+ import { DEFINE_SLOTS , processDefineSlots } from './script/defineSlots'
5353import { DEFINE_MODEL , processDefineModel } from './script/defineModel'
5454import { getImportedName , isCallOf , isLiteralNode } from './script/utils'
5555import { analyzeScriptBindings } from './script/analyzeScriptBindings'
@@ -135,6 +135,16 @@ export interface ImportBinding {
135135 isUsedInTemplate : boolean
136136}
137137
138+ const MACROS = [
139+ DEFINE_PROPS ,
140+ DEFINE_EMITS ,
141+ DEFINE_EXPOSE ,
142+ DEFINE_OPTIONS ,
143+ DEFINE_SLOTS ,
144+ DEFINE_MODEL ,
145+ WITH_DEFAULTS ,
146+ ]
147+
138148/**
139149 * Compile `<script setup>`
140150 * It requires the whole SFC descriptor because we need to handle and merge
@@ -317,15 +327,18 @@ export function compileScript(
317327 const imported = getImportedName ( specifier )
318328 const source = node . source . value
319329 const existing = ctx . userImports [ local ]
320- if (
321- source === 'vue' &&
322- ( imported === DEFINE_PROPS ||
323- imported === DEFINE_EMITS ||
324- imported === DEFINE_EXPOSE )
325- ) {
326- warnOnce (
327- `\`${ imported } \` is a compiler macro and no longer needs to be imported.` ,
328- )
330+ if ( source === 'vue' && MACROS . includes ( imported ) ) {
331+ if ( local === imported ) {
332+ warnOnce (
333+ `\`${ imported } \` is a compiler macro and no longer needs to be imported.` ,
334+ )
335+ } else {
336+ ctx . error (
337+ `\`${ imported } \` is a compiler macro and cannot be aliased to ` +
338+ `a different name.` ,
339+ specifier ,
340+ )
341+ }
329342 removeSpecifier ( i )
330343 } else if ( existing ) {
331344 if ( existing . source === source && existing . imported === imported ) {
@@ -1054,13 +1067,16 @@ function walkDeclaration(
10541067 // export const foo = ...
10551068 for ( const { id, init : _init } of node . declarations ) {
10561069 const init = _init && unwrapTSNode ( _init )
1057- const isDefineCall = ! ! (
1070+ const isConstMacroCall =
10581071 isConst &&
10591072 isCallOf (
10601073 init ,
1061- c => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS ,
1074+ c =>
1075+ c === DEFINE_PROPS ||
1076+ c === DEFINE_EMITS ||
1077+ c === WITH_DEFAULTS ||
1078+ c === DEFINE_SLOTS ,
10621079 )
1063- )
10641080 if ( id . type === 'Identifier' ) {
10651081 let bindingType
10661082 const userReactiveBinding = userImportAliases [ 'reactive' ]
@@ -1077,7 +1093,7 @@ function walkDeclaration(
10771093 } else if (
10781094 // if a declaration is a const literal, we can mark it so that
10791095 // the generated render fn code doesn't need to unref() it
1080- isDefineCall ||
1096+ isConstMacroCall ||
10811097 ( isConst && canNeverBeRef ( init ! , userReactiveBinding ) )
10821098 ) {
10831099 bindingType = isCallOf ( init , DEFINE_PROPS )
@@ -1109,9 +1125,9 @@ function walkDeclaration(
11091125 continue
11101126 }
11111127 if ( id . type === 'ObjectPattern' ) {
1112- walkObjectPattern ( id , bindings , isConst , isDefineCall )
1128+ walkObjectPattern ( id , bindings , isConst , isConstMacroCall )
11131129 } else if ( id . type === 'ArrayPattern' ) {
1114- walkArrayPattern ( id , bindings , isConst , isDefineCall )
1130+ walkArrayPattern ( id , bindings , isConst , isConstMacroCall )
11151131 }
11161132 }
11171133 }
0 commit comments