Skip to content

Commit

Permalink
test: add a failing test for vuejs#10852
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang committed May 9, 2024
1 parent fdd1dd5 commit d73dab7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
31 changes: 31 additions & 0 deletions packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type RawSourceMap, SourceMapConsumer } from 'source-map-js'
import { parse as babelParse } from '@babel/parser'
import {
type SFCTemplateCompileOptions,
compileTemplate,
Expand Down Expand Up @@ -452,6 +453,36 @@ test('prefixing edge case for reused AST ssr mode', () => {
).not.toThrowError()
})

// #10852
test('non-identifier expression in legacy filter syntax', () => {
const src = `
<template>
<div>
Today is
{{ new Date() | formatDate }}
</div>
</template>
`

const { descriptor } = parse(src)
const compilationResult = compileTemplate({
id: 'xxx',
filename: 'test.vue',
ast: descriptor.template!.ast,
source: descriptor.template!.content,
ssr: false,
compilerOptions: {
compatConfig: {
MODE: 2,
},
},
})

expect(() => {
babelParse(compilationResult.code, { sourceType: 'module' })
}).not.toThrow()

Check failure on line 483 in packages/compiler-sfc/__tests__/compileTemplate.spec.ts

View workflow job for this annotation

GitHub Actions / unit-test-windows

packages/compiler-sfc/__tests__/compileTemplate.spec.ts > non-identifier expression in legacy filter syntax

AssertionError: expected [Function] to not throw an error but 'SyntaxError: Missing semicolon. (6:14…' was thrown - Expected: undefined + Received: "SyntaxError: Missing semicolon. (6:140)" ❯ packages/compiler-sfc/__tests__/compileTemplate.spec.ts:483:10

Check failure on line 483 in packages/compiler-sfc/__tests__/compileTemplate.spec.ts

View workflow job for this annotation

GitHub Actions / unit-test

packages/compiler-sfc/__tests__/compileTemplate.spec.ts > non-identifier expression in legacy filter syntax

AssertionError: expected [Function] to not throw an error but 'SyntaxError: Missing semicolon. (6:14…' was thrown - Expected: undefined + Received: "SyntaxError: Missing semicolon. (6:140)" ❯ packages/compiler-sfc/__tests__/compileTemplate.spec.ts:483:10
})

interface Pos {
line: number
column: number
Expand Down
11 changes: 0 additions & 11 deletions packages/vue-compat/__tests__/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,4 @@ describe('FILTERS', () => {
}).$mount()
expect(vm.$el.textContent).toBe('6000000010000000')
})

it('#10852', () => {
const vm = new Vue({
template: `<div>{{ new Date() | formatDate }}</div>`,
filters: {
formatDate: (value: any) => new Date(value).toISOString().slice(0, 10),
},
}).$mount()
expect(vm.$el.textContent).toBe('2024-05-07')
expect(CompilerDeprecationTypes.COMPILER_FILTERS).toHaveBeenWarned()
})
})
15 changes: 0 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
packages:
- 'packages/*'
- 'explorations/*'

0 comments on commit d73dab7

Please sign in to comment.