File tree Expand file tree Collapse file tree 2 files changed +3
-59
lines changed
Expand file tree Collapse file tree 2 files changed +3
-59
lines changed Original file line number Diff line number Diff line change 5353 }
5454 }
5555
56- function pad ( n , length ) {
57- var s = String ( n )
56+ function pad ( s , length ) {
5857 if ( s . length > length ) {
59- return n
58+ return s
6059 }
6160 return Array ( length - s . length + 1 ) . join ( " " ) + s
6261 }
593592 }
594593 }
595594
596- Lexer . prototype . lastNLines = lastNLines
597-
598595 Lexer . prototype . formatError = function ( token , message ) {
599596 if ( token == null ) {
600597 // An undefined token indicates EOF
623620 for ( var i = 0 ; i < displayedLines . length ; i ++ ) {
624621 var line = displayedLines [ i ]
625622 var lineNo = firstDisplayedLine + i
626- errorLines . push ( pad ( lineNo , lastLineDigits ) + " " + line ) ;
623+ errorLines . push ( pad ( String ( lineNo ) , lastLineDigits ) + " " + line ) ;
627624 if ( lineNo === token . line ) {
628625 errorLines . push ( pad ( "" , lastLineDigits + token . col + 1 ) + "^" )
629626 }
Original file line number Diff line number Diff line change @@ -1261,56 +1261,3 @@ describe('unicode flag', () => {
12611261 } )
12621262
12631263} )
1264-
1265- describe ( "lastNLines" , ( ) => {
1266- const lexer = moo . compile ( { } )
1267-
1268- test ( "grabs last n lines if more than needed" , ( ) => {
1269- const input = "line 1\nline 2\nline 3"
1270- expect ( lexer . lastNLines ( input , 2 ) )
1271- . toEqual ( [
1272- "line 2" ,
1273- "line 3"
1274- ] )
1275- } )
1276-
1277- test ( "grabs all lines if not enough" , ( ) => {
1278- const input = "line 1\nline 2\nline 3"
1279- expect ( lexer . lastNLines ( input , 10 ) )
1280- . toEqual ( [
1281- "line 1" ,
1282- "line 2" ,
1283- "line 3"
1284- ] )
1285- } )
1286-
1287- test ( "grabs last empty line" , ( ) => {
1288- const input = "line 1\nline 2\nline 3\n"
1289- expect ( lexer . lastNLines ( input , 2 ) )
1290- . toEqual ( [
1291- "line 3" ,
1292- ""
1293- ] )
1294- } )
1295-
1296- test ( "grabs first empty line" , ( ) => {
1297- const input = "\nline 1\nline 2\nline 3"
1298- expect ( lexer . lastNLines ( input , 10 ) )
1299- . toEqual ( [
1300- "" ,
1301- "line 1" ,
1302- "line 2" ,
1303- "line 3"
1304- ] )
1305- } )
1306-
1307- test ( "does not grab first empty line if unneeded" , ( ) => {
1308- const input = "\nline 1\nline 2\nline 3"
1309- expect ( lexer . lastNLines ( input , 3 ) )
1310- . toEqual ( [
1311- "line 1" ,
1312- "line 2" ,
1313- "line 3"
1314- ] )
1315- } )
1316- } )
You can’t perform that action at this time.
0 commit comments