Skip to content

Commit 1299574

Browse files
committed
feat: support composition api
1 parent 56f3c56 commit 1299574

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

packages/core/core.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const unplugin = createUnplugin<Options>(
3535
const importCSSModule = createCSSModule(descriptor, id, preProcessCSSRes)
3636
const variableName = getVariable(descriptor)
3737
code = injectCSSVars(code, importCSSModule, variableName)
38+
console.log(code)
3839
}
3940
return code
4041
} catch (err: unknown) {

packages/core/get-variable.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import type { Node } from 'estree-walker'
1010
*/
1111
export const getVariable = (descriptor: SFCDescriptor) => {
1212
// ⭐⭐⭐ TODO: options
13-
// ⭐⭐⭐ TODO: setup composition
14-
const ast = babelParse(descriptor.scriptSetup.content, {
13+
let content = ''
14+
if (descriptor.script)
15+
content = descriptor.script.content
16+
else if (descriptor.scriptSetup)
17+
content = descriptor.scriptSetup.content
18+
19+
const ast = babelParse(content, {
1520
sourceType: 'module',
1621
plugins: ['typescript'],
1722
})

play/src/App.vue

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup lang="ts">
1+
<!-- <script setup lang="ts">
22
import { reactive, ref } from 'vue'
33
/* import Comp from './comp.vue' */
44
const appAsd = () => 'red'
@@ -8,6 +8,36 @@ const appTheme3 = ref('red')
88
const appTheme4 = reactive({ color: 'red' })
99
const appTheme5 = { color: 'red' }
1010
const appTheme6 = () => 'red'
11+
</script> -->
12+
<script>
13+
import { defineComponent, reactive, ref } from 'vue'
14+
/* import Comp from './comp.vue' */
15+
const appAsd = () => 'red'
16+
const color = appAsd()
17+
const appTheme2 = 'red'
18+
const appTheme3 = ref('red')
19+
const appTheme4 = reactive({ color: 'red' })
20+
const appTheme5 = { color: 'red' }
21+
const appTheme6 = () => 'red'
22+
export default defineComponent({
23+
setup() {
24+
const appAsd = () => 'red'
25+
const color = appAsd()
26+
const appTheme2 = 'red'
27+
const appTheme3 = ref('red')
28+
const appTheme4 = reactive({ color: 'red' })
29+
const appTheme5 = { color: 'red' }
30+
const appTheme6 = () => 'red'
31+
return {
32+
color,
33+
appTheme2,
34+
appTheme3,
35+
appTheme4,
36+
appTheme5,
37+
appTheme6,
38+
}
39+
},
40+
})
1141
</script>
1242

1343
<template>

0 commit comments

Comments
 (0)