From 9ede6ea53c91e80e542c86e24dd3d34c70415cd8 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 1 Nov 2023 16:16:29 +0100 Subject: [PATCH] feat: update to `jsonrepair@3.4.0` --- package-lock.json | 38 ++++++++++++++++++-------------- package.json | 4 ++-- src/lib/logic/validation.test.ts | 8 +++---- src/lib/utils/jsonUtils.test.ts | 2 +- src/lib/utils/jsonUtils.ts | 10 +++------ 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index d64a7aca..d1bc1a69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "immutable-json-patch": "^5.1.3", "jmespath": "^0.16.0", "json-source-map": "^0.6.1", - "jsonrepair": "^3.2.4", + "jsonrepair": "^3.4.0", "lodash-es": "^4.17.21", "memoize-one": "^6.0.0", "natural-compare-lite": "^1.4.0", @@ -69,7 +69,7 @@ "eslint-plugin-svelte": "2.34.0", "husky": "8.0.3", "jsdom": "22.1.0", - "lossless-json": "2.0.11", + "lossless-json": "3.0.0", "npm-run-all": "4.1.5", "prettier": "3.0.3", "prettier-plugin-svelte": "3.0.3", @@ -9613,9 +9613,9 @@ ] }, "node_modules/jsonrepair": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.2.4.tgz", - "integrity": "sha512-NvCthT+ciKTU62IF8z34WMl6/TEyDcBjFWWVG038Nzd08+v+VfeEI2gElgpgrbYB5tWsiRiwrAo0TTBDoiDpEA==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.4.0.tgz", + "integrity": "sha512-dFI5+BXlOra3SsJXEODXjHMpDPkZje6q2kCTPS9Ugb3Bdj9aok7HtrSPCXCOMsCbTStdUzhUVNS2xuVyMn2qFg==", "bin": { "jsonrepair": "bin/cli.js" } @@ -9844,10 +9844,13 @@ "dev": true }, "node_modules/lossless-json": { - "version": "2.0.11", - "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-2.0.11.tgz", - "integrity": "sha512-BP0vn+NGYvzDielvBZaFain/wgeJ1hTvURCqtKvhr1SCPePdaaTanmmcplrHfEJSJOUql7hk4FHwToNJjWRY3g==", - "dev": true + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-3.0.0.tgz", + "integrity": "sha512-8pg3EzFHRa/+4yyWkTqWywmRw3qHuZYFUe5W4XoBI7gJW621YqJFWjXydafpcZHFopX0zBuFKxJnccpGYofrpA==", + "dev": true, + "dependencies": { + "vitest": "0.34.6" + } }, "node_modules/loupe": { "version": "2.3.7", @@ -20344,9 +20347,9 @@ "dev": true }, "jsonrepair": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.2.4.tgz", - "integrity": "sha512-NvCthT+ciKTU62IF8z34WMl6/TEyDcBjFWWVG038Nzd08+v+VfeEI2gElgpgrbYB5tWsiRiwrAo0TTBDoiDpEA==" + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.4.0.tgz", + "integrity": "sha512-dFI5+BXlOra3SsJXEODXjHMpDPkZje6q2kCTPS9Ugb3Bdj9aok7HtrSPCXCOMsCbTStdUzhUVNS2xuVyMn2qFg==" }, "JSONStream": { "version": "1.3.5", @@ -20532,10 +20535,13 @@ "dev": true }, "lossless-json": { - "version": "2.0.11", - "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-2.0.11.tgz", - "integrity": "sha512-BP0vn+NGYvzDielvBZaFain/wgeJ1hTvURCqtKvhr1SCPePdaaTanmmcplrHfEJSJOUql7hk4FHwToNJjWRY3g==", - "dev": true + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/lossless-json/-/lossless-json-3.0.0.tgz", + "integrity": "sha512-8pg3EzFHRa/+4yyWkTqWywmRw3qHuZYFUe5W4XoBI7gJW621YqJFWjXydafpcZHFopX0zBuFKxJnccpGYofrpA==", + "dev": true, + "requires": { + "vitest": "0.34.6" + } }, "loupe": { "version": "2.3.7", diff --git a/package.json b/package.json index 55d6a482..89cc9c7a 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "immutable-json-patch": "^5.1.3", "jmespath": "^0.16.0", "json-source-map": "^0.6.1", - "jsonrepair": "^3.2.4", + "jsonrepair": "^3.4.0", "lodash-es": "^4.17.21", "memoize-one": "^6.0.0", "natural-compare-lite": "^1.4.0", @@ -131,7 +131,7 @@ "eslint-plugin-svelte": "2.34.0", "husky": "8.0.3", "jsdom": "22.1.0", - "lossless-json": "2.0.11", + "lossless-json": "3.0.0", "npm-run-all": "4.1.5", "prettier": "3.0.3", "prettier-plugin-svelte": "3.0.3", diff --git a/src/lib/logic/validation.test.ts b/src/lib/logic/validation.test.ts index e67662a7..ef512523 100644 --- a/src/lib/logic/validation.test.ts +++ b/src/lib/logic/validation.test.ts @@ -200,15 +200,15 @@ describe('validation', () => { }) test('should validateText with a non-repairable parse error', () => { - const invalidText = '{\n "name": "Joe" ]' + const invalidText = '{\n "name": "Joe" }[]' deepStrictEqual(validateText(invalidText, null, LosslessJSONParser, JSON), { isRepairable: false, parseError: { - column: 16, + column: 17, line: 1, - message: "Comma ',' expected after value but got ']' at line 2 column 17", - position: 18 + message: "Expected end of input but got '[' at line 2 column 18", + position: 19 } }) }) diff --git a/src/lib/utils/jsonUtils.test.ts b/src/lib/utils/jsonUtils.test.ts index ea70c7ca..71043f7d 100644 --- a/src/lib/utils/jsonUtils.test.ts +++ b/src/lib/utils/jsonUtils.test.ts @@ -426,7 +426,7 @@ describe('jsonUtils', () => { describe('parseAndRepairOrUndefined', () => { test('repair partial JSON', () => { expect(parseAndRepairOrUndefined('[1,2', JSON)).toEqual([1, 2]) - expect(parseAndRepairOrUndefined('[1,2}', JSON)).toEqual(undefined) + expect(parseAndRepairOrUndefined('[1,2][]', JSON)).toEqual(undefined) expect(parseAndRepairOrUndefined('hello world', JSON)).toEqual('hello world') // expect(parseAndRepairOrUndefined('0123', JSON)).toEqual('0123') // FIXME }) diff --git a/src/lib/utils/jsonUtils.ts b/src/lib/utils/jsonUtils.ts index 69d6b8a2..294af7fa 100644 --- a/src/lib/utils/jsonUtils.ts +++ b/src/lib/utils/jsonUtils.ts @@ -15,13 +15,12 @@ import type { TextLocation } from '../types' import { int } from './numberUtils.js' -import type { JavaScriptValue } from 'lossless-json' /** * Parse the JSON. if this fails, try to repair and parse. * Throws an exception when the JSON is invalid and could not be parsed. */ -export function parseAndRepair(jsonText: string, parser: JSONParser): JavaScriptValue { +export function parseAndRepair(jsonText: string, parser: JSONParser): unknown { try { return parser.parse(jsonText) } catch (err) { @@ -37,7 +36,7 @@ export function parseAndRepair(jsonText: string, parser: JSONParser): JavaScript export function parseAndRepairOrUndefined( partialJson: string, parser: JSONParser -): JavaScriptValue | undefined { +): unknown | undefined { try { return parseAndRepair(partialJson, parser) } catch (err) { @@ -46,10 +45,7 @@ export function parseAndRepairOrUndefined( } // TODO: deduplicate the logic in repairPartialJson and parseAndRepairPartialJson ? -export function parsePartialJson( - partialJson: string, - parse: (text: string) => JavaScriptValue -): JavaScriptValue { +export function parsePartialJson(partialJson: string, parse: (text: string) => unknown): unknown { // for now: dumb brute force approach: simply try out a few things... // remove trailing comma