Feature: Run-time requiring of pegjs files
See original GitHub issueIssue type
- Bug Report: no
- Feature Request: yes
- Question: no
- Not an issue: no
Prerequisites
- Can you reproduce the issue?: n/a
- Did you search the repository issues?: yes
- Did you check the forums?: I don’t see links to forums
- Did you perform a web search (google, yahoo, etc)?: yes
Description
While there might be other use cases for being able to require PEGJS files directly in Node at run-time, the main intent of this issue is for code coverage (e.g., for Mocha tests).
This latter use case of code coverage would first need #93 (providing source maps) to be first implemented. If implemented, one could avoid the need for a separate instrumented copy of one’s tests + peg code.
I see that Node’s require.extensions is used to accomplish this for ts-node, and though require.extensions is technically deprecated in Node, as per the discussions around https://stackoverflow.com/questions/28884377/better-way-to-require-extensions-with-node-js (particularly in the vein of this answer), it seems to be the only practical mechanism here, and as per the comment, I don’t think we have to worry about Node breaking Babel.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8

Top Related StackOverflow Question
@brettz9 - I was about to say “I’m talking to someone else about this same thing” and then I realized it’s you, so, I’m going to cease this instance of this discussion in favor of the similar one we’re having on #633, if that seems okay to you
I’m writing something long there currently
Also, it looks like what you actually want is testing
You don’t put the coverage hooks in the library. You put them in the test file.
If you want coverage, you can install
jestand just be done. It auto-includes everything you need and no modifications need to take place to the library. Coverage tools are designed to be added from the outside, not the inside.This parser generator should not suddenly become tied to the
node.jspackage ecosystem as an internal feature.Besides, coverage is a false desire for a parser. Consider the following:
Now, just write a test for rice.
pegis going to tryPeanutsfirst, then when it doesn’t workpegwill tryShellfish, thenpegwill tryRiceNotice you only wrote a test for
Rice, but you’re incorrectly showing coverage for all threeThe way a packrat parser (honestly the way ever parser I can think of) works means coverage is fake
Don’t waste your time