Skip to content

Commit 4153dfe

Browse files
committed
chore: parse bindings type
1 parent 1ade268 commit 4153dfe

File tree

8 files changed

+337
-198
lines changed

8 files changed

+337
-198
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@
7474
"update:deps": "npx taze -w && pnpm run init"
7575
},
7676
"peerDependencies": {
77+
"@ast-grep/napi": "^0.6.3",
7778
"baiwusanyu-utils": "^1.0.12",
7879
"chalk": "^4.1.2",
7980
"estree-walker-ts": "^1.0.0",
8081
"fast-glob": "^3.2.12",
8182
"fs-extra": "^11.1.1",
8283
"hash-sum": "^2.0.0",
8384
"magic-string": "^0.30.0",
84-
"@ast-grep/napi": "^0.6.3",
8585
"unplugin": "^1.3.1",
8686
"vue": "^3.2.47"
8787
},
8888
"dependencies": {
89+
"@ast-grep/napi": "^0.6.3",
8990
"baiwusanyu-utils": "^1.0.12",
9091
"chalk": "^4.1.2",
9192
"estree-walker-ts": "^1.0.0",
@@ -94,7 +95,6 @@
9495
"hash-sum": "^2.0.0",
9596
"magic-string": "^0.30.0",
9697
"unplugin": "^1.3.1",
97-
"@ast-grep/napi": "^0.6.3",
9898
"vue": "^3.3.4"
9999
},
100100
"devDependencies": {
@@ -119,8 +119,8 @@
119119
"@vitejs/plugin-vue-jsx": "^3.0.1",
120120
"@vitest/coverage-c8": "^0.31.1",
121121
"@vitest/ui": "^0.31.1",
122-
"@vue/compiler-sfc": "^3.3.4",
123122
"@vue/compiler-dom": "^3.3.4",
123+
"@vue/compiler-sfc": "^3.3.4",
124124
"bumpp": "^9.1.0",
125125
"cross-env": "^7.0.3",
126126
"eslint": "^8.41.0",

packages/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const unplugin = createUnplugin<Options>(
4141
userOptions,
4242
framework: meta.framework,
4343
isScriptSetup: false,
44+
bindingsTypeMap: {},
4445
} as IVueCSSVarsCtx
4546

4647
return [

packages/core/inject/inject-cssvars.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import hash from 'hash-sum'
22
import { type MagicStringBase } from 'magic-string-ast'
33
import { ts } from '@ast-grep/napi'
4-
import MagicString from "magic-string";
4+
import MagicString from 'magic-string'
55
import type { IParseSFCRes, TMatchVariable } from '../parser'
66

77
const importer = 'import { useCssVars as _useCssVars } from "vue"\n'
@@ -11,15 +11,15 @@ function findIdentifierFromExp(cssContent: string) {
1111
rule: {
1212
matches: 'cssComplexExpIdentifier',
1313
},
14-
utils:{
14+
utils: {
1515
cssComplexExpIdentifier: {
1616
any: [
1717
{
1818
kind: 'identifier',
1919
},
2020
],
21-
}
22-
}
21+
},
22+
},
2323
})
2424
}
2525

@@ -142,30 +142,21 @@ export function createCSSVarsObjCode(
142142
const hashVal = vbVar.hash || hash(vbVar.value + vbVar.has)
143143
vbVar.hash = hashVal
144144
let varStr = ''
145-
// composition api 和 option api 一直帶 _ctx
146-
if (!isScriptSetup) { // non-inline
147-
varStr = vbVar.value ? `(_ctx.${vbVar.value})` : '()'
148-
} else {
149-
if(!vbVar.has){
150-
varStr = `_ctx.${vbVar.value}`
151-
}else {
152-
// TODO use BindingsType
153-
debugger
154-
const ms = new MagicString(vbVar.value)
155-
// get Identifier sgNode
156-
const cssBindKeySgNodes = findIdentifierFromExp(vbVar.value)
157-
cssBindKeySgNodes.forEach((node) => {
158-
const range = node.range()
159-
ms.overwrite(
160-
range.start.index,
161-
range.end.index,
162-
`(_ctx.${node.text()})`
163-
// genCSSVarsValue(node, bindings, propsAlias),
164-
)
165-
})
166-
varStr = ms.toString()
167-
}
168-
}
145+
146+
const ms = new MagicString(vbVar.value)
147+
// get Identifier sgNode
148+
const cssBindKeySgNodes = findIdentifierFromExp(vbVar.value)
149+
cssBindKeySgNodes.forEach((node) => {
150+
const range = node.range()
151+
ms.overwrite(
152+
range.start.index,
153+
range.end.index,
154+
// non-inline composition api 和 option api 一直帶 _ctx
155+
!isScriptSetup ? `(_ctx.${node.text()})` : '',
156+
// genCSSVarsValue(node, bindings, propsAlias),
157+
)
158+
})
159+
varStr = ms.toString()
169160
resCode = `\n "${hashVal}": ${varStr},${resCode}`
170161
})
171162

@@ -206,3 +197,15 @@ export function createUseCssVarsCode(
206197
}
207198
return resCode
208199
}
200+
201+
// TODO non-inline css - vite - dev
202+
// TODO inline bindingTypes - vite - dev
203+
204+
// TODO non-inline css - vite - build
205+
// TODO inline bindingTypes - vite - build
206+
207+
// TODO non-inline css - webpack - dev
208+
// TODO inline bindingTypes - webpack - dev
209+
210+
// TODO non-inline css - webpack - build
211+
// TODO inline bindingTypes - webpack - build

packages/core/parser/parser-compiled-sfc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function resetVar() {
8787
}
8888

8989
// test only
90-
export function getVar() {
90+
export /*#__PURE__*/ function getVar() {
9191
return {
9292
isSetupEnter,
9393
setupBodyNode,
@@ -98,7 +98,7 @@ export function getVar() {
9898
}
9999

100100
// test only
101-
export function setVar(k: string, v: any) {
101+
export /*#__PURE__*/ function setVar(k: string, v: any) {
102102
if (k === 'isSetupEnter')
103103
isSetupEnter = v
104104

0 commit comments

Comments
 (0)