Skip to content

Commit 85d9fc6

Browse files
committed
chore: Soundry refactoring
1 parent 64f6eb0 commit 85d9fc6

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

benchmarks/jju/extended.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,45 @@ var unescapeMap = {
2929
'/': '/'
3030
}
3131

32-
function formatError (input, msg, position, lineno, column, json5) {
33-
var result = msg + ' at ' + (lineno + 1) + ':' + (column + 1)
32+
function formatError (input, message, position, lineNumber, column, json5) {
33+
var result = message + ' at ' + (lineNumber + 1) + ':' + (column + 1)
3434

35-
var tmppos = position - column - 1
35+
var startPosition = position - column - 1
3636

37-
var srcline = ''
37+
var sourceLine = ''
3838

3939
var underline = ''
4040

4141
var isLineTerminator = json5 ? Uni.isLineTerminator : Uni.isLineTerminatorJSON
4242

4343
// output no more than 70 characters before the wrong ones
44-
if (tmppos < position - 70) {
45-
tmppos = position - 70
44+
if (startPosition < position - 70) {
45+
startPosition = position - 70
4646
}
4747

4848
while (1) {
49-
var chr = input[++tmppos]
49+
var chr = input[++startPosition]
5050

51-
if (isLineTerminator(chr) || tmppos === input.length) {
52-
if (position >= tmppos) {
51+
if (isLineTerminator(chr) || startPosition === input.length) {
52+
if (position >= startPosition) {
5353
// ending line error, so show it after the last char
5454
underline += '^'
5555
}
5656
break
5757
}
58-
srcline += chr
58+
sourceLine += chr
5959

60-
if (position === tmppos) {
60+
if (position === startPosition) {
6161
underline += '^'
62-
} else if (position > tmppos) {
63-
underline += input[tmppos] === '\t' ? '\t' : ' '
62+
} else if (position > startPosition) {
63+
underline += input[startPosition] === '\t' ? '\t' : ' '
6464
}
6565

6666
// output no more than 78 characters on the string
67-
if (srcline.length > 78) break
67+
if (sourceLine.length > 78) break
6868
}
6969

70-
return result + '\n' + srcline + '\n' + underline
70+
return result + '\n' + sourceLine + '\n' + underline
7171
}
7272

7373
function parse (input, options) {
@@ -99,10 +99,10 @@ function parse (input, options) {
9999

100100
var stack = []
101101

102-
function fail (msg) {
102+
function fail (message) {
103103
var column = position - lineStart
104104

105-
if (!msg) {
105+
if (!message) {
106106
if (position < length) {
107107
var token = '\'' +
108108
JSON
@@ -112,13 +112,13 @@ function parse (input, options) {
112112
.replace(/\\"/g, '"') +
113113
'\''
114114

115-
if (!msg) msg = 'Unexpected token ' + token
115+
if (!message) message = 'Unexpected token ' + token
116116
} else {
117-
if (!msg) msg = 'Unexpected end of input'
117+
if (!message) message = 'Unexpected end of input'
118118
}
119119
}
120120

121-
var error = SyntaxError(formatError(input, msg, position, lineNumber, column, json5))
121+
var error = SyntaxError(formatError(input, message, position, lineNumber, column, json5))
122122
error.row = lineNumber + 1
123123
error.column = column + 1
124124
throw error
@@ -250,11 +250,11 @@ function parse (input, options) {
250250

251251
function parseKeyword (keyword) {
252252
// keyword[0] is not checked because it should've checked earlier
253-
var _pos = position
253+
var startPosition = position
254254
var len = keyword.length
255255
for (var i = 1; i < len; i++) {
256256
if (position >= length || keyword[i] !== input[position]) {
257-
position = _pos - 1
257+
position = startPosition - 1
258258
fail()
259259
}
260260
position++

benchmarks/jju/original.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,45 @@ var unescapeMap = {
2929
'/': '/'
3030
}
3131

32-
function formatError (input, msg, position, lineno, column, json5) {
33-
var result = msg + ' at ' + (lineno + 1) + ':' + (column + 1)
32+
function formatError (input, message, position, lineNumber, column, json5) {
33+
var result = message + ' at ' + (lineNumber + 1) + ':' + (column + 1)
3434

35-
var tmppos = position - column - 1
35+
var startPosition = position - column - 1
3636

37-
var srcline = ''
37+
var sourceLine = ''
3838

3939
var underline = ''
4040

4141
var isLineTerminator = json5 ? Uni.isLineTerminator : Uni.isLineTerminatorJSON
4242

4343
// output no more than 70 characters before the wrong ones
44-
if (tmppos < position - 70) {
45-
tmppos = position - 70
44+
if (startPosition < position - 70) {
45+
startPosition = position - 70
4646
}
4747

4848
while (1) {
49-
var chr = input[++tmppos]
49+
var chr = input[++startPosition]
5050

51-
if (isLineTerminator(chr) || tmppos === input.length) {
52-
if (position >= tmppos) {
51+
if (isLineTerminator(chr) || startPosition === input.length) {
52+
if (position >= startPosition) {
5353
// ending line error, so show it after the last char
5454
underline += '^'
5555
}
5656
break
5757
}
58-
srcline += chr
58+
sourceLine += chr
5959

60-
if (position === tmppos) {
60+
if (position === startPosition) {
6161
underline += '^'
62-
} else if (position > tmppos) {
63-
underline += input[tmppos] === '\t' ? '\t' : ' '
62+
} else if (position > startPosition) {
63+
underline += input[startPosition] === '\t' ? '\t' : ' '
6464
}
6565

6666
// output no more than 78 characters on the string
67-
if (srcline.length > 78) break
67+
if (sourceLine.length > 78) break
6868
}
6969

70-
return result + '\n' + srcline + '\n' + underline
70+
return result + '\n' + sourceLine + '\n' + underline
7171
}
7272

7373
function parse (input, options) {
@@ -131,10 +131,10 @@ function parse (input, options) {
131131
})()
132132
}
133133

134-
function fail (msg) {
134+
function fail (message) {
135135
var column = position - lineStart
136136

137-
if (!msg) {
137+
if (!message) {
138138
if (position < length) {
139139
var token = '\'' +
140140
JSON
@@ -144,13 +144,13 @@ function parse (input, options) {
144144
.replace(/\\"/g, '"') +
145145
'\''
146146

147-
if (!msg) msg = 'Unexpected token ' + token
147+
if (!message) message = 'Unexpected token ' + token
148148
} else {
149-
if (!msg) msg = 'Unexpected end of input'
149+
if (!message) message = 'Unexpected end of input'
150150
}
151151
}
152152

153-
var error = SyntaxError(formatError(input, msg, position, lineNumber, column, json5))
153+
var error = SyntaxError(formatError(input, message, position, lineNumber, column, json5))
154154
error.row = lineNumber + 1
155155
error.column = column + 1
156156
throw error
@@ -302,11 +302,11 @@ function parse (input, options) {
302302

303303
function parseKeyword (keyword) {
304304
// keyword[0] is not checked because it should've checked earlier
305-
var _pos = position
305+
var startPosition = position
306306
var len = keyword.length
307307
for (var i = 1; i < len; i++) {
308308
if (position >= length || keyword[i] !== input[position]) {
309-
position = _pos - 1
309+
position = startPosition - 1
310310
fail()
311311
}
312312
position++

benchmarks/jju/pure.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,45 @@ var unescapeMap = {
2323
'/': '/'
2424
}
2525

26-
function formatError (input, msg, position, lineno, column) {
27-
var result = msg + ' at ' + (lineno + 1) + ':' + (column + 1)
26+
function formatError (input, message, position, lineNumber, column) {
27+
var result = message + ' at ' + (lineNumber + 1) + ':' + (column + 1)
2828

29-
var tmppos = position - column - 1
29+
var startPosition = position - column - 1
3030

31-
var srcline = ''
31+
var sourceLine = ''
3232

3333
var underline = ''
3434

3535
var isLineTerminator = Uni.isLineTerminatorJSON
3636

3737
// output no more than 70 characters before the wrong ones
38-
if (tmppos < position - 70) {
39-
tmppos = position - 70
38+
if (startPosition < position - 70) {
39+
startPosition = position - 70
4040
}
4141

4242
while (1) {
43-
var chr = input[++tmppos]
43+
var chr = input[++startPosition]
4444

45-
if (isLineTerminator(chr) || tmppos === input.length) {
46-
if (position >= tmppos) {
45+
if (isLineTerminator(chr) || startPosition === input.length) {
46+
if (position >= startPosition) {
4747
// ending line error, so show it after the last char
4848
underline += '^'
4949
}
5050
break
5151
}
52-
srcline += chr
52+
sourceLine += chr
5353

54-
if (position === tmppos) {
54+
if (position === startPosition) {
5555
underline += '^'
56-
} else if (position > tmppos) {
57-
underline += input[tmppos] === '\t' ? '\t' : ' '
56+
} else if (position > startPosition) {
57+
underline += input[startPosition] === '\t' ? '\t' : ' '
5858
}
5959

6060
// output no more than 78 characters on the string
61-
if (srcline.length > 78) break
61+
if (sourceLine.length > 78) break
6262
}
6363

64-
return result + '\n' + srcline + '\n' + underline
64+
return result + '\n' + sourceLine + '\n' + underline
6565
}
6666

6767
function parse (input) {

0 commit comments

Comments
 (0)