Browse Source

tweak message

legacy-quote-reserved-properties
Rich-Harris 8 years ago
parent
commit
4040022443
  1. 8
      src/ast/nodes/ThisExpression.js
  2. 9
      test/function/warn-on-top-level-this/_config.js

8
src/ast/nodes/ThisExpression.js

@ -1,6 +1,8 @@
import Node from '../Node.js';
import getLocation from '../../utils/getLocation.js';
const warning = `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten. See https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined for more information`;
export default class ThisExpression extends Node {
initialise ( scope ) {
const lexicalBoundary = scope.findLexicalBoundary();
@ -8,9 +10,9 @@ export default class ThisExpression extends Node {
if ( lexicalBoundary.isModuleScope ) {
this.alias = this.module.context;
if ( this.alias === 'undefined' ) {
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})`);
const { line, column } = getLocation( this.module.code, this.start );
const detail = `${this.module.id} (${line}:${column + 1})`; // use one-based column number convention
this.module.bundle.onwarn( `${detail} ${warning}` );
}
}
}

9
test/function/warn-on-top-level-this/_config.js

@ -1,13 +1,12 @@
const assert = require( 'assert' );
module.exports = {
solo: true,
description: 'warns on top-level this (#770)',
warnings: warnings => {
const message = `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`;
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/));
assert.deepEqual( warnings, [
`main.js (3:1) The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten. See https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined for more information`
]);
},
runtimeError: err => {
assert.equal( err.message, `Cannot set property 'foo' of undefined` );

Loading…
Cancel
Save