diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 820b1d97..f66245ad 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -318,7 +318,9 @@ function genIfBranch( if (condition) { // v-if or v-else-if const { push, indent, deindent, newline } = context - push(`(${condition.content})`, condition) + push(`(`) + genExpression(condition, context) + push(`)`) indent() context.indentLevel++ push(`? `) diff --git a/packages/compiler-core/src/index.ts b/packages/compiler-core/src/index.ts index 5af9df19..a3a3e711 100644 --- a/packages/compiler-core/src/index.ts +++ b/packages/compiler-core/src/index.ts @@ -21,9 +21,9 @@ export function compile( transform(ast, { ...options, nodeTransforms: [ + ...(!__BROWSER__ && options.useWith === false ? [rewriteExpression] : []), transformIf, transformFor, - ...(!__BROWSER__ && options.useWith === false ? [rewriteExpression] : []), prepareElementForCodegen, ...(options.nodeTransforms || []) // user transforms ], diff --git a/packages/compiler-core/src/transforms/expression.ts b/packages/compiler-core/src/transforms/expression.ts index 943cb5ac..d365091a 100644 --- a/packages/compiler-core/src/transforms/expression.ts +++ b/packages/compiler-core/src/transforms/expression.ts @@ -31,9 +31,6 @@ export const rewriteExpression: NodeTransform = (node, context) => { } } } - } else if (node.type === NodeTypes.IF) { - for (let i = 0; i < node.branches.length; i++) {} - } else if (node.type === NodeTypes.FOR) { } } @@ -102,10 +99,7 @@ function convertExpression( }) return { - type: NodeTypes.EXPRESSION, - content: '', - isStatic: false, - loc: node.loc, + ...node, children } } diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index 8c293ea9..ed42fa69 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -17,6 +17,7 @@ export const transformFor = createStructuralDirectiveTransform( if (aliases) { // TODO inject identifiers to context + // and remove on exit context.replaceNode({ type: NodeTypes.FOR, loc: node.loc,