Skip to content

Commit 4d94b61

Browse files
committed
Addressed code review comments.
1 parent 5b73140 commit 4d94b61

File tree

2 files changed

+3
-59
lines changed

2 files changed

+3
-59
lines changed

moo.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@
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
}
@@ -593,8 +592,6 @@
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
@@ -623,7 +620,7 @@
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
}

test/test.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff 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-
})

0 commit comments

Comments
 (0)