Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Dec 18, 2024
1 parent 94c473e commit 5f2d93e
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions packages/compiler-vapor/src/generators/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,30 @@ function genDeclarations(
context: CodegenContext,
): [Record<string, string>, CodeFragment[]] {
const [frag, push] = buildCodeFragment()
const ids= declarations.reduce((acc, cur) => {
if(!cur.replacement.includes('_')) {
acc[cur.replacement] = `_${cur.replacement}`
push(`const _${cur.replacement} = `, ...genExpression(cur.value, context), NEWLINE)
}
return acc
},{} as Record<string, string>)
const ids = declarations.reduce(
(acc, cur) => {
if (!cur.replacement.includes('_')) {
acc[cur.replacement] = `_${cur.replacement}`
push(
`const _${cur.replacement} = `,
...genExpression(cur.value, context),
NEWLINE,
)
}
return acc
},
{} as Record<string, string>,
)

for (let i = 0; i < declarations.length; i++) {
const { replacement, value } = declarations[i]
const isExp = replacement.includes('_')
if(isExp) {
if (isExp) {
ids[replacement] = `_${replacement}`
const descareFrag = context.withId(() => genExpression(value, context), isExp ? ids : {})
const descareFrag = context.withId(
() => genExpression(value, context),
isExp ? ids : {},
)
push(`const _${replacement} = `, ...descareFrag, NEWLINE)
}
}
Expand All @@ -180,12 +190,16 @@ function processExpressions(context: CodegenContext): DeclarationValue[] {
const options: BabelOptions = {
plugins: plugins ? [...plugins, 'typescript'] : ['typescript'],
}
const { block: { expressions } } = context
const {
block: { expressions },
} = context
const seenExp: Record<string, number> = Object.create(null)
const replaceMap = new Map<string, Set<SimpleExpressionNode>>()
const expMap = new Map<string, Node>()
const declarations: DeclarationValue[] = []
expressions.forEach(exp => extractExpression(exp, seenExp, replaceMap, expMap))
expressions.forEach(exp =>
extractExpression(exp, seenExp, replaceMap, expMap),
)
for (const [key, values] of replaceMap) {
if (seenExp[key]! > 1 && values.size > 0) {
const varName = getReplacementName(key)
Expand All @@ -195,15 +209,17 @@ function processExpressions(context: CodegenContext): DeclarationValue[] {
declarations.push({
replacement: varName,
// TODO 获取 key 对应的 node 表达式
value: extend({ ast: isExp ? parseExpression(`(${key})`, options) : null }, createSimpleExpression(key)),
value: extend(
{ ast: isExp ? parseExpression(`(${key})`, options) : null },
createSimpleExpression(key),
),
})
}
const replaceRE = new RegExp(escapeRegExp(key), 'g')
values.forEach(node => {
node.content = node.content.replace(replaceRE, varName)
node.ast = parseExpression(`(${node.content})`, options)
})

}
}

Expand Down Expand Up @@ -268,7 +284,10 @@ function extractExpression(
}
}

function getMemberExp(expr: Node, onIdentifier: (name: string) => void): string {
function getMemberExp(
expr: Node,
onIdentifier: (name: string) => void,
): string {
if (!expr) return ''

switch (expr.type) {
Expand Down

0 comments on commit 5f2d93e

Please sign in to comment.