peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
906 stars 64 forks source link

Es test #460

Closed hildjj closed 6 months ago

hildjj commented 6 months ago

Allow testing of es modules. Fixes #399

frostburn commented 6 months ago

Tests succeed on my end. I'm not familiar with the issues in this PR. Is there something that I could test manually that is broken on main and this one fixes?

hildjj commented 6 months ago

This should fail on main, but pass on this branch:

echo "foo = '1'" | bin/peggy.js --format es -t 1

unless you run this branch on node 20.7 or earlier, then it should fail with a version error.

hildjj commented 6 months ago

All of the interesting stuff is now in bin/fromMem.js. It shouldn't actually be security-relevant, even though it looks like it. All of those gyrations are there so that import and require work relative to the output directory (which is the input directory by default).

frostburn commented 6 months ago

This should fail on main, but pass on this branch:

echo "foo = '1'" | bin/peggy.js --format es -t 1

unless you run this branch on node 20.7 or earlier, then it should fail with a version error.

Apparently my version of Ubuntu ships with node version 18.13.0 so I get the expected failure. (Don't feel like messing around with updates right now...)

On main I get:

Error running test
Unexpected token 'export'
hildjj commented 6 months ago

Good, that works as expected. I like to use npm -g install nve and nve 21 ./bin/peggy ... to use different node versions without having to change what is installed globally.

frostburn commented 6 months ago

Thanks!

$ echo "foo = '1'" | nve 21 node --experimental-vm-modules ./bin/peggy.js --format es -t 1
'1'