File tree 2 files changed +16
-2
lines changed
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'
2
2
import {
3
3
getInnerRange ,
4
4
advancePositionWithClone ,
5
- isMemberExpression
5
+ isMemberExpression ,
6
+ toValidAssetId
6
7
} from '../src/utils'
7
8
8
9
function p ( line : number , column : number , offset : number ) : Position {
@@ -107,3 +108,13 @@ test('isMemberExpression', () => {
107
108
expect ( isMemberExpression ( 'a?b:c' ) ) . toBe ( false )
108
109
expect ( isMemberExpression ( `state['text'] = $event` ) ) . toBe ( false )
109
110
} )
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(
430
430
name : string ,
431
431
type : 'component' | 'directive' | 'filter'
432
432
) : 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
+ } ) } `
434
437
}
435
438
436
439
// Check if a node contains expressions that reference current context scope ids
You can’t perform that action at this time.
0 commit comments