File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 11const INPUT_VAR_NAME = "it" ;
22const QUOTE_CHAR = '"' ;
3+ const ESCAPE_CHAR = "\\" ;
34
45export type Template < T extends object > = ( data : T ) => string ;
56
@@ -12,8 +13,8 @@ export function compile(value: string, displayName = "template") {
1213 const char = value [ i ] ;
1314
1415 // Escape special characters due to quoting.
15- if ( char === QUOTE_CHAR || char === "\\" ) {
16- result += "\\" ;
16+ if ( char === QUOTE_CHAR || char === ESCAPE_CHAR ) {
17+ result += ESCAPE_CHAR ;
1718 }
1819
1920 // Process template param.
@@ -25,7 +26,7 @@ export function compile(value: string, displayName = "template") {
2526 for ( let j = start ; j < value . length ; j ++ ) {
2627 const char = value [ j ] ;
2728 if ( withinString ) {
28- if ( char === "\\" ) j ++ ;
29+ if ( char === ESCAPE_CHAR ) j ++ ;
2930 else if ( char === withinString ) withinString = "" ;
3031 continue ;
3132 } else if ( char === "}" && value [ j + 1 ] === "}" ) {
@@ -40,7 +41,7 @@ export function compile(value: string, displayName = "template") {
4041 if ( ! end ) throw new TypeError ( `Template parameter not closed at ${ i } ` ) ;
4142
4243 const param = value . slice ( start , end ) . trim ( ) ;
43- const sep = `+-/*.?:![]()%&|;={}<>,` . indexOf ( param [ 0 ] ) > - 1 ? "" : "." ;
44+ const sep = param [ 0 ] === "[" ? "" : "." ;
4445 result += `${ QUOTE_CHAR } + (${ INPUT_VAR_NAME } ${ sep } ${ param } ) + ${ QUOTE_CHAR } ` ;
4546 continue ;
4647 }
You can’t perform that action at this time.
0 commit comments