8000 feat(common): support `local` option for `importHelperFn` · vue-macros/vue-macros@03a4e1e · GitHub
[go: up one dir, main page]

Skip to content

Commit 03a4e1e

Browse files
authored
feat(common): support local option for importHelperFn
1 parent c2e437a commit 03a4e1e

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

packages/common/src/ast.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,16 @@ export const HELPER_PREFIX = '__MACROS_'
152152
export function importHelperFn(
153153
s: MagicString,
154154
offset: number,
155-
local: string,
155+
imported: string,
156+
local: string = imported,
156157
from = 'vue',
157-
isDefault = false,
158158
) {
159-
const imported = isDefault ? 'default' : local
160159
const cacheKey = `${from}@${imported}`
161160
if (!importedMap.get(s)?.has(cacheKey)) {
162161
s.appendLeft(
163162
offset,
164163
`\nimport ${
165-
isDefault
164+
imported === 'default'
166165
? HELPER_PREFIX + local
167166
: `{ ${imported} as ${HELPER_PREFIX + local} }`
168167
} from ${JSON.stringify(from)};`,

packages/define-models/src/core/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ export function transformDefineModels(
286286
const text = `${importHelperFn(
287287
s,
288288
setupOffset,
289+
'default',
289290
'useVModel',
290291
useVmodelHelperId,
291-
true,
292292
)}(${Object.entries(map)
293293
.map(([name, { options }]) => {
294294
const prop = getPropKey(name, true)
@@ -325,9 +325,9 @@ export function transformDefineModels(
325325
const content = `${importHelperFn(
326326
s,
327327
setupOffset,
328+
'default',
328329
'emitHelper',
329330
emitHelperId,
330-
true,
331331
)}(${emitsIdentifier}, '${getEventKey(String(eventName))}', ${value}${
332332
original ? `, ${id.name}` : ''
333333
})`

packages/define-prop/src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ export async function transformDefineProp(
9494
const normalizePropsOrEmits = importHelperFn(
9595
s,
9696
offset,
97+
'default',
9798
'normalizePropsOrEmits',
9899
helperId,
99-
true,
100100
)
101101
s.overwriteNode(
102102
definePropsCall.arguments[0],

packages/jsx-directive/src/core/v-for.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function resolveVFor(
4242
s,
4343
0,
4444
'renderList',
45+
undefined,
4546
lib.startsWith('vue') ? 'vue' : '@vue-macros/jsx-directive/helpers',
4647
)
4748
return `${renderList}(${list}, ${params} => `

packages/jsx-directive/src/core/v-memo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function transformVMemo(
1616
s,
1717
0,
1818
'withMemo',
19+
undefined,
1920
lib.startsWith('vue') ? 'vue' : '@vue-macros/jsx-directive/helpers',
2021
)
2122
s.prependRight(0, `const ${HELPER_PREFIX}cache = [];`)

packages/jsx-directive/src/core/v-on.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function transformOnWithModifiers(
3737
s,
3838
0,
3939
isKeyboardEvent(name) ? 'withKeys' : 'withModifiers',
40+
undefined,
4041
lib.startsWith('vue') ? 'vue' : '@vue-macros/jsx-directive/helpers',
4142
)
4243

packages/jsx-directive/src/core/v-slot.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ export function transformVSlot(
6868
})
6969
result.push(
7070
isDynamic
71-
? `[${importHelperFn(s, 0, 'unref', lib.startsWith('vue') ? 'vue' : '@vue-macros/jsx-directive/helpers')}(${attributeName})]`
71+
? `[${importHelperFn(
72+
s,
73+
0,
74+
'unref',
75+
undefined,
76+
lib.startsWith('vue')
77+
? 'vue'
78+
: '@vue-macros/jsx-directive/helpers',
79+
)}(${attributeName})]`
7280
: `'${attributeName}'`,
7381
vForAttribute ? ', ' : ': ',
7482
)

0 commit comments

Comments
 (0)
0