@prantlf/jsonlint 10.1.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +35 -19
- package/lib/cli.js +34 -26
- package/lib/formatter.js +12 -10
- package/lib/jsonlint.d.ts +3 -0
- package/lib/jsonlint.js +121 -121
- package/lib/printer.js +54 -27
- package/lib/schema-drafts.js +6 -3
- package/lib/sorter.js +6 -6
- package/lib/validator.js +31 -31
- package/package.json +31 -17
- package/web/ajv.min.js +3 -1
- package/web/ajv.min.js.map +1 -1
- package/web/formatter.min.js +1 -1
- package/web/formatter.min.js.map +1 -1
- package/web/jsonlint.html +333 -0
- package/web/jsonlint.min.js +1 -1
- package/web/jsonlint.min.js.map +1 -1
- package/web/printer.min.js +1 -1
- package/web/printer.min.js.map +1 -1
- package/web/schema-drafts.min.js +1 -1
- package/web/schema-drafts.min.js.map +1 -1
- package/web/sorter.min.js +1 -1
- package/web/sorter.min.js.map +1 -1
- package/web/validator.min.js +1 -1
- package/web/validator.min.js.map +1 -1
- package/CHANGELOG.md +0 -258
package/lib/jsonlint.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// This is autogenerated with esprima tools, see:
|
|
10
10
|
// https://github.com/ariya/esprima/blob/master/esprima.js
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const Uni = { // eslint-disable-line no-unused-vars
|
|
13
13
|
isWhiteSpace: function isWhiteSpace (x) {
|
|
14
14
|
// section 7.2, table 2
|
|
15
15
|
return x === '\u0020' ||
|
|
@@ -84,7 +84,7 @@ function isDecDigit (x) {
|
|
|
84
84
|
return x >= '0' && x <= '9'
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
const unescapeMap = {
|
|
88
88
|
'\'': '\'',
|
|
89
89
|
'"': '"',
|
|
90
90
|
'\\': '\\',
|
|
@@ -102,34 +102,34 @@ function parseInternal (input, options) {
|
|
|
102
102
|
input = String(input)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
const json5 = options.mode === 'json5'
|
|
106
|
+
const ignoreComments = options.ignoreComments || options.mode === 'cjson' || json5
|
|
107
|
+
const ignoreTrailingCommas = options.ignoreTrailingCommas || json5
|
|
108
|
+
const allowSingleQuotedStrings = options.allowSingleQuotedStrings || json5
|
|
109
|
+
const allowDuplicateObjectKeys = options.allowDuplicateObjectKeys
|
|
110
|
+
const reviver = options.reviver
|
|
111
|
+
const tokenize = options.tokenize
|
|
112
|
+
const rawTokens = options.rawTokens
|
|
113
|
+
const tokenLocations = options.tokenLocations
|
|
114
|
+
const tokenPaths = options.tokenPaths
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const isLineTerminator = json5 ? Uni.isLineTerminator : Uni.isLineTerminatorJSON
|
|
117
|
+
const isWhiteSpace = json5 ? Uni.isWhiteSpace : Uni.isWhiteSpaceJSON
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
const inputLength = input.length
|
|
120
|
+
let lineNumber = 0
|
|
121
|
+
let lineStart = 0
|
|
122
|
+
let position = 0
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
const tokens = []
|
|
125
|
+
let startToken
|
|
126
|
+
let endToken
|
|
127
|
+
let tokenPath
|
|
127
128
|
|
|
128
129
|
if (tokenize) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
var tokenColumn
|
|
130
|
+
let tokenOffset = null
|
|
131
|
+
let tokenLine
|
|
132
|
+
let tokenColumn
|
|
133
133
|
startToken = function () {
|
|
134
134
|
if (tokenOffset !== null) throw Error('internal error, token overlap')
|
|
135
135
|
tokenLine = lineNumber + 1
|
|
@@ -138,7 +138,7 @@ function parseInternal (input, options) {
|
|
|
138
138
|
}
|
|
139
139
|
endToken = function (type, value) {
|
|
140
140
|
if (tokenOffset !== position) {
|
|
141
|
-
|
|
141
|
+
const token = { type }
|
|
142
142
|
if (rawTokens) {
|
|
143
143
|
token.raw = input.substr(tokenOffset, position - tokenOffset)
|
|
144
144
|
}
|
|
@@ -166,9 +166,9 @@ function parseInternal (input, options) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
function generateMessage () {
|
|
169
|
-
|
|
169
|
+
let message
|
|
170
170
|
if (position < inputLength) {
|
|
171
|
-
|
|
171
|
+
const token = JSON.stringify(input[position])
|
|
172
172
|
message = 'Unexpected token ' + token
|
|
173
173
|
} else {
|
|
174
174
|
message = 'Unexpected end of input'
|
|
@@ -177,16 +177,16 @@ function parseInternal (input, options) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
function createError (message) {
|
|
180
|
-
|
|
180
|
+
const column = position - lineStart + 1
|
|
181
181
|
++lineNumber
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
const texts = getTexts(message, input, position, lineNumber, column)
|
|
183
|
+
const error = SyntaxError(texts.message)
|
|
184
184
|
error.reason = message
|
|
185
185
|
error.excerpt = texts.excerpt
|
|
186
186
|
error.pointer = texts.pointer
|
|
187
187
|
error.location = {
|
|
188
188
|
start: {
|
|
189
|
-
column
|
|
189
|
+
column,
|
|
190
190
|
line: lineNumber,
|
|
191
191
|
offset: position
|
|
192
192
|
}
|
|
@@ -198,7 +198,7 @@ function parseInternal (input, options) {
|
|
|
198
198
|
if (!message) {
|
|
199
199
|
message = generateMessage()
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
const error = createError(message)
|
|
202
202
|
throw error
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -212,11 +212,11 @@ function parseInternal (input, options) {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
function parseGeneric () {
|
|
215
|
-
|
|
215
|
+
if (position < inputLength) {
|
|
216
216
|
startToken && startToken()
|
|
217
|
-
|
|
217
|
+
const char = input[position++]
|
|
218
218
|
if (char === '"' || (char === '\'' && allowSingleQuotedStrings)) {
|
|
219
|
-
|
|
219
|
+
const string = parseString(char)
|
|
220
220
|
endToken && endToken('literal', string)
|
|
221
221
|
return string
|
|
222
222
|
} else if (char === '{') {
|
|
@@ -227,7 +227,7 @@ function parseInternal (input, options) {
|
|
|
227
227
|
return parseArray()
|
|
228
228
|
} else if (char === '-' || char === '.' || isDecDigit(char) ||
|
|
229
229
|
(json5 && (char === '+' || char === 'I' || char === 'N'))) {
|
|
230
|
-
|
|
230
|
+
const number = parseNumber()
|
|
231
231
|
endToken && endToken('literal', number)
|
|
232
232
|
return number
|
|
233
233
|
} else if (char === 'n') {
|
|
@@ -251,12 +251,12 @@ function parseInternal (input, options) {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
function parseKey () {
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
let result
|
|
255
|
+
if (position < inputLength) {
|
|
256
256
|
startToken && startToken()
|
|
257
|
-
|
|
257
|
+
const char = input[position++]
|
|
258
258
|
if (char === '"' || (char === '\'' && allowSingleQuotedStrings)) {
|
|
259
|
-
|
|
259
|
+
const string = parseString(char)
|
|
260
260
|
endToken && endToken('literal', string)
|
|
261
261
|
return string
|
|
262
262
|
} else if (char === '{') {
|
|
@@ -266,12 +266,12 @@ function parseInternal (input, options) {
|
|
|
266
266
|
endToken && endToken('symbol', '[')
|
|
267
267
|
return parseArray()
|
|
268
268
|
} else if (char === '.' || isDecDigit(char)) {
|
|
269
|
-
|
|
269
|
+
const number = parseNumber(true)
|
|
270
270
|
endToken && endToken('literal', number)
|
|
271
271
|
return number
|
|
272
272
|
} else if ((json5 && Uni.isIdentifierStart(char)) ||
|
|
273
273
|
(char === '\\' && input[position] === 'u')) {
|
|
274
|
-
|
|
274
|
+
const rollback = position - 1
|
|
275
275
|
result = parseIdentifier()
|
|
276
276
|
if (result === undefined) {
|
|
277
277
|
position = rollback
|
|
@@ -290,7 +290,7 @@ function parseInternal (input, options) {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
function skipWhiteSpace () {
|
|
293
|
-
|
|
293
|
+
let insideWhiteSpace
|
|
294
294
|
function startWhiteSpace () {
|
|
295
295
|
if (!insideWhiteSpace) {
|
|
296
296
|
insideWhiteSpace = true
|
|
@@ -306,7 +306,7 @@ function parseInternal (input, options) {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
while (position < inputLength) {
|
|
309
|
-
|
|
309
|
+
const char = input[position++]
|
|
310
310
|
if (isLineTerminator(char)) {
|
|
311
311
|
startToken && startWhiteSpace()
|
|
312
312
|
newLine(char)
|
|
@@ -332,7 +332,7 @@ function parseInternal (input, options) {
|
|
|
332
332
|
|
|
333
333
|
function skipComment (multiLine) {
|
|
334
334
|
while (position < inputLength) {
|
|
335
|
-
|
|
335
|
+
const char = input[position++]
|
|
336
336
|
if (isLineTerminator(char)) {
|
|
337
337
|
if (!multiLine) {
|
|
338
338
|
// let parent function deal with newline
|
|
@@ -356,8 +356,8 @@ function parseInternal (input, options) {
|
|
|
356
356
|
|
|
357
357
|
function parseKeyword (keyword) {
|
|
358
358
|
// keyword[0] is not checked because it was checked earlier
|
|
359
|
-
|
|
360
|
-
for (
|
|
359
|
+
const startPosition = position
|
|
360
|
+
for (let i = 1, keywordLength = keyword.length; i < keywordLength; ++i) {
|
|
361
361
|
if (position >= inputLength || keyword[i] !== input[position]) {
|
|
362
362
|
position = startPosition - 1
|
|
363
363
|
fail()
|
|
@@ -367,19 +367,19 @@ function parseInternal (input, options) {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
function parseObject () {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
370
|
+
const result = {}
|
|
371
|
+
const emptyObject = {}
|
|
372
|
+
let isNotEmpty = false
|
|
373
373
|
|
|
374
374
|
while (position < inputLength) {
|
|
375
375
|
skipWhiteSpace()
|
|
376
|
-
|
|
376
|
+
const key = parseKey()
|
|
377
377
|
if (allowDuplicateObjectKeys === false && result[key]) {
|
|
378
378
|
fail('Duplicate key: "' + key + '"')
|
|
379
379
|
}
|
|
380
380
|
skipWhiteSpace()
|
|
381
381
|
startToken && startToken()
|
|
382
|
-
|
|
382
|
+
let char = input[position++]
|
|
383
383
|
endToken && endToken('symbol', char)
|
|
384
384
|
if (char === '}' && key === undefined) {
|
|
385
385
|
if (!ignoreTrailingCommas && isNotEmpty) {
|
|
@@ -390,7 +390,7 @@ function parseInternal (input, options) {
|
|
|
390
390
|
} else if (char === ':' && key !== undefined) {
|
|
391
391
|
skipWhiteSpace()
|
|
392
392
|
tokenPath && tokenPath.push(key)
|
|
393
|
-
|
|
393
|
+
let value = parseGeneric()
|
|
394
394
|
tokenPath && tokenPath.pop()
|
|
395
395
|
|
|
396
396
|
if (value === undefined) fail('No value found for key "' + key + '"')
|
|
@@ -433,15 +433,15 @@ function parseInternal (input, options) {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
function parseArray () {
|
|
436
|
-
|
|
436
|
+
const result = []
|
|
437
437
|
while (position < inputLength) {
|
|
438
438
|
skipWhiteSpace()
|
|
439
439
|
tokenPath && tokenPath.push(result.length)
|
|
440
|
-
|
|
440
|
+
let item = parseGeneric()
|
|
441
441
|
tokenPath && tokenPath.pop()
|
|
442
442
|
skipWhiteSpace()
|
|
443
443
|
startToken && startToken()
|
|
444
|
-
|
|
444
|
+
const char = input[position++]
|
|
445
445
|
endToken && endToken('symbol', char)
|
|
446
446
|
if (item !== undefined) {
|
|
447
447
|
if (reviver) {
|
|
@@ -476,11 +476,11 @@ function parseInternal (input, options) {
|
|
|
476
476
|
// rewind because we don't know first char
|
|
477
477
|
--position
|
|
478
478
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
479
|
+
let start = position
|
|
480
|
+
let char = input[position++]
|
|
481
|
+
const toNumber = function (isOctal) {
|
|
482
|
+
const string = input.substr(start, position - start)
|
|
483
|
+
let result
|
|
484
484
|
|
|
485
485
|
if (isOctal) {
|
|
486
486
|
result = parseInt(string.replace(/^0o?/, ''), 8)
|
|
@@ -531,8 +531,8 @@ function parseInternal (input, options) {
|
|
|
531
531
|
char = input[position++]
|
|
532
532
|
|
|
533
533
|
// new syntax, "0o777" old syntax, "0777"
|
|
534
|
-
|
|
535
|
-
|
|
534
|
+
const isOctal = char === 'o' || char === 'O' || isOctDigit(char)
|
|
535
|
+
const isHex = char === 'x' || char === 'X'
|
|
536
536
|
|
|
537
537
|
if (json5 && (isOctal || isHex)) {
|
|
538
538
|
while (position < inputLength &&
|
|
@@ -540,7 +540,7 @@ function parseInternal (input, options) {
|
|
|
540
540
|
++position
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
-
|
|
543
|
+
let sign = 1
|
|
544
544
|
if (input[start] === '-') {
|
|
545
545
|
sign = -1
|
|
546
546
|
++start
|
|
@@ -583,9 +583,9 @@ function parseInternal (input, options) {
|
|
|
583
583
|
// rewind because we don't know first char
|
|
584
584
|
--position
|
|
585
585
|
|
|
586
|
-
|
|
586
|
+
let result = ''
|
|
587
587
|
while (position < inputLength) {
|
|
588
|
-
|
|
588
|
+
let char = input[position++]
|
|
589
589
|
if (char === '\\' &&
|
|
590
590
|
input[position] === 'u' &&
|
|
591
591
|
isHexDigit(input[position + 1]) &&
|
|
@@ -619,9 +619,9 @@ function parseInternal (input, options) {
|
|
|
619
619
|
|
|
620
620
|
function parseString (endChar) {
|
|
621
621
|
// 7.8.4 of ES262 spec
|
|
622
|
-
|
|
622
|
+
let result = ''
|
|
623
623
|
while (position < inputLength) {
|
|
624
|
-
|
|
624
|
+
let char = input[position++]
|
|
625
625
|
if (char === endChar) {
|
|
626
626
|
return result
|
|
627
627
|
} else if (char === '\\') {
|
|
@@ -636,9 +636,9 @@ function parseInternal (input, options) {
|
|
|
636
636
|
newLine(char)
|
|
637
637
|
} else if (char === 'u' || (char === 'x' && json5)) {
|
|
638
638
|
// unicode/character escape sequence
|
|
639
|
-
|
|
639
|
+
const count = char === 'u' ? 4 : 2
|
|
640
640
|
// validation for \uXXXX
|
|
641
|
-
for (
|
|
641
|
+
for (let i = 0; i < count; ++i) {
|
|
642
642
|
if (position >= inputLength) {
|
|
643
643
|
fail()
|
|
644
644
|
}
|
|
@@ -649,7 +649,7 @@ function parseInternal (input, options) {
|
|
|
649
649
|
}
|
|
650
650
|
result += String.fromCharCode(parseInt(input.substr(position - count, count), 16))
|
|
651
651
|
} else if (json5 && isOctDigit(char)) {
|
|
652
|
-
|
|
652
|
+
let digits
|
|
653
653
|
if (char < '4' && isOctDigit(input[position]) && isOctDigit(input[position + 1])) {
|
|
654
654
|
// three-digit octal
|
|
655
655
|
digits = 3
|
|
@@ -684,7 +684,7 @@ function parseInternal (input, options) {
|
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
skipWhiteSpace()
|
|
687
|
-
|
|
687
|
+
let returnValue = parseGeneric()
|
|
688
688
|
if (returnValue !== undefined || position < inputLength) {
|
|
689
689
|
skipWhiteSpace()
|
|
690
690
|
if (position >= inputLength) {
|
|
@@ -721,9 +721,9 @@ function tokenize (input, options) { // eslint-disable-line no-unused-vars
|
|
|
721
721
|
}
|
|
722
722
|
// As long as this is the single modification, this is easier than cloning.
|
|
723
723
|
// (Once Node.js 6 is dropped, this can be replaced by object destructuring.)
|
|
724
|
-
|
|
724
|
+
const oldTokenize = options.tokenize
|
|
725
725
|
options.tokenize = true
|
|
726
|
-
|
|
726
|
+
const tokens = parseInternal(input, options)
|
|
727
727
|
options.tokenize = oldTokenize
|
|
728
728
|
return tokens
|
|
729
729
|
}
|
|
@@ -764,46 +764,46 @@ function pointerToPath (pointer) { // eslint-disable-line no-unused-vars
|
|
|
764
764
|
}
|
|
765
765
|
|
|
766
766
|
function getLineAndColumn (input, offset) {
|
|
767
|
-
|
|
767
|
+
const lines = input
|
|
768
768
|
.substr(0, offset)
|
|
769
769
|
.split(/\r?\n/)
|
|
770
|
-
|
|
771
|
-
|
|
770
|
+
const line = lines.length
|
|
771
|
+
const column = lines[line - 1].length + 1
|
|
772
772
|
return {
|
|
773
|
-
line
|
|
774
|
-
column
|
|
773
|
+
line,
|
|
774
|
+
column
|
|
775
775
|
}
|
|
776
776
|
}
|
|
777
777
|
|
|
778
778
|
function pastInput (input, offset) {
|
|
779
|
-
|
|
780
|
-
|
|
779
|
+
const start = Math.max(0, offset - 20)
|
|
780
|
+
const previous = input.substr(start, offset - start)
|
|
781
781
|
return (offset > 20 ? '...' : '') + previous.replace(/\r?\n/g, '')
|
|
782
782
|
}
|
|
783
783
|
|
|
784
784
|
function upcomingInput (input, offset) {
|
|
785
|
-
|
|
785
|
+
let start = Math.max(0, offset - 20)
|
|
786
786
|
start += offset - start
|
|
787
|
-
|
|
788
|
-
|
|
787
|
+
const rest = input.length - start
|
|
788
|
+
const next = input.substr(start, Math.min(20, rest))
|
|
789
789
|
return next.replace(/\r?\n/g, '') + (rest > 20 ? '...' : '')
|
|
790
790
|
}
|
|
791
791
|
|
|
792
792
|
function getPositionContext (input, offset) {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
793
|
+
const past = pastInput(input, offset)
|
|
794
|
+
const upcoming = upcomingInput(input, offset)
|
|
795
|
+
const pointer = new Array(past.length + 1).join('-') + '^'
|
|
796
796
|
return {
|
|
797
797
|
excerpt: past + upcoming,
|
|
798
|
-
pointer
|
|
798
|
+
pointer
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
|
|
802
802
|
function getReason (error) {
|
|
803
|
-
|
|
803
|
+
let message = error.message
|
|
804
804
|
.replace('JSON.parse: ', '') // SpiderMonkey
|
|
805
805
|
.replace('JSON Parse error: ', '') // SquirrelFish
|
|
806
|
-
|
|
806
|
+
const firstCharacter = message.charAt(0)
|
|
807
807
|
if (firstCharacter >= 'a') {
|
|
808
808
|
message = firstCharacter.toUpperCase() + message.substr(1)
|
|
809
809
|
}
|
|
@@ -811,12 +811,12 @@ function getReason (error) {
|
|
|
811
811
|
}
|
|
812
812
|
|
|
813
813
|
function getLocationOnV8 (input, reason) {
|
|
814
|
-
|
|
814
|
+
const match = / in JSON at position (\d+)$/.exec(reason)
|
|
815
815
|
if (match) {
|
|
816
|
-
|
|
817
|
-
|
|
816
|
+
const offset = +match[1]
|
|
817
|
+
const location = getLineAndColumn(input, offset)
|
|
818
818
|
return {
|
|
819
|
-
offset
|
|
819
|
+
offset,
|
|
820
820
|
line: location.line,
|
|
821
821
|
column: location.column,
|
|
822
822
|
reason: reason.substr(0, match.index)
|
|
@@ -825,12 +825,12 @@ function getLocationOnV8 (input, reason) {
|
|
|
825
825
|
}
|
|
826
826
|
|
|
827
827
|
function checkUnexpectedEndOnV8 (input, reason) {
|
|
828
|
-
|
|
828
|
+
const match = / end of JSON input$/.exec(reason)
|
|
829
829
|
if (match) {
|
|
830
|
-
|
|
831
|
-
|
|
830
|
+
const offset = input.length
|
|
831
|
+
const location = getLineAndColumn(input, offset)
|
|
832
832
|
return {
|
|
833
|
-
offset
|
|
833
|
+
offset,
|
|
834
834
|
line: location.line,
|
|
835
835
|
column: location.column,
|
|
836
836
|
reason: reason.substr(0, match.index + 4)
|
|
@@ -839,24 +839,24 @@ function checkUnexpectedEndOnV8 (input, reason) {
|
|
|
839
839
|
}
|
|
840
840
|
|
|
841
841
|
function getLocationOnSpiderMonkey (input, reason) {
|
|
842
|
-
|
|
842
|
+
const match = / at line (\d+) column (\d+) of the JSON data$/.exec(reason)
|
|
843
843
|
if (match) {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
844
|
+
const line = +match[1]
|
|
845
|
+
const column = +match[2]
|
|
846
|
+
const offset = getOffset(input, line, column) // eslint-disable-line no-undef
|
|
847
847
|
return {
|
|
848
|
-
offset
|
|
849
|
-
line
|
|
850
|
-
column
|
|
848
|
+
offset,
|
|
849
|
+
line,
|
|
850
|
+
column,
|
|
851
851
|
reason: reason.substr(0, match.index)
|
|
852
852
|
}
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
|
|
856
856
|
function getTexts (reason, input, offset, line, column) {
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
857
|
+
const position = getPositionContext(input, offset)
|
|
858
|
+
const excerpt = position.excerpt
|
|
859
|
+
let message, pointer
|
|
860
860
|
if (typeof line === 'number') {
|
|
861
861
|
pointer = position.pointer
|
|
862
862
|
message = 'Parse error on line ' + line + ', column ' +
|
|
@@ -865,18 +865,18 @@ function getTexts (reason, input, offset, line, column) {
|
|
|
865
865
|
message = 'Parse error in JSON input:\n' + excerpt + '\n' + reason
|
|
866
866
|
}
|
|
867
867
|
return {
|
|
868
|
-
message
|
|
869
|
-
excerpt
|
|
870
|
-
pointer
|
|
868
|
+
message,
|
|
869
|
+
excerpt,
|
|
870
|
+
pointer
|
|
871
871
|
}
|
|
872
872
|
}
|
|
873
873
|
|
|
874
874
|
function improveNativeError (input, error) {
|
|
875
|
-
|
|
876
|
-
|
|
875
|
+
let reason = getReason(error)
|
|
876
|
+
const location = getLocationOnV8(input, reason) ||
|
|
877
877
|
checkUnexpectedEndOnV8(input, reason) ||
|
|
878
878
|
getLocationOnSpiderMonkey(input, reason)
|
|
879
|
-
|
|
879
|
+
let offset, line, column
|
|
880
880
|
if (location) {
|
|
881
881
|
offset = location.offset
|
|
882
882
|
line = location.line
|
|
@@ -886,16 +886,16 @@ function improveNativeError (input, error) {
|
|
|
886
886
|
offset = 0
|
|
887
887
|
}
|
|
888
888
|
error.reason = reason
|
|
889
|
-
|
|
889
|
+
const texts = getTexts(reason, input, offset, line, column)
|
|
890
890
|
error.message = texts.message
|
|
891
891
|
error.excerpt = texts.excerpt
|
|
892
892
|
if (texts.pointer) {
|
|
893
893
|
error.pointer = texts.pointer
|
|
894
894
|
error.location = {
|
|
895
895
|
start: {
|
|
896
|
-
column
|
|
897
|
-
line
|
|
898
|
-
offset
|
|
896
|
+
column,
|
|
897
|
+
line,
|
|
898
|
+
offset
|
|
899
899
|
}
|
|
900
900
|
}
|
|
901
901
|
}
|
|
@@ -912,8 +912,8 @@ function parseNative (input, reviver) { // eslint-disable-line no-unused-vars
|
|
|
912
912
|
|
|
913
913
|
/* globals navigator, process, parseCustom, parseNative */
|
|
914
914
|
|
|
915
|
-
|
|
916
|
-
|
|
915
|
+
const isSafari = typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor)
|
|
916
|
+
const oldNode = typeof process !== 'undefined' && process.version.startsWith('v4.')
|
|
917
917
|
|
|
918
918
|
function needsCustomParser (options) {
|
|
919
919
|
return options.ignoreComments || options.ignoreTrailingCommas ||
|