Change how the library is exported

This commit makes the library define the |PEG| global variable (for
browser export) and possibly assign it into |module.exports| (for
Node.js export) later. The |module.exports| assignment is done *outside*
the main library |function| statement.

The big idea behind this is to make copy & paste inclusion of the
library into another code easier -- one just needs to strip the last
three lines.
redux
David Majda 13 years ago
parent d35b21e9b2
commit 7f2dc850e0

@ -6,7 +6,7 @@
* Copyright (c) 2010-2012 David Majda
* Licensend under the MIT license.
*/
(function(undefined) {
var PEG = (function(undefined) {
var PEG = {
/* PEG.js version. */
@ -41,12 +41,10 @@ PEG.GrammarError.prototype = Error.prototype;
// @include "parser.js"
// @include "compiler.js"
if (typeof module === "object") {
module.exports = PEG;
} else if (typeof window === "object") {
window.PEG = PEG;
} else {
throw new Error("Can't export PEG library (no \"module\" nor \"window\" object detected).");
}
return PEG;
})();
if (typeof module !== "undefined") {
module.exports = PEG;
}

Loading…
Cancel
Save