Skip to content

Commit 2cbaf72

Browse files
authored
refactor: refactor project dir and updated unit test (#16)
* update: updated unit test * refactor: refactor project dir
1 parent 96bf044 commit 2cbaf72

24 files changed

+92
-27
lines changed

packages/core/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { createUnplugin } from 'unplugin'
22
import { NAME } from '@unplugin-vue-cssvars/utils'
33
import { createFilter } from '@rollup/pluginutils'
44
import { parse } from '@vue/compiler-sfc'
5-
import { preProcessCSS } from './css/pre-process-css'
6-
import { createCSSModule } from './css/process-css'
5+
import { preProcessCSS } from './runtime/pre-process-css'
6+
import { createCSSModule } from './runtime/process-css'
77
import { initOption } from './option'
8-
import { getVariable } from './get-variable'
8+
import { getVariable } from './parser/parser-variable'
99
import { injectCSSVars } from './inject/inject-cssvars'
1010
import { revokeCSSVars } from './inject/revoke-cssvars'
1111
import type { IBundle, Options } from './types'

packages/core/option/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
extend,
66
} from '@unplugin-vue-cssvars/utils'
77
import type { Options } from '../types'
8-
export const defaultOption: Options = {
8+
9+
const defaultOption: Options = {
910
rootDir: resolve(),
1011
include: DEFAULT_INCLUDE_REG,
1112
exclude: DEFAULT_EXCLUDE_REG,

packages/core/get-variable/__test__/get-variable.spec.ts renamed to packages/core/parser/__test__/parser-variable.spec.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { describe, expect, test } from 'vitest'
22
import { parse as babelParse } from '@babel/parser'
33
import {
4-
getObjectExpressionReturnNode, getVariableNameByScript, getVariableNameBySetup,
4+
getObjectExpressionReturnNode,
5+
getVariable,
6+
getVariableNameByScript,
7+
getVariableNameBySetup,
58
setScriptContent,
6-
} from '../index'
9+
} from '../parser-variable'
710
describe('get variable name', () => {
811
test('getObjectExpressionReturnNode', () => {
912
const mockNode = {
@@ -406,4 +409,31 @@ describe('get variable name', () => {
406409
},
407410
})
408411
})
412+
413+
test('getVariable: basic', () => {
414+
const mockDescriptor = {
415+
scriptSetup: null,
416+
script: {
417+
content: 'export default {\n'
418+
+ 'data(){\n'
419+
+ ' return {\n'
420+
+ ' foo: \'data-foo\',\n'
421+
+ ' }\n'
422+
+ ' },\n'
423+
+ ' setup(){\n'
424+
+ ' return {\n'
425+
+ ' foo: \'setup-foo\',\n'
426+
+ ' }\n'
427+
+ ' }\n'
428+
+ '}',
429+
},
430+
} as any
431+
const res = getVariable(mockDescriptor)
432+
expect(res).toMatchObject({
433+
foo: {
434+
type: 'StringLiteral',
435+
value: 'setup-foo',
436+
},
437+
})
438+
})
409439
})
File renamed without changes.
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import test
2+
#app
3+
div
4+
color: v-bind(sassColor)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)