@ -1,9 +1,10 @@
"use strict" ;
var arrays = require ( "../../utils/arrays" ) ,
asts = require ( "../asts" ) ,
op = require ( "../opcodes" ) ,
js = require ( "../js" ) ;
var arrays = require ( "../../utils/arrays" ) ,
objects = require ( "../../utils/objects" ) ,
asts = require ( "../asts" ) ,
op = require ( "../opcodes" ) ,
js = require ( "../js" ) ;
/* Generates parser JavaScript code. */
function generateJS ( ast , options ) {
@ -1184,14 +1185,27 @@ function generateJS(ast, options) {
} ,
umd : function ( ) {
var parts = [ ] ;
var parts = [ ] ,
dependencyIds = objects . values ( options . dependencies ) ,
dependencyVars = objects . keys ( options . dependencies ) ,
dependencies = '['
+ arrays . map (
dependencyIds ,
function ( id ) { return '"' + js . stringEscape ( id ) + '"' ; }
) . join ( ', ' )
+ ']' ,
requires = arrays . map (
dependencyIds ,
function ( id ) { return 'require("' + js . stringEscape ( id ) + '")' ; }
) . join ( ', ' ) ,
params = dependencyVars . join ( ', ' ) ;
parts . push ( [
'(function(root, factory) {' ,
' if (typeof define === "function" && define.amd) {' ,
' define([], factory);' ,
' define( ' + dependencies + ' , factory);',
' } else if (typeof module === "object" && module.exports) {' ,
' module.exports = factory();'
' module.exports = factory( ' + requires + ' );'
] . join ( '\n' ) ) ;
if ( options . exportVar !== null ) {
@ -1203,7 +1217,7 @@ function generateJS(ast, options) {
parts . push ( [
' }' ,
'})(this, function( ) {'
'})(this, function( ' + params + ' ) {'
] . join ( '\n' ) ) ;
parts . push ( indent2 ( generateIntro ( ) ) ) ;