mirror of https://github.com/vuejs/core.git
fix(compiler-vapor): handle special characters in cached variable names (#13626)
This commit is contained in:
parent
f04c9c342d
commit
a5e106d96e
|
@ -12,6 +12,21 @@ export function render(_ctx) {
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`v-on > component event with special characters 1`] = `
|
||||||
|
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';
|
||||||
|
|
||||||
|
export function render(_ctx) {
|
||||||
|
const _component_Foo = _resolveComponent("Foo")
|
||||||
|
const _on_update_model = () => {}
|
||||||
|
const _on_update_model1 = () => {}
|
||||||
|
const n0 = _createComponentWithFallback(_component_Foo, {
|
||||||
|
"onUpdate:model": () => _on_update_model,
|
||||||
|
"onUpdate-model": () => _on_update_model1
|
||||||
|
}, null, true)
|
||||||
|
return n0
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`v-on > dynamic arg 1`] = `
|
exports[`v-on > dynamic arg 1`] = `
|
||||||
"import { on as _on, renderEffect as _renderEffect, template as _template } from 'vue';
|
"import { on as _on, renderEffect as _renderEffect, template as _template } from 'vue';
|
||||||
const t0 = _template("<div></div>", true)
|
const t0 = _template("<div></div>", true)
|
||||||
|
|
|
@ -695,4 +695,16 @@ describe('v-on', () => {
|
||||||
expect(code).matchSnapshot()
|
expect(code).matchSnapshot()
|
||||||
expect(code).include('n0.$evtclick = e => _ctx.handleClick(e)')
|
expect(code).include('n0.$evtclick = e => _ctx.handleClick(e)')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('component event with special characters', () => {
|
||||||
|
const { code } = compileWithVOn(
|
||||||
|
`<Foo @update:model="() => {}" @update-model="() => {}" />`,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(code).matchSnapshot()
|
||||||
|
expect(code).contains('const _on_update_model = () => {}')
|
||||||
|
expect(code).contains('const _on_update_model1 = () => {}')
|
||||||
|
expect(code).contains('"onUpdate:model": () => _on_update_model')
|
||||||
|
expect(code).contains('"onUpdate-model": () => _on_update_model1')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -26,7 +26,7 @@ import {
|
||||||
genCall,
|
genCall,
|
||||||
genMulti,
|
genMulti,
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import { genExpression } from './expression'
|
import { genExpression, genVarName } from './expression'
|
||||||
import { genPropKey, genPropValue } from './prop'
|
import { genPropKey, genPropValue } from './prop'
|
||||||
import {
|
import {
|
||||||
type SimpleExpressionNode,
|
type SimpleExpressionNode,
|
||||||
|
@ -102,6 +102,7 @@ export function genCreateComponent(
|
||||||
|
|
||||||
function getUniqueHandlerName(context: CodegenContext, name: string): string {
|
function getUniqueHandlerName(context: CodegenContext, name: string): string {
|
||||||
const { seenInlineHandlerNames } = context
|
const { seenInlineHandlerNames } = context
|
||||||
|
name = genVarName(name)
|
||||||
const count = seenInlineHandlerNames[name] || 0
|
const count = seenInlineHandlerNames[name] || 0
|
||||||
seenInlineHandlerNames[name] = count + 1
|
seenInlineHandlerNames[name] = count + 1
|
||||||
return count === 0 ? name : `${name}${count}`
|
return count === 0 ? name : `${name}${count}`
|
||||||
|
|
|
@ -647,7 +647,7 @@ function parseExp(context: CodegenContext, content: string): Node {
|
||||||
return parseExpression(`(${content})`, options)
|
return parseExpression(`(${content})`, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
function genVarName(exp: string): string {
|
export function genVarName(exp: string): string {
|
||||||
return `${exp
|
return `${exp
|
||||||
.replace(/[^a-zA-Z0-9]/g, '_')
|
.replace(/[^a-zA-Z0-9]/g, '_')
|
||||||
.replace(/_+/g, '_')
|
.replace(/_+/g, '_')
|
||||||
|
|
Loading…
Reference in New Issue