We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d20c7c4 commit 74cc8bdCopy full SHA for 74cc8bd
packages/core/css/__test__/process-css.spec.ts
@@ -68,6 +68,36 @@ describe('process css', () => {
68
})
69
70
71
+ test('getCSSFileRecursion: circular dependencies', () => {
72
+ const mockEvt = vi.fn()
73
+ const mockRes: Array<ICSSFile> = []
74
+ const mockCssFiles = new Map()
75
+ mockCssFiles.set('foo', {
76
+ importer: new Set(['bar']),
77
+ vBindCode: {
78
+ foo: new Set(['v-bind(foo)']),
79
+ },
80
+ })
81
+ mockCssFiles.set('bar', {
82
+ importer: new Set(['foo']),
83
84
+ bar: new Set(['v-bind(bar)']),
85
86
87
+ getCSSFileRecursion('foo', mockCssFiles, (v) => {
88
+ mockEvt()
89
+ mockRes.push(v)
90
91
+ expect(mockRes.length).toBe(2)
92
+ expect(mockEvt).toBeCalledTimes(2)
93
+ expect(mockRes[0].vBindCode).toMatchObject({
94
95
96
+ expect(mockRes[1].vBindCode).toMatchObject({
97
98
99
100
+
101
test('createCSSModule: basic', () => {
102
const mockCssFiles = new Map()
103
const mockCSSFilesContent = {
packages/core/css/process-css.ts
@@ -5,9 +5,13 @@ import { walkCSSTree } from './pre-process-css'
5
import type { ICSSFile, ICSSFileMap } from '../types'
6
import type { SFCDescriptor } from '@vue/compiler-sfc'
7
8
+const matchedMark = new Set<string>()
9
export const getCSSFileRecursion = (key: string, cssFiles: ICSSFileMap, cb: (res: ICSSFile) => void) => {
10
+ // 避免循环引用
11
+ if (matchedMark.has(key)) return
12
const cssFile = cssFiles.get(key)
13
if (cssFile) {
14
+ matchedMark.add(key)
15
cb(cssFile)
16
if (cssFile.importer.size > 0) {
17
cssFile.importer.forEach((value) => {
play/src/App.vue
@@ -1,14 +1,14 @@
1
-<!-- <script setup lang="ts">
+<script setup lang="ts">
2
import { reactive, ref } from 'vue'
3
/* import Comp from './comp.vue' */
4
const appAsd = () => 'red'
const color = appAsd()
-const appTheme2 = 'red'
+const appTheme2 = 'blue'
const appTheme3 = ref('red')
const appTheme4 = reactive({ color: 'red' })
const appTheme5 = { color: 'red' }
const appTheme6 = () => 'red'
-</script> -->
+</script>
<!-- <script lang="ts">
const sc2 = 'red'
</script> -->
@@ -43,7 +43,7 @@ export default defineComponent({
43
44
45
46
-<script>
+<!-- <script>
47
export default {
48
setup() {
49
const color3 = 'red'
@@ -57,7 +57,7 @@ export default {
57
}
58
},
59
60
-</script>
+</script> -->
61
62
<template>
63
<div class="test">
@@ -68,7 +68,7 @@ export default {
<style scoped>
@import "./assets/test";
- div {
+/* div {
color: v-bind(color2)
- }
+ }*/
</style>
play/src/assets/test.css
@@ -1,4 +1,4 @@
-/*@import "./test2";*/
+@import "./test2";
/** test.css **/
div {
play/src/assets/test2.css
@@ -1,4 +1,10 @@
-
-.test2 {
- color: v-bind(color);
+@import "./test";
+/*
+存在相同样式(test.css),会以先出现的那个优先
+*/
+/*div {
+ color: v-bind(appTheme2);
+}*/
+.test {
0 commit comments