PrismarineJS / node-mojangson

A mojangson parser written in node.js
17 stars 9 forks source link

Disable unused moduleMain code for browserify compatibility #4

Closed deathcap closed 8 years ago

deathcap commented 8 years ago

The jison parser generator by default will generate a command-line interface built into the parser. node-mojangson only uses the parser object and not the command-line interface, and has no way to access it, so it can be safely disabled -- since it causes compatibility issues with some browserify transforms (and is unused): https://github.com/zaach/jison/issues/300 https://github.com/substack/static-eval/pull/12)

Unfortunately, the jison command does not accept the option to disable moduleMain (open pull request to jison: https://github.com/zaach/jison/pull/316 Pass moduleMain option to generator), so I had to write a simple script using the jison API to generate the grammar as part of the prepublish script. Not too happy about this, would be a much simpler change if https://github.com/zaach/jison/pull/316 is accepted:

-   "prepublish": "node jison_generate.js",
+   "prepublish": "jison grammar.json --moduleMain 'function() {}'",

but jison last published a release in 2014, there is still an open question about its maintenance path going forward https://github.com/zaach/jison/issues/297 so I think a workaround using the API instead of CLI is most expedient for now, though admittedly less than ideal.

This change also slightly reduces the generated file size, removing what was only dead code.

deathcap commented 8 years ago

Ugh sorry, tests passed locally on my system, but because I was using the latest jison dev version from https://github.com/zaach/jison - not the old 0.4.15 release on NPM. Marking as [WIP]

update: the tests are hitting this (fixed in master) jison bug: https://github.com/zaach/jison/pull/267

deathcap commented 8 years ago

Updated to use https://github.com/deathcap/jison/tree/modulemain (until https://github.com/zaach/jison/pull/316 can be merged), tests now pass

rom1504 commented 8 years ago

Released as 0.2.2