@@ -11,7 +11,7 @@ export function parseExpression(
1111) : CST . Expression {
1212 const { source } = ctx ;
1313 let pos = start + 1 ; // '{'
14- pos + = whitespaces ( source , pos ) ;
14+ pos = whitespaces ( source , pos ) . end ;
1515
1616 const arg =
1717 source [ pos ] === '$'
@@ -20,10 +20,10 @@ export function parseExpression(
2020 if ( arg ) {
2121 pos = arg . end ;
2222 const ws = whitespaces ( source , pos ) ;
23- if ( ws === 0 && source [ pos ] !== '}' ) {
23+ if ( ! ws . hasWS && source [ pos ] !== '}' ) {
2424 ctx . onError ( 'missing-syntax' , pos , ' ' ) ;
2525 }
26- pos + = ws ;
26+ pos = ws . end ;
2727 }
2828
2929 let functionRef : CST . FunctionRef | CST . Junk | undefined ;
@@ -56,16 +56,16 @@ export function parseExpression(
5656 const attributes : CST . Attribute [ ] = [ ] ;
5757 let reqWS = Boolean ( functionRef || markup ) ;
5858 let ws = whitespaces ( source , pos ) ;
59- while ( source [ pos + ws ] === '@' ) {
60- if ( reqWS && ws === 0 ) ctx . onError ( 'missing-syntax' , pos , ' ' ) ;
61- pos + = ws ;
59+ while ( source [ ws . end ] === '@' ) {
60+ if ( reqWS && ! ws . hasWS ) ctx . onError ( 'missing-syntax' , pos , ' ' ) ;
61+ pos = ws . end ;
6262 const attr = parseAttribute ( ctx , pos ) ;
6363 attributes . push ( attr ) ;
6464 pos = attr . end ;
6565 reqWS = true ;
6666 ws = whitespaces ( source , pos ) ;
6767 }
68- pos + = ws ;
68+ pos = ws . end ;
6969
7070 const open : CST . Syntax < '{' > = { start, end : start + 1 , value : '{' } ;
7171 let close : CST . Syntax < '}' > | undefined ;
@@ -125,17 +125,17 @@ function parseFunctionRefOrMarkup(
125125 let close : CST . Syntax < '/' > | undefined ;
126126 while ( pos < source . length ) {
127127 let ws = whitespaces ( source , pos ) ;
128- const next = source [ pos + ws ] ;
128+ const next = source [ ws . end ] ;
129129 if ( next === '@' || next === '}' ) break ;
130130 if ( next === '/' && source [ start ] === '#' ) {
131- pos + = ws + 1 ;
131+ pos = ws . end + 1 ;
132132 close = { start : pos - 1 , end : pos , value : '/' } ;
133133 ws = whitespaces ( source , pos ) ;
134- if ( ws > 0 ) ctx . onError ( 'extra-content' , pos , pos + ws ) ;
134+ if ( ws . hasWS ) ctx . onError ( 'extra-content' , pos , ws . end ) ;
135135 break ;
136136 }
137- if ( ws === 0 ) ctx . onError ( 'missing-syntax' , pos , ' ' ) ;
138- pos + = ws ;
137+ if ( ! ws . hasWS ) ctx . onError ( 'missing-syntax' , pos , ' ' ) ;
138+ pos = ws . end ;
139139 const opt = parseOption ( ctx , pos ) ;
140140 if ( opt . end === pos ) break ; // error
141141 options . push ( opt ) ;
@@ -152,16 +152,15 @@ function parseFunctionRefOrMarkup(
152152
153153function parseOption ( ctx : ParseContext , start : number ) : CST . Option {
154154 const id = parseIdentifier ( ctx , start ) ;
155- let pos = id . end ;
156- pos += whitespaces ( ctx . source , pos ) ;
155+ let pos = whitespaces ( ctx . source , id . end ) . end ;
157156 let equals : CST . Syntax < '=' > | undefined ;
158157 if ( ctx . source [ pos ] === '=' ) {
159158 equals = { start : pos , end : pos + 1 , value : '=' } ;
160159 pos += 1 ;
161160 } else {
162161 ctx . onError ( 'missing-syntax' , pos , '=' ) ;
163162 }
164- pos + = whitespaces ( ctx . source , pos ) ;
163+ pos = whitespaces ( ctx . source , pos ) . end ;
165164 const value =
166165 ctx . source [ pos ] === '$'
167166 ? parseVariable ( ctx , pos )
@@ -174,23 +173,22 @@ function parseIdentifier(
174173 start : number
175174) : { parts : CST . Identifier ; end : number } {
176175 const { source } = ctx ;
177- const str0 = parseNameValue ( source , start ) ;
178- if ( ! str0 ) {
176+ const name0 = parseNameValue ( source , start ) ;
177+ if ( ! name0 ) {
179178 ctx . onError ( 'empty-token' , start , start + 1 ) ;
180179 return { parts : [ { start, end : start , value : '' } ] , end : start } ;
181180 }
182- let pos = start + str0 . length ;
183- const id0 = { start, end : pos , value : str0 } ;
181+ let pos = name0 . end ;
182+ const id0 = { start, end : pos , value : name0 . value } ;
184183 if ( source [ pos ] !== ':' ) return { parts : [ id0 ] , end : pos } ;
185184
186185 const sep = { start : pos , end : pos + 1 , value : ':' as const } ;
187186 pos += 1 ;
188187
189- const str1 = parseNameValue ( source , pos ) ;
190- if ( str1 ) {
191- const end = pos + str1 . length ;
192- const id1 = { start : pos , end, value : str1 } ;
193- return { parts : [ id0 , sep , id1 ] , end } ;
188+ const name1 = parseNameValue ( source , pos ) ;
189+ if ( name1 ) {
190+ const id1 = { start : pos , end : name1 . end , value : name1 . value } ;
191+ return { parts : [ id0 , sep , id1 ] , end : name1 . end } ;
194192 } else {
195193 ctx . onError ( 'empty-token' , pos , pos + 1 ) ;
196194 return { parts : [ id0 , sep ] , end : pos } ;
@@ -204,10 +202,10 @@ function parseAttribute(ctx: ParseContext, start: number): CST.Attribute {
204202 const ws = whitespaces ( source , pos ) ;
205203 let equals : CST . Syntax < '=' > | undefined ;
206204 let value : CST . Literal | undefined ;
207- if ( source [ pos + ws ] === '=' ) {
208- pos + = ws + 1 ;
205+ if ( source [ ws . end ] === '=' ) {
206+ pos = ws . end + 1 ;
209207 equals = { start : pos - 1 , end : pos , value : '=' } ;
210- pos + = whitespaces ( source , pos ) ;
208+ pos = whitespaces ( source , pos ) . end ;
211209 value = parseLiteral ( ctx , pos , true ) ;
212210 pos = value . end ;
213211 }
0 commit comments