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 methods are incorrectly renamed #42

Closed
Rich-Harris opened this issue Jul 14, 2015 · 4 comments
Closed

Class methods are incorrectly renamed #42

Rich-Harris opened this issue Jul 14, 2015 · 4 comments

Comments

@Rich-Harris
Copy link
Contributor

Discovered while refactoring:

import { parse } from 'acorn';

class Module {
  ...
  parse () {
    // ...
  }
}

The parse method name is incorrectly rewritten as acorn.parse.

@eventualbuddha
Copy link
Contributor

Is this a good place for a contributor to start? It seems like a good excuse to dig into the codebase.

@Rich-Harris
Copy link
Contributor Author

Would be an excellent place, and you'd be extremely welcome 😄

It think it's just a matter of having a similar check to this one further down, next to these ones.

@eventualbuddha
Copy link
Contributor

I can't reproduce the original problem. Using this code as foo.js:

import { parse } from 'acorn';

class Module {
  parse () {
    // ...
  }
}

export default parse;

When I run rollup -i foo.js -f cjs -e acorn I get this output:

'use strict';

var acorn = require('acorn');

class Module {
  parse () {
    // ...
  }
}

var foo = null.parse;

module.exports = foo;

So there's clearly a problem, as null should be acorn, but I can't get it to rewrite parse() { as acorn.parse() {.

@Rich-Harris
Copy link
Contributor Author

Yeah, turned out there were a couple of things going on here, fixed in 0.11.3. The method name got rewritten if the function was used in the module in question; the null.parse thing was happening because module.getCanonicalName was called before external modules were assigned names - just needed to change the order.

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

No branches or pull requests

2 participants