Skip to content

Commit

Permalink
fix(compiler-core): allow unicode to appear in simple identifiers (#6765
Browse files Browse the repository at this point in the history
)

close #6367
  • Loading branch information
godxiaoji authored May 30, 2024
1 parent 4c74302 commit 3ea9644
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion packages/compiler-core/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
baseParse as parse,
transform,
} from '../../src'
import { transformFor } from '../../src/transforms/vFor'
import { transformOn } from '../../src/transforms/vOn'
import { transformElement } from '../../src/transforms/transformElement'
import { transformExpression } from '../../src/transforms/transformExpression'

function parseWithVOn(template: string, options: CompilerOptions = {}) {
const ast = parse(template, options)
transform(ast, {
nodeTransforms: [transformExpression, transformElement],
nodeTransforms: [transformExpression, transformElement, transformFor],
directiveTransforms: {
on: transformOn,
},
Expand Down Expand Up @@ -602,6 +603,17 @@ describe('compiler: transform v-on', () => {
expect(root.cached).toBe(1)
})

test('unicode identifier should not be cached (v-for)', () => {
const { root } = parseWithVOn(
`<div v-for="项 in items" :key="value"><div v-on:click="foo(项)"/></div>`,
{
prefixIdentifiers: true,
cacheHandlers: true,
},
)
expect(root.cached).toBe(0)
})

test('inline function expression handler', () => {
const { root, node } = parseWithVOn(`<div v-on:click="() => foo()" />`, {
prefixIdentifiers: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function isCoreComponent(tag: string): symbol | void {
}
}

const nonIdentifierRE = /^\d|[^\$\w]/
const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/
export const isSimpleIdentifier = (name: string): boolean =>
!nonIdentifierRE.test(name)

Expand Down

0 comments on commit 3ea9644

Please sign in to comment.