Skip to content

Commit 74cc8bd

Browse files
committed
chore: temp commit
1 parent d20c7c4 commit 74cc8bd

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

packages/core/css/__test__/process-css.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,36 @@ describe('process css', () => {
6868
})
6969
})
7070

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+
vBindCode: {
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+
foo: new Set(['v-bind(foo)']),
95+
})
96+
expect(mockRes[1].vBindCode).toMatchObject({
97+
bar: new Set(['v-bind(bar)']),
98+
})
99+
})
100+
71101
test('createCSSModule: basic', () => {
72102
const mockCssFiles = new Map()
73103
const mockCSSFilesContent = {

packages/core/css/process-css.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { walkCSSTree } from './pre-process-css'
55
import type { ICSSFile, ICSSFileMap } from '../types'
66
import type { SFCDescriptor } from '@vue/compiler-sfc'
77

8+
const matchedMark = new Set<string>()
89
export const getCSSFileRecursion = (key: string, cssFiles: ICSSFileMap, cb: (res: ICSSFile) => void) => {
10+
// 避免循环引用
11+
if (matchedMark.has(key)) return
912
const cssFile = cssFiles.get(key)
1013
if (cssFile) {
14+
matchedMark.add(key)
1115
cb(cssFile)
1216
if (cssFile.importer.size > 0) {
1317
cssFile.importer.forEach((value) => {

play/src/App.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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'
55
const color = appAsd()
6-
const appTheme2 = 'red'
6+
const appTheme2 = 'blue'
77
const appTheme3 = ref('red')
88
const appTheme4 = reactive({ color: 'red' })
99
const appTheme5 = { color: 'red' }
1010
const appTheme6 = () => 'red'
11-
</script> -->
11+
</script>
1212
<!-- <script lang="ts">
1313
const sc2 = 'red'
1414
</script> -->
@@ -43,7 +43,7 @@ export default defineComponent({
4343
})
4444
</script> -->
4545

46-
<script>
46+
<!-- <script>
4747
export default {
4848
setup() {
4949
const color3 = 'red'
@@ -57,7 +57,7 @@ export default {
5757
}
5858
},
5959
}
60-
</script>
60+
</script> -->
6161

6262
<template>
6363
<div class="test">
@@ -68,7 +68,7 @@ export default {
6868

6969
<style scoped>
7070
@import "./assets/test";
71-
div {
71+
/* div {
7272
color: v-bind(color2)
73-
}
73+
}*/
7474
</style>

play/src/assets/test.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*@import "./test2";*/
1+
@import "./test2";
22

33
/** test.css **/
44
div {

play/src/assets/test2.css

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
2-
.test2 {
3-
color: v-bind(color);
1+
@import "./test";
2+
/*
3+
存在相同样式(test.css),会以先出现的那个优先
4+
*/
5+
/*div {
6+
color: v-bind(appTheme2);
7+
}*/
8+
.test {
9+
color: v-bind(appTheme2);
410
}

0 commit comments

Comments
 (0)