-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to browserify jison generated parsers #300
Comments
Just hit this issue myself, proposed this fix in static-eval: browserify/static-eval#12 Fix exception instead of failure when parsing CallExpressions The unbrowserifable (or more accurately, unbrfs-able, since static-eval chokes) code is in the generated command-line tool main function:
if jison omits this code (probably not needed when running in the browser - override with var path = require('path').normalize(args[1]); or if static-eval integrates browserify/static-eval#12, then jison should be browserifable |
If using the jison API, then the unbrowserifiable code can be omitted by passing an alternate var Parser = require('jison').Parser;
var fs = require('fs');
var path = require('path');
var options = {
mainModule: function() {}
};
var grammar = fs.readFileSync(path.join(__dirname, 'grammar.jison'), 'utf8');
var parser = new Parser(grammar);
var parserSource = parser.generate(options);
fs.writeFileSync(path.join(__dirname, 'grammar.js'), parserSource, 'utf8'); As for the CLI, if #316 is merged then this will work: jison grammar.jison --moduleMain 'function() {}' |
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), see: zaach/jison#300 browserify/static-eval#12
This is also a problem when using webpack to incorporate a jison-generated module into a build. (By the way, Ultimately, what I'd like to see is the capability to completely turn off the generation of code that pertains to calling a "main function". Perhaps setting |
I would be very happy with a compiler flag to just disable including the main function export |
After a bit of scanning through the source code, I found that running |
Although this may be a stale issue, I just wanted to add that I found a way around this by using a custom generator script which uses the import { readFileSync, writeFileSync } from "fs"
import jison from "jison"
const moduleName = "parser"
const source = new URL("../parser/grammar.jison", import.meta.url).pathname
const dest = new URL("../parser/grammar.js", import.meta.url).pathname
const grammar = readFileSync(source, "utf8")
const parser = new jison.Parser(grammar)
const parserSource = parser.generate({ moduleType: "js", moduleName })
writeFileSync(dest, `${parserSource}\nexport {${moduleName}}`) I run this generator is run prior to bundling the whole thing with rollup using the following:
Hopefully this helps anyone stuck on this issue! |
TypeError: Object # has no method 'apply'
at walk (/home/path/node_modules/brfs/node_modules/static-module/node_modules/static-eval/index.js:89:27)
at walk (/home/path/node_modules/brfs/node_modules/static-module/node_modules/static-eval/index.js:92:23)
at walk (/home/path/node_modules/brfs/node_modules/static-module/node_modules/static-eval/index.js:77:26)
at walk (/home/path/node_modules/brfs/node_modules/static-module/node_modules/static-eval/index.js:85:25)
at module.exports (/home/path/node_modules/brfs/node_modules/static-module/node_modules/static-eval/index.js:114:7)
at traverse (/home/path/node_modules/brfs/node_modules/static-module/index.js:256:23)
at walk (/home/path/node_modules/brfs/node_modules/static-module/index.js:208:13)
at walk (/home/path/node_modules/brfs/node_modules/static-module/node_modules/falafel/index.js:49:9)
at /home/path/node_modules/brfs/node_modules/static-module/node_modules/falafel/index.js:46:17
at forEach (/home/path/node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/foreach/index.js:12:16)
I have one line of code: var formula = require("./formula");
and I am using the calculator example from the website.
The text was updated successfully, but these errors were encountered: