Add module id when warning about top level this - #1012
Conversation
Hard to fix the problem when not knowing which module actually has it.
|
Good idea! Could you include the line number as well? |
|
I've fixed tests. Did not really expect there will be one checking exact format of the message :) Had to do it bit differently instead of checking for a fixed message because the path to the file is dynamic. I hope it's enough like that. @Victorystick That would be lovely. I tried looking at what data are available there, but could not find information about line number there :( |
|
To get the line and column location of an AST node just use |
|
@Victorystick Ok I did try it like this, but I don't think it's correct. It returns |
| this.alias = this.module.bundle.context; | ||
| if ( this.alias === 'undefined' ) { | ||
| this.module.bundle.onwarn( `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten (in ${this.module.id})` ); | ||
| const location = getLocation(this.module.code, this.module.ast.end); |
There was a problem hiding this comment.
All AST nodes have start and end properties. Use this.start instead of this.module.ast.end. (That'll always give you the last line of the bundle.)
There was a problem hiding this comment.
That doesn't seem about right because the start seems to be always zero in the test. Even if the actual problem occurred one line 4.
There was a problem hiding this comment.
I did try now using either this.start or this.module.start, both are undefined.
There was a problem hiding this comment.
@Victorystick can you please advice what else I should try?
|
Thanks! I fixed the location thing, and tweaked the message a bit so that it includes a link to https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined.
For #1033 I added a utility, |
|
Released as 0.36.2 |
|
Thanks @Rich-Harris. So you think that using |
No, I changed it to use |
|
Ah I've missed that. Looks great, amazing. |
When during a bundling I get a cryptic message stating
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten, it's not very helpful to find actual problematic module especially since it can occur anywhere inside node_modules.Adding module ID to the message should help locate and possibly remove the problem.