]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): allow unicode to appear in simple identifiers (#6765)
authorTravis <godxiaoji@163.com>
Thu, 30 May 2024 09:45:11 +0000 (17:45 +0800)
committerGitHub <noreply@github.com>
Thu, 30 May 2024 09:45:11 +0000 (17:45 +0800)
close #6367

packages/compiler-core/__tests__/transforms/vOn.spec.ts
packages/compiler-core/src/utils.ts

index b1c37e3f74e46d372460108d6a097b839fe297e2..27d5027533b37d67abc025512a0645f95e8ea08e 100644 (file)
@@ -10,6 +10,7 @@ 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'
@@ -17,7 +18,7 @@ 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,
     },
@@ -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,
index aa59602844003e3b3cfae80f14e9893ed25d5687..561c63578644ea46bb4fea092eddb6c8d60ce962 100644 (file)
@@ -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)