[Pkg-javascript-commits] [node-acorn-jsx] 109/484: Make Acorn work with AMD modules

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:11 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit 76be1f8eee184c104d4d328ca93c4002e42b6d72
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Sun Mar 17 22:56:49 2013 +0100

    Make Acorn work with AMD modules
    
    (Hopefully)
---
 acorn.js       |  8 ++++++--
 acorn_loose.js | 10 +++++++---
 index.html     |  8 ++++++--
 util/walk.js   |  8 ++++++--
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/acorn.js b/acorn.js
index b2a513d..fb7b734 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 4c97323..87802f3 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 e005f75..257958c 100644
--- a/index.html
+++ b/index.html
@@ -14,7 +14,11 @@ https://github.com/marijnh/acorn.git
 
 <p>This file defines the main parser interface. The library also comes
 with a <a href="acorn_loose.js">error-tolerant parser</a> and an
-<a href="util/walk.js">abstract syntax tree walker</a>, defined in other files.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
+<a href="util/walk.js">abstract syntax tree walker</a>, defined in other files.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">mod</span><span class="p">)</span> <span class="p">{</span>
+  <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">exports</span> <span class="o">==</span> <span class="s2">"object"</span> <span class="o">&&</span> <span class="k">typeof</span> <span class="nx">module</span> <span class="o">==</span> <span class="s2">"object"</span><span class="p">)</span> <span class="k">return</span> <span class="nx">mod</span><span class="p">(</span><span class="nx">exports</span><span cla [...]
+  <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">define</span> <span class="o">==</span> <span class="s2">"function"</span> <span class="o">&&</span> <span class="nx">define</span><span class="p">.</span><span class="nx">amd</span><span class="p">)</span> <span class="k">return</span> <span class="nx">define</span><span class="p">([</span><span class="s2">"exports"</span><span class="p">],</span> <span class="n [...]
+  <span class="nx">mod</span><span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">||</span> <span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">=</span> <span class="p">{}));</span> <span class="c1">// Plain browser env</span>
+<span class="p">})(</span><span class="kd">function</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
   <span class="s2">"use strict"</span><span class="p">;</span>
 
   <span class="nx">exports</span><span class="p">.</span><span class="nx">version</span> <span class="o">=</span> <span class="s2">"0.1.01"</span><span class="p">;</span></pre></div>             </td>           </tr>                               <tr id="section-2">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-2">¶</a>               </div>               <p>The main exported interface (under <code>self.a [...]
@@ -1284,6 +1288,6 @@ identifiers.</p>             </td>             <td class="code">               <
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"Identifier"</span><span class="p">);</span>
   <span class="p">}</span>
 
-<span class="p">})(</span><span class="k">typeof</span> <span class="nx">exports</span> <span class="o">===</span> <span class="s2">"undefined"</span> <span class="o">?</span> <span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">=</span> <span class="p">{})</span> <span class="o">:</span> <span class="nx">exports</span><span class="p">);</span>
+<span class="p">});</span>
 
 </pre></div>             </td>           </tr>                </tbody>     </table>   </div> </body> </html> 
\ No newline at end of file
diff --git a/util/walk.js b/util/walk.js
index afed78c..054c289 100644
--- a/util/walk.js
+++ b/util/walk.js
@@ -1,6 +1,10 @@
 // AST walker module for Mozilla Parser API compatible trees
 
-(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.walk = {}); // Plain browser env
+})(function(exports) {
   "use strict";
 
   // A simple walk is one where you simply specify callbacks to be
@@ -302,4 +306,4 @@
     }
   });
 
-})(typeof exports == "undefined" ? acorn.walk = {} : exports);
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list