peg.generate: Implement { format: "global" }
This commit is contained in:
parent
61c11ee1b4
commit
db9920e3ca
|
@ -144,9 +144,10 @@ object to `peg.generate`. The following options are supported:
|
|||
`"umd"` (default: `{}`)
|
||||
* `exportVar` — name of a global variable into which the parser object is
|
||||
assigned to when no module loader is detected; valid only when `format` is
|
||||
set to `"umd"` (default: `null`)
|
||||
* `format` — format of the genreated parser (`"amd"`, `"bare"`, `"node"`, or
|
||||
`"umd"`); valid only when `output` is set to `"source"` (default: `"bare"`)
|
||||
set to `"global"` or `"umd"` (default: `null`)
|
||||
* `format` — format of the genreated parser (`"amd"`, `"bare"`, `"global"`,
|
||||
`"node"`, or `"umd"`); valid only when `output` is set to `"source"`
|
||||
(default: `"bare"`)
|
||||
* `optimize`— selects between optimizing the generated parser for parsing
|
||||
speed (`"speed"`) or code size (`"size"`) (default: `"speed"`)
|
||||
* `output` — if set to `"parser"`, the method will return generated parser
|
||||
|
|
|
@ -1326,6 +1326,20 @@ function generateJS(ast, options) {
|
|||
].join('\n');
|
||||
},
|
||||
|
||||
global: function() {
|
||||
return [
|
||||
generateGeneratedByComment(),
|
||||
'(function(root) {',
|
||||
' "use strict";',
|
||||
'',
|
||||
indent2(toplevelCode),
|
||||
'',
|
||||
indent2('root.' + options.exportVar + ' = ' + generateParserObject() + ';'),
|
||||
'})(this);',
|
||||
''
|
||||
].join('\n');
|
||||
},
|
||||
|
||||
umd: function() {
|
||||
var parts = [],
|
||||
dependencyIds = objects.values(options.dependencies),
|
||||
|
|
Loading…
Reference in a new issue