diff --git a/src/ast/nodes/ThisExpression.js b/src/ast/nodes/ThisExpression.js index baba840..15de769 100644 --- a/src/ast/nodes/ThisExpression.js +++ b/src/ast/nodes/ThisExpression.js @@ -1,4 +1,5 @@ import Node from '../Node.js'; +import getLocation from '../../utils/getLocation.js'; export default class ThisExpression extends Node { initialise ( scope ) { @@ -7,7 +8,9 @@ export default class ThisExpression extends Node { if ( lexicalBoundary.isModuleScope ) { 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); + const detail = `${this.module.id}, line: ${location.line}, column: ${location.column}`; + this.module.bundle.onwarn( `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten (in ${detail})`); } } } diff --git a/test/function/warn-on-top-level-this/_config.js b/test/function/warn-on-top-level-this/_config.js index fd8f9a0..53fe344 100644 --- a/test/function/warn-on-top-level-this/_config.js +++ b/test/function/warn-on-top-level-this/_config.js @@ -7,6 +7,7 @@ module.exports = { assert.equal(warnings.length, 1); assert.equal(warnings[0].indexOf(message), 0); assert(warnings[0].match(/\(in.*warn-on-top-level-this.*\)/)); + assert(warnings[0].match(/line: 4, column: 0/)); }, runtimeError: err => { assert.equal( err.message, `Cannot set property 'foo' of undefined` ); diff --git a/test/function/warn-on-top-level-this/main.js b/test/function/warn-on-top-level-this/main.js index 3853449..e3ca378 100644 --- a/test/function/warn-on-top-level-this/main.js +++ b/test/function/warn-on-top-level-this/main.js @@ -1 +1,3 @@ +const someVariableJustToCheckOnCorrectLineNumber = true; // eslint-disable-line + this.foo = 'bar';