@@ -58,6 +58,7 @@ function getMacro(
58
58
if ( expression ) {
59
59
return {
60
60
expression,
61
+ variableDeclaration : decl ,
61
62
initializer : decl . initializer ,
62
63
isRequired : ts . isNonNullExpression ( initializer ) ,
63
64
}
@@ -127,7 +128,7 @@ export function getRootMap(options: TransformOptions): RootMap {
127
128
128
129
const macro = getMacro ( node , ts , options )
129
130
if ( macro ) {
130
- const { expression, initializer } = macro
131
+ const { expression, initializer, variableDeclaration } = macro
131
132
let isRequired = macro . isRequired
132
133
if ( ! rootMap . has ( root ) ) rootMap . set ( root , { } )
133
134
const macroName = expression . expression . getText ( ast )
@@ -193,20 +194,23 @@ export function getRootMap(options: TransformOptions): RootMap {
193
194
codes . replaceRange (
194
195
initializer . getStart ( ast ) ,
195
196
initializer . getStart ( ast ) ,
196
- `// @ts-ignore\n${ id } ;\nlet ${ id } = ` ,
197
+ variableDeclaration ? `// @ts-ignore\n${ id } ;\n` : '' ,
198
+ `let ${ id } = ` ,
197
199
)
198
200
} else if ( options . defineSlots . alias . includes ( macroName ) ) {
199
201
codes . replaceRange (
200
202
expression . getStart ( ast ) ,
201
203
expression . getStart ( ast ) ,
202
- `// @ts-ignore\n__slots;\nconst __slots = ` ,
204
+ variableDeclaration ? '// @ts-ignore\n__slots;\n' : '' ,
205
+ `const __slots = ` ,
203
206
)
204
207
rootMap . get ( root ) ! . defineSlots = `Partial<typeof __slots>`
205
208
} else if ( options . defineExpose . alias . includes ( macroName ) ) {
206
209
codes . replaceRange (
207
210
expression . getStart ( ast ) ,
208
211
expression . getStart ( ast ) ,
209
- `// @ts-ignore\n__exposed;\nconst __exposed = ` ,
212
+ variableDeclaration ? '// @ts-ignore\n__exposed;\n' : '' ,
213
+ `const __exposed = ` ,
210
214
)
211
215
rootMap . get ( root ) ! . defineExpose = `typeof __exposed`
212
216
}
0 commit comments