Skip to content
Browse files

Behave like CommonJS module in CommonJS context

  • Loading branch information...
1 parent 77ec4f7 commit 2120de36af601277daa232ec7f72a2c48d491437 @dmajda dmajda committed
Showing with 13 additions and 3 deletions.
  1. +7 −3 src/peg.js
  2. +6 −0 src/utils.js
View
10 src/peg.js
@@ -1,4 +1,4 @@
-(function(global) {
+(function() {
var undefined;
@@ -32,6 +32,10 @@ PEG.GrammarError.prototype = Error.prototype;
// @include "parser.js"
// @include "compiler.js"
-global.PEG = PEG;
+if (typeof exports !== "undefined") { // Looks like we're in CommonJS environment.
+ extend(exports, PEG);
+} else { // Okay, assume this is a browser.
+ window.PEG = PEG;
+}
-})(this);
+})();
View
6 src/utils.js
@@ -1,3 +1,9 @@
+function extend(target, source) {
+ for (var key in source) {
+ target[key] = source[key];
+ }
+}
+
function contains(array, value) {
/*
* Stupid IE does not have Array.prototype.indexOf, otherwise this function

0 comments on commit 2120de3

Please sign in to comment.
Something went wrong with that request. Please try again.