Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class transform allows referencing classes before they are defined #225

Open
nene opened this issue Mar 28, 2017 · 1 comment
Open

Class transform allows referencing classes before they are defined #225

nene opened this issue Mar 28, 2017 · 1 comment
Labels

Comments

@nene
Copy link
Collaborator

nene commented Mar 28, 2017

The following code:

module.exports = Foo;

function Foo() {
}
Foo.prototype.doSomething = function() {
};

gets transformed to:

module.exports = Foo;

class Foo {
  doSomething() {
  }
}

which will not work, as class Foo is effectively a const which can't be referenced in preceding code.

The minimally correct thing for Lebab to do, would be to not transform this code. Reorganizing the code to make it transformable will be quite a bit more difficult (the code example here representing just one possible scenario).

Really the core logic of class transform needs a rewrite to properly deal with variable scoping.

@jimmywarting
Copy link

Wouldn't it be possible to move module.exports to the bottom?

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

No branches or pull requests

2 participants