diff --git a/acorn.js b/acorn.js index b2a513d52a..fb7b734aa0 100644 --- a/acorn.js +++ b/acorn.js @@ -20,7 +20,11 @@ // [dammit]: acorn_loose.js // [walk]: util/walk.js -(function(exports) { +(function(mod) { + if (typeof exports == "object" && typeof module == "object") return mod(exports); // CommonJS + if (typeof define == "function" && define.amd) return define(["exports"], mod); // AMD + mod(self.acorn || (self.acorn = {})); // Plain browser env +})(function(exports) { "use strict"; exports.version = "0.1.01"; @@ -1708,4 +1712,4 @@ return finishNode(node, "Identifier"); } -})(typeof exports === "undefined" ? (self.acorn = {}) : exports); +}); diff --git a/acorn_loose.js b/acorn_loose.js index 4c97323a74..87802f3b13 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -29,10 +29,14 @@ // invasive changes and simplifications without creating a complicated // tangle. -(function(exports) { +(function(mod) { + if (typeof exports == "object" && typeof module == "object") return mod(exports, require("./acorn")); // CommonJS + if (typeof define == "function" && define.amd) return define(["exports", "./acorn"], mod); // AMD + mod(self.acorn || (self.acorn = {}), self.acorn); // Plain browser env +})(function(exports, acorn) { "use strict"; - var acorn = exports.parse ? exports : require("./acorn"), tt = acorn.tokTypes; + var tt = acorn.tokTypes; var options, input, fetchToken, context; @@ -740,4 +744,4 @@ eat(close); return elts; } -})(typeof exports === "undefined" ? self.acorn : exports); +}); diff --git a/index.html b/index.html index e005f759d4..257958c239 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,11 @@ https://github.com/marijnh/acorn.git
This file defines the main parser interface. The library also comes with a error-tolerant parser and an -abstract syntax tree walker, defined in other files.
(function(exports) {
+abstract syntax tree walker, defined in other files. (function(mod) {
+ if (typeof exports == "object" && typeof module == "object") return mod(exports); // CommonJS
+ if (typeof define == "function" && define.amd) return define(["exports"], mod); // AMD
+ mod(self.acorn || (self.acorn = {})); // Plain browser env
+})(function(exports) {
"use strict";
exports.version = "0.1.01";The main exported interface (under self.acorn when in the
@@ -1284,6 +1288,6 @@ identifiers.