Skip to content

Commit 4d545e5

Browse files
committed
chore: temp commit
1 parent 918ee94 commit 4d545e5

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

packages/core/inject/inject-css.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { MagicStringBase } from 'magic-string-ast'
55
import type { TInjectCSSContent } from '../runtime/process-css'
66
import type { SFCDescriptor } from '@vue/compiler-sfc'
77
import type { TMatchVariable } from '../parser'
8+
import {ts} from "@ast-grep/napi";
89
export function injectCSSOnServer(
910
mgcStr: MagicStringBase,
1011
vbindVariableList: TMatchVariable | undefined,
@@ -16,7 +17,26 @@ export function injectCSSOnServer(
1617
if (!vbVar.hash && isHMR)
1718
vbVar.hash = hash(vbVar.value + vbVar.has)
1819

19-
vbVar.hash && (mgcStr = mgcStr.replaceAll(`v-bind-m(${vbVar.value})`, `var(--${vbVar.hash})`))
20+
21+
22+
const viteCSSSgNode = ts.parse(mgcStr.toString()).root().find({
23+
rule: {
24+
matches: 'VITE_CSS',
25+
},
26+
utils: {
27+
VITE_CSS: {
28+
any: [
29+
{
30+
pattern: "const __vite__css = \"$VAL\""
31+
},
32+
],
33+
}
34+
}
35+
})
36+
const content = viteCSSSgNode?.getMatch('VAL')
37+
vbVar.hash && (mgcStr = mgcStr.replaceAll(`v-bind-m`, `var`))
38+
vbVar.hash && (mgcStr = mgcStr.replaceAll(`${vbVar.value}`, `--${vbVar.hash}`))
39+
debugger
2040
})
2141
return mgcStr
2242
}

packages/core/inject/inject-cssvars.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {BindingMetadata, BindingTypes} from "@vue/compiler-dom";
88
import {CSSVarsBindingTypes} from "../parser/utils";
99

1010
const importer = 'import { useCssVars as _useCssVars } from "vue"\n'
11-
11+
const importerUnref = 'import { unref as _unref } from "vue"\n'
1212
function findIdentifierFromExp(cssContent: string) {
1313
return ts.parse(cssContent).root().findAll({
1414
rule: {
@@ -89,6 +89,7 @@ export function injectUseCssVarsSetup(
8989
parserRes: IParseSFCRes,
9090
) {
9191
let resMgcStr = mgcStr
92+
resMgcStr = resMgcStr.prependLeft(0, importerUnref)
9293
if (parserRes) {
9394
if (!hasUseCssVars
9495
&& parserRes.setupBodyNode
@@ -114,6 +115,7 @@ export function injectUseCssVarsOption(
114115
parserRes: IParseSFCRes,
115116
) {
116117
let resMgcStr = mgcStr
118+
resMgcStr = resMgcStr.prependLeft(0, importerUnref)
117119
if (!hasUseCssVars) {
118120
resMgcStr = resMgcStr.replaceAll('const _sfc_main', 'const __default__')
119121
resMgcStr = resMgcStr.replaceAll(
@@ -152,7 +154,6 @@ export function createCSSVarsObjCode(
152154
const ms = new MagicString(vbVar.value)
153155
// get Identifier sgNode
154156
const cssBindKeySgNodes = findIdentifierFromExp(vbVar.value)
155-
debugger
156157
cssBindKeySgNodes.forEach((node) => {
157158
const range = node.range()
158159
ms.overwrite(
@@ -235,14 +236,14 @@ function genCSSVarsValue(
235236
}
236237
return res
237238
}
238-
// TODO non-inline css - vite - dev
239-
// TODO inline bindingTypes - vite - dev
239+
// TODO non-inline css - vite - dev 🚧
240+
// TODO non-inline bindingTypes - vite - build
240241

241-
// TODO non-inline css - vite - build
242+
// TODO inline css - vite - dev
242243
// TODO inline bindingTypes - vite - build
243244

244245
// TODO non-inline css - webpack - dev
245-
// TODO inline bindingTypes - webpack - dev
246+
// TODO non-inline bindingTypes - webpack - build
246247

247-
// TODO non-inline css - webpack - build
248-
// TODO inline bindingTypes - webpack - build
248+
// TODO inline css - webpack - dev
249+
// TODO inline bindingTypes - webpack - build

play/vite/src/views/App.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ export default defineComponent({
109109
</script> -->
110110

111111
<template>
112-
<div id="foo" class="scss" @click="sassColor = 'red'">
113-
<p>app122</p>
114-
<compjsx />
115-
<!-- <Comp />
116-
<Comp2 /> -->
112+
<div>
113+
1
117114
</div>
115+
<p>
116+
1
117+
</p>
118118
</template>
119119

120120
<style lang="scss" scoped>

pnpm-lock.yaml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)