|
|
|
@ -1168,17 +1168,60 @@ function generateJS(ast, options) {
|
|
|
|
|
].join('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var parts = [];
|
|
|
|
|
var generators = {
|
|
|
|
|
bare: function() {
|
|
|
|
|
var parts = [];
|
|
|
|
|
|
|
|
|
|
parts.push('(function() {');
|
|
|
|
|
parts.push(indent2(generateIntro()));
|
|
|
|
|
parts.push('');
|
|
|
|
|
parts.push(indent2(toplevelCode));
|
|
|
|
|
parts.push('');
|
|
|
|
|
parts.push(indent2('return ' + generateParserObject() + ';'));
|
|
|
|
|
parts.push('})()');
|
|
|
|
|
parts.push('(function() {');
|
|
|
|
|
parts.push(indent2(generateIntro()));
|
|
|
|
|
parts.push('');
|
|
|
|
|
parts.push(indent2(toplevelCode));
|
|
|
|
|
parts.push('');
|
|
|
|
|
parts.push(indent2('return ' + generateParserObject() + ';'));
|
|
|
|
|
parts.push('})()');
|
|
|
|
|
|
|
|
|
|
return parts.join('\n');
|
|
|
|
|
return parts.join('\n');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
umd: function() {
|
|
|
|
|
var parts = [];
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
'(function(root, factory) {',
|
|
|
|
|
' if (typeof define === "function" && define.amd) {',
|
|
|
|
|
' define([], factory);',
|
|
|
|
|
' } else if (typeof module === "object" && module.exports) {',
|
|
|
|
|
' module.exports = factory();'
|
|
|
|
|
].join('\n'));
|
|
|
|
|
|
|
|
|
|
if (options.exportVar !== null) {
|
|
|
|
|
parts.push([
|
|
|
|
|
' } else {',
|
|
|
|
|
' root.' + options.exportVar + ' = factory();'
|
|
|
|
|
].join('\n'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
' }',
|
|
|
|
|
'})(this, function() {'
|
|
|
|
|
].join('\n'));
|
|
|
|
|
|
|
|
|
|
parts.push(indent2(generateIntro()));
|
|
|
|
|
parts.push('');
|
|
|
|
|
parts.push(indent2(toplevelCode));
|
|
|
|
|
parts.push('');
|
|
|
|
|
parts.push(indent2('return ' + generateParserObject() + ';'));
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
'});',
|
|
|
|
|
''
|
|
|
|
|
].join('\n'));
|
|
|
|
|
|
|
|
|
|
return parts.join('\n');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return generators[options.format]();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast.code = generateWrapper(generateToplevel());
|
|
|
|
|