@@ -145,13 +145,11 @@ export class Parser {
145145 const parts = [ ] ;
146146
147147 const start = token . start + 2 ;
148-
149148 let index = 0 ;
150149
151150 while ( index < text . length ) {
152151 const char = text [ index ] ;
153152
154- // Handle escaped opening braces
155153 if ( char === "{" ) {
156154 let brace = index ;
157155 let count = 0 ;
@@ -162,16 +160,13 @@ export class Parser {
162160 }
163161
164162 if ( count % 2 === 0 ) {
165- // Even number - literal { characters
166163 parts . push (
167164 new StringLiteral ( "{" . repeat ( count / 2 ) , start + brace + 1 )
168165 ) ;
169166 continue ;
170167 }
171168
172- // Odd count - must be interpolation
173- const inteprolation = index ;
174-
169+ const interpolation = index ;
175170 let depth = 1 ;
176171
177172 while ( index < text . length && depth > 0 ) {
@@ -184,7 +179,7 @@ export class Parser {
184179 throw new InvalidSyntaxError ( "Unclosed interpolation" , start + brace ) ;
185180 }
186181
187- const interpolated = text . slice ( inteprolation , index - 1 ) . trim ( ) ;
182+ const interpolated = text . slice ( interpolation , index - 1 ) . trim ( ) ;
188183
189184 if ( interpolated . length === 0 ) {
190185 throw new InvalidSyntaxError ( "Empty interpolation" , start + brace ) ;
@@ -199,7 +194,7 @@ export class Parser {
199194 specifier === - 1 ? null : interpolated . slice ( specifier + 1 ) . trim ( ) ;
200195
201196 const tokens = tokenize ( expression , {
202- offset : start + inteprolation ,
197+ offset : start + interpolation ,
203198 } ) ;
204199 const parser = new Parser ( tokens ) ;
205200 const part = parser . parseExpression ( ) ;
@@ -210,47 +205,41 @@ export class Parser {
210205 if ( ! format ) {
211206 throw new InvalidSyntaxError (
212207 `Invalid format "${ value } "` ,
213- start + inteprolation + specifier + 1
208+ start + interpolation + specifier + 1
214209 ) ;
215210 }
216211
217212 parts . push (
218- new FormattedExpression ( part , format , start + inteprolation )
213+ new FormattedExpression ( part , format , start + interpolation )
219214 ) ;
220215 } else {
221216 parts . push ( part ) ;
222217 }
218+
223219 continue ;
224220 }
225221
226- // Handle escaped closing braces
227222 if ( char === "}" ) {
228- let braceStart = index ;
223+ let brace = index ;
229224 let count = 0 ;
230225 while ( text [ index ] === "}" ) {
231226 count ++ ;
232227 index ++ ;
233228 }
234229
235230 if ( count % 2 === 0 ) {
236- // Even number: literal } characters
237231 parts . push (
238- new StringLiteral (
239- "}" . repeat ( count / 2 ) ,
240- token . start + braceStart + 1
241- )
232+ new StringLiteral ( "}" . repeat ( count / 2 ) , token . start + brace + 1 )
242233 ) ;
243234 continue ;
244235 }
245236
246- // Odd number of closing braces with no matching opening
247237 throw new InvalidSyntaxError (
248238 "Unmatched closing brace" ,
249- token . start + braceStart + 1
239+ token . start + brace + 1
250240 ) ;
251241 }
252242
253- // Handle literals until next brace
254243 const literal = index ;
255244
256245 while (
@@ -260,13 +249,13 @@ export class Parser {
260249 ) {
261250 index ++ ;
262251 }
263-
264252 if ( index > literal ) {
265253 parts . push (
266254 new StringLiteral ( text . slice ( literal , index ) , start + literal + 1 )
267255 ) ;
268256 }
269257 }
258+
270259 return new InterpolatedString ( parts , token . start ) ;
271260 }
272261
0 commit comments