{"action":"opened","issue":{"url":"https://api.github.com/repos/facebook/regenerator/issues/212","labels_url":"https://api.github.com/repos/facebook/regenerator/issues/212/labels{/name}","comments_url":"https://api.github.com/repos/facebook/regenerator/issues/212/comments","events_url":"https://api.github.com/repos/facebook/regenerator/issues/212/events","html_url":"https://github.com/facebook/regenerator/issues/212","id":96935738,"number":212,"title":"Error when compiling: var myFn = function *myFn() {}","user":{"login":"benlambt","id":272372,"avatar_url":"https://avatars.githubusercontent.com/u/272372?v=3","gravatar_id":"","url":"https://api.github.com/users/benlambt","html_url":"https://github.com/benlambt","followers_url":"https://api.github.com/users/benlambt/followers","following_url":"https://api.github.com/users/benlambt/following{/other_user}","gists_url":"https://api.github.com/users/benlambt/gists{/gist_id}","starred_url":"https://api.github.com/users/benlambt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benlambt/subscriptions","organizations_url":"https://api.github.com/users/benlambt/orgs","repos_url":"https://api.github.com/users/benlambt/repos","events_url":"https://api.github.com/users/benlambt/events{/privacy}","received_events_url":"https://api.github.com/users/benlambt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-24T00:45:32Z","updated_at":"2015-07-24T00:45:32Z","closed_at":null,"body":"I tried using regenerator to compile koa-router, but it breaks down on this function:\r\nhttps://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L313\r\n\r\n###### Input\r\n\r\n    var dispatch = function *dispatch(next) {\r\n      debug('%s %s', this.method, this.path);\r\n\r\n      var path = router.opts.routerPath || this.routerPath || this.path;\r\n      var matched = router.match(path, this.method);\r\n\r\n      if (this.matched) {\r\n        this.matched.push.apply(this.matched, matched.layers);\r\n      } else {\r\n        this.matched = matched.layers;\r\n      }\r\n\r\n      if (matched.route) {\r\n        this.route = matched.route;\r\n        this.captures = this.route.captures(path, this.captures);\r\n        this.params = this.route.params(path, this.captures, this.params);\r\n\r\n        debug('dispatch %s %s', this.route.path, this.route.regexp);\r\n\r\n        next = matched.route.middleware.call(this, next);\r\n\r\n        for (var i = 0, l = matched.middleware.length; i < l; i++) {\r\n          next = matched.middleware[i].call(this, next);\r\n        }\r\n      }\r\n\r\n      yield *next;\r\n    };\r\n\r\n###### Output\r\n\r\n    var dispatch = regeneratorRuntime.mark(function dispatch(next) {\r\n      var path, matched, i, l;\r\n\r\n      return regeneratorRuntime.wrap(function dispatch$(context$2$0) {\r\n        while (1) switch (context$2$0.prev = context$2$0.next) {\r\n        case 0:\r\n          debug('%s %s', this.method, this.path);\r\n\r\n          path = router.opts.routerPath || this.routerPath || this.path;\r\n          matched = router.match(path, this.method);\r\n\r\n          if (this.matched) {\r\n            this.matched.push.apply(this.matched, matched.layers);\r\n          } else {\r\n            this.matched = matched.layers;\r\n          }\r\n\r\n          if (matched.route) {\r\n            this.route = matched.route;\r\n            this.captures = this.route.captures(path, this.captures);\r\n            this.params = this.route.params(path, this.captures, this.params);\r\n\r\n            debug('dispatch %s %s', this.route.path, this.route.regexp);\r\n\r\n            next = matched.route.middleware.call(this, next);\r\n\r\n            for (i = 0, l = matched.middleware.length; i < l; i++) {\r\n              next = matched.middleware[i].call(this, next);\r\n            }\r\n          }\r\n\r\n          return context$2$0.delegateYield(next, \"t0\", 6);\r\n        case 6:\r\n        case \"end\":\r\n          return context$2$0.stop();\r\n        }\r\n      }, dispatch, this);\r\n    });\r\n\r\n###### Runtime Error\r\n`ReferenceError: dispatch is not defined`\r\n\r\nIf I change the first line to an anonymous function `var dispatch = function *(next) {`, regenerator gives this output:\r\n\r\n    var dispatch = regeneratorRuntime.mark(function callee$1$0(next) {\r\n      var path, matched, i, l;\r\n\r\n      return regeneratorRuntime.wrap(function callee$1$0$(context$2$0) {\r\n        while (1) switch (context$2$0.prev = context$2$0.next) {\r\n        case 0:\r\n          debug('%s %s', this.method, this.path);\r\n\r\n          path = router.opts.routerPath || this.routerPath || this.path;\r\n          matched = router.match(path, this.method);\r\n\r\n          if (this.matched) {\r\n            this.matched.push.apply(this.matched, matched.layers);\r\n          } else {\r\n            this.matched = matched.layers;\r\n          }\r\n\r\n          if (matched.route) {\r\n            this.route = matched.route;\r\n            this.captures = this.route.captures(path, this.captures);\r\n            this.params = this.route.params(path, this.captures, this.params);\r\n\r\n            debug('dispatch %s %s', this.route.path, this.route.regexp);\r\n\r\n            next = matched.route.middleware.call(this, next);\r\n\r\n            for (i = 0, l = matched.middleware.length; i < l; i++) {\r\n              next = matched.middleware[i].call(this, next);\r\n            }\r\n          }\r\n\r\n          return context$2$0.delegateYield(next, \"t0\", 6);\r\n        case 6:\r\n        case \"end\":\r\n          return context$2$0.stop();\r\n        }\r\n      }, callee$1$0, this);\r\n    });\r\n\r\nwhich works."}}