optimize: size produces invalid typescript
james-criscuolo opened this issue · 2 comments
I believe this was the cause of #12, but wanted to open another issue as that one is closed and almost a year old.
If I clone this repo and include --optimize size
in the test:cli
script, I get:
> pegjs --plugin ./src/tspegjs --extra-options-file test/genoptions2.json --optimize size --allowed-start-rules groupFile,templateFile,templateFileRaw,templateAndEOF -o output/st2.ts examples/st.pegjs && tsc output/st2.ts && tslint output/st2.ts
output/st2.ts(938,5): error TS2540: Cannot assign to 'peg$startRuleIndex' because it is a constant or a read-only property.
output/st2.ts(1067,5): error TS2322: Type 'number[]' is not assignable to type 'number'.
output/st2.ts(1074,18): error TS2339: Property 'length' does not exist on type 'number'.
output/st2.ts(1220,66): error TS2339: Property 'length' does not exist on type 'string | RegExp | ILiteralExpectation | IClassExpectation | IAnyExpectation | IOtherExpectation |...'.
Property 'length' does not exist on type 'RegExp'.
output/st2.ts(1234,66): error TS2339: Property 'length' does not exist on type 'string | RegExp | ILiteralExpectation | IClassExpectation | IAnyExpectation | IOtherExpectation |...'.
Property 'length' does not exist on type 'RegExp'.
output/st2.ts(1248,40): error TS2339: Property 'test' does not exist on type 'string | RegExp | ILiteralExpectation | IClassExpectation | IAnyExpectation | IOtherExpectation |...'.
Property 'test' does not exist on type 'string'.
output/st2.ts(1266,51): error TS2339: Property 'length' does not exist on type 'string | RegExp | ILiteralExpectation | IClassExpectation | IAnyExpectation | IOtherExpectation |...'.
Property 'length' does not exist on type 'RegExp'.
output/st2.ts(1273,24): error TS2345: Argument of type 'string | RegExp | ILiteralExpectation | IClassExpectation | IAnyExpectation | IOtherExpectation |...' is not assignable to parameter of type 'Expectation'.
Type 'string' is not assignable to type 'Expectation'.
output/st2.ts(1289,25): error TS2339: Property 'slice' does not exist on type 'number'.
output/st2.ts(1295,38): error TS2339: Property 'apply' does not exist on type 'string | RegExp | ILiteralExpectation | IClassExpectation | IAnyExpectation | IOtherExpectation |...'.
Property 'apply' does not exist on type 'string'.
I am currently converting my library to typescript, and this library has been tremendously helpful, but I had to remove optimize: size
, which I believe is the main contributor to the doubling in size of the bundle unminified, and 25% increase minified (its about an order of magnitude larger) minified. Bundles aren't necessarily the main way the library will be used going forward, but it's hard to fight for a size increase.
Is there anything preventing this from being merged? I saw a PR was taken recently and released, so was curious if there is anything I could do to get this taken and released as well.
Hi @james-criscuolo thank you for your great contribution and sorry for my delay in the review and merge. I need to get some free time to double check and ensure backward compatibility.