Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rough support for instrumenting "return" statements

  • Loading branch information...
commit b21eb2b34114f73611e108364992afc83ef75252 1 parent ea806b8
authored April 16, 2012

Showing 1 changed file with 11 additions and 0 deletions. Show diff stats Hide diff stats

  1. 11  index.js
11  index.js
@@ -44,6 +44,17 @@ Bunker.prototype.compile = function () {
44 44
             nodes.push(node);
45 45
             node.wrap('{' + names.stat + '(' + i + ');%s}');
46 46
         }
  47
+        else if (node.name === 'return') {
  48
+            nodes.push(node);
  49
+            // We need to wrap the new source in a function definition
  50
+            // so that UglifyJS will allow the presence of return
  51
+            var stat = names.stat + '(' + i + ');';
  52
+            var wrapped = 'function a(){{' + stat + node.source() +'}}';
  53
+            var parsed = burrito.parse(wrapped);
  54
+            // Remove the function definition from the AST
  55
+            parsed[1] = parsed[1][0][3];
  56
+            node.state.update(parsed, true);
  57
+        }
47 58
         else if (node.name === 'binary') {
48 59
             nodes.push(node);
49 60
             node.wrap(names.expr + '(' + i + ')(%s)');

0 notes on commit b21eb2b

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