-
Notifications
You must be signed in to change notification settings - Fork 453
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
AMD module generator should be able to define dependencies #202
Conversation
I've updated my code so it picks up the moduleName option and uses it, as well as the "deps" option that I added. (must be a flat array of string values) |
…nd although technically allowed, defining a module name explicitly is not recommended by requirejs.
I landed here looking for a solution to adding dependencies to a parser generated with jison as an AMD module designed to be loaded in a browser by RequireJS. Now, unless I misread something, the proposed patch won't handle dependencies like:
The first dependency in this list is one I actually have in my parser. I've added the other cases for the sake of completeness. I don't right now need to load in my jison-generated parser modules with dashes in them or periods but some modules do have these characters in their names. For the record, I'm currently fixing my problem by replacing the initial:
with:
A call to define without dependencies but with a list of argument on the factory tells RequireJS that the module's factory is using a CommonJS idiom. I do not know whether this is common to AMD loaders in general or specific to RequireJS. |
I was not aware of the |
AMD module generator should be able to define dependencies
Thanks @cjbrowne and @lddubeau! 🍻 |
The AMD module generator is great, but at the moment it's hardcoded to produce an empty list of dependencies. This obviously makes it hard to integrate a Jison-generated AMD module into a larger project.
Should only take a small patch of line 954 of jison.js:
var out = '\n\ndefine('+JSON.stringify(opt.deps)+', function('+opt.deps.join(',')+'){'
If I'm correct in my assumptions, that patch would allow you to define dependencies for the generated module using the generator options by providing an array of strings. It's a bit limited since it uses the same array for the names of the modules and their filenames, but it would be enough for most projects.