From f811c16b7451fda6b74fe8f156ce8da58d33fd67 Mon Sep 17 00:00:00 2001 From: Travis Date: Wed, 28 Sep 2022 11:45:40 +0800 Subject: [PATCH 1/4] fix(compiler-core): allow unicode to appear in simple identifiers --- .../compiler-core/__tests__/transforms/vOn.spec.ts | 12 ++++++++++++ packages/compiler-core/src/utils.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index 8f943a7491f..007038d9158 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -568,6 +568,18 @@ describe('compiler: transform v-on', () => { expect(root.cached).toBe(1) }) + test('should not be cached if the function references closure variables (v-for, v-slot)', () => { + const { root } = parseWithVOn( + `
`, + { + prefixIdentifiers: true, + cacheHandlers: true + } + ) + expect(root.cached).not.toBe(2) + expect(root.cached).toBe(1) + }) + test('inline function expression handler', () => { const { root, node } = parseWithVOn(`
`, { prefixIdentifiers: true, diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index c9e310fe089..21fc01ec993 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -65,7 +65,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) From fdd4b67bd87bd1569b0392e064f2ea64ba55beae Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 29 May 2024 14:01:02 +0000 Subject: [PATCH 2/4] [autofix.ci] apply automated fixes --- packages/compiler-core/__tests__/transforms/vOn.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index fea36247413..07c62af2759 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -607,8 +607,8 @@ describe('compiler: transform v-on', () => { `
`, { prefixIdentifiers: true, - cacheHandlers: true - } + cacheHandlers: true, + }, ) expect(root.cached).not.toBe(2) expect(root.cached).toBe(1) From b7a15d00fe99ec20ebe5c7b1b9dca2546e5f7294 Mon Sep 17 00:00:00 2001 From: Travis Date: Wed, 29 May 2024 22:49:10 +0800 Subject: [PATCH 3/4] test(compiler-core): Add unit testing again --- .../compiler-core/__tests__/transforms/vOn.spec.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index 07c62af2759..efe25664326 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -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,16 +603,16 @@ describe('compiler: transform v-on', () => { expect(root.cached).toBe(1) }) - test('should not be cached if the function references closure variables (v-for, v-slot)', () => { + test('unicode identifier should not be cached (v-for, v-slot)', () => { const { root } = parseWithVOn( - `
`, + `
`, { prefixIdentifiers: true, cacheHandlers: true, }, ) - expect(root.cached).not.toBe(2) - expect(root.cached).toBe(1) + expect(root.cached).not.toBe(1) + expect(root.cached).toBe(0) }) test('inline function expression handler', () => { From 00656cb8dd624c1574cb0ab723c81b972bb004d7 Mon Sep 17 00:00:00 2001 From: Travis Date: Thu, 30 May 2024 11:16:33 +0800 Subject: [PATCH 4/4] test(compiler-core): modify unit test --- packages/compiler-core/__tests__/transforms/vOn.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index efe25664326..27d5027533b 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -603,7 +603,7 @@ describe('compiler: transform v-on', () => { expect(root.cached).toBe(1) }) - test('unicode identifier should not be cached (v-for, v-slot)', () => { + test('unicode identifier should not be cached (v-for)', () => { const { root } = parseWithVOn( `
`, { @@ -611,7 +611,6 @@ describe('compiler: transform v-on', () => { cacheHandlers: true, }, ) - expect(root.cached).not.toBe(1) expect(root.cached).toBe(0) })