File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,8 @@ import { Position } from '../src/ast'
22import {
33 getInnerRange ,
44 advancePositionWithClone ,
5- isMemberExpression
5+ isMemberExpression ,
6+ toValidAssetId
67} from '../src/utils'
78
89function p ( line : number , column : number , offset : number ) : Position {
@@ -107,3 +108,13 @@ test('isMemberExpression', () => {
107108 expect ( isMemberExpression ( 'a?b:c' ) ) . toBe ( false )
108109 expect ( isMemberExpression ( `state['text'] = $event` ) ) . toBe ( false )
109110} )
111+
112+ test ( 'toValidAssetId' , ( ) => {
113+ expect ( toValidAssetId ( 'foo' , 'component' ) ) . toBe ( '_component_foo' )
114+ expect ( toValidAssetId ( 'p' , 'directive' ) ) . toBe ( '_directive_p' )
115+ expect ( toValidAssetId ( 'div' , 'filter' ) ) . toBe ( '_filter_div' )
116+ expect ( toValidAssetId ( 'foo-bar' , 'component' ) ) . toBe ( '_component_foo_bar' )
117+ expect ( toValidAssetId ( 'test-测试-1' , 'component' ) ) . toBe (
118+ '_component_test_2797935797_1'
119+ )
120+ } )
Original file line number Diff line number Diff line change @@ -430,7 +430,10 @@ export function toValidAssetId(
430430 name : string ,
431431 type : 'component' | 'directive' | 'filter'
432432) : string {
433- return `_${ type } _${ name . replace ( / [ ^ \w ] / g, '_' ) } `
433+ // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
434+ return `_${ type } _${ name . replace ( / [ ^ \w ] / g, ( searchValue , replaceValue ) => {
435+ return searchValue === '-' ? '_' : name . charCodeAt ( replaceValue ) . toString ( )
436+ } ) } `
434437}
435438
436439// Check if a node contains expressions that reference current context scope ids
You can’t perform that action at this time.
0 commit comments