@@ -46,7 +46,7 @@ class Snippet {
46
46
47
47
static parse ( template : string ) {
48
48
let fields : { seq : number | null , name : string } [ ] = [ ]
49
- let lines = [ ] , positions = [ ] , m
49
+ let lines = [ ] , positions : FieldPos [ ] = [ ] , m
50
50
for ( let line of template . split ( / \r \n ? | \n / ) ) {
51
51
while ( m = / [ # $ ] \{ (?: ( \d + ) (?: : ( [ ^ } ] * ) ) ? | ( [ ^ } ] * ) ) \} / . exec ( line ) ) {
52
52
let seq = m [ 1 ] ? + m [ 1 ] : null , name = m [ 2 ] || m [ 3 ] || "" , found = - 1
@@ -63,13 +63,13 @@ class Snippet {
63
63
positions . push ( new FieldPos ( found , lines . length , m . index , m . index + name . length ) )
64
64
line = line . slice ( 0 , m . index ) + name + line . slice ( m . index + m [ 0 ] . length )
65
65
}
66
- for ( let esc ; esc = / \\ ( [ { } ] ) / . exec ( line ) ; ) {
67
- line = line . slice ( 0 , esc . index ) + esc [ 1 ] + line . slice ( esc . index + esc [ 0 ] . length )
68
- for ( let pos of positions ) if ( pos . line == lines . length && pos . from > esc . index ) {
66
+ line = line . replace ( / \\ ( [ { } ] ) / g, ( _ , brace , index ) => {
67
+ for ( let pos of positions ) if ( pos . line == lines . length && pos . from > index ) {
69
68
pos . from --
70
69
pos . to --
71
70
}
72
- }
71
+ return brace
72
+ } )
73
73
lines . push ( line )
74
74
}
75
75
return new Snippet ( lines , positions )
0 commit comments