Skip to content

Commit 07b3c4b

Browse files
authoredMay 27, 2024··
fix(compat): correctly transform non-identifier expressions in legacy filter syntax (#10896)
close #10852
1 parent 37f9ef8 commit 07b3c4b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
 

‎packages/compiler-core/src/compat/transformFilter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ function parseFilter(node: SimpleExpressionNode, context: TransformContext) {
168168
expression = wrapFilter(expression, filters[i], context)
169169
}
170170
node.content = expression
171+
// reset ast since the content is replaced
172+
node.ast = undefined
171173
}
172174
}
173175

‎packages/compiler-sfc/__tests__/compileTemplate.spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type RawSourceMap, SourceMapConsumer } from 'source-map-js'
2+
import { parse as babelParse } from '@babel/parser'
23
import {
34
type SFCTemplateCompileOptions,
45
compileTemplate,
@@ -452,6 +453,36 @@ test('prefixing edge case for reused AST ssr mode', () => {
452453
).not.toThrowError()
453454
})
454455

456+
// #10852
457+
test('non-identifier expression in legacy filter syntax', () => {
458+
const src = `
459+
<template>
460+
<div>
461+
Today is
462+
{{ new Date() | formatDate }}
463+
</div>
464+
</template>
465+
`
466+
467+
const { descriptor } = parse(src)
468+
const compilationResult = compileTemplate({
469+
id: 'xxx',
470+
filename: 'test.vue',
471+
ast: descriptor.template!.ast,
472+
source: descriptor.template!.content,
473+
ssr: false,
474+
compilerOptions: {
475+
compatConfig: {
476+
MODE: 2,
477+
},
478+
},
479+
})
480+
481+
expect(() => {
482+
babelParse(compilationResult.code, { sourceType: 'module' })
483+
}).not.toThrow()
484+
})
485+
455486
interface Pos {
456487
line: number
457488
column: number

0 commit comments

Comments
 (0)
Please sign in to comment.