Skip to content

Commit 0f85c1a

Browse files
committed
refactor(macros): ignore placeholder variable for variableDeclaration
1 parent 65c6a5e commit 0f85c1a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/macros/src/volar/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function getMacro(
5858
if (expression) {
5959
return {
6060
expression,
61+
variableDeclaration: decl,
6162
initializer: decl.initializer,
6263
isRequired: ts.isNonNullExpression(initializer),
6364
}
@@ -127,7 +128,7 @@ export function getRootMap(options: TransformOptions): RootMap {
127128

128129
const macro = getMacro(node, ts, options)
129130
if (macro) {
130-
const { expression, initializer } = macro
131+
const { expression, initializer, variableDeclaration } = macro
131132
let isRequired = macro.isRequired
132133
if (!rootMap.has(root)) rootMap.set(root, {})
133134
const macroName = expression.expression.getText(ast)
@@ -193,20 +194,23 @@ export function getRootMap(options: TransformOptions): RootMap {
193194
codes.replaceRange(
194195
initializer.getStart(ast),
195196
initializer.getStart(ast),
196-
`// @ts-ignore\n${id};\nlet ${id} = `,
197+
variableDeclaration ? `// @ts-ignore\n${id};\n` : '',
198+
`let ${id} = `,
197199
)
198200
} else if (options.defineSlots.alias.includes(macroName)) {
199201
codes.replaceRange(
200202
expression.getStart(ast),
201203
expression.getStart(ast),
202-
`// @ts-ignore\n__slots;\nconst __slots = `,
204+
variableDeclaration ? '// @ts-ignore\n__slots;\n' : '',
205+
`const __slots = `,
203206
)
204207
rootMap.get(root)!.defineSlots = `Partial<typeof __slots>`
205208
} else if (options.defineExpose.alias.includes(macroName)) {
206209
codes.replaceRange(
207210
expression.getStart(ast),
208211
expression.getStart(ast),
209-
`// @ts-ignore\n__exposed;\nconst __exposed = `,
212+
variableDeclaration ? '// @ts-ignore\n__exposed;\n' : '',
213+
`const __exposed = `,
210214
)
211215
rootMap.get(root)!.defineExpose = `typeof __exposed`
212216
}

0 commit comments

Comments
 (0)