metadevpro/ts-pegjs

--allowed-start-rules cli option is broken.

cd1m0 opened this issue · 4 comments

cd1m0 commented

Trying to use the --allowed-start-rules option results in an exception:

[dimo@bender tmp]$ tspegjs --allowed-start-rules Expression,Term tmp.pegjs 
/home/dimo/tmp/tmp/node_modules/ts-pegjs/src/passes/generate-ts.js:1026
        options.allowedStartRules.map(
                                  ^

TypeError: options.allowedStartRules.map is not a function
    at generateToplevel (/home/dimo/tmp/tmp/node_modules/ts-pegjs/src/passes/generate-ts.js:1026:35)
    at generateTS (/home/dimo/tmp/tmp/node_modules/ts-pegjs/src/passes/generate-ts.js:1534:30)
    at /home/dimo/tmp/tmp/node_modules/pegjs/lib/compiler/index.js:62:50
    at Object.each (/home/dimo/tmp/tmp/node_modules/pegjs/lib/utils/arrays.js:63:7)
    at Object.compile (/home/dimo/tmp/tmp/node_modules/pegjs/lib/compiler/index.js:62:16)
    at Object.generate (/home/dimo/tmp/tmp/node_modules/pegjs/lib/peg.js:50:25)
    at /home/dimo/tmp/tmp/node_modules/ts-pegjs/src/cli.js:82:24
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:63:3)

I believe options.allowedStartRules is a string, while an array is expected.

Perhaps there is a missing split(',') on this line https://github.com/metadevpro/ts-pegjs/blob/master/src/cli.js#L32

Thanks @cd1m0 Fixed.

cd1m0 commented

So I don't think this is fixed. In b893042 you added this code:

allowedStartRules = (args[index + 1] | '').split(',');

However I think you meant to say "||" instead of "|". The type of bitwise-or-ing 2 strings is actually a number. So if you run this code you still get an error:

/home/dimo/work/consensys/scribble-clean/node_modules/ts-pegjs/src/cli.js:32
        allowedStartRules = (args[index + 1] | "").split(",");
                                                   ^

TypeError: (args[(index + 1)] | "").split is not a function
    at /home/dimo/work/consensys/scribble-clean/node_modules/ts-pegjs/src/cli.js:32:52
    at Array.map (<anonymous>)
    at Object.<anonymous> (/home/dimo/work/consensys/scribble-clean/node_modules/ts-pegjs/src/cli.js:29:6)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

Thanks @cd1m0 for catching the typo. Just fixed in 0.3.1

cd1m0 commented

Thanks for fixing this so quickly!