acp-kernel 0.0.67-pr.269.127 → 0.0.67-pr.271.128
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/dist/index.js +41 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4000,6 +4000,13 @@ function tryParseLenient(s) {
|
|
|
4000
4000
|
} catch {
|
|
4001
4001
|
}
|
|
4002
4002
|
}
|
|
4003
|
+
const ctrlFixed = repairAtParserPositions(noTrailingCommas);
|
|
4004
|
+
if (ctrlFixed !== noTrailingCommas) {
|
|
4005
|
+
try {
|
|
4006
|
+
return JSON.parse(ctrlFixed);
|
|
4007
|
+
} catch {
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4003
4010
|
return void 0;
|
|
4004
4011
|
}
|
|
4005
4012
|
function normalizeSingleQuotes(raw) {
|
|
@@ -4140,6 +4147,40 @@ function escapeRawNewlinesInStrings(s) {
|
|
|
4140
4147
|
}
|
|
4141
4148
|
return out;
|
|
4142
4149
|
}
|
|
4150
|
+
function repairAtParserPositions(s) {
|
|
4151
|
+
let cur = s;
|
|
4152
|
+
for (let i = 0; i < 500; i++) {
|
|
4153
|
+
let err;
|
|
4154
|
+
try {
|
|
4155
|
+
JSON.parse(cur);
|
|
4156
|
+
return cur;
|
|
4157
|
+
} catch (e) {
|
|
4158
|
+
err = e;
|
|
4159
|
+
}
|
|
4160
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4161
|
+
const posMatch = /position (\d+)/.exec(msg);
|
|
4162
|
+
if (posMatch === null) return cur;
|
|
4163
|
+
const pos = Number(posMatch[1]);
|
|
4164
|
+
if (!Number.isInteger(pos) || pos < 0 || pos >= cur.length) return cur;
|
|
4165
|
+
if (/control character/i.test(msg)) {
|
|
4166
|
+
const ch = cur.charAt(pos);
|
|
4167
|
+
let esc;
|
|
4168
|
+
if (ch === "\n") esc = "\\n";
|
|
4169
|
+
else if (ch === "\r") esc = "\\r";
|
|
4170
|
+
else if (ch === " ") esc = "\\t";
|
|
4171
|
+
else if (ch.charCodeAt(0) < 32) esc = "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0");
|
|
4172
|
+
if (esc === void 0) return cur;
|
|
4173
|
+
cur = cur.slice(0, pos) + esc + cur.slice(pos + 1);
|
|
4174
|
+
} else if (/Bad escaped character/i.test(msg)) {
|
|
4175
|
+
const b = cur.charAt(pos - 1) === "\\" ? pos - 1 : cur.charAt(pos) === "\\" ? pos : -1;
|
|
4176
|
+
if (b < 0) return cur;
|
|
4177
|
+
cur = cur.slice(0, b) + "\\\\" + cur.slice(b + 1);
|
|
4178
|
+
} else {
|
|
4179
|
+
return cur;
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
return cur;
|
|
4183
|
+
}
|
|
4143
4184
|
function looksTruncated(s) {
|
|
4144
4185
|
let depth = 0;
|
|
4145
4186
|
let inString = false;
|