@@ -49,7 +49,7 @@ import {
49
49
} from './script/defineEmits'
50
50
import { DEFINE_EXPOSE , processDefineExpose } from './script/defineExpose'
51
51
import { DEFINE_OPTIONS , processDefineOptions } from './script/defineOptions'
52
- import { processDefineSlots } from './script/defineSlots'
52
+ import { DEFINE_SLOTS , processDefineSlots } from './script/defineSlots'
53
53
import { DEFINE_MODEL , processDefineModel } from './script/defineModel'
54
54
import { getImportedName , isCallOf , isLiteralNode } from './script/utils'
55
55
import { analyzeScriptBindings } from './script/analyzeScriptBindings'
@@ -135,6 +135,16 @@ export interface ImportBinding {
135
135
isUsedInTemplate : boolean
136
136
}
137
137
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
+
138
148
/**
139
149
* Compile `<script setup>`
140
150
* It requires the whole SFC descriptor because we need to handle and merge
@@ -317,15 +327,18 @@ export function compileScript(
317
327
const imported = getImportedName ( specifier )
318
328
const source = node . source . value
319
329
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
+ }
329
342
removeSpecifier ( i )
330
343
} else if ( existing ) {
331
344
if ( existing . source === source && existing . imported === imported ) {
@@ -1054,13 +1067,7 @@ function walkDeclaration(
1054
1067
// export const foo = ...
1055
1068
for ( const { id, init : _init } of node . declarations ) {
1056
1069
const init = _init && unwrapTSNode ( _init )
1057
- const isDefineCall = ! ! (
1058
- isConst &&
1059
- isCallOf (
1060
- init ,
1061
- c => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS ,
1062
- )
1063
- )
1070
+ const isMacroCall = ! ! ( isConst && isCallOf ( init , c => MACROS . includes ( c ) ) )
1064
1071
if ( id . type === 'Identifier' ) {
1065
1072
let bindingType
1066
1073
const userReactiveBinding = userImportAliases [ 'reactive' ]
@@ -1077,7 +1084,7 @@ function walkDeclaration(
1077
1084
} else if (
1078
1085
// if a declaration is a const literal, we can mark it so that
1079
1086
// the generated render fn code doesn't need to unref() it
1080
- isDefineCall ||
1087
+ isMacroCall ||
1081
1088
( isConst && canNeverBeRef ( init ! , userReactiveBinding ) )
1082
1089
) {
1083
1090
bindingType = isCallOf ( init , DEFINE_PROPS )
@@ -1109,9 +1116,9 @@ function walkDeclaration(
1109
1116
continue
1110
1117
}
1111
1118
if ( id . type === 'ObjectPattern' ) {
1112
- walkObjectPattern ( id , bindings , isConst , isDefineCall )
1119
+ walkObjectPattern ( id , bindings , isConst , isMacroCall )
1113
1120
} else if ( id . type === 'ArrayPattern' ) {
1114
- walkArrayPattern ( id , bindings , isConst , isDefineCall )
1121
+ walkArrayPattern ( id , bindings , isConst , isMacroCall )
1115
1122
}
1116
1123
}
1117
1124
}
0 commit comments