Skip to content

Commit 9548729

Browse files
committed
fix(macros): remove lib option
1 parent 563b2f0 commit 9548729

File tree

7 files changed

+10
-24
lines changed

7 files changed

+10
-24
lines changed

packages/macros/src/core/define-expose.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import type { CallExpression } from '@babel/types'
44
export function transformDefineExpose(
55
node: CallExpression,
66
s: MagicStringAST,
7-
lib: string,
7+
version: number,
88
): void {
99
s.overwriteNode(node.callee, ';')
1010
s.appendRight(
1111
node.arguments[0]?.start || node.end! - 1,
12-
lib.includes('vapor')
12+
version >= 3.6
1313
? `${importHelperFn(s, 0, 'currentInstance')}.exposed = `
1414
: `${importHelperFn(s, 0, 'getCurrentInstance')}().exposed = `,
1515
)

packages/macros/src/core/define-slots.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import type { CallExpression } from '@babel/types'
33

44
export function transformDefineSlots(
55
node: CallExpression,
6-
propsName: string,
76
s: MagicStringAST,
8-
lib: string,
97
): void {
108
s.overwrite(
119
node.start!,
@@ -14,8 +12,6 @@ export function transformDefineSlots(
1412
node.callee.end!,
1513
`Object.assign`,
1614
)
17-
const slots = lib.includes('vue')
18-
? `${importHelperFn(s, 0, 'useSlots')}()`
19-
: `${propsName}.vSlots`
15+
const slots = `${importHelperFn(s, 0, 'useSlots')}()`
2016
s.appendLeft(node.end! - 1, `${node.arguments[0] ? ',' : '{}, '}${slots}`)
2117
}

packages/macros/src/core/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ export function transformJsxMacros(
103103
})
104104
}
105105
if (map.defineSlots) {
106-
transformDefineSlots(map.defineSlots, propsName, s, options.lib)
106+
transformDefineSlots(map.defineSlots, s)
107107
}
108108
if (map.defineExpose) {
109-
transformDefineExpose(map.defineExpose, s, options.lib)
109+
transformDefineExpose(map.defineExpose, s, options.version)
110110
}
111111
}
112112

packages/macros/src/options.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
detectVueVersion,
2+
// detectVueVersion,
33
REGEX_NODE_MODULES,
44
REGEX_SETUP_SFC,
55
REGEX_SRC_FILE,
@@ -8,7 +8,6 @@ import {
88
} from '@vue-macros/common'
99

1010
export type Options = BaseOptions & {
11-
lib?: 'vue' | 'vue/vapor' | (string & {})
1211
defineComponent?: { alias: string[] }
1312
defineModel?: { alias: string[] }
1413
defineExpose?: { alias: string[] }
@@ -19,7 +18,6 @@ export type OptionsResolved = MarkRequired<
1918
Options,
2019
| 'include'
2120
| 'version'
22-
| 'lib'
2321
| 'defineComponent'
2422
| 'defineModel'
2523
| 'defineExpose'
@@ -28,14 +26,14 @@ export type OptionsResolved = MarkRequired<
2826
>
2927

3028
export function resolveOptions(options: Options): OptionsResolved {
31-
const version = options.version || detectVueVersion()
32-
const lib = options.lib || 'vue/vapor'
29+
// waiting for [email protected] release
30+
// const version = options.version || detectVueVersion()
31+
const version = options.version || 3.6
3332
return {
3433
include: [REGEX_SRC_FILE],
3534
exclude: [REGEX_SETUP_SFC, REGEX_NODE_MODULES],
3635
...options,
3736
version,
38-
lib,
3937
defineComponent: {
4038
alias: options?.defineComponent?.alias ?? [
4139
'defineComponent',

packages/macros/src/volar/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export { getGlobalTypes } from './global-types'
1212

1313
type UserOptions = MarkRequired<
1414
Exclude<Options, false>,
15-
| 'lib'
1615
| 'defineModel'
1716
| 'defineSlots'
1817
| 'defineStyle'
@@ -23,7 +22,6 @@ export type TransformOptions = Overwrite<
2322
TsmVirtualCode,
2423
{
2524
ts: typeof import('typescript')
26-
lib: UserOptions['lib']
2725
defineModel: UserOptions['defineModel']
2826
defineSlots: UserOptions['defineSlots']
2927
defineStyle: UserOptions['defineStyle']

packages/macros/src/volar/transform.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ export function transformJsxMacros(
8686
node.expression.getStart(ast),
8787
`return {\nprops: {} as { ${props.join(', ')} }`,
8888
`,\nslots: {} as ${map.defineSlots ?? '{}'}`,
89-
`,\nexpose: (exposed: ${
90-
options.lib === 'vue'
91-
? `import('vue').ShallowUnwrapRef`
92-
: 'NonNullable'
93-
}<${map.defineExpose ?? '{}'}>) => {}`,
89+
`,\nexpose: (exposed: import('vue').ShallowUnwrapRef<${map.defineExpose ?? '{}'}>) => {}`,
9490
`,\nrender: `,
9591
shouldWrapByCall ? '(' : '',
9692
)

packages/macros/tests/fixtures.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('fixtures', async () => {
3131
globs,
3232
(args, id, code) =>
3333
transformJsxMacros(code, id, new Map(), {
34-
lib: 'vue',
3534
include: ['*.tsx'],
3635
version: 3.6,
3736
...options,
@@ -44,7 +43,6 @@ describe('vue/vapor fixtures', async () => {
4443
globs,
4544
(args, id, code) =>
4645
transformJsxMacros(code, id, new Map(), {
47-
lib: 'vue/vapor',
4846
include: ['*.tsx'],
4947
version: 3.6,
5048
...options,

0 commit comments

Comments
 (0)