[Pkg-mozext-commits] [adblock-plus] 283/464: Rewrite expression closures into regular functions

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:25 UTC 2014


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

taffit pushed a commit to branch master
in repository adblock-plus.

commit d0c0697100f3f33a79f42d0aaa492f37711888d8
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Fri Aug 24 15:07:43 2012 +0200

    Rewrite expression closures into regular functions
---
 autotest/abprewrite_source.js               |  5 +++++
 autotest/test_abprewrite.js.expected        | 11 +++++++++++
 autotest/test_abprewrite_module.js.expected | 11 +++++++++++
 scripts/abprewrite.js                       | 26 ++++++++++++++++++++++++++
 4 files changed, 53 insertions(+)

diff --git a/autotest/abprewrite_source.js b/autotest/abprewrite_source.js
index a928658..3a4531f 100644
--- a/autotest/abprewrite_source.js
+++ b/autotest/abprewrite_source.js
@@ -33,3 +33,8 @@ for each (let [a, b] in fooList);
 
 for each (k in fooList)
   alert(k);
+
+let a = function() 1;
+let b = {
+  get foo() 1
+};
diff --git a/autotest/test_abprewrite.js.expected b/autotest/test_abprewrite.js.expected
index 56e5c89..03b3d98 100644
--- a/autotest/test_abprewrite.js.expected
+++ b/autotest/test_abprewrite.js.expected
@@ -55,3 +55,14 @@ for (var _loopIndex9 = 0; _loopIndex9 < fooList.length; ++_loopIndex9)
   k = fooList[_loopIndex9];
   alert(k);
 }
+var a = function()
+{
+  return 1;
+};
+var b =
+{
+  get foo()
+  {
+    return 1;
+  }
+};
diff --git a/autotest/test_abprewrite_module.js.expected b/autotest/test_abprewrite_module.js.expected
index 4898deb..dad60a7 100644
--- a/autotest/test_abprewrite_module.js.expected
+++ b/autotest/test_abprewrite_module.js.expected
@@ -58,5 +58,16 @@ require.scopes["abprewrite_source"] = (function()
     k = fooList[_loopIndex9];
     alert(k);
   }
+  var a = function()
+  {
+    return 1;
+  };
+  var b =
+  {
+    get foo()
+    {
+      return 1;
+    }
+  };
   return exports;
 })();
diff --git a/scripts/abprewrite.js b/scripts/abprewrite.js
index 8e302e5..ef65ea1 100644
--- a/scripts/abprewrite.js
+++ b/scripts/abprewrite.js
@@ -338,6 +338,32 @@ function modifyForInStatement(ast)
   return ast;
 }
 
+function modifyFunctionExpression(ast)
+{
+  if (ast.expression)
+  {
+    // Convert expression closures:
+    // function() foo;
+    //
+    // Change into:
+    // function()
+    // {
+    //   return foo;
+    // }
+    ast.expression = false;
+    ast.body = {
+      type: "BlockStatement",
+      body: [
+        {
+          type: "ReturnStatement",
+          argument: ast.body
+        }
+      ]
+    };
+  }
+  return ast;
+}
+
 process_js = function(ast, filename, args)
 {
   for each (let arg in args.split(/\s+/))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list