Skip to content

Commit 4c74e3d

Browse files
committed
fix: Rename the property "exzerpt" in error information to "excerpt"
BREAKING CHANGE: If you used the property "exzerpt" from the parsing error object, you have to change it to "excerpt". It should be easy using a full-text search in your sources.
1 parent d5eaa93 commit 4c74e3d

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ If parsing fails, a `SyntaxError` will be thrown with the following properties:
271271
| ---------- | ----------------------------------------- |
272272
| `message` | the full multi-line error message |
273273
| `reason` | one-line explanation of the error |
274-
| `exzerpt` | part of the input string around the error |
275-
| `pointer` | "--^" pointing to the error in `exzerpt` |
274+
| `excerpt` | part of the input string around the error |
275+
| `pointer` | "--^" pointing to the error in `excerpt` |
276276
| `location` | object pointing to the error location |
277277

278278
The `location` object contains properties `line`, `column` and `offset`.
@@ -289,13 +289,13 @@ const { parse } = require('@prantlf/jsonlint')
289289
try {
290290
parse('{"creative": ?}')
291291
} catch (error) {
292-
const { message, reason, exzerpt, pointer, location } = error
292+
const { message, reason, excerpt, pointer, location } = error
293293
const { column, line, offset } = location.start
294294
// Logs the complete error message:
295295
console.log(message)
296296
// Logs the same text as included in the `message` property:
297297
console.log(`Parse error on line ${line}, ${column} column:
298-
${exzerpt}
298+
${excerpt}
299299
${pointer}
300300
${reason}`)
301301
}

lib/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
var column = location.column
4040
var texts = jsonlint.getErrorTexts(problem.reason, input, offset, line, column)
4141
problem.message = texts.message
42-
problem.exzerpt = texts.exzerpt
42+
problem.excerpt = texts.excerpt
4343
if (texts.pointer) {
4444
problem.pointer = texts.pointer
4545
problem.location = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"build": "npm run compile && npm run compile:tests",
4141
"compile": "node scripts/bundle-jsonlint && uglifyjs -o web/jsonlint.min.js --source-map \"filename='jsonlint.js',url='jsonlint.min.js.map',includeSources=true\" lib/jsonlint.js && uglifyjs -o web/validator.min.js --source-map \"filename='validator.js',url='validator.min.js.map',includeSources=true\" lib/validator.js && uglifyjs -o web/formatter.min.js --source-map \"filename='formatter.js',url='formatter.min.js.map',includeSources=true\" lib/formatter.js && uglifyjs -o web/sorter.min.js --source-map \"filename='sorter.js',url='sorter.min.js.map',includeSources=true\" lib/sorter.js && uglifyjs -o web/printer.min.js --source-map \"filename='printer.js',url='printer.min.js.map',includeSources=true\" lib/printer.js && node scripts/bundle-schema-drafts && uglifyjs -o web/schema-drafts.min.js --source-map \"filename='schema-drafts.js',url='schema-drafts.min.js.map',includeSources=true\" lib/schema-drafts.js && uglifyjs -o web/ajv.min.js --source-map \"filename='ajv.js',url='ajv.min.js.map',includeSources=true\" node_modules/ajv/dist/ajv.bundle.js",
4242
"compile:tests": "tsc --lib es6 test/typings.test.ts",
43-
"test": "nyc --silent node test/typings.test.js && nyc --silent --no-clean node test/parse1 && nyc --silent --no-clean node test/parse1 --native-parser && nyc --silent --no-clean node test/parse2 && nyc --silent --no-clean node test/parse3 && nyc --silent --no-clean node test/parse4 && nyc --silent --no-clean node test/parse5 && nyc --silent --no-clean node test/portable && nyc --silent --no-clean node test/tokenize && nyc --silent --no-clean node test/print && nyc --silent --no-clean node lib/cli package.json test/recursive && nyc --silent --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && nyc --silent --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && nyc --silent --no-clean node lib/cli -C test/passes/comments.txt && nyc --silent --no-clean node lib/cli -S test/passes/strings.txt && nyc --silent --no-clean node lib/cli -M json5 test/passes/json5.text && nyc --silent --no-clean node lib/cli -v && nyc --silent --no-clean node lib/cli -h && nyc --silent --no-clean node lib/cli -Pc test/fails/10.json || nyc report",
43+
"test": "nyc --silent node test/typings.test.js && nyc --silent --no-clean node test/parse1 && nyc --silent --no-clean node test/parse1 --native-parser && nyc --silent --no-clean node test/parse2 && nyc --silent --no-clean node test/parse3 && nyc --silent --no-clean node test/parse4 && nyc --silent --no-clean node test/parse5 && nyc --silent --no-clean node test/portable && nyc --silent --no-clean node test/tokenize && nyc --silent --no-clean node test/print && nyc --silent --no-clean node lib/cli package.json test/recursive && nyc --silent --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && nyc --silent --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && nyc --silent --no-clean node lib/cli -C test/passes/comments.txt && nyc --silent --no-clean node lib/cli -pS test/passes/strings.txt && nyc --silent --no-clean node lib/cli -M json5 test/passes/json5.text && nyc --silent --no-clean node lib/cli -v && nyc --silent --no-clean node lib/cli -h && nyc --silent --no-clean node lib/cli -Pc test/fails/10.json || nyc report",
4444
"start": "http-server -c 5",
4545
"web": "npm run web:sync && npm run web:deploy",
4646
"web:clone": "test ! -d ../jsonlint-pages && git clone --single-branch --branch gh-pages `git remote get-url origin` ../jsonlint-pages",

src/custom-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function parseInternal (input, options) {
114114
var texts = getTexts(message, input, position, lineNumber, column)
115115
var error = SyntaxError(texts.message)
116116
error.reason = message
117-
error.exzerpt = texts.exzerpt
117+
error.excerpt = texts.excerpt
118118
error.pointer = texts.pointer
119119
error.location = {
120120
start: {

src/native-parser.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getPositionContext (input, offset) {
2929
var upcoming = upcomingInput(input, offset)
3030
var pointer = new Array(past.length + 1).join('-') + '^'
3131
return {
32-
exzerpt: past + upcoming,
32+
excerpt: past + upcoming,
3333
pointer: pointer
3434
}
3535
}
@@ -90,18 +90,18 @@ function getLocationOnSpiderMonkey (input, reason) {
9090

9191
function getTexts (reason, input, offset, line, column) {
9292
var position = getPositionContext(input, offset)
93-
var exzerpt = position.exzerpt
93+
var excerpt = position.excerpt
9494
var message, pointer
9595
if (typeof line === 'number') {
9696
pointer = position.pointer
9797
message = 'Parse error on line ' + line + ', column ' +
98-
column + ':\n' + exzerpt + '\n' + pointer + '\n' + reason
98+
column + ':\n' + excerpt + '\n' + pointer + '\n' + reason
9999
} else {
100-
message = 'Parse error in JSON input:\n' + exzerpt + '\n' + reason
100+
message = 'Parse error in JSON input:\n' + excerpt + '\n' + reason
101101
}
102102
return {
103103
message: message,
104-
exzerpt: exzerpt,
104+
excerpt: excerpt,
105105
pointer: pointer
106106
}
107107
}
@@ -123,7 +123,7 @@ function improveNativeError (input, error) {
123123
error.reason = reason
124124
var texts = getTexts(reason, input, offset, line, column)
125125
error.message = texts.message
126-
error.exzerpt = texts.exzerpt
126+
error.excerpt = texts.excerpt
127127
if (texts.pointer) {
128128
error.pointer = texts.pointer
129129
error.location = {

test/parse1.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ parse = nativeParser ? exported.parseNative : exported.parseCustom
1616
function checkErrorInformation (error) {
1717
assert.equal(typeof error.message, 'string')
1818
assert.equal(typeof error.reason, 'string')
19-
assert.equal(typeof error.exzerpt, 'string')
19+
assert.equal(typeof error.excerpt, 'string')
2020
if (!oldNode) {
2121
assert.equal(typeof error.pointer, 'string')
2222
assert.equal(typeof error.location, 'object')
@@ -264,7 +264,7 @@ if (!oldNode) {
264264
exported.parseNative(json)
265265
assert.fail('should throw error')
266266
} catch (error) {
267-
assert.equal(error.exzerpt, '... "bar": } }')
267+
assert.equal(error.excerpt, '... "bar": } }')
268268
assert.equal(error.pointer, '-------------------^')
269269
assert.equal(error.reason, 'Unexpected token }')
270270
assert.deepEqual(error.location, {
@@ -281,7 +281,7 @@ exports['test error location with Windows line breaks using the custom parser']
281281
exported.parseCustom(json)
282282
assert.fail('should throw error')
283283
} catch (error) {
284-
assert.equal(error.exzerpt, '... "bar": } }')
284+
assert.equal(error.excerpt, '... "bar": } }')
285285
assert.equal(error.pointer, '-------------------^')
286286
assert.equal(error.reason, 'No value found for key "bar"')
287287
assert.deepEqual(error.location, {

0 commit comments

Comments
 (0)