Skip to content

Commit ba511fc

Browse files
authored
Merge pull request #13 from hildjj/warning
Add warning if running in debug mode to prevent confusion when a peg$debugger statement is left in by mistake.
2 parents 2cd3ae5 + e8c126e commit ba511fc

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

lib/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
184184
startRule,
185185
...options,
186186
});
187-
fail("Expected error but none received");
187+
fail(`Expected error but none received for invalidInput: "${start.invalidInput}"`);
188188
} catch (er) {
189189
if (!(er instanceof grammar.SyntaxError)) {
190190
throw er;
@@ -424,9 +424,14 @@ export async function testPeggy(grammarUrl, starts, opts) {
424424
const withMap = src.toStringWithSourceMap();
425425
const map = Buffer.from(withMap.map.toString()).toString("base64");
426426
let code = withMap.code;
427-
const sm = (opts && Object.prototype.hasOwnProperty.call(opts, "noMap"))
428-
? !opts.noMap
429-
: starts.every(s => !s.options?.peg$debugger);
427+
let sm = starts.every(s => !s.options?.peg$debugger);
428+
if (opts && Object.prototype.hasOwnProperty.call(opts, "noMap")) {
429+
sm = !opts.noMap;
430+
} else {
431+
if (!sm) {
432+
console.error("WARNING: sourcemap disabled due to peg$debugger");
433+
}
434+
}
430435
const start = "//#"; // c8: THIS file is not mapped.
431436
if (sm) {
432437
code += `

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"typedoc": "0.26.11",
4141
"typescript": "5.6.3"
4242
},
43-
"packageManager": "[email protected]",
43+
"packageManager": "[email protected]+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387",
4444
"pnpm": {
4545
"overrides": {
4646
"@eslint/plugin-kit": "^0.2.3",

test/index.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,19 @@ test("thows errors", async() => {
186186
},
187187
]));
188188
});
189+
190+
test("peg$debugger", async() => {
191+
const old = console.error;
192+
const stderr = [];
193+
console.error = (...args) => stderr.push(args);
194+
await testPeggy(MIN, [
195+
{
196+
validInput: "foo",
197+
options: {
198+
peg$debugger: true,
199+
},
200+
},
201+
]);
202+
console.error = old;
203+
deepEqual(stderr, [["WARNING: sourcemap disabled due to peg$debugger"]]);
204+
});

0 commit comments

Comments
 (0)