Skip to content

Commit 2cb1733

Browse files
committed
chore: format code
1 parent eed3b21 commit 2cb1733

File tree

5 files changed

+38
-43
lines changed

5 files changed

+38
-43
lines changed

Diff for: packages/core/inject/__test__/inject-cssvars.spec.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -498,36 +498,36 @@ describe('inject-cssvars', () => {
498498
fn8: CSSVarsBindingTypes.SETUP_LET,
499499
fn9: CSSVarsBindingTypes.SETUP_LET,
500500
a: CSSVarsBindingTypes.SETUP_CONST,
501-
fooAlias:CSSVarsBindingTypes.SETUP_MAYBE_REF,
501+
fooAlias: CSSVarsBindingTypes.SETUP_MAYBE_REF,
502502
bar: CSSVarsBindingTypes.SETUP_MAYBE_REF,
503503
hh: CSSVarsBindingTypes.SETUP_MAYBE_REF,
504504
})
505-
expect(res.mgcStr.toString()).toContain(' "75f73e04": _unref(hh),\n' +
506-
' "0104392a": _unref(bar),\n' +
507-
' "2bbe40ae": _unref(fooAlias),\n' +
508-
' "770ddb39": a,\n' +
509-
' "33bad66e": _unref(fn9),\n' +
510-
' "33d70570": _unref(fn8),\n' +
511-
' "33f33472": _unref(fn7),\n' +
512-
' "340f6374": fn6,\n' +
513-
' "342b9276": _unref(fn5),\n' +
514-
' "3447c178": _unref(fn4),\n' +
515-
' "3463f07a": fn3,\n' +
516-
' "34801f7c": fn2,\n' +
517-
' "349c4e7e": _ctx.fn1,\n' +
518-
' "e29ebaa8": _unref(head4),\n' +
519-
' "268cecf6": _unref(bar4),\n' +
520-
' "6bb6f0b2": _unref(foo4),\n' +
521-
' "6f79c2b5": _unref(color4),\n' +
522-
' "e2bae9aa": head3,\n' +
523-
' "26a91bf8": bar3,\n' +
524-
' "6ba8d931": foo3,\n' +
525-
' "6f6bab34": color3,\n' +
526-
' "e2d718ac": _unref(head2),\n' +
527-
' "6b9ac1b0": _unref(foo2),\n' +
528-
' "6f5d93b3": color2,\n' +
529-
' "2a5f3ac4": _unref(foo),\n' +
530-
' "1439c43b": color.value,')
505+
expect(res.mgcStr.toString()).toContain(' "75f73e04": _unref(hh),\n'
506+
+ ' "0104392a": _unref(bar),\n'
507+
+ ' "2bbe40ae": _unref(fooAlias),\n'
508+
+ ' "770ddb39": a,\n'
509+
+ ' "33bad66e": _unref(fn9),\n'
510+
+ ' "33d70570": _unref(fn8),\n'
511+
+ ' "33f33472": _unref(fn7),\n'
512+
+ ' "340f6374": fn6,\n'
513+
+ ' "342b9276": _unref(fn5),\n'
514+
+ ' "3447c178": _unref(fn4),\n'
515+
+ ' "3463f07a": fn3,\n'
516+
+ ' "34801f7c": fn2,\n'
517+
+ ' "349c4e7e": _ctx.fn1,\n'
518+
+ ' "e29ebaa8": _unref(head4),\n'
519+
+ ' "268cecf6": _unref(bar4),\n'
520+
+ ' "6bb6f0b2": _unref(foo4),\n'
521+
+ ' "6f79c2b5": _unref(color4),\n'
522+
+ ' "e2bae9aa": head3,\n'
523+
+ ' "26a91bf8": bar3,\n'
524+
+ ' "6ba8d931": foo3,\n'
525+
+ ' "6f6bab34": color3,\n'
526+
+ ' "e2d718ac": _unref(head2),\n'
527+
+ ' "6b9ac1b0": _unref(foo2),\n'
528+
+ ' "6f5d93b3": color2,\n'
529+
+ ' "2a5f3ac4": _unref(foo),\n'
530+
+ ' "1439c43b": color.value,')
531531
expect(res.mgcStr.toString()).toContain('_useCssVars')
532532
})
533533
})

Diff for: packages/core/inject/inject-cssvars.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import hash from 'hash-sum'
22
import { type MagicStringBase } from 'magic-string-ast'
33
import { ts } from '@ast-grep/napi'
44
import MagicString from 'magic-string'
5-
import { BindingTypes } from '@vue/compiler-dom'
65
import { CSSVarsBindingTypes } from '../parser/utils'
76
import type { BindingMetadata } from '@vue/compiler-dom'
87
import type { IParseSFCRes, TMatchVariable } from '../parser'

Diff for: packages/core/parser/__test__/parser-script-binding.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, test } from 'vitest'
22
import { parse } from '@vue/compiler-sfc'
3-
import { getObjectExpressionReturnNode } from '../parser-variable'
43
import { analyzeScriptBindings } from '../parser-script-bindings'
54

65
describe('parse sfc to set bindings type', () => {

Diff for: packages/core/parser/parser-script-bindings.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,29 @@ export function analyzeScriptBindings(descriptor: SFCDescriptor): BindingMetadat
1919
}
2020

2121
function walkSgNodeToGetBindings(node: SgNode, bindings: BindingMetadata) {
22-
node.findAll(getRules('LET_VAR')).map((n) => {
22+
node.findAll(getRules('LET_VAR')).forEach((n) => {
2323
const key = n.getMatch('VAR')?.text() || ''
2424
bindings[key] = CSSVarsBindingTypes.SETUP_LET
2525
})
2626

2727
let constVARs = node.findAll(getRules('CONST_VAR'))
2828
// function x(){}
2929
constVARs = constVARs.concat(node.findAll(getRules('CONST_NOR_FN')))
30-
constVARs.map((n) => {
30+
constVARs.forEach((n) => {
3131
const key = n.getMatch('VAR')?.text() || n.find(getRules('IDENT_NAME'))?.text() || ''
3232
if (!key) return
3333
bindings[key] = CSSVarsBindingTypes.LITERAL_CONST
3434
// ref
3535
if (n.find(getRules('CONST_REF_VAR'))) {
3636
bindings[key] = CSSVarsBindingTypes.SETUP_REF
37-
}
38-
// reactive
39-
else if (n.find(getRules('CONST_REACTIVE_VAR'))) {
37+
} else if (n.find(getRules('CONST_REACTIVE_VAR'))) {
38+
// reactive
4039
bindings[key] = CSSVarsBindingTypes.SETUP_REACTIVE_CONST
41-
}
42-
// const a = b()、new xxx()
43-
else if (n.find(getRules('FN_CALL'))
40+
} else if (n.find(getRules('FN_CALL'))
4441
|| n.find(getRules('NEW_EXP'))
4542
|| (n.find(getRules('OBJ_PATTERN'))?.text().startsWith('{')
4643
&& n.find(getRules('OBJ_PATTERN'))?.text().endsWith('}'))) {
44+
// const a = b()、new xxx()
4745
bindings[key] = CSSVarsBindingTypes.SETUP_MAYBE_REF
4846
// 解构赋值
4947
const deconstructVal = n.find(getRules('OBJ_PATTERN'))
@@ -52,18 +50,17 @@ function walkSgNodeToGetBindings(node: SgNode, bindings: BindingMetadata) {
5250
Reflect.deleteProperty(bindings, key)
5351
bindings[nI.text()] = CSSVarsBindingTypes.SETUP_MAYBE_REF
5452
})
55-
}
56-
// const a = () => {}
57-
// const a = function x(){}
58-
// function x(){}
59-
else if (
53+
} else if (
6054
n.find(getRules('ARROW_FN'))
6155
|| n.find(getRules('NOR_FN'))
6256
|| n.find(getRules('OBJ_VAR'))
6357
|| n.find(getRules('ARR_VAR'))
6458
|| n.kind() === 'function_declaration'
6559
|| n.find(getRules('NOR_FN_VAR'))
6660
) {
61+
// const a = () => {}
62+
// const a = function x(){}
63+
// function x(){}
6764
if (n.kind() === 'function_declaration')
6865
bindings[n.find(getRules('IDENT_NAME'))?.text() || 'unk'] = CSSVarsBindingTypes.SETUP_CONST
6966
else

Diff for: packages/core/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BindingMetadata, BindingTypes } from '@vue/compiler-dom'
1+
import type { BindingMetadata } from '@vue/compiler-dom'
22
import type { TMatchVariable } from './parser'
33
import type { Node } from '@babel/types'
44
import type { FilterPattern } from '@rollup/pluginutils'

0 commit comments

Comments
 (0)