• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jsonicjs / jsonic / 18684222349

21 Oct 2025 12:43PM UTC coverage: 87.929% (+2.6%) from 85.307%
18684222349

push

github

rjrodger
error.ts

1463 of 1729 branches covered (84.62%)

Branch coverage included in aggregate %.

102 of 113 new or added lines in 5 files covered. (90.27%)

55 existing lines in 3 files now uncovered.

1538 of 1684 relevant lines covered (91.33%)

521333.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.1
/dist/debug.js
1
"use strict";
2
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
3
Object.defineProperty(exports, "__esModule", { value: true });
36✔
4
exports.Debug = void 0;
36✔
5
const jsonic_1 = require("./jsonic");
36✔
6
const DEFAULTS = {
36✔
7
    print: true,
8
    trace: {
9
        step: true,
10
        rule: true,
11
        lex: true,
12
        parse: true,
13
        node: true,
14
        stack: true,
15
    },
16
};
17
const { entries, tokenize } = jsonic_1.util;
36✔
18
const Debug = (jsonic, options) => {
36✔
19
    options.trace =
18✔
20
        true === options.trace ? { ...DEFAULTS.trace } : options.trace;
18!
21
    const { keys, values, entries } = jsonic.util;
18✔
22
    jsonic.debug = {
18✔
23
        describe: function () {
24
            let cfg = jsonic.internal().config;
9✔
25
            let match = cfg.lex.match;
9✔
26
            let rules = jsonic.rule();
9✔
27
            return [
9✔
28
                '========= TOKENS ========',
29
                Object.entries(cfg.t)
30
                    .filter((te) => 'string' === typeof te[1])
459✔
31
                    .map((te) => {
32
                    return ('  ' +
153✔
33
                        te[0] +
34
                        '\t' +
35
                        te[1] +
36
                        '\t' +
37
                        ((s) => (s ? '"' + s + '"' : ''))(cfg.fixed.ref[te[0]] || ''));
153✔
38
                })
39
                    .join('\n'),
40
                '\n',
41
                '========= RULES =========',
42
                ruleTree(jsonic, keys(rules), rules),
43
                '\n',
44
                '========= ALTS =========',
45
                values(rules)
46
                    .map((rs) => '  ' +
45✔
47
                    rs.name +
48
                    ':\n' +
49
                    descAlt(jsonic, rs, 'open') +
50
                    descAlt(jsonic, rs, 'close'))
51
                    .join('\n\n'),
52
                '\n',
53
                '========= LEXER =========',
54
                '  ' +
55
                    ((match &&
18!
56
                        match.map((m) => m.order + ': ' + m.matcher + ' (' + m.make.name + ')')) ||
63✔
57
                        []).join('\n  '),
58
                '\n',
59
                '\n',
60
                '========= PLUGIN =========',
61
                '  ' +
62
                    jsonic
63
                        .internal()
64
                        .plugins.map((p) => p.name +
9✔
65
                        (p.options
9!
66
                            ? entries(p.options).reduce((s, e) => (s += '\n    ' + e[0] + ': ' + JSON.stringify(e[1])), '')
18✔
67
                            : ''))
68
                        .join('\n  '),
69
                '\n',
70
            ].join('\n');
71
        },
72
    };
73
    const origUse = jsonic.use.bind(jsonic);
18✔
74
    jsonic.use = (...args) => {
18✔
UNCOV
75
        let self = origUse(...args);
×
76
        if (options.print) {
×
UNCOV
77
            self
×
78
                .internal()
79
                .config.debug.get_console()
80
                .log('USE:', args[0].name, '\n\n', self.debug.describe());
81
        }
82
        return self;
×
83
    };
84
    if (options.trace) {
18!
85
        jsonic.options({
18✔
86
            parse: {
87
                prepare: {
88
                    debug: (_jsonic, ctx, _meta) => {
89
                        const console_log = ctx.cfg.debug.get_console().log;
36✔
90
                        console_log('\n========= TRACE ==========');
36✔
91
                        ctx.log =
36✔
92
                            ctx.log ||
72✔
93
                                ((kind, ...rest) => {
94
                                    if (LOGKIND[kind] && options.trace[kind]) {
1,710!
95
                                        console_log(LOGKIND[kind](...rest)
1,710✔
96
                                            .filter((item) => 'object' != typeof item)
14,058✔
97
                                            .map((item) => 'function' == typeof item ? item.name : item)
9,531!
98
                                            .join('  '));
99
                                    }
100
                                });
101
                    },
102
                },
103
            },
104
        });
105
    }
106
};
107
exports.Debug = Debug;
36✔
108
function descAlt(jsonic, rs, kind) {
109
    const { entries } = jsonic.util;
90✔
110
    return 0 === rs.def[kind].length
90!
111
        ? ''
112
        : '    ' +
113
            kind.toUpperCase() +
114
            ':\n' +
115
            rs.def[kind]
116
                .map((a, i) => {
117
                var _a, _b;
118
                return '      ' +
468✔
119
                    ('' + i).padStart(5, ' ') +
120
                    ' ' +
121
                    ('[' +
122
                        (a.s || [])
531✔
123
                            .map((tin) => null == tin
513!
124
                            ? '***INVALID***'
125
                            : 'number' === typeof tin
513✔
126
                                ? jsonic.token[tin]
127
                                : '[' + tin.map((t) => jsonic.token[t]) + ']')
423✔
128
                            .join(' ') +
129
                        '] ').padEnd(32, ' ') +
130
                    (a.r ? ' r=' + ('string' === typeof a.r ? a.r : '<F>') : '') +
540!
131
                    (a.p ? ' p=' + ('string' === typeof a.p ? a.p : '<F>') : '') +
594!
132
                    (!a.r && !a.p ? '\t' : '') +
1,332✔
133
                    '\t' +
134
                    (null == a.b ? '' : 'b=' + a.b) +
468✔
135
                    '\t' +
136
                    (null == a.n
468✔
137
                        ? ''
138
                        : 'n=' +
139
                            entries(a.n).map(([k, v]) => k + ':' + v)) +
45✔
140
                    '\t' +
141
                    (null == a.a ? '' : 'A') +
468✔
142
                    (null == a.c ? '' : 'C') +
468✔
143
                    (null == a.h ? '' : 'H') +
468!
144
                    '\t' +
145
                    (null == ((_a = a.c) === null || _a === void 0 ? void 0 : _a.n)
1,872!
146
                        ? '\t'
147
                        : ' CN=' +
UNCOV
148
                            entries(a.c.n).map(([k, v]) => k + ':' + v)) +
×
149
                    (null == ((_b = a.c) === null || _b === void 0 ? void 0 : _b.d) ? '' : ' CD=' + a.c.d) +
1,872!
150
                    (a.g ? '\tg=' + a.g : '');
468!
151
            })
152
                .join('\n') +
153
            '\n';
154
}
155
function ruleTree(jsonic, rn, rsm) {
156
    const { values, omap } = jsonic.util;
9✔
157
    return rn.reduce((a, n) => ((a +=
45✔
158
        '  ' +
159
            n +
160
            ':\n    ' +
161
            values(omap({
162
                op: ruleTreeStep(rsm, n, 'open', 'p'),
163
                or: ruleTreeStep(rsm, n, 'open', 'r'),
164
                cp: ruleTreeStep(rsm, n, 'close', 'p'),
165
                cr: ruleTreeStep(rsm, n, 'close', 'r'),
166
            }, ([n, d]) => [
180✔
167
                1 < d.length ? n : undefined,
180✔
168
                n + ': ' + d,
169
            ])).join('\n    ') +
170
            '\n'),
171
        a), '');
172
}
173
function ruleTreeStep(rsm, name, state, step) {
174
    return [
180✔
175
        ...new Set(rsm[name].def[state]
176
            .filter((alt) => alt[step])
936✔
177
            .map((alt) => alt[step])
198✔
178
            .map((step) => ('string' === typeof step ? step : '<F>'))),
198!
179
    ].join(' ');
180
}
181
function descTokenState(ctx) {
182
    return ('[' +
1,413✔
183
        (ctx.NOTOKEN === ctx.t0 ? '' : ctx.F(ctx.t0.src)) +
1,413✔
184
        (ctx.NOTOKEN === ctx.t1 ? '' : ' ' + ctx.F(ctx.t1.src)) +
1,413✔
185
        ']~[' +
186
        (ctx.NOTOKEN === ctx.t0 ? '' : tokenize(ctx.t0.tin, ctx.cfg)) +
1,413✔
187
        (ctx.NOTOKEN === ctx.t1 ? '' : ' ' + tokenize(ctx.t1.tin, ctx.cfg)) +
1,413✔
188
        ']');
189
}
190
function descParseState(ctx, rule, lex) {
191
    return (ctx.F(ctx.src().substring(lex.pnt.sI, lex.pnt.sI + 16)).padEnd(18, ' ') +
1,413✔
192
        ' ' +
193
        descTokenState(ctx).padEnd(34, ' ') +
194
        ' ' +
195
        ('' + rule.d).padStart(4, ' '));
196
}
197
function descRuleState(ctx, rule) {
198
    let en = entries(rule.n);
585✔
199
    let eu = entries(rule.u);
585✔
200
    let ek = entries(rule.k);
585✔
201
    return ('' +
585✔
202
        (0 === en.length
585✔
203
            ? ''
204
            : ' N<' +
205
                en
206
                    .filter((n) => n[1])
405✔
207
                    .map((n) => n[0] + '=' + n[1])
405✔
208
                    .join(';') +
209
                '>') +
210
        (0 === eu.length
585✔
211
            ? ''
212
            : ' U<' + eu.map((u) => u[0] + '=' + ctx.F(u[1])).join(';') + '>') +
198✔
213
        (0 === ek.length
585!
214
            ? ''
UNCOV
215
            : ' K<' + ek.map((k) => k[0] + '=' + ctx.F(k[1])).join(';') + '>'));
×
216
}
217
function descAltSeq(alt, cfg) {
218
    return ('[' +
504✔
219
        (alt.s || [])
558✔
220
            .map((tin) => 'number' === typeof tin
576✔
221
            ? tokenize(tin, cfg)
222
            : Array.isArray(tin)
171!
223
                ? '[' + tin.map((t) => tokenize(t, cfg)) + ']'
477✔
224
                : '')
225
            .join(' ') +
226
        '] ');
227
}
228
const LOG = {
36✔
229
    RuleState: {
230
        o: jsonic_1.S.open.toUpperCase(),
231
        c: jsonic_1.S.close.toUpperCase(),
232
    },
233
};
234
const LOGKIND = {
36✔
235
    step: (...rest) => rest,
297✔
236
    stack: (ctx, rule, lex) => [
288✔
237
        jsonic_1.S.logindent + jsonic_1.S.stack,
238
        descParseState(ctx, rule, lex),
239
        // S.indent.repeat(Math.max(rule.d + ('o' === rule.state ? -1 : 1), 0)) +
240
        jsonic_1.S.indent.repeat(rule.d) +
241
            '/' +
242
            ctx.rs
243
                // .slice(0, ctx.rsI)
244
                .slice(0, rule.d)
245
                .map((r) => r.name + '~' + r.i)
405✔
246
                .join('/'),
247
        '~',
248
        '/' +
249
            ctx.rs
250
                // .slice(0, ctx.rsI)
251
                .slice(0, rule.d)
252
                .map((r) => ctx.F(r.node))
405✔
253
                .join('/'),
254
        // 'd=' + rule.d,
255
        //'rsI=' + ctx.rsI,
256
        ctx,
257
        rule,
258
        lex,
259
    ],
260
    rule: (ctx, rule, lex) => [
297✔
261
        rule,
262
        ctx,
263
        lex,
264
        jsonic_1.S.logindent + jsonic_1.S.rule + jsonic_1.S.space,
265
        descParseState(ctx, rule, lex),
266
        jsonic_1.S.indent.repeat(rule.d) +
267
            (rule.name + '~' + rule.i + jsonic_1.S.colon + LOG.RuleState[rule.state]).padEnd(16),
268
        ('prev=' +
269
            rule.prev.i +
270
            ' parent=' +
271
            rule.parent.i +
272
            ' child=' +
273
            rule.child.i).padEnd(28),
274
        descRuleState(ctx, rule),
275
    ],
276
    node: (ctx, rule, lex, next) => [
288✔
277
        rule,
278
        ctx,
279
        lex,
280
        next,
281
        jsonic_1.S.logindent + jsonic_1.S.node + jsonic_1.S.space,
282
        descParseState(ctx, rule, lex),
283
        jsonic_1.S.indent.repeat(rule.d) +
284
            ('why=' + next.why + jsonic_1.S.space + '<' + ctx.F(rule.node) + '>').padEnd(46),
285
        descRuleState(ctx, rule),
286
    ],
287
    parse: (ctx, rule, lex, match, cond, altI, alt, out) => {
288
        let ns = match && out.n ? entries(out.n) : null;
297!
289
        let us = match && out.u ? entries(out.u) : null;
297✔
290
        let ks = match && out.k ? entries(out.k) : null;
297!
291
        return [
297✔
292
            ctx,
293
            rule,
294
            lex,
295
            jsonic_1.S.logindent + jsonic_1.S.parse,
296
            descParseState(ctx, rule, lex),
297
            jsonic_1.S.indent.repeat(rule.d) + (match ? 'alt=' + altI : 'no-alt'),
297✔
298
            match && alt ? descAltSeq(alt, ctx.cfg) : '',
882✔
299
            match && out.g ? 'g:' + out.g + ' ' : '',
882✔
300
            (match && out.p ? 'p:' + out.p + ' ' : '') +
882✔
301
                (match && out.r ? 'r:' + out.r + ' ' : '') +
882✔
302
                (match && out.b ? 'b:' + out.b + ' ' : ''),
882✔
303
            alt && alt.c ? 'c:' + cond : jsonic_1.EMPTY,
882✔
UNCOV
304
            null == ns ? '' : 'n:' + ns.map((p) => p[0] + '=' + p[1]).join(';'),
×
305
            null == us ? '' : 'u:' + us.map((p) => p[0] + '=' + p[1]).join(';'),
36✔
UNCOV
306
            null == ks ? '' : 'k:' + ks.map((p) => p[0] + '=' + p[1]).join(';'),
×
307
        ];
308
    },
309
    lex: (ctx, rule, lex, pnt, sI, match, tkn, alt, altI, tI) => [
243✔
310
        jsonic_1.S.logindent + jsonic_1.S.lex + jsonic_1.S.space + jsonic_1.S.space,
311
        descParseState(ctx, rule, lex),
312
        jsonic_1.S.indent.repeat(rule.d) +
313
            // S.indent.repeat(rule.d) + S.lex, // Log entry prefix.
314
            // Name of token from tin (token identification numer).
315
            tokenize(tkn.tin, ctx.cfg),
316
        ctx.F(tkn.src), // Format token src for log.
317
        pnt.sI, // Current source index.
318
        pnt.rI + ':' + pnt.cI, // Row and column.
319
        (match === null || match === void 0 ? void 0 : match.name) || '',
1,116✔
320
        alt
243✔
321
            ? 'on:alt=' +
322
                altI +
323
                ';' +
324
                alt.g +
325
                ';t=' +
326
                tI +
327
                ';' +
328
                descAltSeq(alt, ctx.cfg)
329
            : '',
330
        ctx.F(lex.src.substring(sI, sI + 16)),
331
        ctx,
332
        rule,
333
        lex,
334
    ],
335
};
336
Debug.defaults = DEFAULTS;
36✔
337
//# sourceMappingURL=debug.js.map
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc