@@ -17,7 +17,17 @@ for (const entry of fs.readdirSync(FIXTURES)) {
1717 pos : Position ;
1818 label : string ;
1919 } [ ] [ ] = Array . from ( { length : lines . length } , ( ) => [ ] ) ;
20- const addRange = ( label : string , range : Range ) => {
20+ // we'll remove windows newlines for the purposes of snapshots.
21+ const read = ( range : Range ) => parser . read ( range ) . replace ( / \r / g, "" ) ;
22+ const addRange = ( label : string , inputRange : Range ) => {
23+ // we'll normalize windows newline positions for the snapshots.
24+ const range =
25+ src . charAt ( inputRange . start ) === "\r"
26+ ? {
27+ start : inputRange . start + 1 ,
28+ end : inputRange . end ,
29+ }
30+ : inputRange ;
2131 const pos = parser . positionAt ( range . start ) ;
2232 partsByLine [ pos . line ] . push ( {
2333 label,
@@ -100,13 +110,10 @@ for (const entry of fs.readdirSync(FIXTURES)) {
100110 addValueRange ( "attrSpread" , range ) ;
101111 } ,
102112 onOpenTagEnd ( range ) {
103- addRange (
104- `openTagEnd(${ parser . read ( tagStack [ tagStack . length - 1 ] ) } )` ,
105- range
106- ) ;
113+ addRange ( `openTagEnd(${ read ( tagStack [ tagStack . length - 1 ] ) } )` , range ) ;
107114 } ,
108115 onCloseTag ( range ) {
109- const label = `closeTag(${ parser . read ( tagStack . pop ( ) ! ) } )` ;
116+ const label = `closeTag(${ read ( tagStack . pop ( ) ! ) } )` ;
110117 if ( range . value ) {
111118 addValueRange ( label , range as Ranges . Value ) ;
112119 } else {
@@ -134,15 +141,15 @@ for (const entry of fs.readdirSync(FIXTURES)) {
134141 if ( line === 0 ) {
135142 result += `${
136143 linePrefix +
137- parser . read ( {
144+ read ( {
138145 start : 0 ,
139146 end : lines [ 1 ] ,
140147 } )
141148 } `;
142149 } else {
143150 result += `\n${
144151 linePrefix +
145- parser . read ( {
152+ read ( {
146153 start : lines [ line ] + 1 ,
147154 end : lines [ line + 1 ] ,
148155 } )
@@ -177,11 +184,9 @@ for (const entry of fs.readdirSync(FIXTURES)) {
177184 let label = `─ ${ part . label } ` ;
178185
179186 if ( range . end > range . start ) {
180- const txt = parser . read ( part . range ) ;
187+ const txt = read ( part . range ) ;
181188 if ( txt . length > 1 || / \s / . test ( txt ) ) {
182- label += ` ${ JSON . stringify (
183- parser . read ( part . range ) . replace ( / \r \n / g, "\n" )
184- ) } `;
189+ label += ` ${ JSON . stringify ( txt ) } ` ;
185190 }
186191 }
187192
0 commit comments