Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Scope issue for function expressions #19

Open
dominicbarnes opened this issue Mar 18, 2015 · 1 comment
Open

Scope issue for function expressions #19

dominicbarnes opened this issue Mar 18, 2015 · 1 comment

Comments

@dominicbarnes
Copy link

There's a weird issue I'm trying to resolve that shows up when dealing with a hoisted function declaration vs a function expression. I've trimmed my code down to the bare minimum to reproduce the problem.

index.js

require('gnode');
var fn = require('./es6');
fn().next();

es6.js

module.exports = function *named() {};

When executing node index.js (using node 0.11+ without the --harmony-generators flag) I get the following error:

/Users/dominic/Desktop/test/es6.js:8
  }, named, this);
     ^
ReferenceError: named is not defined
    at named (/Users/dominic/Desktop/test/es6.js:8:6)
    at Object.<anonymous> (/Users/dominic/Desktop/test/index.js:3:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Changing es6.js to the following fixes the issue:

module.exports = named;
function *named() {}

So, it appears like there's some sort of weird scope issue regarding the exported function. Oddly enough, using a name with 2 or fewer characters works regardless.

This could be an issue with regenerator itself, but for some reason I can't reproduce this bug using regenerator directly, only when using require('gnode');.

@dominicbarnes
Copy link
Author

fwiw, I came across this while investigating duojs/duo#433

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant